PricingOpen Lab
Chapter 03 of 13 · ~10 min · FREE

Single-Qubit Circuit Patterns

Five small patterns — prepare, rotate, shift phase, undo, and change basis before measuring — cover most single-qubit work. Because gate order is not interchangeable, it pays to learn them as patterns rather than as isolated gate facts.

Why learn patterns instead of gates?

Individual gates are easy to memorise and easy to misuse. Short, named patterns are easier to debug because each has a purpose and a checkable outcome. The five worth knowing:

  • Prepare: set a known starting state explicitly, so your assumptions are visible in the circuit.
  • Rotate: move some amplitude — the number whose square gives an outcome's probability — between 0 and 1 by a chosen amount.
  • Phase: change the sign (or angle) of an amplitude without changing any probability on its own. Invisible alone; decisive later.
  • Undo: apply a gate's inverse so the state returns exactly to its input — a built-in self-test.
  • Basis change before measurement: rotate the question you want to ask into the standard readout.

Worked example: the undo pattern (H then H)

The Hadamard gate H follows this rule: new amplitude of 0 = (amp of 0 + amp of 1) ÷ 1.4142, and new amplitude of 1 = (amp of 0 − amp of 1) ÷ 1.4142.

  • Start: amplitudes (1, 0) — definitely 0.
  • First H: ((1+0)÷1.4142, (1−0)÷1.4142) = (0.7071, 0.7071).
  • Second H: ((0.7071+0.7071)÷1.4142, (0.7071−0.7071)÷1.4142) = (1, 0).

H is its own inverse, so the pair restores the input exactly. Prediction: 1000 shots, 1000 reads of 0. Any other result means the circuit you ran is not the circuit you think you ran — which is precisely why undo pairs make good self-tests.

Run the undo pair

A single bar at 0 — the second H exactly undoes the first.standby
123q0|0⟩HH
press run to acquire
|0|1
counts: sampledamplitudes: statevector, exactengine: in-browser
Open in the Lab →

Worked example: the hidden sign (H, Z, H)

The Z gate flips the sign of the amplitude on 1 and leaves the amplitude on 0 alone. Insert it between the two Hadamards:

  • After the first H: (0.7071, 0.7071).
  • After Z: (0.7071, −0.7071). Note the probabilities are unchanged — squaring kills the sign: (−0.7071)² = 0.5. Measured right now, this state is indistinguishable from the previous one.
  • After the second H: amp of 0 = (0.7071 + (−0.7071)) ÷ 1.4142 = 0; amp of 1 = (0.7071 − (−0.7071)) ÷ 1.4142 = 1.4142 ÷ 1.4142 = 1.

Every shot now reads 1. The invisible sign became visible through interference — the adding and cancelling of amplitudes when a later gate recombines them. This is the single most important mechanism in quantum computing, and it is just arithmetic.

Compare: one sign flip in the middle

123q0|0⟩HZH

Compare with the H-H run: the hidden sign flip turns 'always 0' into 'always 1'.

The rotate pattern: RY(θ)

RY(θ) is a dial rather than a switch: it rotates amplitude from 0 towards 1 by an angle θ, given in radians — the angle unit in which π ≈ 3.1416 is half a turn. Starting from 0, it produces amplitude cos(θ/2) on 0 and sin(θ/2) on 1.

Take θ = π/3 ≈ 1.0472. Then θ/2 ≈ 0.5236 (30 degrees), so the amplitudes are cos = 0.8660 and sin = 0.5. Squaring: 0.8660² = 0.75 and 0.5² = 0.25. Prediction for 1000 shots: about 750 read 0 and 250 read 1.

The dial's inverse is the same dial turned backwards: RY(θ) followed by RY(−θ) restores the input, just as H-H did. Parameterised dials get a full treatment in Parameterized Gates.

Measure in the right basis

The last pattern places a basis-change gate immediately before measurement. Standard readout always asks "0 or 1?"; an H placed just before it rotates a different question — "plus or minus?", the X-basis question, distinguishing the two 50/50 states |+⟩ and |−⟩ met in the developers course — into that standard readout. The gate's position matters: it defines what is being asked, so it belongs directly before the measurement, not somewhere earlier.

Takeaway: prepare explicitly, rotate by dials, remember that phase is invisible until interference reveals it, use undo pairs as self-tests, and choose the measurement question deliberately. The next lesson extends these patterns to multiple qubits; measurement choices get their own lesson in Measurement Strategies.

Single-Qubit Circuit Patterns · QPU137