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

Increase array size of material grid by 1 in each dimension #2504

Merged
merged 1 commit into from
May 11, 2023

Conversation

mawc2019
Copy link
Contributor

@mawc2019 mawc2019 commented May 4, 2023

The missing +1 in the array size of the material grid is restored in this PR, but some tests in test_adjoint_solver.py fail.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@codecov-commenter
Copy link

codecov-commenter commented May 4, 2023

Codecov Report

Merging #2504 (0d73d36) into master (79e8d17) will not change coverage.
The diff coverage is 100.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@           Coverage Diff           @@
##           master    #2504   +/-   ##
=======================================
  Coverage   73.92%   73.92%           
=======================================
  Files          18       18           
  Lines        5296     5296           
=======================================
  Hits         3915     3915           
  Misses       1381     1381           
Impacted Files Coverage Δ
python/adjoint/filters.py 79.89% <100.00%> (ø)

@mawc2019
Copy link
Contributor Author

mawc2019 commented May 4, 2023

We need to increase some tolerances in test_adjoint_solver.py.

Python 3.7:

FAIL: test_eigenmode (__main__.TestAdjointSolver)
Verifies that the adjoint gradient for an objective function based
----------------------------------------------------------------------
Traceback (most recent call last):
  File "../../../python/tests/test_adjoint_solver.py", line 592, in test_eigenmode
    self.assertClose(adj_dd, fnd_dd, epsilon=tol)
  File "/home/runner/work/meep/meep/build/meep-1.27.0-beta/python/tests/utils.py", line 30, in assertClose
    self.assertLessEqual(diff_norm, epsilon * np.maximum(x_norm, y_norm), msg)
AssertionError: 2.4692787936065122e-05 not less than or equal to 2.147141650190434e-05 : 

======================================================================
FAIL: test_ldos (__main__.TestAdjointSolver)
Verifies that the adjoint gradient for an objective function based
----------------------------------------------------------------------
Traceback (most recent call last):
  File "../../../python/tests/test_adjoint_solver.py", line 621, in test_ldos
    self.assertClose(adj_dd, fnd_dd, epsilon=tol)
  File "/home/runner/work/meep/meep/build/meep-1.27.0-beta/python/tests/utils.py", line 30, in assertClose
    self.assertLessEqual(diff_norm, epsilon * np.maximum(x_norm, y_norm), msg)
AssertionError: 1.866014771444676e-10 not less than or equal to 7.504694841953264e-11 : 

Python 3.10:

FAIL: test_DFT_fields (__main__.TestAdjointSolver)
Verifies that the adjoint gradient for an objective function based
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/meep/meep/build/meep-1.27.0-beta/_build/sub/python/../../../python/tests/test_adjoint_solver.py", line 551, in test_DFT_fields
    self.assertClose(adj_dd, fnd_dd, epsilon=tol)
  File "/home/runner/work/meep/meep/build/meep-1.27.0-beta/python/tests/utils.py", line 30, in assertClose
    self.assertLessEqual(diff_norm, epsilon * np.maximum(x_norm, y_norm), msg)
AssertionError: 0.00032576555598241895 not less than or equal to 0.00015930181276331502 : 

======================================================================
FAIL: test_eigenmode (__main__.TestAdjointSolver)
Verifies that the adjoint gradient for an objective function based
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/meep/meep/build/meep-1.27.0-beta/_build/sub/python/../../../python/tests/test_adjoint_solver.py", line 592, in test_eigenmode
    self.assertClose(adj_dd, fnd_dd, epsilon=tol)
  File "/home/runner/work/meep/meep/build/meep-1.27.0-beta/python/tests/utils.py", line 30, in assertClose
    self.assertLessEqual(diff_norm, epsilon * np.maximum(x_norm, y_norm), msg)
AssertionError: 6.287598863467803e-05 not less than or equal to 3.214987858228824e-05 : 

======================================================================
FAIL: test_ldos (__main__.TestAdjointSolver)
Verifies that the adjoint gradient for an objective function based
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/meep/meep/build/meep-1.27.0-beta/_build/sub/python/../../../python/tests/test_adjoint_solver.py", line 621, in test_ldos
    self.assertClose(adj_dd, fnd_dd, epsilon=tol)
  File "/home/runner/work/meep/meep/build/meep-1.27.0-beta/python/tests/utils.py", line 30, in assertClose
    self.assertLessEqual(diff_norm, epsilon * np.maximum(x_norm, y_norm), msg)
AssertionError: 2.0344705001442236e-10 not less than or equal to 1.5012644966061473e-10 : 

@mawc2019
Copy link
Contributor Author

mawc2019 commented May 4, 2023

The test in test_unfilter_design also fails due to mismatch of array size.

ValueError: cannot reshape array of size 160000 into shape (401,401)

@stevengj
Copy link
Collaborator

stevengj commented May 4, 2023

A factor of ≈2 increase in the tolerances seems fine.

@oskooi
Copy link
Collaborator

oskooi commented May 4, 2023

Looks like the error tolerances in test_adjoint_solver.py need to be reverted to (close to) what they were in #1769.

@mawc2019
Copy link
Contributor Author

mawc2019 commented May 5, 2023

Looks like the error tolerances in test_adjoint_solver.py need to be reverted to (close to) what they were in #1769.

We probably cannot do so because frequency widths are quite different in the two cases. Now there is df = 0.05*fcen, but in #1769 there was df = 0.23*fcen. The values of gradients and hence the tolerances are not comparable between the two cases.

In addition, it seems that +1 is also needed in the expressions of Nr and Nz in test_adjoint_cyl.py.

Nr, Nz = int(design_r * design_region_resolution), int(design_z * design_region_resolution)

@mawc2019 mawc2019 force-pushed the material_grid_size_plus1 branch from f61c5aa to 47a1d71 Compare May 6, 2023 07:46
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.

4 participants