You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ForwardDiff gives wrong derivatives for rays on the optical axis #147
Derivatives through solve_system! with ForwardDiff agree with finite differences for rays off the axis, but are wrong for rays exactly on the axis, without a warning. Example: the derivative of the spot position behind a component w.r.t. a lateral shift of the component, ray on the axis:
component
ForwardDiff
finite difference
bi-convex SphericalLens
0.0
1.90
bi-concave SphericalLens
−0.97
−1.98
meniscus SphericalLens
−0.96
0.73
ParabolicMirror, ConicMirror
NaN
finite
Rays on the axis, e.g. the chief ray of a rotationally symmetric system, are the ones an optimizer typically differentiates.
Causes (all where the derivative of a normal is taken, i.e. in nested AD)
The radius of revolution norm(Point2(x, z)) evaluates to NaN on the axis in nested AD. This flips comparisons between SDF branches, and the derivative of the radius is not defined there.
The vertex of a concave surface touches the face of the lens body. Both are equally close, and the union took the flat face, which has no curvature.
A hit of _raymarch_outside may end slightly inside the shape, where the gradient of a composite SDF belongs to another part.
refractive_index(optic, λ) returned Float64, which drops derivatives w.r.t. a refractive index or the wavelength.
Activity