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

Uploaded Source

Built Distributions

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

Uploaded Python 2 Python 3

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

Uploaded CPython 3.12 Windows x86-64

pytensor-2.26.0-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.26.0-cp312-cp312-musllinux_1_2_i686.whl (2.0 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

pytensor-2.26.0-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.26.0-cp312-cp312-macosx_10_13_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12 macOS 10.13+ x86-64

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

Uploaded CPython 3.11 Windows x86-64

pytensor-2.26.0-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.26.0-cp311-cp311-musllinux_1_2_i686.whl (2.0 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

pytensor-2.26.0-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.26.0-cp311-cp311-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

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

Uploaded CPython 3.10 Windows x86-64

pytensor-2.26.0-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.26.0-cp310-cp310-musllinux_1_2_i686.whl (1.8 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

pytensor-2.26.0-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.26.0-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.26.0.tar.gz.

File metadata

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

File hashes

Hashes for pytensor-2.26.0.tar.gz
Algorithm Hash digest
SHA256 d8370439a9e917af1bc09eaaafb29a7b0883a3e251ae763589416e52a2a4438c
MD5 d869f2495813b66a3c9a89b59b24c0f9
BLAKE2b-256 d75a797a4cc3683833ca4cf0d9bc2c86cd40c1218cd1d63ff722a56ac7a7ae68

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytensor-2.26.0-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.1 CPython/3.12.7

File hashes

Hashes for pytensor-2.26.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 93f94666873675737c417c8c2f43a93eff7bf20ba0b6f3f9c2c660946ea5aae1
MD5 35eb5d67f074a1abf7746b57bf5f8162
BLAKE2b-256 59fd36333de73c416d5de304f77655d5c7f630932b08dc5aa965e511a558f047

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 46ad9d33a157c8ec37ad4b484dd182d2b1ad405039186a08e38175a49bc26972
MD5 ab4fc955a27293e8d8b5dc690e0132b4
BLAKE2b-256 b5a238142b3379d4e2959ff9e22c1a2555078161121c00a21def279dbeb100ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6105a078d40a3178258790bbcf6f15fd381659f74fe9a34cf0527df86a709914
MD5 828d0d3fe7393accd730286a67eb8cd8
BLAKE2b-256 9b6b82fd6c84ec8ae0b52b36ca1885f317fd5ac5ceb0fc851dfbcc994cbb1703

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.0-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 11fe64d3b4b5d5b2529d9bf47e8021056039234b369780a74575bf7038075002
MD5 302d15809bc0228aa86bafc30ab7671b
BLAKE2b-256 9acc0f234b9211bbae42e1b9caf921bd11efad7ca2143335f98c6dc113783dfb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fe40264dd4fed9f7f0006addd463a66a3f909081bf80570ef28ebb0171e6396d
MD5 d89f1460f68400cc7429af4353ecf04d
BLAKE2b-256 d917fbc4d8d549684554eded3ac26207d5da4e4da066f1248fa6f770039f6ada

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 210ae14d84fffafb82a8f8e1d9d4ee9eee0a4b38297687fa7222c0ab3143e182
MD5 8ffb078244d47626a00fe9f844d8cf0f
BLAKE2b-256 17b6ccbeb97ce6cb9448568fe40bdbe3698e0c7764613ca5e26507f49e797b30

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c18e6531cd431ab9c6f386fdd3e365636a8a758c7e223a4e07db3759cb1b33fd
MD5 6e471643c179024099aafba1335cb6fb
BLAKE2b-256 8fe3fc9e0273b48bd1ce22e9e1eafcb3f11aa23860246816bf23e8f2d8c1643d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f14fc699e831dc01b29643864bcb8e8436658d7459297f8968fdc84a08c91d3e
MD5 afcd7d0bb838c6a137a0056020b64c5a
BLAKE2b-256 945224cc1153214ba02c4f72626f02308b694be0251ac58cf678167db38c572a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.0-cp311-cp311-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 e00813d7303a4676c8cc5e0604620f9cfc859b92dc5598a0bbe156bc6e46b1ff
MD5 b24acca3ccd3fde6379355d5c6a5e746
BLAKE2b-256 b9057966b67e40af67bbb81a6cd82c495f78c9ac8e03e9e34d1a422a7bfc1285

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 264f92edb2f32718e03ed916e9a6145b0fbd30e79254ff6e3831072540a9fcf8
MD5 bdc46d2e0cfe31d8e506cf7d84f970bf
BLAKE2b-256 fa41ac74e23813dc34ef31eb14f9894f52d7da006a03f4339696d447b94f66b8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8f5c1e4f439244cd74392319cf09595cfb0383fb50c2654a86da3b411575efd1
MD5 a1c3ab5be8ef56faa890b0979a7414ea
BLAKE2b-256 279a85b57eda75d8a6c25c755277c66b980bbfd16b1635e9252c69e3c76834b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b02afc718a2162605e029da5bbc35cb481839f646ce4ac019d0c0a637ff477fc
MD5 07d37c89a11b90659db76e7b51c3f19e
BLAKE2b-256 98a4784ee4a38f28762a68cd7b5ef48ee3554165a448510bc7646b5c40f4eabb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.0-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 31564a761ff9e41e3f6b190005ff33d519dc96e5096e41dbb342dc143a8ee61b
MD5 097a6f0504c5360237f614ab376b2a08
BLAKE2b-256 38e733448978507d5933c2bafd9431c71cb6a7c303e249a6e3f0c73d69b0c4ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.0-cp310-cp310-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 76303934fe9e80a2593f8d41ab16d35fba89cf112a2436e726350b3d0f3009ad
MD5 92c34157779a1e3638c2182dc069bba1
BLAKE2b-256 32f10d3b0fc62408c0eec4cf3a76328f6296ce0f2359c1a9ef58ba8a7609786a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5bab9186838d7f772a4a330f5726ae552d45ca3dff4377ed45a89bd32b9b82ae
MD5 4aa752ef91a85dac96ec182abc16196e
BLAKE2b-256 ba977a62e8eea6adec912507f7f6ef3d6a717393eacee65f3981dcfa88c82627

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c0a163de7c7dddf914863e24cc4f066c343c0c8b47ef12fc3e60948bc2b10e8f
MD5 6348dab692d48cda185043c881e4170f
BLAKE2b-256 08f08a04e46a4d8336fcf9f526b390eb368a5046843212a69e0a84d539e262f8

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