Skip to main content
TenCirPauli logo

TenCirPauli

Fast, Rust-native Pauli algebra and quantum-circuit primitives for TensorCircuit.

CI status Documentation PyPI version Python versions PyPI downloads GitHub stars Apache 2.0 license

TenCirPauli brings a compact Rust core and a Python-first API to the Pauli-heavy parts of quantum workflows. Build Hamiltonians, group measurements, reduce symmetries, work in fixed-particle-number sectors, and propagate observables without leaving the TensorCircuit ecosystem.

Why TenCirPauli?

Workflow What you get
Pauli algebra Canonical words, products, phases, commutation, support, and deterministic term aggregation.
Hamiltonians Dense, COO, CSR, matrix-vector products, and reusable native or TensorCircuit backend plans.
Measurement and symmetry QWC/general commuting groups, Z2 tapering, and U(1) sector restriction.
Native circuit execution Fixed-particle-number circuits, deterministic Pauli propagation, gradients, and stochastic Pauli-path estimates.
Structured fermion workflows Majorana algebra, Jordan–Wigner/parity/Bravyi–Kitaev plans, exact additive charges, and guarded restricted sectors.

Install

python -m pip install tencirpauli

Released wheels target CPython 3.9+ on Linux x86_64/aarch64, macOS x86_64/arm64, and Windows x64. A matching wheel does not require a local Rust toolchain.

Quick start

import tencirpauli as tcp

hamiltonian = tcp.PauliOperator.from_terms(
    2,
    (("XX", 0.5), ("ZI", -1.25j)),
)

matrix = hamiltonian.compile(target="dense")
print(matrix.shape)  # (4, 4)

For a complete circuit example, see examples/ and the TensorCircuit integration guide below.

Built for the ecosystem

TenCirPauli is designed for TensorCircuit users, while its Rust core remains independent of Python and TensorCircuit. The public package is distributed on PyPI with wheels and an sdist; source builds require Rust 1.85+, Cargo, and maturin.

Architecture

TensorCircuit / Python facade
        │
        ├── PauliOperator, grouping, symmetry, backend MVP
        ├── U1Circuit
        ├── PropagationCircuit       (deterministic native facade)
        ├── SPPSCircuit              (stochastic native facade)
        └── Majorana/mapping/charge  (structured Phase 7.5 facade)
        │
        ▼
PyO3 batch boundary
        │
        ├── Rust U(1) restricted-state executor
        ├── Rust deterministic Heisenberg propagation executor
        └── Rust stochastic Pauli-path executor

The three circuit facades share Python-level construction, parameter and objective conventions. Their native executors remain independent because they implement different numerical contracts.

Core conventions

External Pauli codes are 0=I, 1=X, 2=Y, 3=Z. Internal packed words use qubit zero as the least-significant bit. Matrix and TensorCircuit computational-basis interfaces use qubit zero as the most-significant bit. Coefficients are complex128-compatible, duplicate Pauli terms are aggregated deterministically, and public arrays are returned read-only where the API promises immutable results.

Main objects

Task Entry point
Pauli algebra PauliWord, PauliOperator
Hamiltonian targets .dense(), .coo(), .csr(), .mvp()
Reusable native MVP .native_mvp_plan()
TensorCircuit backend MVP .backend_mvp_plan(), backend_mvp()
QWC/general grouping .group_commuting()
Z2 symmetry/tapering .find_z2_symmetries(), .taper_z2()
Fixed-particle-number operator U1Sector, .restrict_u1()
Fixed-particle-number circuit U1Circuit
Majorana algebra and fermion mappings MajoranaOperator, FermionQubitMapping
Additive-charge sectors AdditiveCharge, ChargeSector, .restrict_charge()
Deterministic Pauli propagation PropagationCircuit (advanced GateTape/PropagationEngine remain available)
Stochastic Pauli-path estimation SPPSCircuit (low-level SPPSEngine remains available)

Structured operator algebra

Phase 7 adds FermionOperator, BosonOperator, QuditWeylOperator, and OperatorSpace for canonical fermionic CAR, symbolic bosonic CCR, hybrid mixed-radix layouts, and uniform-dimension Weyl words. Fermions map through Jordan–Wigner; boson cutoffs are required only at finite compilation and use the projected open-boundary Fock convention. The batch OperatorBuilder is available under tencirpauli.advanced.

Phase 7.5 adds exact MajoranaWord/MajoranaOperator conversion, reusable Jordan–Wigner, parity, and Bravyi–Kitaev occupation mappings, and integer AdditiveCharge/ChargeSector workflows. Charge sectors use exact conservation checks, infer simple finite boson bounds, retain uncharged qudit spectators, and expose guarded dense/COO/CSR plus matrix-free restricted plans. See examples/majorana_charge.py and the frozen phase-7.5-spec.md.

Finite targets are selected explicitly with compile("dense" | "coo" | "csr" | "native_mvp" | "backend_mvp"). Dense/COO/CSR and native MVP are available for guarded finite structured layouts. backend_mvp is available for Pauli plans and uniform pure-qudit Weyl plans through direct TensorCircuit NumPy/JAX backend operations; finite boson and mixed-dimension hybrid backend plans raise NotImplementedError rather than falling back silently. See examples/structured_algebra.py for an executable example.

Common circuit facade

Phase Alpha defines the target Python contract for the three circuit classes. The circuit structure is built once; runtime values are supplied as a parameter vector.

import tencirpauli as tcp

p0 = tcp.Parameter(0)
p1 = tcp.Parameter(1)

circuit = tcp.U1Circuit(nqubits=4, particle_number=2, occupied=[0, 1])
circuit.iswap(0, 1, theta=p0)
circuit.rzz(1, 2, theta=2.0 * p1 + 0.1)

hamiltonian = tcp.PauliOperator.from_terms(
    4,
    (("XXII", 0.5), ("YYII", 0.5), ("ZIZI", -0.2)),
)

result = circuit.value_and_grad(
    hamiltonian,
    parameters=[0.2, -0.3],
)
energy = circuit.expectation(hamiltonian, parameters=[0.2, -0.3])

The same high-level shape is used by the implemented PropagationCircuit and SPPSCircuit facades:

circuit = tcp.PropagationCircuit(nqubits=4, initial_state=tcp.ZeroState())
circuit.ry(0, theta=p0)
circuit.cnot(0, 1)
circuit.rz(1, theta=p1)

result = circuit.value_and_grad(hamiltonian, parameters=[0.2, -0.3])
energy = circuit.expectation(hamiltonian, parameters=[0.2, -0.3])

Parameter reuse means shared differentiation. A static theta=0.2 is not a differentiable parameter. Concrete NumPy arrays, Python sequences, and concrete JAX arrays are converted to host contiguous float64 vectors for native calls. Native circuit calls are not JAX-traceable; use the backend MVP path when the computation must remain inside a JAX graph.

The current implementation contract and rollout status are recorded in docs/vibe/phase-alpha-spec.md.

Backend MVP

Use the TensorCircuit backend path when JAX/JIT/autodiff or a TensorCircuit backend tensor must remain active:

import numpy as np
import tensorcircuit as tc
import tencirpauli as tcp

tc.set_backend("numpy")
tc.set_dtype("complex128")

h = tcp.PauliOperator.from_terms(2, (("XY", 0.5), ("ZI", -1.25j)))
plan = h.backend_mvp_plan()
state = np.arange(4, dtype=np.complex128)
result = tcp.backend_mvp(plan)(state)

The plan structure is static; coefficients may be supplied as backend tensors where the plan API permits it. This path is distinct from native deterministic or stochastic circuit gradients.

Existing low-level propagation API

The low-level API remains available when an Agent needs explicit tape or engine control:

from tencirpauli import advanced

tape = advanced.GateTape(3)
tape.h(0)
tape.cnot(0, 1)
tape.rz(1, parameter=0)

observable = tcp.PauliOperator.from_terms(3, (("ZII", 1.0),))
engine = advanced.PropagationEngine(tape, observable, max_weight=3)
result = engine.value_and_grad([0.125])

PropagationEngine propagates the observable in reverse Heisenberg order. max_weight=None or a cutoff at least as large as nqubits is exact; a finite cutoff applies deterministic Pauli-weight projection after same-word contributions have been aggregated. The gradient is for the executed frozen sparse trace, not a dense derivative at support-change points.

The Phase Alpha facade adds the corresponding value-only form circuit.expectation(observable, parameters=...); it must agree with value_and_grad(...).value for deterministic execution without computing a gradient.

SPPSEngine provides seeded stochastic value-and-gradient estimates with fixed or adaptive per-term sample budgets. Its result includes standard-error and stopping-proxy metadata and must not be interpreted as a deterministic gradient result.

U(1) semantics

U1Sector and U1Circuit use TensorCircuit computational-basis integer ordering. U1Circuit stores and executes only the fixed-Hamming-weight sector; state()/probability() are restricted-space terminals and state_full()/probability_full() are explicit full-space terminals. The native restricted implementation supports arbitrary-width packed occupation limbs, while full-space materialization remains subject to the public DEFAULT_MAX_BYTES guard.

TensorCircuit conversion

TensorCircuit is the required ecosystem dependency. User-facing conversion uses target-type classmethods:

native_u1 = tcp.U1Circuit.from_circuit(tc_u1_circuit)
native_propagation = tcp.PropagationCircuit.from_circuit(tc_circuit)

Low-level QIR restoration remains available through from_qir(). Numeric QIR produces static gates; direct symbolic references produce parameter slots. TensorCircuit gate objects are normalized at the boundary to a static logical payload, especially for diagonal gates.

Development

The local quality gate is:

python scripts/check.py --benchmark smoke

The full release checks include Rust formatting, Clippy, Rust tests, Black, Ruff, strict mypy, release maturin installation, Python tests, and benchmark harness smoke tests. TensorCircuit differential tests use the supported TensorCircuit installation and compare ordering, gate conventions, state/observable values, backend MVP results, and native conversion behavior.

See CONTRIBUTING.md, docs/vibe/phase-alpha-spec.md, docs/vibe/semantics.md, and docs/vibe/releasing.md.

License

Apache License 2.0.

Download files

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

Source Distribution

tencirpauli-0.2.0.tar.gz (216.2 kB view details)

Uploaded Source

Built Distributions

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

tencirpauli-0.2.0-cp39-abi3-win_amd64.whl (954.5 kB view details)

Uploaded CPython 3.9+Windows x86-64

tencirpauli-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

tencirpauli-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

tencirpauli-0.2.0-cp39-abi3-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

tencirpauli-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file tencirpauli-0.2.0.tar.gz.

File metadata

  • Download URL: tencirpauli-0.2.0.tar.gz
  • Upload date:
  • Size: 216.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tencirpauli-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7cf0ea8035180fcbdab0ec82c238069b4f4f92ad87b8e094814397dc11979728
MD5 cf4d37f7172a1f3da087c01036983cf0
BLAKE2b-256 5f9de5d65885dcfd0588339c145fbaa39f7027cdf51324af98adbe258393aa4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for tencirpauli-0.2.0.tar.gz:

Publisher: release.yml on tensorcircuit/TenCirPauli

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

File details

Details for the file tencirpauli-0.2.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: tencirpauli-0.2.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 954.5 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tencirpauli-0.2.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7e2898c52a8662b75883ad527508cb32ec1114e4924b8d61d8779d27fbea8a27
MD5 dfd9183b87119fa60cfdbe5f68bd3be0
BLAKE2b-256 5ba44604a3b453ddab0571277e7b5b96ee11067177e6b2e11ae5ac8bf6f004ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for tencirpauli-0.2.0-cp39-abi3-win_amd64.whl:

Publisher: release.yml on tensorcircuit/TenCirPauli

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

File details

Details for the file tencirpauli-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tencirpauli-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 019428288364d62ce32dbe4048d2d6b440d599a6badeec8828b009d60fd9dd1e
MD5 3d78c999fef1d9efe1e73b7bc9ea0cb0
BLAKE2b-256 170969ede6e89a398050805c70caf94c13e64e06f31066036e79522bd8f1ac84

See more details on using hashes here.

Provenance

The following attestation bundles were made for tencirpauli-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on tensorcircuit/TenCirPauli

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

File details

Details for the file tencirpauli-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tencirpauli-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 73b0c69242c9a54e4fcab6e45ca560e0b7d646c6afa9e5105cfd827c1f1174bb
MD5 ce55d8be6d410751e162b5c634d12b9f
BLAKE2b-256 3fd40b3ace80d40bfa8726c63284578b701651891fb8dd463f913156aa9aba0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for tencirpauli-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on tensorcircuit/TenCirPauli

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

File details

Details for the file tencirpauli-0.2.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tencirpauli-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 932eb9253935833e8712cddd1d406edd804a7666ae884d3196dda3a90faf18fe
MD5 d3701a6d704be88ca93466482d25a485
BLAKE2b-256 18f3ccd0bf79829a91d1023a33390509d01993fcfffbf6a50b2179ca4110a56d

See more details on using hashes here.

Provenance

The following attestation bundles were made for tencirpauli-0.2.0-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on tensorcircuit/TenCirPauli

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

File details

Details for the file tencirpauli-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for tencirpauli-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 789a917bb64dcece55a772acb648b43166130b247645b930f64b49f2e1412abe
MD5 ef0116496dd7443c84bad32c8035cb0b
BLAKE2b-256 ccdf04b37335cece9fc9848ddbec0ff8e0e5cbbfc7f2d14902d05f362d27c34c

See more details on using hashes here.

Provenance

The following attestation bundles were made for tencirpauli-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on tensorcircuit/TenCirPauli

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

Release history Release notifications | RSS feed

0.5.0

6 files

0.4.1

6 files

0.4.0

6 files

0.3.0

6 files

This release

0.2.0 This release

6 files

0.1.0

6 files

Supported by

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