Skip to content

Commit 26e5981

Browse files
yaugenst-flexdaquinteroflex
authored andcommitted
feat(adjoint): Adaptively sample fields along slab height and polygon edges
- Implement adaptive field sampling for PolySlab and Cylinder for shape derivatives - Replace fixed grid with Gauss-Legendre quadrature - Sample fields along all surface boundaries (edges and faces) - Handle edge cases: slabs outside simulation, faces at ±inf, 2D simulations - Add analytical tests for gradient computation - Remove `DerivativeSurfaceMesh` abstraction in favor of direct evaluation - Convert `DerivativeInfo` from Pydantic model to dataclass for efficiency - Implement interpolator sharing at `GeometryGroup` level - Add Gauss-Legendre quadrature caching - Optimize memory allocation with pre-allocated arrays - Ensure dtype consistency throughout gradient pipeline
1 parent 73dec98 commit 26e5981

File tree

10 files changed

+1898
-534
lines changed

10 files changed

+1898
-534
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ with fewer layers than recommended.
3131
- Warnings are now generated (instead of errors) when instantiating `PML`, `StablePML`, or `Absorber` classes (or when invoking `pml()`, `stable_pml()`, or `absorber()` functions) with fewer layers than recommended.
3232
- `Simulation.subsection` can no longer take `symmetry` as an argument - the symmetry is always taken from the original simulation.
3333
- If a mode simulation is crossing a symmetry plane of the larger simulation domain, but the mode plane is not symmetric, a warning is issued that it will be expanded symmetrically. Previously this warning only happened during the solver run.
34+
- Enhanced `PolySlab` and `Cylinder` gradient computation via adaptive field sampling along geometry boundaries instead of fixed-grid center sampling.
35+
- Shape derivatives have been sped up significantly, especially for simulations containing many structures in a `GeometryGroup`.
3436

3537
### Fixed
3638
- Arrow lengths are now scaled consistently in the X and Y directions, and their lengths no longer exceed the height of the plot window.

tests/test_components/test_autograd.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ def test_autograd_async(use_emulated_run, structure_key, monitor_key):
812812
make_sim = fn_dict["sim"]
813813
postprocess = fn_dict["postprocess"]
814814

815-
task_names = {"test_a", "adjoint", "task1", "_test"}
815+
task_names = {"test_a", "adjoint", "_test"}
816816

817817
def objective(*args):
818818
sims = {task_name: make_sim(*args) for task_name in task_names}
@@ -912,7 +912,7 @@ def test_autograd_async_some_zero_grad(use_emulated_run, structure_key, monitor_
912912
make_sim = fn_dict["sim"]
913913
postprocess = fn_dict["postprocess"]
914914

915-
task_names = {"1", "2", "3", "4"}
915+
task_names = {"1", "2"}
916916

917917
def objective(*args):
918918
sims = {task_name: make_sim(*args) for task_name in task_names}
@@ -934,7 +934,7 @@ def test_autograd_async_all_zero_grad(use_emulated_run):
934934
make_sim = fn_dict["sim"]
935935
postprocess = fn_dict["postprocess"]
936936

937-
task_names = {"1", "2", "3", "4"}
937+
task_names = {"1", "2"}
938938

939939
def objective(*args):
940940
sims = {task_name: make_sim(*args) for task_name in task_names}
@@ -1927,11 +1927,6 @@ def postprocess(sim_data: td.SimulationData) -> float:
19271927
def test_multi_freq_edge_cases(use_emulated_run, structure_key, label, check_fn, monkeypatch):
19281928
# test multi-frequency adjoint handling
19291929

1930-
import tidy3d.components.data.sim_data as sd
1931-
1932-
monkeypatch.setattr(sd, "RESIDUAL_CUTOFF_ADJOINT", 1)
1933-
reload(td)
1934-
19351930
postprocess_fn = check_fn(structure_key=structure_key)
19361931

19371932
def objective(params):

0 commit comments

Comments
 (0)