Skip to content

Commit 327755b

Browse files
committed
refc(adjoint): Move imaginary factor in MonitorData.get_amplitude() to adjoint calculation
1 parent e0e8dbb commit 327755b

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ with fewer layers than recommended.
2525
- Bug in `PlaneWave` defined with a negative `angle_theta` which would lead to wrong injection.
2626
- Plots of objects defined by shape intersection logic will no longer display thin line artifacts.
2727
- Fixed incorrect gradient computation in PyTorch plugin (`to_torch`) for functions returning multi-element arrays.
28+
- `MonitorData.get_amplitude()` no longers multiplies by a factor of `1j` and now directly returns the complex value of the data.
2829

2930
## [2.9.0rc1] - 2025-06-10
3031

tidy3d/components/data/monitor_data.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ def get_amplitude(x) -> complex:
185185
"""Get the complex amplitude out of some data."""
186186

187187
if isinstance(x, DataArray):
188-
x = complex(x.values)
188+
x = x.values
189189

190-
return 1j * complex(x)
190+
return complex(x)
191191

192192

193193
class AbstractFieldData(MonitorData, AbstractFieldDataset, ABC):
@@ -2115,7 +2115,7 @@ def _make_adjoint_sources_amps(self, fwidth: float) -> list[ModeSource]:
21152115
for mode_index in coords["mode_index"]:
21162116
amp_single = self.amps.sel(f=freq, direction=direction, mode_index=mode_index)
21172117

2118-
if self.get_amplitude(amp_single) == 0.0:
2118+
if abs(self.get_amplitude(amp_single)) == 0.0:
21192119
continue
21202120

21212121
adjoint_source = self._adjoint_source_amp(amp=amp_single, fwidth=fwidth)
@@ -2138,7 +2138,7 @@ def _adjoint_source_amp(self, amp: DataArray, fwidth: float) -> ModeSource:
21382138
amp_complex = self.get_amplitude(amp)
21392139
k0 = 2 * np.pi * freq0 / C_0
21402140
grad_const = k0 / 4 / ETA_0
2141-
src_amp = grad_const * amp_complex
2141+
src_amp = 1j * grad_const * amp_complex
21422142

21432143
# construct source
21442144
src_adj = ModeSource(
@@ -3404,7 +3404,7 @@ def _make_adjoint_sources_amps(self, fwidth: float) -> list[PlaneWave]:
34043404

34053405
# ignore any amplitudes of 0.0 or nan
34063406
amp_complex = self.get_amplitude(amp_single)
3407-
if (amp_complex == 0.0) or np.isnan(amp_complex):
3407+
if (abs(amp_complex) == 0.0) or np.isnan(amp_complex):
34083408
continue
34093409

34103410
# compute a plane wave for this amplitude (if propagating / not None)

0 commit comments

Comments
 (0)