-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix off-by-one filtering errors. (#2016)
* fix fftshift by using ifftshift * update tests * add new function to get_epsilon_grid and material_grid * use proper padding and allow for arbitrary mg sizes * fix gradient of filters
- Loading branch information
1 parent
cd569b2
commit 11545a1
Showing
8 changed files
with
120 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'''test_adjoint_utils.py | ||
Check various components of the adjoint solver codebase, like | ||
filters, which may not need explicit gradient computation | ||
(i.e. forward and adjoint runs). | ||
''' | ||
|
||
import meep as mp | ||
try: | ||
import meep.adjoint as mpa | ||
except: | ||
import adjoint as mpa | ||
import numpy as np | ||
from autograd import numpy as npa | ||
from autograd import tensor_jacobian_product | ||
import unittest | ||
from enum import Enum | ||
from utils import ApproxComparisonTestCase | ||
import parameterized | ||
|
||
_TOL = 1e-6 if mp.is_single_precision() else 1e-14 | ||
|
||
## ensure reproducible results | ||
rng = np.random.RandomState(9861548) | ||
|
||
class TestAdjointUtils(ApproxComparisonTestCase): | ||
@parameterized.parameterized.expand([ | ||
('1.0_1.0_20_conic',1.0, 1.0, 20, 0.24, mpa.conic_filter), | ||
('1.0_1.0_23_conic',1.0, 1.0, 23, 0.24, mpa.conic_filter), | ||
('0.887_1.56_conic',0.887, 1.56, 20, 0.24, mpa.conic_filter), | ||
('0.887_1.56_conic',0.887, 1.56, 31, 0.24, mpa.conic_filter), | ||
('0.887_1.56_gaussian',0.887, 1.56, 20, 0.24, mpa.gaussian_filter), | ||
('0.887_1.56_cylindrical',0.887, 1.56, 20, 0.24, mpa.cylindrical_filter) | ||
]) | ||
def test_filter_offset(self,test_name,Lx,Ly,resolution,radius,filter_func): | ||
'''ensure that the filters are indeed zero-phase''' | ||
print("Testing ",test_name) | ||
Nx, Ny = int(resolution*Lx), int(resolution*Ly) | ||
x = np.random.rand(Nx,Ny) | ||
x = x + np.fliplr(x) | ||
x = x + np.flipud(x) | ||
y = filter_func(x, radius, Lx, Ly, resolution) | ||
self.assertClose(y,np.fliplr(y),epsilon=_TOL) | ||
self.assertClose(y,np.flipud(y),epsilon=_TOL) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.
The shape of the kernel is changed from a disc to a square. Is it still a cylindrical filter?