-
Notifications
You must be signed in to change notification settings - Fork 50
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
Fix gradient magnitude custom medium #2159
Fix gradient magnitude custom medium #2159
Conversation
Thanks for catching this @groberts-flex! I guess I'm a bit confused as to why two integration measures are necessary here (
In fact, maybe we can get rid of most of the logic here by just using xarray's |
Thanks @yaugenst-flex for the comments and suggestions on this! Currently, |
7f4152a
to
ed5bd2e
Compare
updated the way this was done to use the underlying grid from the electric field data for the final dimension if it exists to interpolate and define the correct volume element for |
I think we can go with this fix if the result matches the I'm just wondering whether it wouldn't be simpler if we just removed all of the manual volume element calculations, something like:
Wouldn't this eliminate the need for any special handling? |
This is a good point, but I still need the handling for a dimension of size 0 when I use integrate. Otherwise, that integrate ends up returning a zero array. So I would need to keep the size checking in place, but the nice aspect of this is it doesn't create as large of a In |
Yeah so for now I think doing it based on the electric field data is the right approach. We should however have a look at how the adjoint monitors are created from which that field data is sampled, and ideally the accuracy of this sampling could be a setting in a global configuration (that we'll eventually get to...) where you could set This still needs a changelog entry, otherwise looks good to go :) |
Sounds good, that makes sense! Adding changelog entry, thanks for the reminder on that |
5e1d007
to
e072c80
Compare
…hen permittivity and medium defined over different number of dimensions
e072c80
to
5a4bfdb
Compare
Found while debugging the autograd level set notebook that the gradient magnitudes when using the autograd version vs. the Jax version were off by a couple orders of magnitude (the direction was the same).
CustomMedium
is implemented differently thanJaxCustomMedium
for the case where the gradient is computed with the coordinate array for one of the dimensions fixed. InCustomMedium
, the volume normalization was not taking into account the thickness of the dimension and summing so that each slice in the gradient array were all effectively weighted by 1. The change here is to usemean
instead ofsum
and multiply by missing volume factors.