-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nan reverse mode gradient when FourierPlanarCurve
normal
is parallel or anti-parallel to Zaxis
#1456
Comments
More minimal example (the nans going away if coil4 is removed is likely due to the deriv_mode changing) from desc.magnetic_fields import ToroidalMagneticField
from desc.coils import (
FourierPlanarCoil,
)
from desc.objectives import (
BoundaryError,
ObjectiveFunction,
)
from desc.examples import get
from desc.optimize import Optimizer
eq = get("SOLOVEV")
coil1 = FourierPlanarCoil(current=1e5,center=[0,0, 2.4],normal=[0,0,1],r_n=4.5)
field = ToroidalMagneticField(1,1) # no error if a TF is used for field
field = coil1 # error if a single coil is used (or any coilset)
objective = ObjectiveFunction((BoundaryError(eq,field, deriv_mode="rev"), # error only when deriv_mode is rev
))
optimizer = Optimizer("lsq-exact")
(eq_opt,field_opt), out = optimizer.optimize([eq,field],
objective,
constraints=(),
verbose=3,
options={},copy=True,
ftol=1e-4, xtol=1e-6,maxiter=2
) yields nan in optimality, so jacobian of BoundaryError has a nan in reverse mode, but only when a coil is in the field... |
More data: the failure only occurs when there is a So seems to somehow be an issue with the reverse mode gradient going through the rotations etc for FourierPlanarCoil when the normal is in the z axis |
The failure also affects the |
I think its because we measure rotations relative to the Z axis, and when the normal is also along z then Lines 209 to 213 in 273515b
|
|
Ah wait Rory beat me, but why in |
in |
Instead of getting the rotation matrix from axis and angle might be easier just to get it directly from the 2 normals: https://math.stackexchange.com/questions/180418/calculate-rotation-matrix-to-align-vector-a-to-vector-b-in-3d |
FourierPlanarCurve
axis is parallel or anti-parallel to Zaxis
FourierPlanarCurve
axis is parallel or anti-parallel to Zaxis
FourierPlanarCurve
normal
is parallel or anti-parallel to Zaxis
When I design TF and PF coils for the Solovev equilibrium everything works fine but when I add a helical coil to the coilset, I get a nan optimality.
Here's a minimal failing example
The nans go away if you remove coil4 from the coilset.
Another way to fix this(as suggested by @dpanici ) while including the helical coil is to add deriv_mode="fwd" to all the objectives.
What might be the reason for this?
The text was updated successfully, but these errors were encountered: