rstim
rstim is a Rust stabilizer-circuit simulator and detector-error-model (DEM)
toolkit. It parses Stim-style circuits, generates common QEC memory circuits,
samples measurements and detection events, and extracts DEMs for downstream
decoders.
Add the simulator library from crates.io:
[]
= "0.8"
= { = "0.4.0", = false }
rstim's sampling APIs accept RNGs from rand 0.8, so downstream crates that
seed their own RNG should depend on that major version explicitly.
use ;
use ;
let circuit = parse_lines?;
let mut rng = seed_from_u64;
let samples = sample_batch?;
for shot in 0..8
# Ok::
No optional feature is required for the simulator library API. Library-only
consumers can disable the default CLI features with default-features = false.
Reusable file-independent command operations live in rstim::operations.
Optional features are intentionally additive:
unified-cliadds structured circuit, dataset, decoding, and capability commands.clibuilds the simulator commands andrstimexecutable.ilpadds exact envelope MLE through HiGHS.codegen-cssenables CSS circuit generation backed byqec-code.shot-viewerembeds the browser viewer and exposes its loopback server API.plottingadds the self-containedrstim surface-code-lerexperiment and SVG plot.benchmark-toolsbuilds benchmark workers and examples.benchmark-telemetryenables internal benchmark instrumentation.qasmenables checked OpenQASM 2.0 import/export with register layouts, ordered measurements, and explicit stabilizer or near-Clifford lowering. See the QASM 2 guide. Addunified-clito exposecircuit import-qasm,circuit export-qasm, and document sampling with explicit result views.
OpenQASM 2.0 circuits
The optional qasm feature adds a checked conversion pipeline: parse and validate
the source, expand gate definitions into ordered typed operations, analyze backend
support, then lower for stabilizer or near-Clifford execution. T gates and general
rotations require an explicit near-Clifford backend. Mid-circuit measurement,
reset and one-bit X/Y/Z feedback retain their execution order.
Keep the versioned semantic JSON document for bidirectional conversion: it
preserves declared registers and overwritten classical destinations. Native
.stim output is an execution projection. Native-to-QASM export checks a
specified instruction subset; noise and loss are rejected, and dropping QEC
annotations requires an explicit reported policy.
From the development checkout, install the optional commands with
cargo install --locked --path rstim --features qasm --force. Follow the
runnable feedback example or the
Rust API example. The guide includes the support
matrix, resource limits, phase conventions and independent semantic tests.
CLI and further reading
The development checkout combines all public commands in one executable.
Install it with cargo install --locked --path rstim --force. This combined release
has not yet been published to crates.io. A smaller simulator-only CLI can be
built with --no-default-features --features cli.
After installation, run rstim surface-code-ler --distances 3,5,7 --rounds 9,15,21 --physical-error-rates 0.008,0.009,0.01,0.011,0.012 --shots 2000 --out-dir .
from any working directory to produce a CSV and SVG plot.
Detector error models must be decomposed into graphlike components before
passing them to a matching decoder that only accepts one- and two-detector
errors.
See the getting-started guide, the near-Clifford usage guide (compiled execution, Strict/Fused arithmetic, and raw postselected counts), the repository's complete external-consumer example, and the rmatching decoder. The full API reference is available on docs.rs.
Licensed under Apache-2.0.
For a Rust-only library dependency, set default-features = false. Core simulation,
DEM analysis, measurement transforms, and QP101/SVG export remain available.
Compressed sample archive readers, writers, and corruption fixtures require the
archive-zstd feature, enabled by default and by cli. Archive metadata and
uncompressed measurement transforms do not require it.