-
Notifications
You must be signed in to change notification settings - Fork 633
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
Unit test for constraint functions of a periodic design region #2497
Comments
The argument |
In addition, in Case 2, under periodic boundary conditions, the pattern is repeated quadrants instead of repeated discs. To make repeated discs, we need to add three quadrants at the other three corners. |
Good catch. I added the However, even with these changes, the Case 2 results do not match Case 1 (which are unaffected by these changes). Case 2: circle crosses the edge of the design region
|
We need to make more revisions on the test code:
|
Applying fixes (1) and (2) seems to finally produce the expected agreement for Case 1 and 2. Fix 3 is not necessary because the results for Case 1 and Case 2 (second check in which the constraint is violated) converge to the same value with resolution: a log-log plot of the relative error in the constraint-function value (for which Case 1 is the reference result) vs. resolution shows linear convergence. I think these results would be useful as an additional unit test which will be added shortly. resolution = 100 Case 1
Case 2
resolution = 200 Case 1
Case 2
resolution = 400 Case 1
Case 2
|
Maybe plot the constraint function as a function of the lengthscale constraint L — it should become > 0 for L > 1. (For L < 1, the current algorithm should give something ≈ 0.) Should also be pretty easy to go back to old versions and see whether it changed, since it doesn't require any optimization etc. |
The constraint functions meep/python/adjoint/filters.py Lines 870 to 893 in 79e8d17
This meep/python/adjoint/filters.py Lines 918 to 934 in 79e8d17
@smartalecH: is |
Yes. |
Thanks for clarifying. In my test (results to be posted shortly), |
IIRC it should absolutely have an impact. It scales the numerical spatial gradient within the indicator function. Not including it is analogous to scaling |
Here is a plot of the constraint function (
Note, however, that it seems that as The test used to generated these results is available here. |
Ya this doesn't look good. Can you take a few cases where the constraint should obviously be failing (and it's not) and plot
|
Here are plots of (1) the original design weights, (2) projected field ( The plot of (2) and (3) shows that the circle has a diameter which is clearly smaller than (1). |
Ok there are multiple issues with the test you proposed. But here's what's killing things: you are trying to place a lengthscale on the latent field, and ignoring what the projected field looks like. In reality, you need to place a lengthscale on the projected field. Which means you need to figure out what the latent field for a particular Let's look at example, in particular, the extreme case when The maximum value is 0.15, well below Wow, The indicator function is practically 0 everywhere (which means the constraint function should be 0). So. If we instead determine what the latent field is supposed to look like (doing a mini optimization problem) we can get much better results: Where we can start to see the constraint increasing around How does the We see that the exponential is "steeper". It looks like the curve doesn't start increasing until 1.25 now... but in reality it's hard to tell in linear scale. So in log scale: We see that the threshold point (at Ideally we would use plots like this to determine what our threshold should be.* The plot is good for all optimizations for the given resolution, minimum length scale, and Here's some other things I noticed:
|
Thanks for the detailed analysis. However, even with these modifications, the constraint function value does not produce the expected behavior. In your plot of the constraint function value vs.
However, this does not seem to be practical for typical applications where essentially nothing is known about the design weights a priori. What we would like is for the constraint function to change discontinuously at the minimum lengthscale. This does not seem to be possible with our existing approach, unfortunately.
These values for the hyperparameters are from the tutorial Broadband Waveguide Mode Converter with Minimum Feature Size: meep/python/examples/adjoint_optimization/mode_converter.py Lines 273 to 274 in b3f42f2
The values were obtained through some experimentation and introduced in NanoComp/photonics-opt-testbed#32 (comment) because they seemed to produce decent results. |
Not true. Please look again at the log plot, posted again below for convenience.
Yes, this is always the case for constraint functions susceptible to numerical noise (and numerical solvers in general!)
... but it doesn't depend on the weights themselves. As I said earlier, it depends on the minimum length scale and resolution, and
Wrong for two reasons. For one, we do have that. And, that's not ideal. Ideally, we'd have something with a continuous derivative (and a continuous second derivative etc) so that the optimizer can more easily traverse (or in the case of ccsa, approximate it with an expansion).
Again, they seem too high (even if they heuristically worked for one problem). I would go back to the original paper. Things break down quickly when |
@oskooi just to add a bit more signal to the discussion, I decided to run a different test. The current test keeps the (projected) geometry fixed, and sweeps the lengthscale constraint. This isn't what the optimizer does, of course. In reality, we want to keep the lengthscale constraint fixed, and sweep the geometry size (the diameter in this case). So I modified the above, fixing the linewidth constraint to Again we see that discontinuity that you were looking for (although, remember, that's not necessarily a good thing... it depends on the optimizer and where it's at). We see different thresholds for each But again, these thresholds shouldn't depend on the densities. |
As commented above and in #2517, the lengthscale constraints need to (a) be applied to filtered/projected densities and (b) must be calibrated for a particular filter radius. To calibrate it, you could calibrate it on a disc. Then, as a test case we could use the same constraint on a different shape with a known lengthscale (e.g. stripes or annuli). |
#2465 added support for periodic design regions to the filters used in the adjoint solver. To verify that this feature is working correctly, a possible test that we discussed involves evaluating the constraint function for the solid and void features of the design weights and checking that the results are unchanged whether or not a feature with known lengthscale (i.e., a circle with a given diameter) crosses the edge of the design region. (The test in #2465 used a design region with random weights which may not be appropriate since it can contain multiple features with the same lengthscale.)
The test described above is set up in this gist. However, the results of this test are different for the two cases which seems to suggest that #2465 is not working correctly.
Case 1: circle does not cross the edge of the design region
For this test, we conduct two checks:
The results from this test match the expected values:
Also, note that the value of the constraint function for the solid and void regions is identical (as expected based on the single test feature of a circle).
Case 2: circle crosses the edge of the design region
The results from this test do not match those in Case 1.
The value for all checks is identical and positive which means the constraint is violated.
The text was updated successfully, but these errors were encountered: