Skip to content

Commit

Permalink
Bug fix for overlap_sort() modifying self
Browse files Browse the repository at this point in the history
  • Loading branch information
dbochkov-flexcompute authored and momchil-flex committed Dec 7, 2022
1 parent ff2588e commit 05f4565
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
7 changes: 3 additions & 4 deletions tests/test_data/test_monitor_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,8 @@ def test_mode_solver_data_sort():
# test sorting function
data = make_mode_solver_data()
data_first = data.overlap_sort(track_freq="lowest")
data_last = data.overlap_sort(track_freq="highest")
data_center = data.overlap_sort(track_freq="central")
# these are probably not the best tests
assert data_first.field_components == data.field_components
data_last = data_first.overlap_sort(track_freq="highest")
data_center = data_first.overlap_sort(track_freq="central")
# check repeated sorting doesn't change anything
assert data_first.field_components == data_last.field_components
assert data_first.field_components == data_center.field_components
12 changes: 8 additions & 4 deletions tidy3d/components/data/monitor_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,17 +672,21 @@ def _reorder_modes(
fields = {}
for field_name, field in self.field_components.items():

field_sorted = field.copy()

# Apply phase shift
field.data = field.data * np.exp(-1j * phase[None, None, None, :, :])
field_sorted.data = field_sorted.data * np.exp(-1j * phase[None, None, None, :, :])

# Rearrange modes
for freq_id in range(num_freqs):
field.data[..., freq_id, :] = field.data[..., freq_id, sorting[freq_id, :]]
field_sorted.data[..., freq_id, :] = field_sorted.data[
..., freq_id, sorting[freq_id, :]
]

fields[field_name] = field
fields[field_name] = field_sorted

# Rearrange propagation index data
index_data = self.n_complex
index_data = self.n_complex.copy()
for freq_id in range(num_freqs):
index_data.data[freq_id, :] = index_data.data[freq_id, sorting[freq_id, :]]

Expand Down

0 comments on commit 05f4565

Please sign in to comment.