Skip to main content

Crate stim

Crate stim 

Source
Expand description

Safe public Stim Rust bindings.

Stim is a high-performance library for simulating and analyzing quantum stabilizer circuits. This crate provides safe Rust wrappers around the core C++ library, exposing types for building circuits, sampling measurements, analyzing errors, and working with stabilizer tableaus and Pauli strings.

§Core types

  • Circuit – a mutable stabilizer circuit that describes a noisy quantum computation.
  • DetectorErrorModel – an error model listing independent fault mechanisms and the detectors/observables they flip.
  • PauliString – a signed tensor product of Pauli operators.
  • Tableau – a stabilizer tableau representing a Clifford operation.

§Simulators

  • TableauSimulator – an interactive stabilizer simulator backed by an inverse stabilizer tableau. Supports gate-by-gate execution, mid-circuit measurements, resets, and noise channels.
  • FlipSimulator – a batched simulator that tracks Pauli flips and classical flip records, requiring only O(1) work per gate.
  • MeasurementSampler – fast repeated measurement sampling from a compiled circuit.
  • DetectorSampler – fast repeated detector-event sampling from a compiled circuit.
  • DemSampler – fast repeated sampling from a compiled detector error model.
  • MeasurementsToDetectionEventsConverter – converts raw measurement results into detection events using a compiled circuit.

§I/O

  • read_shot_data_file – reads shot data from files in Stim’s various result formats ("01", "b8", "r8", "dets", "hits", "ptb64").
  • write_shot_data_file – writes shot data to files in those formats.

§Rust-only utilities

§Error handling

All fallible operations return Result<T>, which is an alias for std::result::Result<T, StimError>. The StimError type wraps a human-readable message and implements std::error::Error.

§Quick start

// Build a simple Bell-state circuit with noise.
let circuit: stim::Circuit = "\
    H 0
    CNOT 0 1
    DEPOLARIZE2(0.01) 0 1
    M 0 1
    DETECTOR rec[-1] rec[-2]
".parse().unwrap();

// Sample detector events.
let mut sampler = circuit.compile_detector_sampler();
let events = sampler.sample(100);
assert_eq!(events.ncols(), 1);

Modules§

noise

Structs§

Circuit
A mutable stabilizer circuit.
CircuitErrorLocation
Describes the location of an error mechanism within a Stim circuit.
CircuitErrorLocationStackFrame
A single frame in a CircuitErrorLocation’s stack trace, describing the position of an instruction within one level of a circuit’s nesting structure.
CircuitInstruction
A single instruction from a stabilizer circuit, such as H 0 1 or CNOT rec[-1] 5.
CircuitRepeatBlock
A REPEAT block from a circuit, representing a sub-circuit that is executed a fixed number of times.
CircuitTargetsInsideInstruction
Describes a range of targets within a circuit instruction that were involved in a specific error.
CliffordString
A tensor product of single-qubit Clifford gates (e.g. “H x X x S”).
DemInstruction
An instruction from a detector error model (DEM).
DemRepeatBlock
A repeat block from a detector error model.
DemSampler
Fast repeated sampling from a compiled detector error model.
DemTarget
An instruction target from a detector error model (.dem) file.
DemTargetWithCoords
A DEM target paired with coordinate metadata.
DetectorErrorModel
An error model built out of independent error mechanisms, describing how faults trigger detectors and logical observables.
DetectorSampler
Fast repeated detector-event sampling from a compiled Stim circuit.
ExplainedError
Describes a single error mechanism from a Stim circuit, pairing the detectors and observables it affects with the location(s) where it occurs in the circuit.
FlipSimulator
A batched simulator that tracks Pauli flips and classical flip records.
FlippedMeasurement
Describes a measurement that was flipped by an error mechanism.
Flow
A stabilizer flow relating an input Pauli frame to an output Pauli frame, optionally mediated by measurement records and observable indices.
GateData
Metadata about a specific canonical Stim gate.
GateTarget
A target operand used inside Stim circuit instructions.
GateTargetWithCoords
A gate target paired with associated coordinate information.
MeasurementSampler
Fast repeated measurement sampling from a compiled Stim circuit.
MeasurementsToDetectionEventsConverter
Converts batched measurements into detector events using a compiled circuit.
PauliString
A signed tensor product of Pauli operators (e.g., +X ⊗ Y ⊗ Z or -iX ⊗ I ⊗ Z).
PauliStringIterator
An iterator that yields crate::PauliString values matching specified weight and Pauli-type filters.
StimError
An error produced by the Stim library.
Tableau
A stabilizer tableau representing a Clifford operation.
TableauIterator
An iterator that yields all Clifford crate::Tableau values of a given qubit count.
TableauSimulator
A stabilizer circuit simulator backed by an inverse stabilizer tableau.

Enums§

CircuitDiagramType
Diagram style accepted by Circuit::diagram and related helpers.
CircuitInsertOperation
An operation that can be inserted into a Circuit via methods like Circuit::insert().
CircuitItem
An item that can appear at the top level of a crate::Circuit.
ConvertedMeasurements
The result of converting measurements into detector data.
DemAppendOperation
An operation that can be appended to a DetectorErrorModel.
DemInstructionTarget
A target used inside a detector error model (DEM) instruction.
DemInstructionType
A detector error model instruction kind.
DemItem
An item that can appear at the top level of a detector error model.
DetectingRegionFilter
A filter that selects which detecting regions to return from a circuit analysis.
DetectorErrorModelDiagramType
Diagram style accepted by DetectorErrorModel::diagram.
Endian
Qubit-ordering convention used by matrix and state-vector conversions.
Gate
A canonical Stim gate identifier.
OpenQasmVersion
OpenQASM major version supported by Stim exports.
PauliPhase
The unit complex phase carried by a PauliString.
PauliStringConjugation
The type of Clifford operation used to conjugate a PauliString.
PauliValue
A single Pauli operator value accepted by PauliString::set.
SatProblemFormat
SAT/maxSAT format supported by Stim search exports.
ShotDataFormat
Shot-data file/sample format supported by Stim I/O APIs.
TableauSynthesisMethod
Circuit synthesis strategy used when converting a tableau back into a circuit.

Functions§

read_shot_data_file
Reads shot data from a file in one of Stim’s supported formats.
upstream_commit
Returns the pinned upstream Stim commit recorded by the bridge layer.
write_shot_data_file
Writes shot data to a file in one of Stim’s supported formats.

Type Aliases§

Array1
one-dimensional array
Array2
two-dimensional array
Complex32
A 32-bit complex number.
Result
A type alias for results that may contain a StimError.