-
Notifications
You must be signed in to change notification settings - Fork 65
Add interpolation to EME #2973
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
base: develop
Are you sure you want to change the base?
Add interpolation to EME #2973
Conversation
bdd7b09 to
aedc3a9
Compare
ead0cff to
0b23b05
Compare
3571d01 to
73e8ac0
Compare
0c72776 to
3676cf9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
9 files reviewed, 4 comments
| interp_spec: Optional[ModeInterpSpec] = pd.Field( | ||
| ModeInterpSpec.cheb(num_points=3, reduce_data=True), | ||
| title="Mode frequency interpolation specification", | ||
| description="Specification for computing modes at a reduced set of frequencies and " | ||
| "interpolating to obtain results at all requested frequencies. This can significantly " | ||
| "reduce computational cost for broadband simulations where modes vary smoothly with " | ||
| "frequency. Requires frequency tracking to be enabled (``sort_spec.track_freq`` must " | ||
| "not be ``None``) to ensure consistent mode ordering across frequencies.", | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: The description states "Requires frequency tracking to be enabled (sort_spec.track_freq must not be None)", but EMEModeSpec no longer has a track_freq field (it was removed in this PR). The docstring should be updated to reflect the actual requirements. Consider checking the parent ModeSpec class's sort_spec field instead if tracking is needed.
Prompt To Fix With AI
This is a comment left during a code review.
Path: tidy3d/components/eme/grid.py
Line: 29:37
Comment:
**logic:** The description states "Requires frequency tracking to be enabled (`sort_spec.track_freq` must not be `None`)", but `EMEModeSpec` no longer has a `track_freq` field (it was removed in this PR). The docstring should be updated to reflect the actual requirements. Consider checking the parent `ModeSpec` class's `sort_spec` field instead if tracking is needed.
How can I resolve this? If you propose a fix, please make it concise.| if self.num_points >= len(freqs): | ||
| return freqs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: changed from > to >= but now the validation warning is commented out in monitor.py:440 and mode_solver.py:518-519. Users won't be warned when num_points >= len(freqs), which defeats the purpose of this optimization. Either restore the warning or add a comment explaining why it's acceptable.
Prompt To Fix With AI
This is a comment left during a code review.
Path: tidy3d/components/mode_spec.py
Line: 436:437
Comment:
**style:** changed from `>` to `>=` but now the validation warning is commented out in monitor.py:440 and mode_solver.py:518-519. Users won't be warned when `num_points >= len(freqs)`, which defeats the purpose of this optimization. Either restore the warning or add a comment explaining why it's acceptable.
How can I resolve this? If you propose a fix, please make it concise.| return bytes_single | ||
|
|
||
| _warn_interp_num_points = validate_interp_num_points() | ||
| # _warn_interp_num_points = validate_interp_num_points() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: validation commented out instead of removed. Add a comment explaining why (e.g., "Warning disabled because EME now defaults to interpolation" or similar context).
Prompt To Fix With AI
This is a comment left during a code review.
Path: tidy3d/components/monitor.py
Line: 440:440
Comment:
**style:** validation commented out instead of removed. Add a comment explaining why (e.g., "Warning disabled because EME now defaults to interpolation" or similar context).
How can I resolve this? If you propose a fix, please make it concise.| # if self.mode_spec.interp_spec is not None: | ||
| # _warn_interp_num_points(self.mode_spec.interp_spec, self.freqs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: validation commented out. Add a comment explaining why this warning was disabled.
Prompt To Fix With AI
This is a comment left during a code review.
Path: tidy3d/components/mode/mode_solver.py
Line: 518:519
Comment:
**style:** validation commented out. Add a comment explaining why this warning was disabled.
How can I resolve this? If you propose a fix, please make it concise.| "mode tracking based on the lowest, central, or highest frequency. " | ||
| "If ``None`` no mode tracking is performed, which is the default for best performance.", | ||
| interp_spec: Optional[ModeInterpSpec] = pd.Field( | ||
| ModeInterpSpec.cheb(num_points=3, reduce_data=True), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@momchil-flex We could change this to be GVD based (i.e. polynomial with three sampling points concentrated around the central frequency). But I'm not sure that's better in general. It can lower the accuracy towards the edge of the spectrum, and I haven't had a problem with mode tracking. And the user can customize this if needed
| if self.mode_spec.interp_spec is not None: | ||
| _warn_interp_num_points(self.mode_spec.interp_spec, self.freqs) | ||
| # if self.mode_spec.interp_spec is not None: | ||
| # _warn_interp_num_points(self.mode_spec.interp_spec, self.freqs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dbochkov-flexcompute Do we need these warnings? They are annoying in an EME simulation where interpolation is the default, and falling back to the actual frequencies specified is even better (not worth warning about necessarily)
| >>> sampling_freqs = interp_spec.sampling_points(freqs) | ||
| """ | ||
| if self.num_points > len(freqs): | ||
| if self.num_points >= len(freqs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dbochkov-flexcompute not really needed for EME, but should we make this change?
3676cf9 to
455b032
Compare
455b032 to
5a642c9
Compare
| return val | ||
|
|
||
| @property | ||
| def _stored_freqs(self) -> list[float]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dbochkov-flexcompute this is to update _storage_size_solver for ModeSolverMonitor (although the full freqs will still be used for ModeMonitor)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, yeah, I updated ModeMonitor and ModeSolverMonitor directly but forgot about AbstractModeMonitor
Interpolation in EME can greatly speed up multi-frequency EME simulations.
Greptile Overview
Greptile Summary
This PR adds frequency interpolation support to EME simulations, enabling significant performance improvements for multi-frequency simulations by computing modes at a reduced set of frequencies and interpolating to obtain results at all requested frequencies.
Key Changes:
track_freqfield withinterp_specfield inEMEModeSpec, defaulting to Chebyshev sampling with 3 points_monitor_mode_freqs()method to compute actual frequencies based on interpolation settingssmatrix_in_basis()for mode overlaps when both modes have matchinginterp_specsampling_points()comparison from>to>=to handle edge case where num_points equals frequency countFreqDataset.interp_in_freq()when frequencies already matchvalidate_interp_num_pointswarnings in monitor and mode solverIssues Found:
EMEModeSpec.interp_specincorrectly references removedsort_spec.track_freqfield (should reference parent class'ssort_specif tracking is actually required)Confidence Score: 3/5
modes.monitor.freqsshould be verified for all mode data types; (4) the feature itself is well-designed and fills a real performance need.tidy3d/components/eme/grid.py(incorrect docstring reference) andtidy3d/components/eme/data/sim_data.py(verify monitor.freqs access pattern)Important Files Changed
File Analysis
track_freqfield withinterp_specfield in EMEModeSpec, enabling frequency interpolation with default Chebyshev samplingSequence Diagram
sequenceDiagram participant User participant EMESimulation participant EMEModeSpec participant ModeInterpSpec participant ModeSolver participant EMESimulationData User->>EMESimulation: Create simulation with EMEModeSpec EMESimulation->>EMEModeSpec: Get interp_spec (default: Cheb 3 points) Note over EMESimulation,ModeInterpSpec: Frequency Sampling Phase EMESimulation->>EMEModeSpec: _monitor_mode_freqs() EMEModeSpec->>ModeInterpSpec: sampling_points(freqs) ModeInterpSpec-->>EMEModeSpec: Return reduced freq set EMEModeSpec-->>EMESimulation: Actual frequencies to compute Note over ModeSolver: Mode Computation Phase EMESimulation->>ModeSolver: Solve modes at sampled freqs ModeSolver-->>EMESimulation: Mode data at reduced freqs Note over EMESimulationData: S-Matrix Computation Phase User->>EMESimulationData: smatrix_in_basis(modes1, modes2) EMESimulationData->>EMESimulationData: Check interp_spec1 and interp_spec2 alt Both have matching interp_spec EMESimulationData->>EMESimulationData: Compute overlaps at sampled freqs EMESimulationData->>EMESimulationData: _interp_dataarray_in_freq() on overlaps EMESimulationData-->>User: Interpolated S-matrix else Different or None interp_spec EMESimulationData->>EMESimulationData: Use interpolated_copy EMESimulationData->>EMESimulationData: Interpolate modes to all freqs first EMESimulationData->>EMESimulationData: Compute overlaps at all freqs EMESimulationData-->>User: Full frequency S-matrix endContext used (3)
dashboard- Keep docstrings and comments synchronized with code changes to ensure they are always accurate and n... (source)dashboard- Remove commented-out or obsolete code; rely on version control for history. (source)dashboard- Add comments to explain the reasoning (why) behind complex, non-obvious, or workaround code decision... (source)