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.0.0

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.0.0.tar.gz (4.9 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.0.0-py2.py3-none-any.whl (1.4 MB view details)

Uploaded Python 2Python 3

pytensor-3.0.0-cp314-cp314-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.14Windows x86-64

pytensor-3.0.0-cp314-cp314-musllinux_1_2_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

pytensor-3.0.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pytensor-3.0.0-cp314-cp314-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pytensor-3.0.0-cp313-cp313-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.13Windows x86-64

pytensor-3.0.0-cp313-cp313-musllinux_1_2_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

pytensor-3.0.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pytensor-3.0.0-cp313-cp313-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

pytensor-3.0.0-cp312-cp312-musllinux_1_2_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

pytensor-3.0.0-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.0.0-cp312-cp312-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pytensor-3.0.0-cp311-cp311-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.11Windows x86-64

pytensor-3.0.0-cp311-cp311-musllinux_1_2_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

pytensor-3.0.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pytensor-3.0.0-cp311-cp311-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file pytensor-3.0.0.tar.gz.

File metadata

  • Download URL: pytensor-3.0.0.tar.gz
  • Upload date:
  • Size: 4.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytensor-3.0.0.tar.gz
Algorithm Hash digest
SHA256 7efe6656fe6644ea67420109c5204a4f84726eb354ae2f3312d4859224827203
MD5 b1827c333fe3db2b9976f70f1e8d02f0
BLAKE2b-256 52800ef93f2d29a1ddd06ff0905a598f420c8273e35b87db599d84976d71b108

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytensor-3.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a3598164d6c785671e60d574e0f7adf8ccf821f94e8cbf1276931295b1b39f34
MD5 1b5d55248cd43e1d473fdcc18e3496c6
BLAKE2b-256 48f706a397a97dd1c91dd2b9698e1de4dc5cef723a79f0894c2c1ebf84ab3e1f

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytensor-3.0.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 ef0e945e946dd42cc0ba627e55d0525cdfc8b8fbb14aecbadd636f39d8aba131
MD5 19c89f79c6241df1cdc4e75d42324c29
BLAKE2b-256 b14097c31396ef4d85b9caab1e222eaa4b18873b7a626c5f3aef12e0f8d471fa

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.0-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5b764877f18334dfbccd460b182c13fa4ae2e59489caffd1e0e430298bb18320
MD5 147932de0a0b87076c2d39b55e08b410
BLAKE2b-256 b8877416ea105e1605be1bc6825e6939de569450358e11c143e779e2b5c2a7e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.0-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.0.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-3.0.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 00fe8071eee66a2d64f575e0b5849cf97210cb0002e391fc07b5b6a02017139c
MD5 0d4c798f48db68a87991f11ff4a65c4e
BLAKE2b-256 e6f0806847c7ab435cd9b8ff1b0fb13946b0612ff3382df3493a186e29ec54b9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9cc5b7f15bbffefdb39fbbf86d15624e3b38a2d704be48bcc0fe07e8d44fd038
MD5 111de27d14cb23b0d0ceba537b167862
BLAKE2b-256 5651e2a8718416f571340554b37d2cf919c759a589311afe0611bd751dd90c22

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytensor-3.0.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e7e5c6c1d39eaf62dc1ce61e087e3c85fe7b1d40fbf64155fbd3f8a20e0620bd
MD5 6a078d30f80cbc093e91720d0a2286c8
BLAKE2b-256 6d77cbdd4cf86945e03caf6c047b33a91159dcdf1a03e5396c0a6ed088f40933

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5f0b2c30a64a9e67833c46165fb76f18a3d17dffad161df58559fff6db68e142
MD5 ea8824e53022f8e18c5bb3cdbe3da2a9
BLAKE2b-256 6d072c802f52428ac140febd5c686b2c91a2fa6d7789ec7bcafb53fd26c99cb2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.0-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.0.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-3.0.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 508201a290bc21be22a094238bf86ce832938dd7363d4670b757aae932deed15
MD5 f57e308c3ae66ac727567ab948d692f0
BLAKE2b-256 d0fbf6c8598f5d56567a573c3ad80f0c1e1f0b22cc5ad1de44d025b5fd2bb644

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1c9a6921388b04455870e27cf125c040a7cfb7e7c7ce6d35262b7fd8736386cd
MD5 1aceac44815db8d291d8b2b6e226252f
BLAKE2b-256 c07947d026f19b19649266924dee204c441b48863bfa6b13cc4948a1a669f14f

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.0-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.7

File hashes

Hashes for pytensor-3.0.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 33080a90e3e7a9d23ce42141204350673cf0f7f9447caeaf20408dd53880d992
MD5 64a5fe7932c8970b3e970328283a63b4
BLAKE2b-256 8d8e901dc2ea503f9e2434af1e8967153eec70f3567128b0b591356f098888f4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 196c3ba0ccf1a54815785ff271988d86eed7ab8633f3714e5370e9780548e622
MD5 e29ec4065380441a2c4c10d5be9aba71
BLAKE2b-256 d960927430f5419fb6fa3ca4ecd4c4d4f21a4bd38cd345dd688f4928328685e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.0-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.0.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-3.0.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d5c0f267edbca1e94f6ef1e803b77e2b12aaff195bb8d47e92d75404b25684f3
MD5 35510c7e353dad47590bac1888bdf30d
BLAKE2b-256 09ba842b82a84f685c5c910ddcf2f61b0a70e7170efe5acbd7088a0d89487057

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ffa166e92047b407a71d71baa3834a94fc1937d9714d0607856a9508e03b9ec3
MD5 c913a7e2e9754ebd8f66c0a339240633
BLAKE2b-256 f8535e7cc266c9dd6191f8f5a4a2043eed539e224163c77a35c6c0b197219e67

See more details on using hashes here.

Provenance

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

File details

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

File metadata

  • Download URL: pytensor-3.0.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytensor-3.0.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9957eb5b549e6cb78b5369cc583d6c0a17eac7d2529315bdfb691f11061ae82d
MD5 e373a24f9d21ac736ad7b1c143e3ffcb
BLAKE2b-256 21e062487af7be62423d1a26c4634ea83e761c34b991571a0da8a99e7b65366b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.0-cp311-cp311-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.0.0-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-3.0.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f6817318fd2cf1d76ced755179bbf103597d1687622601d1ff42bd3ee01d40c3
MD5 62675fced2efc10f4e2c4e35d4c2e475
BLAKE2b-256 f50eaf85709c7be66d1a7883bb10ea896453838ea6b67c23c522a8f8fbdfc90d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.0-cp311-cp311-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.0.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-3.0.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 44d616789ff1b019ea147d08d38b80455f26747c1afef0595e089d4a4627f750
MD5 a6c0f429631afe6b0ec21acc1aff87db
BLAKE2b-256 d3d607f358f96e9da81352671946e76c19cf57ffe96a5fd2807b7e7b7b219f34

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.0-cp311-cp311-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.0.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pytensor-3.0.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 099590c7af2be933af2358189c627ffd319dec175809e5dc9b69282034775d9c
MD5 d138de80cecc700576df9062dc411ae9
BLAKE2b-256 530ec145c378becd06a3c1866f5a794f8fc43b51d6cc74260a0c3afb298cbc42

See more details on using hashes here.

Provenance

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