Skip to main content

Optimizing compiler for evaluating mathematical expressions on CPUs and GPUs.

Project description

PyTensor logo

Tests Status Coverage

PyTensor is a fork of Aesara – a Python library that allows one to define, optimize, and efficiently evaluate mathematical expressions involving multi-dimensional arrays.

Features

  • A hackable, pure-Python codebase

  • Extensible graph framework suitable for rapid development of custom operators and symbolic optimizations

  • Implements an extensible graph transpilation framework that currently provides compilation via C, JAX, and Numba

  • Based on one of the most widely-used Python tensor libraries: Theano

Getting started

import pytensor
from pytensor import tensor as pt

# Declare two symbolic floating-point scalars
a = pt.dscalar("a")
b = pt.dscalar("b")

# Create a simple example expression
c = a + b

# Convert the expression into a callable object that takes `(a, b)`
# values as input and computes the value of `c`.
f_c = pytensor.function([a, b], c)

assert f_c(1.5, 2.5) == 4.0

# Compute the gradient of the example expression with respect to `a`
dc = pytensor.grad(c, a)

f_dc = pytensor.function([a, b], dc)

assert f_dc(1.5, 2.5) == 1.0

# Compiling functions with `pytensor.function` also optimizes
# expression graphs by removing unnecessary operations and
# replacing computations with more efficient ones.

v = pt.vector("v")
M = pt.matrix("M")

d = a/a + (M + a).dot(v)

pytensor.dprint(d)
#  Add [id A]
#  ├─ ExpandDims{axis=0} [id B]
#  │  └─ True_div [id C]
#  │     ├─ a [id D]
#  │     └─ a [id D]
#  └─ dot [id E]
#     ├─ Add [id F]
#     │  ├─ M [id G]
#     │  └─ ExpandDims{axes=[0, 1]} [id H]
#     │     └─ a [id D]
#     └─ v [id I]

f_d = pytensor.function([a, v, M], d)

# `a/a` -> `1` and the dot product is replaced with a BLAS function
# (i.e. CGemv)
pytensor.dprint(f_d)
# Add [id A] 5
#  ├─ [1.] [id B]
#  └─ CGemv{inplace} [id C] 4
#     ├─ AllocEmpty{dtype='float64'} [id D] 3
#     │  └─ Shape_i{0} [id E] 2
#     │     └─ M [id F]
#     ├─ 1.0 [id G]
#     ├─ Add [id H] 1
#     │  ├─ M [id F]
#     │  └─ ExpandDims{axes=[0, 1]} [id I] 0
#     │     └─ a [id J]
#     ├─ v [id K]
#     └─ 0.0 [id L]

See the PyTensor documentation for in-depth tutorials.

Installation

The latest release of PyTensor can be installed from PyPI using pip:

pip install pytensor

Or via conda-forge:

conda install -c conda-forge pytensor

The current development branch of PyTensor can be installed from GitHub, also using pip:

pip install git+https://github.com/pymc-devs/pytensor

Contributing

We welcome bug reports and fixes and improvements to the documentation.

For more information on contributing, please see the contributing guide.

A good place to start contributing is by looking through the issues here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytensor-2.16.1.tar.gz (3.5 MB view details)

Uploaded Source

Built Distributions

pytensor-2.16.1-cp311-cp311-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.11 Windows x86-64

pytensor-2.16.1-cp311-cp311-musllinux_1_1_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

pytensor-2.16.1-cp311-cp311-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

pytensor-2.16.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pytensor-2.16.1-cp311-cp311-macosx_10_9_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pytensor-2.16.1-cp310-cp310-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.10 Windows x86-64

pytensor-2.16.1-cp310-cp310-musllinux_1_1_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

pytensor-2.16.1-cp310-cp310-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pytensor-2.16.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pytensor-2.16.1-cp310-cp310-macosx_10_9_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pytensor-2.16.1-cp39-cp39-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.9 Windows x86-64

pytensor-2.16.1-cp39-cp39-musllinux_1_1_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

pytensor-2.16.1-cp39-cp39-musllinux_1_1_i686.whl (1.7 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pytensor-2.16.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pytensor-2.16.1-cp39-cp39-macosx_10_9_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

File details

Details for the file pytensor-2.16.1.tar.gz.

File metadata

  • Download URL: pytensor-2.16.1.tar.gz
  • Upload date:
  • Size: 3.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for pytensor-2.16.1.tar.gz
Algorithm Hash digest
SHA256 dc586d5aea09e29dcc6927c3b99b13af86ea07736d1555be03e2d11282da821a
MD5 4fa2e4be1bdb7e19ab45f4299be31acf
BLAKE2b-256 c5b0dc5273efa47ac6c817879e6863bee63f578f8030f0bc98482f57f7e03f41

See more details on using hashes here.

File details

Details for the file pytensor-2.16.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for pytensor-2.16.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 78998d5f4a0501d30e9873232c6209165305ed236a50bee250c3743c258491c1
MD5 cfa441fc3c19c37c3fb83bb140c6ea0b
BLAKE2b-256 89d946c65a83bf5d5034ff4f8ffdc649c3541e9f60bff0c984ae21170441b66d

See more details on using hashes here.

File details

Details for the file pytensor-2.16.1-cp311-cp311-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.16.1-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 37b787e5f864d8ecf6a285a3cfbf179df422e642f616a208da2f24f574d839a3
MD5 f8c4b3af0787bf24fe1c7ce0210c67d8
BLAKE2b-256 75b2435217ea416ffda7f75bfc4b8d30b4db914c7cff707438d2a948c0413bc8

See more details on using hashes here.

File details

Details for the file pytensor-2.16.1-cp311-cp311-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.16.1-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 5f89154c13d51e1d3b4f29d027d60f1dbce21e8bcf5a71d6fc9cd6c650b72353
MD5 f9793a8cb775b4226cd1a7cc4095090f
BLAKE2b-256 1084775ebacaa592fb24ccd6b23c16ffd2d192cf07d0690813611f05c60f1ee2

See more details on using hashes here.

File details

Details for the file pytensor-2.16.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.16.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a8eb0dd68fa383d635e5fd0b89d22d3632c7cf8e90df3ccc37ea459bbf3e6c3f
MD5 18aaac10df36fcf20d97cbdffffd4a0a
BLAKE2b-256 7c2e7189275319a75507e145119f726daa8d3d3110de163aa6ad581d1de67876

See more details on using hashes here.

File details

Details for the file pytensor-2.16.1-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.16.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5ff70f49c66059a894b408d340f9d83c6cc5850bb096a035f1fbf8c609aedfab
MD5 16dcd251d309d6570ba84f7239c01f38
BLAKE2b-256 6894683ad3af5fdc557e9e02f6e9990ccec10100bf578a7039f327dbfa3cba26

See more details on using hashes here.

File details

Details for the file pytensor-2.16.1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for pytensor-2.16.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 67f25d3c794a25430efad499f356dbe389dd6700387d245fa293fa474adcbcaf
MD5 a9ece9f10a0f77f05a3bf9c43d4099ac
BLAKE2b-256 116e1cdbf25a257cea4a34f4187e6f1dd407065fe038a1552ad8dd3f41a0c89d

See more details on using hashes here.

File details

Details for the file pytensor-2.16.1-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.16.1-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 0fa2956f5219711673b71825f6316cfbb8dcbf4d398b13d9d3e2e73d7578c157
MD5 4d8092b656e24ac54d2c65f55c762d47
BLAKE2b-256 11549a9ffa6b7f76158e11a702de951e093a96ca9ce07e79dffcca22f2ff59c2

See more details on using hashes here.

File details

Details for the file pytensor-2.16.1-cp310-cp310-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.16.1-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 e6b2d78b84e9b22ac1c817409aeb629de49886c01c1f0e9607cf968416c8956a
MD5 130f8d2375cd3bb67db676d34d65e22b
BLAKE2b-256 5e37b5c0332a23c54c6f7ed2e57061a503bf38215dfc49493a5e1fbb68a1f9cf

See more details on using hashes here.

File details

Details for the file pytensor-2.16.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.16.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2b9629ee883cd7881c0e06e17b93da3a672028d4fb0198dbf3cbd959b55e79b8
MD5 2a6c12e466cdbb40065c3999f818de4b
BLAKE2b-256 0ccc6929144501215699abcff7da9143bf6d8fa7c619e7084a900cc0cae75767

See more details on using hashes here.

File details

Details for the file pytensor-2.16.1-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.16.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8d521e9fa556ee085c837098310ca6561772e6012cb310ff66eed1306d6c68d4
MD5 89e406cdb7cc4721208f565ef2014ecc
BLAKE2b-256 dd7cef0b818fa39eacfe423b28f6a7cb1ed186398dbe3d2b13b09049b0d0d0dd

See more details on using hashes here.

File details

Details for the file pytensor-2.16.1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pytensor-2.16.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for pytensor-2.16.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 3191208f2e9816d205995acd94269f97db5a050f9e16f836fb7e0d8cbe824b67
MD5 c6acf76f32cef1d2839dd771b2047206
BLAKE2b-256 4ca305e1ef058ea65bca1aeff24b4b4179f91b259713f89fadb3caf08887e73f

See more details on using hashes here.

File details

Details for the file pytensor-2.16.1-cp39-cp39-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.16.1-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 47eca1d1fc0acd86e5b5867d40be2e361b399f6c4137510b158642cd66c76d75
MD5 6fa6a15ed2f98cf935a54c8bacab3a5c
BLAKE2b-256 c12e31a9d2bdb621fd949e9cae2ac8bfcaf834f6ad2a5e9ead8fd9d43c57ad4a

See more details on using hashes here.

File details

Details for the file pytensor-2.16.1-cp39-cp39-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.16.1-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 fa29fe4f15785e326d4af91b8882442820f94db8ce4293d97b4a83bd3b0e895a
MD5 a5e430d7fac3776198f569efafdd9368
BLAKE2b-256 e77491ef9ee56f4e5d1919da39fb01b71d2cb32951a8c105bca29af12ccf1a7e

See more details on using hashes here.

File details

Details for the file pytensor-2.16.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.16.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 096c4cbd4c22c50d01f3e3fe156d8182337011accc634cfec56043f8e93f39db
MD5 53b36094035245aa8ee147eff16090ff
BLAKE2b-256 a4f37dd6060548f07c87b4f76071d91e6f488841c3ae48e7cff20eeeeb16a503

See more details on using hashes here.

File details

Details for the file pytensor-2.16.1-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.16.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 208b2fa548465f323ef5fd1779e37c7d4a14980c6263650e4a9f4befbe7c002e
MD5 ad8f7b22b185615adf16b382ccfde893
BLAKE2b-256 906fc884a2c0c00cebb1b0299920802a0a7c5a6900fa6ebcf1b6d8bda61dec2f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page