Intermediate

Quantum Circuits for Machine Learning

Variational quantum circuits are the building blocks of quantum ML. They use parameterized gates as trainable weights, optimized by classical computers in a hybrid loop.

Variational Quantum Circuits (VQCs)

A variational quantum circuit (also called a parameterized quantum circuit) is the quantum equivalent of a neural network. It consists of:

  1. Data Encoding

    Encode classical data into quantum states using rotation gates. Each feature maps to a qubit rotation angle.

  2. Parameterized Layers

    Apply layers of rotation gates with trainable parameters (θ) and entangling gates (CNOT) between qubits.

  3. Measurement

    Measure qubits to get classical output. The expectation values serve as model predictions.

  4. Classical Optimization

    A classical optimizer (Adam, COBYLA) updates the parameters to minimize a loss function.

Data Encoding Strategies

EncodingMethodQubits NeededBest For
Angle EncodingEach feature → rotation angle on one qubitn (one per feature)Small feature sets
Amplitude EncodingFeatures encoded as amplitudes of quantum statelog(n)Large feature sets
Basis EncodingBinary features mapped to computational basisn (one per bit)Binary data
IQP EncodingFeatures encoded with entangling interactionsnCapturing feature correlations

Ansatz Design

The ansatz is the structure of the parameterized circuit. Common designs include:

  • Hardware-efficient ansatz: Uses gates native to the quantum hardware. Minimizes circuit depth but may be hard to train (barren plateaus).
  • Strongly entangling layers: Alternating rotation and CNOT layers with full qubit connectivity. Good expressibility.
  • Problem-inspired ansatz: Circuit structure tailored to the specific problem (e.g., UCCSD for chemistry).
  • Tensor network ansatz: Mimics tensor network structures like MPS or MERA. Good for structured data.

Quantum Kernels

An alternative to VQCs is using quantum computers to compute kernel functions. The idea: map data into quantum Hilbert space and compute inner products (overlaps) between quantum states. This can create feature spaces that are exponentially hard to compute classically.

  • Encode data point x into quantum state |φ(x)⟩
  • Compute kernel: K(x, x') = |⟨φ(x)|φ(x')⟩|²
  • Use the kernel matrix with classical SVM or other kernel methods

The Barren Plateau Problem

A major challenge in training VQCs is the barren plateau phenomenon: as the number of qubits grows, gradients of the cost function vanish exponentially, making optimization impossible. Mitigation strategies include:

  • Using shallow circuits with local cost functions
  • Problem-inspired ansatz designs
  • Layer-wise training (train one layer at a time)
  • Parameter initialization strategies
Key takeaway: Variational quantum circuits encode data into quantum states and use parameterized gates as trainable weights. The choice of data encoding and ansatz design critically affects model performance. Watch out for barren plateaus in deep circuits.