GithubHelp home page GithubHelp logo

smartalech / meep_adjoint_simple Goto Github PK

View Code? Open in Web Editor NEW
6.0 6.0 4.0 1.34 MB

Simple adjoint variable method for meep that works out of the box.

License: GNU General Public License v2.0

Python 99.23% Shell 0.77%

meep_adjoint_simple's People

Contributors

homerreid avatar smartalech avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

meep_adjoint_simple's Issues

Correct adjoint scaling factors

This is a simplified version of Homer's adjoint variable method. Homer's current version has several great features, but the core functionality still seems slightly buggy. Specifically, the adjoint gradients don't match the finite difference approximates. I've stripped the extra features, and am focusing on objective functions that only have eigenmode coefficient features (q). A test script for the current version is examples/check_gradients.py, which simulates a simple waveguide crossing with the following geometry:

design_region

The design region is the center square (with both blue and green hashes). It's parameterized using a first-degree continuous Galerkin finite element basis (implemented in fenics). It uses just two triangles, which corresponds to just 4 nodes/design variables. This makes calculating the finite-difference gradient relatively easy (compared to having hundreds of partials to choose from).

There is an eigenmode source (red line) and various eigenmode monitors to optimize over. The script currently optimizes abs(P1_north)**2 where P1_north corresponds to the forward propagating mode coefficient from the north monitor.

Unfortunately, the adjoint gradient still doesn't match the finite difference approximate. I'm assuming the issue has to do with the source/fields scaling.

I've slightly modified Homer's implementation. The resulting procedure is as follows:

  1. Differentiate the objective function (still using sympy) with respect to each mode monitor of interest (i.e. find ∂J/∂q).
  2. Run the forward simulation using an eigenmode source.
  3. Calculate the eigenmode coefficients at the mode monitors and record fields in design region (E_x_forward, E_y_forward, E_z_forward).
  4. Plug mode coefficients into the differentiated objective function to evaluate ∂J/∂q with correct values.
  5. Place eigenmode sources at appropriate monitors. Scale amplitude of each source.
  6. Run adjoint simulation and record fields in design region (E_x_adjoint, E_y_adjoint, E_z_adjoint).
  7. Calculate ∂J/∂ϵ with Re{ΣE_i_forward * E_i_adjoint} summing over x,y,z components. "*" is elementwise product.
  8. Project ∂J/∂ϵ onto p to get ∂J/∂p (seems like there should also be a partial ∂ϵ/∂p somewhere in here...?)

I think the issue is with the scaling of the adjoint sources (or fields, depending on which you want to do). I'm scaling the adjoint source with the following:

scale factor = - ∂J/∂q / (2.0*ω). (from Homer's code)

where ω is meep's ω (i.e. no 2π).

Potential values that need correction/normalization:

  • eigenmode coefficients (correct for power scaling?)
  • forward eigenmode source amplitude (normalize out default amplitude?)
  • adjoint eigenmode source amplitude (normalize out default amplitude?)
  • other normalization terms?

Any ideas?

@oskooi @stevengj @HomerReid @danielwboyce

2D convolution with user_function

A common task with practical inverse design is to "filter" the design region with a gaussian kernel so that the resulting geometry is smoothed. This is one of many ways to implement a minimum feature size constraint.

Accomplishing this with meep's user interface seems tricky. While material functions make it easy to "continuously" modify the permittivity profile of a geometry with position, it only accesses one point at a time. Consequently, functions like filters (or any other integrating function) can't be used because they require feedback/feedforward terms.

One solution could leverage a special material function that provides the user with an array of all the points it plans to fill. The user can then supply an array with the post-processed values corresponding to these points. This is similar to the user_file feature, but without the interpolation (which would defeat the whole purpose). Maybe there's an easy fix that I'm missing?

@oskooi @stevengj @HomerReid @danielwboyce

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.