-
Notifications
You must be signed in to change notification settings - Fork 59
feat[adjoint]: Add conductivity gradient for CustomMedium
#2582
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
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 files reviewed, 2 comments
Edit PR Review Bot Settings | Greptile
Diff CoverageDiff: origin/develop...HEAD, staged and unstaged changes
Summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
1 file reviewed, no comments
Edit PR Review Bot Settings | Greptile
1b5e0be
to
00cce22
Compare
Introduces support for computing gradients with respect to the `conductivity` field in `CustomMedium`. To achieve this, the derivative computation logic was generalized: - The `_derivative_field_cmp` method is refactored to accept a `component` parameter ('real', 'imag', 'complex') to compute the VJP for different parts of the complex permittivity. - For the 'imag' component, the derivative is scaled by `1 / (omega * epsilon_0)` to convert from derivative w.r.t. complex permittivity to derivative w.r.t. conductivity. - The `_compute_derivatives` dispatcher now handles the new `"conductivity"` parameter path. - A new autograd test is added to validate the conductivity gradient calculation on a `CustomMedium` with constant permittivity.
20bc219
to
7e50b67
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
a really minor comment is that I notice that we sum("f")
the E_der_dim_interp
in each of the handlings of component
. could be slightly more robust if w just sum that after constructing E_der_dim_interp
.
good point, fixed |
monitor, postprocess = make_monitors()["field_point"] | ||
|
||
def objective(params): | ||
"""Objective function testing only gonductivity gradient (constant permittivity).""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gonductivity -> conductivity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good! not sure this would be in the scope of the PR or not but would love to have a numerical test for conductivity as well. I'm happy to take this on at some point, think I could modify the field and/or mode numerical tests we have to check conductivity (right now, they use custom medium for permittivity, but should be quick change to also test conductivity.
Summary
This PR introduces the capability to compute gradients with respect to the
conductivity
of aCustomMedium
.Implementation Details
_derivative_field_cmp
helper method with a newcomponent
parameter that can be set to'real'
,'imag'
, or'complex'
.component='imag'
) by scaling the imaginary part of the complex permittivity derivative by1 / (omega * epsilon_0)
._compute_derivatives
dispatcher to handle the new"conductivity"
parameter path and invoke the generalized helper method.test_custom_medium_conductivity_only_gradient
to validate the gradient calculation for aCustomMedium
with variable conductivity and constant permittivity.custom_med_with_conductivity
, that contains both variable permittivity and conductivity.Greptile Summary
Implements conductivity gradient calculations for
CustomMedium
by extending the permittivity gradient framework to handle real, imaginary, and complex components, enabling material conductivity optimization.component
parameter to_derivative_field_cmp
to support 'real', 'imag', and 'complex' gradient types1/(omega * epsilon_0)
custom_med_with_conductivity
to validate combined permittivity and conductivity gradientstest_autograd.py
to improve maintainability with shared coordinate dictionaries