← Quantum Store · Guides · Lessons · Glossary · Packages · About · Türkçe
Quantum machine learning and hardware course · Lesson 3 / 5 · 10 min
Quantum kernels: comparing data with quantum states
Measuring how similar two data points are by the overlap of quantum states. Meet the quantum kernel method, the claims of advantage and the “dequantization” results.
Overlap as a similarity measure
Classical methods such as the support vector machine (SVM) rely on a kernel function that measures the similarity between data points. In the quantum kernel method each point x is turned into a quantum state by a feature map circuit, and similarity is measured by |⟨φ(x)|φ(y)⟩|²: 1 for identical points and close to 0 for very different ones.
This overlap is easy to measure on a quantum computer: apply the circuit for x, then the inverse of the circuit for y, and look at the probability of everything giving 0. Once the kernel matrix is computed, the rest is an entirely classical SVM.
import numpy as np
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
def feature_map(x):
qc = QuantumCircuit(2)
qc.h([0, 1])
qc.rz(x[0], 0)
qc.rz(x[1], 1)
qc.cx(0, 1)
qc.rz(x[0] * x[1], 1) # a term that links the two features
qc.cx(0, 1)
return Statevector(qc)
def kernel(a, b):
return abs(feature_map(a).inner(feature_map(b))) ** 2
points = [[0.1, 0.2], [0.15, 0.25], [2.0, 1.5]]
print(np.array([[kernel(a, b) for b in points] for a in points]).round(3))
# [[1. 0.999 0.242]
# [0.999 1. 0.219]
# [0.242 0.219 1. ]] nearby points 0.999, the distant point about 0.2
Where is the advantage?
In 2019 Havlíček and colleagues at IBM demonstrated this method on a real device. The idea is that a kernel classical computers cannot compute might classify certain kinds of data better. In 2021 Liu, Arunachalam and Temme showed that on a specially constructed problem quantum kernels give a provable advantage.
But these problems are artificial. On real data quantum kernels usually perform about as well as well-tuned classical methods. Also, as the number of qubits grows the overlaps of different points can get very close to zero and the kernel becomes uninformative.
Dequantization
In 2018 Ewin Tang showed that the exponential advantage of the quantum recommendation-system algorithm disappears against a classical algorithm working under the same assumptions. Results like this are called dequantization and have been applied to many quantum machine learning algorithms.
Today the most promising direction of the field is where the data itself is quantum: for example, processing states that come from a quantum sensor or a quantum simulation directly on a quantum computer. There are proven exponential advantages on such “quantum data”.
Try it yourself
This circuit is an overlap test: H is the feature map for x and the second H is its inverse. Because the states are identical the result is 0 with 100% certainty, so the kernel value is 1. Insert a Z in between: the two states are now orthogonal and the probability of 0, the kernel value, becomes 0.
Open the circuit in your browserThe circuit playground is in Turkish. Button guide: “1000 kez ölç” = measure 1000 times, “Durum vektörünü göster” = show the state vector, “Bu devrenin Qiskit kodu” = this circuit’s Qiskit code, “Geri al” = undo, “Temizle” = clear. Click a gate in the circuit to remove it.
Key points
- A quantum kernel measures the similarity of two data points by the overlap |⟨φ(x)|φ(y)⟩|².
- The overlap is measured by applying the circuit and its inverse and looking at the probability of 0; the rest is a classical SVM.
- Proven advantages are on artificial problems; superiority on real data is unclear.
- Dequantization results have matched many QML speed-up claims with classical algorithms.
Test yourself
In the quantum kernel method, what is the kernel value of two identical data points?
- 0
- 1
- 0.5
Show the answer
1. Identical points go to the same quantum state; the overlap of a state with itself is |⟨φ|φ⟩|² = 1.
← The variational classifier: training a circuit like a neural network · Kinds of quantum hardware: from superconductors to photons →