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 Majorana and charge 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_charge() |
| 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) |
Pauli algebra uses native-backed lazy results by default. Each result remains a lightweight PauliOperator backed by a private Rust handle; term_count, algebra, and matrix/MVP targets do not construct Python PauliTerm objects. Use result.to_dict() for a plain {pauli_string: coefficient} mapping, or access result.terms when the full Python term objects are explicitly needed.
native_result = hamiltonian.commutator(hamiltonian)
weights = native_result.to_dict()
python_terms = native_result.terms # explicit, cached materialization
Fermion, Boson, Qudit, Hybrid, and Majorana operators follow the same default lazy boundary with family-specific canonical native arrays and to_dict() exports. The exact native coverage and intentionally retained Python fallbacks are listed in docs/vibe/operator-lazy-results.md.
Structured operator algebra
structured 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.
Majorana and charge 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 design index under docs/vibe/README.md.
CPU-native MVP plans default to storage="lazy"; use storage="eager" when a reusable retained representation fits the budget. A restricted facade starts compact, and mvp_plan(storage="eager"), dense(), coo(), or csr() explicitly authorizes a thread-safe eager transition cache that later facade calls may reuse. Fixed plans never change storage, and apply_into(input_state, output_state) writes into caller-owned non-overlapping complex128 buffers.
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
The circuit facade accepts actual gate angles through theta= and exposes angle_count. Direct gradients are returned in deterministic gate-occurrence order; JAX owns any outer parameter sharing or arithmetic. Circuit facades do not expose public compile plans.
import tencirpauli as tcp
circuit = tcp.U1Circuit(nqubits=4, particle_number=2, occupied=[0, 1])
circuit.iswap(0, 1, theta=0.2)
circuit.rzz(1, 2, theta=-0.5)
hamiltonian = tcp.PauliOperator.from_terms(
4,
(("XXII", 0.5), ("YYII", 0.5), ("ZIZI", -0.2)),
)
result = circuit.value_and_grad(hamiltonian)
energy = circuit.expectation(hamiltonian)
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=0.2)
circuit.cnot(0, 1)
circuit.rz(1, theta=-0.3)
result = circuit.value_and_grad(hamiltonian)
energy = circuit.expectation(hamiltonian)
expectation_jax() accepts scalar JAX values or tracers and uses one host callback plus a first-order custom VJP. Build the circuit inside the traced objective when outer parameters are shared or transformed; TenCirPauli sees only independent gate-angle occurrences. The first JAX route requires jax_enable_x64=True and does not promise higher-order derivatives, jvp, or implicit batching.
The current implementation contract and rollout status are recorded in the docs/vibe index.
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 circuit facade adds a value-only expectation(observable) terminal; it agrees with value_and_grad(observable).value and does not allocate a gradient buffer.
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() for concrete numeric gate records. JAX-traced angles belong in a circuit built inside the expectation_jax() objective rather than in a serialized QIR payload. 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
Built Distributions
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 tencirpauli-0.3.0.tar.gz.
File metadata
- Download URL: tencirpauli-0.3.0.tar.gz
- Upload date:
- Size: 241.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ac79fe3af166f18eb49926b1db6a20616c8b49318324ac0751891c338b30bd4
|
|
| MD5 |
2d233eb8b939cbd127d4d8664f2e123c
|
|
| BLAKE2b-256 |
bbe8cfe4f56d23a0c28c90f384c4f671da18b454f0aca2467651910d29ed8ff7
|
Provenance
The following attestation bundles were made for tencirpauli-0.3.0.tar.gz:
Publisher:
release.yml on tensorcircuit/TenCirPauli
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tencirpauli-0.3.0.tar.gz -
Subject digest:
2ac79fe3af166f18eb49926b1db6a20616c8b49318324ac0751891c338b30bd4 - Sigstore transparency entry: 2357666744
- Sigstore integration time:
-
Permalink:
tensorcircuit/TenCirPauli@84a495f750a8356a12c91a51442c5e01fd55d18e -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/tensorcircuit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@84a495f750a8356a12c91a51442c5e01fd55d18e -
Trigger Event:
release
-
Statement type:
File details
Details for the file tencirpauli-0.3.0-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: tencirpauli-0.3.0-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
475a2f6f032203b2721d09740e7024332569641d2f9f0ea08cf7ae1b1789fc89
|
|
| MD5 |
1b1da3eb338113964379148a002adfd1
|
|
| BLAKE2b-256 |
3c266d19f7dd2c208f3881a088c3c7b1a66cb6bfe91bd648b609a11fd88e982a
|
Provenance
The following attestation bundles were made for tencirpauli-0.3.0-cp39-abi3-win_amd64.whl:
Publisher:
release.yml on tensorcircuit/TenCirPauli
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tencirpauli-0.3.0-cp39-abi3-win_amd64.whl -
Subject digest:
475a2f6f032203b2721d09740e7024332569641d2f9f0ea08cf7ae1b1789fc89 - Sigstore transparency entry: 2357666893
- Sigstore integration time:
-
Permalink:
tensorcircuit/TenCirPauli@84a495f750a8356a12c91a51442c5e01fd55d18e -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/tensorcircuit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@84a495f750a8356a12c91a51442c5e01fd55d18e -
Trigger Event:
release
-
Statement type:
File details
Details for the file tencirpauli-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: tencirpauli-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84e450af3dd5b53ceea423c0c1b21c9175040badb1e7f1c32a955f20e7429611
|
|
| MD5 |
eae59ad1ae35f0fa0539114e8b7205bc
|
|
| BLAKE2b-256 |
ddc22a878674f0819ff93abc982c7f71afa87a59505f928bfa40536bff5f670a
|
Provenance
The following attestation bundles were made for tencirpauli-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on tensorcircuit/TenCirPauli
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tencirpauli-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
84e450af3dd5b53ceea423c0c1b21c9175040badb1e7f1c32a955f20e7429611 - Sigstore transparency entry: 2357666979
- Sigstore integration time:
-
Permalink:
tensorcircuit/TenCirPauli@84a495f750a8356a12c91a51442c5e01fd55d18e -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/tensorcircuit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@84a495f750a8356a12c91a51442c5e01fd55d18e -
Trigger Event:
release
-
Statement type:
File details
Details for the file tencirpauli-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: tencirpauli-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33d6f4582a1e008922735a2981c912c362a1257d7d4ea88f5b222567a2acfc63
|
|
| MD5 |
3b569a7bdd8166048068907ba8d2dc3c
|
|
| BLAKE2b-256 |
0d305e41521a31c8b4531d537ff4cdb6e555a234f505eb47dc1736a47a3c42e3
|
Provenance
The following attestation bundles were made for tencirpauli-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
release.yml on tensorcircuit/TenCirPauli
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tencirpauli-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
33d6f4582a1e008922735a2981c912c362a1257d7d4ea88f5b222567a2acfc63 - Sigstore transparency entry: 2357667064
- Sigstore integration time:
-
Permalink:
tensorcircuit/TenCirPauli@84a495f750a8356a12c91a51442c5e01fd55d18e -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/tensorcircuit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@84a495f750a8356a12c91a51442c5e01fd55d18e -
Trigger Event:
release
-
Statement type:
File details
Details for the file tencirpauli-0.3.0-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: tencirpauli-0.3.0-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0954dcdeb0d3b1308b033ce1915b509fa780c7587e339cac57baed5f6f89ed29
|
|
| MD5 |
f1bf9b652c117dd310b00b037e105dc3
|
|
| BLAKE2b-256 |
1feee01f4a52078ee08eef0ed72ca04f994d4ed1982d1700daf944a408855956
|
Provenance
The following attestation bundles were made for tencirpauli-0.3.0-cp39-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on tensorcircuit/TenCirPauli
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tencirpauli-0.3.0-cp39-abi3-macosx_11_0_arm64.whl -
Subject digest:
0954dcdeb0d3b1308b033ce1915b509fa780c7587e339cac57baed5f6f89ed29 - Sigstore transparency entry: 2357666837
- Sigstore integration time:
-
Permalink:
tensorcircuit/TenCirPauli@84a495f750a8356a12c91a51442c5e01fd55d18e -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/tensorcircuit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@84a495f750a8356a12c91a51442c5e01fd55d18e -
Trigger Event:
release
-
Statement type:
File details
Details for the file tencirpauli-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: tencirpauli-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.9+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40cfe27482c1777fd2d09762cb92845fef6634bf2b91efa14af5f94c9391f45e
|
|
| MD5 |
57c93ceb49381088daf2af5f5504e5f0
|
|
| BLAKE2b-256 |
0840561452780e34cb4378189ff7abc00d12a1b23d2b4b816eb349842fe46424
|
Provenance
The following attestation bundles were made for tencirpauli-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl:
Publisher:
release.yml on tensorcircuit/TenCirPauli
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tencirpauli-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl -
Subject digest:
40cfe27482c1777fd2d09762cb92845fef6634bf2b91efa14af5f94c9391f45e - Sigstore transparency entry: 2357666782
- Sigstore integration time:
-
Permalink:
tensorcircuit/TenCirPauli@84a495f750a8356a12c91a51442c5e01fd55d18e -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/tensorcircuit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@84a495f750a8356a12c91a51442c5e01fd55d18e -
Trigger Event:
release
-
Statement type: