Adjoint gradients are easy to get subtly wrong (signs, factors of 2, boundary terms, projections). The standard check is the Taylor test.

Pick a point and a random direction , ideally smooth and in the correct space. For a decreasing sequence compute

  • : convergence rate 1.
  • if and only if the gradient is correct: convergence rate 2, observed as .

A wrong gradient gives rate 1 for . Too small gives round-off plateaus, and inexact solves give a noise floor, so linear solves must be tight during the test.

Further checks:

  • Central differences in a few coordinates: .
  • Dot-product test for linearised operators: to machine precision.
  • Symmetry of the boundary operator: the computed NtD matrix should be symmetric up to solver tolerance (see Properties of the Boundary Operators).

References

  1. P. E. Farrell, D. A. Ham, S. W. Funke, M. E. Rognes (2013). Automated Derivation of the Adjoint of High-Level Transient Finite Element Programs. SIAM J. Sci. Comput. 35(4), C369–C393. doi:10.1137/120873558
  2. A. Griewank, A. Walther (2008). Evaluating Derivatives, 2nd ed. SIAM. doi:10.1137/1.9780898717761