Skip to main content

Clifford + noisy stabilizer simulator: noise-free and noisy (importance-sampled) stabilizer simulation with a native core.

Project description

qliff

A Clifford stabilizer simulator with support for noisy and mid-circuit measurement-based simulation.

  • Clifford stab simulation via the Aaronson–Gottesman tableau
  • Noisy sim via stabilizer-channel decomposition E = Σ_μ q_μ S_μ and stratified importance sampling (arXiv:2512.07304), "nearly as cheap as Pauli noise."
  • Decoder-ready QEC primitives: detectors, observables, detection-event sampling, a detector error model by Pauli-frame propagation, and exporters (parity-check matrix + priors, matching weights, syndrome/label tensors). These drop directly into MWPM (pymatching), BP, or ML decoders.

Install

pip install qliff

Docs at plutoniumm.github.io/qliff.

Clifford simulation

from qliff import Simulator

s = Simulator(2).H(0).CX(0, 1)
s.canon()        # ['+XX', '+ZZ']
s.peek("ZZ")     # +1
s.measure("XX")  # (+1, False)

m0, m1 = Simulator(2).H(0).CX(0, 1).M(0, 1)  # m0 == m1

Mid-circuit measurement and classical feedback are just Python — the simulator is stateful, so conditionals (teleportation, syndrome correction) need no special API:

s = Simulator(3, seed=0)
s.H(0)
s.H(1).CX(1, 2)
s.CX(0, 1).H(0)

if s.M(1) == 1:
    s.X(2)
if s.M(0) == 1:
    s.Z(2)

s.peek("__X")  # +1

Noise

Build Circuit with gate/noise methods, then sample or estimate.

Circuit.estimate picks the right sampler by default — plain Monte-Carlo when every channel is Pauli, otherwise stratified importance sampling

from qliff import Circuit

c = Circuit(1)
c.H(0).DEPOLARIZE1(0, 0.1).M(0)
c.sample(1000)

c = Circuit(1)
c.H(0).RZ(0, 0.3)
c.estimate("X", 20000)  # ≈ cos(0.3)

c = Circuit(1)
c.X(0).AMPLITUDE_DAMP(0, 0.3)
c.estimate("Z", 60000)  # ≈ 2p - 1

Force the variance strategy with c.estimate(obs, shots, stratify=False) (flat) or stratify=True (stratified), or drive the sampler directly: from qliff.noise import Sampler, then Sampler(c).expect(obs, shots, stratify=True). Add a custom channel by subclassing qliff.noise.Channel and dropping it in with c.noise(ch, q).

Quantum error correction

qliff.qec ships code-circuit generators, so you can go straight to a logical-error-rate curve. Any circuit's detectors and observables are declared with c.detector(...) / c.observable(...), then turned into decoder inputs:

from qliff.qec import rotated_surface_code, logical_fidelity
from pymatching import Matching

c = rotated_surface_code(distance=5, rounds=5, p=0.01)
dem = c.dem()

H, priors, obs_matrix = dem.check_matrix()
m = Matching.from_check_matrix(
  H,
  weights=dem.weights(),
  faults_matrix=obs_matrix
)

dets, flips = c.detector_sampler().sample(20000)
fidelity = logical_fidelity(m.decode_batch(dets), flips)

Extending

Everything you'd customize lives in Python. Add a noise channel by subclassing qliff.noise.Channel and returning its stabilizer-channel branches; plug in a custom sampler or observable; export the DEM to whatever decoder you like. The Rust core stays a thin, fast tableau engine.

Develop

./do develop   # build rust core
./do test
./do lint
./do bench
./do build     # all wheels (macOS/Linux/Windows, x86_64 + arm) + sdist, no upload
./do deploy    # same build, then publish to PyPI

cd docs && npm run build && npm run deploy   # docs site -> GitHub Pages

License

MIT

If you are a company using this, please get a grad student to help you with issues. If you are a grad student, please feel free to email me :)

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

qliff-0.0.1.tar.gz (143.9 kB view details)

Uploaded Source

Built Distributions

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

qliff-0.0.1-cp311-abi3-win_arm64.whl (310.8 kB view details)

Uploaded CPython 3.11+Windows ARM64

qliff-0.0.1-cp311-abi3-win_amd64.whl (321.2 kB view details)

Uploaded CPython 3.11+Windows x86-64

qliff-0.0.1-cp311-abi3-macosx_11_0_x86_64.whl (422.8 kB view details)

Uploaded CPython 3.11+macOS 11.0+ x86-64

qliff-0.0.1-cp311-abi3-macosx_11_0_arm64.whl (408.0 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

File details

Details for the file qliff-0.0.1.tar.gz.

File metadata

  • Download URL: qliff-0.0.1.tar.gz
  • Upload date:
  • Size: 143.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for qliff-0.0.1.tar.gz
Algorithm Hash digest
SHA256 906319e56f5dc7cb26b6987a0047c7763848745373426c968081285a48329279
MD5 8ecb3373051b6afb42fef0bf64db0bb8
BLAKE2b-256 fbce5941ab0d75f5b95af5e6cdd8e39de6bfa64cb08e5b8462d194b820a4e41e

See more details on using hashes here.

File details

Details for the file qliff-0.0.1-cp311-abi3-win_arm64.whl.

File metadata

  • Download URL: qliff-0.0.1-cp311-abi3-win_arm64.whl
  • Upload date:
  • Size: 310.8 kB
  • Tags: CPython 3.11+, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for qliff-0.0.1-cp311-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 d4761b10270026e73837a8d673557bfa4c0bc15b0b9c49702c81f5b7c9ed6fa9
MD5 787aa94016151e78e52c6623e729c780
BLAKE2b-256 d69d0b7d65b82f02a67fe7286ac2b6fde443fc2f24ebdbaf3015910b386f9c4e

See more details on using hashes here.

File details

Details for the file qliff-0.0.1-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: qliff-0.0.1-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 321.2 kB
  • Tags: CPython 3.11+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for qliff-0.0.1-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1894e7f5906ae9ca2c1136f506b04e4df2d1b2c73f9860469436ae50a96d4b76
MD5 ed420dc7230fc993122a89a0d6321162
BLAKE2b-256 2716cdc50d787b21a28aaace5c4352777be4c9654f56b94c232b23cc47e35cf9

See more details on using hashes here.

File details

Details for the file qliff-0.0.1-cp311-abi3-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for qliff-0.0.1-cp311-abi3-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 65973ae16c087e034533e5e9bf30e31a4b446dd5fe0c45e480f34bfbf372daa7
MD5 197ff8cad179c87ea93d886dc6fb26e3
BLAKE2b-256 9fa4d6958492cb7a1bf765e3ed6037649cf00493a1f5383c9d1b7cb5ce3034cc

See more details on using hashes here.

File details

Details for the file qliff-0.0.1-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for qliff-0.0.1-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5805d13fd73cfe0c5662a8b26ef000054bbb27f817bc4c21dba5fed051e74ecd
MD5 47d1be8d9725431ec3ef612085bd7fdb
BLAKE2b-256 24802472946267fe36d6b4b9bccf8267c5d8bfafad651ba6d98ecadfde22929e

See more details on using hashes here.

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