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


Release history Release notifications | RSS feed

Download files

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

Source Distribution

pytensor-3.2.3.tar.gz (5.2 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pytensor-3.2.3-py2.py3-none-any.whl (1.6 MB view details)

Uploaded Python 2Python 3

pytensor-3.2.3-cp314-cp314-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.14Windows x86-64

pytensor-3.2.3-cp314-cp314-musllinux_1_2_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

pytensor-3.2.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pytensor-3.2.3-cp314-cp314-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pytensor-3.2.3-cp313-cp313-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.13Windows x86-64

pytensor-3.2.3-cp313-cp313-musllinux_1_2_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

pytensor-3.2.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pytensor-3.2.3-cp313-cp313-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pytensor-3.2.3-cp312-cp312-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.12Windows x86-64

pytensor-3.2.3-cp312-cp312-musllinux_1_2_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

pytensor-3.2.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pytensor-3.2.3-cp312-cp312-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pytensor-3.2.3.tar.gz
  • Upload date:
  • Size: 5.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pytensor-3.2.3.tar.gz
Algorithm Hash digest
SHA256 ca64ae1a3da4b2df9abb19110f3c091bf5f3cbf06f3e4bbe2eaeedb04078ab58
MD5 17e9551c3cba4ddd5dc04b538181dea2
BLAKE2b-256 ae77053d7cedad989c2cf4e11a5846972528da7e016dba25c85ba007ce328243

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.2.3.tar.gz:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: pytensor-3.2.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pytensor-3.2.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 78daa74b922981358d7213e55548bba82037ac84fb95b4de9a853d8799f27228
MD5 2fb18268a7eed65760a0dd815c2833b7
BLAKE2b-256 05a638cd9497edd75986d405ed4a8c90d1d7c322389e8f1e3f9a5922066da93b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.2.3-py2.py3-none-any.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-3.2.3-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: pytensor-3.2.3-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pytensor-3.2.3-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 e95f3c6d017736eb76d810c811f14694e2498edbbb3ff98fb421d720adca048d
MD5 d8c548bc889bc1fafdb9a43cb71721dc
BLAKE2b-256 584f09c8eea75b1e1d0bebb769c466ed13cf6e595ab480a327836deb560a7cf4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.2.3-cp314-cp314-win_amd64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-3.2.3-cp314-cp314-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-3.2.3-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c5c03227f776e172796488e183fc82f807a969b02862a85ffa572dc8035e4395
MD5 8532c4110d2991c2830322eb7f74e828
BLAKE2b-256 f389d9de0d49b257c56314613054f3e87c6e8145346604d9de1c07225d181336

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.2.3-cp314-cp314-musllinux_1_2_x86_64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-3.2.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-3.2.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 34fa2d02355dac3612eefbf74ff5dad3cd54f0f0b15bca0a79667ead27271c7f
MD5 0b351502be317c7455e084d890d9467e
BLAKE2b-256 75ea5a45a891d1df53bbc5bb9499dd6f22d1385babd7050070a9fbd960e24bab

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.2.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-3.2.3-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pytensor-3.2.3-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4ea19e1bacfabb8ffbf2d18aac2a45cc03b3864c6efc421e011562410c74f371
MD5 042b026daac4f86691af1c5f45137372
BLAKE2b-256 3eae9b337054468e613ef8249d0c5020dc2577e76704dc2844d8cf50ee9d7d6a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.2.3-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-3.2.3-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pytensor-3.2.3-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pytensor-3.2.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 78a483680533bc15bb94612594beee4a7575fa7bd184442c84a3817334f5fb2e
MD5 5438ace727affb990aa798fb2d8af895
BLAKE2b-256 45e5bb95fb8e5ade7be2d4e739399f4c19045fb8435ce8c81f6dec37c5e104a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.2.3-cp313-cp313-win_amd64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-3.2.3-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-3.2.3-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 36f6dbb403c8bb119949a1a0ad4b92c93efc7f55eb32aef56f8984a051439c72
MD5 50e71d5eb9e61774ada38eed11d658dd
BLAKE2b-256 14244948e98a6a74a1e8dc0f242ecdc6a26c1d71aa52e8d44b46dc56f434e1ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.2.3-cp313-cp313-musllinux_1_2_x86_64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-3.2.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-3.2.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4a0490b7d294fe64a2b8e687ac49bce4af560c8065af8bcdad209c2c48a89561
MD5 6e979fb2042e63ab83d55d8b67f5110c
BLAKE2b-256 16b7ff1c8185dedf287f74bd413645bd8dec9071d041e064280a2a22a7ec3924

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.2.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-3.2.3-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pytensor-3.2.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ccb495e930f99419c792817fbd8841104803c656e288094d0550b266942ef50a
MD5 b32c111588549e21aed2c16dd8fb15de
BLAKE2b-256 30f024d99868c65311a273c43bee3f3f75b94198dc26f51ef3d3dc5e8938d56a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.2.3-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: pytensor-3.2.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pytensor-3.2.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 846973b283d3e2d2c69fd844e466bc200ff1d0114ffb32500746dcc23b409d4f
MD5 0a7fb6b5b25caa7797e38e477ff79896
BLAKE2b-256 e9404259e9b49a692c2a9a364a08d8d66707ab1232cbbf6df02f28d5c9b29afc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.2.3-cp312-cp312-win_amd64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for pytensor-3.2.3-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e2004ead96e19843b0444d24ba1e61c584874663ff12efbf4510b99fb741efb7
MD5 d85ebe96cad041fb334752cfc8886a7a
BLAKE2b-256 c0ce68a7ba63e51137f62dad29419067510393c2d7d6ac7ccc5d83d83fca8446

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.2.3-cp312-cp312-musllinux_1_2_x86_64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-3.2.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-3.2.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 82826e52288d9ecc95f4e5db9567943e5d9ba976f861618aead83d68f8855bae
MD5 5d7cb9ab3a147ad4f44f6d6e64f47d87
BLAKE2b-256 901711ba323ec2e95b83ed075afac5ffffe9779932fade1f6af3e29c51ef5d87

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.2.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-3.2.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pytensor-3.2.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 edbcabd049c81b60012309cbab6c4984545025cd0c3902a83f676be6d0f1c4ea
MD5 31c17d0742abc75cc20a3aa8c0d446de
BLAKE2b-256 4518fad6c72b95050636a7ef9bea0230490c493f295931a91c7d1fcd3f691960

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.2.3-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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