Quantum Machine Learning
Open in the Padhaiko app8.1 Introduction to QML and its importance
Quantum Machine Learning (QML) is an interdisciplinary field combining quantum information processing with machine learning algorithms to solve pattern recognition, classification, regression, clustering, and generative modeling tasks.
The Four Quadrants of QML
QML paradigms are classified according to whether the data and the learning algorithm are classical (C) or quantum (Q):
| Paradigm | Data Source | Processing Device | Description & Examples |
|---|---|---|---|
| CC | Classical | Classical | Quantum-inspired classical algorithms (e.g., tensor networks) |
| CQ | Classical | Quantum | Classical datasets mapped into quantum states and learned via VQCs or QSVMs (main NISQ focus) |
| QC | Quantum | Classical | Classical neural networks analyzing experimental quantum measurements or tomography data |
| Quantum | Quantum | Quantum algorithms operating directly on quantum states from quantum sensors or simulations |
Why QML Is Important
- Exponentially High-Dimensional Feature Spaces: An -qubit register spans a -dimensional complex Hilbert space . Embedding classical data into this space enables learning non-linear decision boundaries via quantum inner products (kernels) that can be intractable to evaluate classically.
- Linear Algebra Acceleration: Fault-tolerant subroutines such as quantum phase estimation and the Harrow–Hassidim–Lloyd (HHL) algorithm offer exponential speedups for structured linear systems, Principal Component Analysis (qPCA), and least-squares fitting (subject to efficient state-loading assumptions).
- Native Modeling of Quantum Systems: For molecular energies, materials discovery, and quantum phase recognition (QQ), quantum models avoid the exponential memory wall of classical simulation.
- NISQ Practical Constraints: Real-world QML on classical data (CQ) faces a data-loading bottleneck (encoding features can negate speedups if state preparation takes gates) and barren plateaus during optimization.
8.2 Quantum data representation and feature encoding
Before a quantum circuit can process a classical feature vector , it must be embedded into a quantum state via a quantum feature map acting on :
Three Fundamental Quantum Feature Encoding Methods
- Basis Encoding: Converts each integer/binary feature into its -bit binary string and maps the concatenated bitstring directly to a computational basis state using gates wherever .
- Example: .
- Cost: circuit depth, but requires qubits and treats similar real values orthogonally.
- Amplitude Encoding: Stores a normalized -dimensional data vector directly inside the probability amplitudes of an -qubit state:
- Cost: Exponentially compact in qubits ( qubits for features), but arbitrary state preparation requires up to entangling gates.
- Angle (Rotation) Encoding: Rescales each feature into an angle (e.g., or ) and applies one single-qubit Pauli rotation gate ( or ) per qubit:
- Cost: Constant circuit depth using qubits for features—the standard choice for NISQ classifiers. (Entangling layers like in ZZ-Feature Maps add non-linear feature interactions.)
| Encoding Scheme | Qubits for Features | Circuit Depth | NISQ Suitability | Key Limitation |
|---|---|---|---|---|
| Basis Encoding | (-bit precision) | Low (huge qubit count) | No continuous geometry / no inner-product similarity | |
| Amplitude Encoding | Moderate (deep prep) | State preparation bottleneck; discards norm | ||
| Angle Encoding | (or with dense angle) | High (shallow) | Qubit count grows linearly with feature dimension |
8.3 Variational Quantum Circuits (VQC)
A Variational Quantum Circuit (VQC)—also called a Parameterized Quantum Circuit (PQC)—is the quantum analogue of a trainable neural network architecture.
Structure of a Variational Quantum Circuit
A VQC maps an input state through a sequence of parameterized unitary layers:
where:
- consists of single-qubit rotations (such as and ) with trainable real parameters .
- is a fixed entangling layer (such as a ladder or ring of or gates) creating multi-qubit correlations.
The circuit output is extracted as the expectation value of a chosen Hermitian observable (e.g., ):
Exact Gradients on Hardware: The Parameter-Shift Rule
Classical finite-difference approximations fail on noisy quantum hardware because dividing shot noise by small causes huge variance. Instead, VQCs use the exact Parameter-Shift Rule:
The Parameter-Shift Rule
For any parameterized gate of the form , where is a Hermitian operator with eigenvalues (including all Pauli rotations ), the exact partial derivative of with respect to parameter is:
This yields the exact analytical gradient using macroscopically separated shifts rather than small .
Barren Plateaus
When an ansatz is too deep and unstructured (approximating a 2-design over ), the variance of cost-function gradients vanishes exponentially with qubit count :
This phenomenon, called a barren plateau, flattens the optimization landscape and prevents gradient descent from training. It is mitigated using shallow local cost functions, problem-inspired ansatzes, and layer-by-layer initialization.
8.4 Simple quantum classifiers and QNN concepts
Variational Quantum Classifiers (VQC)
For binary classification ( or ):
- Encode classical sample into .
- Apply trainable ansatz .
- Measure Pauli- on the readout qubit(s), obtaining , and convert to class probability:
(Predict if , and if .)
Quantum Neural Networks (QNNs) and Data Re-Uploading
A Quantum Neural Network (QNN) generalizes a single feature-map + ansatz block into multi-layer architectures:
- Data Re-Uploading: Interleaving feature encoding blocks repeatedly between trainable layers —i.e., —allows the circuit to generate high-order Fourier series in , acting as a universal function approximator even with few qubits.
- Quantum Convolutional Neural Networks (QCNNs): Apply translation-invariant local unitaries followed by partial qubit measurements (pooling) to halve qubit count per layer, avoiding barren plateaus.
Quantum Kernel Classifiers (QSVM)
Instead of optimizing circuit weights inside a loop, a Quantum Kernel Support Vector Machine uses the quantum hardware strictly to compute the kernel matrix:
The symmetric positive semi-definite matrix is then passed to a classical convex SVM solver, guaranteeing convergence to a unique global optimum.
8.5 Hybrid quantum-classical learning models
Because NISQ processors have limited qubit counts, shallow coherence budgets, and no quantum RAM, practical QML operates as a hybrid quantum-classical feedback loop.
Hybrid Quantum-Classical Training Loop
In a hybrid QML architecture, responsibilities are split across two processors:
- Quantum Processor (QPU) — Forward Pass & Gradient Evaluation:
- Prepares encoded state and executes parameterized circuit .
- Samples measurements to estimate expectation values and parameter-shift derivatives .
- Classical Processor (CPU/GPU) — Loss & Parameter Optimization:
- Evaluates a classical loss function (e.g., Mean Squared Error or Binary Cross-Entropy) over mini-batches.
- Updates using classical optimizers:
- Gradient-based: Adam, SGD (via parameter-shift rule).
- Gradient-free / Shot-efficient: SPSA (Simultaneous Perturbation Stochastic Approximation, requiring only evaluations per step regardless of parameter count), COBYLA, Nelder–Mead.
- Iterates until converges.
Dressed Quantum Circuits (Classical + Quantum Neural Hybrids)
For high-dimensional inputs (e.g., -pixel images), a dressed quantum circuit integrates classical and quantum layers end-to-end:
- The classical front-end compresses high-dimensional raw inputs into compact features matching the NISQ qubit budget.
- The classical back-end maps quantum expectations to arbitrary numbers of output classes, and automatic differentiation (PyTorch/PennyLane) propagates gradients seamlessly across both classical and quantum parameters.
| Aspect | Purely Quantum VQC | Hybrid Dressed QNN |
|---|---|---|
| Input Dimension | Limited directly by available qubits | Arbitrary (classical encoder compresses to ) |
| Parameter Count | quantum rotation angles | Classical weights + quantum VQC angles trained jointly |
| NISQ Practicality | Suited to low-dimensional tabular/quantum data | Suited to images, speech, and real-world datasets |
Worked Examples
8.1
Consider the classical 4-dimensional feature vector :
- Construct the -qubit amplitude-encoded quantum state and compute the measurement probabilities and .
- Suppose instead a rescaled feature vector is embedded via angle encoding using on qubits. Write the encoded product state and find the probability of measuring .
Amplitude Encoding on 2 Qubits: First compute the Euclidean norm of :
Dividing each entry by gives the normalized -qubit state:
Measurement probabilities by Born's rule:
-Angle Encoding on 4 Qubits: Using on each qubit:
- Qubit 1 ():
- Qubit 2 ():
- Qubit 3 ():
- Qubit 4 ():
Thus:
The amplitude of is , so:
- Amplitude state: , with .
- Angle state probability: .
8.2
Consider a single-qubit Variational Quantum Circuit applying to , with objective function .
- Derive the closed-form expression for and evaluate .
- Compute the gradient using the parameter-shift rule and verify it against the exact analytical derivative.
Deriving : Applying :
At :
Evaluating the Gradient via Parameter-Shift Rule:
Substituting into the parameter-shift formula:
Checking against calculus: , confirming exact agreement.
- , and .
- Parameter-shift gradient: , matching identically.
8.3
A single-qubit hybrid classifier encodes input using followed by a trainable variational gate initialized at , giving . The predicted probability for class is , trained with MSE loss . For a training sample and learning rate :
- Compute , , and the initial loss .
- Perform one classical gradient-descent step .
Forward Pass on the Quantum Circuit: At and , the total rotation angle is :
The predicted probability and MSE loss (for ) are:
Gradient Calculation and Classical Optimizer Update: Using the chain rule (where ):
Updating with learning rate :
Increasing moves closer to , pushing toward and toward .
- , , initial loss .
- Gradient , updated parameter .
Practice Exercises
Practice Exercises — Quantum Machine Learning
Describe the four quadrants of Quantum Machine Learning (CC, CQ, QC, QQ) and explain the data-loading bottleneck faced by CQ algorithms in the NISQ era.
The Four QML Quadrants:
- CC (Classical data, Classical algorithm): Quantum-inspired classical techniques such as tensor networks.
- CQ (Classical data, Quantum algorithm): Classical feature vectors embedded into quantum states and processed by VQCs or quantum kernels.
- QC (Quantum data, Classical algorithm): Classical ML applied to quantum measurement records (e.g., quantum state tomography or phase classification).
- QQ (Quantum data, Quantum algorithm): Quantum processors analyzing quantum states directly without classical conversion.
The CQ Data-Loading Bottleneck: Many fault-tolerant QML speedups (like HHL or qPCA) assume classical data of size can be loaded in time via Quantum RAM (QRAM). On NISQ hardware without QRAM, preparing an arbitrary -dimensional amplitude state requires gates, which can erase any theoretical quantum speedup. Consequently, NISQ QML favors shallow angle encoding or hybrid dressed networks.
The four quadrants classify QML by data type processor type (CC, CQ, QC, QQ). The data-loading bottleneck in CQ occurs because loading classical amplitudes without QRAM can take gates, dominating the total runtime.
Encode the classical data vector using -qubit amplitude encoding. Write the normalized state and compute the probability of observing each computational basis outcome .
Computing the Euclidean Norm:
Normalized State and Basis Probabilities: Dividing each entry by :
Measurement probabilities:
, with probabilities .
For a 1-qubit VQC with acting on and observable , show that , and verify the parameter-shift rule explicitly at .
Evaluating : Applying to :
Computing the expectation of :
Parameter-Shift Check at : Exact derivative: . Parameter-shift formula:
Both match identically.
, and at the parameter-shift rule gives , matching exactly.
In a Quantum Kernel Estimator (QSVM), two scalar inputs and are encoded into 1-qubit feature states using . Compute the quantum kernel entry .
Writing the Two Feature States:
- For : .
- For : .
Computing Kernel Overlap:
Squaring the modulus (which equals ):
The quantum kernel value is (in general, ).
Explain the division of tasks in a hybrid quantum-classical learning model and state two practical strategies used to mitigate barren plateaus when training Variational Quantum Circuits.
Division of Tasks in Hybrid QML:
- Quantum Co-Processor (QPU): Encodes classical features (or compressed latent vectors) into quantum states, executes the parameterized ansatz , and measures expectation values plus parameter-shift gradients over finite shots.
- Classical Host (CPU/GPU): Runs pre-/post-processing neural layers (in dressed quantum circuits), computes the loss function , and updates parameters via optimizers like Adam or SPSA.
Two Barren Plateau Mitigation Strategies:
- Shallow / Local Cost Functions & Problem-Inspired Ansatzes: Restricting circuit depth to or using problem-aware symmetry-preserving ansatzes and local observables (e.g., instead of global projectors ) prevents exponential gradient concentration.
- Identity-Block / Layer-by-Layer Initialization: Initializing parameters near identity blocks (e.g., pairs of ) or training one shallow layer at a time keeps initial gradients large and avoids random Haar-like mixing.
The QPU executes feature encoding, parameterized circuits, and expectation/gradient measurements, while the CPU/GPU computes loss and parameter updates (Adam/SPSA). Barren plateaus are mitigated using (1) shallow circuits with local cost observables and (2) identity-block or layerwise parameter initialization.