Skip to main content

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 is a high-performance Python and C++ library for simulating and analyzing quantum stabilizer circuits. It is designed for quantum error correction (QEC) research, enabling researchers to simulate large circuits with thousands of qubits and millions of operations at kilohertz sampling rates using vectorized AVX instructions.

Quickstart

Get Stim installed and run your first stabilizer circuit simulation in minutes.

Installation

Install Stim via pip, build from source as a C++ library, or use the CLI binary.

Core Concepts

Learn about stabilizer circuits, Pauli strings, tableaus, and detector error models.

Python API Reference

Full reference for stim.Circuit, stim.Tableau, stim.PauliString, and all simulators.

Why Stim?

Stim makes three core algorithmic improvements over prior stabilizer simulators that make it exceptionally fast:

Vectorized Code

Hot loops use 256-bit AVX instructions. Stim can multiply Pauli strings with 100 billion terms per second.

Reference Frame Sampling

Bulk sampling uses a single reference run, then derives additional samples by propagating simulated errors — constant cost per gate.

Inverted Tableau

Tracking the inverse stabilizer tableau makes redundant measurements (common in QEC) run in linear time instead of quadratic.

Get started

1

Install Stim

Install the Python package with pip:
pip install stim
2

Build a circuit

Define a stabilizer circuit using Stim’s circuit language:
import stim

circuit = stim.Circuit("""
    H 0
    CNOT 0 1
    M 0 1
""")
3

Sample measurements

Compile a sampler and collect measurement shots:
sampler = circuit.compile_sampler()
shots = sampler.sample(1000)
print(shots[:5])
# [[False, False], [True, True], ...]
4

Analyze errors

Convert a noisy circuit into a detector error model for decoder configuration:
noisy = stim.Circuit("""
    X_ERROR(0.001) 0 1
    H 0
    CNOT 0 1
    DEPOLARIZE1(0.001) 0 1
    M 0 1
    DETECTOR rec[-1] rec[-2]
""")
dem = noisy.detector_error_model(decompose_errors=True)
print(dem)

Explore the documentation

Sampling guide

Learn measurement sampling, detector sampling, and bulk data collection workflows.

Detector error models

Convert noisy circuits into Tanner graphs for configuring decoders.

Sinter: QEC sampling

Run parallel Monte Carlo sampling across CPU cores with the Sinter companion tool.

Gate reference

Browse all supported Clifford gates, noise channels, and measurement operations.

Command line

Use Stim’s CLI for scripting, pipeline integration, and quick analysis.

File formats

Understand the .stim circuit format and .dem detector error model format.
Stim only supports Clifford (stabilizer) operations. There is no support for non-Clifford gates like T gates or Toffoli gates. For non-Pauli noise, drive a stim.TableauSimulator manually.

Build docs developers (and LLMs) love