Sitemap
Andreabenassi

Andreabenassi

Day 19 Qucode Cohort 3

6 min readSep 20, 2025

--

Topic: Quantum Machine Learning Basics, Quantum data encoding, Quantum neural networks

Quantum Machine Learning (QML) is an emerging research area that fuses quantum computing with machine learning. Its goal is not to simply “port” classical ML to quantum hardware, but to leverage quantum mechanics — superposition, entanglement, interference — to create new models that can capture complex patterns in data more efficiently.

At its heart, QML hinges on three pillars:

  1. Quantum data encoding (quantum feature maps): how classical data are represented as quantum states.
  2. Variational quantum models (quantum neural networks): parameterized quantum circuits trained like neural networks.
  3. Hybrid optimization loops: where classical optimizers update quantum circuit parameters based on measurements.

1. From Classical ML to Quantum ML

Classical ML models (e.g. neural networks, SVMs) rely on feature maps that transform data into high-dimensional spaces where classification or regression is easier. Quantum computers natively manipulate vectors in a Hilbert space of dimension 2^n for n qubits, providing a natural “high-dimensional” setting.

The hope is that quantum feature maps can generate data representations not efficiently reproducible classically, leading to potential quantum advantages in pattern recognition.

2. Quantum Data Encoding

Encoding is the first and most critical step: mapping classical vectors x∈R^d into quantum states |ψ(x)⟩.

2.1 Common Encoding Strategies

  1. Basis (computational) encoding:
    Encode each bit of binary data as a qubit state ∣0⟩ or ∣1⟩. Efficient but scales poorly with real-valued data.
  2. Amplitude encoding:
    Normalize a vector x and use its components as amplitudes

Very compact (exponentially many features in nnn qubits), but requires complex state preparation.

3. Angle (rotation) encoding:
Encode data into rotation angles of single-qubit gates. For example,

Simple and widely used on near-term devices

2.2 Feature Maps and Kernels

A quantum feature map is a unitary Uϕ(x) that embeds data into Hilbert space:

The kernel between two data points is then the inner product:

Quantum kernels can capture correlations beyond classical kernels. Qiskit provides built-in feature maps (ZFeatureMap, ZZFeatureMap, PauliFeatureMap), with tunable parameters: entanglement type (linear, circular, full), repetitions, and choice of rotation gates.

3. Quantum Neural Networks

A Quantum Neural Network (QNN) is essentially a parameterized quantum circuit:

  1. Input layer: data encoding via a feature map.
  2. Hidden layers: variational layers with parameterized rotations and entangling gates
  3. Output layer: measurement of qubits to yield classical probabilities or expectation values

Mathematically, a QNN defines a function

where M is a measurement operator and θ are trainable parameters.

3.1 Geometric Intuition (Grover-like rotations)

As visualized on the Bloch sphere, parameterized gates rotate qubits through specific angles. Training a QNN can be seen as finding the correct rotation trajectory so that measurement probabilities align with labels. This is why many QNN tutorials emphasize the geometric picture: encoding rotates qubits by data-dependent angles, then variational layers rotate further to separate classes.

Get Andreabenassi’s stories in your inbox

Join Medium for free to get updates from this writer.

3.2 Architectures

  • TwoLocal ansatz: alternating single-qubit rotations and entangling layers.
  • Hardware-efficient ansatz: optimized for device connectivity.
  • Problem-inspired ansatz: e.g., quantum convolutional networks or Hamiltonian-inspired layers.

4. Training Quantum Neural Networks

QNNs are trained in hybrid quantum-classical loops, analogous to Variational Quantum Algorithms (VQE, QAOA).

  1. Encode data point x into a quantum circuit
  2. Run circuit on a QPU or simulator, measure observables
  3. Define a loss function (e.g., cross-entropy for classification, MSE for regression)
  4. Use a classical optimizer (SPSA, Adam, L-BFGS) to update circuit parameters

4.1 Sampler vs Estimator Models in Qiskit

  • SamplerQNN: maps input → measurement probabilities → predicted class.
  • EstimatorQNN: outputs expectation values of observables (e.g., Pauli-Z or Hamiltonians), useful for regression and variational problems

4.2 Integration with PyTorch / TensorFlow

Qiskit’s TorchConnector allows QNNs to integrate with PyTorch, enabling GPU-accelerated training loops, auto-differentiation, and mixing quantum layers with classical deep nets (hybrid QML).

5. Example Workflows

To make QML concepts more concrete, let us examine two canonical workflows: classification and regression. Both rely on the same underlying machinery, feature maps for data encoding, variational ansatz circuits for trainable layers, and a hybrid optimization loop. The main difference, as in normal machine learning, lies in the loss functions used and the tasks they address.

5.1 Classification (Variational Quantum Classifier, VQC)

The Variational Quantum Classifier (VQC) is the quantum analogue of a classical supervised classifier. The pipeline consists of:

  1. Feature map (encoding):
    Classical inputs (e.g., 2D points from a dataset) are encoded into quantum states. A common choice is the ZZFeatureMap, which uses entangling rotations to capture pairwise correlations between features
  2. Variational ansatz (model):
    After encoding, a parameterized quantum circuit (often the TwoLocal ansatz) is applied. This ansatz alternates between single-qubit rotation gates and entangling layers, with trainable parameters that are updated during optimization.
  3. Training loop:
    The circuit is wrapped into a VQC object in Qiskit. Training proceeds as follows:
Press enter or click to view image in full size

4. Evaluation:
The output is a set of class probabilities, from which labels are assigned. Performance is measured using accuracy or other classification metrics like in normal machine learning.

The key point: the VQC learns a decision boundary not directly in the classical feature space, but in the quantum feature space induced by the encoding and entangling structure.

5.2 Regression (Variational Quantum Regressor, VQR)

Regression tasks focus on predicting continuous values rather than discrete labels. The Variational Quantum Regressor (VQR) adapts the same architecture but changes the objective:

  1. Feature map:
    Input variables (e.g., scalar values along a sine wave) are encoded into qubit rotations. For regression, even simple one-qubit encodings can suffice.
  2. Variational ansatz:
    A parameterized circuit (often shallow and hardware-efficient) is applied to transform the encoded input.
  3. Training loop:
    Instead of classification loss, the objective is Mean Squared Error (MSE) between the predicted expectation values (obtained from qubit measurements) and the true continuous labels.
  4. Evaluation:
    After training, the regressor can output smooth predictions for unseen data points.

The key point: the VQR illustrates how quantum circuits can interpolate and approximate continuous functions, highlighting their potential in regression-based applications such as physics simulations and forecasting.

6. Challenges in QML

  1. Barren Plateaus: gradients vanish for deep random circuits, limiting trainability.
  2. Encoding bottleneck: loading large classical datasets into quantum states may erase advantages.
  3. Noise & decoherence: small circuits can be trained, but scaling remains difficult.
  4. Lack of “killer app” yet: no clear evidence of quantum advantage in practical ML tasks on current devices.

7. Opportunities and Applications

Despite challenges, QML is being explored for:

  1. Chemistry & physics simulations: QNNs as ansatz for many-body wavefunctions.
  2. Finance: portfolio optimization and risk modeling.
  3. Healthcare: quantum-enhanced classification of molecular or imaging data.
  4. Generative modeling: quantum GANs and quantum Boltzmann machines.

--

--