Skip to main content

Fast arithmetics for quantum operators (Pauli strings & Hamiltonians).

Reason this release was yanked:

Wheel broken for windows

Project description

PauliEngine — Fast Arithmetic for Quantum Operators

A C++ core with a nanobind Python frontend for working with Pauli strings and qubit Hamiltonians. Coefficients can be numeric (std::complex<double>) or fully symbolic (SymEngine).

See arXiv:2601.02233 for the algorithmic background.

Status. Functional core with a large test suite. The Python API surface is stable. Sphinx docs are not published yet.


Highlights

  • Binary symplectic representation — multiplication, commutators, and hashing are O(n / 64) over the qubit count.
  • Two coefficient backends — numeric (complex<double>) and symbolic (SymEngine::Expression); cross-type arithmetic is handled automatically and type-promotes the way you expect (any symbolic term → the whole Hamiltonian becomes symbolic).
  • Compaction invariant — every operation that returns a QubitHamiltonian merges duplicate-operator terms and drops zero-coefficient terms. You never need to call simplify() for correctness.
  • Tequila-compatible APIqubits, n_qubits, is_hermitian, is_antihermitian, dagger, conjugate, transpose, simplify(threshold), split, map_qubits, power / __pow__, to_matrix, paulistrings, count_measurements, is_all_z.
  • OpenFermion bridge — the QubitHamiltonian factory accepts an openfermion.QubitOperator directly; to_openfermion and from_openfermion helpers are available.

Quickstart

import pauliengine as pe

# A single Pauli string: dict-of-operators style.
p1 = pe.PauliString(1.0, {0: "Z", 1: "X"})

# Symbolic coefficient — anything coercible to a SymEngine Expression.
p2 = pe.PauliString("a", {1: "X"})

# OpenFermion-style: PauliString((coeff, [(Pauli, qubit), ...]))
p3 = pe.PauliString((1.0, [("X", 0), ("Y", 2)]))

# Build a Hamiltonian from a list of PauliStrings (or (coeff, dict) tuples).
H = pe.QubitHamiltonian([p1, p2, p3])

print(H.qubits())        # [0, 1, 2]
print(H.is_hermitian())  # True
print(H.dagger())        # for Hermitian H this is just H

Tests are in tests/:

pytest tests/

Construction

pe.PauliString accepts several input shapes:

pe.PauliString(1.0, {0: "Z", 1: "X"})         # dict input
pe.PauliString(1.0, "X0 Y1 Z2")               # space-separated string input
pe.PauliString((1.0, [("X", 0), ("Y", 2)]))   # OpenFermion-style (coeff, list)
pe.PauliString("a", {0: "X"})                 # symbolic coefficient

pe.QubitHamiltonian accepts:

pe.QubitHamiltonian([ps1, ps2, ...])                       # list of PauliStrings
pe.QubitHamiltonian([(1.0, {0: "X"}), ("a", {1: "Z"})])    # list of tuples
pe.QubitHamiltonian(openfermion_qubit_operator)            # see OpenFermion bridge
pe.QubitHamiltonian.zero()                                 # empty Hamiltonian
pe.QubitHamiltonian.unit()                                 # identity (single term, coeff 1, no ops)

If any term in the list is symbolic, the resulting Hamiltonian is symbolic.


Arithmetic

# PauliString * PauliString, with the right factors of i from Pauli algebra.
p4 = pe.PauliString(1.0, {0: "X"}) * pe.PauliString(1.0, {0: "Y"})  # -> 1j * Z(0)

# Scalar multiplication on both sides; +, -, unary -, and addition between
# PauliStrings (returns a QubitHamiltonian).
H1 = p1 + p2 - p3
H2 = 0.5 * H1 + (-H1) * 2j
H3 = H1 ** 3                  # integer powers
c  = H1.commutator(H2)        # commutator (also available on PauliString)

Cross-type multiplication (numeric × symbolic) is supported and promotes the result to symbolic.


Inspection and properties

H.size()                # number of Pauli-string terms (also len(H))
H.qubits()              # sorted list of qubits with non-identity operators
H.n_qubits()            # len(H.qubits())
H.is_all_z()
H.is_hermitian()        # True iff every coefficient is real
H.is_antihermitian()    # True iff every coefficient is purely imaginary
H.count_measurements()  # 1 if all-Z, else len(H)

For a single PauliString:

ps.size()               # number of non-identity Pauli ops (also len(ps))
ps.count_y()            # number of Y operators (used by conjugate/transpose)
ps.naked()              # same operator with coefficient 1
ps.key_openfermion()    # OpenFermion-style key
ps.get_pauli_at_index(q)  # "I" / "X" / "Y" / "Z"

Transformations

H.dagger()           # complex-conjugate each coefficient
H.conjugate()        # complex conjugation (flips a sign per Y operator)
H.transpose()        # transpose (flips a sign per Y operator, no conjugation)
H.simplify(1e-10)    # drop terms with |coefficient| <= threshold
H.split()            # -> (hermitian, anti_hermitian) pair (numeric coeffs only)
H.map_qubits({0: 5, 1: 2})
H.power(3)           # also via H ** 3

split() and to_matrix() require coefficients that evaluate to a complex number — call H.subs({...}) first on symbolic Hamiltonians.

Dense matrix

import numpy as np

M = np.array(H.to_matrix())                          # 2**n x 2**n, ignores unused qubits
M_full = np.array(H.to_matrix(ignore_unused_qubits=False))  # absolute qubit indices

Symbolic coefficients

Any string coefficient (or SymEngine::Expression from C++) makes the term symbolic. Symbolic PauliStrings and Hamiltonians support every arithmetic operation plus:

H = pe.QubitHamiltonian([("a", {0: "X"}), ("b", {1: "Z"})])

dH = H.diff("a")            # symbolic derivative
H2 = H.subs({"a": 2.0})     # substitute and evaluate

diff is also available on PauliString. Mixing symbolic and numeric inputs is fine: the factory scans every element and uses the symbolic builder if needed.


OpenFermion bridge

from openfermion import QubitOperator
qop = 1.5 * QubitOperator("X0 Y1") + 0.5j * QubitOperator("Z2")

# Factory accepts QubitOperator directly:
H = pe.QubitHamiltonian(qop)

# Or use the explicit helpers:
H = pe.from_openfermion(qop)
qop_back = pe.QubitHamiltonian.to_openfermion(H)
assert qop == qop_back

openfermion is an optional dependency — from_openfermion / to_openfermion import it lazily and raise ImportError with a helpful message if it is missing.


C++ usage

The library is a header-only template under include/pauliengine/. Both PauliString<Coeff> and QubitHamiltonian<Coeff> work for Coeff = std::complex<double> and Coeff = SymEngine::Expression. Every operation exposed in Python is available in C++ with the same name.


Installation

From PyPI

pip install pauliengine

Prebuilt wheels are available for Linux (x86_64/aarch64), macOS (arm64) and Windows (x86_64/arm64) on Python 3.10–3.13. Installing from the source distribution requires the build dependencies below.

Build dependencies

  • A C++20 compiler (MSVC 19.3+, GCC 11+, or Clang 14+)
  • CMake 3.20+
  • Python 3.10–3.13
  • Conan 2 (to pull in SymEngine)
  • nanobind (build-time)

Install from source

pip install conan
conan profile detect
conan install . --output-folder=build --build=missing
pip install .

The CMake build picks up the Conan toolchain from build/conan_toolchain.cmake. For an editable / development install use pip install -e . instead of pip install ..

Windows notes

If you are on Windows and have not built SymEngine before, the Conan step will build it from source on first install — that takes a few minutes. Subsequent builds use the cached artifact.

Performance note. PauliEngine can be built without SymEngine, but symbolic coefficients are unavailable in that mode and the runtime cost of certain numeric paths increases.

macOS prerequisite

Conan does not currently ship a prebuilt SymEngine binary for macOS. Build it from source once before the main install step:

conan install --build=symengine/0.14.0

Subsequent installs pick up the cached artifact, so this only needs to be done the first time.


Testing

pip install pytest
pytest tests/

Citation

If you use PauliEngine in academic work, please cite arXiv:2601.02233.

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

pauliengine-0.1.2.tar.gz (57.6 kB view details)

Uploaded Source

Built Distributions

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

pauliengine-0.1.2-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pauliengine-0.1.2-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (1.7 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

pauliengine-0.1.2-cp312-abi3-macosx_15_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.12+macOS 15.0+ ARM64

pauliengine-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pauliengine-0.1.2-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (1.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

pauliengine-0.1.2-cp311-cp311-macosx_15_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

pauliengine-0.1.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pauliengine-0.1.2-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (1.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

pauliengine-0.1.2-cp310-cp310-macosx_15_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.10macOS 15.0+ ARM64

File details

Details for the file pauliengine-0.1.2.tar.gz.

File metadata

  • Download URL: pauliengine-0.1.2.tar.gz
  • Upload date:
  • Size: 57.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pauliengine-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4a0530a3f0a50f10f87edb3ac43c98fb1e0a79bd00c816e5af5e30e159a6eb96
MD5 3f3f9e25a042526b2e5279180b901b5d
BLAKE2b-256 a0cbffc7130c9832dc9280f90401188f45a6f102b1fabd3a0e04f7c11181bf30

See more details on using hashes here.

Provenance

The following attestation bundles were made for pauliengine-0.1.2.tar.gz:

Publisher: deploy.yml on tequilahub/pauliengine

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

File details

Details for the file pauliengine-0.1.2-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pauliengine-0.1.2-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ab9101d1ae211599456e9b19a5ce0bfd31cd8944003fa6179102f1748af88653
MD5 3e226d83c425b18f1765fbcd49ead0c8
BLAKE2b-256 58c32677618a877e076c6d1d2b8f1f114418321329d8686ec352a88f343ba9b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pauliengine-0.1.2-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: deploy.yml on tequilahub/pauliengine

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

File details

Details for the file pauliengine-0.1.2-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pauliengine-0.1.2-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 19bd5abeb1525bd738c27f8ebaa489041c1d827c79a14a1bb9d9eb63b276ba29
MD5 6afad0b41b8187397ed26da6b6e42fef
BLAKE2b-256 923624a550aa556308c7cfa2bf57847290d3225cd5a599e1ffef6471f7d2f95d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pauliengine-0.1.2-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl:

Publisher: deploy.yml on tequilahub/pauliengine

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

File details

Details for the file pauliengine-0.1.2-cp312-abi3-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pauliengine-0.1.2-cp312-abi3-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 b54d8ec009788ca175e899c356439a65f6f42f45f88f164dbc47a6c629adfe4b
MD5 804f5799dd429f3e5e37b5fc4d127c53
BLAKE2b-256 d2580bada1373cbcda88056cbe2173030dbc80f8bf3155a70b4b1f75393b1e4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pauliengine-0.1.2-cp312-abi3-macosx_15_0_arm64.whl:

Publisher: deploy.yml on tequilahub/pauliengine

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

File details

Details for the file pauliengine-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pauliengine-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5415144f267d4b2a9ca1dde5491454804ffb5a8b866f3cbbf75be7337cbf5552
MD5 b446eedb8fc1ab9f9feea888ae17077f
BLAKE2b-256 ad4ef59dec5e922d47c8161b54307a7ae432bdec8ff9b60bf517b42802d7d382

See more details on using hashes here.

Provenance

The following attestation bundles were made for pauliengine-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: deploy.yml on tequilahub/pauliengine

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

File details

Details for the file pauliengine-0.1.2-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pauliengine-0.1.2-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 811641172ed4982831a7760f50b966d0838d81da11d48fead823657e6fafa72d
MD5 ca4190e99ee26be56b5dff46a77d3840
BLAKE2b-256 08922cfaf4de68aa95f4d015a2842e81d88062876b05b5978de0146c009e697c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pauliengine-0.1.2-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl:

Publisher: deploy.yml on tequilahub/pauliengine

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

File details

Details for the file pauliengine-0.1.2-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pauliengine-0.1.2-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 48c165e5a173ee9263520660c470584d3b9fa2148cfaff122d691d660abf9140
MD5 e800a4a8ce2b4aeff3924c0965e80ce9
BLAKE2b-256 055fa03a60cdb89cd77ffca15f9ca3d5eaee84edea90e73151df093e2b6b830a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pauliengine-0.1.2-cp311-cp311-macosx_15_0_arm64.whl:

Publisher: deploy.yml on tequilahub/pauliengine

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

File details

Details for the file pauliengine-0.1.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pauliengine-0.1.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 06fd5f063ca2d69a20774b05eb5962a40ed4ac04807d239ba679c69492eea557
MD5 6b58ef600941e71dcb5d8285caf94e16
BLAKE2b-256 0561c1f945cebd2242b393e48e972b1d230bcc80699116a55a000a3c15b0839c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pauliengine-0.1.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: deploy.yml on tequilahub/pauliengine

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

File details

Details for the file pauliengine-0.1.2-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pauliengine-0.1.2-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 5c0f93ff6866491419248315e0c8d5b9057d66d9c9b1500ebbfbcfa437437ccf
MD5 afdfde80266e4ca67a9d8be86ede7304
BLAKE2b-256 53ac2c46d1debf5c58bb277ce348adac6b831ae6ecca392ee2d1538d4d7d5e17

See more details on using hashes here.

Provenance

The following attestation bundles were made for pauliengine-0.1.2-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl:

Publisher: deploy.yml on tequilahub/pauliengine

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

File details

Details for the file pauliengine-0.1.2-cp310-cp310-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pauliengine-0.1.2-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 f9d22020ef9740000a1496b692a162f5016fc67f5e9961d3c1d8f5c97bd4e068
MD5 c2191896e8c2799929c79b36b5b93449
BLAKE2b-256 3f25ae8162b0600234c4f48639e823c4c4413daf2103001dc3fe14707abdd5d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pauliengine-0.1.2-cp310-cp310-macosx_15_0_arm64.whl:

Publisher: deploy.yml on tequilahub/pauliengine

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page