|q⟩ Bad Qubits

advanced · Programming · Quantum Machine Learning (Advanced)

Checkpoint: Train a QML Model

This checkpoint assembles the whole module into one runnable model: a two-qubit variational classifier with data encoding, a trainable entangling ansatz, and a measured readout. You build the forward pass of the model with its trained parameters and read out the measurement statistics that the classifier uses to decide a label.

The model you are building

For a two-feature point x=(x0,x1)\boldsymbol{x} = (x_0, x_1), the circuit is

ψ(x,θ)=W(θ)UΦ(x)00,|\psi(\boldsymbol{x},\boldsymbol{\theta})\rangle = W(\boldsymbol{\theta})\,U_\Phi(\boldsymbol{x})\,|00\rangle,

with the pieces drawn from earlier lessons:

  1. Encoding UΦ(x)=RY(2x0)RY(2x1)U_\Phi(\boldsymbol{x}) = R_Y(2x_0)\otimes R_Y(2x_1) — angle encoding, one feature per qubit.
  2. Trainable ansatz W(θ)W(\boldsymbol{\theta}): a layer of single-qubit RY(θi)R_Y(\theta_i) rotations followed by a CNOT\text{CNOT} entangler. Entanglement lets the two features interact, which a product feature map cannot do on its own.
  3. Readout: measure both qubits. The output bit distribution is what a downstream rule turns into a class label and a confidence.

Concrete instance

Use the data point and trained parameters

x0=0.5,x1=0.9,θ0=0.4,θ1=1.2,x_0 = 0.5,\quad x_1 = 0.9,\qquad \theta_0 = 0.4,\quad \theta_1 = 1.2,

and apply the gates in this order:

  1. encode: RY(2x0)R_Y(2x_0) on qubit 0, RY(2x1)R_Y(2x_1) on qubit 1;
  2. ansatz rotations: RY(θ0)R_Y(\theta_0) on qubit 0, RY(θ1)R_Y(\theta_1) on qubit 1;
  3. entangler: CNOT\text{CNOT} with control qubit 0, target qubit 1;
  4. measure both qubits.

What the grader checks

The grader compares the full measurement distribution over the four outcomes 00,01,10,1100, 01, 10, 11 to the distribution produced by the correct circuit. The probabilities follow from the Born rule applied to the prepared state, so getting the gate order, angles, and entangler right is the whole task. An identity or missing-CNOT circuit will produce a different distribution and fail.

Try it

Build the two-qubit variational classifier described above for x=(0.5,0.9)\boldsymbol{x} = (0.5, 0.9) and trained angles (θ0,θ1)=(0.4,1.2)(\theta_0, \theta_1) = (0.4, 1.2), then measure both qubits.

Run your code to see the quantum state.

Sign in on the full site to ask questions and join the discussion.