Modeling Errors as Gates
Because our simulator is deliberately noise-free, we model a discrete error by inserting an actual X (bit-flip) or Z (phase-flip) gate into the circuit at the exact moment the fault would strike. This turns noise into something you can place, trace by hand, and predict exactly — including the surprising rule that one error entering a CX gate exits as two.
How can a noise-free simulator teach us about noise?
Our simulator is deliberately exact: it tracks every amplitude to full floating-point precision and adds no noise at all — see noise-free simulation limits for why that is a design choice, not a shortcoming. So how do you study errors on a machine that never makes any?
You commit them yourself. A quantum error, at the moment it strikes, can be modeled as an unwanted gate that got inserted into your circuit. So we take a clean circuit and deliberately insert the fault: an X gate where a bit flip would strike, or a Z gate where a phase flip would. Quick definitions for readers landing here directly: a qubit holds a superposition — a weighted combination of 0 and 1, with weights called amplitudes whose squares give measurement probabilities. X swaps the 0-part and the 1-part, like a NOT. Z leaves both parts in place but negates the sign of the 1-part. See X, Y, Z gates.
This turns noise — normally random, continuous, and invisible — into something better than real: an error with an exact location, an exact type, and an exactly computable consequence. In this chapter you will place errors, trace them by hand, watch one wreck a circuit, watch the same error somewhere else do nothing at all, and derive the rule for how errors spread.
Why are X and Z the only errors we need?
A real physical fault could be anything — a tiny over-rotation, a partial decay, a stray coupling to a neighbor. Yet the entire theory of quantum error correction rests on just two discrete error types, and this is a proved mathematical fact, not an approximation being swept past: any error on a single qubit can be written as a weighted combination of four cases — nothing (identity), bit flip (X), phase flip (Z), and both at once (X and Z together, which is the Y error up to an overall phase factor that no measurement can detect).
The consequence: a code that corrects X errors and Z errors automatically corrects every single-qubit error, including all the continuous, partial ones. The two-line algebra behind this "error digitization" is worked out in Shor's nine-qubit code and beyond; the honest summary for now is that it is safe to study only inserted X and Z gates, because X and Z span the whole error alphabet.
This chapter drills X. Its stealthier sibling Z — the error that changes no measurement probabilities and hides from plain sight — gets its own chapter.
Worked example: how do you trace an X error by hand?
Let's trace an X error through the Bell-pair circuit from the last chapter, amplitude by amplitude. We write two-qubit states as |q1 q0⟩ — highest qubit index on the left, matching the bitstring display. The clean circuit is H on q0, then CX with control q0 and target q1 (CX flips the target exactly when the control is 1; see CNOT and controlled operations). We inject the error after the CX:
- Start: |00⟩ with amplitude 1.
- H on q0 splits it: amplitude 0.70711 on |00⟩ and 0.70711 on |01⟩ (0.70711 = 1/√2).
- CX: |00⟩ stays |00⟩; in |01⟩ the control q0 is 1, so q1 flips: |01⟩ → |11⟩. State: 0.70711·|00⟩ + 0.70711·|11⟩ — the Bell pair.
- Injected X on q0 flips the rightmost bit of every component: |00⟩ → |01⟩ and |11⟩ → |10⟩. State: 0.70711·|01⟩ + 0.70711·|10⟩.
Predicted probabilities: P(01) = 0.70711² = 0.500, P(10) = 0.500, and P(00) = P(11) = 0 exactly. Notice the error didn't add randomness — it moved the entire distribution somewhere else, deterministically. That is what modeling errors as gates buys you: predictions exact enough to check against a run.
Run the corrupted Bell pair
How does one error become two?
Errors don't stay put. Push an X through a CX and something important happens. Claim: an X on the control just before a CX is exactly equivalent to the CX followed by an X on both qubits. Derive it by checking all four basis inputs, writing (c, t) for the control and target values:
- (0,0): error first → control flips to 1 → CX fires → (1,1). CX first → (0,0) → X on both → (1,1). Match.
- (0,1): error first → (1,1) → CX fires, target flips → (1,0). CX first → (0,1) → X on both → (1,0). Match.
- (1,0): error first → (0,0) → CX doesn't fire → (0,0). CX first → target flips → (1,1) → X on both → (0,0). Match.
- (1,1): error first → (0,1) → CX doesn't fire → (0,1). CX first → (1,0) → X on both → (0,1). Match.
All four inputs agree, and since every state is a weighted combination of these four, the equivalence holds for superpositions too. One error walked into the gate; two walked out. Z errors obey the mirror rule — a Z on the target spreads to a Z on both qubits (the intuition: a CX carries bit information forward, from control to target, and phase information the opposite way, from target to control) — which we will use in the phase-flip code.
This is why error correction is hard mode: the very CX gates a code uses to check for errors can also spread errors. Circuits designed to survive their own machinery are called fault-tolerant — a theme that returns in the surface code.
What are the odds an error strikes at all?
Inserted errors are deterministic; real ones arrive with probabilities, and the bookkeeping is ordinary probability arithmetic. Suppose each gate in a 3-gate circuit independently suffers an X error with probability p = 0.01 — an illustrative figure; real rates are on the two-qubit fidelity page:
- P(a given gate is clean) = 1 − 0.01 = 0.99.
- P(all 3 clean) = 0.99 × 0.99 × 0.99: first 0.99 × 0.99 = 0.9801, then 0.9801 × 0.99 = 0.970299.
- P(at least one error) = 1 − 0.970299 = 0.029701 ≈ 3%.
At 100 gates the same arithmetic (worked in why qubits fail) leaves only a 36.6% chance of a clean run — a coin flip against you. And as the try-it experiment showed, the consequence of each possible error depends on where it lands: some locations invert your output, some are harmless, and — as the next chapters show — some corrupt the state in ways no immediate measurement can reveal. A full error analysis of even a small circuit means enumerating every location, every error type, and every propagation path. Doing exactly that, by hand, is how we will design the three-qubit bit-flip code.
How does this connect to errors on real devices?
Three honest connections between inserted error gates and physical reality:
- Real noise is continuous. A physical fault is rarely a crisp, full X — it is a small over-rotation here, a partial decay there, drifting crosstalk everywhere. The digitization result from earlier in this chapter is what licenses the discrete model anyway: correct X and Z and you have corrected the continuum. That result is proved theory, not marketing.
- Deliberate error injection is a real laboratory technique. Hardware teams validating an error-correction experiment insert known errors — exactly as you just did — to confirm the machinery detects and corrects them before trusting it against natural noise. This is demonstrated, routine practice at small scale.
- Twirling. A real technique that deliberately inserts randomizing Pauli gates — "Pauli" is the collective name for the X, Y, Z family — in canceling pairs so that messy, structured hardware noise averages into simple random X/Z errors — making real noise look more like this chapter's model, on purpose. Its costs and limits are covered honestly in mitigation vs correction.
Per-gate error rates for real devices, with sources and methodology labels, are on the two-qubit fidelity page; how vendors measure them is explained in fidelity, error and calibration.