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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 Windows x86-64

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

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

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

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

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

File metadata

  • Download URL: pytensor-2.25.0.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.0.tar.gz
Algorithm Hash digest
SHA256 365f8128dd953e3ba5449c3d45b295d32401fa76738f28632f7de2f3df3bc817
MD5 b6a7a3847bc8768c729c0329268b878b
BLAKE2b-256 ce22f0efcc5263fc36cf4f3c187d08eebac5ef5f563442a25603fc1129e6d353

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 06af40681c94eb9751834de0d62ba45b4cee879bcb2be2b63d14f512b0d3a60f
MD5 fcf546eb5e7918a23ef4c7ebbc516b3c
BLAKE2b-256 8203b6f1ffaa32ef51166b84c6eb6ee8f6fb16ef88425d912093cd534ae785b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 91482073650a79fc52677c2976dd1a7964f41f4d6986487c854464e1407930d7
MD5 8c95aa1d976e6796d7d92967df1ea5b9
BLAKE2b-256 dae931c84747655ac0c33124ada814a85128eebd26756885bb50b39548d35831

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.0-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 bc4d392698363a88cd80fe29ea92cf6d184f1381643f7921006d475e47932593
MD5 8e7d4bd8f3fed0a4e7b542a274824337
BLAKE2b-256 d6dcd01e63a2015be34db5c9f7978152a9e5a3377d737f14e5ecb227eca8bd33

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c030882048279eb94393a241206184610b57491f4291029d22625997ac1764e5
MD5 9098b2c5a3fb9493eebd24ed35377f52
BLAKE2b-256 ccbd7185a36d8b721d2f2b5a4d4734cc9ec68a4818c72bd015f9c3d36d051d10

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.0-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7c2eb3523536c92a6bf08956c4922dcbcb67fc758b7225c13b52444b26260386
MD5 8ace7fe06404d67e75a5eafbbdfd2181
BLAKE2b-256 c56f2df2015bc96cb95993441aa1a4391209d2c919d95f561dcb1dd463fb1c8e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f6ab87f2d36522a982e311676af842ffdd0fe57b4bc47c51c8bba9c34f6d9d69
MD5 f4893e473203c6e60cde2e92e4f5996f
BLAKE2b-256 992dfd4597eca2a80eef1398133f177c1ab8947533e967d719b74f4b74d57566

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9a821eac3fcd160cca4253c06e2b53c5e39c942738eefd77a65d0e6f1a1a0df9
MD5 d596eddefcc2c8b4db03851068b753f6
BLAKE2b-256 ddeae6e19cbd40e394c5246389d91ba6f92a189c80eea3e094043921b6c3b2ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.0-cp311-cp311-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 334804d4e356fbf3fa06e03f9fcca0a113d945c61fa4ec6a16513b14fcdf2059
MD5 cd66bc193a39c34489e042c09e599d3e
BLAKE2b-256 6867b2d47f964dbbb1356f5d9f65ed771fdfb73be8c057f5f11ec41ecd0070ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3f235383f3db622a88251d2a6ebabbfd960bcfd07f66a5a7f8d683494fff90bb
MD5 624c0124b01f2c22674dbf9f04389e2d
BLAKE2b-256 a5ffbd3acd0dcf38b64da54e6f1efc130b8745241890a680b928016b38708a7e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 08ccc0a0aa2d9bdae87f64c4d3e041b020a60389f1f30dc7ec9efef3e483c510
MD5 cc47c62b68c3b8c52375ebdff7bc679f
BLAKE2b-256 4fbc344f98ba74c7e2ac98e8888a3b3d809b3172e0510d4cc4db9dcb99e776cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d4b9ae4beacc6960fd2cb197b5bfeff51f0aeb0602199d3a57e735c323566307
MD5 16dccec42dd5bff7478146c7f294ea2f
BLAKE2b-256 61fd840303027df013101ae702cd71a473d1fd9387621b3ce6ef6418878ecdbd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.0-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d01aa7ab98960fcdbede655d1fbabc76d59d60f078e6c40a725fcce1f3675924
MD5 3f2e9cc5d1304f6d0b2e8d3cf3d460ba
BLAKE2b-256 497d8695a88dd519c4c8c34bddd44ba82e4aacd9e1027b2aa618ab21636f1be5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.0-cp310-cp310-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 f31931fd4c6fdb38a53b4c9a7829f936a615932a2e3a05043adb2c24effda8a2
MD5 fa377383a218d73ee5e364dea20e9444
BLAKE2b-256 f87f8bacc1df46b171f040156c4244088641081648d8b65e2baeaa452be42e7b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0197b91f473c88fa4abd13624c9d4b0be1de1deaeefb0fc3be817c275bb5e5d8
MD5 53617bb9fcc9f2a9da0c96fe43b9af6b
BLAKE2b-256 64d4b7acb7f3e5960b929f3deaec3c15dc29791e717da3353ef7f9fb0878266f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.25.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0c1edba547cffa25cdcfd64d9163e72122e70a0167a0cd20351be8982d6b4f9b
MD5 8e3dba57b37a46f7d493f9ef9422e0e4
BLAKE2b-256 799a7a4a0a17315a1e3de173b3416dfed42442c01dbbbe523ff7d951e66acffb

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