The Promise and the Reality
Quantum machine learning sits where two heavily marketed technologies meet, which makes the claims around it worth checking carefully. In theory, quantum computers could speed up learning tasks by large factors. Evidence available today points somewhere more specific and more limited.
Current devices, usually called Noisy Intermediate-Scale Quantum (NISQ) machines, have tens to hundreds of qubits with limited coherence and non-trivial error rates. Those constraints rule out the algorithms with headline speedups, such as quantum support vector machines, which assume fault-tolerant hardware with thousands of logical qubits.
What NISQ devices can do is act as specialised co-processors inside hybrid quantum-classical algorithms. That is where the practical work sits today, and where the interesting research is happening.
Variational Quantum Circuits
The workhorse of near-term quantum machine learning is the variational quantum circuit: a parameterised circuit used as a function approximator, with its parameters tuned by a classical optimiser. Note the direction of that relationship, since it is often stated backwards. Variational circuits are the general family, and the variational quantum eigensolver is one member of it, applied to finding ground-state energies.
Here is a four-qubit classifier. It encodes each feature as a rotation angle, applies trainable layers with entangling gates between them, and measures one expectation value.
import pennylane as qml
from pennylane import numpy as pnp
N_QUBITS, N_LAYERS = 4, 2
dev = qml.device("default.qubit", wires=N_QUBITS)
@qml.qnode(dev)
def circuit(inputs, weights):
inputs = pnp.atleast_2d(inputs) # accept one sample or a batch
# Encode classical data as rotation angles
for i in range(N_QUBITS):
qml.RY(inputs[:, i], wires=i)
# Trainable layers
for layer in range(N_LAYERS):
for i in range(N_QUBITS):
qml.RY(weights[layer][i][0], wires=i)
qml.RZ(weights[layer][i][1], wires=i)
for i in range(N_QUBITS - 1):
qml.CNOT(wires=[i, i + 1])
return qml.expval(qml.PauliZ(0))The weights train by gradient descent, exactly as a neural network would. Two details are worth noting, because both are easy to get wrong.
Batching matters. Passing the whole training set through at once, rather than looping sample by sample, took this example from 59 seconds to 3.5 seconds on a laptop.
Every parameter needs to affect the output. A rotation placed where it cannot change the measured expectation value will sit in your model looking trainable and do nothing. The accompanying test suite checks that each layer receives a nonzero gradient, which is a cheap guard against a silent bug that otherwise shows up as a model that trains poorly for no visible reason.
Does It Work? Train It and See
Claims about quantum machine learning are easy to make and easy to check on small problems. So here is the same circuit, trained on a toy binary classification task with four features, next to a logistic regression fitted on the same data.
Training a 4-qubit, 2-layer variational classifier on 84 samples
step 0 loss 2.2016
step 30 loss 0.6532
step 60 loss 0.5718
step 119 loss 0.5712
quantum model, train accuracy : 0.762
quantum model, test accuracy : 0.750
logistic regression, test acc : 1.000The quantum model learns. It goes from random to 75%, and the loss falls steadily. Against one of the simplest classical models available, on a task that happens to be linearly separable in the raw features, it loses decisively.
That result is not a failure of the code. It is the expected outcome, and publishing it is more useful than publishing a tuned example that flatters the quantum side.
When Does QML Actually Help?
Two findings should shape your expectations more than any demo.
The first is systematic benchmarking. Bowles, Ahmed and Schuld tested 12 popular quantum machine learning models across 6 binary classification tasks and 160 datasets. Out-of-the-box classical models systematically outperformed the quantum classifiers. More pointedly, removing entanglement from a quantum model often left performance equal or better, which suggests that quantumness was not doing the work in these tasks.
The second is dequantization. Several of the theoretical speedups that made quantum machine learning exciting assumed data already loaded into a quantum-accessible structure. Ewin Tang's classical algorithm for recommendation systems showed that this assumption gives classical algorithms the same leverage, and later work extended the result across principal component analysis, supervised clustering, support vector machines, low-rank regression and semidefinite programming. Under the same input model, those exponential speedups disappear.
Barren plateaus add a third constraint. Gradients vanish exponentially as circuit size grows, which makes large variational models hard to train rather than merely slow.
Where the argument stays strong is on data with quantum structure. Classifying phases of quantum matter, learning properties of quantum systems, and modelling molecular configurations are natural fits, because the quantum computer speaks the same language as the problem and no data-loading bottleneck stands in the way.
For images, text and tabular data, the honest summary is that the evidence is thin and the burden of proof sits with the quantum model.
A Pragmatic Path Forward
The tooling has matured. PennyLane, Qiskit Machine Learning and TensorFlow Quantum give high-level interfaces, and you can build and train a variational model in an afternoon without a physics doctorate.
If you want to spend that afternoon well, do three things. Run a classical baseline first and hold the quantum model to it. Check that every trainable parameter influences the output. Pick a problem whose data is already quantum, since that is where the argument does not depend on hardware that doesn't exist yet.
None of this makes quantum machine learning a dead end. It makes it a research field with a narrow current application and a wide potential one, which is a reasonable thing to work on as long as nobody sells it as the other thing.
Run the Code
The classifier, the classical baseline and the test suite are in the Towards Quantum studies repository, pinned to the versions they were tested against.
git clone https://github.com/TowardsQuantum/studies
cd studies/quantum-machine-learning
pip install -r requirements.txt
python qml_classifier.py
pytest test_qml_classifier.py -vgithub.com/TowardsQuantum/studies. Issues and corrections are welcome.