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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 Windows x86-64

pytensor-2.21.0-cp312-cp312-musllinux_1_1_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

pytensor-2.21.0-cp312-cp312-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

pytensor-2.21.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.21.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.21.0-cp311-cp311-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.11 Windows x86-64

pytensor-2.21.0-cp311-cp311-musllinux_1_1_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

pytensor-2.21.0-cp311-cp311-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

pytensor-2.21.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.21.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.21.0-cp310-cp310-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.10 Windows x86-64

pytensor-2.21.0-cp310-cp310-musllinux_1_1_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

pytensor-2.21.0-cp310-cp310-musllinux_1_1_i686.whl (1.7 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pytensor-2.21.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.21.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.21.0.tar.gz.

File metadata

  • Download URL: pytensor-2.21.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.21.0.tar.gz
Algorithm Hash digest
SHA256 3b17f47c034540fe39239b0488bb7dc5e72fbbad92765a80bcace0e51cd1c430
MD5 0640e899afadf1746533fba7eea0df6e
BLAKE2b-256 de9e0108ffc31890f56b5dd59ebe47d523179c3ef0e17a895a272b9baada35f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.21.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 260c7615f0a19f5c3f5ce3a778d799aff2b9d4001204c0783fb752eb6e3097d4
MD5 2312f0e1c87608950aa861ecb7378e3b
BLAKE2b-256 a9d60ddedd0f6817570bdd2e4cc5449acd68a71fb276eb29de52dceda3e4e2e3

See more details on using hashes here.

File details

Details for the file pytensor-2.21.0-cp312-cp312-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.21.0-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 041921d8059718b5ef9b1c784d79315a1cb85f3a8e98217d26dd9c07ba8c2a82
MD5 e4bbd952815aa9b6c1711e47af7e7e06
BLAKE2b-256 6cbcbab7089fcbf4d2c405a9be8c4d32ec2d6e2683fb893a66a15aaf3d481fe0

See more details on using hashes here.

File details

Details for the file pytensor-2.21.0-cp312-cp312-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.21.0-cp312-cp312-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 d08e30928e80dab5b7f5d3562784d55ce4bf62f8536c3183ef2adeedeb959b54
MD5 5f4fe9af678f276f95d8917a00dabc92
BLAKE2b-256 1cfa36f9cbc380bcd43086d5e8469742ce274191a33e29064d24126df2ef801b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.21.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ecee4d2f78a0f9c02f8879ec86a69907a5bf5ba78c4b237057ca49cd572da823
MD5 0445d1e42311208444e6ee4840d84efb
BLAKE2b-256 a0622c338e2bf233952d5383794cb23ee5f2f6412ea4ef47ba3c38089eb552f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.21.0-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8a0b20a94528b3d39091373dfefb620347ec50289e2116a5068740cf71ea0e8f
MD5 f44c28ea8969b4e760bec7150765b63e
BLAKE2b-256 b1388661e6c824fa96497d1f2e2f2bad7f50627bc46bc4073a783d05350d6f96

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.21.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 2b0ea49dc19386e6d12d88ec877ce90e5d735e1a100db49b9ec4ffb8e9d75ef0
MD5 d00c474fbab9543a04a3946d82e05127
BLAKE2b-256 dfe1c7f9c1280683a1c8334f94305aa0a28dedb22e61675ecf2b44cd75eabf4c

See more details on using hashes here.

File details

Details for the file pytensor-2.21.0-cp311-cp311-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.21.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 bd2530b9af43debeddcea1c53c7f5840368991f9182030ffe57d9f6c1e32a058
MD5 3b115a205cf539f9b12e3d6870937453
BLAKE2b-256 3e7c8840182c2429455f619e84b56951aa06c91e27d71355c5f805c99231d195

See more details on using hashes here.

File details

Details for the file pytensor-2.21.0-cp311-cp311-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.21.0-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 468ee2b63601d9680c3dbafb6dc35ee4453dea2ba79e3375d433285f53ccaa5c
MD5 65d3d11590fa5fd525db3dd46ec1acf8
BLAKE2b-256 240833445547e14039d6d0b5519bfff79d0ca9e516d52677ab721d14d56a586f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.21.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0523c37f314bcf2111d27f8201696dc63b6dd6542766ebf77aa295a1876cd863
MD5 48ac4ad58f97936694e143b915bcc478
BLAKE2b-256 aca7a80301b8aa521a1ff7caab3b776399bcb438c497f47c7cbf9551b14dffa3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.21.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 db630265336f026a096f2834b2b24fb22a52d9134f9966993933f08fdebaa5af
MD5 a85b86bd0a6b440a8f2bcff0940dd3d3
BLAKE2b-256 70fa623934884d04d722e12f5c4dde4b44e875f19c38fa2d97cd5f6d74db00b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.21.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 54cc6f8b8ddee380779bdb7f62d90c785bfe267f6f87b1107e486a46649849e0
MD5 0c5644f4a505e3b901c305a71f0ebcc8
BLAKE2b-256 79c51af5470fcf3a08575cbefde6822ef7403e8555dfec7fb39a2ff948862d38

See more details on using hashes here.

File details

Details for the file pytensor-2.21.0-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.21.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 1af4c587b34d49c968aa386389dded31b6e622caff51195270cf2718999eca8a
MD5 6bcf3f0dd7825d6420d406ef1fb54a95
BLAKE2b-256 bbe9e96825c9317779a0f919a92603b790b3b2b963150adf0ee0299b3480cf98

See more details on using hashes here.

File details

Details for the file pytensor-2.21.0-cp310-cp310-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.21.0-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 41b94a5132ee0c2f18121c539cff16e47101960acc324ec69a21a5dcb42d58aa
MD5 86407a2370476b36f1cafaf4e4e60ae1
BLAKE2b-256 8304b426a81605b6d3fe1fddc9a9db55b083b6cd29f579f84ccf7b236c84a726

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.21.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5504b89085e252683c498ef183644e550fe889978761501280ccbe9ed428d0ed
MD5 c9ab66e7c84eacde3743f02f1f0aa0f4
BLAKE2b-256 c8d96804cf15e0d2f244322f9c7d457ab83c7cd8516fd082a60c83fc6f8746a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.21.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1e964ce53704f22d4a43eb6efe5313b87e6b7242aa21019e464bd33fd3615ea2
MD5 527b551a673c6721e5cd698bf3bdca31
BLAKE2b-256 9ac99ff14b7f0b8d4c94ac4a1047e5d319169aea4264878415d8b1a96b7f18d7

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