Skip to content

fix[autograd]: sample fields along slab height and polygon edges #2418

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

Merged
merged 3 commits into from
Jul 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ with fewer layers than recommended.
- 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.
- `Simulation.subsection` can no longer take `symmetry` as an argument - the symmetry is always taken from the original simulation.
- 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.
- Enhanced `PolySlab` and `Cylinder` gradient computation via adaptive field sampling along geometry boundaries instead of fixed-grid center sampling.
- Shape derivatives have been sped up significantly, especially for simulations containing many structures in a `GeometryGroup`.

### Fixed
- Arrow lengths are now scaled consistently in the X and Y directions, and their lengths no longer exceed the height of the plot window.
Expand Down
13 changes: 4 additions & 9 deletions tests/test_components/test_autograd.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

import tidy3d as td
import tidy3d.web as web
from tidy3d.components.autograd.constants import MAX_NUM_TRACED_STRUCTURES
from tidy3d.components.autograd.derivative_utils import DerivativeInfo
from tidy3d.components.autograd.utils import is_tidy_box
from tidy3d.components.data.data_array import DataArray
from tidy3d.exceptions import AdjointError
from tidy3d.plugins.polyslab import ComplexPolySlab
from tidy3d.web import run, run_async
from tidy3d.web.api.autograd.autograd import MAX_NUM_TRACED_STRUCTURES
from tidy3d.web.api.autograd.utils import FieldMap

from ..utils import SIM_FULL, AssertLogLevel, run_emulated, tracer_arr
Expand Down Expand Up @@ -812,7 +812,7 @@ def test_autograd_async(use_emulated_run, structure_key, monitor_key):
make_sim = fn_dict["sim"]
postprocess = fn_dict["postprocess"]

task_names = {"test_a", "adjoint", "task1", "_test"}
task_names = {"test_a", "adjoint", "_test"}

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

task_names = {"1", "2", "3", "4"}
task_names = {"1", "2"}

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

task_names = {"1", "2", "3", "4"}
task_names = {"1", "2"}

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

import tidy3d.components.data.sim_data as sd

monkeypatch.setattr(sd, "RESIDUAL_CUTOFF_ADJOINT", 1)
reload(td)

postprocess_fn = check_fn(structure_key=structure_key)

def objective(params):
Expand Down
Loading