Stim is built around the stabilizer formalism, a compact way to represent quantum states and Clifford operations that scales polynomially rather than exponentially with qubit count. The two core data structures areDocumentation 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.PauliString, which represents a tensor product of single-qubit Pauli operators, and stim.Tableau, which encodes how a Clifford operation transforms those Pauli operators under conjugation. Together they power every simulation and analysis feature in the library.
Pauli strings
A Pauli string is a tensor product of single-qubit operators chosen from{I, X, Y, Z}, multiplied by a global phase factor of +1, -1, +i, or -i. Stim represents this as stim.PauliString.
Creating Pauli strings
stim.PauliString accepts many input forms:
Combining and inspecting
Pauli strings can be multiplied (composing the tensor products and accumulating phase), and you can check commutation:PauliString.commutes() returns True if the two strings commute and False if they anti-commute. Anti-commutation is determined by counting positions where both strings have non-identity, non-equal Paulis: an odd count means they anti-commute.Pauli strings and circuits
You can propagate a Pauli string through a Clifford operation usingafter():
Tableaus
Astim.Tableau encodes a Clifford operation by recording where each single-qubit Pauli generator is sent under conjugation. For an n-qubit Clifford U, the tableau stores the 2n Pauli strings U X_k U† and U Z_k U† for each qubit k.
Creating tableaus
Composing tableaus
Tableaus multiply in the same order as their corresponding unitaries:Querying outputs
You can ask what Pauli string a given X or Z generator maps to:Inverse tableaus
Stim internally tracks the inverse tableau rather than the forward tableau. This is a detail of the Aaronson–Gottesman simulation algorithm that makes certain operations (like applying a gate to a few qubits of a large state) more efficient. The inverse tableau is accessible viaTableauSimulator.current_inverse_tableau.
TableauSimulator
stim.TableauSimulator provides a general-purpose stabilizer simulator that you control step-by-step. Unlike the fast bulk samplers built on stim.Circuit, it is interactive: you apply gates one at a time and can inspect or manipulate the state between steps.
When to use TableauSimulator vs. compile_sampler
When to use TableauSimulator vs. compile_sampler
Use
stim.TableauSimulator when you need interactive control — for example, to implement adaptive circuits where later gates depend on mid-circuit measurement outcomes. Use circuit.compile_sampler() or circuit.compile_detector_sampler() when you want to collect millions of shots from a fixed circuit as fast as possible; those paths are orders of magnitude faster for bulk sampling.Noise in TableauSimulator
Noise in TableauSimulator
TableauSimulator supports noise operations such as depolarize1(p), depolarize2(p), x_error(p), and z_error(p). These are useful for simulating non-Pauli noise models (such as amplitude damping) by manually decomposing them into Pauli operations and calling them at the right moments — something that cannot be expressed directly in the .stim circuit file format.