pytensor 2.38.2


pip install pytensor

  Latest version

Released: Mar 06, 2026


Meta
Author: pymc-devs
Requires Python: <3.15,>=3.11

Classifiers

Development Status
  • 6 - Mature

Intended Audience
  • Education
  • Science/Research
  • Developers

Programming Language
  • Python :: 3
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: 3.14

Topic
  • Software Development :: Code Generators
  • Software Development :: Compilers
  • Scientific/Engineering :: Mathematics

Operating System
  • Microsoft :: Windows
  • POSIX
  • Unix
  • MacOS
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.

2.38.2 Mar 06, 2026
2.38.1 Mar 01, 2026
2.38.0 Feb 19, 2026
2.37.0 Jan 24, 2026
2.36.3 Jan 07, 2026
2.36.2 Jan 02, 2026
2.36.1 Dec 22, 2025
2.36.0 Dec 15, 2025
2.35.1 Oct 20, 2025
2.35.0 Oct 14, 2025
2.34.0 Oct 07, 2025
2.33.0 Oct 04, 2025
2.32.0 Jul 27, 2025
2.31.7 Jul 09, 2025
2.31.6 Jul 03, 2025
2.31.5 Jun 30, 2025
2.31.4 Jun 24, 2025
2.31.3 Jun 02, 2025
2.31.2 May 25, 2025
2.31.1 May 21, 2025
2.31.0 May 20, 2025
2.30.3 Apr 09, 2025
2.30.2 Apr 02, 2025
2.30.1 Mar 30, 2025
2.30.0 Mar 27, 2025
2.29.0 Mar 18, 2025
2.28.3 Mar 05, 2025
2.28.2 Mar 03, 2025
2.28.1 Feb 24, 2025
2.28.0 Feb 20, 2025
2.27.1 Feb 03, 2025
2.27.0 Jan 24, 2025
2.26.4 Dec 03, 2024
2.26.3 Nov 15, 2024
2.26.2 Nov 11, 2024
2.26.1 Nov 11, 2024
2.26.0 Nov 08, 2024
2.25.5 Oct 03, 2024
2.25.4 Aug 24, 2024
2.25.3 Aug 21, 2024
2.25.2 Jul 15, 2024
2.25.1 Jul 10, 2024
2.25.0 Jul 09, 2024
2.24.2 Jul 08, 2024
2.24.1 Jul 04, 2024
2.24.0 Jul 03, 2024
2.23.0 Jun 06, 2024
2.22.1 May 28, 2024
2.22.0 May 22, 2024
2.21.0 May 13, 2024
2.20.0 Mar 28, 2024
2.19.0 Mar 09, 2024
2.18.6 Jan 12, 2024
2.18.5 Jan 02, 2024
2.18.4 Dec 15, 2023
2.18.3 Dec 11, 2023
2.18.2 Dec 10, 2023
2.18.1 Nov 24, 2023
2.18.0 Nov 21, 2023
2.17.4 Nov 12, 2023
2.17.3 Oct 17, 2023
2.17.2 Oct 12, 2023
2.17.1 Oct 04, 2023
2.17.0 Sep 29, 2023
2.16.3 Sep 25, 2023
2.16.2 Sep 21, 2023
2.16.1 Sep 12, 2023
2.16.0 Sep 07, 2023
2.15.0 Aug 25, 2023
2.14.2 Aug 04, 2023
2.14.1 Jul 27, 2023
2.14.0 Jul 26, 2023
2.13.1 Jul 15, 2023
2.13.0 Jul 14, 2023
2.12.3 Jun 17, 2023
2.12.2 Jun 13, 2023
2.12.1 May 24, 2023
2.12.0 May 22, 2023
2.11.3 May 10, 2023
2.11.2 Apr 25, 2023
2.11.1 Apr 13, 2023
2.11.0 Apr 07, 2023
2.10.1 Feb 20, 2023
2.10.0 Feb 15, 2023
2.9.1 Jan 10, 2023
2.8.11 Dec 14, 2022
2.8.10 Nov 23, 2022
Extras:
Dependencies:
setuptools (>=59.0.0)
scipy (<2,>=1)
numpy (>=2.0)
numba (<1,>0.57)
filelock (>=3.15)
etuples
logical-unification
miniKanren
cons