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

Various improvements to EME solver. #1636

Merged
merged 1 commit into from
Jun 5, 2024
Merged

Various improvements to EME solver. #1636

merged 1 commit into from
Jun 5, 2024

Conversation

caseyflex
Copy link
Contributor

@caseyflex caseyflex commented Apr 24, 2024

Summary of changes:

  • Adds EMEFreqSweep with freq_scale_factors
  • Adds mode solver relative to existing basis via _data_on_yee_grid_relative
  • Changes mode solver eigenvalue formula in eigs_to_effective_index to avoid small keff approximation
  • Adds sweep_index to more EME data structures. Rearranges some of the other dims to be more consistent and user-friendly.
  • Handling of sweep_index in smatrix_in_basis and field_in_basis
  • Reorganizes some of the plotting functionality in sim_data.py to avoid code duplication. The main thing here was wanting a function plot_field_monitor_data that takes the monitor data directly as an argument instead of taking the monitor name.
  • Adds normalize field to EMESimulation which specifies whether to normalize the port modes to unity flux (thereby normalizing the scattering matrix and expansion coefficients). True by default, but can be set to False in certain cases involving evanescent port modes.
  • Other minor changes based on feedback: improved monitor storage size estimation, better handling of lists / np arrays, warning for large number of modes with constraint, convenience methods for port modes, cell-dependent EMELengthSweep

Todo:

  • improve test coverage
  • replace numpy operations with xarray operations in smatrix_in_basis and field_in_basis

Later:

  • further improve code quality in smatrix_in_basis / field_in_basis

@caseyflex caseyflex marked this pull request as draft April 24, 2024 14:00
@momchil-flex momchil-flex added the 2.7 will go into version 2.7.* label Apr 30, 2024
@caseyflex caseyflex force-pushed the casey/eme_improve branch 3 times, most recently from f30427a to 05692b8 Compare May 10, 2024 16:50
@caseyflex caseyflex changed the title Added support for frequency sweeps in EME solver. Various improvements to EME solver. May 16, 2024
@tylerflex tylerflex added the blocking This version can't be released until this PR is merged label May 24, 2024
@caseyflex caseyflex force-pushed the casey/eme_improve branch 2 times, most recently from 909a1d6 to e68100a Compare May 28, 2024 16:25
@caseyflex caseyflex force-pushed the casey/eme_improve branch 2 times, most recently from bb51d14 to 9f62e61 Compare May 29, 2024 16:46
@caseyflex
Copy link
Contributor Author

@tylerflex the test tests/test_plugins/test_adjoint.py::test_no_poynting is failing in this branch -- somehow the NotImplementedError in JaxSimulationData.get_poynting_vector is not being raised. Could you take a look? I tried to debug but I'm not too familiar with the adjoint tests.

@tylerflex
Copy link
Collaborator

@caseyflex due to some subtleties with how JaxSimulationData raises NotImplementedError when calling get_poynting_vector and now a lot of simulation data stuff calls _get_poynting_vector internally.

See the fix here:
https://github.com/flexcompute/tidy3d/pull/1636/files#r1619410128

@tylerflex
Copy link
Collaborator

by the way, should I just review once the to-do items are done and it's in it's final state?

@caseyflex
Copy link
Contributor Author

caseyflex commented May 29, 2024 via email

@tylerflex
Copy link
Collaborator

ok I guess ping me when it's done, thanks

@caseyflex caseyflex force-pushed the casey/eme_improve branch 4 times, most recently from 5a4d532 to c9aa039 Compare May 31, 2024 11:33
@caseyflex
Copy link
Contributor Author

ok I guess ping me when it's done, thanks

I think it is all ready for review now

@caseyflex caseyflex marked this pull request as ready for review May 31, 2024 12:07
@caseyflex caseyflex force-pushed the casey/eme_improve branch 2 times, most recently from 698eb88 to d9458e5 Compare May 31, 2024 13:04
Copy link
Collaborator

@tylerflex tylerflex left a comment

Choose a reason for hiding this comment

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

Thanks @caseyflex . I think this looks good overall. I left some comments.

In general it seems there are a ton of edge cases being handled here. While I'm sure it's correct, it was a bit difficult to follow the complexity in the code when reading through. More importantly, though, I am a little concerned about making sure the edge cases are tested properly to avoid unexpected issues in use. I think adding some unit tests for these various edge would go a long way towards the stability of the code.

The command I use to test coverage is:

pytest -rA tests --cov-report=html --cov=tidy3d && open htmlcov/index.html

must also pip install pytest-cov

Another general comment is that I would suggest trying to use xarray instead of to_numpy() and using axis manipulation. One can imagine in the future if the order of some of the data dimensions gets changed, or we add another dimension, this can quickly become unsustainable. So if there's any way to rewrite the array manipulation bits using the named axes of xarray, that would also really improve the stability and readability of the code.

Thanks a lot for these improvements to the EME solver and all of the hard work to get them out!

tests/test_components/test_eme.py Show resolved Hide resolved
tests/test_components/test_eme.py Outdated Show resolved Hide resolved
tests/test_components/test_eme.py Show resolved Hide resolved
tidy3d/components/eme/data/sim_data.py Show resolved Hide resolved
tidy3d/components/eme/data/sim_data.py Show resolved Hide resolved
tidy3d/components/eme/simulation.py Outdated Show resolved Hide resolved
tidy3d/components/eme/simulation.py Outdated Show resolved Hide resolved
tidy3d/components/eme/simulation.py Outdated Show resolved Hide resolved
tidy3d/components/eme/simulation.py Show resolved Hide resolved
tidy3d/plugins/mode/solver.py Outdated Show resolved Hide resolved
@momchil-flex
Copy link
Collaborator

When I run through the web, it seems that the task monitoring stays stuck at "starting up solver" until it eventually goes to "success". This may not be something introduced by this PR but worth noting to fix.

image

@momchil-flex
Copy link
Collaborator

So currently EMESimulation supports both freqs and a sweep_spec that can be a frequency sweep, right? Providing multiple freqs will compute the modes exactly, while providing a frequency sweep spec will use the mode computation in the reduced basis? What happens if both are provided?

@caseyflex
Copy link
Contributor Author

So currently EMESimulation supports both freqs and a sweep_spec that can be a frequency sweep, right? Providing multiple freqs will compute the modes exactly, while providing a frequency sweep spec will use the mode computation in the reduced basis? What happens if both are provided?

Yeah, that's right -- I should clarify in the docstrings. When both are provided, it kind of works as expected -- performs exact mode solves at all the freqs, and then applies the freq_scale_factors to each exact solution. Although this would definitely be an obscure use case.

@caseyflex caseyflex force-pushed the casey/eme_improve branch 2 times, most recently from 3645c73 to 7d81b25 Compare June 3, 2024 13:19
@yaugenst-flex
Copy link
Contributor

@caseyflex fyi, autograd tests are failing because of #1734 and will pass once #1736 is merged

@caseyflex caseyflex force-pushed the casey/eme_improve branch 3 times, most recently from bc4a166 to 0fec522 Compare June 4, 2024 11:56
@caseyflex caseyflex requested a review from tylerflex June 4, 2024 16:05
@caseyflex caseyflex force-pushed the casey/eme_improve branch 2 times, most recently from 836637f to ddb82ec Compare June 4, 2024 17:39
Copy link
Collaborator

@tylerflex tylerflex left a comment

Choose a reason for hiding this comment

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

As far as I'm concerned, this is good to go assuming whatever comments I had earlier are either resolved or marked somewhere for revisiting whenever possible. Thanks @caseyflex

@caseyflex caseyflex merged commit 16192f5 into pre/2.7 Jun 5, 2024
16 checks passed
@caseyflex caseyflex deleted the casey/eme_improve branch June 5, 2024 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.7 will go into version 2.7.* blocking This version can't be released until this PR is merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants