Stim Compiler

Pattern to stim compiler.

This module provides:

  • stim_compile: Function to compile a pattern into stim format.

graphqomb.stim_glue.compiler.stim_compile(pattern, *, emit_qubit_coords=True, noise_models=None, tick_duration=1.0)[source]

Compile a pattern to stim format.

Parameters:
  • pattern (Pattern) – The pattern to compile.

  • emit_qubit_coords (bool, optional) – Whether to emit QUBIT_COORDS instructions for nodes with coordinates, by default True.

  • noise_models (collections.abc.Sequence[NoiseModel] | None, optional) – Custom noise models for injecting Stim noise instructions, by default None. Use DepolarizingNoiseModel for gate noise and MeasurementFlipNoiseModel for measurement errors.

  • tick_duration (float, optional) – Duration associated with each TICK for idle noise, by default 1.0.

Returns:

The compiled stim string.

Return type:

str

Raises:

ValueError – If the pattern’s frame carries Clifford feedforward (cflow): stim classical feedback is Pauli-only, so such patterns cannot be exported.

Notes

Stim only supports Clifford gates, therefore this compiler only supports Pauli measurements (X, Y, Z basis) which correspond to Clifford operations. Non-Pauli measurements will raise a ValueError.

Each parity check group compiles to a DETECTOR instruction, and the group’s tag from graphqomb.pauli_frame.PauliFrame.parity_check_tags is emitted as a Stim instruction tag (for example DETECTOR[type=flag]). Use graphqomb.stim_glue.postselect.flag_postselection_mask on the compiled circuit to post-select flag detectors with sinter.

Examples

Basic compilation without noise:

>>> # stim_str = stim_compile(pattern)

With depolarizing and measurement flip noise:

>>> from graphqomb.noise_model import DepolarizingNoiseModel, MeasurementFlipNoiseModel
>>> # stim_str = stim_compile(
>>> #     pattern,
>>> #     noise_models=[
>>> #         DepolarizingNoiseModel(p1=0.001, p2=0.01),
>>> #         MeasurementFlipNoiseModel(p=0.001)
>>> #     ]
>>> # )