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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 Windows x86-64

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

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

pytensor-2.24.2-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.2-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.2-cp311-cp311-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

pytensor-2.24.2-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.2-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.2-cp310-cp310-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

pytensor-2.24.2-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.2-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.2.tar.gz.

File metadata

  • Download URL: pytensor-2.24.2.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.2.tar.gz
Algorithm Hash digest
SHA256 f7e7aeaf1b3966d0af2c78822a18429199557145566804a68ff41a4288ca0974
MD5 f150a51a7c6ffe7f2e1bc44e776c8657
BLAKE2b-256 fa483b81f24a0be313fb319a7934c135fefcbaa51a66d2d3bd1b17bfcee17db1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 bd99f60c4d9a1b235fa556c047f6b1f7ac10bc228fd5d5b0d741aaa0b487a5f1
MD5 f2351e84982cb3691058a2d5a777024a
BLAKE2b-256 cba7f7bc8c421fe4b67ca9d33e45159465d3e1737152aa3b55fee401d386957d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.2-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 33a2cb74ab3cc9497f946eeca882a5342f4c52db4f2f65cf7d1644dc6fcb45c3
MD5 d73ccd0be6affc7220297e395cd37ed0
BLAKE2b-256 ec8dab1d70a99a039eace8799d4cb4f386efab0cd59cb8c167fa7c98914f47ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.2-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 8d915cdc0321ad5e22b2f7ff30c269c1e037af28cf27c05ddc6c163613445873
MD5 091ec0cab1b79f8a12f9286f49aeac98
BLAKE2b-256 0dd58b4612e48f8e38b5f307ef72efe0c5d6edb46f145e40529a551c79e8c987

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0f364cdf9c11f1c967d9588035508d591c1a236595b6067cebfcb4ca2a3e04b7
MD5 ea3ee86ef8a3f4839eb767bb262dfe7c
BLAKE2b-256 4628bc0e21d4666138ea433aea3f491d744d1ceb76dc011d16ea3b48d9f547ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.2-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4dbd02f86995e6fd4c529ddc790c9835a0a1c5592494c79cdb7b6a11df92a886
MD5 322d576e9760d29ca2878c90e40d5115
BLAKE2b-256 ae8d938c93d99cbc411ab878ded08acc9b00ca589b686bb1639c0c372466266b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b919f6c1cdc5b6c4c27b251a7dc8d5b8cd2af5f3f591fbe0befd7408f3bf3011
MD5 d51042f35aaabf5724bb7544882aa183
BLAKE2b-256 3472c8ee17f8d97518cf127b68522bf6366c38b5c293eb25bdc28532929012b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.2-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 69f737b9485b76e0dbe55af3b023f0ef3b81074241ed1ab1c94e89df7f20ac9f
MD5 a46fb2a27f8cabfdb37e26326b065123
BLAKE2b-256 ba2dce3ba77016ed85f2bd61721a80e86a1e685b6a7153daac12b383dfb79e12

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.2-cp311-cp311-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 420952d3f181ce0f7977ffed5b337d251061fe71cd280ef0854ee8c7371a2544
MD5 2eb9d2e2a0abe7edad5dd4ded07972c7
BLAKE2b-256 2a001fe77e16628021b08a58a025b13348d126c22dd257e6403ac5f8312fd27c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6278630d46ad6445198529a860bb18b265ad6e77278dc257b00bca491d877924
MD5 f3237dc95d9058a91ad2b21a0c9c3f74
BLAKE2b-256 c4d72b6cc78147f07f421143dbe5038923defe8965d724c5c98cef922865dbab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4f11028ed04175bc5616e24d08f026c1b7c10f0fc2734fc9c6d1c6db0beab2a5
MD5 9b118105bf7e57cb4fe8bfd66165b357
BLAKE2b-256 8e570f3213734fefa1ad3a54cf5e5f576e976d66286f27b41119465c7fbd444b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b160ddd102380115b691cf46476fbccfc41a88a0fa07999ab0f2a58a1b5b6d9c
MD5 097561dae0b3eed99fa17eeea7a45fe5
BLAKE2b-256 1a49e5b25feb18fac98e910fc8bed8b85a80272826ba9d177d9d29804415da76

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.2-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b99da8eb27c38ce4ddf5934c1d8536268ad8b69c55074819d56d2e79e919179d
MD5 8a4957ef7b3ed09381d1c4ddbbb89d6b
BLAKE2b-256 35f8769cb0e100dddda97edf44d61d9c875d6886f54088eef1eafee0ce36c457

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.2-cp310-cp310-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 2f1c5497af9e3ac8bf710533643934850fa6b3274fdd2bbaef48e2b598b29a64
MD5 415fbf78da6319eb6ae80771968f18af
BLAKE2b-256 d9a6fe387f007dc1707aac81dc79d0d9bd220d2d18ebeea501c1e09637f55a54

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a667c4604ac791d4b97dc208be4ae110743777d06edb86cdfb83dc79ff2ff7d1
MD5 51b40ccadc20f50fcaed1e1f81b6551c
BLAKE2b-256 cea61c788c79fd0581c41bccb54c7d016fd1ece4de76728536c6882de07c75ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.24.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5c677c098a1290b66aa58dbecbc9885ba65d7010b3fbbf62af598de55be28d6a
MD5 b582773d932093c603b200683429aa6d
BLAKE2b-256 df78f89f2bf90946a00a9acef79c3981a92eef345c61288615bd0a87e4428383

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