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

This version

3.1.1

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

Uploaded Python 2Python 3

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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

pytensor-3.1.1-cp313-cp313-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

File metadata

  • Download URL: pytensor-3.1.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.1.1.tar.gz
Algorithm Hash digest
SHA256 557c57e1ff36effe43c158b77f121a272b8da7323296c6a8b885861585705efe
MD5 2ddd8ac588a5531e7bea16fd966617a7
BLAKE2b-256 ccbe7e4a95947c0b0e6b575bae1eeb0c251937041da25010146a4036acb54745

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.1.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.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a99f718c5688db9d0418304c85eed1167f1f890fe6e6307ecf1085ea2ea178fb
MD5 dae03cd13ee46afb0806708ff6100606
BLAKE2b-256 909eba3dc06b7157198d544036236d6700f8672cabefd71b255cc1832059260a

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.1.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.1.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 4714ada01d94f9da84efbca193bfe7f774a15bef2e7983c8d29e84bef4a2a8c5
MD5 570497f61d83ddf01960e7545e10fc3c
BLAKE2b-256 a80af99c197223ecdf7a1a74e032ab67f5bd988ae17ef83c5a96eb7aa0389a8b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.1.1-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 cb86ed6fe0142e01d963b72f16b2bd3d737efa61d25f1696bf4476b2a399bf8e
MD5 e384030802052d1401a30b50c1ac3493
BLAKE2b-256 4078d82076fac6d2601fc8da2d21c8edbe817153bc5cd26f7155cb1e6c6b3a53

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.1.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.1.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.1.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1903ca0429e7d62f955b25b9c67c4027f7bd3d43bb2c6f1309a3c196724d90ac
MD5 0239c439c211d6b2bc84f4f967f28906
BLAKE2b-256 e161ec48170ba00f8f2cadf83ff7db135e6ed0cb350c123c2b2b63bd8bc1275d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.1.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 945ce4b51a66a40e9ceffce2fcd35493c435cfcc41845ffa693f8e93e4cd9b5a
MD5 d9754c394a8e22c25dcfefdb3e69af0d
BLAKE2b-256 f49e6403ec562454f39dd86c8ace6a18fee437faa1e13897a4cc514fc265c8fb

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.1.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 1.8 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.1.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d8d159e7e2ecfa1bff737215a8f3651c5f541e14e0f1101a9cb56e17058bcdc6
MD5 7c86a129e3d29c722869cc69cc5b009d
BLAKE2b-256 fa9db4b5feaa1648b3cb8adca80c2f25b1032dc9fe1026774a656d20b7172b1a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.1.1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c8d4adae00a360b6d43bda73baa69d0e5e6d5c4237c635e019a2b9ff24f24053
MD5 25a6fd2a10915c17ba0fba22e2f51a47
BLAKE2b-256 71f902519eab804ab2b6e1c4254f5ba2e3aa50f60ece2f24348d37103878ce78

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.1.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.1.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.1.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8c68e60fd6feb2887483063cd68b1c77258c88a94d2f1853f1dee902a2a6541d
MD5 82e4d38b57ea7849b49ca781567829b3
BLAKE2b-256 da37444ff2a33eb97f95f75e27095c0479f13d170df9479def2cde44350cc396

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.1.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 46dd33bf9840f69a90e2e21aa1b036145ccc78c6ab6af5b68e4efadc6792f79a
MD5 e87e152f6f135430304747165c00e405
BLAKE2b-256 c3465bf10b66d02f0d6b286dcd742ee9e78b2908b1d75e2b93ea240b85a27218

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.1.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.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c8d64c3e35da82efbd4cc38c2649ed87b471f59305ca897b2e756cdb32496f43
MD5 7eeef57cb1ae7e0de315d49937b23eef
BLAKE2b-256 3a5e649720faba76f79aeac9b15df9a9d9c1eb23fd63b74870737e6d882d25fe

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.1.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 718bcf8c313f45f3ae08e831f861a5d910a6d225b556214020e5026570622550
MD5 40d9f3735fb8563561684ebacb80c2c8
BLAKE2b-256 64485562d15f247074e6a0f0317c13b4daecd09e306382df702ea64575a372c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.1.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.1.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.1.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 40779737f5abb43a93c5c3fcaae1f6c4b73a983328c08d248441f54c492bf3ff
MD5 ab8ece44d41aea7523c83c7307869f46
BLAKE2b-256 9e7b2022e23a1148caa813004a69f4d3c4eeefa39e669aeb2f0c8b0071c32196

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.1.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f6840e040b81562e1151fc3dbd25388848a4174b86ac62000add57283a048b61
MD5 5c28b7ba9e1d82c64b08a0d3f5fe0aad
BLAKE2b-256 56b876add2964aae9a0c469ee38ecf09b6fd33bddae4daaa2c6528ce07279a1f

See more details on using hashes here.

Provenance

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