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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 Windows x86-64

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

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

pytensor-2.24.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.24.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.24.0-cp311-cp311-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

pytensor-2.24.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.24.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.24.0-cp310-cp310-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

pytensor-2.24.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.24.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.24.0.tar.gz.

File metadata

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

File hashes

Hashes for pytensor-2.24.0.tar.gz
Algorithm Hash digest
SHA256 b5834e49008d719b1f9968d7b09e8cb3e38dc19a0be8d7c27943560eabec0a66
MD5 23bd26e5e91389d94ddd81b30a450674
BLAKE2b-256 378bbc027c0e2c01b315b58f2ffe250d783456c926f65ccf8663b8447b528001

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 97b3e4ed0e8eb129828bdb3b463a64610f3850ff7f8070ec9161b47ae9f9cf7e
MD5 823fb4418ed836186d83c711938e2d4f
BLAKE2b-256 cdba1e4ab187587f6176563a24e4eb8b6a57821710bead9dd3899c0848198108

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1613c5d870fff3f561746d6e4c0d4afdd098a9ff33f7a2a34186bc3d40a54776
MD5 0e00c1d34f5791e375d6d4e7a6b93365
BLAKE2b-256 e91fce580e617fb655808d7a2815eb33846bdb6f01ae4fa14fcca8d454c531b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.0-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 5c293fc55cce54dc316cceff0724e61c579137cb72e2a2a7aa93bf265b0ef5cf
MD5 451abbcf756289cdac8525f52e2a1f6d
BLAKE2b-256 3fa72d2d4ad948e3938d0ebfb2bdf5b246c6f5293525323bb5172b9f097b1f08

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e2215c6b0f92431f56762b761eae52817524409f1a2063b544e12ff3c5159d43
MD5 79bc0e4db47b0a2b10af7f467bf0e83c
BLAKE2b-256 be814585cea20ac7a1c8d5e9a7a89d2e35763bcfa1cb07429bab809b2c0e6e69

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.0-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f9408b4db791f4a9147e1a31e384062c5cbafdaa045e650e9edb93c7d4a2e3d1
MD5 88b92928d2ed6b0435ab6b494bd26c31
BLAKE2b-256 a3ec1eb86cc913b66b54b5a1243f4eecf1cad21176ba7b49c03a609fb5c34335

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1774d060cf637434e992fc32425d12845b226f6d30bd141cc05b2e5ff3e29ca2
MD5 2583b330cf79f3d7b479f5ca96bbd8bd
BLAKE2b-256 0ed0f54d77a079a5494575e6db8ad1a97ead2cb1698ac0131249899f2eb621e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 eeab38915ba5f4fad5e5c9f5a48780e14e6ff3005db1205134437e40ba911613
MD5 859309b0659d857b1ca7c9e3ad1d2d79
BLAKE2b-256 6596b7cda480138bd1e11e53a4ed9da0390b146714d08644684dc7af33eabdbb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.0-cp311-cp311-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 66e99e536efccd55efeb50fabf69c3d218b62b84f01d96e4cdb9016a63d61ef1
MD5 84bd19e2d10b700394c3ab52ce09ba8a
BLAKE2b-256 9b84a2b46f29a0ccd281d732af3a44aaafa772d9c3fe2e7cf8ad93284aa77177

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 68eb3ed066501ce704054b41e7219db3fdda36e2a32073593f8ff7e40b3165c5
MD5 990a27b7a70a93a4fcde55de57453ea1
BLAKE2b-256 83b1135a0ff0fe28d4e41bf59edf454629cb2b236f5b295a1495c496d32563f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ae4e7206013c2d06c4fc950cf890236ea6469cf046965b7f8fc9974851fecb90
MD5 bef25314e07785eeb796918531fdea62
BLAKE2b-256 1c9e63d0b9671308984d74e041ff2c792f0cec086c07e967b5e8e04a9a544173

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ed1097d723cda202d989916b003b7149b4f27f84106cb4edf9ee9b83663ab8aa
MD5 caddcd9f7fedf3834de3b197fcf4d616
BLAKE2b-256 1a5b203ab99a997807d061a83b96dc42bc2b98b3be7380698df95c6e56c668e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.0-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2af84ecb96f1c34167b8851b076768c01ac08f1e747e0c65a52092da0f2f76c2
MD5 b683c713955640822f399d7a03001926
BLAKE2b-256 5fb5c1530de415ec935b2382a17a2a4a69f66aa1bd0065204e33a006d23530bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.0-cp310-cp310-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 8811b8d0103f381f6810a8c7e2c59a7dac98e36b2cfdecf9aaadf11f6b5cfb95
MD5 6371c2e3ee0c811ca5e8dec603e1089c
BLAKE2b-256 7eb5863d5326cd5b8fdfea34843956cace692c309b5a9c0095a6e0b5b6f58509

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6712a73dae4bf3e668d01b79cf0282830f09406e119ddaf6aed23e04ec4821bb
MD5 b1c35e06846f9530af94c0dc0c9cd4ed
BLAKE2b-256 db87d138936fb5d3613c72a27f75ac5722cb90b7956834d0989056e3021509b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 525eb6404d008e8bdbc697643549849b941df8b23e64856870cf50c99fb5390f
MD5 765560c74a925149ccce4e7d86bb8f4e
BLAKE2b-256 978e14f797b5e90a47d6b6ae76519fe55c0926a1c05e0f471b101d85aff72caf

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