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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 Windows x86-64

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

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

pytensor-2.22.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.22.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.22.1-cp311-cp311-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

pytensor-2.22.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.22.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.22.1-cp310-cp310-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.10 Windows x86-64

pytensor-2.22.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.22.1-cp310-cp310-musllinux_1_2_i686.whl (1.7 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

pytensor-2.22.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.22.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.22.1.tar.gz.

File metadata

  • Download URL: pytensor-2.22.1.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.22.1.tar.gz
Algorithm Hash digest
SHA256 60b9655ac74a86ccad8f47b4569f5cbb3196a5b2ecffdc0eaa372a2f67ffa28b
MD5 d0ad05e4b4b1fa86cf1a2df3aa56c15d
BLAKE2b-256 fa09ef4540093897de150a43ed351ed751a2e85ac3b071accb20e55310788e1a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.22.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4b6fecc78aff4dd113573983c44aec566429d673252737173bf9827735c9f4c8
MD5 f31416ffb83580b3574bb37ecdabd37f
BLAKE2b-256 32a705d727999cfa53af1de195d3a5d4c44b1bd5f73f29d74fd119c25f25758e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.22.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2fe83d199eff270abf929a3f0595312722bc9f5546ce4734bcdccf82f3dbcbab
MD5 be049fd663f0edef5fce6a5da0b998a4
BLAKE2b-256 7f830e7cd7cb078826309386f4eade9ffa8372f514e6437d1be8c145c51e9d56

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.22.1-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 7415bceee4a460c3d4df2cc388457d4505633601daf3f6e8011542c751c0cd68
MD5 1a0104333932f3dc0c33a27fb4090bdb
BLAKE2b-256 c70d6ccf4a47e7135007ed430803bdabcc51db941b4cff95d83296a56b5b8729

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.22.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0631d10652e55557da4b3c4643286889ea1c5589ea1d5916c33f8b43c3a41b29
MD5 7915b28b094f26c19ac8613710a751ae
BLAKE2b-256 2cad408ddcf1f935c5ab70bb32ee3fc61e891b6f9ada0b3a2a6f5af418403fad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.22.1-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a7b12e22ebe42e1770ebc319323902e6c3dd355f57176b778533b35b92b721bb
MD5 0772e93103cde96855452eff11849ad4
BLAKE2b-256 f0e25f04826c8fe1c7da35d0d74f9660e7ff5db1b5df3c094c33d564f434e7b8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.22.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a85565b63b51f377447465b76c6340853444da2b8a978e1d1da5fb37fdb32df0
MD5 ea0cf49c90c8bbacdddbab5ed4f1261e
BLAKE2b-256 09765fffc53be9d894251666b48daebd976cd04fa3896161d4770d6eed277639

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.22.1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 80a7af33254bab2b9376da07de6be16e3955a68c4fe62c184db2c4f4ab97c937
MD5 1e2d090980e0c035583b4fec0b9af868
BLAKE2b-256 d4bfade3535073aff8ed6534df3ef78d1a615207d41112aed152949aab3fb551

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.22.1-cp311-cp311-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 c611dbde412251650ae77fb0f699610cb51fa74ddcdcfb3ae46d14a9955a40dd
MD5 4181631724decd70d6173cd9b085b004
BLAKE2b-256 e0082c40f3532c3d8b61d45a770db84905237893e4ba5d4f5b83e782f1717658

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.22.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c00ab92c573fae9c0071711f3f94697a133534d59b8a5b4c3ebd73313e6f0977
MD5 76d93a437dddd9a97a6148d1f7b38933
BLAKE2b-256 a98ff4af77a314c2a02baa4294e3ec786af759988ff5ce9d4a8eda8a7e94ec68

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.22.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 eb30e2ccc00a730ab3c75cc29a726f202911704e4b99b2aae035f3fb3ac63a07
MD5 8edabb752b87168bd786ab9cf785bc06
BLAKE2b-256 85b35dccd9f38cb9e25ea3513130b8bd5d23be4b26c00bf674db53d869512a9b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.22.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b5bd93eafedd230602e6786ace04b52584c2a35af33d8cd44cdcdeefa3b8ea4a
MD5 324fef6edc1f977925dd54c6b8434833
BLAKE2b-256 8ce586e61b069ad7e1078136cee1f7e2ccaa3a37ef6e9f3dddafa3eb79cfa508

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.22.1-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5f9df9c2bebf4faef6067d194843b35284550a6e405e12d8785199e31d05a94b
MD5 5c25186bcc947b048c717076e7656dc2
BLAKE2b-256 36f742f90191a98cbc6d4c740d5f17f919c7b9401052fdf76b1e29f0dd8c314b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.22.1-cp310-cp310-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 d622411232338b20170ca51d3680b524724aab5bb8108c23589bf5ef2c30ed71
MD5 d8c92fc1254bf4dd1b0e1d64351f3c6d
BLAKE2b-256 bb7195aaea9f937b78837664716bc446351f469676e172a2fcdb43c4be9c5f41

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.22.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d4fd4936039fb8adb6049c96555c995ab31f896f4dd19ee5471958c841f13ed6
MD5 55b04b383dc1476dc4016c7e6455d224
BLAKE2b-256 cb6c266aa77316c4be9b29f49cbe6d8a2f738cc1237646165b8276a34281e517

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.22.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d3cfda18e866074e2a61007410bd64224ac623746b0d36ccb08d757f27fc2f59
MD5 d7da7c230caf5471bbb6ba7323924891
BLAKE2b-256 01903e3d267e344b8ddbf35666b5ba7ffd461092f4bfe1f4bbc1caaeed33dfd7

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