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

Uploaded Python 2Python 3

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

Uploaded CPython 3.14Windows x86-64

pytensor-3.2.0-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.0-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.0-cp314-cp314-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

pytensor-3.2.0-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.0-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.0-cp313-cp313-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

pytensor-3.2.0-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.0-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.0-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.0.tar.gz.

File metadata

  • Download URL: pytensor-3.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 2f9060b2fdab74fd3f10002c880e06e6bb5c55fcaf5c2d484470a1328101d747
MD5 508b54a94a2feb06e899935e18be17c5
BLAKE2b-256 d103fb1158e49121e095d6f04668c9bf6c0e10a35a7c03c8f33ba45c5adf7da0

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.2.0-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.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8759c69eaa85a0778e0f24fe9dbdfa3b47776f1e367d95099585532ce42bec8c
MD5 48e388935a33e2578c05057c4d21c3d7
BLAKE2b-256 0cc23a423ec383043433856b0348833ced1236d8a080ce52b84534c22ddef071

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.2.0-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.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 22eab951c497b2aaf1b9b54a73dcab8a90a6ad9547e0a7b74ec1ef50421cdca9
MD5 5dc0013989fd554f2a4c8f6e2f211f39
BLAKE2b-256 4ab2223f98afb45ba5d3efe16e90f6ce8dd70144007f16ec20181b8f2804e600

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.2.0-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e79fd5d00c3deb535903548e47bb618855444eef627183a09f268b37e7b4edd7
MD5 3aeb8c98b17cce855808f3ca0163759f
BLAKE2b-256 ef1763f591dca3d599793ce4b3159800a3e212b29f252ba9eeb0beb7dbda9b2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.2.0-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.0-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.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f66256b54449fa1051578b874c240dbbf192239de61fbd05d3d2120f9e306933
MD5 2f415e8a41b1ce8398721b0280d132cd
BLAKE2b-256 4c786cd2d6ab53a1cc8fb6d2ff75eabf97e227b4cf203b9a275ea5f598ff365f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.2.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c1aa47ee0a0bea385e015d90bf94cf4cd08fa1e413a466d7d9f025d0ba01e357
MD5 651cf988a57aaa22a71415e59738945e
BLAKE2b-256 1781e2703a78d15ceedf52e0aeca5d8a0192ca2fe8dbd18e596728e7f4efff0a

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.2.0-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.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 59292fb0e2d19c07f5d44ba96dede776299afacaadb7e6fedc63393f0af64fca
MD5 48fd2637022cf018af780eb45aac02ea
BLAKE2b-256 ac39f8341174d45089d7f6efabb402df1ba38119fcdd1a0b245a09f335e589f3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.2.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4322eef04cbd83f60510be5d94957e816a47f42930b35daa0b8dd52eefa76133
MD5 20f8fde1fe2bb2192eff00d4d44fe94b
BLAKE2b-256 e0e1ccdce58e24bb864a503ceaa6907f9b258226784bd308cc83a2ffc4fb7662

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.2.0-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.0-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.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f893dcd6956611849cdc88beddebd56ca404d24e31259a9b2a75d722eb88feeb
MD5 b88799a37d55f9e6659ebb692ede6e73
BLAKE2b-256 85ae9c54b340b574413142ffb6f4b302bd1913082e79f5bb20492c852cbe3db2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 df8835c06d2609ee66a5f6c228ea8ad1d0bd01b31fc368523191d2fbead58428
MD5 b88bd421a47c50f6691080606e698f90
BLAKE2b-256 7beed406fe9325c79dc63878b037e87e42f10e3df780004882dcced458d04397

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.2.0-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.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7ad60afef8f17eefab865f0f49c26a7e7ae4bd343fee59ee775f3c22b8b4ceee
MD5 79654e6663ffd1f1bdaae8045a3f7c31
BLAKE2b-256 5ff0520eca572471770da93b3a143a564274096a2c4cd7e7878c514674dabea9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.2.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d7224f30ab90bf3f1c889a21a7e7068c798685cb1f5c0981b196429187ca3c6f
MD5 fa1f5d0f63cc63694d691508ed14ee90
BLAKE2b-256 8edf7d5b9b60c456b5fb1ebd4c3849484fa79a9daf9eebb9ade415a2eb23d9cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.2.0-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.0-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.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bb46e33dca6370f811c07fe8648cd8e5981a72701b0cbcea8479ca832765e81a
MD5 60a93e696d3f33938d11e68dcd8e5553
BLAKE2b-256 a40b6b8ac61a51ec3005435c972a953efce4bd844c3410c76500d60eb82e90e3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 463770bcad4db0c755d66a04e0b888b40687536be9a22dde50401bca6cfe1b8c
MD5 8f7169e99fdacc11211908b3b861872c
BLAKE2b-256 baac0edb8a6343217561053294e3e00826fadc118d0abbb48c2b7bd6e7f5fe98

See more details on using hashes here.

Provenance

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