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.26.1.tar.gz (3.6 MB view details)

Uploaded Source

Built Distributions

pytensor-2.26.1-py2.py3-none-any.whl (1.2 MB view details)

Uploaded Python 2 Python 3

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

Uploaded CPython 3.12 Windows x86-64

pytensor-2.26.1-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.26.1-cp312-cp312-musllinux_1_2_i686.whl (2.0 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

pytensor-2.26.1-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.26.1-cp312-cp312-macosx_10_13_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12 macOS 10.13+ x86-64

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

Uploaded CPython 3.11 Windows x86-64

pytensor-2.26.1-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.26.1-cp311-cp311-musllinux_1_2_i686.whl (2.0 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

pytensor-2.26.1-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.26.1-cp311-cp311-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

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

Uploaded CPython 3.10 Windows x86-64

pytensor-2.26.1-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.26.1-cp310-cp310-musllinux_1_2_i686.whl (1.8 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

pytensor-2.26.1-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.26.1-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.26.1.tar.gz.

File metadata

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

File hashes

Hashes for pytensor-2.26.1.tar.gz
Algorithm Hash digest
SHA256 c5760e856eef9f4993088da4e8fad509ad8bad82e82bbf98efb1c3212bfd8bf8
MD5 a7abc2f7660155a3f58e4bf2b71b54cb
BLAKE2b-256 c263fbcca6f12660f3c16c24bb87b849e1a93f7774849bf3a3e973bbbe173fc7

See more details on using hashes here.

File details

Details for the file pytensor-2.26.1-py2.py3-none-any.whl.

File metadata

  • Download URL: pytensor-2.26.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pytensor-2.26.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 043c6e667e7461fbf696c2a1f1d1b0361c31811c383ed804a1e7b510bf758518
MD5 4d1c1f6397dcfb065c465fbabf204a67
BLAKE2b-256 c63945ca8d43600a787aff4ca2909c51e3b3e3776e88240dee59c4b3be7884bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 963b57e49e1d9b356634fc4b7b2db080443c23779fc0a1605f68ddf096f00977
MD5 5c45792920b4064cc162320ca6839ab5
BLAKE2b-256 960f987dd94aa88ade3b4e7a0e799cf0c3d063ca1d2ca3468daf1497f525b365

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e0f388164706fe28c00a237367f18d63e2da725f94a748754f22375d261765d5
MD5 fb51e453523a2088b11835cd13cbf963
BLAKE2b-256 4f28aa03efd08a87dafac160ad52ff7bdec1eea172b626213aaa29c65efa2dcb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.1-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 346c304a7b6d5a2b67a612e7cb78b97a255ed57e43e7af556fdecb58db6a2c6e
MD5 2ebefb10f99d7d2ab8940e11623e64e0
BLAKE2b-256 750266e9f9e9b380b99625cf5fd495c88fa943e17a53e80fa9c296ee3d6426b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6d09324d50685cf62f7c5fcab7a47590bf5391056d0c2a3feea623c21dd1c1b2
MD5 eaf576f099b8194839bbfd7111e38b2e
BLAKE2b-256 7d61344d56567273a4d893efae1062db2e2f8fce94d68b255e382b7aec6cafa1

See more details on using hashes here.

File details

Details for the file pytensor-2.26.1-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.26.1-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 51bfe7ebeba8e8cd0b0fc0acadc8dee9e09749a5b55e0be102cea61470b08860
MD5 1904e51cf769e291bc5f79cc02451929
BLAKE2b-256 4901bbd01ed87326b8796b8f47a5111eb98570e46c382343b11cf1b65ba8232e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 205c1d67a60f894db7b829397c35e901113ea3bfea4d6c746c0456bfc0c5a5bd
MD5 9f50cd150a93780fe7138d449acd12b3
BLAKE2b-256 dbb94d60e96d92b57aa55bdef91cf39170c42d3a0c53808847f22056f70c7494

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5007baf4dce4e7857186549dbdf77552a19d28a2dc947feb859eb841885840b0
MD5 b8aa52954a710085c012ccaa62ebe0dc
BLAKE2b-256 f8a35f790a43a901f2829c08746cc919bc024fa384430f0b26f1ae5b2c378d06

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.1-cp311-cp311-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 989a7b6bfc5c087608aa9666f1e5ee001c0f3fed82c8f7438b44436dc8f9199c
MD5 bfcf53ffd7861b970cf171cbb4d8a44b
BLAKE2b-256 d9b0395e81cabd6320467b3bc9e6b478cba32af9534e0e459cad0682f8a2f956

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 95418a84fa2736de995d37ee7e4040c401d0d7d917287ec90a722e09eda1b7f2
MD5 394278342bbb249924c831a7206e632b
BLAKE2b-256 d5bcebcdad0158dd0f87c2cab74e3ece7e3d9ea9fde53b800cd7698a23e62003

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8afcb5aa25c9a68d36f60c656a84eaf9310e3c5c5ede76e0aaf8c5c16cda2f44
MD5 41a29a1e5c2d322cdbe484da2d8771a5
BLAKE2b-256 4e5476fcd31bf87cb8daa7408fcf5063936ff491d6770719a1388f2a854baa3b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2a589d70e3211085c46d198c3a3e79db5d44aad9e0c1c3aeeb8b6d11c48c226a
MD5 40896e3c76619bb11a2d22f75da70c70
BLAKE2b-256 a1a3551aca21683999ec4ef84e52fac131d6ce231a64aef1d37af1ae54c73b51

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.1-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 317a5b06450dd5b0a848a266528152deda7a47ffba525d4f0084a4baaba0a0da
MD5 bf40af6169847a7b045d17fa1d7997d1
BLAKE2b-256 5a87e76dcf70cd35e084ceab0e3c9df1ebb452ae0749560f29c1e082527735d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.1-cp310-cp310-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 02ef2e735a632fa7b8cb9ddc5cf6fefa484e3f57277f859bab0a49122b6929b4
MD5 b9b8208a485665e1112f4f937f673659
BLAKE2b-256 d72526ac8d4f88f0389ed8baed5e775b6732defe49704384102db3180b6c1603

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7fe7a1a82083d2ba920d174c4f89ed58e2f1151bdfc5fe5c4e1bb49ca552cad1
MD5 3e4ad426f04f5769ff5b1c1643d7ce08
BLAKE2b-256 a82836b081194eb1c2428f58dc6e50f010599d8dddb0a84e4d3d3ebb45b1cf58

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a419880c4f9747bf15497f24019951815234593bf71dff49aee34fa769d511e0
MD5 2e4bb4a12bff61007e6095671307086b
BLAKE2b-256 2a7b25b536959ee13a230d475a911f7db5fbea14b21190d7f5e59309411a3fdc

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