-
Notifications
You must be signed in to change notification settings - Fork 591
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 optimization with multiple objective functions #2097
Comments
I'm guessing this is the culprit, in Lines 3023 to 3029 in 91d36ba
|
I have been able to use multiple objective functions in the adjoint solver, so I think it might be something more specific that's causing the issue. AKA it's the combination of multiple objective functions AND something else that's causing this. |
@smartalecH, it seems odd that those chunks are being deleted in this routine, since they aren't allocated by this routine. Shouldn't they be deleted by the code that "owns" them? |
Basically, we need a new routine that separately deletes DFT chunks when we want to. The tricky part is we need to remember when to delete them. For example, we want to delete each adjoint chunk after we "recombine" it with the forward runs. So modifying the earlier block of code should suffice: // clear all the dft data structures
for (int i=0;i<3;i++){
for (int ii=0;ii<adjoint_dft_chunks[i].size();ii++){
delete adjoint_dft_chunks[i][ii];
}
} However, we need to hang on to the forward chunks until we are all done looping through objective functions (and performing their recombination steps), which is done here: meep/python/adjoint/optimization_problem.py Lines 264 to 272 in 405b7e6
So after this point, we can now delete the forward chunks. |
Adjoint optimization fails if there are more than one objective functions.
meep/python/adjoint/utils.py
Lines 54 to 58 in 91d36ba
mp._get_gradient
frees the memory of the fields, causing problems when we reuse the forward fields again for the another objective function.The issue actually exists before #1855 , where we could make copies of forward fields before passing in
mp._get_gradient
. Right now, the naive fix could be installing one forward design region monitor for each objective function, so that we have a fresh copy each time we callmp._get_gradient
.The text was updated successfully, but these errors were encountered: