qiskit-optimizers
Table of Contents
Optimizers
Optimizers are classical algorithms that train ansatz parameters in variational algorithms. Given a cost function $f(\theta)$, an optimizer iteratively updates $\theta$ to minimize $f$. Qiskit provides gradient-free and gradient-based optimizers.
Gradient-Free Optimizers
- COBYLA (Constrained Optimization By Linear Approximation): robust, handles non-smooth landscapes, no gradient required
- Nelder-Mead: simplex method, good for small problems
- Powell: derivative-free, good convergence
Gradient-free optimizers are noisy-friendly: they work well when cost function evaluations are noisy (as on real quantum hardware).
from qiskit.optimizers import COBYLA def cost_function(params): # Evaluate circuit, measure cost, return return ... optimizer = COBYLA(maxiter=100, rhobeg=1.0) result = optimizer.minimize(cost_function, x0=initial_params) print(result.fun) # Optimal cost print(result.x) # Optimal parameters
Gradient-Based Optimizers
- SLSQP (Sequential Least Squares Programming): uses numerical gradients, fast on simulators
- L-BFGS-B: quasi-Newton method, fewer iterations but slower per iteration
These require computing or estimating gradients, which is more expensive but can converge faster on smooth landscapes.
from qiskit.optimizers import SLSQP def cost_with_gradients(params): cost = cost_function(params) gradient = estimate_gradient(params, cost_function) return cost, gradient optimizer = SLSQP(maxiter=100) result = optimizer.minimize(cost_with_gradients, x0=initial_params)
Hybrid Approaches
Modern variational algorithms combine multiple optimizers: rough search with COBYLA, then fine-tuning with SLSQP.
For noisy hardware, gradient-free methods often work better because gradients are more sensitive to noise than function values.
qiskit-optimizers.md · Last modified: by 127.0.0.1
