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

adjoint for ldos #2077

Merged
merged 11 commits into from Jun 2, 2022
Merged

adjoint for ldos #2077

merged 11 commits into from Jun 2, 2022

Conversation

mochen4
Copy link
Collaborator

@mochen4 mochen4 commented May 19, 2022

Implements the adjoint for ldos. Closes #2026 and closes #1401.

@mochen4
Copy link
Collaborator Author

mochen4 commented May 19, 2022

Based on my testing so far, the ldos adjoint works for Gaussian sources, but not for EigenModeSource. The following issues are observed:

  1. In 2D, if the polarization of the EigenModeSource is specified to be TM, everything is fine; however, when the polarization is TE, finite different gradients agree with adjoint gradients at some resolutions (e.g. 15 and 25 in my test case), but differ by a factor at other resolutions (factor of ~0.8 at resolution=20, factor of ~0.9 at resolution =30). It does look like increasing resolution will eventually lead to complete agreement.

  2. If the EigenModeSource has mp.ALL_COMPONENT, then the adjoint gradients still differ by some factor from the finite different gradients. Such factor seems to be proportional to 1/resolution^2, but it may have different sign as the resolution changes.

  3. As the case for FourierFields and Near2farFields, the adjoint simulation requires one more sign flip for adjoint electric sources than adjoint magnetic sources. This also seems to be the case for LDOS with single component, but not for mp.ALL_COMPONENT.

@stevengj
Copy link
Collaborator

stevengj commented May 19, 2022

I think the derivative of the work done by an eigenmode source (or any Equivalence Principle) source should be zero (with respect to material perturbations that don't intersect the source plane). So maybe you are just looking at discretization errors (and it's not surprising that they don't agree)?

Would be nice to check this, e.g. compute the power P for different perturbations of the material grid and verify that |δP/P| << 1

src/meep.hpp Outdated Show resolved Hide resolved
@mochen4
Copy link
Collaborator Author

mochen4 commented May 25, 2022

  1. In 2D, if the polarization of the EigenModeSource is specified to be TM, everything is fine; however, when the polarization is TE, finite different gradients agree with adjoint gradients at some resolutions (e.g. 15 and 25 in my test case), but differ by a factor at other resolutions (factor of ~0.8 at resolution=20, factor of ~0.9 at resolution =30). It does look like increasing resolution will eventually lead to complete agreement.

Correction: actually, the gradients are consistent using electric components but not magnetic components, regardless of the polarization.

I think the derivative of the work done by an eigenmode source (or any Equivalence Principle) source should be zero (with respect to material perturbations that don't intersect the source plane). So maybe you are just looking at discretization errors (and it's not surprising that they don't agree)?

Would be nice to check this, e.g. compute the power P for different perturbations of the material grid and verify that |δP/P| << 1

I found that the gradients with EigenModeSource is around the same magnitude as with GaussianSource, and in both cases, gradients get smaller with larger resolutions. Since the gradients with GaussianSource make sense, I think the gradients with EigenmodeSource also needs to make sense.

  1. As the case for FourierFields and Near2farFields, the adjoint simulation requires one more sign flip for adjoint electric sources than adjoint magnetic sources. This also seems to be the case for LDOS with single component, but not for mp.ALL_COMPONENT.

I checked that using mp.ALL_COMPONENTS was indeed the same as using the corresponding individual components together; however, it was not consistent with the running simulations with individual components separately. Specifically, at eig_band = 2, LDOS with mp.Hz alone is 1.705 and with mp.Ey alone is 0.2, but for mp.ALL_COMPONENTS is 0.236.

@smartalecH
Copy link
Collaborator

I found that the gradients with EigenModeSource is around the same magnitude as with GaussianSource, and in both cases, gradients get smaller with larger resolutions. Since the gradients with GaussianSource make sense, I think the gradients with EigenmodeSource also needs to make sense.

By GaussianSource, do you actually mean GaussianBeamSource? Note that the EigenModeSource is a spatial definition, while the GaussianSource is a time profile. As you know, an EigenModeSource can also be defined by a GaussianSource pulse...

@mochen4
Copy link
Collaborator Author

mochen4 commented May 25, 2022

By GaussianSource, do you actually mean GaussianBeamSource? Note that the EigenModeSource is a spatial definition, while the GaussianSource is a time profile. As you know, an EigenModeSource can also be defined by a GaussianSource pulse...

Sorry for the confusion. By GaussianSource I mean a plane wave with Gaussian as the time profile. By EigenModeSource I mean an eigenmode as the space profile and Gaussian as the time profile.

@mochen4 mochen4 marked this pull request as ready for review June 2, 2022 18:48
@smartalecH smartalecH changed the base branch from master to cache_mpb_eps June 2, 2022 19:29
@smartalecH smartalecH changed the base branch from cache_mpb_eps to master June 2, 2022 19:29
@stevengj
Copy link
Collaborator

stevengj commented Jun 2, 2022

Looks good! Just needs some documentation?

@stevengj stevengj merged commit 91d36ba into NanoComp:master Jun 2, 2022
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

Successfully merging this pull request may close these issues.

differentiable dft_ldos objects LDOS adjoint
3 participants