Quantum Computing Master Course — 151. Hybrid Quantum Classical Loops
Lesson 151: Hybrid Quantum Classical Loops
Smartyfy Quantum Computing Master Course
Objectives and prerequisites
Identify the stages of a variational hybrid algorithm, calculate one simple parameter update, and account for sampling and optimization costs. Prerequisites are parameterized circuits, expectation values, derivatives, and experiment records. Hybrid means that classical and quantum-style computations play different roles in an iterative procedure; it does not by itself establish an advantage over classical methods.
Define the objective before the loop
Choose a parameter vector θ and a circuit U(θ) preparing |ψ(θ)⟩ from a specified initial state. An objective might be E(θ) = ⟨ψ(θ)|H|ψ(θ)⟩ for a Hermitian observable H, or another explicitly defined function of measurement statistics. The parameters, circuit family, observable, and optimization goal together define the problem.
A classical controller proposes parameter values. The preparation stage builds the corresponding state. Measurement circuits estimate the required observables from repeated fresh preparations. Classical postprocessing combines those estimates into an objective and, when needed, a gradient estimate. An optimizer uses that information to select the next values.
The controller receives classical data such as counts and estimates, not a complete unknown statevector extracted from a physical run. A small local simulator can supply exact amplitudes for debugging, but that shortcut is a property of the classical model and must not be included silently in a hardware resource claim.
| Stage | Input | Output |
|---|---|---|
| Prepare | Parameters and circuit template | Repeated state preparations |
| Measure | Observable measurement settings | Classical outcomes or counts |
| Estimate | Counts, coefficients and mapping | Objective and uncertainty |
| Update | Estimates and optimizer state | New parameters or stopping decision |
Worked one-qubit objective
Prepare Ry(θ)|0⟩ and choose H = Z, with eigenvalues +1 on zero and −1 on one. Then E(θ) = cosθ. The goal is to minimize E, whose global minimum is −1 at θ = π modulo 2π. This example is fully solvable classically and is used only to expose the loop’s mechanics.
The exact derivative is E′(θ) = −sinθ. A gradient-descent update with positive step size η is θnew = θ − ηE′(θ) = θ + ηsinθ. Starting at θ = π/3 with η = 0.1 gives θnew ≈ 1.13380009 radians. The objective falls from 0.5 to about 0.423220, so this particular update moves in the intended direction.
Choosing η too large can overshoot or oscillate, and starting at an exact stationary point can produce zero update. At θ = 0, the gradient is zero even though E is maximal. A zero gradient alone therefore does not certify the desired minimum. Initialization and stopping rules matter even in a smooth one-parameter example.
Replace exact expectations with estimates
A Z measurement returns +1 or −1. For the ideal state, its mean is cosθ and its variance is 1 − cos²θ = sin²θ. With N independent shots, the sample mean has variance sin²θ/N. At θ = π/3 and N = 1000, the standard error is √(0.75/1000) ≈ 0.02739.
The optimizer then sees a noisy estimate rather than the exact cosine. A small observed improvement may be consistent with sampling fluctuation. Comparing two independently estimated objectives requires accounting for uncertainty in both; comparing only their point estimates can cause unnecessary or misleading updates.
Hardware noise can also shift the expectation itself. More shots reduce sampling uncertainty around that shifted value, not necessarily around the ideal objective. An optimizer may adapt to some systematic effects, but variational adjustment is not a general error-correction procedure and does not guarantee recovery of the noiseless optimum.
Count circuit evaluations, not only iterations
One optimizer iteration can require many circuit evaluations. An objective expressed as a sum of incompatible observables may need several measurement settings. A gradient procedure may need additional parameter settings. Multiple starting points, line searches, and validation measurements add further cost.
For a declared toy budget of fifty iterations, six circuit settings per iteration, and two thousand shots per setting, the loop uses 50 × 6 × 2000 = 600,000 state preparations and measurements. This excludes any final validation or retries. Saying only fifty iterations hides the main sampling workload.
Wall time also includes state preparation, circuit duration, readout, reset, classical processing, and communication where relevant. Batching independent settings can reduce some overhead, but a dependency between iterations may still require feedback. A simulator’s near-instantaneous exact objective should not be used as a proxy for this full physical loop.
Choose an update rule suited to the evidence
Gradient-based methods use derivatives or derivative estimates. Derivative-free methods choose new points using objective values, local models, or stochastic perturbations. Neither family is universally best. Parameter dimension, objective geometry, noise, evaluation cost, and available gradients determine which approach is useful.
Step size, parameter bounds, periodicity, initialization, and convergence tolerances are part of the algorithm. A circuit angle may be periodic in its observable even when the exact unitary has a different global-phase period. Wrapping angles can simplify a search, but should preserve the intended family and any controlled-operation conventions.
Stopping because consecutive estimates differ by less than a threshold is unsafe if that threshold is far below their sampling uncertainty. A more defensible stopping rule combines a budget, uncertainty-aware progress checks, and a final independent evaluation. It should distinguish convergence of the chosen optimizer from proof of a global optimum.
Validate outcomes and compare baselines
For small problems, compare with exact diagonalization or a direct classical optimization. That reference catches sign, normalization, and measurement-mapping errors and reveals whether the ansatz, the chosen parameterized circuit family, can reach the desired solution. For larger claims, use appropriate classical baselines and include the cost of preparing inputs and extracting useful outputs.
Save the full parameter trajectory, objective estimates, uncertainties, seeds, circuit settings, shot counts, and stopping reason. Reporting only the best observed point can introduce selection bias, especially when many noisy estimates were compared. Re-evaluating the selected point with fresh samples helps separate a genuine improvement from a favorable fluctuation.
A successful hybrid demonstration shows that its specified loop works for its stated problem and resources. It does not establish that every variational family is trainable, that every quantum objective is hard to simulate classically, or that a near-term device has achieved an application advantage.
Four exercises with worked solutions
-
For E(θ) = cosθ, what happens at θ = π under exact gradient descent?
Solution. The derivative is −sinπ = 0, so the update leaves θ unchanged. Here the stationary point is a global minimum with value −1.
-
Find the worst-case standard error of a ±1 mean from 2500 independent shots.
Solution. The single-shot variance is at most one, so standard error is at most 1/√2500 = 0.02.
-
A loop uses eighty iterations, ten settings and five hundred shots per setting. Count shots.
Solution. Multiply 80 × 10 × 500 = 400,000. Add any validation and retry shots separately.
-
Why re-evaluate the best point with fresh samples?
Solution. Selecting the minimum among noisy estimates favors downward fluctuations. Independent evaluation provides less selection-biased evidence about that chosen point’s actual objective.
Five explained multiple-choice questions
-
The classical optimizer normally receives from physical measurements: A. The full complex amplitude vector in one shot. B. Classical outcomes and derived estimates. C. Exact derivatives without additional resources. D. An objective estimate whose uncertainty is determined by iteration count alone.
Answer: B. Measurement data must be processed into objectives and uncertainty-aware decisions.
-
For minimizing cosθ, the exact gradient update is: A. θ minus ηsinθ. B. θ plus ηcosθ. C. θ minus ηcosθ. D. θ plus ηsinθ.
Answer: D. Subtracting the derivative −sinθ yields the stated positive-sine update.
-
Zero gradient at θ = 0 means: A. The point is stationary but is a maximum for this objective. B. The ground state has been found. C. Every finite-shot gradient estimate at that point will also be zero. D. The circuit family cannot change the objective at any other parameter value.
Answer: A. Stationarity alone does not identify the desired optimum.
-
Increasing shots primarily reduces: A. Sampling uncertainty under the assumed repeated-trial model. B. The ansatz’s approximation bias. C. Every hardware-induced bias automatically. D. The number of required parameter settings.
Answer: A. More samples sharpen an estimate of the distribution actually measured.
-
A useful resource count includes: A. Only optimizer iteration number. B. Only the number of free angles. C. Settings, shots, preparation, measurement, feedback and validation costs. D. Only the best point’s final circuit depth.
Answer: C. The complete loop can require many evaluations per iteration and substantial non-gate overhead.
Pitfalls and summary
Define the objective and evidence flow, distinguish statistical from systematic errors, and count the whole loop. Hybrid optimization is a framework whose usefulness depends on the ansatz, estimator, optimizer, and workload rather than the label quantum alone.
Primary sources and further study
These sources support the definitions and context. The numerical examples, exercises, and explanations here were prepared for this lesson. Research papers are optional advanced reading.
- Cerezo and colleagues: Variational Quantum Algorithms
- McClean, Romero, Babbush and Aspuru-Guzik: The theory of variational hybrid quantum-classical algorithms
- Peruzzo and colleagues: A variational eigenvalue solver on a quantum processor
- Schuld and colleagues: Evaluating analytic gradients on quantum hardware