Skip to content

Commit c410ae2

Browse files
Gregory Robertsyaugenst-flex
authored andcommitted
feature[adjoint]: pec gradient support for Box
1 parent 5e7ef85 commit c410ae2

File tree

11 files changed

+2412
-89
lines changed

11 files changed

+2412
-89
lines changed

tests/test_components/test_autograd.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,7 @@ def J(eps):
16211621
[[[[2.0]]]], coords={"x": [0], "y": [0], "z": [0], "f": [1.94e14]}
16221622
),
16231623
bounds_intersect=((-1, -1, -1), (1, 1, 1)),
1624+
simulation_bounds=((-2, -2, -2), (2, 2, 2)),
16241625
)
16251626

16261627
grads_computed = pr._compute_derivatives(derivative_info=info)
@@ -1662,6 +1663,7 @@ def test_adaptive_spacing(eps_real):
16621663
eps_no_structure={},
16631664
eps_inf_structure={},
16641665
bounds_intersect=((-1, -1, -1), (1, 1, 1)),
1666+
simulation_bounds=((-2, -2, -2), (2, 2, 2)),
16651667
)
16661668

16671669
with AssertLogLevel("WARNING", contains_str="Based on the material, the adaptive spacing"):
@@ -1691,6 +1693,7 @@ def test_cylinder_discretization(eps_real):
16911693
eps_no_structure={},
16921694
eps_inf_structure={},
16931695
bounds_intersect=((-1, -1, -1), (1, 1, 1)),
1696+
simulation_bounds=((-2, -2, -2), (2, 2, 2)),
16941697
)
16951698

16961699
with AssertLogLevel(
@@ -1771,6 +1774,7 @@ def J(eps):
17711774
[[[[2.0]]]], coords={"x": [0], "y": [0], "z": [0], "f": [1.94e14]}
17721775
),
17731776
bounds_intersect=((-1, -1, -1), (1, 1, 1)),
1777+
simulation_bounds=((-2, -2, -2), (2, 2, 2)),
17741778
)
17751779

17761780
grads_computed = pr._compute_derivatives(derivative_info=info)

tests/test_components/test_autograd_polyslab.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def __init__(
9696
axis: int,
9797
coeffs: dict[str, float],
9898
bounds_intersect: Optional[tuple[tuple[float, ...], tuple[float, ...]]] = None,
99+
simulation_bounds: Optional[tuple[tuple[float, ...], tuple[float, ...]]] = None,
99100
) -> None:
100101
self.paths = paths
101102
self.axis = axis
@@ -113,6 +114,12 @@ def __init__(
113114
else ((-1e3, -1e3, -1e3), (1e3, 1e3, 1e3))
114115
)
115116

117+
self.simulation_bounds = (
118+
simulation_bounds
119+
if simulation_bounds is not None
120+
else ((-2e3, -2e3, -2e3), (2e3, 2e3, 2e3))
121+
)
122+
116123
adaptive_vjp_spacing = DerivativeInfo.adaptive_vjp_spacing
117124
wavelength_min = property(lambda self: DerivativeInfo.wavelength_min.fget(self))
118125
wavelength_max = property(lambda self: DerivativeInfo.wavelength_max.fget(self))
@@ -234,6 +241,7 @@ def _setup(self):
234241
axis=self.AXIS,
235242
coeffs=COEFFS,
236243
bounds_intersect=((-1e3, -1e3, z_mid), (1e3, 1e3, z_mid)),
244+
simulation_bounds=((-2e3, -2e3, z_mid - 1e3), (2e3, 2e3, z_mid + 1e3)),
237245
)
238246
self.results = self.slab._compute_derivatives(self.di)
239247
self.z_mid = z_mid
@@ -304,6 +312,7 @@ def setup_class(cls):
304312
axis=cls.AXIS,
305313
coeffs=COEFFS,
306314
bounds_intersect=(sim_min, sim_max),
315+
simulation_bounds=(sim_min, sim_max),
307316
)
308317
cls.results = cls.slab._compute_derivatives(cls.di)
309318

0 commit comments

Comments
 (0)