tlm_adjoint.cached_hessian

Module Contents

class tlm_adjoint.cached_hessian.CachedHessian(J, *, manager=None, cache_adjoint=True)

Represents a Hessian associated with a given forward. Uses a cached forward calculation.

Parameters:
  • J – A variable defining the Hessian.

  • manager – The EquationManager used to record the forward. This must have used ‘memory’ checkpointing with automatic dropping of variable references disabled. manager() is used if not supplied.

  • cache_adjoint – Whether to cache the first order adjoint calculation.

compute_gradient(M, M0=None)

Compute the (conjugate of the) derivative of a functional with respect to a control using an adjoint.

Parameters:
  • M – A variable or a Sequence of variables defining the control.

  • M0 – A variable or a Sequence of variables defining the control value. M is used if not supplied.

Returns:

The (conjugate of the) derivative. A variable or Sequence of variables, depending on the type of M.

action(M, dM, M0=None)

Compute (the conjugate of) a Hessian action on some \(\zeta\) using an adjoint of a tangent-linear. i.e. considering derivatives to be row vectors, compute

\[\left( \frac{d}{dm} \left[ \frac{d \mathcal{J}}{d m} \zeta \right] \right)^{*,T}.\]
Parameters:
  • M – A variable or a Sequence of variables defining the control.

  • dM – A variable or a Sequence of variables defining \(\zeta\). The (conjugate of the) Hessian action on \(\zeta\) is computed.

  • M0 – A variable or a Sequence of variables defining the control value. M is used if not supplied.

Returns:

A tuple (J, dJ, ddJ). J is the value of the functional. dJ is the value of \(\left( d \mathcal{J} / d m \right) \zeta\). ddJ stores the (conjugate of the) result of the Hessian action on \(\zeta\), and is a variable or a Sequence of variables depending on the type of M.

class tlm_adjoint.cached_hessian.CachedGaussNewton(X, R_inv_action, B_inv_action=None, *, manager=None)

Represents a Gauss-Newton approximation to a Hessian associated with a given forward. Uses a cached forward calculation.

Parameters:
  • X – A variable or a Sequence of variables defining the state.

  • R_inv_action – See GaussNewton.

  • B_inv_action – See GaussNewton.

  • manager – The EquationManager used to record the forward. This must have used ‘memory’ checkpointing with automatic dropping of variable references disabled. manager() is used if not supplied.

action(M, dM, M0=None)

Compute (the conjugate of) a Hessian action on some \(\zeta\), using the Gauss-Newton approximation for the Hessian. i.e. compute

\[\left( H \zeta \right)^{*,T}.\]
Parameters:
  • M – A variable or a Sequence of variables defining the control.

  • dM – A variable or a Sequence of variables defining \(\zeta\). The (conjugate of the) approximated Hessian action on \(\zeta\) is computed.

  • M0 – A variable or a Sequence of variables defining the control value. M is used if not supplied.

Returns:

The (conjugate of the) result of the approximated Hessian action on \(\zeta\). A variable or a Sequence of variables depending on the type of M.