-
Notifications
You must be signed in to change notification settings - Fork 67
feat(FXC-4519): Added check to warn of duplicated voltage values #3108
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
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
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 adds validation to the DCVoltageSource class to warn users when duplicate voltage values are present in the voltage array. The implementation correctly handles the special case where 0.0 and -0.0 are treated as the same value.
- Added a new validator
check_repeated_voltagethat warns when duplicate voltage values are detected - Implemented special handling to normalize
0.0and-0.0as the same value before checking for duplicates - Added comprehensive test coverage for various duplicate scenarios
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tidy3d/components/spice/sources/dc.py | Added new validator method check_repeated_voltage with logic to detect and warn about duplicate voltage values, including special handling for zero values |
| tests/test_components/test_heat_charge.py | Added test function test_repeated_voltage_warning with multiple test cases covering unique values, repeated values, 0/-0 duplicates, and multiple repeated values |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
48dc80e to
54840fd
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.
3 files reviewed, 1 comment
54840fd to
b93f677
Compare
|
@greptile update summary |
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.
3 files reviewed, 1 comment
008c617 to
c81e649
Compare
Diff CoverageDiff: origin/develop...HEAD, staged and unstaged changes
Summary
|
| "Duplicate voltage values detected in 'voltage' array. " | ||
| f"Found {len(val)} values but only {len(unique_values)} are unique. " | ||
| "Note: '0' and '-0' are considered the same value." | ||
| ) |
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.
Generally looks good, but the one thing that bugs me a little is there's no guaranteed correspondence between what's validated here and what values the solver will compute at. Would be nice to have a single source of truth for the "computed voltages", which also e.g. defines the tolerance within which two values are considered identical.
Greptile Summary
Added validation to
DCVoltageSourcethat warns users when duplicate voltage values are detected in thevoltagearray. The implementation treats0and-0as the same value by normalizing zeros before checking for duplicates.check_repeated_voltagevalidator that normalizes zero values and usesnp.unique()to detect duplicatesNote: Previous thread comments identified a floating-point precision issue - the current implementation only normalizes zeros but uses direct equality for non-zero values via
np.unique(), which may miss near-duplicate floating-point values like1.0and1.0000000001.Confidence Score: 4/5
tidy3d/components/spice/sources/dc.pyregarding the floating-point comparison approach discussed in previous commentsImportant Files Changed
Sequence Diagram
sequenceDiagram participant User participant DCVoltageSource participant Validator participant numpy as NumPy participant Logger User->>DCVoltageSource: Create with voltage array DCVoltageSource->>Validator: @validator("voltage") check_voltage Validator->>Validator: Check for infinite values Validator-->>DCVoltageSource: Return validated values DCVoltageSource->>Validator: @validator("voltage") check_repeated_voltage Validator->>numpy: np.isclose(val, 0, atol=1e-10) numpy-->>Validator: Boolean mask for zeros Validator->>numpy: np.where(mask, 0.0, val) numpy-->>Validator: Normalized array (zeros unified) Validator->>numpy: np.unique(normalized) numpy-->>Validator: Unique values array Validator->>Validator: Compare len(unique_values) < len(val) alt Duplicates found Validator->>Logger: log.warning(duplicate message) Logger-->>User: Display warning end Validator-->>DCVoltageSource: Return original values DCVoltageSource-->>User: Instance created