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

Uploaded Python 2Python 3

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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

File metadata

  • Download URL: pytensor-3.2.2.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.2.tar.gz
Algorithm Hash digest
SHA256 e3936b58adc6f806a8d641ff4513f695e38a9d7c33a9aa6544b2353689fe3b2c
MD5 2d5bb4efcb74c407f77790f338220de7
BLAKE2b-256 4992c9a5872d4f639cf2c60576f4db0677d01a1f85885d0e315df64103d6e352

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.2.2-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.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ebe7752e29f855af3f18ab103b54af29726c45ae5a9f60f55bca515d6e878688
MD5 f677b0aa400e56411b161b8fa3377c06
BLAKE2b-256 50902584d1ffd3f9ae84aff7ce2e22e9ad4209f57898eaca55e348fe495519c2

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.2.2-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.2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 29258a7bbbaef682d4d25c86404e2a6e1b50777b0a7df823ce27b69512d09646
MD5 1b5b87f8f2e37f4e3144a37734faea54
BLAKE2b-256 8dcda79cd48e7a3dc150493aadcd56f99261fd5ef6a51bb38d7d0f79f4e8002b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.2.2-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 daf4db0d84b49ddbcdcfbd28ddd8a6930a7ccad8152f44465834f8e0db9ac783
MD5 f45faec9875ac3b4400595d34d8c1105
BLAKE2b-256 bb4f4eeddb7f1af6f2f7d9d43a7812bc9445891a032a5ab85418d3b3a7ca4286

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.2.2-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.2-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.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a236586acbf513e034407148a93e5213ce0c20a5921720a74590c3f3dc48113f
MD5 da4e36a2d726cfb81a73213002ff6baf
BLAKE2b-256 478d2a36ad72d6ada389d7eb88314fe16f5884ccd68307e64812c950cac362e2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.2.2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 860179c49c1dceb12e151df007d3c114d108eb5083bcb91e9846f17fffbbf876
MD5 af120244acd36b58707bb9ceb7700e6a
BLAKE2b-256 56f7144153eb94a1dfdf79a54705e9bc71c7308e10bc90b10954ed35a46b9186

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.2.2-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.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 0850b19a31ace04860a922b4dcf6c126de6a5a73a639f9687c1ec1f51588ae97
MD5 adb421a2cb229a6d9c526d494e875e77
BLAKE2b-256 53fb7433206fdf4f5bad234113dc85a61c463cad4397895a115d4d69576181b8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.2.2-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 80a823a018bef7e1a71b2460a80ef5bd9a0a619b3a7473aff274f7669e3aa0cc
MD5 b680591161200978d00e3e4674acf678
BLAKE2b-256 67d5f6fccc7bf67c19e69ce22884a6f61778f339e8a896d0c95a6158c4254b1d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.2.2-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.2-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.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0dec273a31cd3f976bdbdb74d92c71683dc76bb11991f097bbd3aea21d60d984
MD5 21343dbbee5e539e66514ff68c215748
BLAKE2b-256 f52247c88f52acd8b638893fa67460a0c83bef54eb9a93b997cdbb3a57b57538

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.2.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e245219eca51355f391247a228420d900c4cf5ba91d93f106578e133b87e1e77
MD5 231422af6f5da9cba420fa2d04707576
BLAKE2b-256 00b4d85014fe8e14d1220f14e80367053f0d67b6b3bf1448a074ef02e2632289

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.2.2-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.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e1bcb797725c0ac20945cdc9f43d8b6eab2925ac97a263f21b87dd29d307d6f5
MD5 7424135ddbeb2f9458c9a985044df193
BLAKE2b-256 c6d03952407b582dcbbd4512e9427b05e97213756edc41dabc4353268ca10852

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.2.2-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a92024be01e67f5e5999b40ac9dfa96f721f8b022ec80094e2da202c96fc1616
MD5 358320fe1e3817ac0a27dd3af133ea1d
BLAKE2b-256 c0b15df696774dc0e9976b6a12bbd04a9742736f16534c963c713dc1d6e8cbbc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.2.2-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.2-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.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2b49c4546d3ea19e320a405c08c6ddb01ec16ba49b93515b7a6e3aa6d37860a7
MD5 7025960dd83e54a04347ebed4e97aa4b
BLAKE2b-256 b527ace36f0ea56bade0f6894c0de8085ee549b94402706de9b2d7fe4a04be40

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.2.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 880c4792c2f9409e944c4d2db6b92a8e52010a594c47b45b6bce5a6e2f1a935e
MD5 fd8c7f8a67bcccdcbefa82cf13dcd698
BLAKE2b-256 92d1f8631f1d1eacf8c6241b0669be32d4f4a41e5b2241c7a2205e0af2520300

See more details on using hashes here.

Provenance

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