Variational Quantum Circuits & Core QML Algorithms
Maya's data can finally get into a circuit. Now: what makes that circuit actually learn something? This module is the payoff of everything so far — seven real algorithms built from one shared trainable idea.
Module 8 ended with Maya's molecule data properly loaded into a quantum state. Today she asks the question that's been sitting under everything: encoding gets the data in — what makes the circuit smart?
The Variational Idea
Every algorithm in this module shares one skeleton: encode data → apply a trainable parameterized circuit → measure → let a classical optimizer update the parameters → repeat. What changes between VQC, QSVM, QNN, and the rest is which part of that loop does the heavy lifting, and what you do with the result.
Tap each card below for a one-line preview of where this module is headed.
Parameterized Quantum Circuits
A Parameterized Quantum Circuit (PQC) is a fixed circuit structure with free parameters θ — usually rotation angles — that get tuned by training, exactly like weights in a classical network. Drag the slider to add more layers and watch the ansatz grow.
- Two gate types alternate: single-qubit rotations (Rx, Ry, Rz) hold the trainable parameters; entangling gates (usually CNOT) let qubits influence each other.
- Parameter count scales with layers and qubits — more layers means more expressive power, but also more parameters to train.
- The familiar tension returns: deeper ansätze are more expressive, but also more prone to the barren plateaus you met in Module 7.
Variational Quantum Classifiers (VQC)
A Variational Quantum Classifier is the loop from Chapter 1, made literal: encode → ansatz → measure an observable (commonly ⟨Z⟩ on one qubit) → compare against the true label → compute a loss → let a classical optimizer adjust the ansatz's parameters. Click through the pipeline, then hit train.
def cost(params, x, y):
pred = circuit(params, x) # encode + ansatz + measure
return (pred - y) ** 2
params = optimizer.step(cost, params)
Quantum Support Vector Machines (QSVM)
This is the kernel trick from Module 7, wearing a quantum costume. A quantum kernel measures the overlap between two quantum-encoded data points: K(xᵢ,xⱼ) = |⟨φ(xᵢ)|φ(xⱼ)⟩|². Feed a whole matrix of these values into a classical SVM, and the quantum computer's job is already done.
- Two-step split: quantum computer → kernel matrix; classical computer → the actual SVM optimization.
- Often easier to get running on today's hardware than a fully-trained VQC, since the quantum circuit is only called once per pair of points, not once per training iteration.
- Directly reuses IQP encoding from Module 8 as one popular choice of quantum feature map.
Quantum Neural Networks (QNN)
The analogy is genuinely useful, with one honest wrinkle: quantum evolution is linear (unitary), so the nonlinearity that gives classical networks their power has to sneak in some other way — usually through measurement, or a small classical layer stitched on afterward.
Classical Neural Network
Quantum Neural Network
- Same skeleton as Chapter 2's PQC — QNN is a framing, not a different circuit structure.
- Nonlinearity is the honest sticking point: unitary operations alone can't produce it, so QNNs borrow it from measurement statistics or a small classical post-processing step.
- Layered QNN variants with local, weight-shared structure lead directly to QCNNs, which you'll meet properly in Module 11.
Quantum Kernel Methods
As a quantum feature map (like IQP from Module 8) gets more expressive, the kernel values it produces can start to concentrate — collapsing toward a near-constant value almost everywhere. When that happens, the kernel can no longer tell data points apart, and both trainability and generalization suffer.
- The general idea: any kernel method can plug in a quantum kernel instead of a classical one.
- The real risk: kernel concentration — deep, highly expressive feature maps can wash out the very differences a kernel is supposed to detect.
- The sweet spot is often a shallower, carefully-designed feature map — not the deepest one available.
Quantum PCA
Classical PCA finds directions of maximum variance via eigen-decomposition of a covariance matrix. Quantum PCA (qPCA) uses phase estimation and density matrix exponentiation to extract dominant eigenvalues/eigenvectors — claimed to scale exponentially better in the number of features, under specific assumptions.
- Classical PCA: cost grows polynomially with the number of features (roughly cubic for a direct eigen-decomposition).
- Quantum PCA: claimed logarithmic scaling in feature count — a dramatic theoretical improvement.
- The asterisk: that speedup typically assumes the data is already available as an efficiently-preparable quantum state — the same efficient-state-preparation assumption that made QRAM (Module 8) an open problem, not a solved one.
Quantum Autoencoders
A quantum autoencoder is a PQC trained to squeeze an n-qubit state into fewer "latent" qubits, while the discarded "trash" qubits are pushed toward a fixed reference state — typically |0⟩. Drag the slider to change how many qubits get kept versus discarded.
- Training goal: minimize how far the trash qubits drift from |0⟩ — usually measured via a SWAP test or direct fidelity.
- Applications: compressing quantum simulation data, denoising, and anomaly detection — data that compresses poorly may be genuinely unusual.
- Closes the loop on this module: like every other algorithm here, it's the same encode → ansatz → measure → optimize pattern from Chapter 1, aimed at a new goal.
Module 9 Assessment
Eight synthesis questions, one per chapter. Your result adapts to your whole session — chapters where you struggled above get flagged for review here, regardless of how this final round goes.