Skip to main content

Optimizing compiler for evaluating mathematical expressions on CPUs and GPUs.

Project description

PyTensor logo

Tests Status Coverage

PyTensor is a Python library that allows one to define, optimize, and efficiently evaluate mathematical expressions involving multi-dimensional arrays. It provides the computational backend for PyMC.

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

  • Contrary to PyTorch and TensorFlow, PyTensor maintains a static graph which can be modified in-place to allow for advanced optimizations

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

Background

PyTensor is a fork of Aesara, which is a fork of Theano.

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.25.5.tar.gz (3.6 MB view details)

Uploaded Source

Built Distributions

pytensor-2.25.5-py2.py3-none-any.whl (1.2 MB view details)

Uploaded Python 2 Python 3

pytensor-2.25.5-cp312-cp312-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.12 Windows x86-64

pytensor-2.25.5-cp312-cp312-musllinux_1_2_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

pytensor-2.25.5-cp312-cp312-musllinux_1_2_i686.whl (2.0 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

pytensor-2.25.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

pytensor-2.25.5-cp312-cp312-macosx_10_13_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12 macOS 10.13+ x86-64

pytensor-2.25.5-cp311-cp311-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.11 Windows x86-64

pytensor-2.25.5-cp311-cp311-musllinux_1_2_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

pytensor-2.25.5-cp311-cp311-musllinux_1_2_i686.whl (2.0 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

pytensor-2.25.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pytensor-2.25.5-cp311-cp311-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pytensor-2.25.5-cp310-cp310-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.10 Windows x86-64

pytensor-2.25.5-cp310-cp310-musllinux_1_2_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

pytensor-2.25.5-cp310-cp310-musllinux_1_2_i686.whl (1.8 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

pytensor-2.25.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pytensor-2.25.5-cp310-cp310-macosx_10_9_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pytensor-2.25.5.tar.gz
  • Upload date:
  • Size: 3.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.7

File hashes

Hashes for pytensor-2.25.5.tar.gz
Algorithm Hash digest
SHA256 f8b9f7d637104b2fc7fdd9c50219cc639744b718572c034b7cb8fe8f5051da92
MD5 7b712f4ebdbc6ef2209bf6096b740887
BLAKE2b-256 bba54ef19e1a589cb0dfc863af1afa1e9a54d6bc30579504893ec4682f44520e

See more details on using hashes here.

File details

Details for the file pytensor-2.25.5-py2.py3-none-any.whl.

File metadata

  • Download URL: pytensor-2.25.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.7

File hashes

Hashes for pytensor-2.25.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 92271932118e4d9e6528eeba1cdd0e9e8f2d05d8493eb394da2cd8cf09c8836e
MD5 92e801c7eef921b3f6b724dfb3e077bd
BLAKE2b-256 f511032d9c2bb9bfa1b6d933c17a6fd063e075c533cca271d8c9b2055f94b981

See more details on using hashes here.

File details

Details for the file pytensor-2.25.5-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for pytensor-2.25.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 5edaa549903a8be02e6dcf56110d5cf523b6249460c455138e36686928a6c5a7
MD5 ed952ab8284de52757d80ffadae9c16d
BLAKE2b-256 0bffd949332ce887e634de0c26c47486166bb1a56597c3bf477b2e7d61be2767

See more details on using hashes here.

File details

Details for the file pytensor-2.25.5-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.25.5-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 16344b21bd70eb689c7db7ab91eec556012c08e9ad8a7cbeb42812d53f89a64e
MD5 a908f003957287378d5572eb63123b4b
BLAKE2b-256 8e22e68d36ff93a15d1d5d458765503a2937155b08f53c5bf198e6b2fc458f5c

See more details on using hashes here.

File details

Details for the file pytensor-2.25.5-cp312-cp312-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.25.5-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 0c973a8a682854eb47378db33cfb5bc63ba5a868b5749fe79b2846e6795ff46d
MD5 79b90c95064f5ec8e61763faa41f5ef3
BLAKE2b-256 1b63be49fbdb9ad4c43485f637ced24c2df9a0f58da4c765bbfe177748004742

See more details on using hashes here.

File details

Details for the file pytensor-2.25.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.25.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9c99f2aed904178c59fac57f5a760b547f7c1c14c20d31e41721fbebf9e47cf1
MD5 f01757a4a0d69747b857f0e75121e404
BLAKE2b-256 060792f6e94c1ec6eea9e3acebc7c2767a7bbf1d4ebd320e4326aeb04c2eea9e

See more details on using hashes here.

File details

Details for the file pytensor-2.25.5-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.25.5-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 f15cf74eff5e53854f9e74ac4991ae850e48641ccbb211200d214c599b76d691
MD5 48ddca2b76dc6f5f5794478a05830d3a
BLAKE2b-256 7799f8f4a75e3287c48409dad5aa96336d10d76e9b4c9ebf5193b7436473ab2b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8a7b9dc112e3cef8e05641da9429a46fe1cd9d3b3bf11763c3500bc941c49fc7
MD5 27bcc427ad686ffc0dcdd58525de70ce
BLAKE2b-256 653b53e051ba30e399650b065e6da877a733c8b8e92426c891786b515080ba9b

See more details on using hashes here.

File details

Details for the file pytensor-2.25.5-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.25.5-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 78686d9e26b26da2f0824f1f5a297f153b948a93c46e527d43d7337fe31e5afb
MD5 f47df49d67ba2271b35ed3a07df2db99
BLAKE2b-256 98b52ebe68a162f64daf4161ba0f74141adda0c3111ea04a8e4b6a27df9be2c9

See more details on using hashes here.

File details

Details for the file pytensor-2.25.5-cp311-cp311-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.25.5-cp311-cp311-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 930429bdf5cee35868a06a9d075f2fb40b3471708a61bea62cfafd21aaa0811e
MD5 2ba6a271544029ce61f508ae47c321c7
BLAKE2b-256 7b4914eed626a4803d55703714268586250a9c531461c1a2e5a6b89c74bc369d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 eb7f6a370a99095850949798ee0ada38ace5132172fcbb4272398e687de5b417
MD5 3e378ad67e3093c8108b13e601ebbc36
BLAKE2b-256 76284b5cd6067cab5d8180383d13533f6e8e3c1d8e8df8f3cce940d8aa9868b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.5-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a97e769900718fea3a0efd2a4c452775786ca3bd7966c6510e89a1356e516d55
MD5 9b40cbd81956cdc0838e26d4b32917a9
BLAKE2b-256 7a133377794660abf0ca720c3f51b12f9785a40ef8fdf94d61e38056cc8421da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 50264e6365578ee15298f23578ddc00cec4f015c1cb77dafbb6c3216b11f689c
MD5 b1edc0dd18b7baeda8561849e2ae5abd
BLAKE2b-256 051501a2214fe1da4f6140f7d959206d5ed93e3452bfa7ceb8c92e9b600470e0

See more details on using hashes here.

File details

Details for the file pytensor-2.25.5-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.25.5-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 343000f352c12ec36f5307d5c9ff7d8aba6dfa651be8c26b824d75cbad29d776
MD5 d082dac210c327663a7ecead6d9f7530
BLAKE2b-256 bf7289a271a956a68540fb0860d13c64289333b9d342ce3a9cfc66b2000c4550

See more details on using hashes here.

File details

Details for the file pytensor-2.25.5-cp310-cp310-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.25.5-cp310-cp310-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 51ea5083ec4760e6cfda48422d1b69e88d1b68e0f9a4aca41b0a89a4f38a1da7
MD5 7ab7fcb5bb33e67b3bf7dfb8be4cf29b
BLAKE2b-256 1d4e530426b9f42ae9fe7b20c4d9fed668693323fedb7b9a89cf14ae15bd51d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 29754160a84ade77b63e1690aad8306da3b8f6f8e35c8ac5d36d1b19066b5f8d
MD5 9ec243a78ec2fd219f7b59c7b86173fa
BLAKE2b-256 24211453be9b7b9db42347731a482a2608f61683c52996ae1ceafdc482af64db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.5-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 23ffac5ce99089abe3b6e1ae0c957f3af2a382209fb5894eb42acba0e01b96bf
MD5 a91273997b2a8b1325a2bc32628256c4
BLAKE2b-256 05c25ea704f628c8998e80759d8c95645742739f06f405b6ff03efadc7f43719

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