Skip to main content

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). On x86-64 the processor has to support x86-64-v2 (SSE4.2 and POPCNT: Intel from 2009, AMD from 2011):

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())
Notebook From Shows
samples/pauli_propagation.ipynb Q# 100 qubits, truncation, noise, gradients, an error estimate, a surrogate
samples/pauli_propagation_openqasm.ipynb OpenQASM 2 and 3 100 qubits, truncation, noise, gates that the QDK decomposes, input parameters

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_damping and custom_truncation drop anything.
  • max_terms bounds memory and time whatever the circuit does. It cannot be combined with max_freq or max_sins.
  • Truncated results are approximations without an error bound for a given circuit. Check convergence by tightening the truncation; estimate_mse gives 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 angle circuit.angles[k]; a T gate is a rotation. circuit.with_angles(angles) is the circuit with other angles.
  • state is '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.

OpenQASM

from qdk import openqasm, qsharp

qir = openqasm.compile("""
OPENQASM 3.0;
include "stdgates.inc";
qubit[3] q;
output bit[3] c;
h q[0];
cx q[0], q[1];
cry(0.4) q[1], q[2];
c = measure q;
""", target_profile=qsharp.TargetProfile.Base)
circuit = pp.circuit_from_qir(str(qir))
  • OpenQASM 2 and 3. Controlled rotations, U, gate modifiers and the gates that a program defines arrive as Clifford gates and rotations, decomposed by the QDK.
  • input parameters are bound when compiling: import_openqasm(source, name="Main", program_type=ProgramType.File), then openqasm.compile(code.qasm_import.Main, *values).
  • The QDK reduces angles to the range from 0 to 2π, so circuit.angles holds 2π - 0.4 for rx(-0.4). Expectation values do not change.

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, or of the OpenQASM registers in the order of their declarations, 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::reference is 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.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for paulipropagation-qdk 0.1.1
File Size Uploaded Provenance Actions
paulipropagation_qdk-0.1.1.tar.gz 127.5 kB With provenance Details for paulipropagation_qdk-0.1.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for paulipropagation-qdk 0.1.1
File Actions
paulipropagation_qdk-0.1.1-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details for paulipropagation_qdk-0.1.1-cp310-abi3-win_arm64.whl
paulipropagation_qdk-0.1.1-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for paulipropagation_qdk-0.1.1-cp310-abi3-win_amd64.whl
paulipropagation_qdk-0.1.1-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for paulipropagation_qdk-0.1.1-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
paulipropagation_qdk-0.1.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details for paulipropagation_qdk-0.1.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
paulipropagation_qdk-0.1.1-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for paulipropagation_qdk-0.1.1-cp310-abi3-macosx_11_0_arm64.whl

Total release size: 4.9 MB

Release files / paulipropagation_qdk-0.1.1.tar.gz

Download URL paulipropagation_qdk-0.1.1.tar.gz
Size 127.5 kB
Tags Source
SHA-256 checksum
How to use checksums
905f82c1eaab8cc905a935f7cc39249205aeb7c25951ec09ebb69b972df71a6c
BLAKE2b-256 checksum
How to use checksums
73c16872fd5962e6820b961e789ec7bee6b0e4bf4b140735760569f73b4e76cc
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 17, 2026.

Transparency log

Release files / paulipropagation_qdk-0.1.1-cp310-abi3-win_arm64.whl

Download URL paulipropagation_qdk-0.1.1-cp310-abi3-win_arm64.whl
Size 846.9 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
f4f688936a02088c30de8f0c54f2fa929ff680df4af98b70faa9c654e047a5d9
BLAKE2b-256 checksum
How to use checksums
40afe601f89cfd161221698cff8482645414008ecd6583a5116c48918131ec05
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 17, 2026.

Transparency log

Release files / paulipropagation_qdk-0.1.1-cp310-abi3-win_amd64.whl

Download URL paulipropagation_qdk-0.1.1-cp310-abi3-win_amd64.whl
Size 962.0 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
7c4d7f4d536a292f40e0bb5f425b159984fad01c8e3557e20dd3548958332010
BLAKE2b-256 checksum
How to use checksums
9252135ceea8378e42c52fa5a675577ea35d52a1092e43e58e96e97cc6fbad1e
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 17, 2026.

Transparency log

Release files / paulipropagation_qdk-0.1.1-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL paulipropagation_qdk-0.1.1-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
6c2ea1f67879716963bd8b57af7b3f7c271070a0a0910cc45fa1c23ad1bf1858
BLAKE2b-256 checksum
How to use checksums
6a95e56d1f373682c2161175e49c2696cc3052c4b6b59dadeb9e668f93c4da6e
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 17, 2026.

Transparency log

Release files / paulipropagation_qdk-0.1.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL paulipropagation_qdk-0.1.1-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
0e249a76bba117215501c8f94b322515bdff8dc7322a21ee5d77f48b2ba138d7
BLAKE2b-256 checksum
How to use checksums
919383d8519ceb1c1353c66fd3977a3b48ef57d3ffab5ea42792e9271bb7b95e
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 17, 2026.

Transparency log

Release files / paulipropagation_qdk-0.1.1-cp310-abi3-macosx_11_0_arm64.whl

Download URL paulipropagation_qdk-0.1.1-cp310-abi3-macosx_11_0_arm64.whl
Size 915.5 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
5e45cce2d808d91194761376348803087bf1d22e858282ffebbbdd026c46f085
BLAKE2b-256 checksum
How to use checksums
eb2f9bc4f47b3d9ebd840cfe87d4fa0abf7e5230dce6b08e04a0d878ad0081b8
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 17, 2026.

Transparency log

Security for paulipropagation-qdk 0.1.1

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.

Select from 6 files

Attestation for paulipropagation_qdk-0.1.1.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 17, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

6 release files Full provenance

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