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.

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.0.0.tar.gz (50.1 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.0.0-py3-none-any.whl (60.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: extended_einsum-1.0.0.tar.gz
  • Upload date:
  • Size: 50.1 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.0.0.tar.gz
Algorithm Hash digest
SHA256 ef85c7286b02f50df1d3b6a94d53a7cc29354d3a92abce630c1294b78869a4e5
MD5 0cad94d99dc0aa160affeebae2f941ca
BLAKE2b-256 c6dacb1d550c2141d5cae88201f767d84d08e1f26aec750775383da3cba4f3b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for extended_einsum-1.0.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.0.0-py3-none-any.whl.

File metadata

  • Download URL: extended_einsum-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 60.3 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.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 699e55f7123d6f7b54a3dcbf3fc74a99f75f612165d4d9e1919b4e20e8e7fc3e
MD5 98dd97a4f46ea38927c502ee167cd427
BLAKE2b-256 e9ae1d5500b3af6f47d13e55a3629471e41c919345334815830aff37aba90f57

See more details on using hashes here.

Provenance

The following attestation bundles were made for extended_einsum-1.0.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

1.1.0

2 files

This release

1.0.0 This release

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