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
FourierPlanarCoil still gives NaN gradient when axis is vertical #2276
I thought we had fixed this before #1456 but I guess not?
fromdesc.coilsimportFourierPlanarCoilfromdesc.objectivesimportObjectiveFunction, CoilLengthfromdesc.optimizeimportOptimizercoil=FourierPlanarCoil(normal=[0,0,1])
opt=Optimizer("lsq-exact")
obj=ObjectiveFunction(CoilLength(coil))
# Works fine, no Nanopt.optimize(coil,objective=obj,verbose=3,maxiter=2);
coil=FourierPlanarCoil(normal=[1e-18,1e-18,1])
opt=Optimizer("lsq-exact")
obj=ObjectiveFunction(CoilLength(coil))
# Nan Optimality when normal is close but not quite verticalopt.optimize(coil,objective=obj,verbose=3,maxiter=2);
No NaN in forward mode
No NaN if the normal is [2e-8, 2e-8, 1], but NaN when the first two components are anything less than 2e-8
points to handling of the allclose here which depends on the dotproduct I guess? though these are not aligned with negative Z axis...
I think this is due to round-off error during dot product. For [0, 1e-8, 1], dot product becomes 1*1 + 1e-8*1e-8= 1 + 1e-16 and this is rounded to simply 1 (due to float64). Maybe we can prune the very small terms from the dot product before actually computing it?
Activity
YigitElma commentedon Jul 29, 2026
I think this is due to round-off error during dot product. For
[0, 1e-8, 1], dot product becomes1*1 + 1e-8*1e-8= 1 + 1e-16and this is rounded to simply 1 (due to float64). Maybe we can prune the very small terms from the dot product before actually computing it?Fix for NaN in reverse mode gradient of FourierPlanarCoil and Hessian…