-
Notifications
You must be signed in to change notification settings - Fork 70
FXC-4643: update optionality and default values in ModeSortSpec #3144
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?
Conversation
…_key and ModeSortSpec.sort_order
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.
Pull request overview
This PR updates the ModeSortSpec class to make sort_key required with a default value of "n_eff" and sort_order optional with intelligent defaults based on context. The change introduces key-dependent default sort orders, where each mode data key has a natural ordering (descending for confinement-related metrics, ascending for loss/area metrics), and reference-based sorting always defaults to ascending (closest values first).
Key changes:
- Made
sort_keyrequired with default"n_eff"(previously optional) - Made
sort_orderoptional with context-aware defaults via validator - Added
MODE_DATA_KEY_SORT_ORDERdictionary mapping each key to its natural sort order
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tidy3d/components/mode_spec.py | Introduces MODE_DATA_KEY_SORT_ORDER mapping, adds validator for context-aware sort_order defaults, updates field definitions and validation logic |
| tests/test_components/test_mode.py | Adds comprehensive tests for new default sort order behavior and interaction with deprecated filter_pol |
| schemas/TerminalComponentModeler.json | Updates JSON schema to reflect new defaults: sort_key: "n_eff", sort_order: "descending" |
| schemas/Simulation.json | Updates JSON schema to reflect new defaults: sort_key: "n_eff", sort_order: "descending" |
| schemas/ModeSimulation.json | Updates JSON schema to reflect new defaults: sort_key: "n_eff", sort_order: "descending" |
| schemas/EMESimulation.json | Updates JSON schema to reflect new defaults: sort_key: "n_eff", sort_order: "descending" |
| docs/notebooks | Updates subproject commit reference |
| docs/faq | Updates subproject commit reference |
| CHANGELOG.md | Documents the breaking change in ModeSortSpec field defaults and behavior |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
2 files reviewed, 2 comments
Additional Comments (1)
Previously, creating a ModeSortSpec with explicit sort_key equal to the default was considered "custom" because the field was explicitly set. Now, both the default ModeSortSpec and one created with sort_key equal to n_eff result in identical objects, so the validator comparison finds them equal. The test test_mode_spec_filter_pol_sort_spec_exclusive expects a ValidationError when filter_pol is used with sort_key set to n_eff, but this will now pass validation because the comparison finds them identical to the default. You need to either update the test to use a genuinely different sort_key like k_eff, or adjust the validator logic to detect when fields were explicitly provided. Prompt To Fix With AIThis is a comment left during a code review.
Path: tidy3d/components/mode_spec.py
Line: 701:718
Comment:
The updated validator logic will break an existing test in tests/test_plugins/test_mode_solver.py at line 1327.
Previously, creating a ModeSortSpec with explicit sort_key equal to the default was considered "custom" because the field was explicitly set. Now, both the default ModeSortSpec and one created with sort_key equal to n_eff result in identical objects, so the validator comparison finds them equal.
The test test_mode_spec_filter_pol_sort_spec_exclusive expects a ValidationError when filter_pol is used with sort_key set to n_eff, but this will now pass validation because the comparison finds them identical to the default.
You need to either update the test to use a genuinely different sort_key like k_eff, or adjust the validator logic to detect when fields were explicitly provided.
How can I resolve this? If you propose a fix, please make it concise. |
|
@greptile-ai what do you think now? |
|
Let me search for the specific code around line 2384 mentioned in the issue: |
https://flow360.atlassian.net/browse/FXC-4643
I realized that the best default values for sort_order are kind of key-dependent, so went beyond the description in the Jira ticket and made them explicitly so. The defaults are automatically put in the description of the field so it's clear for the user.
Note
Introduces key-aware defaulting and minor performance improvements around mode sorting.
sort_keynow required with default"n_eff";sort_orderbecomes optional and is derived via validator fromsort_keyandsort_referenceusing newMODE_DATA_KEY_SORT_ORDERmap; dynamic field description generated.filter_polexclusivity check to allow defaultModeSortSpecbut error on any customized sorting/filtering.ModeSolverData.overlap_sortto skip re-sorting when already ordered; always precomputesort_metric.sort_key="n_eff",sort_orderdefault removed/behavioral); applied across Simulation/Mode/EME/TerminalComponentModeler.filter_polinteractions; CHANGELOG entry updated.Written by Cursor Bugbot for commit d42ee4f. This will update automatically on new commits. Configure here.
Greptile Overview
Greptile Overview
Greptile Summary
Overview
This PR refactors ModeSortSpec to introduce key-aware default values for mode sorting. The main changes are:
Design Intent
The PR addresses the observation that optimal default sort orders are key-dependent. For example, higher n_eff values (more confined modes) should come first (descending), while lower k_eff values (less lossy modes) should come first (ascending). The new design makes this explicit and automatic.
Critical Issues Found
1. Breaking Test in test_mode_solver.py
The validator logic change will cause test_mode_spec_filter_pol_sort_spec_exclusive in tests/test_plugins/test_mode_solver.py at line 1327 to fail. The test expects a ValidationError when filter_pol is used with an explicit sort_key equal to n_eff, but this will now pass validation because it produces an identical object to the default ModeSortSpec.
2. Inconsistency with monitor_data.py
The code in tidy3d/components/data/monitor_data.py at line 2384 checks if sort_spec.sort_key is not None, which will now always be True since sort_key is no longer optional. This makes the else branch at line 2410 unreachable dead code. While this may be intentional (always apply sorting), the implementation should be updated or documented to reflect this change.
Positive Aspects
Confidence Score: 3/5
Important Files Changed
File Analysis
Sequence Diagram
sequenceDiagram participant User participant ModeSortSpec participant Validator participant MODE_DATA_KEY_SORT_ORDER User->>ModeSortSpec: Create ModeSortSpec(sort_key, sort_reference, sort_order) ModeSortSpec->>ModeSortSpec: Set sort_key (default: "n_eff") ModeSortSpec->>ModeSortSpec: Set sort_reference (default: None) ModeSortSpec->>ModeSortSpec: Set sort_order (default: None) ModeSortSpec->>Validator: Run _set_default_sort_order validator alt sort_order is not None Validator->>ModeSortSpec: Return explicit sort_order else sort_reference is not None Validator->>ModeSortSpec: Return "ascending" (closest to reference) else sort_reference is None Validator->>MODE_DATA_KEY_SORT_ORDER: Get default for sort_key MODE_DATA_KEY_SORT_ORDER->>Validator: Return "descending" or "ascending" Validator->>ModeSortSpec: Return key-specific default end ModeSortSpec->>User: Return configured ModeSortSpecImportant Files Changed
File Analysis
Sequence Diagram
sequenceDiagram participant User participant ModeSortSpec participant Validator participant MODE_DATA_KEY_SORT_ORDER User->>ModeSortSpec: Create ModeSortSpec(sort_key, sort_reference, sort_order) ModeSortSpec->>ModeSortSpec: Set sort_key (default: "n_eff") ModeSortSpec->>ModeSortSpec: Set sort_reference (default: None) ModeSortSpec->>ModeSortSpec: Set sort_order (default: None) ModeSortSpec->>Validator: Run _set_default_sort_order validator alt sort_order is not None Validator->>ModeSortSpec: Return explicit sort_order else sort_reference is not None Validator->>ModeSortSpec: Return "ascending" (closest to reference) else sort_reference is None Validator->>MODE_DATA_KEY_SORT_ORDER: Get default for sort_key MODE_DATA_KEY_SORT_ORDER->>Validator: Return "descending" or "ascending" Validator->>ModeSortSpec: Return key-specific default end ModeSortSpec->>User: Return configured ModeSortSpec