Skip to main content

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

Project description

qliff

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    # publish what `build` made to PyPI (no rebuild)

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.2.tar.gz (160.4 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.2-cp311-abi3-win_arm64.whl (329.3 kB view details)

Uploaded CPython 3.11+Windows ARM64

qliff-0.0.2-cp311-abi3-win_amd64.whl (341.0 kB view details)

Uploaded CPython 3.11+Windows x86-64

qliff-0.0.2-cp311-abi3-macosx_11_0_x86_64.whl (442.1 kB view details)

Uploaded CPython 3.11+macOS 11.0+ x86-64

qliff-0.0.2-cp311-abi3-macosx_11_0_arm64.whl (426.5 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: qliff-0.0.2.tar.gz
  • Upload date:
  • Size: 160.4 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.2.tar.gz
Algorithm Hash digest
SHA256 18bf95771fa5c5b4cebe8ebafdf41572697670021ebe8d8caee47bcaec94c2cf
MD5 0282cc68157e4678cbcdab95b8996892
BLAKE2b-256 dc197f93ccf18d97d9fd5a54a9d01549c129d01723e33314c9509acb66c5605d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: qliff-0.0.2-cp311-abi3-win_arm64.whl
  • Upload date:
  • Size: 329.3 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.2-cp311-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 48ad35f9fa74145bf086b105bae96d4928b72e77cb7805ed0b5040dead6152bb
MD5 20b475cf026631fb5610474adefcc32f
BLAKE2b-256 a46ed99a7e6a057b690e6ac4ff585d03c01e6d4f97a2010b0e9698d7c96b65d2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: qliff-0.0.2-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 341.0 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.2-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c2c6a8623ab9560852e5aa533f68782928d2fe0dfa499728a03a6935fea43386
MD5 a4dc9f580f682319c364332cb226cf3d
BLAKE2b-256 61ac3f1b4d1c195859ce70cf3704df353ab49be2ceb1280b0c334347ec9f11a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for qliff-0.0.2-cp311-abi3-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 fe6800813afa97012bdac081512825f2f2a51b4dafff04fd50dd9a42e0173511
MD5 a34a8c3f3d65d07f461d3b686223705a
BLAKE2b-256 f4bd16205296c5952e58f318c0f165f867bd8b06c47799c61104e637dddc8de7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for qliff-0.0.2-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f5b39d0e8d0897da41a699bcf676125670c8073c60d787a2ec7bad85f5ab44cd
MD5 e9675095c1ef026212e4d59adc4cb90f
BLAKE2b-256 46d5cb6cbd1a30c47d792454249eaee139afc9702c40cc1e43c30deea385d519

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