Skip to main content

Optimizing compiler for evaluating mathematical expressions on CPUs and GPUs.

Project description

PyTensor logo

Tests Status Coverage

PyTensor is a fork of Aesara – a Python library that allows one to define, optimize, and efficiently evaluate mathematical expressions involving multi-dimensional arrays.

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

  • Based on one of the most widely-used Python tensor libraries: Theano

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

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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.11 Windows x86-64

pytensor-2.18.3-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.18.3-cp311-cp311-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.11 macOS 10.9+ x86-64

pytensor-2.18.3-cp310-cp310-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.10 Windows x86-64

pytensor-2.18.3-cp310-cp310-musllinux_1_1_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

pytensor-2.18.3-cp310-cp310-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pytensor-2.18.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pytensor-2.18.3-cp310-cp310-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pytensor-2.18.3-cp39-cp39-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.9 Windows x86-64

pytensor-2.18.3-cp39-cp39-musllinux_1_1_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

pytensor-2.18.3-cp39-cp39-musllinux_1_1_i686.whl (1.7 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pytensor-2.18.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pytensor-2.18.3-cp39-cp39-macosx_10_9_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pytensor-2.18.3.tar.gz
  • Upload date:
  • Size: 3.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for pytensor-2.18.3.tar.gz
Algorithm Hash digest
SHA256 26ce14fddf03971bb4cd4200e368f942a71a6e628660e3498d37c7df163bf602
MD5 9952953a818d27c7a07bdf6cbaf0781a
BLAKE2b-256 b9bbfc917b4a308aaa6358901375176ff2a8051eb82c3d918cd31dff60492692

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 39eaac171a4576d70fdb0add52b1a33fd72f0bb73978ac71f2049759b4b81ca0
MD5 a2176dc09ab987a5c1ff74bc6a991b08
BLAKE2b-256 80e011d685d6ef0b39b2606fc1a9df61dae424e731ee7c55a7d6f17a56b44e52

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.3-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 a2f468060dac31af87654edfdd9afee5c94c37adf84d0091fc912df7b14bcb0c
MD5 6b487037bf8d291febf18dbf8dbd6445
BLAKE2b-256 dfcb925400af8a7dd6b618bf14313957a59a0257e726dee8e800e3a21cba056b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.3-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 b08f331bc050be311bd169139e6f9f2565f3f7d493d13c56a85caf4e3274108e
MD5 8488d1e451ca06e412cfb8de2fd5e9e3
BLAKE2b-256 e023bf16e92820297e4129121697768150947df5f088482489d1e7d74e2d66cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 728b94debc40dabbce3dbe4f318b4fdea593a466c77e127858ee47b9cd7f1501
MD5 cbe38b5e0f9eaf2ad4583dc4aa995d82
BLAKE2b-256 0020747442f2205dd55b21e2f069e4dcaf47c1465763e46a18dc2424fae0d3fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.3-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d6799aa5bac307f9c7ba1ccd8c8810814d88a060a0b170a88ffae8f7b59e7b83
MD5 6712a268fce729792ab3344283477241
BLAKE2b-256 8ef67c582c21447fbc1eb98c0e37291873f191bc28bef08e11b20eb3812a7d61

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c772e126789ba97cf5f2f6e162a8512c6becd7afbd9a098f6ad81726bf3a3055
MD5 58e84e8bc78f99ed411f740f53a4d991
BLAKE2b-256 41493c8156478359dcba782cd11f4aa83120f01476f5a8f1feb614daf11f89f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.3-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 eb2616dacd2460b7bd3f9be8bc6e32e6f53a25fb306f6a392796bc8c59017c78
MD5 f2a289f9099182ff80b093f305597153
BLAKE2b-256 ac2bb7c520b474acd61d5ac7bbbde1a8914abc8312325d445e8196d43163c8be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.3-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 59aa13d919164e027c1c597153c867bcf36df1d7ec321a2dc3e76e7a21bb536f
MD5 757ba8acd78b5c1e93cc873bf1b94458
BLAKE2b-256 20ba484a1467c4901b95ce8d5f31774af3911410f197f74c5c48501823ed9a45

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2019d125e137c08531bcd4a71b5eb6d8bb56b2441ddd24f77a1df74c6b271fde
MD5 134aaeaf19c0befaf1c504608ec12534
BLAKE2b-256 47bc9cc3546a90c9c71de2717f9418c7dfa955336048b19128681b6e552a920f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.3-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6e50dc29f346970e84d9a98b5cebcb2dc7ed0e5495b86360235c9ab746ab2737
MD5 d0454dd8482020641a0d1cd3267a194d
BLAKE2b-256 3d22cc4cdece085e240ebb2fa4aeee7bcd198ee8dd30fe0787dc440dd8e69142

See more details on using hashes here.

File details

Details for the file pytensor-2.18.3-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pytensor-2.18.3-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for pytensor-2.18.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f07d1bb97bb6bafe9853f22282248103cfb57e79ea9203369fa59c723105dcc6
MD5 554d37859af2f20b441fd9f50adedf99
BLAKE2b-256 3100559a6854c413f7129124a853f09ae6d65a8ee45f0a7bd31337ff7be834a0

See more details on using hashes here.

File details

Details for the file pytensor-2.18.3-cp39-cp39-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.18.3-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 d0de5865e3473326dd4358a65b559e2d09f45e0f8423aeb26b10dfb0c8a99760
MD5 ef102e049d1d8f3fe23fe2fec63c9048
BLAKE2b-256 6f8e824826b2d30817dd1c535fa1ee96635932defe03b8ccc5141b7200d79233

See more details on using hashes here.

File details

Details for the file pytensor-2.18.3-cp39-cp39-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.18.3-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 d0f134a75a7f7731b261c6b3d62c95fc248f68be35a0bb23aa2b1c17cdf0eb88
MD5 24149a8748bb78a5adeff526ef88f61e
BLAKE2b-256 365223e11f2fdedc6928366adb5072a7374898222571ba80a551581e3346ecae

See more details on using hashes here.

File details

Details for the file pytensor-2.18.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.18.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 241e8809ce68ecfd4bb7acfb3c6af813f7383c4bb984d363b43d69189fb6fb22
MD5 22cbd3b2904359a4bb4a7ef799648a99
BLAKE2b-256 d36055a81fade46db67c5f550f165aed9078a4b5f953789c5224d8361c11f5a8

See more details on using hashes here.

File details

Details for the file pytensor-2.18.3-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.18.3-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ff164e3cf3855e5136b74b21c589a34bc20d180a0b4104d6d363ef3fb6876de3
MD5 c3cbc0d92e1684813a34c4499a67bb19
BLAKE2b-256 5c1207f5523002565057646e0026c255e9bd1aa7b63df8cf7472e753a82ea766

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