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.1.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.1.3-py2.py3-none-any.whl (1.6 MB view details)

Uploaded Python 2Python 3

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

Uploaded CPython 3.14Windows x86-64

pytensor-3.1.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.1.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.1.3-cp314-cp314-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

pytensor-3.1.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.1.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.1.3-cp313-cp313-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

pytensor-3.1.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.1.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.1.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.1.3.tar.gz.

File metadata

  • Download URL: pytensor-3.1.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.1.3.tar.gz
Algorithm Hash digest
SHA256 76dcc74417edfe24fbbe0b5687b8be7bc069c53e9ee93e08cb245f3b3d2c612f
MD5 b32d194916bcbf95ae381c0be6d1d689
BLAKE2b-256 5cae61f36d8ffa05d0eb1ca7a6c18bec83eef1f8e43d5d307531bdab51dac8be

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.1.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.1.3-py2.py3-none-any.whl.

File metadata

  • Download URL: pytensor-3.1.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.1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9f2337cedf135b2710aebf51fd03533c1211b386b9742f2b4578951fd013d4c9
MD5 d02a0fa752f4a888d7a73a00845e18c0
BLAKE2b-256 e25a671304f945d1d32d8ed39af7d66da49df18a6d0287dce88d81e345ec50be

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.1.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.1.3-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: pytensor-3.1.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.1.3-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 17d290ef2d03582135ca3389510aa7f786742cc9612d23715fe1162af918fbaf
MD5 7926083ef77e256737325227abdfd0d3
BLAKE2b-256 f4bfcd275e16900cb79eba9fa26c230661ac7440094cd63040b692cebe8fd21b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.1.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.1.3-cp314-cp314-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-3.1.3-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 37fda3ecdc32078922e2e7eb8d5e3c125ca43622086eacf55f466b21f396f997
MD5 54fe195e27b3bd5831b7739db0ee4f84
BLAKE2b-256 c66adbe35867916b7f1ace7e1cbd26b5b0d511bd1556fae1513a82d25e288389

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.1.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.1.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.1.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 697f0634d908b2a4350c9651d9fa26a9d229fc8ed10662bf82e8fea0d61d7181
MD5 eff8a5851e23c623379b6730c33281d6
BLAKE2b-256 fd706567ba609d26dd31e0399d9d628c81f61daab3c4e2ec509da5d8ba8bf1be

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.1.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.1.3-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pytensor-3.1.3-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b755f5d09a6eeacf2819e2dbc62cb4a697f869730160f9ffe22f2a115e917a98
MD5 8b336b511749569710fe7e1048c66b9e
BLAKE2b-256 97b57f27b95359f880da71e8670744e275cb2828014888e31f3dd1fa8cd8bbd3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.1.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.1.3-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pytensor-3.1.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.1.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 fe44159d5f8961ae423ccdf900b39f167c8c52d9f841318f05c06a2992ba1706
MD5 68d3c30a96d84f085d9976120eb02681
BLAKE2b-256 72e46458c2ae93857cc6228b867c5ea4e2018a170222d164c53b6126994104d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.1.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.1.3-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-3.1.3-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 76ed66b9da94233ccc35fc517c5c6666e7b6fffd605c37fce351d804ce7d8424
MD5 9a608e32071c81feb52d4916040c7312
BLAKE2b-256 e86a766389d77fce15528a663b42a0ebb83a687970d6b61f64e358823c8968a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.1.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.1.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.1.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2e9e796b7b6ad186a32d900df5c596c54cb6727f2226993ff2c48e7af1580062
MD5 adbcfa61121436c7c35475a95869453a
BLAKE2b-256 af65fd00742c0f578ec2c3d50c75366ef3a96ecf9461255eb34913032b6a3261

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.1.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.1.3-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pytensor-3.1.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5ac02c0e62d7b8d517bbb2534bfff52744b8352b7e8ba128bed05cbe96090446
MD5 d500f774cc770320f0d56fa71c8463a3
BLAKE2b-256 403b0f79959021a293577533942c3154e1ff7eb550b2a2c13d1b5defda7c231b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.1.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.1.3-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pytensor-3.1.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.1.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2944147f391a112ae553f5102758747299e22c6ac29cacd80a928574494701e2
MD5 c39006b9e3204ed2013ceee15365fb61
BLAKE2b-256 5069b93a36f16e8ba138c94f9a655acaf5dc3bf7c5c12699b05ffe241c42367f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.1.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.1.3-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-3.1.3-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8e201b7be3ffebc43bafa889af2c51dc08730118c53e190c868bbf6045699568
MD5 9fa0b7db1746f1fd6246cdfc573f0e15
BLAKE2b-256 54b8510b8ad7790e7d560544654a8e188880ae5f7d93524860c2f94e67772980

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.1.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.1.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.1.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 39f1a37fa860d00ed931dff93e4c494b5a6c39bea0498c7af5bc795ab5a26250
MD5 49e028d942eb775e6422247bd03357d6
BLAKE2b-256 da838e30fdf7282ee4e9f1b12caa1c793c25408bea7594c51c4992fadbb88790

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.1.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.1.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pytensor-3.1.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8111a763a656631179494002cd31ac3f5dd92527c46b938a8abc1257d7cbf2ff
MD5 bcf85e7f7e2bed49ea30304533a4769a
BLAKE2b-256 98ef02f9f1c1aba044ba60ef2d4bfb6563482824620e0aefb41fe30f766a43b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.1.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