compute_hessian¶
- compute_hessian(program, center, *, gradient_method=GradientMethod.PARAMETER_SHIFT, eps=0.001, reporter=None)[source]¶
Compute the Hessian matrix at center.
Eigenvalues reveal local curvature; eigenvectors can be used as scan directions via
HessianResult.top_eigenvectors().All evaluations are batched into a single call to
_evaluate_cost_param_sets. The total number of evaluation points is \(2n^2 + 1\) where n is the number of parameters.- Parameters:
program (
_SupportsVizScan) – Variational program whose Hessian is computed.center (
TypeAliasType) – Flat parameter vector at which to evaluate the Hessian. A typical choice isprogram.best_params. When usingprogram.viz.compute_hessian(), this defaults tobest_paramsif omitted.gradient_method (
GradientMethod) – Strategy for computing second derivatives.GradientMethod.PARAMETER_SHIFT(default) uses the double parameter-shift rule (exact for standard quantum gates).GradientMethod.FINITE_DIFFERENCEuses centered finite differences with step size eps.eps (
float) – Finite-difference step size. Only used when gradient_method isGradientMethod.FINITE_DIFFERENCE. Defaults to1e-3.reporter (
ProgressReporter|None) – OptionalProgressReporter.
- Returns:
Hessian matrix, eigenvalues (ascending), eigenvectors, and the center point.
- Return type:
- Raises:
TypeError – If
programis not a supported variational program.NotImplementedError – If
programis anIterativeQAOAinstance.ValueError – If
centerhas the wrong shape orepsis non-positive.