Skip to content

Commit 6faed26

Browse files
Gregory Robertsmomchil-flex
authored andcommitted
fix[adjoint]: remove sources from sim_inf_structure in adjoint postprocessing to avoid validation error between sources and structure used as background medium
1 parent 48a433b commit 6faed26

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2626
- Validation of `freqs` in the `ComponentModeler` and `TerminalComponentModeler`.
2727
- Calculation of voltage and current in the `WavePort`, when one type of path integral is supplied and the transmission line mode is lossy.
2828
- Polygon vertices cleanup in `ClipOperation.intersections_plane`.
29+
- Removed sources from `sim_inf_structure` simulation object in `postprocess_adj` to avoid source and background medium validation errors.
2930

3031
## [2.9.0] - 2025-08-04
3132

tidy3d/web/api/autograd/autograd.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
)
2323
from tidy3d.components.autograd.derivative_utils import DerivativeInfo
2424
from tidy3d.components.data.data_array import DataArray
25+
from tidy3d.components.grid.grid_spec import GridSpec
2526
from tidy3d.exceptions import AdjointError
2627
from tidy3d.web.api.asynchronous import DEFAULT_DATA_DIR
2728
from tidy3d.web.api.asynchronous import run_async as run_async_webapi
@@ -1070,10 +1071,14 @@ def postprocess_adj(
10701071
sim_orig = sim_data_orig.simulation
10711072
plane_eps = eps_fwd.monitor.geometry
10721073

1074+
sim_orig_grid_spec = GridSpec.from_grid(sim_orig.grid)
1075+
10731076
# permittivity without this structure
10741077
structs_no_struct = list(sim_orig.structures)
10751078
structs_no_struct.pop(structure_index)
1076-
sim_no_structure = sim_orig.updated_copy(structures=structs_no_struct)
1079+
sim_no_structure = sim_orig.updated_copy(
1080+
structures=structs_no_struct, monitors=[], sources=[], grid_spec=sim_orig_grid_spec
1081+
)
10771082

10781083
eps_no_structure_data = [
10791084
sim_no_structure.epsilon(box=plane_eps, coord_key="centers", freq=f)
@@ -1086,6 +1091,8 @@ def postprocess_adj(
10861091
structures=structs_inf_struct,
10871092
medium=structure.medium,
10881093
monitors=[],
1094+
sources=[],
1095+
grid_spec=sim_orig_grid_spec,
10891096
)
10901097

10911098
eps_inf_structure_data = [

0 commit comments

Comments
 (0)