Variational Quantum Machine Learning Algorithms

Variational quantum machine learning algorithms are a hybrid approach in which a parameterized quantum circuit is tuned by a classical optimizer to approximate solutions to complex problems.

by Frank Zickert
September 15, 2025
Variational Quantum Machine Learning Algorithms

Variational Quantum Machine Learning algorithms are the defining approach of the era of Noisy Intermediate-Scale Quantum refers to the current generation of quantum devices that have enough qubits to run non-trivial algorithms but are still small and error-prone, limiting their reliability and scalability. medium-sized quantum computers.

    At the highest level, a variational quantum algorithm contains a simple feedback loop:
  1. Prepare a Quantum State is... using a A parameterized quantum circuit (PQC) is a Quantum Circuit whose Quantum Gate depend on adjustable Real Number parameters. These parameters are optimized by a classical algorithm to minimize a Cost Function making parameterized quantum circuits the central building block of variational quantum algorithms. They serve as an interface between Quantum Computer and Optimization is... tasks, connecting abstract algorithm design with practical implementation. (Ansatz).
  2. Measurement an Observable to obtain the Expectation Value.
  3. Update the parameters with a classical Optimization is... to minimize the Cost Function.
  4. This process repeats until the Cost Function no longer improves.

Parameterized Quantum Circuit

The tunable gate toward practical Quantum Machine Learning
5 min
Parameterized quantum circuits let us embed classical data into quantum states, tune them with adjustable gates, and read out predictions through measurement. The real question is whether these simple building blocks can be scaled into architectures that deliver genuine quantum advantage.
Figure 1 Variational Quantum Algorithm (VQA) Feedback Loop

It looks almost exactly like training a Machine Learning is an approach on solving problems by deriving the rules from data instead of explicitly programming. Model is.... The Ansatz is the Model is..., the Measurement is its prediction, the Cost Function measures the error, and the Optimization is... updates the parameters. Conceptually, this results in a simple recipe: alternate between running the A parameterized quantum circuit (PQC) is a Quantum Circuit whose Quantum Gate depend on adjustable Real Number parameters. These parameters are optimized by a classical algorithm to minimize a Cost Function making parameterized quantum circuits the central building block of variational quantum algorithms. They serve as an interface between Quantum Computer and Optimization is... tasks, connecting abstract algorithm design with practical implementation. and adjusting the parameters until the Cost Function converges.

This high-level recipe is neat, but incomplete. It obscures the fact that not all Ansatz, Observable, or Optimization is... behave the same way.

Since Variational Quantum Machine Learning algorithms look pretty much like classic Machine Learning is an approach on solving problems by deriving the rules from data instead of explicitly programming. algorithms, it stands to reason that greater depth also means higher quality. In Deep Learning, for example, adding layers generally increases Expressiveness and improves Accuracy when sufficient data is available. With Variational Quantum Machine Learning algorithms, however, Circuit Depth quickly becomes a disadvantage.

Optimization does not work on a flat cost landscape
Figure 2 Optimization does not work on a flat cost landscape

Deeper Ansatz cover a larger number of Quantum State is..., but this Expressiveness comes at the expense of Trainability McClean, J.R., 2018, Nature Communications, Vol. 9, pp. 4812. The Optimization is... then sees a flat landscape and is unable to distinguish good updates from bad ones. In practice, this means that doubling the Circuit Depth rarely leads to a doubling of performance. Instead, it often completely suppresses the learning signal.

The tension is structural: shallow circuits are Trainability but limited, deep circuits are Expressiveness but untrainable. When designing Ansatz, the focus is therefore not on more layers but on a balance between Expressiveness and optimization stability (Trainability).

Looking at the top level, three components define how a Variational Quantum Machine Learning algorithm really works. Together, Encoding, Ansatz, and Measurement define the hypothesis class, the optimization landscape, and the signal available for learning. In practice, it is the savvy selection of these components that makes the difference between a functioning algorithm and one that stalls.

  • Encoding of is a An Unitary operator is a reversible quantum transformation. (therefore ) that Encoding the data value according to a Quantum Feature Map is... ("phi"). Different choices of correspond to different ways of embedding data into a Quantum State is..., such as Angle Encoding, Amplitude Encoding, or more elaborate Quantum Feature Map is...). So means apply the unitary defined by encoding rule to input . The is not a variable like , but a tag to remind you how the data is being encoded.: injects classical data or problem structures into a Quantum State is... For example, in Quantum Machine Learning is the field of research that combines principles from Quantum Computing is a different kind of computation that builds upon the phenomena of Quantum Mechanics. with traditional Machine Learning is an approach on solving problems by deriving the rules from data instead of explicitly programming. to solve complex problems more efficiently than classical approaches. , a Quantum Feature Map is... encodes inputs into Amplitude Encoding or Phase Encoding; in chemistry, a Hamiltonian Operator is encoded into the Quantum Circuit However, the concept is the same. This part encodes the problem we want to solve.
  • Ansatz : The trainable part of the Quantum Circuit, constructed from parameterized Rotation Operator and Entanglement Operator. This is the space in which Optimization is... takes place, analogous to the architecture of a An artificial neural network is a computational model of interconnected nodes inspired by biological neurons, used to approximate functions and recognize patterns. whose weights describes the solution.
  • Measurement : The Observable that defines the learning signal. In classification, it could be a Pauli Operator mapped to labels.

The complete prediction takes the form of an Expectation Value as shown in the ?.

Figure 3 Variational quantum machine learning prediction

Here, is a basis state. is the reference state, which consists exclusively of zeros. is a An Unitary operator is a reversible quantum transformation. (therefore ) that Encoding the data value according to a Quantum Feature Map is... ("phi"). Different choices of correspond to different ways of embedding data into a Quantum State is..., such as Angle Encoding, Amplitude Encoding, or more elaborate Quantum Feature Map is...). So means apply the unitary defined by encoding rule to input . The is not a variable like , but a tag to remind you how the data is being encoded. is the encoding that prepares a data-dependent state. is the trainable A parameterized quantum circuit (PQC) is a Quantum Circuit whose Quantum Gate depend on adjustable Real Number parameters. These parameters are optimized by a classical algorithm to minimize a Cost Function making parameterized quantum circuits the central building block of variational quantum algorithms. They serve as an interface between Quantum Computer and Optimization is... tasks, connecting abstract algorithm design with practical implementation.. And is the selected Observable. The full Bra Ket means that we average the measurement result over many runs. The Adjoint occur because an Expectation Value in Linear Algebra is an Inner Product

Let's make this more practical and implement a variational Quantum Machine Learning algorithm with Qiskit.

We begin with some preparations as depicted in ?. To do this, we all the functions that we will use from other modules.

simple-vqa.py
1
2
3
4
5
6
7
8
import numpy as np
from qiskit import QuantumCircuit
from qiskit.quantum_info import SparsePauliOp
from qiskit_aer.primitives import EstimatorV2 as Estimator
 
estimator = Estimator()
observable = SparsePauliOp.from_list([("Z", 1.0)])
target = 0.0
Listing 1 Preparation for a simple variational quantum machine learning algorithm
    We also initialize instances of classes that we will use in our example.
  1. We . This creates the EstimatorV2 primitive from Qiskit Aer. You use it to calculate Expectation Value for (Quantum Circuit, Observable) pairs.
  2. We . This creates the Hermitian Matrix . In practice, this example means: Measure the one A qubit is the basic unit of quantum information, representing a superposition of 0 and 1 states. we have in the basis and assign the Eigenvalue that correspond to Basis State. So, we assign to is a basis state. and to is a basis state..
  3. We target = 0.0. Accordingly, the Optimization is... attempts to bring to . That means, it moves the Quantum State Vector to the equator of the Bloch Sphere (relative to the -axis. When you change the target value, the Optimization is... will pursue this new target value. For instance, target=1 pushes toward is a basis state. and target=-1 pushes toward is a basis state..

Qiskit Primitives

The next ? depicts the main Machine Learning is an approach on solving problems by deriving the rules from data instead of explicitly programming. . But before we start this loop, we initialize the Optimization is... with a (guessed) starting parameter , the , a within which we accept results as good enough, and the from evaluating the cost function at the starting parameter value.

simple-vqa.py
1
2
3
4
5
6
7
8
9
10
11
12
13
theta = 0.3
max_iters = 100
tol = 1e-4
prev_loss = cost(theta)
 
for k in range(max_iters):
theta = spsa_update(theta, k)
curr_loss = cost(theta)
if abs(prev_loss - curr_loss) < tol:
break
prev_loss = curr_loss
 
print(f"Final theta: {theta:.4f}, final cost: {curr_loss:.6f}")
Listing 2 The main machine learning loop
  1. Each iteration starts by with the result we obtain from calling the function spsa_update(theta, k), which applies a stochastic approximation step potentially using gradient estimates affected by the .
  2. Then, we using the cost function at the new theta.
  3. The algorithm then , measured as the absolute difference between the previous loss and current loss, is below the tolerance threshold tol. If so, it breaks the loop early, indicating convergence.
  4. If not converged, the to be used in the next iteration's comparison.

In this main feedback loop, we use two functions we have not yet defined: and

? shows the implementation of the spsa_update function that performs the classical Simultaneous Perturbation Stochastic Approximation Optimization is....

simple-vqa.py
1
2
3
4
5
6
7
8
9
def spsa_update(theta: float, k: int, a0=0.1, c0=0.1) -> float:
"""Classical optimizer step (SPSA-like)."""
a_k = a0 / (k + 1) ** 0.101
c_k = c0 / (k + 1) ** 0.102
delta = 1 if np.random.rand() < 0.5 else -1
loss_plus = cost(theta + c_k * delta)
loss_minus = cost(theta - c_k * delta)
ghat = (loss_plus - loss_minus) / (2 * c_k * delta)
return theta - a_k * ghat
Listing 3 Classical SPSA-like parameter update with stochastic gradient approximation

This optimizer the result of the cost function at slightly around theta. Here, the decays with the iteration count kto refine the approximation over time.

The difference quotient estimates the , which is used to update theta by stepping opposite to the gradient scaled by the that also decays slightly with k. Finally, we the updated theta parameter .

Let's now look at the code of the cost function in ?.

simple-vqa.py
1
2
3
def cost(theta: float) -> float:
ev = measure_expectation(theta)
return (ev - target) ** 2 # simple squared-error cost
Listing 4 Cost function computing squared error from measure_expectation and target

This function evaluates the quality of the by measuring the expectation value via and comparing it to the predefined target.

The cost is computed as the squared error between the measured value and target, forming a simple loss landscape guiding the optimizer toward minimizing this difference.

So far, all the code we have seen works in a purely classical way. This now changes with the calculation of the Expectation Value depicted in ?.

simple-vqa.py
1
2
3
4
5
6
7
def measure_expectation(theta: float) -> float:
"""Measure the observable to get an expectation value."""
qc = build_ansatz(theta)
# V2 API: (circuit, observable, parameter_values), no free Parameters, so [] is fine
result = estimator.run([(qc, observable, [])]).result()
evs = np.asarray(result[0].data.evs)
return float(np.atleast_1d(evs).ravel()[0])
Listing 5 Quantum circuit execution and measurement using the Estimator API to obtain expectation value
  1. The function takes a single parameter theta and passes it to a A parameterized quantum circuit (PQC) is a Quantum Circuit whose Quantum Gate depend on adjustable Real Number parameters. These parameters are optimized by a classical algorithm to minimize a Cost Function making parameterized quantum circuits the central building block of variational quantum algorithms. They serve as an interface between Quantum Computer and Optimization is... tasks, connecting abstract algorithm design with practical implementation. we create in the .
  2. We use the Estimator instance with a tuple containing the circuit, the observable, and an empty parameter list corresponding to no free parameters, as highlighted in to .
  3. We extract the and coerce the batch of expectation values that we return.

? depicts the final missing piece of our variational quantum machine learning algorithm: the Ansatz.

simple-vqa.py
1
2
3
4
5
def build_ansatz(theta: float) -> QuantumCircuit:
"""Prepare a parameterized state |ψ(θ)⟩."""
qc = QuantumCircuit(1)
qc.ry(theta, 0)
return qc
Listing 6 Function to create the ansatz

The build_ansatz function the simplest imaginable Ansatz: a Quantum Circuit with a single A qubit is the basic unit of quantum information, representing a superposition of 0 and 1 states.. It applies the Rotation Operator and therefore turns the Quantum State Vector around the -axis by the angle (theta) that the function takes as a .

This simple Ansatz only explores Quantum State is... around the -axis of the Bloch Sphere. This is the vertical circle in the -plane as shown in ?.

Figure 4 States reachable by the RY-operator

After the minimal code demo with a single A qubit is the basic unit of quantum information, representing a superposition of 0 and 1 states., a single , and a -measurement, we've seen the mechanics but also the limitation: a very simple Ansatz is easy to train yet too weak for most problems. The next step is to scale carefully because the pitfalls are waiting for us. Nevertheless, Barren Plateau Noise and over-parameterization are manageable with disciplined design:

  • Problem-inspired ansätze: mirror the structure of the objective (chemistry Hamiltonians, graph constraints). This preserves gradient signal and reduces wasted parameters.
  • Shallow designs: keep depth minimal to limit noise accumulation and avoid flat landscapes while still capturing key correlations.
  • Initialization near identity: start close to the reference circuit so gradients don't vanish at step zero.
  • Geometry-aware optimization: use Stokes, J., 2020, Quantum, Vol. 4, pp. 269.
  • Error mitigation: apply lightweight post-processing (e.g. Zero Noise Extrapolation) to curb bias without full fault tolerance.

These are the exact fronts where Quantum Machine Learning is the field of research that combines principles from Quantum Computing is a different kind of computation that builds upon the phenomena of Quantum Mechanics. with traditional Machine Learning is an approach on solving problems by deriving the rules from data instead of explicitly programming. to solve complex problems more efficiently than classical approaches. research is concentrated today.