-
Notifications
You must be signed in to change notification settings - Fork 632
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
Tutorial example for computing the adjoint gradient of a level set #2792
Conversation
If you are willing to do finite difference, in principle you should be able to skip the subpixel smoothing entirely. You can instead do:
(You need high resolution for φ for finite differences to be accurate, since you can only change h by steps of one pixel in φ, unless you are willing to do your own subpixel averaging.) |
Unfortunately, even using this new approach (downsampling from a grid for the level set The test uses a resolution of 400 pixels/um which is fairly high. It is not obvious why the results for the 1.
2.
Script used to generate these results is in this gist. |
When you carry out the chain rule, you multiply the Meep d/dρ with the level-set dρ/dh derivative. The latter is only nonzero on the boundary pixels. So, if the Meep derivative is inaccurate right on the boundary, that would be exacerbated by this d/dh derivative. My hypothesis at the moment is that the p-polarization Meep derivatives are less accurate at the boundary (due to the the differentiate–then–discretize errors), since the p polarization has a discontinuity at the boundary, compared to the s polarization (which is continuous). To check this, try checking the Meep d/dρ derivatives against finite differences, but instead of using a random perturbation to ρ, do a perturbation right at the the boundary pixels. |
The P polarization Meep derivatives are indeed less accurate at the boundaries compared to the S polarization. To verify this, I used the example of the usual 1D binary grating and added a 2-pixel perturbation for the height (see gist). Results are similar for a 1-pixel height perturbation. As shown in the results below, the error in the directional derivative is small and decreases with resolution for the S polarization but not the P polarization. We can explain this feature in this tutorial. For now, the tutorial is restricted to just the S polarization.
|
…th downsampling from a high-resolution grid
The test failures are due to Autograd's dependence on deprecated Numpy features as reported (and fixed but not yet merged) in HIPS/autograd#618. |
Would be good to check the in-plane polarization for the Maybe there is a bug in what @smartalecH calls the "recombination" step (the overlap between adjoint and forward fields) that is lowering the accuracy. |
@stevengj, this is ready to be merged pending final review. |
Closes #2235.
In order to obtain early feedback, this is the first commit which currently just includes two explanatory figures and an image showing simulation output along with the simulation script in what will eventually become a new tutorial for the adjoint solver. Text and additional results are forthcoming.