Skip to content
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

Improved efficiency of overlap_sort #1465

Merged
merged 1 commit into from
Feb 15, 2024
Merged

Conversation

caseyflex
Copy link
Contributor

@caseyflex caseyflex commented Feb 13, 2024

Uses the faster outer_dot to improve efficiency of overlap_sort. Sometimes, sorting modes can be a bottleneck in mode solving, and this should prevent that from occuring.

Based off of #1464

@tylerflex
Copy link
Collaborator

@caseyflex should we close this (or make a draft) in view of #1464 ?

@caseyflex
Copy link
Contributor Author

@caseyflex should we close this (or make a draft) in view of #1464 ?

no sorry -- we should close this one: #1463

This PR uses the revised outer_dot PR #1464 to improve overlap_sort.

@tylerflex
Copy link
Collaborator

ok I see, sorry for the confusion

``self.monitor.mode_spec`` and ``self.monitor.freqs`` will no longer be matching the
newly created data."""

update_dict = dict(self._grid_correction_dict, **self.field_components)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_grid_correction_dict is a property so it shouldn't be added here at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is adding grid_primal_correction and grid_dual_correction to the update list. I copied this from _isel, but it is probably not needed as these fields keep their old values...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh actually, it does do something -- it updates the coordinates on those two fields as well as the field_components. This may actually be needed so best to leave it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, got it.

@@ -1081,6 +1081,7 @@ def overlap_sort(
for freq_id in range(f0_ind + step, last_ind, step):
# Get next frequency to sort
data_to_sort = self._isel(f=[freq_id])
data_to_sort = data_to_sort._assign_coords(f=[self.monitor.freqs[f0_ind]])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused, why is this needed? For a regular DataArray, isel-ing already redefines the coordinates, too. Is something not working right in our _isel wrapper?

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit of a hack -- I want to isel f=[freq_id], which is the next frequency to sort. But, I want to compute outer_dot against the base frequency f0. But because of how outer_dot works, it only keeps frequencies which are common between the two datasets. So, here, I isel f=[freq_id], then I assign coords to f0, so that outer_dot will think they are at the same frequency and know to compare them.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhhhh. Funny. One thing we could do also do is to allow outer_dot to work without a frequency dimension, and just pop it? But, eh, I think this is fine.

tidy3d/components/data/monitor_data.py Outdated Show resolved Hide resolved
Base automatically changed from casey/alternativeouterdot to pre/2.6 February 15, 2024 19:07
@momchil-flex
Copy link
Collaborator

I don't know if @weiliangjin2021 still wants to look at this, but it should be good to merge after a rebase. The conflicts are probably in the changelog. You could squash the commits too.

@caseyflex
Copy link
Contributor Author

I don't know if @weiliangjin2021 still wants to look at this, but it should be good to merge after a rebase. The conflicts are probably in the changelog. You could squash the commits too.

Rebased and squashed. Merge when you're ready. thanks!

Copy link
Collaborator

@weiliangjin2021 weiliangjin2021 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't take a very careful look. From what I understand, it all look good.

@momchil-flex momchil-flex merged commit cfd1d07 into pre/2.6 Feb 15, 2024
16 checks passed
@momchil-flex momchil-flex deleted the casey/modesorting branch February 15, 2024 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants