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

separately delete forward dft chunk for adjoint optimization #2251

Merged
merged 9 commits into from Oct 14, 2022

Conversation

mochen4
Copy link
Collaborator

@mochen4 mochen4 commented Sep 29, 2022

Fix #2097. Delete forward dft chunks at the end of all adjoint gradients calculation.

src/meepgeom.cpp Outdated
next_forward_chunk = current_forward_chunk->next_in_dft;
delete current_forward_chunk;
current_forward_chunk = next_forward_chunk;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this need to set fields_f[i]->chunks = NULL or something?

@smartalecH smartalecH self-requested a review September 29, 2022 19:19
@mochen4 mochen4 marked this pull request as ready for review October 6, 2022 15:50
@stevengj
Copy link
Collaborator

stevengj commented Oct 6, 2022

Seems like this code should be refactored?

meep/src/fields.cpp

Lines 182 to 190 in fba8aeb

while (dft_chunks) {
dft_chunk *nxt = dft_chunks->next_in_chunk;
// keep the dft chunk in memory for adjoint calculations
if (dft_chunks->persist)
dft_chunks->fc = NULL;
else
delete dft_chunks;
dft_chunks = nxt;
}
no, that's deleting it from the fields object, which is a bit different.

src/meepgeom.cpp Outdated
}
}

} // material_grids_addgradient

void delete_forward_dft_chunk(std::vector<meep::dft_fields *> fields_f) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like it would make more sense to have a dft_fields::delete_dft_chunks method, and then just call it for each element of the array.

@@ -304,6 +304,13 @@ def calculate_gradient(self):
for ar in range(len(self.objective_functions))
]

for dri in range(self.num_design_regions):
mp._delete_forward_dft_chunk(
self.forward_design_region_monitors[dri][0].swigobj,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just call self.forward_design_region_monitors[dri][0].delete_dft_chunks() on each of the objects?

@codecov-commenter
Copy link

Codecov Report

Merging #2251 (6a92367) into master (82734d1) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2251      +/-   ##
==========================================
+ Coverage   73.23%   73.24%   +0.01%     
==========================================
  Files          17       17              
  Lines        4916     4919       +3     
==========================================
+ Hits         3600     3603       +3     
  Misses       1316     1316              
Impacted Files Coverage Δ
python/adjoint/optimization_problem.py 57.94% <100.00%> (+0.65%) ⬆️

@stevengj stevengj merged commit 49aef42 into NanoComp:master Oct 14, 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.

adjoint optimization with multiple objective functions
3 participants