Stim supports over 100 operations organized into eight categories: Pauli gates, single-qubit Clifford gates, two-qubit Clifford gates, noise channels, collapsing gates (measurements and resets), pair measurement gates, generalized Pauli product gates, control flow, and annotations. Gate names are case-insensitive and can be broadcast over multiple targets. All qubits start in the |0⟩ state by convention.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.
Pauli Gates
Pauli Gates
Pauli gates apply the four fundamental single-qubit Pauli operations. They take no parenthesized arguments and accept one or more qubit targets.
| Gate | Description | Stabilizer action |
|---|---|---|
I | Identity — does nothing | X → X, Z → Z |
X | Pauli X — bit flip | X → X, Z → −Z |
Y | Pauli Y | X → −X, Z → −Z |
Z | Pauli Z — phase flip | X → −X, Z → Z |
Single-Qubit Clifford Gates
Single-Qubit Clifford Gates
Single-qubit Clifford gates perform rotations within the single-qubit Clifford group. They take no parenthesized arguments and accept one or more qubit targets; when given multiple targets the gate is broadcast over each target in order.
| Gate | Description |
|---|---|
H / H_XZ | Hadamard — swaps X and Z axes |
H_XY | Hadamard variant swapping X and Y |
H_YZ | Hadamard variant swapping Y and Z |
H_NXZ | Hadamard with negation on X and Z |
H_NXY | Hadamard variant swapping −X and Y |
H_NYZ | Hadamard variant swapping −Y and Z |
S / SQRT_Z | S gate (phase gate) — 90° rotation around Z |
S_DAG / SQRT_Z_DAG | S† — inverse of S |
SQRT_X | 90° rotation around X |
SQRT_X_DAG | Inverse 90° rotation around X |
SQRT_Y | 90° rotation around Y |
SQRT_Y_DAG | Inverse 90° rotation around Y |
C_XYZ | Right-handed period-3 cycle X → Y → Z → X |
C_ZYX | Left-handed period-3 cycle X → Z → Y → X |
C_NXYZ | Period-3 cycle −X → Y → Z → −X |
C_NZYX | Period-3 cycle X → −Z → Y → X |
C_XNYZ | Period-3 cycle X → −Y → Z → X |
C_XYNZ | Period-3 cycle X → Y → −Z → X |
C_ZNYX | Period-3 cycle X → Z → −Y → X |
C_ZYNX | Period-3 cycle X → −Z → −Y → X |
H, H_XZ, S, and SQRT_Z are aliases for the same operation. S_DAG and SQRT_Z_DAG are also aliases for each other.Two-Qubit Clifford Gates
Two-Qubit Clifford Gates
Two-qubit Clifford gates act on pairs of qubits. When given more than two targets they are broadcast over aligned pairs in order —
CNOT 0 1 2 3 applies CNOT to (0,1) then (2,3). An odd number of targets is an error.| Gate | Description |
|---|---|
CNOT / CX / ZCX | Controlled-X (controlled-NOT). Control qubit listed first. |
CY / ZCY | Controlled-Y |
CZ / ZCZ | Controlled-Z |
SWAP | Swaps two qubits |
ISWAP | SWAP with an extra iZ⊗Z phase |
ISWAP_DAG | Inverse of ISWAP |
CXSWAP | Applies CX then SWAP |
SWAPCX / CZSWAP | Applies SWAP then CX |
SWAPCZ | Applies SWAP then CZ |
SQRT_XX | 90° rotation in the XX plane |
SQRT_XX_DAG | Inverse 90° rotation in the XX plane |
SQRT_YY | 90° rotation in the YY plane |
SQRT_YY_DAG | Inverse 90° rotation in the YY plane |
SQRT_ZZ | 90° rotation in the ZZ plane |
SQRT_ZZ_DAG | Inverse 90° rotation in the ZZ plane |
XCX | X-controlled-X |
XCY | X-controlled-Y |
XCZ | X-controlled-Z |
YCX | Y-controlled-X |
YCY | Y-controlled-Y |
YCZ | Y-controlled-Z |
II | Two-qubit identity (does nothing) |
Noise Channels
Noise Channels
Noise channels apply probabilistic errors. They take one probability argument inside parentheses, written as
GATE(p) targets. They only have an effect during noisy simulation; they are no-ops in ideal stabilizer simulation unless the simulator is configured to include them.| Gate | Description |
|---|---|
X_ERROR(p) | Apply X with probability p |
Y_ERROR(p) | Apply Y with probability p |
Z_ERROR(p) | Apply Z with probability p |
I_ERROR(p) | Apply identity with probability p (vacuous) |
II_ERROR(p) | Two-qubit identity error (vacuous) |
DEPOLARIZE1(p) | Uniform single-qubit depolarizing channel: X, Y, or Z each with probability p/3 |
DEPOLARIZE2(p) | Uniform two-qubit depolarizing channel over all 15 non-identity Paulis |
PAULI_CHANNEL_1(px, py, pz) | Single-qubit Pauli channel with explicit X, Y, Z probabilities |
PAULI_CHANNEL_2(pIX, pIY, pIZ, pXI, pXX, ...) | Two-qubit Pauli channel with all 15 non-identity probabilities |
CORRELATED_ERROR(p) X0 Y1 Z2 | Apply the given Pauli product with probability p |
ELSE_CORRELATED_ERROR(p) ... | Like CORRELATED_ERROR but conditioned on the preceding correlated error not having fired |
E(p) ... | Alias for CORRELATED_ERROR |
HERALDED_ERASE(p) | Erase qubit with probability p; always appends a herald measurement bit |
HERALDED_PAULI_CHANNEL_1(p_no, pX, pY, pZ) | Heralded single-qubit Pauli channel; always appends a herald bit |
Collapsing Gates (Measurements and Resets)
Collapsing Gates (Measurements and Resets)
Collapsing gates measure and/or reset qubits. Measurement results are appended to the measurement record and can be referenced by subsequent instructions using
Reset gates (no measurement result appended)
rec[-n] targets. A ! prefix on a qubit target inverts the recorded result.Measurement gates| Gate | Basis | Resets? |
|---|---|---|
M / MZ | Z | No |
MX | X | No |
MY | Y | No |
MR / MRZ | Z | Yes |
MRX | X | Yes |
MRY | Y | Yes |
| Gate | Resets to | |
|---|---|---|
R / RZ | 0⟩ (Z basis) | |
RX | +⟩ (X basis) | |
RY | i⟩ (Y basis) |
M and MZ are aliases. MR and MRZ are aliases. R and RZ are aliases.Pair Measurement Gates
Pair Measurement Gates
Pair measurement gates measure two-qubit Pauli products. Each pair of targets is measured as a joint observable.
| Gate | Measured observable |
|---|---|
MXX | X⊗X on each target pair |
MYY | Y⊗Y on each target pair |
MZZ | Z⊗Z on each target pair |
Generalized Pauli Product Gates
Generalized Pauli Product Gates
These gates apply or measure arbitrary Pauli products specified using Pauli targets (
X0, Y1, Z2) joined by combiner tokens (*).| Gate | Description |
|---|---|
MPP | Measure arbitrary Pauli product(s) |
SPP | Apply the square root of a Pauli product |
SPP_DAG | Apply the inverse square root of a Pauli product |
Annotations
Annotations
Annotations carry metadata used for detection-event sampling, circuit drawing, and spacetime layout hinting. They have no effect on the quantum state or the measurement record.
| Gate | Description |
|---|---|
DETECTOR(coords...) | Declares a detection event defined by the XOR of the listed rec[-n] measurement results. Optional coordinate arguments hint at spacetime location. |
OBSERVABLE_INCLUDE(k) | XORs the listed rec[-n] results into logical observable k. |
TICK | Marks the boundary between time steps. Used for circuit drawing and timing hints. |
QUBIT_COORDS(x, y, ...) | Annotates the spacetime coordinates of a qubit. |
SHIFT_COORDS(dx, dy, ...) | Shifts the global coordinate offset, used inside REPEAT blocks. |
MPAD(bit) | Appends a constant 0 or 1 to the measurement record without measuring a qubit. |
Control Flow
Control Flow
Stim provides one control-flow construct: the
REPEAT block.| Construct | Description |
|---|---|
REPEAT K { ... } | Repeats the enclosed instructions exactly K times. K must be a positive integer (zero is not allowed). |