Automatic differentiation¶
Implicit pole derivative¶
For a simple non-Hermitian pole
differentiation with respect to parameter \(\theta_j\) gives
No derivative of the arbitrarily normalized eigenvector is required for the pole. The denominator is also the QNM residue normalization; a small magnitude warns of ill-conditioning or a multiple pole.
With \(\tilde\omega=a+ib\), \(b<0\),
Geometry derivatives¶
Current nanobeam kernels differentiate exact Fourier/Galerkin projections of translated elliptical holes. A Jacobian-vector product differentiates the operator action; a vector-Jacobian contraction computes all geometry coordinates without materializing a dense operator Jacobian. Layer thickness and beam width modify the layered cross-section operator and use separately contracted fixed-pole differences in the legacy implementation.
“Automatic differentiation” here means that the end-to-end objective exposes a programmatic derivative. Individual kernels may use analytic partials, JVPs, VJPs, implicit differentiation, or carefully isolated finite differences. Every approximation must be named in the recipe and gradient audit.
cavitygrad.autodiff.autograd_primitive is the adapter used by Design 23. A
value-and-adjoint-gradient callback becomes an opaque primitive with a
registered reverse-mode VJP, so ordinary autograd.grad composition works
without replaying or differentiating through nonlinear pole iterations. The
forward value/VJP pair is cached for a differentiated input to avoid paying for
the eigensolve twice during backpropagation.
Observable derivatives¶
Mode volume and guided coupling depend on both pole and eigenvectors. Their total derivatives require the linearized QNM state or an adjoint solve plus explicit point/port-map derivatives. Secant models can be used experimentally, but must not be described as exact gradients and must remain inside a guarded trust region.
Gradient audit¶
For a normalized random direction \(p\), compare
over a logarithmic sweep of \(h\). The error should decrease quadratically before cancellation dominates. Repeat for representative individual gaps, radii, cross-section parameters, and the full objective. Each perturbed solve must re-track the same branch.