Skip to content

Export Stim detector error models from QuantumClifford codes #726

Description

@Krastanov

This issue is part of unitaryHACK26. You have to be registered to complete this issue.
Learn more about the PR submission process here and about unitaryHACK rules here!

A note about AI Slop: while we are open to collaboration with LLMs for unitaryHACK, fully AI-generated PRs are not acceptable. It is at the maintainers' discretion whether or not LLM-generated PRs are the right fit for the issues, and those that appear fully AI-generated may be immediately rejected. Read unitaryHACK's full AI Policy here.

Note from the maintainer: If you have not contributed before to open source projects, no AI agent use is permitted for this issue.


QuantumClifford already has a strong error-correction layer: code definitions,
parity checks, syndrome circuits, and the faults_matrix helper that maps
physical Pauli faults to logical faults. Stim uses detector error model (.dem)
files as a compact interchange format for syndrome-detector graphs and logical
observable flips. Exporting .dem files from QuantumClifford codes would make it
much easier to compare QuantumClifford simulations with Stim-based workflows and
external decoders.

Relevant links:

Desired user-facing behavior

A user should be able to create a detector error model from one of the ECC code
types and write it to a .dem file that Stim can parse:

using QuantumClifford
using QuantumClifford.ECC

dem = detector_error_model(Steane7(); px=1e-3, py=0.0, pz=1e-3)
write_detector_error_model("steane7.dem", dem)

The exact API can be adjusted, but it should support both returning an in-memory
model and writing directly to an IO or filename:

detector_error_model(code; px, py, pz)
write_detector_error_model(io, dem)
write_detector_error_model(path::AbstractString, dem)

Suggested implementation

Start with a code-capacity detector error model generated from the code's parity
checks:

  1. Use parity_checks(code) as the detector definitions.
  2. For each physical qubit and each enabled Pauli fault (X, Y, Z), compute
    the stabilizer checks flipped by that fault.
  3. Use faults_matrix(code) to compute which logical observables are flipped by
    the same fault.
  4. Emit one error(p) D... L... line per nonzero physical fault probability.
  5. Emit deterministic detector and logical-observable declarations so output is
    stable across runs and easy to test.

For example, a single-qubit Pauli error that flips checks 1 and 4 and logical
observable 0 should produce a line equivalent to:

error(0.001) D0 D3 L0

The exact detector numbering can follow QuantumClifford's internal stabilizer
row order. Please document the convention.

In scope

  • A small internal representation for detector error models, or a direct writer
    if that is simpler.
  • Support for independent X, Y, and Z physical fault probabilities.
  • Export for at least the built-in ECC codes where parity_checks and
    faults_matrix are available.
  • Deterministic .dem text output.
  • Unit tests for a few small codes.
  • A smoke test that verifies the emitted .dem file can be parsed by Stim when
    Stim is available in the test environment. This can be optional or guarded so
    the Julia test suite does not require Python by default.
  • Documentation with a short example.

Out of scope

  • Full circuit-to-DEM extraction for noisy syndrome extraction circuits.
  • Modeling correlated gate faults from a full hardware schedule.
  • Coordinates, repeated rounds, or repeat blocks, unless they fall out
    naturally from the implementation.
  • Building or integrating a decoder.

Acceptance criteria

  • detector_error_model(Steane7(); px=..., py=..., pz=...) or an equivalent API
    exists and is exported or documented.
  • The generated .dem files follow Stim's detector error model syntax.
  • Tests check that detector targets match the stabilizers flipped by the
    corresponding Pauli error.
  • Tests check that logical targets match faults_matrix(code).
  • The output ordering is deterministic.
  • Docs show how to generate a .dem file and parse it with Stim.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions