Checkpoint: A Tiny Quantum Classifier
This checkpoint pulls together every idea from Module 12: angle encoding, entangling ansatz layers, trained weights, and measurement. You will assemble a tiny but complete quantum classifier and verify that it correctly predicts class 1 for a given input.
The classification task
We have a one-dimensional dataset with two classes:
- Class 0 — points near (small angle, qubit naturally close to ).
- Class 1 — points near (large angle, qubit naturally close to ).
The classifier is a two-qubit circuit where is the data feature and are the trained weights. Measurement of the full two-qubit register at the end produces a probability distribution; a class-1 prediction corresponds to a high probability of measuring on qubit 1 (the label qubit).
Circuit structure
The circuit has three layers:
Layer 1 — data encoding. Apply to qubit 0. Starting from , the state after encoding is
For the amplitude on for qubit 0 is , so the data qubit already leans strongly toward .
Layer 2 — entanglement. A CNOT with control on qubit 0 and target on qubit 1 creates correlations between the data qubit and the label qubit:
Layer 3 — trainable weights. Independent rotations on both qubits let the optimizer tune which region of the entangled state maps to class 0 or class 1.
Deriving the trained weights
A classical optimizer minimizes a cost function by evaluating the circuit on training data. For this toy task, gradient descent (using the parameter-shift rule) converges to the weights and .
We can verify analytically that these weights work for . After the encoding and CNOT the state is
Applying to qubit 0 and to qubit 1 rotates the amplitudes within each two-qubit basis state. The marginal probability of measuring qubit 1 in works out to approximately , well above the 50% decision threshold. For the class-0 input the same weights produce a probability of roughly on for qubit 1 — correctly predicted as class 0.
Try it
Build the complete classifier circuit for the class-1 input , using the trained weights and . Then measure. The grader checks that the output distribution matches the reference.
After a correct run, the outcome should dominate the histogram — qubit 1 in signals the class-1 prediction. Compare what happens when you change to (a class-0 input): the distribution shifts dramatically toward .
Sign in on the full site to ask questions and join the discussion.