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

Uploaded Source

Built Distributions

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

Uploaded Python 2 Python 3

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

Uploaded CPython 3.12 Windows x86-64

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

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

pytensor-2.26.2-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.2-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.2-cp311-cp311-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

pytensor-2.26.2-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.2-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.2-cp310-cp310-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

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

File metadata

  • Download URL: pytensor-2.26.2.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.2.tar.gz
Algorithm Hash digest
SHA256 a0dff395dec898f04ba30c5fde9f2e3ff6a6c714827e10d9b2211b704b15da2d
MD5 aeeca5f20b2ab8ff8865be84b70cc0c4
BLAKE2b-256 3d73771d05cbdff7474e5401b99ba11c18f36068288a929b6d241735840fbbef

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: pytensor-2.26.2-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.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 49721a5f7029e1cde6a1cc81bd9bb644ff0dbb2b91c8d790d653fd13df2cedbf
MD5 ac3962f3e2604eea9ce5442020fa6eb0
BLAKE2b-256 d9399a331f8ad65351b2d556be2dd482a71ece6e5c8985f51e55d003d2b7a753

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1eafc1909f56fa2d5ad97e7d37fc7e21cc9b29161807607ad6d2cbe4afbf3a02
MD5 c3eaf382ed4b05d38bb41666730ddae4
BLAKE2b-256 4fb01194701f0fafb3e5a7a55fd64cf77500e2d00922a34c1e620764e8683afe

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.2-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b3d4700a65b75d62b73b46eeddf0caa9e4f44eab7d27ab791183a53d7c2097b7
MD5 275b395af77242687164cdac5c4c8dca
BLAKE2b-256 714253df2da403f0522915883da9acc642e11a5dbb7ac58ad83931ce1693c50b

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.2-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 39cd2deb9ee9ac1d7f342e7967237adb01b7c3977fb22ae612ebca40a9b12dbf
MD5 31f4b8f00f8b6ae7dc3cc376bf97e5c4
BLAKE2b-256 5052ce209ca6a8ad7025e822f8dcd16e80bcd552b7dd565d3ca30ef547e20593

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 804f37e0c4c7e282c580546b6ce07bd7b44ee1d14b8d139ccc8808274e1d408d
MD5 d91e88d12a2a0846f992f8309b0bbe4c
BLAKE2b-256 22dc68567a9abd57b9ce0327f80f54ebacbb04c1f982f20e77fdc7927d87b2a4

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.2-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 b3278f7cc91ba67808c3318bae89bd5b2e4e16bcf148d234c1d0cf18b61691ee
MD5 e3ad6ac8e476251335cccbfa14565645
BLAKE2b-256 6a2d9c96c8e86b910eba9e007c9042bafbadfeec1b2ff922bcdd1b143cf683b1

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c607e46050eb41a1128dbda0ad781eb860edb1f43754ba21737a95653030753f
MD5 f67fd5975d98949ced862ae9d6d195a2
BLAKE2b-256 981ed1657a0b9b68652e543ebab6ad0e949f8104495de073cf17e333920f4a90

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.2-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 000aeb7cf74cb40e499259b16ccdf2e6c3093defa30858c44ba87376fdfcbe07
MD5 56411ba26029ff7de56f887120b59c34
BLAKE2b-256 9bb7bff84876848e095fd0a761c88d5f6e0db312a6bf77e5fb372e13f3577b50

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.2-cp311-cp311-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 51c6f4c7d94607ed1159c86518267b12954bc242422aa9c3c64f498097a92c35
MD5 8ff174400568c87d972137f67e210fa6
BLAKE2b-256 4c1c3c7ad8d7ec93c228afd44cfc459a05886a33173db6692bc0e5bcc4390b31

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b8276a3c8e4f0f7944317ee2cfbb60366c1987b11b532761df249ddafbdc16ab
MD5 98959b78cf019be9a38dbafd08917347
BLAKE2b-256 3e98c59ec61a31454b7d7d978d5a7038da9b0b580b8e37e83394e6e5ed88ffc5

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a499a5fc10af4c70d15fde7ddced12996ed75b51883e1e0c5b29a64d6e79591a
MD5 1a59839e4769ec913b1e73034a9015f9
BLAKE2b-256 25a8b1d395395836f14da0670e1a568a0ef07456b9314c8b1412156cef93112c

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 923ab2d8dd4b80e3c2ae86b1c5ecef514d2f4060bfe09844b2d334f36c36df24
MD5 fa559f235c5f801031937e6e34094aa4
BLAKE2b-256 030046443b644f83bd84dd362b3d402959f4db99e44d319b7ec98a08745e0dad

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.2-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 50d77aa0c5b979d3249be4d57c58fd822c43916b0ac5228e3a2e9726936188b6
MD5 8a4a497791a4ea847e768074f5b78101
BLAKE2b-256 e84e1a7102578393484970ff31a782dd9cec5c98533e03aa0e685876162c2b1d

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.2-cp310-cp310-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 32b1cbe5e16d233616b1f1fe688faa7eca2eef94c00c8884a7821de1895e036e
MD5 c8d9bc69860c8a70529d3852daa7fa8a
BLAKE2b-256 6a9bf34c78789330bf794ab6dc98eb1c8c6cdfa9829be03a6e07796063d27850

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4b3f2edd945af8ecc009069629a3ace1e57222b400bfa6ec3ed3ed6828ef9b4c
MD5 6dc27a16613eeaffdce21bbf09777019
BLAKE2b-256 4a1b6295355da6ee0aa0db229f33c54f1a179c03507024474a2919514cfed7e0

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pytensor-2.26.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b4c2b4c4026ff1cd825bf300c930ba323ac36435607365a5f00886529daf9b6e
MD5 74b7c8924d740d6662e7d76321fc1215
BLAKE2b-256 f6a990b4e2b599155e08700fef57ec2afb455b8fa4556a8894732f06915dfc22

See more details on using hashes here.

Provenance

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