This variational quantum eigensolver tutorial shows how to build a small VQE experiment, tune its moving parts, and decide whether the result is meaningful. You will define a Hamiltonian, choose an ansatz, initialize parameters, run a classical optimizer, measure expectation values, check convergence, and compare the final energy with an exact classical calculation.
Overview
A variational quantum eigensolver is a hybrid quantum-classical algorithm for estimating the lowest eigenvalue of a Hamiltonian. In a chemistry setting, that value is often interpreted as an estimate of a molecule's ground-state energy after the physical problem has been mapped to qubits. More generally, VQE can optimize the lowest-energy state of any operator that can be expressed as a weighted sum of measurable Pauli terms.
The workflow is iterative. A parameterized quantum circuit, or ansatz, prepares a trial state |ψ(θ)⟩. The quantum processor or simulator estimates the objective function:
E(θ) = ⟨ψ(θ)|H|ψ(θ)⟩
A classical optimizer updates θ to reduce E. The loop continues until the energy stops improving, the parameter updates become small, or a predefined evaluation budget is reached. VQE does not automatically produce a useful answer: a low-looking number may result from a sign error, an incomplete Hamiltonian, insufficient sampling, optimizer instability, or a circuit that cannot represent the target state.
For a first experiment, use a small Hamiltonian with a known exact solution. A two-qubit operator such as:
H = c0I + c1Z0 + c2Z1 + c3Z0Z1 + c4X0X1
is enough to test the complete loop. The coefficients can be chosen for a controlled demonstration, but your experiment record should state exactly how they were obtained. For a chemistry application, document the basis, mapping, active space, geometry, and any reductions before interpreting the energy.
Checklist by scenario
Scenario 1: Validate the algorithm on a simulator
- Define the operator. Store each Pauli term, coefficient, and qubit index explicitly. Confirm that identity terms and signs are preserved.
- Build a reference state. Start with a simple computational-basis state or a problem-informed initial state. Record the preparation circuit separately from the trainable ansatz.
- Select a compact ansatz. A hardware-efficient circuit with alternating single-qubit rotations and entangling gates is easy to test. Keep depth modest at first.
- Initialize parameters. Try small random values, zeros where the circuit permits them, and a few fixed seeds. One favorable run is not enough evidence.
- Implement the objective. For every Pauli term, estimate its expectation value and multiply it by its coefficient. Sum all contributions, including the constant term.
- Run the optimizer. Pass the objective function and parameter vector to a classical optimizer. Save the energy after every evaluation, not only the final value.
- Compare with an exact result. Diagonalize the same finite-dimensional Hamiltonian classically and compare its lowest eigenvalue with the optimized VQE energy.
A useful simulator-first test uses exact expectation values or a statevector when available. Then repeat the experiment with finite shots. The first run checks circuit and Hamiltonian logic; the second reveals sampling variance and the practical behavior of the optimizer.
Scenario 2: Move from a simulator to hardware
- Transpile or compile the circuit for the selected device and record the resulting depth, gate set, and qubit layout.
- Measure each Hamiltonian term using the backend's supported measurement workflow. Grouping compatible terms can reduce executions, but validate that the grouping implementation preserves the objective.
- Use a fixed shot count and record it with every run. Shot noise changes the objective between evaluations, which can confuse optimizers that expect smooth values.
- Run simple calibration or reference circuits where appropriate. These help separate an algorithmic problem from readout or gate errors.
- Repeat the optimization with several seeds and report a distribution of final energies rather than presenting one run as definitive.
Before choosing a backend, review the quantum cloud backend selection guide. Use the quantum circuit debugging checklist when transpilation increases depth or measurements behave unexpectedly.
Scenario 3: Test a chemistry Hamiltonian
Separate the chemistry-to-qubit conversion from the VQE loop. First verify that the mapped Hamiltonian is Hermitian, that the qubit count is expected, and that symmetries or reductions have been applied consistently. Then test the optimizer on the mapped operator before adding hardware noise. A chemistry result should be compared with an exact diagonalization of the same reduced Hamiltonian, not with a value produced by a different basis or approximation.
What to double-check
| Area | Check | Why it matters |
|---|---|---|
| Hamiltonian | Terms, coefficients, signs, qubit ordering, and identity contribution | A single indexing or sign error changes the objective being optimized. |
| Ansatz | Expressibility, parameter count, entanglement pattern, and circuit depth | An overly small ansatz may miss the ground state; an oversized one may be hard to optimize. |
| Initialization | Several seeds, parameter scales, and the starting energy | VQE can be sensitive to local minima and flat regions. |
| Measurements | Basis rotations, shot count, term grouping, and expectation-value convention | Measurement mistakes can look like optimizer failure. |
| Optimization | Stopping rule, evaluation budget, step size, and noisy-objective tolerance | A converged parameter trace is not necessarily a converged physical answer. |
| Validation | Exact eigenvalue, energy gap, variance, and repeated trials | Independent checks show whether the output is plausible and reproducible. |
Track both energy and energy variance when your framework supports it. For a normalized state, a small variance, ⟨H²⟩ − ⟨H⟩², indicates that the state is close to an eigenstate. It does not by itself prove that the state is the ground state, so retain the exact minimum or another trusted reference for comparison.
Record each experiment using a compact template: date, SDK and version, Hamiltonian source, qubit mapping, ansatz description, parameter count, initial state, optimizer and settings, backend, shots, random seed, final energy, exact reference, variance, number of evaluations, and notes about noise mitigation. This makes results comparable after a framework or backend change.
Common mistakes
- Dropping the constant term: Identity coefficients shift the reported energy. Omitting one can make an otherwise correct optimization appear wrong.
- Comparing incompatible references: A VQE result for a reduced Hamiltonian should not be compared with an unreduced or differently mapped calculation.
- Using a single optimizer run: Random initialization and noisy measurements can produce different outcomes. Use repeated seeds and preserve the traces.
- Making the circuit deeper too soon: Add layers only when a simpler ansatz demonstrably cannot reach the reference. Depth increases simulation and hardware costs and may amplify noise.
- Assuming a flat trace means success: The optimizer may be stuck, the gradient may be uninformative, or parameter updates may be too small. Inspect gradients, parameter movement, and the objective scale.
- Ignoring measurement variance: A small energy difference may be smaller than the uncertainty from finite shots. Repeat measurements and report uncertainty or variability where possible.
- Changing several variables at once: Do not simultaneously replace the ansatz, optimizer, backend, and Hamiltonian. Change one factor, rerun the baseline, and keep an experiment log.
For broader hybrid experiments, use the hybrid AI-quantum workflow guide to structure a classical baseline. The same principle applies to VQE: establish a trusted reference before claiming that a quantum workflow improves the result.
When to revisit
Revisit this VQE checklist before each new experiment cycle and whenever a workflow or tool changes. SDK releases may alter circuit-construction, estimator, optimizer, or backend interfaces. A simulator update can also change defaults for precision, shots, transpilation, or execution. Re-run a small regression case with a known Hamiltonian after such changes.
Return to the checklist when you switch from exact simulation to shot-based simulation, move to hardware, introduce error mitigation, change the ansatz, or replace the optimizer. Recheck the Hamiltonian whenever the molecular geometry, basis, active space, qubit mapping, or symmetry reduction changes. If the result is intended for a paper, internal report, or production decision, repeat the experiment with fixed seeds, multiple seeds, and an independently calculated reference.
Practical next step: create a two-qubit regression notebook with one explicit Hamiltonian, one shallow ansatz, one exact diagonalization routine, and a saved energy trace. Verify the objective term by term, run several initializations, then repeat with finite shots. Only after those checks pass should you add chemistry-specific transformations, deeper circuits, hardware execution, or error mitigation. That sequence turns a VQE demonstration into a reproducible quantum algorithm experiment.