Skip to content
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

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

Open
jadonylin opened this issue Jul 1, 2024 · 0 comments

Comments

@jadonylin
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant