Chapter 1: What Quantum Machine Learning Is¶
Quantum machine learning (QML) asks what happens when the ordinary business of learning a rule from examples is rebuilt inside quantum mechanics. This chapter fixes the picture that the rest of the book fills in. It says what is being learned and from what, which part of the work a quantum circuit does and which part stays on an ordinary computer, what the three main designs of a quantum learner are, and, honestly, what is and is not known to work. It is short on algebra on purpose; the formalism begins in Chapter 2.
1.1 Learning a rule from examples¶
A supervised learning problem hands you a table. Each row is an input \(x\), a list of numbers such as sensor readings or flower measurements, together with the answer \(y\) that belongs to it: a class label such as \(+1\) or \(-1\), or a number to be predicted. Your job is to find a function \(f\) that reproduces the answers on the rows you have and, more importantly, gives the right answer on rows you have not seen. A loss function scores each prediction, the training procedure drives the total loss down, and a separate set of held-back examples tells you whether the rule has generalised.
Nothing in this description is quantum. In this book the data is ordinary classical data, numbers in a table. The quantum part is the model: a function \(f\) whose value is computed by running a quantum circuit. That is a deliberate narrowing. There is a large and separate subject in which the data itself is quantum, the output of a quantum experiment or simulation, and we touch it only in Chapter 13. For classical data the first question is the one that organises the whole book: how does a table of numbers become something a quantum circuit can act on?
1.2 Where the quantum computer enters: the hybrid loop¶
A quantum circuit acts on a quantum state, not on an array of numbers. So a quantum model has the following shape. The input \(x\) is encoded into a state of \(n\) qubits by a data-dependent circuit \(U(x)\). A second circuit \(W(\theta)\), whose gates carry adjustable angles \(\theta\), transforms the state. Finally an observable is measured, and its average value is the model's output \(f(x;\theta)\). A classical computer compares this output with the label \(y\), computes the loss, and chooses a better \(\theta\).
data x -> [ encode U(x) ] -> [ trainable W(theta) ] -> [ measure ] -> f(x; theta)
^ |
| v
new theta <----- optimiser <----- compare with y (loss)
QUANTUM computer: prepares the state, applies the circuit, measures.
CLASSICAL computer: scales the data, computes the loss, chooses the next theta.
This is a hybrid loop. The quantum part is small and is repeated very many times. The learning itself, deciding which \(\theta\) to try next, is classical optimisation. When you read about "training a quantum model" you should picture exactly this: a loop in which a quantum device is repeatedly asked to evaluate a function, and an ordinary computer decides what to ask next.
An intuition: the qubit as a needle
It helps to picture one qubit as a needle inside a globe. At the start the needle points straight up; this is the state \(\lvert 0\rangle\). A data value tells the circuit how far to turn the needle. A small value leaves the needle near the top, a large value turns it nearly to the bottom, which is \(\lvert 1\rangle\). Measuring is like tossing a biased coin: when the needle is near the top you will see mostly \(0\), near the bottom mostly \(1\). You never read the needle's angle directly. You infer it from many tosses. Each toss is called a shot. Chapter 2 turns this picture into precise mathematics.
1.3 Three ways to use a quantum circuit in learning¶
The hybrid loop above is only one design. The book studies three.
Quantum kernel methods (Chapters 6 to 8). The circuit is used only to measure how similar two data points are, after both have been encoded as quantum states. The table of similarities, the kernel matrix, is then handed to a classical algorithm such as a support vector machine. Quantum computes the similarities; classical learns from them. The optimisation stays convex, with a single global optimum.
Variational quantum classifiers (Chapters 9 to 11). The circuit itself is the trained model, with trainable angles tuned by gradient descent. The optimisation is not convex, and its difficulties are the subject of Chapter 12.
Distance-based and structured circuits (Chapter 13). A few designs involve no training at all, or build the structure of the problem into the circuit, as quantum convolutional networks do.
All three share the first step. Whichever you choose, the data must be encoded into a quantum state, and that choice is part of the model. Chapter 5 is therefore the hinge of the book.
1.4 What QML can and cannot do yet¶
Because the field is young and attracts a good deal of enthusiasm, it is worth stating plainly what the evidence supports. The following six points will recur in every later chapter.
- There is no proven general speed-up for learning from classical data. The known advantages are for specially constructed problems. A single provable separation, built on the discrete logarithm and requiring fault-tolerant hardware, is discussed in Chapter 8.
- Loading data costs time. Amplitude encoding is compact, but preparing the state can cost as many gates as there are data values, and that can cancel any gain.
- Barren plateaus. In large, random-looking circuits the gradient shrinks exponentially with the number of qubits, and training stalls.
- Shot noise. Every output is an estimate from a finite number of shots. Estimating a value to accuracy \(\varepsilon\) costs about \(1/\varepsilon^2\) shots.
- Hardware noise. Today's devices add errors that grow with circuit depth.
- Elaborate is not better. A fancier feature map can do worse than a simple one. In Chapter 8 a sophisticated encoding scores below a coin flip on a real dataset on which the plainest encoding scores 100%.
The working rule
Always compare with a classical baseline. A quantum model is interesting when it is competitive with a well-tuned classical one, not merely when it runs. A quantum model that beats a weak classical baseline is no evidence of anything.
1.5 A map of the road ahead¶
To compute anything about a quantum model we need the language of quantum states: Hilbert space, the Born rule, density matrices, observables, unitaries. That is Chapters 2 and 3. To say what it means for a model to learn, and to understand kernels, we need a few pages of classical learning theory, which is Chapter 4. Then data must be encoded (Chapter 5). After that the road forks into kernels (Chapters 6 to 8) and variational circuits (Chapters 9 to 11) and rejoins in Chapters 12 and 13, which ask when and why any of it works.
1.6 Summary¶
Chapter Summary
- In this book the data is classical; the quantum circuit is the model.
- A quantum model has three stages: encode the data into a state, transform it with a trainable circuit, measure an observable. The average of the measurement is the output.
- Training is a hybrid loop: the quantum device evaluates the model, a classical computer computes the loss and updates the parameters.
- Three designs are studied: quantum kernels with a classical learner, variational classifiers, and distance-based or structured circuits.
- Every output is estimated from a finite number of shots, and precision is paid for in repetitions.
- There is no proven general advantage for classical data. Compare with a tuned classical baseline every time.
1.7 Exercises¶
Exercise 1.1
In your own words, state what is quantum and what is classical in the hybrid training loop.
Answer
The quantum computer prepares the encoded state, applies the trainable circuit and measures; it evaluates the model (and, as Chapter 10 shows, its gradients). The classical computer scales the data, computes the loss from the measured values, and decides the next parameters. The learning itself is classical optimisation.
Exercise 1.2
A model's output is estimated from \(M=100\) shots. How many shots are needed to gain one more decimal digit of accuracy?
Answer
The standard error falls as \(1/\sqrt{M}\). One more decimal digit means ten times smaller error, so \(10^2=100\) times more shots: \(M=10\,000\).
Exercise 1.3
Why does Chapter 5 matter to both kernel methods and variational classifiers?
Answer
Both begin by encoding the classical input into a quantum state. The encoding is the feature map: it fixes the kernel used by a kernel method and the family of functions a variational classifier can represent. It is therefore a modelling choice, not a preprocessing step.
Exercise 1.4
A paper reports that a quantum classifier beats a classical logistic regression on a small dataset. Using Section 1.4, list two further things you would want to know before accepting that the quantum model is better.
Answer
Whether the classical baseline was tuned fairly (for example an RBF-kernel support vector machine or a small neural network with the same hyperparameter budget, on identical splits), and what the quantum model's cost was in shots. A comparison with a weak baseline is no evidence. Other acceptable answers: whether the hardware or simulator noise was included, and whether the result held on more than one split.
Exercise 1.5
Give one example of "classical data" and one of "quantum data".
Answer
Classical data: a table of sepal lengths and widths of flowers, or sensor readings. Quantum data: the quantum state produced by a physical experiment or simulation, for example the ground state of a many-body system whose phase is to be recognised. For quantum data no short classical description of the input exists to begin with.