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

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

Uploaded Python 2Python 3

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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

File metadata

  • Download URL: pytensor-3.1.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.1.2.tar.gz
Algorithm Hash digest
SHA256 2b0eafee4a431654dc3b836bd904211e4dccf8756820ea415d46b82d2d1c26ea
MD5 54c99b5448c582720ba68985f31eb5f7
BLAKE2b-256 5ab5075a2c0d0c5545cc810839265d6d0ef74109d12b825e786aa7215c3ee2d2

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.1.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.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5ec79dd1b36d1a6401e609a37ad337dd6cc977cb7078b9cf48964dbe776cb93d
MD5 856d965bb66d7448f126f83ba9e946b7
BLAKE2b-256 c93eff65bf05813d7faab112b81bd4493aab4159886b6518e8553b15f78b0e3d

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.1.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.1.2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 533a79947a284967a7011c9200f8a8971928fdda097dbf19ebc7a8d9e5f7d7a3
MD5 a1bd69a8416e812ced08f25d1f99b712
BLAKE2b-256 71b5223c0e8eb9b851a12dddb6a42d931d8a0905ab019c3e17acb9612d924011

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.1.2-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 55905d7e229e4faf47bab7d4d1eb6ded41d6cbf51c4274e15f884435a002227b
MD5 482a2bf554c42109d6bb200589506071
BLAKE2b-256 0e77acadcc410601556c9d122dfd1a09c20d24a1067ac340da5abfd79a85b065

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.1.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.1.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.1.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5848e481bb9df27b57657f42086234abfde3d9a14baf31ed1ea508fcef1a5ec7
MD5 d60d6ae258c02f04ee24aa7516bb9b7c
BLAKE2b-256 a659c9371b906abbd58be57e28de9c4dc68c4d63bb67b1639e939932c1fd75ca

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.1.2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 05fde8ccb262330d11fea88258dea5a41d245b587558fdc900c5f0e331caddfe
MD5 ffdc613d1184f229ba53ea4f19f3da80
BLAKE2b-256 8f6fcded87adc04bd04c74acbec3434763d398b4f4cc9de18ee89840bc6f1de9

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.1.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.1.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c8523f988b683312a1ec4d5ff1594efc0a534d3a65b2eb676d35a67da65edea2
MD5 38a200d53eac1fba02e864fb68552029
BLAKE2b-256 6a260a48a5b1a8d60200082d3a06a48ad87c48c78e64b7f0435bd9b2028c9fba

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.1.2-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a71563375bd4095a16feb0499668c67b4c425766f65391840cf26572443e4589
MD5 80b36ab6c7ea4534141ad1a3020a8206
BLAKE2b-256 fd1c1061c1a82f29618455cfb0069eee74409f00d6b078e3a41ef4900836e4b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.1.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.1.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.1.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 30d48fcc8b5074c97b5decf3a1fb75011e94ccc1cff27d42889776bb111fefdf
MD5 459959a03a2621f87859d0c6ac658a43
BLAKE2b-256 4be8bb136bfe2ea896aa8676024d03b264c81b4ffc94d8de1836e8515686cb2f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.1.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f58c7bc5dbd40639b1c20ca373c40eed3893cf639a0510ad27a42d848cbc6de5
MD5 d882117b3730235afd6a0794d0e4e826
BLAKE2b-256 8a0631bf3d305cc73f88c1dfe8359cf4593bcf81d991acb9d5a58070de12f63b

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.1.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.1.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1f3e51bffb5be25ca70a33b4828a9d006678ef8bfe5c495c362068a894adb0cd
MD5 98b24bda28f11bd1b2548b9fbdbd2a3f
BLAKE2b-256 1efd7dd21f5329ed6a2c879d03e7421a027ed33e55306278265b70f65e241ec4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.1.2-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d5479ba2c25ae8876fe63df2d2180786a4c228dac3fcf1a83fb55f31969bbd79
MD5 9f7a06bace2c216e5370909cbbdc9941
BLAKE2b-256 5d88d6f002511902dcc4b474af1474180879d39a08ac5cd352f925184fb9cfd3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.1.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.1.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.1.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dead2057a875a1cdeec5f95d346ecbbaadbcb479463b582e75689965d7a19da6
MD5 eebb9ba9159e7cb0c97fc1b99a77829d
BLAKE2b-256 a23a5e2864f76508aff853fd5657cbc37ff06b3377974a12b6ffb9f5330f0a35

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.1.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 00a0d4429327ba233b8db7013ff045b0c1005475f8a1bf1e5007d1ef0913a1ff
MD5 11ddccd5cbb3280d6c053e349632cbd3
BLAKE2b-256 c0dadb3d971421973a12f30d6af02046aa23ea748cede534e2da6350cdd94950

See more details on using hashes here.

Provenance

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