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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 Windows x86-64

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

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

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

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

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

File metadata

  • Download URL: pytensor-2.24.1.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.1.tar.gz
Algorithm Hash digest
SHA256 6c785d77bf4c8659298ddda7b1f87ceaa00c1f897a87e58351ecd88b3a122485
MD5 7c11aa7404a2b320c5b9a25ab6cb6769
BLAKE2b-256 ab84c7a1b3ce7f2d49ce22b4b0368a87bc226c752e64fe6e2e0b2c7524b042fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 76472753f42f5deb440d72003cbd754a98d243b380f5f3482c942b40b871211d
MD5 e780f0acece700d89e05a54b07923bc8
BLAKE2b-256 7cf30283006dbb28af9358c04bdedb5c29d0c1af9ecd083019b095d88e7e43ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 41cfb6625d59f94fc3342e2408534fafe68f68061b4ee2446820f72a5aa37a5a
MD5 d6cb6c689577a9e39cb5cdb5764e5e17
BLAKE2b-256 c0cfdeed5affc2484fc925749246db5885c01c0948eb144b966f5c7fcb363175

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.1-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 94c232f112b06a5bc04ba497aa200258276b2e2e382cde5d67d57d6aa5b1e145
MD5 84517bc7b71695af8284eb3883d940d5
BLAKE2b-256 74482086dae80c44f56e485c361c03cdf840553f4b4618c80f30df94c5d2f91b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ddbb9ddc26fe343ad6d96e08115c41d4c8a14acf123b710a7fe87c93e2241b1e
MD5 724f56aa8133fe3f84d73e0b0898045b
BLAKE2b-256 17873eda94003f8f9ca6e67441e9df194c803a390bcd620ab6cdce36d4d4462c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.1-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a3f9051ba62087338c5847d8b7a1c321e07e04e433e95387e7b502f8baadc91e
MD5 167f41cccc82f98c026452ed568a36b3
BLAKE2b-256 99e3cf38163793ab55f98908b77a6ee8a45536bc13e5d1ac2b7494724866e2f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e308b06c4687eab9cb862207ecb009ce7d4f03ec1d956b0df73ea1d8f7d59443
MD5 17069f849a8e93385e8ad11afc5e9520
BLAKE2b-256 89bdf4828ff78613743a0f6a3d63cd5e47e4be268d25f8a9e55aa1b656a62f8a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0ae295929a40a4e86cec83096528f3d8eecff48166773c73fdfca7e9dce3e629
MD5 d784c3b5012a4fd846fef3fee042e26f
BLAKE2b-256 4a7243dbdd5d5a8461ffc258adda2f0a2464e4d66d001409bb7705c59388c93e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.1-cp311-cp311-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 19f7bcc1762f7fc0aaa7a7d48fdbc94fd8289f60484178a509df54cafeccedc2
MD5 b641e1c6fb971fb34bd4b6478d9f600f
BLAKE2b-256 41e5387222a968b92c6b124f64fe3aef0ce156b5347b54515ff4e47cfa40c7f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 afea9495d0229f7378b78ae0417234c35677c8aaeabdc4ac8e3f93e8cbf5114e
MD5 d5cf9ca5c35614f73e865cc2f6227551
BLAKE2b-256 29d797926b4d0c21a287ecc39ecac0615ab78135d4fd457fbd816969125b8bf3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9370b6d29f1d801591ffee3b722efa32e858b6785acab11325f2cd559f6b9c4b
MD5 366fd073de9310629a3d8b6291b90b15
BLAKE2b-256 20a3c7188bd06c74e6ddb8b275c606b9ec9b82b1c72337ebec29087a85758850

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 1ca381de274a9eff802a6e79be1c4629085688f3e710cb8df06917fecb0485ef
MD5 1772d6b063efbc66aee569954b618b24
BLAKE2b-256 6050f8de442dad32be8f85b2d490b0d90a12f3147b33fb9d7e234d83b71b1fdc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.1-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 35a1ac079bdb878400f810aa6d5553ef08ea3e611c7e9746bf75cb757832c0f1
MD5 b152fc7ee742c01a8e7c8c496397bfd7
BLAKE2b-256 4c29a36f7170489dc0e750c122c8c53a8fa0e77414e16a5f1343c5af7cbe3e32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.1-cp310-cp310-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 0c1e3d5fc6fd71fdce4ba422c64039baeb6ebca80853b5fb022ff3c7ed5be75e
MD5 9b18eb50e2e7cf3b0505e13756d99c63
BLAKE2b-256 1230a7af1ee65a6e5a0908855358395cd25ce59fc0345aebfada5bdc368d2e10

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dca834d3e474e2b96406c778885cf658092e8208af0bae22d128e156f77f1d7d
MD5 d136bad0f4746bd3de068536e7c12de6
BLAKE2b-256 0e8e3dc343ccb7c413773829f7b12c52fe6a73bac7d865cd8cbfccf394d0ccc4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1e6209bfdeeb1b6931e3359839b62b0c8673c05de61ff33b3c72c6da76e6bab0
MD5 d99e7e5ccaf445de8de19d2b64cd53a4
BLAKE2b-256 20d7d85723665e55930df5f8337318ea55746679f33ef32e70685d73a926e396

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