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

Introducing Adjoint Solver 2.0 #1167

Merged
merged 6 commits into from
Apr 15, 2020
Merged

Introducing Adjoint Solver 2.0 #1167

merged 6 commits into from
Apr 15, 2020

Conversation

smartalecH
Copy link
Collaborator

@smartalecH smartalecH commented Apr 3, 2020

This is an initial stab at the new and improved adjoint solver. This update is meant to enable an adjoint solver that is simple, flexible, and accurate.

Major differences and features from previous version:

  • Support for broadband dispersive materials
  • Calculates gradients for multiple frequency points simultaneously -- even if the objective function has multiple arguments
  • Plug and play support for filters, projections, "robust" implementations, etc.
  • Automated differentiation of objective functions using autograd
  • Accurate gradients rigorously benchmarked against their finite differences
  • Simplified API with minimal code overhead
  • Built-in bilinear interpolation basis

The quickest and easiest way to get up to speed with the new features is to review the accompanying notebooks:

I'm sure several changes will have to be made before merging. Some of those include:

  • Docs
  • Tests
  • Fix interpolation gradient with lots of design parameters per pixel
  • Supply typical filters as built-in functions.
  • Specify a minimum run time, if you need to force it to run longer.
  • Pass an freq array (like other features recently added).
  • Instead of passing a single point to determine when to stop the simulation, look at the objective arguments and/or the Fourier transforms of the fields in the design region.
  • Maybe call the variable design_variables = [...] instead of basis = [...].
  • Would be good to support passing a list of objective functions (all with the same arguments).
  • Add a tutorial that designs a fabricatable structure (using a simple design like the bend)
  • Extend a basic tutorial (like the phase grating) to calculate the sensitivity
  • Simple 3d example

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

You'll be able to see Jupyter notebook diff and discuss changes. Powered by ReviewNB.

@stevengj
Copy link
Collaborator

stevengj commented Apr 3, 2020

The bend optimization results look like they are converging towards:
image

@stevengj
Copy link
Collaborator

stevengj commented Apr 3, 2020

Comments:

  • Supply typical filters as built-in functions.
  • Specify a minimum run time, if you need to force it to run longer.
  • Pass an freq array (like other features recently added).
  • Instead of passing a single point to determine when to stop the simulation, look at the objective arguments and/or the Fourier transforms of the fields in the design region.
  • Maybe call the variable design_variables = [...] instead of basis = [...].

@stevengj
Copy link
Collaborator

stevengj commented Apr 3, 2020

Would be good to support passing a list of objective functions (all with the same arguments). Then you do one forward simulation to get all of the objective functions (at each frequency), but then do a separate adjoint simulation for each objective function.

The reason to do this is to support arbitrary constrained optimization problems. For example, suppose we are maximizing power in mode 1 with a constraint that the power in mode 2 is ≤ 0.1 × (power in mode 1).

(We could still support passing a single objective function as now, as a special case.)

@stevengj
Copy link
Collaborator

stevengj commented Apr 3, 2020

If you plot the gradient of an optimized structure, it should be positive where ε=12 and negative where ε=1 (or vice versa, depending on whether you are maximizing or minimizing), and nearly zero at points where ε takes on intermediate values. (This is just the KKT conditions.)

@smartalecH
Copy link
Collaborator Author

I've made the requested changes but discovered an annoying bug with my interpolator. It seems that if I have far more design parameters than meep pixels in the design region, the gradient doesn't match up with its finite difference approximate.

You can view this effect in this notebook.

Interestingly I can still optimize fairly well (as demonstrated in the filtering example).

@smartalecH
Copy link
Collaborator Author

Tutorials are fixed.

Filtered Waveguide Bend designs a fully binarized, broadband bend with a minimum length scale constraint:

image

with a decent response:

image

I'd say it's ready for merging. I can pull docs and "official" tests together in another PR.

@stevengj stevengj merged commit fc61d28 into NanoComp:master Apr 15, 2020
@smartalecH smartalecH mentioned this pull request Apr 15, 2020
@franklee90
Copy link

Hi, I tried to run the introduction script but got this error:

AttributeError: module 'meep.adjoint' has no attribute 'BilinearInterpolationBasis'

I updated my meep using the simpetus nightly build before trying. Has the adjoint solver 2.0 been included in it?

@stevengj
Copy link
Collaborator

No, it was just merged, so it will take 24 hours or so to appear in the nightly builds.

bencbartlett pushed a commit to bencbartlett/meep that referenced this pull request Sep 9, 2021
* init

* fix notebooks

* Forgot Makefile.am

* more notebooks and updated requested changes

* bug fixes

* tutorials

Co-authored-by: Alec Hammond <[email protected]>
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.

3 participants