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

Uploaded Source

Built Distributions

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

Uploaded Python 2 Python 3

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

Uploaded CPython 3.12 Windows x86-64

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

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

pytensor-2.25.3-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.3-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.3-cp311-cp311-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

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

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

pytensor-2.25.3-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.3-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.3.tar.gz.

File metadata

  • Download URL: pytensor-2.25.3.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.3.tar.gz
Algorithm Hash digest
SHA256 7ad8dcecc5f99bb0c3eaf559cc1ab69af2187bf33694a71c37940d3df9be568f
MD5 6db2df5b2fd01b8f1918885d7bbdd5d6
BLAKE2b-256 bc73c25f12656a9a4ab5f6ff878f57398cd3b194d31e89b8445b53b635a424a8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytensor-2.25.3-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.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b5ce68adc2aefd7cd6ebc91e67fc4b28f771dbd512e72e769a492031e2ec7cb3
MD5 d107f1b7979dbc0d9800d173999bd1f8
BLAKE2b-256 040265edf67334eb9ab67bf4e7143ae41ef59fbc124efa881e2ade714d8d697f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 829cadab0285b692965d45684b5908753be4ad0768ff08ad76b070e4234ac46a
MD5 249725496f7d31cacc4c6191a486a7a4
BLAKE2b-256 ecbf2867df0f23da80fb603409fe38b928f9b887f4731fb16f85d027fa4132cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.3-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 151cf065faaf590532e6378ef152f9a76d4e535ee74b24796961f874dbead7a0
MD5 cee6dd3c429c87d58fbc274a36837bea
BLAKE2b-256 b443585b71c34f72d4376a49850421a6a5f421e99ada9582ed466b928f533c76

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.3-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 0af8cbc590fe888d26d15dc3deeea3475b449b0090f2a3e037245e1df8a1309d
MD5 6bd14b1ee28378de9cdc29e76c1be735
BLAKE2b-256 6b2624b73da8ee4fa37a74371e0687c6727525526b0d8834411a0df30857f59e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1c918f828ba227af98268b8abeefcb0c0fcb7cd3e74c9c439bcb6fe7f3f9b02b
MD5 50f6309fb3d3adda91670251a14a1870
BLAKE2b-256 8abcf1cb657746cba5273ddaf192e16cb668967f3f2524737d6ca156566314ec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.3-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1e36ab918152a91497f1f634946e170d20fe9c841cb4f556d0819865d3917d86
MD5 f83690eac81627e72fef47048b1926b5
BLAKE2b-256 c101c0ace7097a08d563c3e3e13e2392a5e007b56741c935181d0d02e0531624

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fc1a3300e388cb2a8233631161c85017d6deb37f14d750fd72470943bf087a8d
MD5 4a4b8059bf2a20fbfe6c8ed34ebfe77d
BLAKE2b-256 8a2315b38d0c26b96bff72f38fafc97c311e7365828bb8ffffc82e168a6b3b64

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.3-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 862df18fc8743ec7150cd3aa0d05600b61dbccfe42e712183b305353147e8c26
MD5 a71fca5d6029af90d87920de28ec1763
BLAKE2b-256 1a398f1bac2bd5c010f4a7604216e4631d4f2b9d282383dcc8cac4c281508c9a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.3-cp311-cp311-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 ae46eb4ef0261892222b92aeacb07a2dafc0e60520224a8d17043f29831e1501
MD5 4d8fd6c22cf78992ba7a7fb3bad9a5ab
BLAKE2b-256 a861bae3a5d0da5b22747298f58823f28adc3defab872b64b254add094979278

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c584a924650244d1bcd899d95181a671d1a375586c5c2bea88afedb82b5999fc
MD5 3bd2f8f60ad377fb69b7c1790749a300
BLAKE2b-256 072db56e6e4a77788c3758eee1852802e58512df06dad5fa9f94e2c2e849cbe5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.3-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 aabafbb072a5c5625013bb10bb086f47e6463d6fed4e44d4bf732d8397e14846
MD5 adbe7f640bad8bcb8cb7e0a19d5ef680
BLAKE2b-256 91dd38d658ec4881e247712c3fbfc3ce045761de9c8ece2f8d64a497f891861a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ae525b4ab52b6147ac94d5642f5170e34e4c7a47102d2794c9f1003b7c4771e7
MD5 c54e01b387a6be24352dfb737eca501c
BLAKE2b-256 f9f08d0cd708285b8583185738d4486e7baa249e77a9237b36dd8929a13c9c4d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.3-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d47ec66f5ddefd61bea4090b98be3e1a48d69ee0ce43466827d4a0c477e3bc12
MD5 41cdcd0188105398c411d181601692d8
BLAKE2b-256 202a3e844fd0999df34ac449fae06fdc18c80879875460947f382728d7097f05

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.3-cp310-cp310-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 df055cbf5fabc040c057081b6b809e2c5768e9fc5a2da4119a4d4192db1d54d8
MD5 701e175c2a5c253a89f9fedc0d1384e6
BLAKE2b-256 824b4b1cb3af254f132d2837d8e20890194ab71c4b0b111a48e0fdd8dbc28b30

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8f2ec3647889a3bc9b8c06dffc877d6c26f355655f89dd5fdead38ad72da930f
MD5 6448c47a057fe2df905fc78881cfaef8
BLAKE2b-256 b8a6e5bfe10eec859500e49e6324ab0c85d28b47930f43bb5001431662e0d7f6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.3-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a4388ba3cf652597777309c963307261d29099e5fa48706b39be87971031f958
MD5 49b30952c151e5bcc35772da6315eb10
BLAKE2b-256 84eca43dfb34672600bf96b6f3e4c93879ad235e8436346077589f83674d09d1

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