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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 Windows x86-64

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

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

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

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

pytensor-2.25.2-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.2-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.2.tar.gz.

File metadata

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

File hashes

Hashes for pytensor-2.25.2.tar.gz
Algorithm Hash digest
SHA256 bf181c8c40543498991fa818450cba2b778ba19732b13b2d21882317d97ca038
MD5 1f6d1091b5253130ed32aa38b3fde269
BLAKE2b-256 a27f6779e62369bf036cb45027250790bb8fe1e8eb9f38ea10949592076e281e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ef3ef16c7b3e80008a68d34586e914129be9db1a09cd40d6a3f0588d57e3f958
MD5 f638060c77df8ce74fc1a3bc197f0126
BLAKE2b-256 a66c5a370c751864c25e1b8e979ee8342df50631de10246ab38ecf0d61b6de5a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.2-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fce0e3382c1f351b6c39ed2f098de71879ef778fc50db06f815a33ac957e2e47
MD5 2bf9e5ce46153717bc79af33039ce5d4
BLAKE2b-256 ee0cdd4bdd1c817df6e39e7291d97e0ee1f8d0f3cde3de7d7a18a8f3fc39cb7d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.2-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 e557de79fd20d6c8def70303e30e846bf4169e71dfe9700c4b5c4e8fd2a5d11b
MD5 88ea17f8579c6091b77d3d42b63413e9
BLAKE2b-256 2a574b9083209ce154d6a9eca77f7bfbca446dbbb4be6b25f0f5b3c714eb03f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 034e92036f193c408679bced4a66be79d069f4aeff63eee5fbfb1631d7663c8c
MD5 c4c0ebd97b0aea14ee1c601b72632bea
BLAKE2b-256 0b4a25c7f29e1064f1ac03945adcb353e825940e53c7cf2395b05117e95f4d74

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.2-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b082af99a2c09fb2204c2092d600793fc2466411348ddf7ec09033ba1a22cc0a
MD5 a6effb9ed6b601dbc76cd6623a20df11
BLAKE2b-256 1fa1feb32f8a5fc46a83b64e52820b7088cf8430aafd940c4ed59813cf6717d3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ba5c4759f3df4395ab536eb67753e46983cb45037f29902599da9594e2808746
MD5 f0778e99250c1d3e32285bac793be110
BLAKE2b-256 6fb14474c9a6c2ae4900b4694fb4d20d8f32757cbda29714225d50b047498f10

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.2-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7c7465bde71b69e233c9685df72c362a5d4d77afc0902603fe0ad35aafac07c5
MD5 af5aa29cce899aba0889ee6319059882
BLAKE2b-256 0e9c8b2b90ba014a74447e6ea739293c7a4fda835e40d66c6801bc48e088b6e5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.2-cp311-cp311-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 2d56a6e623a2d2893a5840f1a46b4f8d5de8db6c2181570b896b3be94cf92d52
MD5 0b857d3bf0551fa47e60bde68aa69cf4
BLAKE2b-256 a4dcc57dfda9dc128d563d202051ffb551b718644660ee2e442ed43ed67297af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 285b823d60a2a125df4bfffb4201e2bd8f0c551cbc3cb8b1b89fbc4fcc8ee99c
MD5 8147df2a90fbb371b75f691771721711
BLAKE2b-256 8b5fe126d82009e86bbd3e359572efa76fa52b5a9e56ac0e2b2abfbde55dfe98

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2b0372c7cf163751d143f2af9c286c35b0579aa038019b6708ac8a2649d70b51
MD5 48bca9e42825cb252e5a2332d68eda91
BLAKE2b-256 5423f51610e2fb22157a5c6dd42e8e9ab63c115e5da7df25dc048d4b0778e432

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d3a6840b783956aaf7ab2d6352f9b1cacd97ff4f2a877cbea060bc21237f9d4f
MD5 9ee5bab5b2c6a123eef42eb8b5af034c
BLAKE2b-256 0ef15f911e394b238d0861886f086589dbda17495997cac5508c292e832ef869

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.2-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c9bfef093723117fb24cfd9e742846cbf4428e92ecfcb089e32f2c639837054d
MD5 221699ed764e87de54f00938bd8c2ebf
BLAKE2b-256 01fe149f10119805c7daa9cd57bf5303ae8d19ff2756f55097eb8fe40a4158dd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.2-cp310-cp310-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 725fe95e1ef979c5ffde174b8bad74b9e58471b257f1d4ff5f0d97bbfbc73bf1
MD5 379d3612c0e1b1eef2e204221222d915
BLAKE2b-256 7ca4fc405ce81c8ed19886b66bfe6e987116507adc7ddb3cbc7c9c68468c1fa9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bc47007812dd0f96e90e1aa3d3344d1500953f08d81cc7d92efde54dac8c9716
MD5 dea30c02a3aaf959b6a01e3ce7b5d3eb
BLAKE2b-256 1a141c83322adb441097c6b5ec75d64d18c5eeeb366324f5d66e0fa3643758ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1973ecb30d33d09c2154ecc754219e1f05645e3d5d34cb60a3b81ce23b8773b0
MD5 ed3722ae5327c0fccc317984b07ee3fd
BLAKE2b-256 432350947619e8757c1ba7df6bd54c5a8c2804ea4181f30c6afef79bed38a821

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