-
Notifications
You must be signed in to change notification settings - Fork 66
fix: raise error when _finalized simulation fails #2913
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
fix: raise error when _finalized simulation fails #2913
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, no comments
Diff CoverageDiff: origin/develop...HEAD, staged and unstaged changes
Summary
|
momchil-flex
left a comment
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.
Yeah it's kind of the other way round, if you raise a Tidy3dError subclass, it will also get log.error-ed before exiting.
Do you want to also add anything about the frame = {} in this PR?
caseyflex
left a comment
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.
Why not just allow the original exception to be raised? or raise a new exception from it? What was the original reason for the try-catch logic?
Actually, it seems like a common thing throughout tidy3d: setting |
to add the additional info that simulation fails after trying to add those auxiliary structures. For example: instead of just |
|
@dbochkov-flexcompute what about this: |
Works too, just doesn't log the error message. I don't remember to what extent it is import for propagating error information in GUI. I will switch to |
3d837ec to
15a4378
Compare
|
Seems good to me, we merge, @caseyflex ? |
Sounds good to me |

forgot that
log.error()doesn't raise an actual errorGreptile Overview
Updated On: 2025-10-20 23:29:22 UTC
Greptile Summary
This PR fixes a critical bug in simulation validation where
log.error()was incorrectly assumed to raise an exception. The_validate_finalized()method inSimulationnow properly captures and re-raises exceptions after logging, ensuring that validation failures when adding mode source PEC frames are surfaced to users rather than silently ignored. The corresponding test was updated to call_validate_finalized()explicitly instead of accessing the_finalizedproperty directly, ensuring the validation logic is properly exercised. This change aligns with the codebase's error handling pattern where validation failures must raise exceptions, not just log messages, particularly important for pre-upload validation that prevents invalid simulations from being submitted.Important Files Changed
Changed Files
_validate_finalized()to properly capture and re-raise exceptions after logging, ensuring validation errors are not silently ignored_validate_finalized()method instead of accessing_finalizedproperty; inconsistency remains on line 42 where_finalizedis still accessed directlyConfidence score: 4/5
_finalizeddirectly without validation, which may or may not be intentional)_finalizedaccess should also be updated to_validate_finalized()Sequence Diagram
sequenceDiagram participant Test as test_source_absorber_frames participant Simulation as Simulation participant Log as log participant Exception as ValidationError Note over Test: Create bad_sim with conflicting<br/>mode source frame and projection monitor Test->>Simulation: bad_sim._validate_finalized() activate Simulation Simulation->>Simulation: try: _ = self._finalized activate Simulation Note over Simulation: Validation fails due to<br/>incompatible components Simulation->>Exception: Exception raised deactivate Simulation Simulation->>Log: log.error("Simulation fails after<br/>requested mode source PEC frames<br/>are added. Please inspect '._finalized'.") Simulation->>Exception: raise e deactivate Simulation Exception-->>Test: ValidationError raised Note over Test: pytest.raises(ValidationError)<br/>assertion passesContext used:
dashboard- Uselog.errorinstead ofassertstatements for error handling in production code. (source)