Checkpoint: From Spec to Circuit
This checkpoint asks you to translate a written circuit specification into working code — exactly the skill you will use every time you implement a quantum algorithm from a textbook or paper description. Read the spec carefully, then build the circuit stage by stage.
The specification
The circuit operates on two qubits. Qubit 0 is the most significant bit, so the computational basis state is ordered with qubit 0 on the left.
Stage 1 — prepare: Apply the gate (bit-flip) to qubit 1. The two-qubit state starts as and becomes .
Stage 2 — superpose: Apply the Hadamard gate to qubit 0. Because , the joint state becomes
Stage 3 — entangle: Apply a CNOT gate with control = qubit 0 and target = qubit 1. The CNOT flips the target when the control is and leaves it unchanged when the control is . Acting on the superposition:
The term is unchanged (control is 0), and becomes (control is 1, so target flips from 1 to 0). The resulting state is one of the four Bell states:
How to approach a spec
When translating any specification into a circuit, a reliable strategy is:
- Identify the stages. The spec breaks the work into named sections — read each one before writing any code.
- Trace the state. Write out the state vector after each stage (as done above) to verify your mental model before you code.
- Write gate calls in order. Each stage maps directly to one or more gate calls appended to the circuit object. The order of your calls must match the order in the spec.
- Check the output. After running, compare the simulator's state vector to the state you derived by hand.
This disciplined read-trace-code cycle scales to algorithms of any complexity — the same method works whether the spec has three stages or thirty.
Try it
Implement the three-stage circuit described in the spec. The grader compares the full state vector of your circuit with the reference output , so the order of your gate calls matters.
After running, inspect the State Vector tab: the two non-zero amplitudes should each read , corresponding to and .
Sign in on the full site to ask questions and join the discussion.