paulipropagation-qdk
Pauli propagation for circuits compiled with the Microsoft Quantum Development Kit (QDK).
An observable is evolved backwards through a circuit as a truncated sum of Pauli strings. This
gives expectation values <0| U† O U |0> on hundreds of qubits without a state vector.
- Rust engine, Python API.
- Circuits come from QIR, so from Q# or OpenQASM, or are built gate by gate.
- Algorithms, conventions and defaults follow PauliPropagation.jl.
---
config:
layout: elk
---
flowchart LR
Q["Q# / OpenQASM"] -->|QDK| QIR --> C[Circuit]
B["pp.Circuit(n)"] --> C
C --> P["propagate: apply gate, merge, truncate"]
O["PauliSum (observable)"] --> P
P --> R["PauliSum"] --> E["expectation value"]
Install
Python 3.10 or later; wheels for Linux and Windows (x86-64, arm64) and macOS (arm64):
pip install paulipropagation-qdk
From source, with Rust:
uv venv --python 3.12 .venv && source .venv/bin/activate
uv pip install maturin
maturin develop --release
Example
from qdk import qsharp
import paulipropagation_qdk as pp
qsharp.init(target_profile=qsharp.TargetProfile.Base)
qsharp.eval("""
operation Main() : Result[] {
use qs = Qubit[32];
for _ in 1..8 {
for i in 0..30 { Rzz(0.1, qs[i], qs[i + 1]); }
for i in 0..31 { Rx(0.1, qs[i]); }
}
MResetEachZ(qs)
}
""")
circuit = pp.circuit_from_qir(str(qsharp.compile("Main()")))
observable = pp.PauliSum(circuit.num_qubits)
observable.add("Z", [15])
evolved = pp.propagate(circuit, observable, max_weight=6, min_abs_coeff=1e-4)
print(len(evolved), evolved.overlap_with_zero())
samples/pauli_propagation.ipynb goes from a Q# program to expectation values on 100 qubits,
with truncation, noise, gradients, an error estimate and a surrogate.
Features
| Circuits | QIR from Q# or OpenQASM; pp.Circuit built gate by gate |
| Gates | H, X, Y, Z, S, SX, T and adjoints; CX, CY, CZ, SWAP, CCX; RX, RY, RZ, RXX, RYY, RZZ; rotation(paulis, qubits, theta); unitary and transfer matrices on up to 5 qubits |
| Noise | Pauli channels on up to 6 qubits; depolarizing, dephasing, Pauli X, Y, Z noise; amplitude damping; the Pauli errors of a QDK NoiseConfig |
| Pauli sums | real or complex coefficients, up to 512 qubits; sums, products, commutators |
| Pictures | observables backwards, states forwards |
| Expectation values | in the zero, plus, computational basis and maximally mixed states, or a state given as a Pauli sum |
| Truncation | eight rules, see below |
| Gradients | all angles in one backward and one forward pass |
| Surrogates | propagate once, evaluate at any angles |
| Sampling | resampling, propagation with resampling, single random paths |
| Error estimate | mean squared error of a truncation |
| Symmetries | merging of translations on rings and tori, or of any symmetry given as a function |
| Threads | all cores; every coefficient is the same bit for bit on any number of threads |
Usage
Truncation
A sum is truncated after every gate.
| Option | Drops a term when |
|---|---|
max_weight |
it has more non-identity operators than this |
min_abs_coeff (default 1e-10) |
its coefficient is smaller than this in absolute value |
min_rel_coeff |
its coefficient is smaller than this fraction of the largest in the sum |
max_freq |
more rotations than this split the Pauli string on its way |
max_sins |
it took more sine branches of rotations than this |
weight_damping=(gamma, threshold) |
abs(coeff) * 10**(-gamma * weight) < threshold |
custom_truncation |
this function of the label and the coefficient returns true |
max_terms |
the sum has more terms than this and the term is not among the largest |
- A Clifford gate changes only signs, so after one only
max_weight,weight_dampingandcustom_truncationdrop anything. max_termsbounds memory and time whatever the circuit does. It cannot be combined withmax_freqormax_sins.- Truncated results are approximations without an error bound for a given circuit. Check
convergence by tightening the truncation;
estimate_msegives the average error over angles.
Noise
Noise channels are gates of the circuit, and the result is the exact expectation value of the noisy circuit, not a sample.
from qdk.simulation import NoiseConfig
noise = NoiseConfig()
noise.rzz.set_depolarizing(0.01)
noise.rx.set_pauli_noise([("Z", 0.002)])
circuit = pp.circuit_from_qir(str(qsharp.compile("Main()")), noise=noise)
circuit.depolarizing(0.02, q) # or channel by channel
circuit.amplitude_damping(0.01, q)
circuit.pauli_channel([q0, q1], [("XZ", 0.01)])
Of a NoiseConfig, the Pauli errors of every gate are used. Qubit loss is rejected, and noise
on the trailing measurements is dropped.
States
With heisenberg=False the sum is a state in the Pauli basis and the circuit acts on it from
the first gate to the last. A coefficient times 2^n is the expectation value of its string.
state = pp.PauliSum(2) # |00><00| = (I + Z)(I + Z) / 4
for paulis in ("II", "IZ", "ZI", "ZZ"):
state.add(paulis, [0, 1], 0.25)
evolved = pp.propagate(circuit, state, heisenberg=False)
print(evolved.coeff("ZZ", [0, 1]) * 4) # <ZZ> after the circuit
observable.overlap_with_pauli_sum(state) is Tr[state observable].
Gates from matrices
circuit.unitary([q0, q1], matrix) # 4 x 4 complex, q0 the most significant bit
circuit.transfer_map([q], transfer_matrix) # 4 x 4 real
Entry (i, j) of a transfer matrix is the factor of the Pauli string i in the image of the
string j of an observable. Strings are numbered in base 4, with I, X, Y, Z as 0 to 3 and the
first qubit as the lowest digit.
Pauli sums
total = pp.PauliSum(n, dtype=complex) # complex coefficients
hamiltonian = 0.5 * zz + 0.3 * x # + - * with numbers
derivative = 1j * hamiltonian.commutator(observable) # also a.product(b)
Symmetries
Pauli strings that a symmetry of the circuit and the state maps to each other have the same expectation value and can be merged into one term.
for _ in range(layers):
observable = pp.propagate(layer, observable, max_weight=6).translation_merge()
| Method | Merges |
|---|---|
translation_merge() |
translations on a ring |
translation_merge(nx, ny) |
translations on a torus; the qubit in column x of row y is y * nx + x |
symmetry_merge(representative) |
any symmetry: representative maps a label to the label that stands for its images |
Gradients
value, derivatives = pp.gradient(circuit, observable, max_weight=6, min_abs_coeff=1e-6)
derivatives[k]belongs to the rotation with the anglecircuit.angles[k]; a T gate is a rotation.circuit.with_angles(angles)is the circuit with other angles.stateis'zero','plus','mixed', the list of the qubits that are 1, or a Pauli sum.- Exact without truncation, approximate with it. The circuit must have no noise.
Surrogates
A Surrogate propagates once for all angles. Evaluating it returns the same sum as
propagate with those angles and min_abs_coeff=0, bit for bit.
surrogate = pp.Surrogate(circuit, observable, max_weight=5, max_freq=30)
for angles in candidates:
value = surrogate.evaluate(angles).overlap_with_zero()
For circuits of Clifford gates and rotations, with max_weight, max_freq and max_sins.
Sampling
estimate = pp.mcpropagate(circuit, observable, max_size=100_000, seed=1)
| Function | Does |
|---|---|
pp.resample(sum, target_size) |
drops terms at random and scales the others, so that the sum is unchanged on average |
pp.mcpropagate(...) |
propagates and resamples whenever a gate leaves more than max_size terms |
pp.mcsample(circuit, sum, samples) |
follows single random paths, one branch at every rotation |
Resampling methods are 'semideterministic' (default), 'systematic' and 'multinomial'.
A seed makes each of them reproducible on every platform.
The error of a truncation
mse = pp.estimate_mse(circuit, observable, 100_000, max_weight=6) # any angles
mse = pp.estimate_mse(circuit, observable, 100_000, thetas=0.3, max_weight=6) # angles up to 0.3
The mean squared error of max_weight, max_freq, max_sins or a rule on the Pauli string,
averaged over angles drawn uniformly from [-thetas, thetas]. The observable is one Pauli
string.
Threads
evolved = pp.propagate(circuit, observable, max_weight=6, threads=8)
By default all cores are used once the sum is large enough. The result does not depend on the number of threads. On processors with performance and efficiency cores, the number of performance cores is usually fastest.
QIR and qubit numbering
- A QIR program is one unitary circuit, optionally followed by measurements. Branching on measurement results is rejected.
- Observables refer to the qubits of the QIR program. These are the qubits of the Q# register in allocation order as long as the program measures only at the end.
How it works
- Terms are kept in arrays, ordered by Pauli string. A rotation updates coefficients in place, creates one new term per term it splits, and one merge adds up equal strings and drops the truncated ones. This is the vector backend of PauliPropagation.jl.
- For threads, the sum is divided into zones by the commutation of each string with a few fixed strings. A rotation pairs the zones up, and every pair is worked on by one thread.
pauliprop::referenceis a second, simple propagation on a hash map, which the tests compare the engine with.
Building and testing
uv pip install maturin pytest numpy qdk stim
maturin develop --release
cargo test
pytest
Both suites cap their own memory, so a propagation that fails to truncate ends the run instead of exhausting the machine.
Documentation
| docs/verification.md | what the results are checked against, and the runs that were made |
| docs/comparison.md | comparison with PauliPropagation.jl, Qiskit pauli-prop and cuPauliProp: features and timings |
License and attribution
Apache-2.0. The algorithms, conventions and defaults follow PauliPropagation.jl, which is licensed under Apache-2.0 as well.
Metadata
Release files for paulipropagation-qdk 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| paulipropagation_qdk-0.1.0.tar.gz | 126.4 kB | With provenance | Details for paulipropagation_qdk-0.1.0.tar.gz |
Built distributions (wheels)
Total release size: 4.9 MB
Release files / paulipropagation_qdk-0.1.0.tar.gz
| Download URL | paulipropagation_qdk-0.1.0.tar.gz |
|---|---|
| Size | 126.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4068135b4363e7bb885b503a162aa372c8d0c1b842157296f47248375ac85f3d
|
|
BLAKE2b-256 checksum How to use checksums |
c35cd64caec4d4a731c6b771466daa7c5a83d0997fbcd60fdefb19abfffc0281
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logRelease files / paulipropagation_qdk-0.1.0-cp310-abi3-win_arm64.whl
| Download URL | paulipropagation_qdk-0.1.0-cp310-abi3-win_arm64.whl |
|---|---|
| Size | 846.4 kB |
| Tags | CPython 3.10 Windows ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
b08d47e15285d2be2488bd5b99bfc7e2c387458ec94d63c2ecb475acb2c19a32
|
|
BLAKE2b-256 checksum How to use checksums |
9b5ee20d0637741aa916ceea1672e96c094795bf809642cbc29e100d45ea5eb2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logRelease files / paulipropagation_qdk-0.1.0-cp310-abi3-win_amd64.whl
| Download URL | paulipropagation_qdk-0.1.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 994.0 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
92b7d324c51867e85cbcab17b22fe68667696c5d99ad959677e6d1f864b98ff9
|
|
BLAKE2b-256 checksum How to use checksums |
233a87293dbe1b6d366cfeb6a13c8adb22f9a1bf5fa3959437b989cbbec10973
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logRelease files / paulipropagation_qdk-0.1.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | paulipropagation_qdk-0.1.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
a09d8dd9d21530c2d1235f31fefc77008538b13d917cb5f41972804ece328434
|
|
BLAKE2b-256 checksum How to use checksums |
e6d8736da4b3b8124c0ae471441944a617f540d41321772a5261c20cc7cf75ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logRelease files / paulipropagation_qdk-0.1.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | paulipropagation_qdk-0.1.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
|---|---|
| Size | 962.0 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
aa80d145753dbf9ed894d77d6016304b202c8f7422403438bafe21e91ac0d0e2
|
|
BLAKE2b-256 checksum How to use checksums |
2241c7eafc5b016841db7eebfaadd48089449fad1c8bb9f9109adb8cc0fb209d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logRelease files / paulipropagation_qdk-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | paulipropagation_qdk-0.1.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 915.1 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
08e8dbe4039434a73e4589054734c60962de70484e9d1924f14cc4157fde90d1
|
|
BLAKE2b-256 checksum How to use checksums |
ed5f67a9a20cd3697663fb53acdaef797e2b6d9967ca109eed42a47ae9c26891
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logSecurity for paulipropagation-qdk 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 6 files in this release have been uploaded with provenance metadata.
Attestation for paulipropagation_qdk-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.