A Variational Quantum Eigensolver (VQE) experiment is only useful when you can explain how the circuit, optimizer, measurements, and reference energy produced its result. This practical VQE tutorial gives developers a repeatable workflow for estimating the ground-state energy of a small molecule, comparing implementation choices in Qiskit or PennyLane, and deciding whether a result is numerically and physically trustworthy.
Overview
VQE is a hybrid quantum-classical algorithm for estimating the lowest eigenvalue of a Hamiltonian. In a molecular simulation, that eigenvalue is commonly used as an estimate of the molecule's ground-state electronic energy under a chosen model. The quantum processor or simulator evaluates expectation values, while a classical optimizer changes circuit parameters to reduce the measured energy.
The basic loop is:
- Choose a molecule and define its electronic-structure model.
- Map the molecular Hamiltonian to a sum of measurable Pauli operators.
- Prepare a parameterized trial state, called an ansatz.
- Measure the expectation value of each observable.
- Combine those values into an energy estimate.
- Use a classical optimizer to update the circuit parameters.
- Repeat until the energy and parameters satisfy defined convergence criteria.
In compact form, the objective is often written as E(theta) = <psi(theta)|H|psi(theta)>, where H is the Hamiltonian and theta contains the circuit parameters. The variational principle provides an important validation rule: within the same model and assumptions, the estimated energy should not be lower than the exact ground-state energy. A value that appears unusually favorable may indicate a mismatch in conventions, an incorrect Hamiltonian, noise, or an implementation error.
For a first experiment, use a very small system and a simulator with exact or high-shot evaluation. This separates algorithmic behavior from hardware noise. Chemistry packages and SDK integrations change over time, so treat framework code as an implementation pattern rather than a permanent API contract. The durable parts are the Hamiltonian, ansatz, measurement plan, optimizer log, and validation checks.
What to track
1. Problem definition and reference values
Record the molecule, geometry, basis set, charge, spin or multiplicity assumptions, active-space reductions, orbital mapping, and qubit ordering. These choices define the problem. Two VQE runs can produce different energies while both being correct if they use different chemistry models.
Keep an independent reference where possible. For a small system, this may be an exact diagonalization or a classical eigensolver applied to the same qubit Hamiltonian. Do not compare a VQE energy with a reference generated from different geometry, basis, orbital ordering, or nuclear-energy convention.
2. Hamiltonian and observables
Store the complete Pauli decomposition, including coefficients and identity terms. Track the number of terms, the number of qubits, and how terms are grouped into measurement circuits. A typical decomposition has the form H = c0 I + c1 P1 + c2 P2 + ..., where each P is a tensor product of Pauli operators.
Important measurement fields include shots per circuit, random seed where supported, grouping method, and whether expectation values were calculated exactly or sampled. Statistical uncertainty can make the objective appear to rise or fall even when the underlying circuit has not improved. For background on interpreting shot noise, see Quantum Measurement and Shots: A Practical Guide to Estimating Reliable Results.
3. Ansatz and circuit cost
Track the ansatz family, parameter count, circuit depth, two-qubit gate count, initial state, parameter initialization, and any symmetry constraints. A hardware-efficient ansatz is usually convenient for experimentation, but it can have optimization difficulties or explore states that do not reflect the chemistry problem. A problem-informed ansatz may use more domain knowledge and can reduce the search space, but it may be more difficult to construct or transpile.
| Ansatz choice | Useful when | Track carefully |
|---|---|---|
| Hardware-efficient | Testing a device-aware circuit with limited depth | Entangling pattern, depth, barren or flat optimization behavior |
| Problem-informed | Encoding known excitation or symmetry structure | State-preparation assumptions and representational limits |
| Adaptive | Growing the circuit in response to an optimization signal | Operator-selection rule, stopping threshold, and added depth |
4. Optimizer behavior
Log the optimizer name, learning rate or step size, maximum iterations, gradient method, parameter bounds, stopping tolerances, and initial point. Also save the energy after every objective evaluation, not only the final value. A final energy without its optimization history cannot reveal premature termination, oscillation, plateaus, or an invalid objective.
| Optimizer category | Practical consideration |
|---|---|
| Gradient-based | Can be efficient with reliable gradients, but shot noise may make updates unstable. |
| Gradient-free | Useful when derivatives are unavailable or noisy, but may require many objective evaluations. |
| Noise-aware or stochastic | Can tolerate measurement variation, but requires careful stopping rules and repeatable logging. |
5. Trust signals
Track the final energy, energy error against the reference, parameter convergence, objective-evaluation count, shot count, circuit depth after compilation, and repeated-run variation. A trustworthy result is not simply the lowest number. It should be reproducible enough for the experiment's purpose and supported by evidence that the implementation matches the intended model.
Cadence and checkpoints
Use checkpoints during development rather than waiting for the final run.
Before optimization
- Verify qubit ordering and Pauli conventions with a small hand-checkable operator.
- Confirm that the initial state has the intended particle number, spin, or symmetry where applicable.
- Evaluate the Hamiltonian on the initial circuit and compare the result with an independently calculated value.
- Run the same circuit through an exact simulator and a finite-shot simulator to quantify sampling variation.
During optimization
- Save every objective value, parameter vector, seed, and backend configuration.
- Plot energy against iteration and objective evaluations.
- Check whether energy decreases on average rather than demanding monotonic behavior from a noisy run.
- Repeat selected iterations with more shots if an apparent improvement is smaller than measurement uncertainty.
After convergence
- Repeat the final circuit with independent seeds or fresh sampling.
- Compare the best energy, final energy, and median energy across runs.
- Evaluate the converged parameters using the same Hamiltonian in an exact or high-precision simulator.
- Document compilation changes before moving to hardware.
A monthly or quarterly review is useful for a maintained project. Re-run a small benchmark after a major SDK release, chemistry-integration change, backend migration, or modification to the ansatz or optimizer. For broader performance tracking, pair the VQE log with the metrics described in How to Benchmark Quantum Programs: Metrics for Simulators, Cloud Hardware, and Cost.
How to interpret changes
If the energy improves after adding ansatz layers, first check whether the change reflects greater expressibility or merely a larger optimization budget. Compare circuit depth, parameter count, objective evaluations, and repeated-run variation together. A deeper ansatz that finds a lower simulator energy may still be a poor hardware candidate if its two-qubit-gate count increases substantially.
If runs disagree, separate three possible causes:
- Statistical variation: finite shots change expectation estimates. Increase shots or repeat the measurement to estimate the spread.
- Optimization variation: different initial parameters or stochastic steps reach different regions. Use multiple starts and report the distribution, not only the best run.
- Model or implementation variation: a changed Hamiltonian, qubit mapping, observable grouping, or state-preparation circuit makes the comparison invalid.
If the VQE result is lower than a trusted exact reference for the same Hamiltonian, stop and debug rather than treating it as an improvement. Check sign conventions, identity contributions, coefficient units, measurement basis rotations, bit ordering, and whether error mitigation or post-processing changes the variational interpretation. The Quantum Circuit Debugging Guide provides a useful companion checklist.
When moving from a simulator to real hardware, expect the interpretation to change. Gate noise, readout errors, connectivity constraints, compilation, queue or execution settings, and drift can all affect the objective. Compare ideal simulation, noisy simulation where available, and hardware runs using the same circuit definition and measurement plan. Apply error mitigation only as a documented experiment; it may improve an estimate while also increasing variance or computational overhead. See Quantum Error Mitigation Techniques Explained for the relevant tradeoffs.
When to revisit
Revisit this VQE workflow whenever you change the molecule, geometry, basis, active space, Hamiltonian mapping, ansatz, optimizer, shot budget, simulator, or hardware backend. Those changes can alter both the expected energy and the reliability of the comparison. A result should not be carried forward simply because the code still runs.
For a recurring review, maintain a compact experiment record with:
- Problem definition and Hamiltonian checksum or serialized representation
- SDK and chemistry-integration versions
- Ansatz structure and compiled circuit metrics
- Optimizer configuration and initialization method
- Measurement shots, grouping, seeds, and backend details
- Reference energy, final energy, uncertainty, and repeated-run results
- Known limitations and the next validation step
Start with a simulator baseline, validate the Hamiltonian independently, run multiple optimization starts, and only then test hardware. If the result matters to a larger technical program, preserve the run artifacts so another developer can reproduce the calculation. For platform selection and execution options, consult Quantum Cloud Platforms Explained and compare the workflow against the SDK guidance in Qiskit vs Cirq vs PennyLane.
The practical standard is modest but important: know exactly which problem was solved, which approximations were made, how the energy was measured, and what evidence supports the result. That discipline makes a small VQE experiment useful even when it does not yet provide a production-ready molecular calculation.