Skip to content

FourierPlanarCoil still gives NaN gradient when axis is vertical #2276

Description

@dario-panici

I thought we had fixed this before #1456 but I guess not?

from desc.coils import FourierPlanarCoil
from desc.objectives import ObjectiveFunction, CoilLength
from desc.optimize import Optimizer

coil = FourierPlanarCoil(normal=[0,0,1])
opt = Optimizer("lsq-exact")

obj = ObjectiveFunction(CoilLength(coil))

# Works fine, no Nan
opt.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 vertical
opt.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...

Our current tests dont catch this, if I add

      test([0, 1e-8, 1])  # nearly parallel
      test([0, 1e-8, -1])  # nearly antiparallel

to our test for this, these fail.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions