Preface¶
Who this book is for¶
This book is a course in quantum machine learning for readers who already know a little of both parent subjects: some linear algebra with complex numbers, the idea of a qubit and a quantum gate, and the basic vocabulary of supervised learning (training data, labels, a loss function). It is written for postgraduate and senior undergraduate students of computer science, physics and data science, and for practitioners who want to understand what a quantum classifier actually computes before they trust a claim about it.
Where the short field guide in this library (Quantum Machine Learning: the complete student field guide) surveys the whole territory in plain language, this book goes slowly and does the algebra. Every central formula is derived, every worked problem is carried through to a number, and every chapter ends with exercises whose answers are folded away beneath them. Where the broader course Quantum Computing and its Applications teaches the machinery of quantum algorithms, this book uses only the small part of it that learning needs, and spends the saved effort on the questions that matter for a learner: how data gets into a quantum state, what a quantum kernel is, how a trained circuit is differentiated, and why so many of these models are hard to train or hard to distinguish from classical ones.
The book follows one line of argument. A quantum model is a linear functional in an exponentially large Hilbert space. The way data is encoded fixes which functions that functional can reach, so the encoding is part of the model and not a preprocessing step. A quantum kernel turns the encoding into a similarity measure that a classical support vector machine can use, keeping the optimisation convex. A variational classifier trains a parameterised circuit instead, and its gradients are exact through the parameter-shift rule, at two circuit evaluations per parameter. Expressivity is not free: models that are too expressive concentrate their kernels and flatten their gradients. And claims of advantage must be tested against honest classical baselines. The last chapter returns to these six statements.
How the book is organised¶
The thirteen chapters fall into five parts.
| Part | Chapters | What it does |
|---|---|---|
| I. Foundations | 1 to 3 | The hybrid learning loop; Hilbert space, the Born rule, density matrices and measurement; gates, circuits and circuits as functions |
| II. Data and features | 4 and 5 | Classical learning theory in the language the quantum chapters reuse: risk, feature maps, kernels, support vector machines; then the five ways of encoding data into a quantum state |
| III. Quantum kernels | 6 to 8 | The fidelity kernel and its properties; estimating it with the inversion test and the SWAP test; the quantum-kernel SVM, its costs, and when it can help |
| IV. Variational classifiers | 9 to 11 | Architecture, ansatz, readout and loss; gradients by parameter shift and the hybrid training loop; a complete case study, learning XOR with an entangling circuit |
| V. Limits and landscape | 12 and 13 | Barren plateaus, noise, generalisation and dequantisation; the other classifier families and the practical criterion for using a quantum classifier at all |
Back matter holds a glossary and a note on further reading.
The course this book accompanies is organised in seven sections: foundations (the Hilbert-space picture); learning from data; encoding data into quantum states; quantum feature maps and kernels; variational quantum classifiers; trainability, noise and generalisation; and the quantum classifier zoo. Chapters 1 to 3 cover the first section, with extra material on gates; Chapter 4 covers the second; Chapter 5 the third; Chapters 6 to 8 the fourth; Chapters 9 to 11 the fifth; Chapter 12 the sixth; and Chapter 13 the seventh. Eight problems of the lecture course, and five longer solved problems that were worked step by step on small datasets, appear throughout as worked examples. Their original questions are kept, and their numerical answers are reproduced exactly.
How to use it¶
Read with pencil and paper. A derivation that you have followed with your eyes is not yet one you can reproduce. The worked examples are laid out so that you can cover the solution, attempt each step, and compare.
Three kinds of box recur.
Example 0.1: a worked example
Worked examples show every step. They are numbered by chapter, so Example 6.2 is the second of Chapter 6. Where the source problem posed several parts, they are labelled (a), (b), (c).
Definition boxes and key ideas
Definitions and the statements you should be able to recite are set in this style.
Cautions
A caution marks a place where the obvious reading is wrong, or where a popular claim needs qualifying.
Each chapter closes with a Summary of key points and a set of Exercises. Click an answer heading to unfold it. Try the exercise first.
Notation and conventions¶
| Symbol | Meaning |
|---|---|
| \(x \in \mathbb{R}^d\) | a classical data point; \(y\) is its label, \(y\in\{+1,-1\}\) unless stated |
| \(\lvert\psi\rangle,\ \langle\psi\rvert\) | a ket (column vector) and its bra (conjugate transpose) |
| \(\rho\) | a density operator; \(\rho(x)=\lvert\varphi(x)\rangle\langle\varphi(x)\rvert\) for an encoded data point |
| \(U_\varphi(x)\) | the data-encoding circuit; \(\lvert\varphi(x)\rangle=U_\varphi(x)\lvert 0\rangle^{\otimes n}\) |
| \(U(\theta)\) | the trainable circuit (the ansatz) with parameters \(\theta\in\mathbb{R}^p\) |
| \(R_Y(\theta)\) | rotation about the \(y\) axis, \(\cos(\theta/2)I-i\sin(\theta/2)Y\) |
| \(\langle O\rangle\) | an expectation value; \(Z\) is the Pauli-\(Z\) observable with eigenvalues \(\pm1\) |
| \(k(x,x')\) | the quantum (fidelity) kernel \(\lvert\langle\varphi(x)\vert\varphi(x')\rangle\rvert^2\) |
| \(K\) | a Gram matrix, \(K_{ij}=k(x_i,x_j)\) |
| \(M\) | the number of shots (repetitions of a circuit); \(N\) the number of training points; \(p\) the number of parameters; \(n\) the number of qubits |
Qubits are written in the order they are read, left to right, in a bit string: in \(\lvert 10\rangle\) the first qubit is \(1\) and the second is \(0\). Matrices for several qubits are built with the Kronecker product in the same order, which is also the convention of the code in this book. Some software libraries number qubits from the right, so a bit string printed by such a library must be read backwards before it is compared with the text.
Angles are in radians throughout.
Code in this book¶
Every numerical result in the worked examples was reproduced by short programs in plain Python with NumPy. The programs simulate the circuits exactly by linear algebra on state vectors; there is no need for a quantum computer or a special toolkit. One example (Section 8.4) also uses the scikit-learn support vector machine, whose only role is to solve the classical optimisation. Chapter 3 builds a dozen lines of helper functions on which the other chapters rely. Where a number in the text came from a finite-shot experiment, the program shows how to compute the exact value and how to draw a sample of shots, but a sample will of course differ from the quoted one in its last digits.
Code is secondary to understanding. If you read only the mathematics, you will lose nothing the exercises need.