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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 Windows x86-64

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

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

pytensor-2.25.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.25.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.25.1-cp311-cp311-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

pytensor-2.25.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.25.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.25.1-cp310-cp310-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

pytensor-2.25.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.25.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.25.1.tar.gz.

File metadata

  • Download URL: pytensor-2.25.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.25.1.tar.gz
Algorithm Hash digest
SHA256 e8b0c2e751da1e678f26b8b3fe52455344a5b1bd245ca20dadf03d5e0264b7ea
MD5 5ab1eb3ae55e529fb77dfad7e4f68779
BLAKE2b-256 b77a8b4a2b656de8a439d351c0d3a22739d97efb504822afd91394263d09d61b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 55629cdfae2fb1feeb51a24bc0d733aca4bfc7807cf9a18ef328148c475f2ca0
MD5 a7930780c90cb507e756a4215eba3183
BLAKE2b-256 cc9346d8dc28aa65d04ff9d94cfef5ef4daad53236bd2c6ecc951fe9a24d079f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e4e87e44887174ccb11272595f60d18f3e40c51b7e04da28dfc7bbca30862d93
MD5 ca1cc9e42e7353db9f2ce21ddaa44647
BLAKE2b-256 327b28357a60020501926bf5e0fd1dd987dd35dddca99e7574d33153aa9a6fb0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.1-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 262b0a28ace0c78d8619b1e988fab67bcb6c02d32aec25b10c8ee2d8444ad1d7
MD5 9c1416f1d2a27f577a1361c7abcb15a1
BLAKE2b-256 bcd1a20d24126c1b4c573a1ee3a3a089b3446cbe2b6f3d7892da57b27ee1a10f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f0530ff57a83d0912992805ebafb32aa3f44327df79729fae2b3b98dfd730ddd
MD5 fad62162fc5594e23865983203e3c2f1
BLAKE2b-256 13ce92cb93d3e8ad479a654d7850675b8324b6491b6987c0b65170e3cb13be1b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.1-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8fc8d43776c7816ab5489c43d61e98f3c56b09305b29628938c894694b68d97c
MD5 9d2abc730d90775bc50a4f86b223c7f8
BLAKE2b-256 bea26fd8cc1420cd33aa5e2b5f7de9b00b003c6ed24b40bc27b59b2d4db689f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3fcf54b228d04f0037717eb5286aa28b2b66d12c746b5cde32b464c2b73d9be1
MD5 9c1ffd5915cd36624b08c762ad0e3a52
BLAKE2b-256 24b08aa957f1e16a67879fb89bff31db987cf83d79a45a568d9c8847a5644b45

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2816984f638a8ed76a94152176ab908ee49d1f277a87e4878eb9bb77e3d07f78
MD5 e16d28be1aeadf4c04be3c439c9660c4
BLAKE2b-256 7f402bb40b8634a10b5aecf081ab58add2f1fe3ff374e42cb6d81690497efdaf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.1-cp311-cp311-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 117c8f86c70a9dc961ae2283ffbc83b7df2ebf676f2185d4799e8456ad2a909e
MD5 3718d457402db73d18ab67c418266044
BLAKE2b-256 11506536237d9b54bc02cf92f41a260a222290c71dfd0df9c35e4afbac16eeb7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 69ff35271480c71d82704418267214c89864f422567e454652fcaf64ac181c33
MD5 76d6cf5087981d41d4d1c76fb92e5143
BLAKE2b-256 dcb117ada8db9fc84db8bbecdcb62f54f50463cb23eea22e9eecd56cc5c002f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 08734fc57718a3f9a1366e52f34684c7d78e8a2d1b034c7155378d8b17b1ffa0
MD5 7dfe77ece487e942542ceec2bc511c38
BLAKE2b-256 20bddefc5082778ce5d8c2b36bb6d15eec3b45603662cd8afdc9b38a4f9f10ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a1a469821e4051d678caac31a8b2bf16143ece97e892bec0e2401f233df31948
MD5 81f655902945c42ba5be414b19269b09
BLAKE2b-256 50ef6c61cb548360305a9f4b263933fa5939a0789bc40055fb40dd5bb10750cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.1-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 bdc15e22be0154c322495fde9265fa866734b4ade10d93f35512176b9eaf2a79
MD5 427b539a6e8d407bc669bd96304bba3f
BLAKE2b-256 05b7fb8638af7064edf0dce70dc6829358eedfc4025caeddfff6d58fe4e6a41c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.1-cp310-cp310-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 9cc7c7b431efd5d8d6fdf3f855252c15eec8b2d9e4e0a97dcbcc0d6ef4622299
MD5 d40c95fa93c24debb474575773c8a36d
BLAKE2b-256 6d787478894b6c72bde9526ae2d105f79f237a733969e38d3e0f65c31c3fae03

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f5493b37614e5614c8061a140b8b2c173bd58e7f30190c263c367d7c023c849c
MD5 217117628f054bf0772fbc383cdb3065
BLAKE2b-256 de9645e95db0fd90a6beb0b53e8b6487f00d7f9945afe67982aac9a200c88e27

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2b3ad20629d59ee193f49d08ca90b039ccaa6560c38ad3a648b1923382e45d63
MD5 85214824c0093001077f7ef8c1e614c2
BLAKE2b-256 5f0e6d43dfe4262002272793473b8f95565edf13fa4334fc8a1a486a6959952e

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