Documentation Index
Fetch the complete documentation index at: https://mintlify.com/quantumlib/Stim/llms.txt
Use this file to discover all available pages before exploring further.
stim.Circuit is the central object in Stim. It holds a sequence of instructions — Clifford gates, measurements, resets, noise channels, and annotations — that describe a stabilizer circuit. Every sampling and analysis workflow begins with building or loading a circuit, then invoking methods such as compile_sampler() or detector_error_model() to produce results. Circuits can be constructed from a string of .stim program text, generated automatically for common code families, or loaded from a file.
The .stim text format
A.stim file is a UTF-8 text file made up of instruction lines. Each line is either blank, an instruction, a REPEAT block initiator, or a closing }. Comments begin with # and indentation is purely decorative.
An instruction has the form:
rec[-n] (measurement record offsets), or Pauli targets like X1.
Gate categories
Clifford gates
Unitary operations:
H, S, CNOT, CX, CZ, SWAP, ISWAP, and many more. These transform the stabilizer state without collapsing it.Collapsing gates
Measurements and resets:
M (Z-basis measure), MX, MY, MR (measure-and-reset), R (reset). Results are appended to the measurement record.Noise channels
Probabilistic Pauli errors:
X_ERROR(p), DEPOLARIZE1(p), DEPOLARIZE2(p), and others. These are ignored during ideal simulation.Annotations
DETECTOR and OBSERVABLE_INCLUDE are the most important annotations. They define which measurement results form parity checks and which track logical qubit state. Other annotations (QUBIT_COORDS, TICK, SHIFT_COORDS) add spacetime layout hints without affecting simulation.
Basic circuit examples
- Bell pair
- Teleportation
- Noisy repetition code
Creating circuits in Python
Using Circuit.generated()
Generate common QEC circuits with configurable noise in a single call:Available code tasks include
"repetition_code:memory", "surface_code:rotated_memory_x", "surface_code:rotated_memory_z", "surface_code:unrotated_memory_x", "surface_code:unrotated_memory_z", and "color_code:memory_xyz".Key circuit properties
Once you have a circuit, several properties let you inspect its structure without running a simulation:num_measurements, num_detectors, and num_observables fully expand REPEAT blocks when counting. A circuit with REPEAT 1000 { MR 1 3 5 } reports num_measurements = 3000.REPEAT blocks
REPEAT K { ... } executes its body K times. Repetition is the standard way to express the periodic stabilizer measurement rounds in QEC codes without literally unrolling them.