This page documents every subcommand available in theDocumentation 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 CLI. Each entry includes the full command synopsis showing required and optional flags, descriptions of each flag drawn directly from the Stim source, and working examples you can run from your shell. All commands read from stdin and write to stdout by default; use --in and --out to redirect to files.
stim analyze_errors
stim analyze_errors
Converts a Stim circuit into a detector error model (DEM). The output describes all the ways that circuit errors can produce detection events, expressed as independent probabilistic error mechanisms.SynopsisFlags
Examples
| Flag | Description |
|---|---|
--allow_gauge_detectors | Allows non-deterministic detectors in the circuit. Instead of raising an error, Stim appends a 50% error mechanism for detectors that anticommute with a reset or measurement. |
--approximate_disjoint_errors [probability] | Allows disjoint error channels (e.g. PAULI_CHANNEL_1) to be approximated as independent mechanisms. Accepts an optional probability threshold between 0 and 1. |
--block_decompose_from_introducing_remnant_edges | Prevents the error decomposer from introducing remnant edges — detector sets that only appear as leftovers when splitting a larger error. Only relevant with --decompose_errors. |
--decompose_errors | Decomposes non-graphlike errors (those producing more than two detection events) into graphlike pieces with at most two detection events each, using ^ to annotate suggested splits. Required for use with matching decoders. |
--fold_loops | Enables loop folding for circuits containing REPEAT blocks. Substantially reduces analysis time for large repeat counts by detecting periodicity with a cycle-detection algorithm. |
--ignore_decomposition_failures | When --decompose_errors is active, allows non-graphlike errors to pass through into the output instead of causing an abort. |
--in filepath | Path to the input Stim circuit file. Defaults to stdin. |
--out filepath | Path to write the output detector error model. Defaults to stdout. |
stim convert
stim convert
Converts measurement or detection event data between Stim’s supported result formats: Flags
Examples
01 (dense text), b8 (bit-packed binary), r8 (run-length binary), ptb64 (SIMD-friendly binary), hits (sparse text), and dets (sparse text with type prefixes).Synopsis| Flag | Description |
|---|---|
--bits_per_shot int | Number of bits per record when not using a circuit or DEM to infer sizes. Required when --circuit, --dem, and --num_* flags are all absent. Not supported when writing to dets format. |
--circuit filepath | Path to the Stim circuit that generated the data. Used to infer --num_measurements, --num_detectors, and --num_observables. |
--in filepath | Path to the input data file. Defaults to stdin. |
--in_format 01|b8|r8|ptb64|hits|dets | Format of the input data. Defaults to 01. |
--num_detectors int | Number of detectors per record. Required when writing dets format without a circuit or DEM. |
--num_measurements int | Number of measurements per record. Required when writing dets format without a circuit. |
--num_observables int | Number of observables per record. Required when writing dets format without a circuit or DEM. |
--obs_out filepath | Path to write observable flip data extracted from the input. |
--obs_out_format 01|b8|r8|ptb64|hits|dets | Format for the observable output file. Defaults to 01. Irrelevant unless --obs_out is specified. |
--out filepath | Path to write the converted output. Defaults to stdout. |
--out_format 01|b8|r8|ptb64|hits|dets | Format for the output data. Defaults to 01. |
--types M|D|L | Specifies which event types (measurements, detectors, observables) are present in the input. Required when --circuit is given. |
stim detect
stim detect
Samples detection events and observable flips from a noisy circuit. Detection events indicate which detectors fired (i.e., produced an unexpected parity), while observable flips indicate whether logical observables were corrupted by errors.SynopsisFlags
Examples
| Flag | Description |
|---|---|
--append_observables | Appends observable flip data to the end of each detection sample as if they were extra detectors. Prefer --obs_out to keep the data separate. |
--in filepath | Path to the Stim circuit file. Defaults to stdin. |
--obs_out filepath | Path to write observable flip data separately from the detection events. |
--obs_out_format 01|b8|r8|ptb64|hits|dets | Format for the observable output file. Defaults to 01. |
--out filepath | Path to write the detection event samples. Defaults to stdout. |
--out_format 01|b8|r8|ptb64|hits|dets | Format for the detection event output. Defaults to 01. |
--seed int | Non-negative 64-bit integer seed for the random number generator. Makes results reproducible within the same Stim version and machine architecture. |
--shots int | Number of samples to take. Defaults to 1. Maximum is 10^18. |
Seeded results are not guaranteed to be reproducible across different Stim versions or different machine architectures (e.g., machines with vs. without AVX2 support).
stim diagram
stim diagram
Produces various diagrams of Stim circuits and detector error models. Output types include ASCII text, SVG images, and GLTF 3D models. Use Flags
Available diagram types
Examples
--type to select the diagram format and --tick to restrict the view to a specific time slice.Synopsis| Flag | Description |
|---|---|
--filter_coords coords | Coordinate filter controlling which detectors appear. Points are comma-separated coordinates; multiple points are colon-separated (e.g. 2,3:4,5,6). Also accepts detector indices like D0 or observable indices like L0. |
--in filepath | Path to the input circuit or DEM file. Defaults to stdin. |
--out filepath | Path to write the diagram. Defaults to stdout. |
--remove_noise | Strips noise instructions from the input before diagramming, to focus on circuit structure. |
--tick int | int:int | Restricts the diagram to a specific TICK or half-open range of TICKs (e.g. --tick=5 or --tick=2:7). Tick 0 is before the first TICK instruction. |
--type name | Required. Selects the diagram type (see below). |
| Type | Input | Description |
|---|---|---|
timeline-text | Circuit | ASCII diagram of operations over time, qubits top-to-bottom, time left-to-right. |
timeline-svg | Circuit | SVG image of the circuit timeline. |
timeline-3d | Circuit | GLTF 3D model of the circuit timeline. |
timeline-3d-html | Circuit | Self-contained HTML page with an interactive 3D circuit viewer. |
matchgraph-svg | Circuit or DEM | SVG image of the decoding graph. Red lines cross logical observables. |
matchgraph-3d | Circuit or DEM | GLTF 3D model of the decoding graph. |
matchgraph-3d-html | Circuit or DEM | Self-contained HTML page with an interactive 3D decoding graph viewer. |
detslice-text | Circuit | ASCII diagram of the stabilizers that detectors measure at a given tick. |
detslice-svg | Circuit | SVG image of detector stabilizers at a given tick. Uses Pauli color convention XYZ=RGB. |
timeslice-svg | Circuit | SVG image of the operations applied during a given tick or tick range. |
detslice-with-ops-svg | Circuit | SVG combining a timeslice and the resulting detector slices. |
stim explain_errors
stim explain_errors
Finds which specific physical circuit errors are responsible for producing the error mechanisms in a detector error model. Given a DEM filter, only the matching error mechanisms are explained. This is useful for debugging circuit annotations and for understanding what a decoder’s corrections correspond to physically.SynopsisFlags
Examples
| Flag | Description |
|---|---|
--dem_filter filepath | Path to a DEM file specifying which error mechanisms to explain. If omitted, every single-error mechanism in the circuit is explained. |
--in filepath | Path to the Stim circuit file. Defaults to stdin. |
--out filepath | Path to write the explanations. Defaults to stdout. Output is semi-human-readable text. |
--single | Outputs only the simplest circuit error explanation for each DEM error, chosen by heuristics (fewer Pauli terms, earlier in the circuit). Without this flag, all possible single-error explanations are output. |
stim explain_errors can only explain detection events that result from a single physical error. To explain a set of detection events requiring multiple errors, first use a decoder (e.g. pymatching) to identify the contributing DEM errors, then use this command to map those DEM errors to circuit locations.stim gen
stim gen
Generates example quantum error correction circuits with noise, detector annotations, logical observable definitions, and qubit coordinates. Supports the repetition code, surface code, and color code. Generated circuits are useful for quickly testing workflows, not for production research.SynopsisFlags
Available codes and tasks
Examples
| Flag | Description |
|---|---|
--after_clifford_depolarization probability | Adds DEPOLARIZE1(p) after single-qubit Clifford gates and DEPOLARIZE2(p) after two-qubit Clifford gates. Defaults to 0. |
--after_reset_flip_probability probability | Adds X_ERROR(p) after R/RY resets and Z_ERROR(p) after RX resets. Defaults to 0. |
--before_measure_flip_probability probability | Adds X_ERROR(p) before M/MY measurements and Z_ERROR(p) before MX measurements. Defaults to 0. |
--before_round_data_depolarization probability | Adds DEPOLARIZE1(p) to each data qubit at the start of every stabilizer measurement round. Defaults to 0. |
--code surface_code|repetition_code|color_code | Required. The error correcting code to generate. |
--distance int | Required. Code distance — the minimum number of physical errors that cause a logical error. |
--out filepath | Path to write the generated circuit. Defaults to stdout. |
--rounds int | Required. Number of stabilizer measurement rounds. Must be between 1 and 10^18. |
--task name | Required. The experiment the circuit runs. See table below. |
| Code | Task | Description |
|---|---|---|
repetition_code | memory | Initialize |0>, preserve against noise for N rounds, then measure. |
surface_code | rotated_memory_x | Initialize |+> in a rotated surface code, preserve, measure in X basis. |
surface_code | rotated_memory_z | Initialize |0> in a rotated surface code, preserve, measure in Z basis. |
surface_code | unrotated_memory_x | Initialize |+> in an unrotated surface code, preserve, measure in Z basis. |
surface_code | unrotated_memory_z | Initialize |0> in an unrotated surface code, preserve, measure in Z basis. |
color_code | memory_xyz | Initialize |0>, preserve, measure. Alternates X, Y, Z stabilizer rounds. |
stim help
stim help
Prints helpful information about using Stim. When run without subcommands, this displays the list of available commands and general usage guidance.SynopsisExamples
stim m2d
stim m2d
Converts raw measurement data (as collected from quantum hardware) into detection event data. Stim determines the expected parity of each detector’s measurement set by simulating a noiseless reference sample from the circuit, then compares the actual measurements against those expectations to produce detection events.SynopsisFlags
Examples
| Flag | Description |
|---|---|
--append_observables | Appends observable flip data to each detection sample as if they were extra detectors. Prefer --obs_out to keep data separate. |
--circuit filepath | Required. Path to the Stim circuit that was run on hardware. Defines how to derive detection events from measurements. |
--in filepath | Path to the measurement data file. Defaults to stdin. |
--in_format 01|b8|r8|ptb64|hits|dets | Format of the input measurement data. Defaults to 01. |
--obs_out filepath | Path to write observable flip data separately. |
--obs_out_format 01|b8|r8|ptb64|hits|dets | Format for the observable output. Defaults to 01. |
--out filepath | Path to write the detection event data. Defaults to stdout. |
--out_format 01|b8|r8|ptb64|hits|dets | Format for the detection event output. Defaults to 01. |
--ran_without_feedback | Indicates the quantum hardware skipped Pauli feedback operations. The m2d conversion will account for the feedback effects during post-processing. |
--skip_reference_sample | Assumes the all-zeros measurement result is a valid noiseless circuit output. Skips the tableau simulation of the reference sample for improved performance. |
--sweep filepath | Path to a file with sweep configuration bits that control which conditional Pauli gates were active per shot. |
--sweep_format 01|b8|r8|ptb64|hits|dets | Format of the sweep configuration data. Defaults to 01. |
Use
--skip_reference_sample only when the circuit genuinely produces all-zero measurements under noiseless execution. When this assumption is violated, the output will be incorrect.stim repl
stim repl
Runs Stim in interactive read-evaluate-print-loop (REPL) mode. You type circuit instructions one at a time, and Stim immediately prints measurement results. Useful for quick experiments and exploring how circuits behave.SynopsisExamplesOnce in the REPL, type circuit instructions interactively:
stim sample
stim sample
Samples raw measurement results from a Stim circuit. Each shot produces one measurement result per measurement instruction in the circuit. For sampling detection events instead, use Flags
Examples
stim detect.Synopsis| Flag | Description |
|---|---|
--in filepath | Path to the Stim circuit file. Defaults to stdin. |
--out filepath | Path to write the sampled measurement data. Defaults to stdout. |
--out_format 01|b8|r8|ptb64|hits|dets | Format for the output data. Defaults to 01. |
--seed int | Non-negative 64-bit integer seed for the random number generator. Results are reproducible only within the same Stim version and machine architecture. |
--shots int | Number of samples to take. Defaults to 1. Maximum is 10^18. |
--skip_loop_folding | Disables loop-folding optimization when computing the reference sample. Useful for circuits like honeycomb codes where the folding analysis can be slower than direct simulation. |
--skip_reference_sample | Assumes all-zero measurements are a valid noiseless circuit output. Skips the stabilizer tableau reference simulation, improving performance. Only safe when the assumption holds. |
stim sample_dem
stim sample_dem
Samples detection events directly from a detector error model (DEM), bypassing circuit simulation entirely. Supports recording which errors occurred and replaying them later to deterministically reproduce or study specific error patterns.SynopsisFlags
Examples
| Flag | Description |
|---|---|
--err_out filepath | Path to write a record of which DEM errors occurred in each shot. Can be fed back into --replay_err_in to reproduce or modify the errors. |
--err_out_format 01|b8|r8|ptb64|hits|dets | Format for the error record output. Defaults to 01. Irrelevant unless --err_out is specified. |
--in filepath | Path to the detector error model file. Defaults to stdin. |
--obs_out filepath | Path to write observable flip data (which logical observables were corrupted) separately from detection events. |
--obs_out_format 01|b8|r8|ptb64|hits|dets | Format for the observable output. Defaults to 01. |
--out filepath | Path to write the sampled detection event data. Defaults to stdout. |
--out_format 01|b8|r8|ptb64|hits|dets | Format for the detection event output. Defaults to 01. |
--replay_err_in filepath | Path to a file of previously recorded error data. When specified, errors are driven by the file instead of sampled randomly. |
--replay_err_in_format 01|b8|r8|ptb64|hits|dets | Format of the error replay input. Defaults to 01. Irrelevant unless --replay_err_in is specified. |
--seed int | Non-negative 64-bit integer seed for the random number generator. Results are reproducible only within the same Stim version and machine architecture. |
--shots int | Number of samples to take. Defaults to 1. Maximum is 10^18. |