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

fix calculate_fd_gradient to deal with design pixel weights near 0 or 1 #2073

Merged
merged 1 commit into from
May 26, 2022

Conversation

mawc2019
Copy link
Contributor

@mawc2019 mawc2019 commented May 14, 2022

The function calculate_fd_gradient does not return the correct finite-difference gradients when the design pixel weight is 0, 1, or too close to them. This PR replaces the central difference with forward or backward differences in these circumstances, and also forbids a too large (≥0.2) step size for finite difference.

@codecov-commenter
Copy link

Codecov Report

Merging #2073 (5d22b7e) into master (5275f43) will decrease coverage by 0.05%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master    #2073      +/-   ##
==========================================
- Coverage   73.25%   73.19%   -0.06%     
==========================================
  Files          17       17              
  Lines        4902     4906       +4     
==========================================
  Hits         3591     3591              
- Misses       1311     1315       +4     
Impacted Files Coverage Δ
python/adjoint/optimization_problem.py 55.32% <0.00%> (-1.15%) ⬇️

@stevengj
Copy link
Collaborator

Sounds good. How did you test this?

@mawc2019
Copy link
Contributor Author

I tested it with uniform design patterns such as np.zeros(Nx*Ny), np.ones(Nx*Ny), 1.5*np.ones(Nx*Ny), etc. The adjoint and finite-difference gradients were compared.

@stevengj stevengj merged commit 0d89d88 into NanoComp:master May 26, 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.

3 participants