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

Uploaded Python 2Python 3

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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

pytensor-3.2.1-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.1-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.1-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.1.tar.gz.

File metadata

  • Download URL: pytensor-3.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 6c6a86bc28641c21c65d6a54043eee6173feef75069c54dd8a1c702aebe78e19
MD5 5dc86e6f9be8642778f3922bb015536d
BLAKE2b-256 0543a6fab015edd5f04ab8e33211b4e4edb6f78428b54b2f0b108aa36eb26208

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.2.1-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.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9825c06ad3083b239eb4bea0e13883ac033fe934622b76ae61307679cdff85bb
MD5 95950afd26e71e4afbf13a8cf8bd18ee
BLAKE2b-256 1666b0b174ce52e2e2e44d5d620d2cbb07954c33ca4704900ee86e2ebbf43ace

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.2.1-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.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 4c4d711d57ad080a99a7837a616a5271df9d0c07cd174272d00bd3ef3cac5260
MD5 f5391fb11dc3e49afd5abc461e1b6241
BLAKE2b-256 f85cbbbd41a78cad7ed1a6181e6a1b8b1abc99d36ed85c25c6bc23cf130c9d5e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.2.1-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 14a17675e6547d8ec5810f90c955473a0c974977ce7e3ba890a5a02525309558
MD5 3d51d001a890ae272838d84091357453
BLAKE2b-256 b6772ebd41635e00beac1d69d1edc102f8a30f74967c7afa26ee11862f6ca867

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.2.1-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.1-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.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 45fa42509f1d0409a308824a1481f53bd6df127e546a81a4346dc88feb715510
MD5 02824803c3ea7bfed8b269f7e896ee97
BLAKE2b-256 0ba1d659092a2fae1c5c60be08b2d8f8a235339806340e0e1dd0bd64fff15c96

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.2.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 557fd883bb260690151a0582ca2f27b4fb64d5c2bf70e0530c12d99986e2a806
MD5 a2430fc724aaa36f8851934c13801f4d
BLAKE2b-256 da076ca20fdb65595a299e66f63ba557f605c3fa89d9a478ad5bb4f6d07d7362

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.2.1-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.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 9fb6b3a1baac70fe2941d9669652bcfe5e6c7708b423a01b659e51e919897581
MD5 d64e2d1a85a720d621c0452766075293
BLAKE2b-256 3cd308acc001895684921eb616b1cb5cedec15a319f5b1960be472f7c46ce358

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.2.1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4252d12c87da050b746bbb650810bdfe82fbbf4ae43a889aaed66db64ad8148a
MD5 284c761d978cf9ae51efc4bdf5396a9e
BLAKE2b-256 e8cc6861db31e7723a448b64ef3675134ad7c9b5f9981ca926982fdaaffb7f83

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.2.1-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.1-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.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 24ab1bd7b16abbd2876d475af19f45650ee80c12efda137bcd5a6cc491fd5b11
MD5 c23b8df20adaa5570ceb79f641be1c6a
BLAKE2b-256 f143f6bacb10399b43dde38e8e74e9fbc466ba47bffa5ef4d1722a54ace85ccc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.2.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b1cbcf6bcc65836898e7a0e45fe41a2d5a772a5a7e4be067d11355d710dce773
MD5 fd58ae299df6f06e89aefa762a19bab9
BLAKE2b-256 e9650650c7e552a1b543364c127b3f6b2c70e1f493d2acbcdff71a4ce059df3d

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.2.1-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.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 300705c1771246f307dab10dd553bbc8ea5a0191dde63a6d2fd09a96663a27ba
MD5 22de4d35371572fed5ffdd8cb6b79918
BLAKE2b-256 7e5c4766218fe4b956bf98139e749fc315316e322b87781a8d357b4d605b1d90

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.2.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2126d35a15dd14f1427e433dcea559dd0d3435ebcd52392ff3430fff08588067
MD5 32098f0a3e0432c929e604d7614591a1
BLAKE2b-256 051a900d679d3f179b2954313ff056e80218d141a8ad8f95dbefcd1c90f9c373

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.2.1-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.1-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.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 70548a5ff93821ddae9646793358874114073bc20a59296d9854fc51bf3d4ae4
MD5 651c597fc9a0805e8fa9941afe3ef452
BLAKE2b-256 b31f0a835c8d5668b9abbaf5ed29ca6c1bcab855de8116fe0531bf9722951972

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.2.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 938f0d642ea1679c0588686090516144db39b6f4c528e322dcd330779103a6fc
MD5 d0f82536464d001ee4e0831f035dc887
BLAKE2b-256 59c20cc0e96e89d26766c60c03141f17681b25cca8c79e4a40bac699b19aff45

See more details on using hashes here.

Provenance

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