Loading...
Loading...
QNNs & Quantum Kernels
Quantum Machine Learning explores how quantum computers can accelerate learning tasks. Quantum neural networks, kernel methods, and generative models leverage high-dimensional Hilbert spaces to potentially recognize patterns intractable for classical systems.
A Quantum Neural Network (QNN) replaces classical neurons with parameterized quantum circuits. Data is encoded into quantum states via feature maps, processed through variational layers, and measured to produce predictions.
The appeal lies in the exponentially large state space of n qubits (2^n complex amplitudes) and the ability to create feature maps that are extremely difficult to simulate classically. However, training QNNs remains challenging due to barren plateaus and noise.
Quantum kernel methods offer a different path to quantum advantage. Instead of training a quantum circuit end-to-end, a quantum computer computes a kernel matrix K(x_i, x_j) = |⟨φ(x_i)|φ(x_j)⟩|², where φ is a quantum feature map. This kernel is then used in a classical Support Vector Machine (SVM).
The quantum kernel can access feature spaces exponentially larger than any classical kernel, potentially enabling separation of data that is classically inseparable. The challenge is proving that the quantum kernel actually provides advantage for real-world datasets.
Quantum Feature Map
Quantum Kernel
Kernel Matrix
The field is rapidly evolving. Researchers are exploring quantum generative models, quantum reinforcement learning, and quantum transformers. At Identity Lab, we focus on hardware-aware QNN design for neutral atoms and rigorous benchmarking against classical baselines.
Runnable implementations you can copy and experiment with.
A simple QNN that classifies 2D data points using angle encoding and a variational layer.
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
import numpy as np
def feature_map(x):
"""Encode 2D data into qubits."""
qc = QuantumCircuit(2)
qc.ry(x[0], 0)
qc.ry(x[1], 1)
return qc
def variational_layer(theta):
"""Parameterized layer."""
qc = QuantumCircuit(2)
qc.ry(theta[0], 0)
qc.ry(theta[1], 1)
qc.cx(0, 1)
qc.ry(theta[2], 0)
qc.ry(theta[3], 1)
return qc
def classify(x, theta):
qc = QuantumCircuit(2, 1)
qc.compose(feature_map(x), inplace=True)
qc.compose(variational_layer(theta), inplace=True)
qc.measure(0, 0)
simulator = AerSimulator()
job = simulator.run(qc, shots=1024)
counts = job.result().get_counts()
p0 = counts.get('0', 0) / 1024
return 1 if p0 > 0.5 else 0
# Toy data
theta = [0.5, -0.3, 1.2, 0.8]
print(classify([0.1, 0.2], theta))
print(classify([2.0, 1.5], theta))A PennyLane implementation of a quantum kernel using angle encoding and state overlap.
import pennylane as qml
import numpy as np
n_qubits = 2
dev = qml.device('default.qubit', wires=n_qubits)
def feature_map(x):
qml.RY(x[0], wires=0)
qml.RY(x[1], wires=1)
@qml.qnode(dev)
def kernel(x1, x2):
feature_map(x1)
qml.adjoint(feature_map)(x2)
return qml.probs(wires=range(n_qubits))
def kernel_value(x1, x2):
probs = kernel(x1, x2)
return probs[0]
x1 = np.array([0.1, 0.2])
x2 = np.array([0.3, 0.4])
print("Kernel value:", kernel_value(x1, x2))