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

Uploaded Source

Built Distributions

pytensor-2.17.1-cp311-cp311-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.11 Windows x86-64

pytensor-2.17.1-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.17.1-cp311-cp311-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

pytensor-2.17.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pytensor-2.17.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.17.1-cp310-cp310-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.10 Windows x86-64

pytensor-2.17.1-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.17.1-cp310-cp310-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pytensor-2.17.1-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.17.1-cp310-cp310-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

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

Uploaded CPython 3.9 Windows x86-64

pytensor-2.17.1-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.17.1-cp39-cp39-musllinux_1_1_i686.whl (1.7 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pytensor-2.17.1-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.17.1-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.17.1.tar.gz.

File metadata

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

File hashes

Hashes for pytensor-2.17.1.tar.gz
Algorithm Hash digest
SHA256 64855a453b945c52d674086f1d160a35e910efbf13693dfaf0c39e92d474a851
MD5 f83fab410b81981bf4cd0aaa6b560648
BLAKE2b-256 6c9268bf94e44c3a66d15912e3ab7a97ff15020b59ab0e4153ecec102c5a05e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 66d0695214509d20c33787a032c2f646f65069d94d72df469c82c60f13e02753
MD5 3b67672ce9d5a6044070c2376d4d19bf
BLAKE2b-256 2761dca72ddd96a02940a067ce8c9ebcc88944e32e8834385a4986cb1f723dae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.1-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 afb3aed0cd7c5149e30342600db4c795c9343f45d232335cd0678b9b5a0a022b
MD5 5904e9f314f01afa5063abf52a5045f6
BLAKE2b-256 47a6c851da00001474488f8c67bcc3560ec5190a6974c1355f096b88251975f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.1-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 fcb4de02cabab01953b80d5864811f50c38db08b6c945a580670af1000bcfd8e
MD5 fc0521582f84eabc6bcfa2e6703725db
BLAKE2b-256 9d7669acf733154a41e7fccadf55afd0e6a3bb64c515293974b6d9be45342b9a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8d19ad4dbadc2c3d57d7984006264ef04b4ce3bc1753a49d83422cc5d44a913e
MD5 38b70638bd3a0fc540582c643b9b5740
BLAKE2b-256 ea50494392fdee32ecfab48722120c5dfdd8f8a813cfe894f8dbb3e94b382e1c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 066c9ea9cd84be68818c4826f2ad544348086ff0378d026b55ea0db4cc654126
MD5 9eb69448105b7727096740b69e290bf7
BLAKE2b-256 00bfadae9a4b6c4238be2ba66f26be54d0e7367c9da6a0954d695177cf27d5ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 291dfbd0c578a531cfc0e5d2deed9b87a938354a2448caa316d1b7f489647116
MD5 6474d03717a41dc0052966a3b5228e27
BLAKE2b-256 556c9f78af2947c508360191b60f8809b849f2edb97ac469a256a9bd7a3bc305

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.1-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 470a038003b2a40594c92358d7afa389b145d658accc067f0da2f0f867d8c227
MD5 4e6983c62dbfe89b50ecb31ed19cedb9
BLAKE2b-256 da3aa5d41b49457e48d8a5f25b5113e91455ba442ff82392b0dcebdbff751175

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.1-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 e9f9345d165ad6c5d5ecf3eb1cf120ab9a74ad49ca1833c35fd107adedb1163f
MD5 9e696153f26a55de6bed481dab23a486
BLAKE2b-256 be58c1cd3e3887ec9d82ec8e8862a9e51d48ad201172f51ec2f38a4864313751

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3d70bfe8caa5341085bc48c9b1d7aed82d674ff079359a722cbfbf1ccbad3fb7
MD5 9eb96534ed7696c090389da732b7f0a1
BLAKE2b-256 6fa4bc751a4351b87195fd00fd41a3938ef8d628f94cfbcdc6c1881b61194d49

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d7838af35236c2ee089b5854e5ad32c9b87ebaf023e4a622c31463974bfe014e
MD5 8590c36f2f184c41e1fd7a6ca3272c55
BLAKE2b-256 082bd2264fac169d50bac7023a4fd1ae0e7667aafadfa631c6a4328fc9a35b1c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytensor-2.17.1-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.6

File hashes

Hashes for pytensor-2.17.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 b749204fdf2ade541889590791809efa4a44479eb6a3b653204d271fdbeeb190
MD5 5443df0cef7621a4d62643bd1fea89e9
BLAKE2b-256 000396b25007bf740e091f52cf7ea4b0ed96bcaea0b4ddcd4325581da449763c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.1-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 44a46be1e7c5669046743fbe586b85ab93ccd32b4367ef6add02ebebb2fa59f4
MD5 1e78b92541b345988571a650fd78816a
BLAKE2b-256 f9d4ec622328b3d7af57e26eabfcd24518ec1d4708140f9308dd8a07c074f558

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.1-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 648b19b47b325e83910f78b835701b31ff9623faded8f7e0e36ceafe358151c6
MD5 e02d23fee905d04c2eae8216d3d1354d
BLAKE2b-256 fced953cce6070b43bff1ce3a67c7157278faf3f06000ed7fd3b9bf505b69500

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c76a4846277274d6cb4513753fd89146beb3e22a845f0fa296ce17df415a919e
MD5 af0e2f863bc4553dcbdb6dad5e38762f
BLAKE2b-256 616aec8f2f56bdb68d7bad2313cb4dcb2273c31ef97286ae512b3a6cdb43caf5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 17350adb23acdd583764ab78afea2251943cd3c86c8388000c1f2a69cf23ad0b
MD5 164d8c7be7358ed55b552cea3c23a38d
BLAKE2b-256 85571d5c792a39ee1523e9c346ce921ebfe2f51e51ac119625c5aa3d0aab59fa

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