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.2.0.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.2.0-cp311-abi3-win_arm64.whl (329.4 kB view details)

Uploaded CPython 3.11+Windows ARM64

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

Uploaded CPython 3.11+Windows x86-64

qliff-0.2.0-cp311-abi3-manylinux_2_28_x86_64.whl (464.6 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ x86-64

qliff-0.2.0-cp311-abi3-manylinux_2_28_aarch64.whl (459.6 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.11+macOS 11.0+ x86-64

qliff-0.2.0-cp311-abi3-macosx_11_0_arm64.whl (426.4 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: qliff-0.2.0.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.2.0.tar.gz
Algorithm Hash digest
SHA256 04dcc267dd6fadbd96d0b275fce8afe5c8995c84f092ef27060f3045c7b8fc61
MD5 3d50c20e2ac73c95d895e74ea0da7bff
BLAKE2b-256 b04d3d4b44b0cc8047fd08273120154dc73f6fefe18904d84097bf6772072b61

See more details on using hashes here.

File details

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

File metadata

  • Download URL: qliff-0.2.0-cp311-abi3-win_arm64.whl
  • Upload date:
  • Size: 329.4 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.2.0-cp311-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 d80fc3f469e6896d1e1432653c7bffcb1242473e7c7b7a044b68f699d8f11bb1
MD5 95e736368c86b03a40ce86a2a8637a0a
BLAKE2b-256 c09c398a4ea1542450ed8083fcee417aa7aceb5f7fe3cc90d18a6e8daefd8684

See more details on using hashes here.

File details

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

File metadata

  • Download URL: qliff-0.2.0-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.2.0-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5793d17e62bb4663e72986efa3e8ed2db6b13ee4b41e4c53ea1fe9076a74574e
MD5 2b34eb8afb24dc5753863b6273134ea3
BLAKE2b-256 83ac82d7f003982db8d5bf714d06b89e96c4f5ed5966040ab6627a025d0a104e

See more details on using hashes here.

File details

Details for the file qliff-0.2.0-cp311-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for qliff-0.2.0-cp311-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 904c9beff79f7668b609bcb9486fac66e1b566d10e9fdb78a70a53272e83912e
MD5 7705a507dd2a7e3a52b59039e2e296be
BLAKE2b-256 bcb7409d76fb8ee9d63a84c46fc2e6c0993324f11d6efbd762b06b85d2983d43

See more details on using hashes here.

File details

Details for the file qliff-0.2.0-cp311-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for qliff-0.2.0-cp311-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 467a5f3232dcde51c69184ee32a283f5ccf550e4d033ffaff176422c814c0d88
MD5 11cc21556fbf10a0f1a9fe4fff39ebca
BLAKE2b-256 1c59781a22d7866aa032cc15f41fb177668747d920bc8086fab5e7c1fcff6965

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for qliff-0.2.0-cp311-abi3-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 4c1fe0628451da30a202d00b63f7acec250684ec28c25d9f0419da8114faf767
MD5 cbf0956467b30766f05ca19e5171de18
BLAKE2b-256 c2f666f862b8944729903e4afbdf0e2665d6f163d29ccdd79097ea6c58ee8a60

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for qliff-0.2.0-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 57d1a79e6e870fa7f2b52032d0aef454987af9f5d764d098a5271f5dbc2061eb
MD5 de338eeafec9ab8d1dd07398246aa7fe
BLAKE2b-256 6bafd06f580948a0d6c2712a4cfa1d08c0956bb8ee2fc459c20cbae05708e556

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