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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

pytensor-2.18.4-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.4-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.4-cp310-cp310-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pytensor-2.18.4-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.4-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.4.tar.gz.

File metadata

  • Download URL: pytensor-2.18.4.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.4.tar.gz
Algorithm Hash digest
SHA256 bc7f03b177ed2e1c4c0a42cde3ded8fccf55787a21770d7802fb878fdca97a34
MD5 e49fecf0408edf3d231d3217aaa29c3f
BLAKE2b-256 8854a30508766e35ca3aed94eef171d09beeafa3afc437617a47b75d42cdc35f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 69327ad1d85b49beeddd799139a1a37801e60e8ae7c24851d22479ef79dac2ae
MD5 7934f76700569f87dc9a10ab776df6ca
BLAKE2b-256 fc38eaf750be4d5c522917962978bb99f11e2a3c97d050b7fc9d59b4f8a3c8cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.4-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 c12c70acf29e6ff4b206f7fc272fdb31a5180cb680c565f72cbfdfb72f9b66f1
MD5 a55b677e602167d1431ec66830e6f997
BLAKE2b-256 19e209969ab21a61aca99e8f5653dd2c6ca15d1abeaaa10b5d775e054ce377fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.4-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 c70171c1e3c34fa853155fbc919e3503a1d1b5097c857e405ffd6476c00e0441
MD5 8f4917db18edbce248870f863ed4a524
BLAKE2b-256 7381f2aa950bcc899cb750f90526fa55f49906fd58a7942a88a5fcfd065c7bf7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4d474b577ee084b20fb73519369af52ad1c77b1979b38a3671d1c4e46242527e
MD5 04a2f72d478f5878f7ff4e9c83621f79
BLAKE2b-256 15fa72eb55216a5ca10ce8a6d212c675aa2012a75e7140fdd00dd9a492927b5f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.4-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5cfc4c448bfea2a42e4d7fc578102492d1477cc85cfb613eec8a7aa94f80a23f
MD5 c89b61d3e47edd059afb8c0866b60ed0
BLAKE2b-256 e35ebd6660507245b232501f9572c620a734e2e5e25de963a2a5428455ca7af6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a3125e99f6ab226db473e1389c286a171c7901978f11b576f54190621feb79a0
MD5 5884b8bb17dce1faebee121d888b529e
BLAKE2b-256 94983304f4b2a5ec45a6f2ea6e394d4121cc03980760652321c86c53fe1c788b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.4-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 5da085318d9545666b1e9fd433dc28f474c0c7c6139b39882b00195635058a9b
MD5 8af551e16fdacb856dcef82e055619e5
BLAKE2b-256 386166d864d2a3c58da59fe193ebe248e045d59f09f744e39f382b7201832ffa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.4-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 bd5d4b6130a6ea41d0cd71668531f7dec722bbceb3af06c7763634b154ea6db5
MD5 13ace3c6bcdbaa6e67cb8d86b8bcaccf
BLAKE2b-256 63d8a38eec515a10d18c9b963c88f44f9c0a94455546410fd5765045ca0c36f6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 05a217a305a858d0efb054225e73b1e1a02d9d2bca73dcf2741d2f8863d5d867
MD5 7bde866a50e4f1913647e589ffaf454c
BLAKE2b-256 7c29dc5ed0fab91db156526dd6903241ea98cc6e7a2c9e40820c210eff151f77

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.4-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5515365a34ca036b1c8db76e5e4e0b163bfc7d78813bfcb91ccf0a237fc92153
MD5 a0c84fbbcf9dff9a65443985ec557e70
BLAKE2b-256 0afa53aee12f3dd413698f69148459ce6b0b4aa2bb518c4408dbdcec5c6a5246

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytensor-2.18.4-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.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 70d6c9e3fe10ba4df3ec0e138b7094aeef84f089122a0372b5a1296fd815c09d
MD5 c4eb41f62255d317ccbdc81476395d76
BLAKE2b-256 14b5efbb3e37f34898c6c09c055207f0666d5391af261b996b2fa817986700d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.4-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 d604ade399cf6298459ad5eb05614f3856d170edfe0d573f559fa802fe6aecaf
MD5 adaf1065b56f488485d405d15163e1d8
BLAKE2b-256 95ec274d17e67bb4b32abd4c1ffd3cf90437659403c993a0cc863640170b3e7f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.4-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 bf7e5e464c838fea5e9be8c354f39c7e46bfd48c5c6c5e82a0801adb2954d3c8
MD5 09543ff575a93f590daa895a171bf3f5
BLAKE2b-256 9127ba02e1a3f88937dbd1d0973d2ae3f70e745d83d75c8be390b4ad2bb16b97

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 da9941c0d6c3736024aa86dc7ab9b208eff287024273fce355277c458968d9aa
MD5 0ebbabdd656ffa8024da931b6e63c6d8
BLAKE2b-256 bf5b9c933f15b9830313dc3f6d64f72f5af9b7158875b033efc81f8df1dc7325

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.4-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 bc50f9bab8bd3a77841ced7d54a07ec2e624955abb1a3588b6c64f84d0ba1f3a
MD5 a9c881d482073bb4b0b77e71db40e84b
BLAKE2b-256 8539cba0dac2cd26c7619560df3439f9834b31629f83ac17c9e085e429aa9aec

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