Skip to content

Automatic differentiation with respect to variables that appear in conditionals #9

Description

@jadonylin

When using automatic differentiation, there is a subtle issue with automatically differentiating objective functions with respect to a variable which appears in conditional expressions.

For example, differentiating an objective function |Ey|(z) which calculates the y-component of the electric field as a function of z-position for a fixed simulation (layers, lattice, permittivity, etc.). At the z values of the layer boundaries, the derivative might not be well-defined due to inkstone conditionally selecting the right-most (larger z) layer as the layer in which the boundary z belongs. Since autodiff libraries don't know about the control flow (they only trace inside the if statements), they will still output a gradient without throwing errors, even though the gradient is ill-defined. Away from the layer boundaries, autodiff can differentiate through the control flow and the z-derivatives are consistent with finite difference.

To fix, some smoothing function could be used instead of the z-value-layer check in GetFieldsListPoints.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions