QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
HomeLearnCatalogRanksPlaygroundDocs
02 · Classical ML vs. Quantum ML: The Hybrid Loop0%

You are reading without signing in. Sign in or continue as guest to take quizzes and climb the ranks.

Learn/QC 302Cutting and Quantum ML·Lesson 2 of 7

Classical ML vs. Quantum ML: The Hybrid Loop

How a neural network and a variational quantum model learn, side by side, and an honest look at when QML helps.

Advanced12 min read6 sections · 2 questions+45
By the end you will be able to
  1. 01Describe the hybrid loop: encoding, parameterised circuit U(θ), measurement, classical optimiser.
  2. 02Map each part of a neural network to its counterpart in a quantum model.
  3. 03Say where QML is a reasonable research bet and where classical ML is the better tool today.

A neural network learns by adjusting numbers. The input x is multiplied by a weight matrix W, passed through a non-linear activation, compared with the right answer by a loss function, and the weights are nudged downhill along the gradient. A quantum model keeps exactly this loop and replaces the model in the middle with a circuit.

StepClassical neural networkHybrid quantum model
Inputa vector x of numbersx written into rotation angles (encoding, feature map)
Modellayers: W·x, then an activationparameterised circuit U(θ), the ansatz
Outputnumbers from the last layerexpectation values such as ⟨Z⟩, estimated from shots
Losscomputed on the CPU or GPUcomputed on the CPU from the measured values
Updatebackpropagation through all layersgradients from extra circuit runs, or a gradient-free optimiser such as COBYLA
HardwareCPU or GPUQPU for the circuit, CPU for everything else
∂θ∂⟨Z⟩​=21​(⟨Z⟩θ+π/2​−⟨Z⟩θ−π/2​)
The parameter-shift rule for rx, ry and rz: run the circuit twice with θ shifted by ±π/2 and subtract. Two extra runs per parameter, each with its own shot noise, is why training on hardware is slow.

01One turn of the hybrid loop

  • 1. The CPU chooses the parameters θ.
  • 2. The QPU runs encoding + U(θ) for many shots.
  • 3. The CPU turns the counts into expectation values and a loss.
  • 4. The optimiser updates θ and the loop starts again until the loss stops falling.
Hands-on

Be the optimiser

The first ry is the data point x = 0.8, the second is the trainable weight θ = 1.2. Simulate and compute ⟨Z⟩ = P(0) − P(1) from the histogram (about −0.42). Here ⟨Z⟩ = cos(0.8 + θ): change θ to −0.8 and every shot reads 0; change it to 2.34 and almost every shot reads 1. Each edit is one turn of the loop done by hand.

OpenQASM 3
OPENQASM 3.0;
include "stdgates.inc";
qubit[1] q;
bit[1] c;
ry(0.8) q[0];
ry(1.2) q[0];
c[0] = measure q[0];
Sign in to run (nothing is saved)
Open in the IDE Open in the Playground

02When does QML help? An honest answer

  • Images, text, tables of business data and large language models: classical ML is the right tool. Today's chips have few qubits, slow data loading and shot noise, and no advantage has been shown on such data.
  • Loading many classical numbers into a circuit is itself expensive, and that cost can cancel a speed-up that looks good on paper.
  • Promising directions: data that is already quantum (states from a quantum sensor or simulation, molecules and materials) and quantum kernels, which compare data points in a very large feature space. Whether they beat classical methods on practical problems is still an open research question.
  • Training has its own limits: in deep, randomly initialised circuits the gradients can vanish exponentially with the number of qubits (barren plateaus).
Note

Treat QML as a research tool to learn and experiment with, not as a faster replacement for classical machine learning.

Knowledge check

2 questions · one try each counts

Question 1

In the hybrid loop, which part runs on the quantum processor?

Sign in to answer and climb the ranks; you will come back to this lesson.

Question 2

Which statement about QML today is the most honest?

Sign in to answer and climb the ranks; you will come back to this lesson.

Key takeaway

QML keeps the machine-learning loop and swaps the model for a parameterised circuit; the CPU still computes the loss and updates the parameters. It is a research tool, most promising for quantum data, not a faster replacement for classical ML.

Finished reading?

Knowledge check: 2 questions waiting above. Questions are optional. Mark it complete, or press Next: moving on marks it complete too.

Up next
Lesson 3 · 12 min
Variational circuits
Parameterised gates, a cost function and a classical optimiser: the loop behind VQE and QAOA.
Further reading
  • Docs: QML chapter
More in Cutting and Quantum ML
  • Circuit cutting
  • Data encoding
  • Hands-On 2-Qubit Variational Classifier
Circuit cuttingVariational circuits
In this lesson0%
  1. Introduction
  2. One turn of the hybrid loop
  3. Try it: Be the optimiser
  4. When does QML help? An honest answer
  5. Knowledge check
  6. Key takeaway
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in