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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pytensor-2.17.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.17.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.17.2-cp39-cp39-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pytensor-2.17.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.17.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.17.2.tar.gz.

File metadata

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

File hashes

Hashes for pytensor-2.17.2.tar.gz
Algorithm Hash digest
SHA256 77750f370739b565ac341e7868196765c7b0f1c3d7364eebf326a822f50997fe
MD5 a869709a40fcc384d2e47eee37816e70
BLAKE2b-256 4e9aaf374ed77d5f2477f0563a5e405669fcf200dad563fc915bdb193415c01f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 904f6c132937b4617451993e48bfc12da57ff8bd2bff83e37e8b019cb2331fb4
MD5 a04855068e6d0641aac6a73e2a7061b5
BLAKE2b-256 dcfa9fbe7cf688b320ac9ec3c09219d0659177273b4288c817eae94f0a9c94bc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.2-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 d27056bcf0e93924a60edf6d0e73d76948835324f8eca2f6b8a63de22479e74d
MD5 a408c6ebacb3f429a0aa48e03cebc947
BLAKE2b-256 bdf3a057e389910d9c520164a0b23c1557624fc513ee604b1a90996e0e98776e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.2-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 558e2bf5e1640656a60c4cbeefefde764efa9e769dd0afc10b49d6c2ed1db363
MD5 734f35f6773ed33aedca85618b18bff4
BLAKE2b-256 6e58b9b101d25d233130fdf6c8b60eaebef0895cb32b4835b68a2bb2526a3043

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5c6c05be3e47928f4af03bbda1c5147410a3954d4fcb704661d2617da81830ab
MD5 f15ef773d72f5595b2c5c322e117954b
BLAKE2b-256 4a34ac56448555ba478270aba60464cdfd2c22bad9999f3c388e0a544354c430

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 bd682bc36bfe6c650f3966de00d6beb0939ea1175b07215fe044e4124a9f0fdb
MD5 454009bddb02611adb8c9c8b43305dc2
BLAKE2b-256 d8b3b23ff5a6f5c001a1605cf174896ddadb1bc63f0b21112d85064965680382

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 72b8de89326c7241d08b6c1c73bff8190170cb004b1f2515e9c92ac0f9b3768b
MD5 a73cf191d0ac6f58263622fedf375bd1
BLAKE2b-256 f319f0b6dd4881e07c1ff0bee3ae1afa09ea8af483ff4e5f5363dd5d2c4e8cba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.2-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 0ee6471aa6dbd659edcabbae3cf40a6bf811142008f5d7afd178c2bd1580de5f
MD5 c98acfbd98c732942a8df7bcd42960d9
BLAKE2b-256 ac01e1223b84121e24f8fcf57c9acc36ab2a0b707968c2dd164a94bbb25bc670

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.2-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 dd720d84ec9a5f5c896dd8e7986c816f4639aa3fb8ffc2e1a2cfe70ac0e42047
MD5 6c4bc78d3df1a060e06937a1e0b59825
BLAKE2b-256 de8a694f6c48f8402c7f9245fad52e558baa3f529f04c14adf8b5eedc091fda0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 589ed8e2657237c941694e9d7983e9617240dda8dea20dccaa3ff400f906161e
MD5 5b14985bc20dfe27ea61c78c3437ac5a
BLAKE2b-256 8f5bcab212ca7fbad7987cc3cb957886856df6e31ea970e13ffe3b6c48fe4590

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 08648aceb2b823e59ec8a5810fb389e77e93a031dfa5101372f3cf8438153a4b
MD5 7013f4f1afb30fbe78d483198d753027
BLAKE2b-256 3730257a85d5e0ea372873702b2830cf262ff4d65a3190e361de83b1625de417

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pytensor-2.17.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 dd59de9cc492e16c2326267d83878e632d7b29585e3f264255a92e270cb5b7cd
MD5 2ad69b96a3ae12b087707e6f7e21ef97
BLAKE2b-256 c5f3679423e820f3c1ea537b87ecc2abd6b856cd2247847b0f85ebade59799dd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.2-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 420c146387ba1c29b92de3fbb09e8b27138c130880377303c6edb2cb273b7523
MD5 f4a218938a0ec9f46d3fa8c294e241ab
BLAKE2b-256 831942660f20bdc7681f21b6242edfe1948837b6c3069510740d2d74928c8e87

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.2-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 7396cf946d66cda6aea1288a9250452f28391933605354abd05f4121eb675a53
MD5 fd47c77d3cbe3fd280b40d0884bbcbdf
BLAKE2b-256 2c5bb4890d1d8125bd0e718576acca84f6d4fdcd97a79ee89bc93def7a07f763

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5f4a2f65f7960bd17d36a34fd1e7f1d51aaa7cdc63e54b114856f7493af9a6b0
MD5 bd51b515276cfef366d40a75d89d725f
BLAKE2b-256 b1e741956b1622b610efbfe5095499455e8e5cff2a3735b844416ae4c60f3076

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 3c297451f36db0e11c26f350e068fd1163f522c8f39e9d8c468d86ce1ea6d907
MD5 7e8c7b95e0608ac7e57e308b14eae4e4
BLAKE2b-256 bb365e0862c959ee2787bf568c1d4d226ef91457b3ad36c947e6788835c187da

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