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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytensor-2.22.0.tar.gz (3.6 MB view details)

Uploaded Source

Built Distributions

pytensor-2.22.0-cp312-cp312-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.12 Windows x86-64

pytensor-2.22.0-cp312-cp312-musllinux_1_2_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

pytensor-2.22.0-cp312-cp312-musllinux_1_2_i686.whl (2.0 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

pytensor-2.22.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

pytensor-2.22.0-cp312-cp312-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12 macOS 10.9+ x86-64

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

Uploaded CPython 3.11 Windows x86-64

pytensor-2.22.0-cp311-cp311-musllinux_1_2_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

pytensor-2.22.0-cp311-cp311-musllinux_1_2_i686.whl (2.0 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

pytensor-2.22.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pytensor-2.22.0-cp311-cp311-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pytensor-2.22.0-cp310-cp310-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.10 Windows x86-64

pytensor-2.22.0-cp310-cp310-musllinux_1_2_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

pytensor-2.22.0-cp310-cp310-musllinux_1_2_i686.whl (1.7 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

pytensor-2.22.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pytensor-2.22.0-cp310-cp310-macosx_10_9_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pytensor-2.22.0.tar.gz
  • Upload date:
  • Size: 3.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for pytensor-2.22.0.tar.gz
Algorithm Hash digest
SHA256 d39c15dd75ca2b560a72849372e0d731fb5f7b10b139c1de112cf0ea2183078a
MD5 2ae5a029d0e9c92867076aa9ff7611fe
BLAKE2b-256 a10e98960954350ed4b6dcaeaa781c8dfd27568a03141998db76ed51cb44ae72

See more details on using hashes here.

File details

Details for the file pytensor-2.22.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for pytensor-2.22.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9fb476f1ac892791f5cf5e21ca3f37992da73db55f241ad256cd69c4de42cf77
MD5 9ef00a4d58f241ed56612984b13c18c5
BLAKE2b-256 d4e815020464e4cfa28d8eb6648a6e79e151a82a1ab3bcb724c42dc3c01a7e01

See more details on using hashes here.

File details

Details for the file pytensor-2.22.0-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.22.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 21e6941fed937b127ee498be4e11dc765b30b5dd561bb6336239e7c0297016b9
MD5 20da16acc3cc7fb7c1d47f13258fcaa4
BLAKE2b-256 cb0066c295604a3599644972b43f9b233b72b9de9bc852ad0860d6083ffe9028

See more details on using hashes here.

File details

Details for the file pytensor-2.22.0-cp312-cp312-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.22.0-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 e9f21ba13a5f77255fcb3896c5503ee25fa0c5227168f69d14b948fc838149b3
MD5 0a9bd8972e35236ba89f9d19e83b7ad1
BLAKE2b-256 de4074809536309ca41ce276f5a248f1466dd7cd06f4028843aa23037c811115

See more details on using hashes here.

File details

Details for the file pytensor-2.22.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.22.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 05cfc718bbf375d44fcba56a2d23d75e4582a880cc079c6007030778745818ca
MD5 36dd68f8f40b54d6977f5344e1db8d47
BLAKE2b-256 ea5396feb5925ab6dff35a98195ca39a65c88c5cce7b5cf36bf267299b6eddd9

See more details on using hashes here.

File details

Details for the file pytensor-2.22.0-cp312-cp312-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.22.0-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 749163855b33aa1a83d1579784ee5228b1f24dd268e5909e539bfd19d40b7f6c
MD5 291c3b29b17925c5f37c6f0c70db17cc
BLAKE2b-256 01c147a3884ea6683ab30c3078cfa538e0f757deb6cc063088717c43390c2632

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.22.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7b2d476a63faa996ee608e5f60308df67ba357388bce57ca577f44462d29cfe3
MD5 7808dd2761ef3eb52f995f3053f92a97
BLAKE2b-256 bf7249e486c0ddc1f6466e3093cbd42d094d8ee18a2e94922fdfbe273bf441d0

See more details on using hashes here.

File details

Details for the file pytensor-2.22.0-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.22.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 20cb42eb0433eaaae62013d5695fa2b06f85a631418938b3aa58ae0cde92393c
MD5 cd2d4366de556c9b8883e5216d9659b9
BLAKE2b-256 ac01d00e9793ca3adb44ffb190d66b8da05731790997c45c75f2431e78d7188d

See more details on using hashes here.

File details

Details for the file pytensor-2.22.0-cp311-cp311-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.22.0-cp311-cp311-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 0a3b4142034642760e899f2f28f4166f751016c885d06ac67ef00a7dd648ba2e
MD5 b26ada1491511f5379cd76e691760591
BLAKE2b-256 48f048aa8310e2578d780fd19db9342b65822f67c1461ad982bab153892e16cf

See more details on using hashes here.

File details

Details for the file pytensor-2.22.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.22.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 60dd0a4ca272b062903a5a7e8d1d4437a78c6966a19179352f27538fd22d7ba4
MD5 ef475a9c3fce5e3c1a8fcaf06d6e10ed
BLAKE2b-256 ba6df3c40fec4bf065bd432a44c5a4d9b11236648d562e79409b44c12321088f

See more details on using hashes here.

File details

Details for the file pytensor-2.22.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.22.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9d0fcd7a27487f4ee83d3ac3eea4918a41dc82a9f2cbaef7a248aea559a95922
MD5 af96d51779232119819339282279bb72
BLAKE2b-256 9009432d5581dce4288579aa8f5da22fde7e6c3e48478d023f45cf3e6187b37b

See more details on using hashes here.

File details

Details for the file pytensor-2.22.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for pytensor-2.22.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b509354cb70814a17335ddde2a52ff19c5aed7541124ab22762dbc2a64338d41
MD5 d84901830b437eb2440af8fe3b15afd9
BLAKE2b-256 90f6d9f73b3658ec45c3debb6beff0b8daa275dff1cac734862de528147bc477

See more details on using hashes here.

File details

Details for the file pytensor-2.22.0-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.22.0-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 40e0c7f78ee28823e631a9542d21e14bb11172ad557a909776f38ffb53d3b10d
MD5 b699df684b518f2d9b4c12bcedf23639
BLAKE2b-256 aa5c87f99ddd6221f9076bf44e79d28c8acc466ce913442c4d813501dd48ba83

See more details on using hashes here.

File details

Details for the file pytensor-2.22.0-cp310-cp310-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.22.0-cp310-cp310-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 a9ecce189189d0d6660efb9947b6698a09455243ea41ede8f9fac14ef78f6061
MD5 3d403237eda3ce96e9cabc38dbe9fbf5
BLAKE2b-256 63875a30e456410afe600a90319cf4641381492e2ef6fb50954fa94af1eb5604

See more details on using hashes here.

File details

Details for the file pytensor-2.22.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.22.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a01e10144bed623351cb84c95d2cc7d6ea4183932609c5024e7dc1ae38305d7a
MD5 e453346cc2f1843cba1339ff50db3ebd
BLAKE2b-256 35f19d90435ce30fb05c53b9bcc22b08cd2913c4958f06683027a46574329d89

See more details on using hashes here.

File details

Details for the file pytensor-2.22.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.22.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 050171c245cb53ea3deca9f15bd35ae9d60452bacbe96c11719ebe409693b69f
MD5 1130eac48a8499cf5638e9b848a175ae
BLAKE2b-256 9e2413a71cdb5b049f7028f2e9b43337f47d520edf5e6d59bc2935eb1c74dfc1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page