Checkpoint: Register Manipulation
Module 1 built up a toolkit for multi-qubit registers: allocating -qubit state vectors, applying single-qubit gates to individual qubits inside a register, encoding integers, building uniform superpositions with Hadamards, and controlling gates on multiple qubits. This checkpoint combines those ideas in a single state-preparation problem.
The target state
Your goal is to prepare
Qubit 0 is the most significant bit, so means , , , and means , , . Each of the two terms has amplitude , so the Born-rule probability of each outcome is .
Strategy: branch on the most significant qubit
A useful design pattern for state preparation is to create a superposition on one qubit and then fill in the remaining qubits conditioned on which branch you are in.
Step 1 — Hadamard on . Apply to qubit 0. The register becomes
The two branches are now (top) and (bottom).
Step 2 — Handle the branch. In this branch, must become . We need a CNOT that fires when rather than when . To invert the polarity of a control qubit, sandwich the controlled gate between two gates on the control:
The first temporarily flips , so the fires on the originally-zero branch. The second restores . After this three-gate block the state is
Step 3 — Handle the branch. In this branch, must become . A standard fires exactly when , turning into :
The total circuit depth is five gates: . Each step uses gates from the standard universal set, and the control-on-zero trick is exactly the technique introduced in the multi-controlled gates lesson.
Try it
Build the circuit that prepares . The grader checks the complete state vector against the reference solution, so every amplitude — including its sign and phase — must be correct. Leaving the circuit empty will fail.
After a successful run you should see two amplitudes of at positions and , with all other amplitudes equal to zero.
Sign in on the full site to ask questions and join the discussion.