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 ZickertSeptember 15, 2025
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:
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).
Measurement an Observable to obtain the Expectation Value.
Update the parameters with a classical Optimization is... to minimize the Cost Function.
This process repeats until the Cost Function no longer improves.
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.
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 TrainabilityMcClean, J.R., 2018, Nature Communications, Vol. 9, pp. 4812. The optimizerOptimization is... then sees a flat landscape and is unable to distinguish good updates from bad ones. In practice, this means that doubling the Circuit DepthCircuit Depth rarely leads to a doubling of performance. Instead, it often completely suppresses the learning signal.
The tension is structural: shallow circuits are trainableTrainability but limited, deep circuits are expressiveExpressiveness but untrainable. When designing ansätzeAnsatz, the focus is therefore not on more layers but on a balance between ExpressivenessExpressiveness and optimization stability (TrainabilityTrainability).
Looking at the top level, three components define how a Variational Quantum Machine Learning algorithm really works. Together, EncodingEncoding, AnsatzAnsatz, and MeasurementMeasurement 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 Unitary OperatorAn Unitary operator is a reversible quantum transformation. (therefore ) that encodesEncoding the data value according to a encoding scheme or feature mapQuantum Feature Map is... ("phi"). Different choices of correspond to different ways of embedding data into a Quantum StateQuantum State is..., such as Angle EncodingAngle Encoding, Amplitude EncodingAmplitude Encoding, or more elaborate Quantum Feature MapsQuantum 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.Quantum State is... For example, in Quantum Machine LearningQuantum Machine Learning is the field of research that combines principles from Quantum ComputingQuantum Computing is a different kind of computation that builds upon the phenomena of Quantum Mechanics. with traditional Machine LearningMachine 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 MapQuantum Feature Map is... encodes inputs into amplitudesAmplitude Encoding or phasePhase Encoding; in chemistry, a HamiltonianHamiltonian Operator is encoded into the Quantum Circuit.Quantum Circuit However, the concept is the same. This part encodes the problem we want to solve.
Ansatz : The trainable part of the Quantum CircuitQuantum Circuit, constructed from parameterized rotationsRotation Operator and entanglementsEntanglement Operator. This is the space in which OptimizationOptimization is... takes place, analogous to the architecture of a Neural NetworkAn 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 ObservableObservable that defines the learning signal. In classification, it could be a Pauli OperatorPauli Operator mapped to labels.
The complete prediction takes the form of an Expectation Value,Expectation Value as shown in the ?.
Here, is a basis state. is the reference state, which consists exclusively of zeros. is a Unitary OperatorAn Unitary operator is a reversible quantum transformation. (therefore ) that encodesEncoding the data value according to a encoding scheme or feature mapQuantum Feature Map is... ("phi"). Different choices of correspond to different ways of embedding data into a Quantum StateQuantum State is..., such as Angle EncodingAngle Encoding, Amplitude EncodingAmplitude Encoding, or more elaborate Quantum Feature MapsQuantum 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 Parameterized Quantum CircuitA parameterized quantum circuit (PQC) is a Quantum CircuitQuantum Circuit whose Quantum GatesQuantum Gate depend on adjustable realReal Number parameters. These parameters are optimized by a classical algorithm to minimize a Cost Function,Cost Function making parameterized quantum circuits the central building block of variational quantum algorithms. They serve as an interface between quantum hardwareQuantum Computer and OptimizationOptimization is... tasks, connecting abstract algorithm design with practical implementation.. And is the selected ObservableObservable. The full bra-ket notationBra Ket means that we average the measurement result over many runs. The adjunctionsAdjoint occur because an Expectation ValueExpectation Value in Linear AlgebraLinear Algebra is an Inner Product.Inner Product
Let's make this more practical and implement a variational Quantum Machine Learning algorithm with QiskitQiskit.
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
Listing 1 Preparation for a simple variational quantum machine learning algorithmWe also initialize instances of classes that we will use in our example.
We . This creates the EstimatorV2 primitive from Qiskit AerQiskit Aer. You use it to calculate Expectation ValuesExpectation Value for (Quantum CircuitQuantum Circuit, ObservableObservable) pairs.
We . This creates the Hermitian operatorHermitian Matrix. In practice, this example means: Measure the one QubitA qubit is the basic unit of quantum information, representing a superposition of 0 and 1 states. we have in the basis and assign the EigenvaluesEigenvalue that correspond to Basis StatesBasis State. So, we assign to is a basis state. and to is a basis state..
We target = 0.0. Accordingly, the optimizerOptimization is... attempts to bring to . That means, it moves the Quantum State VectorQuantum State Vector to the equator of the Bloch SphereBloch Sphere (relative to the -axis. When you change the target value, the optimizerOptimization 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 LearningMachine 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 OptimizationOptimization 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 inrange(max_iters):
theta = spsa_update(theta, k)
curr_loss = cost(theta)
ifabs(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
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 .
Then, we using the cost function at the new theta.
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.
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 ApproximationSimultaneous Perturbation Stochastic ApproximationoptimizerOptimization is....
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 ?.
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 ValueExpectation Value depicted in ?.
simple-vqa.py
1
2
3
4
5
6
7
defmeasure_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)
returnfloat(np.atleast_1d(evs).ravel()[0])
Listing 5 Quantum circuit execution and measurement using the Estimator API to obtain expectation value
The function takes a single parameter theta and passes it to a Parameterized Quantum CircuitA parameterized quantum circuit (PQC) is a Quantum CircuitQuantum Circuit whose Quantum GatesQuantum Gate depend on adjustable realReal Number parameters. These parameters are optimized by a classical algorithm to minimize a Cost Function,Cost Function making parameterized quantum circuits the central building block of variational quantum algorithms. They serve as an interface between quantum hardwareQuantum Computer and OptimizationOptimization is... tasks, connecting abstract algorithm design with practical implementation. we create in the .
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 .
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 AnsatzAnsatz.
simple-vqa.py
1
2
3
4
5
defbuild_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 AnsatzAnsatz: a Quantum CircuitQuantum Circuit with a single Qubit.A qubit is the basic unit of quantum information, representing a superposition of 0 and 1 states.. It applies the rotationRotation Operator and therefore turns the Quantum State VectorQuantum State Vector around the -axis by the angle (theta) that the function takes as a .
This simple AnsatzAnsatz only explores Quantum StatesQuantum State is... around the -axis of the Bloch SphereBloch 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 QubitA 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 AnsatzAnsatz 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 Plateaus,Barren PlateauNoise,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 natural-gradient or related methods that respect the circuit’s information geometry for more stable progressStokes, J., 2020, Quantum, Vol. 4, pp. 269.
Error mitigation: apply lightweight post-processing (e.g. Zero Noise ExtrapolationZero Noise Extrapolation) to curb bias without full fault tolerance.
These are the exact fronts where Quantum Machine LearningQuantum Machine Learning is the field of research that combines principles from Quantum ComputingQuantum Computing is a different kind of computation that builds upon the phenomena of Quantum Mechanics. with traditional Machine LearningMachine 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.