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
noise::UniformDepolarizingandnoise::Si1000– pure-Rust stabilizer noise model presets that can be applied withCircuit::with_noise.
§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§
Structs§
- Circuit
- A mutable stabilizer circuit.
- Circuit
Error Location - Describes the location of an error mechanism within a Stim circuit.
- Circuit
Error Location Stack Frame - A single frame in a
CircuitErrorLocation’s stack trace, describing the position of an instruction within one level of a circuit’s nesting structure. - Circuit
Instruction - A single instruction from a stabilizer circuit, such as
H 0 1orCNOT rec[-1] 5. - Circuit
Repeat Block - A
REPEATblock from a circuit, representing a sub-circuit that is executed a fixed number of times. - Circuit
Targets Inside Instruction - Describes a range of targets within a circuit instruction that were involved in a specific error.
- Clifford
String - A tensor product of single-qubit Clifford gates (e.g. “H x X x S”).
- DemInstruction
- An instruction from a detector error model (DEM).
- DemRepeat
Block - 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. - DemTarget
With Coords - A DEM target paired with coordinate metadata.
- Detector
Error Model - An error model built out of independent error mechanisms, describing how faults trigger detectors and logical observables.
- Detector
Sampler - Fast repeated detector-event sampling from a compiled Stim circuit.
- Explained
Error - 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.
- Flip
Simulator - A batched simulator that tracks Pauli flips and classical flip records.
- Flipped
Measurement - 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.
- Gate
Data - Metadata about a specific canonical Stim gate.
- Gate
Target - A target operand used inside Stim circuit instructions.
- Gate
Target With Coords - A gate target paired with associated coordinate information.
- Measurement
Sampler - Fast repeated measurement sampling from a compiled Stim circuit.
- Measurements
ToDetection Events Converter - Converts batched measurements into detector events using a compiled circuit.
- Pauli
String - A signed tensor product of Pauli operators (e.g.,
+X ⊗ Y ⊗ Zor-iX ⊗ I ⊗ Z). - Pauli
String Iterator - An iterator that yields
crate::PauliStringvalues matching specified weight and Pauli-type filters. - Stim
Error - An error produced by the Stim library.
- Tableau
- A stabilizer tableau representing a Clifford operation.
- Tableau
Iterator - An iterator that yields all Clifford
crate::Tableauvalues of a given qubit count. - Tableau
Simulator - A stabilizer circuit simulator backed by an inverse stabilizer tableau.
Enums§
- Circuit
Diagram Type - Diagram style accepted by
Circuit::diagramand related helpers. - Circuit
Insert Operation - An operation that can be inserted into a
Circuitvia methods likeCircuit::insert(). - Circuit
Item - An item that can appear at the top level of a
crate::Circuit. - Converted
Measurements - The result of converting measurements into detector data.
- DemAppend
Operation - An operation that can be appended to a
DetectorErrorModel. - DemInstruction
Target - A target used inside a detector error model (DEM) instruction.
- DemInstruction
Type - A detector error model instruction kind.
- DemItem
- An item that can appear at the top level of a detector error model.
- Detecting
Region Filter - A filter that selects which detecting regions to return from a circuit analysis.
- Detector
Error Model Diagram Type - Diagram style accepted by
DetectorErrorModel::diagram. - Endian
- Qubit-ordering convention used by matrix and state-vector conversions.
- Gate
- A canonical Stim gate identifier.
- Open
Qasm Version - OpenQASM major version supported by Stim exports.
- Pauli
Phase - The unit complex phase carried by a
PauliString. - Pauli
String Conjugation - The type of Clifford operation used to conjugate a
PauliString. - Pauli
Value - A single Pauli operator value accepted by
PauliString::set. - SatProblem
Format - SAT/maxSAT format supported by Stim search exports.
- Shot
Data Format - Shot-data file/sample format supported by Stim I/O APIs.
- Tableau
Synthesis Method - 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.