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

Uploaded Source

Built Distributions

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

Uploaded Python 2 Python 3

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

Uploaded CPython 3.12 Windows x86-64

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

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

pytensor-2.25.4-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.4-cp312-cp312-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12 macOS 10.9+ x86-64

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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

pytensor-2.25.4-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.4-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.4-cp310-cp310-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

pytensor-2.25.4-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.4-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.4.tar.gz.

File metadata

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

File hashes

Hashes for pytensor-2.25.4.tar.gz
Algorithm Hash digest
SHA256 6951037301f852acd0964dabf556a27a8710e7b64cc26b58856ddca0d23238cb
MD5 0438dec7fd3de143f112a17d3ef00bca
BLAKE2b-256 5735f8ad7266ad78eaf36ba28d9da0c8e3509a7aef6192d03bd4a5b989f4ea0e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytensor-2.25.4-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.5

File hashes

Hashes for pytensor-2.25.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f0d8981714982f31f87ceb6c5a321d6e186655c6a6d0f3a33686f0e020f499ce
MD5 48dc29dfabaa1f7a67797842b5344f14
BLAKE2b-256 e91beca03e9956c6ae7e6eed8894de66dd2af5910ef5211b8ac9523c428430bc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 37877b8b8ec7c43a2e8cf8b7d95211300b4b4320c119e47510bf611d320b6c3e
MD5 a199e2fe94cdda0ae275dcf112dd74b3
BLAKE2b-256 b0e8facbf3b3876472ad32d72e62a6e01183579088c12450b1cfa7a161ee90a8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.4-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2d27c3a82671186a2d9ddffdb6181c80e2f416cf1198c06d33eb3385f09f563a
MD5 cc346a2411569c571e8cbd79c7989ef7
BLAKE2b-256 ac251fa1b686843ca3c80963abd0d7e4dc179922f0709061c1b666344ca81647

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.4-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 dc0fc3f99fe86c76974e41be45afc9e8e1159fe542c7e12193b8aea3cc70b72d
MD5 6257e59d3a9b6b06f99eb0ab02aad753
BLAKE2b-256 429a2d989b160d16523c0ed1a08ecb8c8040fe266d82dc3c587f13dc765abd65

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ff23f845ae6908de8bdb561fe7f19e9d543e712f2371b16f5f5ff2201c5d1bcb
MD5 a078b614d0a332595373729ba93f678e
BLAKE2b-256 cf9e2a71d517e592f7d1bc883c3b0b5f5c0b4fea2eb2f3e2da87862783fb964f

See more details on using hashes here.

File details

Details for the file pytensor-2.25.4-cp312-cp312-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.25.4-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 cbd4b0b5b1d4d12a885f50595ae213b52487f3fed7b191b9edb2a6a353d4b2d8
MD5 58b1d29a4bb17508e4477a4c31931dd1
BLAKE2b-256 ac3211e3aa200cae17baabadbd84ddd50f5a91c6366fac3183db63a034d79868

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 2aca5afc40910ef8526abe5a516bc14a61d2d817a0de8a4b1228c9bfa9714c03
MD5 7633a2f9f881e89dd846e23bae222399
BLAKE2b-256 29765b8e10fe144b5418ebf936d35e9149d902c28df7dfffacba00865230a901

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.4-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4bfbde49c76adca3ab77646cb0a986ee5cf8c1d10fa2fae72afc55a494706be5
MD5 7a55d2d760490dd3fb910bf81f565b65
BLAKE2b-256 86cc0f0702e5fd537b6054c4a90b8d472a0f618e8f8d255abe003980b8adf88d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.4-cp311-cp311-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 d848ee67654244de4ce24de9469f5b589f302d972b1ac1d24129c906c3db6f31
MD5 2e3ff937f337e107711d8575f7c8394a
BLAKE2b-256 a63e068fb4f52530e29d6cc0533a89e194116832427fc63beee9825a5b9e99d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e51d3fb48f52e0e5c80c9c49245c5ff485528208a7ffb1bd3225561703e5ae28
MD5 7e36199106dee732a9060fcc8ec8f40b
BLAKE2b-256 6e1c964655b59338374b5486208e490d92a0fb41d8cac8b7bc665b67fe23af00

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.4-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 cb62b25aa15692602b1b4f3b587f721f44c48f24734eb7138133f3d5e85f1c30
MD5 3938320685cced9ea2e22e8a8fc9331e
BLAKE2b-256 7653b68644eddd387559faca5994bc4d0a5821fe7120d9ecdf4a165bd46c2f58

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b36bb02f46dd4303b538b6d62ce1e8fee34df29c977111a56c2aba17daf7e540
MD5 8c1090ce80b703eb6e3abf0d3e2b3fb5
BLAKE2b-256 c76b196b2e774e50274de96b9c80d6d9d0487b781783a71128b08251620db3a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.4-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5df66d39cf4e1d9f4c3d723e52e8afcd469e9320127c98fe052b484e238f4335
MD5 645650b132a0d835c20300da186e00e9
BLAKE2b-256 74efeb30c0fcc3e7c138f5dad63da43548018308ea22282880cb5c7806503ab8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.4-cp310-cp310-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 ca20bb49ee704333ffc0997a859ef876506c1b852b01c7a3400c005e1cbcd841
MD5 9ce97231c774e590df2523d85a863493
BLAKE2b-256 91088e694142b9b446f910490bad06f46d6d5dd818605017b0e81451e1aa4140

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 35e162b755772411708162c4b3503bab723bc600449070c8af189555194db6ea
MD5 cf60fa0cf7f5fa6e3bd996da20760b99
BLAKE2b-256 d1a0defd98cab03cf54e91d83874373622ac0645a6d1bf25bd7a4467e96cbaea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.4-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 61086fea85b5bdb06db7f25faf0bfb0d35fc28b2d7b0d0ce02b678b943af61f6
MD5 faa228e08eb870ce523cecdd42cf69e1
BLAKE2b-256 a2ce01eb659fa9cdb919c2eb9167b9c22b0bfea3fce8edbcb44dd433aef0c2fa

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