Build, optimize, and execute numerically stable extended Einstein summation expressions with PyTorch, NumPy, and optional JAX.
Project description
extended-einsum
extended-einsum builds tensor-expression graphs, rewrites contraction programs, and executes them with numerically stable evaluation strategies. PyTorch is the primary backend; NumPy is included in the base installation and JAX is optional.
The package is an expression engine, not a drop-in replacement for torch.einsum or numpy.einsum. Wrap backend arrays with xe.array, compose operations lazily, then call materialize.
Status:
0.1.0is an alpha release. The public expression API is usable, but indexing and some operators or stability-mode combinations are not implemented yet.
Installation
Python 3.12, 3.13, and 3.14 are supported.
pip install extended-einsum
Optional features are installed explicitly:
pip install "extended-einsum[jax]"
pip install "extended-einsum[jax-cuda]"
pip install "extended-einsum[visualization]"
The CUDA extra follows JAX's CUDA 13 installation. PyTorch device support is determined by the PyTorch build available from your configured package index.
Quickstart
import torch
import extended_einsum as xe
left_torch = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
right_torch = torch.tensor([[2.0, 0.0], [1.0, 2.0]])
left = xe.array(left_torch)
right = xe.array(right_torch)
expression = xe.einsum("ik,kj->ij", xe.exp(left), right)
result = expression.materialize(stability_mode="unstable")
assert torch.allclose(
result.backend_array,
torch.einsum("ik,kj->ij", torch.exp(left_torch), right_torch),
)
The same interface accepts NumPy arrays. With the jax extra installed it also accepts JAX arrays:
import numpy as np
import extended_einsum as xe
source = xe.array(np.arange(6.0).reshape(2, 3))
result = xe.softmax(source, axis=1).materialize()
print(result.backend_array)
Expressions and stability
The public interface currently includes:
array,einsum,stack,take,slice, andselectexp,log,sin,cos,tan,sqrt,inverse, andsoftmaxTensorExpression.materializeandextract_program
Supported execution backends are PyTorch, NumPy, and optional JAX. Rich programs can be evaluated in unstable, scaled_min, scaled_sum, logspace_min, or logspace_max mode. Support is operator-dependent; unsupported combinations raise NotImplementedError instead of silently changing semantics.
The preprocessing API also provides expression folding and contraction-path optimization. DAG plotting is available from extended_einsum.visualization when the visualization extra is installed.
Examples
All introductory scripts in examples/ are standalone: copy one into another project with extended-einsum installed and run it from any working directory.
python examples/torch_quickstart.py
python examples/numpy_backend.py
python examples/stable_materialization.py
python examples/jax_backend.py # requires [jax]
python examples/visualize_expression.py graph.png # requires [visualization]
The advanced demo/cirkit.py integration is also standalone, but requires the repository demo dependencies and currently Python 3.12 or 3.13 because of Cirkit's SciPy constraint. Its defaults use a small synthetic circuit; training and benchmark sweeps are opt-in. Generated benchmark data and plots are repository artifacts and are never included in distributions.
Development
This project uses uv:
uv sync --group dev --group demo --extra jax --extra visualization
uv run ruff check .
uv run pytest
uv build
See CONTRIBUTING.md for development details and PUBLISHING.md for the release process.
License
Copyright © 2026 FSU Theoretical Computer Science II. Distributed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file extended_einsum-0.1.0.tar.gz.
File metadata
- Download URL: extended_einsum-0.1.0.tar.gz
- Upload date:
- Size: 44.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2aab2c7bdab90336f5a560ea3bcd0cfe54407ca98fb23f3a1cc379058ebcbd8d
|
|
| MD5 |
49659919d4bdfb58b80a5cb0643ae04b
|
|
| BLAKE2b-256 |
73de97788ce8c970815e96941762237cd2db3e2adcec0a26e38ec91c35293d9c
|
Provenance
The following attestation bundles were made for extended_einsum-0.1.0.tar.gz:
Publisher:
publish.yml on ti2-group/extended_einsum
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
extended_einsum-0.1.0.tar.gz -
Subject digest:
2aab2c7bdab90336f5a560ea3bcd0cfe54407ca98fb23f3a1cc379058ebcbd8d - Sigstore transparency entry: 2186979273
- Sigstore integration time:
-
Permalink:
ti2-group/extended_einsum@73b51e558549a4bc94e5f2e5fd5f05a55adf3c7a -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ti2-group
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@73b51e558549a4bc94e5f2e5fd5f05a55adf3c7a -
Trigger Event:
release
-
Statement type:
File details
Details for the file extended_einsum-0.1.0-py3-none-any.whl.
File metadata
- Download URL: extended_einsum-0.1.0-py3-none-any.whl
- Upload date:
- Size: 54.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bdd62e454cd1202c5367ff8b9199c3cf97a921df7132235809c733978528d28a
|
|
| MD5 |
491fce09713f403f39d67d7c4fca642a
|
|
| BLAKE2b-256 |
33f7f800a4daa4d1dc8165eb29a9dfb039037637e20a6da465cdd70bce453d58
|
Provenance
The following attestation bundles were made for extended_einsum-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on ti2-group/extended_einsum
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
extended_einsum-0.1.0-py3-none-any.whl -
Subject digest:
bdd62e454cd1202c5367ff8b9199c3cf97a921df7132235809c733978528d28a - Sigstore transparency entry: 2186979280
- Sigstore integration time:
-
Permalink:
ti2-group/extended_einsum@73b51e558549a4bc94e5f2e5fd5f05a55adf3c7a -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ti2-group
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@73b51e558549a4bc94e5f2e5fd5f05a55adf3c7a -
Trigger Event:
release
-
Statement type: