Skip to main content

extended-einsum

CI PyPI Python License: MIT

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.

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, and select
  • exp, log, sin, cos, tan, sqrt, inverse, and softmax
  • TensorExpression.materialize and extract_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.

Custom execution backends plug in through extended_einsum.register_backend: subclass extended_einsum.BackendFunctions (only a small set of primitives is abstract; derived operations such as softmax, select, and the arithmetic operators have defaults composed from them), then register it under a name, optionally with a compiler and an is_array predicate for automatic backend detection in xe.array. Without a compiler, programs are interpreted call by call; without a predicate, wrap arrays with xe.array(data, backend="yourname"). Validate an implementation with extended_einsum.testing.check_backend, which runs every operator through every stability mode against the NumPy reference backend.

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

extended_einsum-1.1.0.tar.gz (53.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

extended_einsum-1.1.0-py3-none-any.whl (64.1 kB view details)

Uploaded Python 3

File details

Details for the file extended_einsum-1.1.0.tar.gz.

File metadata

  • Download URL: extended_einsum-1.1.0.tar.gz
  • Upload date:
  • Size: 53.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for extended_einsum-1.1.0.tar.gz
Algorithm Hash digest
SHA256 7401b68e6d1e790a27cd1dbc4a3a0446e833b8ddf12e25dbe40a5ed73c51dc68
MD5 1840e553f1e7e1cf624c7ccf31b8577a
BLAKE2b-256 0c6326ffaf89a5596d36b1cd217aa2da6648f5d59440df339fdcabcfd2beb7de

See more details on using hashes here.

Provenance

The following attestation bundles were made for extended_einsum-1.1.0.tar.gz:

Publisher: publish.yml on ti2-group/extended_einsum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file extended_einsum-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: extended_einsum-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 64.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for extended_einsum-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 84d14b68f9225e5ad7ebc25aef176fbd8cedd82a4d82a7976df108b81219105d
MD5 7ae3a1346de65762a9eba7a16e65471e
BLAKE2b-256 857f261ef845cfe367f74480b88915e0d89d16bfaf5574858f23cc50cea63f49

See more details on using hashes here.

Provenance

The following attestation bundles were made for extended_einsum-1.1.0-py3-none-any.whl:

Publisher: publish.yml on ti2-group/extended_einsum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

1.1.1

2 files

This release

1.1.0 This release

2 files

1.0.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page