-
Notifications
You must be signed in to change notification settings - Fork 640
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
Revamped add fields::dft_fields_norm2 #1740
Conversation
(Also don't forget to squash before merging) |
884bf73
to
64ba078
Compare
64ba078
to
8bb4a6f
Compare
Are you planning to add a unit test for this feature? |
Hi @smartalecH. I considered this approach, but opted for the one in #1718 instead as being more conservative. The basic reason is that the norm of the fields used to update the DFTs (my approach) gives you an upper bound on the change in the norm of the DTFTs (your approach). That is, if I'm not sure what you mean by "aliasing" here, since the norm of the fields works as a bound for all frequencies at once. I don't think computational expense should be a concern, since it should be sufficient to sample the norm of the fields relatively infrequently, e.g. every few optical periods (as measured by (That being said, either approach seems pretty reasonable.) |
Got it. This makes much more sense, thanks!
I was seeing quite a few "false negatives" when using the method in #1718. In fact, I was unable to achieve any sort of convergence -- even with very "fast" sampling (e.g. sub optical period). I tried quite a few "sample rates" but still didn't see any sort of convergence with the adjoint tests. Perhaps there's a small bug (although it looks pretty good to me...)? It's possible that the really small frequencies are taking forever to decay due to issues with PML or other dispersion effects (whereas that isn't a problem with this PR's method, since it's only looking at user-specified frequencies). I'll try your original method again and report the results below. |
The decay rate is calculated every The |
In principle, we should set how often we check this to be |
Since they are performing similarly, maybe we should just do the less conservative approach (your initial approach), and just call it |
Fixed. I added a function,
Fixed. |
I readded the original adjoint solver test file, |
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #1740 +/- ##
==========================================
+ Coverage 74.37% 74.38% +0.01%
==========================================
Files 13 13
Lines 4573 4552 -21
==========================================
- Hits 3401 3386 -15
+ Misses 1172 1166 -6
|
@@ -130,7 +130,7 @@ def __init__( | |||
2)) # index of center frequency | |||
|
|||
self.decay_by = decay_by | |||
self.decay_fields = decay_fields | |||
self.decay_fields = decay_fields # left for legacy, but doesn't do anything |
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.
Probably better to just remove this line here and also from test_adjoint_solver.py
where it is also used?
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.
Fixed.
Should be ready to merge once all tests pass. |
Steven's fixes Co-authored-by: Steven G. Johnson <stevenj@mit.edu>
Finally passing tests and ready to merge |
* squash add fields::dft_fields_norm2 dft_fields_norm, not norm2 add fields::dft_minfreq to extract longest timescale redo l2 norm try rebasing again dft_fields_norm, not norm2 * add functionality for both methods * fix support for both methods and identify good tolerance * remove second function and check for decimation factor * fix tests * fix dependence on sample rate * final changes * whoops * Apply suggestions from code review Steven's fixes Co-authored-by: Steven G. Johnson <stevenj@mit.edu> * fix defualt tolerance Co-authored-by: Steven G. Johnson <stevenj@alum.mit.edu> Co-authored-by: Alec Hammond <ahammond36@gatech.edu> Co-authored-by: Steven G. Johnson <stevenj@mit.edu>
Fixes #1711
Similar to #1718, except it does an L2 norm over the already calculated DFT fields, rather than manually recomputing (a modified version of) them. This means the user doesn't have to run this as often (before you had to "sample" fast enough to prevent aliasing). Plus there are fewer FLOPs with this approach.
I'm sure there's a reason @stevengj didn't do things this way, just not sure what that may be.
It passed the adjoint solver test suite locally. I reran the first tutorial and saw similar relative errors in the gradients as the old method.
We should probably do some profiling to see what convergence thresholds are really needed for "accurate" gradients.