Variational optimization with Haiqu SDK
Usehaiqu.variational_optimization() to minimize the expectation value of an observable for a parameterized ansatz circuit.
Define the variational problem
VariationalProblem requires a parameterized ansatz circuit and a SparsePauliOp observable.API details
The variational optimisation function is defined as:| Argument | Description |
|---|---|
problem | VariationalProblem(ansatz, observable) |
device / device_id | Target backend. At least one must be provided. |
shots | Number of shots per circuit evaluation. |
seed | Reproducible random initialization in [-0.1π, 0.1π]. |
initial_parameters | Explicit initial values (length must match ansatz parameters). |
optimizer_options | Optimizer configuration. Either NFTOptimizerOptions(...) (default) or ScipyOptimizerOptions(method=..., maxiter=..., options=...). |
use_mitigation | Enables mitigation pipeline in backend execution. |
use_session | Enables 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), whereA_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.
maxiter is exposed as a typed top-level field (default 500). Everything else flows through the free-form options dict, validated at construction time against a per-method whitelist:
| Method | Allowed options keys |
|---|---|
cobyla | rhobeg, catol, disp |
nelder-mead | xatol, fatol, adaptive, maxfev, disp |
powell | xtol, ftol, maxfev, direc, disp |
cobyqa | rhobeg, final_tr_radius, disp |
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.