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 is program.best_params. When using program.viz.compute_hessian(), this defaults to best_params if 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_DIFFERENCE uses centered finite differences with step size eps.

  • eps (float) – Finite-difference step size. Only used when gradient_method is GradientMethod.FINITE_DIFFERENCE. Defaults to 1e-3.

  • reporter (ProgressReporter | None) – Optional ProgressReporter.

Returns:

Hessian matrix, eigenvalues (ascending), eigenvectors, and the center point.

Return type:

HessianResult

Raises:
  • TypeError – If program is not a supported variational program.

  • NotImplementedError – If program is an IterativeQAOA instance.

  • ValueError – If center has the wrong shape or eps is non-positive.