cashocs.verification.control_gradient_test#

cashocs.verification.control_gradient_test(ocp: optimal_control.OptimalControlProblem, u: list[fenics.Function] | None = None, h: list[fenics.Function] | None = None, rng: np.random.RandomState | None = None) float[source]#

Performs a Taylor test to verify that the computed gradient is correct.

Parameters:
  • ocp (optimal_control.OptimalControlProblem) – The underlying optimal control problem, for which the gradient of the reduced cost function shall be verified.

  • u (list[fenics.Function] | None) – The point, at which the gradient shall be verified. If this is None, then the current controls of the optimization problem are used. Default is None.

  • h (list[fenics.Function] | None) – The direction(s) for the directional (Gâteaux) derivative. If this is None, one random direction is chosen. Default is None.

  • rng (np.random.RandomState | None) – A numpy random state for calculating a random direction

Returns:

The convergence order from the Taylor test. If this is (approximately) 2 or larger, everything works as expected.

Return type:

float