Skip to main content

Optimizing compiler for evaluating mathematical expressions on CPUs and GPUs.

Project description

PyTensor logo

Tests Status Coverage

PyTensor is a fork of Aesara – a Python library that allows one to define, optimize, and efficiently evaluate mathematical expressions involving multi-dimensional arrays.

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

  • Based on one of the most widely-used Python tensor libraries: Theano

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

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

Uploaded Source

Built Distributions

pytensor-2.18.2-cp311-cp311-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.11 Windows x86-64

pytensor-2.18.2-cp311-cp311-musllinux_1_1_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

pytensor-2.18.2-cp311-cp311-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

pytensor-2.18.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.18.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.18.2-cp310-cp310-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.10 Windows x86-64

pytensor-2.18.2-cp310-cp310-musllinux_1_1_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

pytensor-2.18.2-cp310-cp310-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pytensor-2.18.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pytensor-2.18.2-cp310-cp310-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pytensor-2.18.2-cp39-cp39-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.9 Windows x86-64

pytensor-2.18.2-cp39-cp39-musllinux_1_1_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

pytensor-2.18.2-cp39-cp39-musllinux_1_1_i686.whl (1.7 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pytensor-2.18.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pytensor-2.18.2-cp39-cp39-macosx_10_9_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

File details

Details for the file pytensor-2.18.2.tar.gz.

File metadata

  • Download URL: pytensor-2.18.2.tar.gz
  • Upload date:
  • Size: 3.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for pytensor-2.18.2.tar.gz
Algorithm Hash digest
SHA256 b5bb5a027f433a45ae0d4b4b179b8d2e30ac444ebb32caf4956a4d7f84031125
MD5 31c3368d387fa9a0bbeb16694461c1f1
BLAKE2b-256 68e5fe8f5c22cd9eb4a063cf06dc9ab7f78f6840e43840992d07f985565875ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 66528908a8669a330f8c771762fad5e2035ca81df8d9a492f5f80b266e0913fb
MD5 03579a4cc4f76b30910f961a82f8ae49
BLAKE2b-256 15dc97616dd49aace0c28cb0bdc2b40e46077dbea041587ef91590f4b175669d

See more details on using hashes here.

File details

Details for the file pytensor-2.18.2-cp311-cp311-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.18.2-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 af523f80da9c7ecdb0798e7fe951dcf3ef33576463e0daf556d8fdd6a6863fef
MD5 341097b2a52b588c7c7635e2a28af170
BLAKE2b-256 2922fac193769c0bdd5140efaa30e218756bc072137868492b3e61020e01e107

See more details on using hashes here.

File details

Details for the file pytensor-2.18.2-cp311-cp311-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.18.2-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 2cfd2be6b6311261f2b0644f3001e3619007559de7d0fa055268811eb63bf761
MD5 b4e66c6060983f037f20b27d58787534
BLAKE2b-256 55c89f5eaadc4fed1ebb2fe9fa3573ce6a6378ea159f209a0d431a1943e02a33

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3e4c1238fdade90582f7c713de722c00e66e2b8d1181ff50752b3247c00f4ded
MD5 e7d05ed92cf1405cb193fd92a667208a
BLAKE2b-256 79189a96bb34f467d4cd268d88ed2bc0f717b35e3b1e371dd9fb232cafed8dcd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d673288bd965050ba05d670eebed562f230d9a4b30a23c755f74bee031e31a82
MD5 239ce2e11b9d4770e1c12025db563ee1
BLAKE2b-256 ecde4ad9c4852eef8d63612d9c685fd2664aa23ccf2e6a8159c26bad4d3dc723

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 da1363df4e0d0abaac85c745e2ba4ac81f72926ebd94601dcecd59c849df2d8e
MD5 b1359b456e0460d6411d1e74732711d2
BLAKE2b-256 15f417fda4d0823dfa83d4aa8b90bc154a17a3f5e78016a70b469db7cf5a6973

See more details on using hashes here.

File details

Details for the file pytensor-2.18.2-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.18.2-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 436d07787e9f8528f727a312907da894b40b95ef5b3c2daa0a41764d5c54b2bf
MD5 0521c190ae1076fabd30d0b1b3f79437
BLAKE2b-256 f7460e4d94dd8d0f9e4ada5e15e8d1fd2d882b0adc7e55a439de762ed4aba667

See more details on using hashes here.

File details

Details for the file pytensor-2.18.2-cp310-cp310-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.18.2-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 03da4cd45b4b0b08781b7556ac6309ccd111e61f5e5be6faa5b1ae54420c6967
MD5 5544e9b43482dbff32140205a5168676
BLAKE2b-256 dc72686be3e7b99cc9b3390cff5be9ab4a313915b796a0554cf303be04531904

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8f1e330515bdb6749cac119f5f4a4bef23604d3088b99e7ae94da9e9d81a3012
MD5 7817adc98d7401fdedc0681204c82e94
BLAKE2b-256 34e2b97786cc6d746396699a98777591a0a2fecac94d98dca7787d70dec4a565

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9ab4ca10cb09639afb1cfcbb7fbdb113b6e6180f95655955ca65678c61ec68a3
MD5 19d35ae25fae495fdf7e60331a7525d9
BLAKE2b-256 9b2710fcea2490dda9aad76fe04a8a0b5f45b22218df5e3851609204ec6b968f

See more details on using hashes here.

File details

Details for the file pytensor-2.18.2-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pytensor-2.18.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for pytensor-2.18.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 8f4aab67fcdd5db1d8a9248da835b022106f41af95146ddb785da9628ca1d0ff
MD5 bd1fea03750e45de7a3c7517ff23e74b
BLAKE2b-256 a3d71f1ee737d882b7ecbd7e91d23dd1f3c03d6ff575a4cefc2fb83df06b506b

See more details on using hashes here.

File details

Details for the file pytensor-2.18.2-cp39-cp39-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.18.2-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 87da849b00059d45d8981a58f0e8333879f223b3712b2078dd3a2747850c9d2d
MD5 ce87b19d8c3711ebb92733e88d67a2a4
BLAKE2b-256 41a9c42c9fef04e0104fb5abec7a1418e2c76e680c8d9116d8e9c470d9b18070

See more details on using hashes here.

File details

Details for the file pytensor-2.18.2-cp39-cp39-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.18.2-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 f588000812a5b7be7fd91959bbd54b34a00f673ef2ac2770922966a01a61e9c6
MD5 bca62eddbfad8f9296d03f70d707f738
BLAKE2b-256 dd50332f4428e031be9de448b08d8b1197223b5797874ab4a9293c9a7ad29eed

See more details on using hashes here.

File details

Details for the file pytensor-2.18.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.18.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2e1d136f597b692038830a662938727a0f883392853e5edacf9806d80ad5f837
MD5 e5e38b4420fc585a611b672ba303ad62
BLAKE2b-256 a301950e6b5aab384b693625e49c36a064e23196dd60c8661241034d76962eca

See more details on using hashes here.

File details

Details for the file pytensor-2.18.2-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.18.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4586f9ca6175fb9cfff7985da5669dd1af4328e53686ab92d96aed6b529059c7
MD5 d97a9e403809fb75241b7ba986a02b2d
BLAKE2b-256 ab304899494c9b73028d000287d7fc7c244e3f19cf69ad55bfb76c5de70dc65d

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