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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pytensor-2.18.0-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.0-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.0-cp39-cp39-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pytensor-2.18.0-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.0-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.0.tar.gz.

File metadata

  • Download URL: pytensor-2.18.0.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.18.0.tar.gz
Algorithm Hash digest
SHA256 8ea8f333d7e09860838241b2f84ee2095278aa43410c8ed838735b88b5d57275
MD5 f234337598326a360a872d9db83b69a1
BLAKE2b-256 8bed07223249ffdbbb89f72f6a76367c1dc324433842e5f37bef1b2a75d182ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b1b4c0f21f3e2b3091c29bb3e2c6d10e4e31d1db9b8853294c7144d73029a24c
MD5 e8e8d19f81392cf5ea18d3777ecebbb3
BLAKE2b-256 9d5ce95cb16e7f0ff7f624410e4edd29a8354b8e76c6ed202465bd47a1af8ed9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 d4b4030037f3ee671ef1180c32192a56b0d531f6da550472d4261ec25ca24af0
MD5 c95767db0bc19caa1250b9efaadf2378
BLAKE2b-256 c80a165decc7b7b7d0bebc2f2f26357d41ea83484b451ef6fbad266b9cce882d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.0-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 769c66b4fc762d4191e0d66a914a61bfbf4b6f9a41fbcfe6104dcc71961896aa
MD5 60d40a853da0e68df00657fbf517b853
BLAKE2b-256 54ed00f66daecf04e2867d9197fedd72919629556822510c3f57b0721a0a1904

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 da81d5c944a70b74342a1e31a52d0492cf6362042076b6aa74fbfb349e52848e
MD5 8119db994e3be4949ba189c29e3dc544
BLAKE2b-256 a16b007500ad584145630bbd5e4a895306e206456579a9cd29f63e9d0debf205

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 93f2c4071f2d69b66bcb9062c852128e50a0c6543d36f3c45874260e8d4e3f63
MD5 91eba089e57f82188b58edcfac935241
BLAKE2b-256 87b3bfbf53ea267c286aeac620017d61249b4fe9df386266a5b735e11fd95d89

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f0ce6b3559cf78c7c9c2d98e6c25fe94b767cb0b91f3703f0c7ba28ce3d1b10f
MD5 a234224f04b1fa7b663408746aeea326
BLAKE2b-256 ac2aacc286825fea344895db0fb473d23c4420b735ec22f7d2d2de09f780be9d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 ebedd3b042341ff791dc9ecf24be2530857a01b66217905c60fcd4f60ba0f722
MD5 7acd67f2358a39d3752d75c86096c412
BLAKE2b-256 8f2b2c884b8775210cbc646ac907b2e754b718c14dc5cc54ac2e56d38a6d5a32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.0-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 341f64b0a8f18038a0e7b872689ca87acafa62ae67a5869b3c8028fed5b4f948
MD5 8bd78c7e997ba03a8ba4b36f8700846c
BLAKE2b-256 4965773133b89c0cba729ed1f3ce88640af24f29318ea220f2f21cd64c2e2dcb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ce45f7268cdf801bdd9375a7329095cb63da9776c16636eb56cb50de5824dee5
MD5 d9592f469400e2091ea234025b0c8e97
BLAKE2b-256 a1d1fd94317c8867ef5147459270e54d6adf8eb8a7ee213b8605651bc280bc5b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 01c18e2f6f1511418d03c0a52e62f952da59d05522a44becdd08d15d3515709a
MD5 19f47ce80d1fcb831d22dbcea39af86d
BLAKE2b-256 4eb69ee352f7a85593afa47701c84c31e73cec3661c702dab25a5f206ae86acf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytensor-2.18.0-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.18.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 6d95c10c82fc424fc90142ff4c90e29a7554288103a12ca8a0dd66dd725b9f11
MD5 ee656bdd221c37dda931125f70da1395
BLAKE2b-256 be663f6f5ce4a9a430cbe73185ea7c0e860d61c668a21e2d4b89de2fa9225ab9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 29f33eeb339ed853db1b7510f49c6ec420416ebaf34aef5651e55aaffef8fbce
MD5 6e1657202e6c25ce6f76b7d753370a80
BLAKE2b-256 0b52cc94306e741c86698bb4abb65e2cd581dbb2f0806e65e7dde1e492cdc006

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.0-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 2b7f4bb5c0d67119b37814ed5e64e7b72d02a0f2d69659a1ac3303f6a44f4270
MD5 5031a1e2ab59971e120f8fb4f7fb598d
BLAKE2b-256 1ae5a5aaa33de4f00b61e659a47a4961a55aa9f821d44bda9ac7e2ae6b9108b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e212f7adea3f5d17a9f8c32fba236fe7148702689cbe843c07a561b5e59a65fe
MD5 6403d579a37bc3e76b7bb97c5a4488c3
BLAKE2b-256 d99399879a794ebfbc9a2e3d4aac700bb09830de0b93074e48e50631fad361f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d99983cd20584f82ff64836f7ef306fb17a4f532124c579ac6aebbea67925cb3
MD5 0bedefc4c6591ff5834ec2a045db60e7
BLAKE2b-256 cfaf3e3cc1542c8f7dc643378c0c451271482a4bee6026e78e61b4299edc6189

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