Module 6: Measurement and Fast Stabilizer Simulation
Learning goals. After this module you should be able to
Classify a Pauli measurement on a stabilizer state or code as deterministic, random, or logical, and update the generators after the measurement.
Explain why random outcomes on stabilizer states always have probability exactly .
Find the outcome of a deterministic measurement by solving a linear system over (Gaussian elimination).
Describe the Aaronson-Gottesman destabilizer tableau and run its measurement algorithm by hand on small examples.
Explain the two ideas that make Stim fast for error-correction workloads: a single reference tableau run plus Pauli frames, and detectors.
Module 5 showed that Clifford gates act on a stabilizer tableau by cheap column updates. The remaining ingredient of the Gottesman-Knill theorem is measurement. Measurement is also the heart of error correction: syndrome extraction is the repeated measurement of stabilizer generators. In this module we work out exactly what a Pauli measurement does to a stabilizer description, and then how to do it fast.
1. Measuring a Pauli operator
Measuring a Hermitian Pauli (eigenvalues ) on a state gives outcome , with , with probability
and leaves the state . We use the standard convention that eigenvalue is bit and eigenvalue is bit . Measuring qubit in the computational basis is the case .
Everything hinges on how relates to the stabilizer group : does it anticommute with some generator, and if not, is it (up to sign) an element of ?
Theorem 6.1 (Pauli measurement on a stabilizer code).
Let be any state in the codespace of , and measure a Hermitian Pauli with .
Deterministic. If for some , the outcome is with certainty and the state does not change.
Logical. If commutes with every but , then is a nontrivial logical operator. The outcome probabilities depend on the encoded state. Afterwards the state is stabilized by : the stabilizer grows by one generator and one logical qubit is used up.
Random. If anticommutes with at least one generator, the outcome is uniformly random, , independently of . Pick one anticommuting generator . The post-measurement stabilizer is obtained by
replacing every other anticommuting generator by , then
replacing itself by .
For a stabilizer state (, ), case 2 cannot occur: every Pauli either anticommutes with some generator or is an element of .
Proof
(1) If then , an eigenstate; the outcome is and .
(3) Suppose . Using ,
where in the last step we used ( is Hermitian). So and . After the measurement the state is stabilized by . Which old generators survive? A generator that commutes with commutes with , so it still stabilizes . A generator that anticommutes with does not. But the product of two anticommuting generators commutes with (two sign flips cancel) and stabilizes , so it survives. The new list consists of , the products , and the untouched commuting generators. These are independent commuting operators, so they generate the new stabilizer. Note that itself is gone: it is the one generator “spent” on the measurement.
(2) commutes with , so maps the codespace to itself, and the post-measurement state is stabilized by and by . Since , the new group has independent generators. For , the normalizer equals up to phases (Module 4: a Lagrangian subspace is its own symplectic complement), so case 2 is empty.
measure Pauli Panticommutes with some g_i ?random outcomep = 1/2, update S+P or -P in S ?deterministicstate unchangedlogical (codes)k drops by 1yesnoyesno
Two consequences are worth stating plainly.
Random outcomes are always fair coins. For a Pauli measurement on a stabilizer state, the only possible probabilities are , and . Never . This is why a stabilizer simulator only needs a random bit, not a probability calculation.
“Commutes with everything” is not the same as “deterministic” for codes. The last leaf of the decision tree (case 2 of Theorem 6.1) is exactly a logical measurement. Using the theorem’s numbering: syndrome measurements of a code are case 1 (the measured operators are generators); measuring a logical operator is case 2; measuring a single qubit of an encoded block is usually case 3 (random).
2. Worked examples
Example 6.1 (Measuring half of a Bell pair).
Take with and measure .
anticommutes with (one clash) and commutes with . Case 3: the outcome is random. Take ; there are no other anticommuting generators.
Replace by . The new stabilizer is . Multiplying the two generators, , so this is for and for .
Now measure . It commutes with both generators and : deterministic, with the same outcome . The perfect correlation of a Bell pair falls out of the algebra.
On the same Bell state, and are deterministic with outcome , and is deterministic with outcome , because . Measuring instead is random (it anticommutes with ) and leaves .
Example 6.2 (Syndrome, logical, and random measurements on the repetition code).
Measuring reveals the encoded bit and collapses the code to , i.e. or .
A good drill uses all three cases in a row. Start from the code of Module 4 and measure, in order, , , , (taking outcome each time):
step
measure
case
generators afterwards
1
logical (commutes, not in )
2
deterministic:
unchanged
3
random: anticommutes with only
4
deterministic:
unchanged
Step 3 is the instructive one: commutes with (overlap 2) but anticommutes with (overlap 1), so the generator added in step 1 is the one that gets replaced.
3. Deterministic outcomes: Gaussian elimination
In case 1 we know , but which sign? We must write as a product of generators,
and track the sign of the product. In binary this is the linear system over , where is the check matrix and the binary vector of . Solve it by Gaussian elimination (row reduction mod 2), then multiply the selected rows with the phase-aware product of Module 5 (Proposition 5.3).
Example 6.3 (Is YYX in the GHZ stabilizer?).
The GHZ state has . To measure we solve
The part forces ; the part then forces , . The product with phases is . So , and measuring gives with certainty. The same calculation shows and also give , while and are random.
Row reduction is also the general tool for changing the description without changing the state: it brings a tableau into a canonical form, detects dependent or invalid generator lists, and exposes logical operators. But it costs bit operations for an -qubit tableau, which is the bottleneck that Aaronson and Gottesman removed.
Here is the cost picture for a straightforward tableau of stabilizer rows.
operation
cost
Clifford gate
: one or two columns of every row
decide random vs deterministic for
: scan column of the block
random-case update
: up to row products of length
deterministic-case outcome
: Gaussian elimination
4. Destabilizers: the Aaronson-Gottesman trick
The expensive step is finding which generators multiply to . Aaronson and Gottesman observed that if we store, next to each stabilizer generator, a “partner” Pauli that anticommutes with it and with nothing else, the answer can be read off directly.
Definition 6.1 (Destabilizer tableau).
A destabilizer tableau for is a list of Paulis such that
the pairwise commute (they generate ), and the pairwise commute;
anticommutes with and commutes with for .
The are called destabilizers. The tableau is stored as a bit array (destabilizer rows on top, stabilizer rows below; columns of bits, of bits and one sign column), plus one scratch row used during measurement, so the allocated array is .
For take and : the tableau starts as the identity matrix. Clifford gates are applied to all rows with the rules of Module 5. Conjugation preserves all commutation relations, so the defining property is maintained for free. In fact the full tableau is just the Clifford tableau of the circuit applied so far (Proposition 5.1): destabilizers are the images of the and stabilizers the images of the .
X blockZ blocksignn x nn x nrn x nn x nrscratch row (used in the deterministic case)destabilizersd_1 ... d_nstabilizerss_1 ... s_n
Lemma 6.1 (Reading off the decomposition).
In a destabilizer tableau, the rows form a basis of , and any Pauli decomposes, up to phase, as
In particular, if commutes with every stabilizer, then : the stabilizers needed are exactly those whose destabilizer anticommutes with .
Proof
Write (vectors over ). Pair with : by the defining relations only the term survives, so . Pair with : only survives, so . The rows are linearly independent, since any linear relation can be paired with each and to show all coefficients vanish, so they form a basis and the expansion exists. If commutes with all then all .
Each coefficient is one symplectic product, . That turns the linear solve into work. Here is the full algorithm for measuring (the general Pauli case is reduced to this by a Clifford basis change). Note that is just the bit of .
Random case. Some stabilizer row has (it anticommutes with ). Then:
for every other row (destabilizer or stabilizer) with , replace ;
move into the destabilizer slot: ;
set with a fresh random bit , and return .
Deterministic case. No stabilizer row has . Clear the scratch row, multiply into it every for which has , and return its sign bit. The tableau is unchanged.
Both cases cost : at most row products of length .
Proof
Random case: step 1 on stabilizer rows is exactly the update of Theorem 6.1. On destabilizer rows it restores the relations: every row other than now commutes with , and multiplying () by does not change its commutation with any , , while making it commute with , the new . The old anticommutes with the new , commutes with every other stabilizer, and commutes with the other destabilizers after step 1, so it is a valid new . Deterministic case: by Lemma 6.1, , and is the bit of . Accumulating that product with the phase-aware row product (Proposition 5.3) gives the sign.
We implemented this algorithm in numpy and compared it to an exact state-vector simulation on 300 random 4-qubit circuits of 40 operations: 1148 random outcomes, all with state-vector probability exactly , and 1929 deterministic outcomes, all matching.
Example 6.4 (AG trace on a Bell pair).
After and the tableau is (this is the Clifford tableau of the Bell circuit from Module 5)
Measure . Stabilizer has : random case with . No other row has (, , all have ), so step 1 does nothing. Step 2: . Step 3: . Result:
Measure . Neither nor has : deterministic. The destabilizers with are and , so the scratch row becomes , and the outcome is , the same as the first measurement.
The same procedure on the GHZ state (; ) measuring is in the homework; it uses step 1 nontrivially, because the destabilizer has and gets multiplied by .
Costs, compared. With destabilizers the memory doubles, from bits to bits (for : 20,100 versus 40,200 bits, against amplitudes for a state vector). In exchange, every measurement costs instead of up to . The speedup is polynomial: destabilizers do not make any non-Clifford circuit simulable.
5. CHP: the reference implementation
Aaronson and Gottesman released their algorithm as a short C program, CHP (for CNOT-Hadamard-Phase). Its input language has four instructions,
h a (Hadamard on qubit ), p a (phase gate ), c a b (CNOT with control , target ), and m a (measure qubit in the basis),
and its state is exactly the tableau above, plus the scratch row. A Bell-pair program reads h 0, c 0 1, m 0, m 1; CHP reports the first measurement as random and the second as determinate with the same value. The 2004 paper reports that CHP handled circuits with thousands of qubits on the hardware of the time. CHP is small enough to read in an afternoon and is still the clearest introduction to how a stabilizer simulator works.
6. Stim: frames and detectors
Error-correction experiments ask a stabilizer simulator for something specific: millions of samples of the same noisy circuit. Gidney’s simulator Stim (2021) is built around that workload. It keeps the tableau idea of CHP and adds three improvements:
it tracks the inverse of the stabilizer tableau, which reduces the cost of deterministic measurements from quadratic to linear in ;
it uses a cache-friendly memory layout and 256-bit SIMD instructions;
it runs the expensive tableau simulation only once, to produce a noiseless reference sample, and then produces all other samples by propagating batches of Pauli frames.
The third idea deserves a picture. In a stabilizer circuit with Pauli noise, a noisy shot differs from a noiseless one only by some Pauli errors. A Pauli error pushed through a Clifford gate is another Pauli (that is the definition of Clifford!), so we can track just the error, the “frame”, as a pair of bits per qubit. When the frame has an or component on a qubit being measured in the basis, that measurement result is flipped relative to the reference. One frame update per gate costs per qubit, and Stim packs many shots into the bits of a machine word, processing them in parallel.
reference sampleone tableau runPauli frameserrors only, many shotsXORnoisy samplesmeasurement records
You can watch a frame propagate with Stim’s FlipSimulator. After X_ERROR(1) 0, CNOT 0 1, M 0 1 2, the measurement flips are in every shot: the error on qubit 0 has spread forward through the CNOT to qubit 1, exactly as the CNOT rule of Module 5 predicts.
Detectors (preview). A single measurement in a QEC circuit is often random even without noise (think of the first measurement of an -check on a fresh ). What is deterministic is certain parities of measurements, for example the same stabilizer measured in two consecutive rounds. Stim calls such a parity a detector: a set of measurement results whose XOR is fixed in the noiseless circuit. A detector that fires signals an error. Here is the smallest example: an ancilla (qubit 2) measures twice, with an error on qubit 0 in between.
The first detector (round-1 parity, deterministic because the data start in ) never fires; the second (round 1 XOR round 2) fires in every shot, flagging the error between the rounds. Without the error, both detectors are always . Stim’s built-in repetition_code:memory circuit with distance 3 and 3 rounds has 5 qubits, 9 measurements, 8 detectors and 1 logical observable. Detectors, observables, and the detector error model are the subject of Module 9.
Summary
A Pauli measurement on a stabilizer code falls into one of three cases (Theorem 6.1): deterministic if , logical if commutes with but is not in it, and uniformly random if it anticommutes with some generator. For states only the first and last occur.
Random-case update: multiply the chosen anticommuting generator into the other anticommuting ones, then replace it by (Example 6.1, Example 6.2).
The sign of a deterministic outcome comes from solving by Gaussian elimination and multiplying rows with phases (Example 6.3), at cost .
Stim adds an inverse tableau, SIMD, and Pauli-frame sampling from one reference run, and organizes QEC circuits around detectors.
Further reading
S. Aaronson and D. Gottesman, “Improved simulation of stabilizer circuits,” Phys. Rev. A 70, 052328 (2004), arXiv:quant-ph/0406196, sections III-IV (algorithm and CHP).
C. Gidney, “Stim: a fast stabilizer circuit simulator,” Quantum 5, 497 (2021), arXiv:2103.02202.
D. Gottesman, “The Heisenberg representation of quantum computers,” arXiv:quant-ph/9807006.
P. Faist, Quantum Error Correction lecture notes (FU Berlin), section 5.3 (the three measurement cases, including the logical case for codes).
Stim documentation and getting-started notebook: github.com/quantumlib/Stim.