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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 Windows x86-64

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

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

pytensor-2.23.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.23.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.23.0-cp311-cp311-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

pytensor-2.23.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.23.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.23.0-cp310-cp310-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

pytensor-2.23.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.23.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.23.0.tar.gz.

File metadata

  • Download URL: pytensor-2.23.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.23.0.tar.gz
Algorithm Hash digest
SHA256 eb5850ddae5670f1699526de6397a9b3a0a0a71e792c3250e19dabe45d54bfa9
MD5 85aa156d0c38019a1b38783a975d982b
BLAKE2b-256 66242446f7b3b21e645d17b400404253dd5027b8f323f6d91afa72cbcd5cfc95

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.23.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 fdca4dfbfe559c70505c0412f592ed0b76297920591e6f85d5be3ff8e0a9d4d0
MD5 6837f01786b1fef35cd638b62410bef5
BLAKE2b-256 c6802c806228d24e63061e86c4f3bdb90997bb6f9e3410e46ef537bdbb2fea73

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.23.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4559e4ff0d523e11f885c50b5d4878121361b6192b836543f3840be122d85e3a
MD5 81320d7241727c3a8d8218fe84fd10cb
BLAKE2b-256 34525ae9a2db064f3a0d7b3532ba26bef664684a740a467b49cb102c868be5b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.23.0-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 a49f3a772629587e27d5dbc6469989426a91221ff39afc915f6ab7d70d7162b9
MD5 8122d127df5bf779e9cb5952d46de48f
BLAKE2b-256 36ff99c20c1ba768f09b051a0d4526b5696e0580fb662ceac585e7eab58a6dfc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.23.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1eec9a5790b64b47302ff473fe2bac2522fbe5fa750d090818d76e4a8e5ad776
MD5 cce9734c2eff1ca442e66bf86fc9564d
BLAKE2b-256 6ff392a7c24fff209490cca6e3ed1faa5d951bf94397c3c51e99da7649e3a668

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.23.0-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ab9112e9403e3039e2571cd406a8b14761820ccc3b5e1f5526f8c84216d11805
MD5 b62d12a65b26d7da5e103f992fb54ccd
BLAKE2b-256 c77f5f5b8783dce42e25191f61170fc10c32bcce642d70c5260c071affd6b4a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.23.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9b78b5a4866f1ee5441c0d42f22e26d5cbd7087df411d4ef410743f9544aaf69
MD5 3afa8568f7f44968be985f8fd9c538db
BLAKE2b-256 9869a87a42fa7d8d0e712f8e6ca9ad027027c18ee7bac2db9fbbc37cb5df51f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.23.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d4371d9438b6361f14e0cac8a3bc04a0300aeebd953e6667fd64a120952a6307
MD5 fb8d717c96875a1eed3af9676de4402a
BLAKE2b-256 981f99b0cf591581fed07ef80ffdf967e8315ec9bcb02f5e03e3036eab96d510

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.23.0-cp311-cp311-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 5445f895130369185cd8329cb63d6131d59a372a267eb4924787fd6d79c26f9e
MD5 77285ae4a0c66af2df6b61f2eb0f75d4
BLAKE2b-256 f749db52de3a66082950486a9cafdab9089180f4c69838a7cf422b02d336f90e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.23.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e006e894501d8a5173ac9be76e8cc8f441008feed3388a01d0b8b01c416103db
MD5 37be3b9404c631abcdce06b701a60a56
BLAKE2b-256 808afd9c6c006ede198020e1482776befb5f1f1ce1ad27a14381db831f6b8032

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.23.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9725dd5b03c721b94aa8009779cb6d92d6a2c60017395ddf5d4bf2c1daf4b7e6
MD5 2a9553d102f1aac078b20dec8336768d
BLAKE2b-256 bbe7481fec0a4ce792f04b490e9e74f0e5a29095a31baa7d0a3a97cb487483a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.23.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 65010aa05b2c3f969744d1095a7a97f77d21c1b630361a2bcc4961c6464ace49
MD5 95641a852f809dfd7213da00a6d5c0b5
BLAKE2b-256 c120cf714bebb645fe27cc8370c11b498d0df01ce1d6ce0407764bfe2567ca7a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.23.0-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9f60f3a755938f25cf0cd83edd7b5f5bbf93cc2ae5052370b0c5582d5ed318fc
MD5 f12d8138672d1646940106a6ead396f3
BLAKE2b-256 f7dd032a7187e23800ce876f270fd12f34df31dd0387b11a6940bde069796919

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.23.0-cp310-cp310-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 7974432dad0b5211b9a6ef065b7564f0cad79830022165f654b546b7239e7244
MD5 0824d2e9a1d2ca3414c810fd2b6e6f92
BLAKE2b-256 e96ea884f271066beff1d1b595cbcf4c1a06e33f26acf5c4ac8fab86d950eada

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.23.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6ffcbe212c3c4a05f55703d378af44d959eb43f42a905d307dd4f3cbe31cf121
MD5 c2d459547ad6d4845efc705e375ec93f
BLAKE2b-256 8b44c405649fd39584d47db41af4f98a6979e6a40afa741fc917e22dfefabba2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.23.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f3666fa09150fb425caa9a72d5515dafbe9de223300daa1c0510907c1d4e4730
MD5 2aef24f726eab619c112d96a1b2726be
BLAKE2b-256 3846e879380c6ecf1e9d48e5b241581e6ef9f4a081baf1eb12c535ee7dc938c1

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