Stim is a fast Python library for high-performance simulation and analysis of quantum stabilizer circuits, particularly those used in quantum error correction (QEC). It focuses on providing low-level, fast building blocks for simulating circuits with thousands of qubits and millions of operations, enabling rapid Monte Carlo sampling. The library maintains a regular release cadence, with minor versions typically released every few months, ensuring active development and improvements.
pip install stimVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a basic quantum circuit, add gates, compile a sampler for efficient measurement shot generation, and extract a detector error model from a noisy circuit. The example includes fundamental operations and a simple noise model.
Explicitly set `ignore_ungraphlike_errors=False` if you require the old behavior, or review your logic to account for the new default.
Ensure all operations involving `"ptb64"` format data handle shot counts that are exact multiples of 64.
When interacting with Stim's C++ components directly, always pin to a specific Stim version and be prepared for API changes with updates. For stability, use the Python API.
Upgrade to Stim v1.12.1 or newer to ensure correct behavior of `HERALDED_PAULI_CHANNEL_1`. If using older versions, thoroughly validate circuits involving this gate. [cite: -Github release v1.12.1]
For advanced noise or feedback scenarios, use `stim.TableauSimulator` and implement custom logic for state evolution.
Install Stim using pip: `pip install stim`
Adjust the `shots` parameter to be a multiple of 64. For example, `sampler.sample(shots=128, format='ptb64')`.
Consult the Stim documentation for the specific gate's target format. For single-qubit gates, pass qubits individually (e.g., `circuit.append("H", [0]); circuit.append("H", [1])`) or as separate entries. For multi-qubit gates, ensure the list format matches (e.g., `circuit.append("CNOT", [0, 1])`).