Skip to main content

Variational optimization with Haiqu SDK

Use haiqu.variational_optimization() to minimize the expectation value of an observable for a parameterized ansatz circuit.
1

Define the variational problem

VariationalProblem requires a parameterized ansatz circuit and a SparsePauliOp observable.
2

Configure optimizer and submit the job

3

Track progress and fetch results

job.result() returns a VariationalResult with min_loss, optimal_parameters, and loss_history.

API details

The variational optimisation function is defined as:
ArgumentDescription
problemVariationalProblem(ansatz, observable)
device / device_idTarget backend. At least one must be provided.
shotsNumber of shots per circuit evaluation.
seedReproducible random initialization in [-0.1π, 0.1π].
initial_parametersExplicit initial values (length must match ansatz parameters).
optimizer_optionsOptimizer configuration. Either NFTOptimizerOptions(...) (default) or ScipyOptimizerOptions(method=..., maxfev=..., options=...).
use_mitigationEnables mitigation pipeline in backend execution.
use_sessionEnables Qiskit Runtime Session mode.

Optimizer details

haiqu.variational_optimization accepts two optimizer types via optimizer_options: NFTOptimizerOptions (the default) and ScipyOptimizerOptions. Both are gradient-free.

NFT (default)

Haiqu uses the NFT optimizer by default for variational optimization. NFT, short for Nakanishi-Fujii-Todo, is a gradient-free optimizer designed for parameterized quantum circuits. Instead of estimating a full gradient, NFT updates circuit parameters sequentially. For a common class of ansatz circuits, the cost function as a function of one parameter has a simple trigonometric form, so each parameter update can be minimized efficiently from a small number of cost evaluations. This makes NFT a good default choice for noisy variational workloads:
  • It is gradient-free, so it avoids the high measurement cost of full gradient estimation.
  • It is efficient compared with many general-purpose gradient-free optimizers.
  • Recent scaling studies also rank NFT among the more noise-resilient classical optimizers, while showing that stochastic noise can still create serious scalability challenges for large variational optimization problems; see Scalability challenges in variational quantum optimization under stochastic noise.

Requirements and limitations

NFT assumes the variational problem satisfies the following preconditions:
  • Independent parameters: each ansatz parameter should be independent. Reusing the same parameter across multiple rotation gates is not supported by the standard NFT update rule.
  • Supported gate structure: the parameterized circuit should be composed of fixed unitary gates and rotation gates of the form R_j(theta_j) = exp(-i * theta_j * A_j / 2), where A_j^2 = I.
  • Simple expectation-value cost: the objective should be a weighted sum of expectation values, L(theta) = Σ_k w_k <phi_k|U†(theta) H_k U(theta)|phi_k>.
NFT can improve optimizer robustness, but it does not remove the fundamental sampling and noise-scaling challenges of variational quantum algorithms.

Derivative-free scipy methods

For ansatz / problem combinations that violate NFT’s preconditions, or for comparison against established baselines, ScipyOptimizerOptions dispatches to any of four derivative-free scipy.optimize.minimize methods:
  • cobyla: Constrained Optimization BY Linear Approximation. Trust-region method with linear surrogates.
  • nelder-mead: Downhill simplex. No surrogate model; forgiving on noisy or non-smooth objectives but tends to need more evaluations.
  • powell: Direction-set method that minimizes along conjugate directions.
  • cobyqa: COBYLA’s quadratic-approximation successor; usually higher quality per evaluation at modest extra cost.
maxfev is exposed as a typed top-level field (default 200). Everything else flows through the free-form options dict, validated at construction time against a per-method whitelist:
MethodAllowed options keys
cobylarhobeg, catol, disp
nelder-meadxatol, fatol, adaptive, disp
powellxtol, ftol, direc, disp
cobyqarhobeg, final_tr_radius, disp
Example:
Scipy methods can wander after they find a good point, so Haiqu returns the best-so-far parameters tracked across the optimization, not the final scipy iterate.