-
Notifications
You must be signed in to change notification settings - Fork 69
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
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
tidy3d/components/spice/sources/dc.pyLines 82-90 82 Uses sorted comparison to group values that are practically equal
83 due to floating-point representation differences (e.g., single vs double precision).
84 """
85 if len(arr) == 0:
! 86 return 0
87 sorted_arr = np.sort(arr)
88 # Count values that are "different enough" from their predecessor
89 unique_count = 1
90 for i in range(1, len(sorted_arr)): |
a20771f to
3d3695c
Compare
3d3695c to
80e8e39
Compare
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 createdNote
Introduces a tolerance-based warning for duplicate entries in
DCVoltageSource.voltage, normalizing0/-0and logging a warning when repeats are detected._count_unique_with_toleranceand a@validator(check_repeated_voltage) indc.pyto detect near-duplicates vianp.isclose, treating0and-0as the sametest_repeated_voltage_warningto assert warning behavior for unique values, exact duplicates,0vs-0, and multiple repeatsCHANGELOG.mdto document the new validationWritten by Cursor Bugbot for commit 80e8e39. This will update automatically on new commits. Configure here.