4198 raise exceptions on negative fuel ion charge density and temperature profile elements#4217
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4217 +/- ##
==========================================
- Coverage 52.15% 52.15% -0.01%
==========================================
Files 148 148
Lines 30431 30435 +4
==========================================
+ Hits 15870 15872 +2
- Misses 14561 14563 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR aims to surface unphysical plasma states earlier in the tokamak physics workflow by raising exceptions closer to where invalid values are produced, rather than letting them trigger harder-to-diagnose downstream failures.
Changes:
- Added an early exception when
znfuelbecomes negative during plasma composition. - Added an early exception when the Sauter bootstrap routine sees a negative temperature profile element.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
process/models/physics/physics.py |
Adds an early guard for negative znfuel in plasma composition. |
process/models/physics/bootstrap_current.py |
Adds a negative-temperature check in the Sauter bootstrap current path. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # frequently resulting in a confusing bootstrap current error later. | ||
| # Catch early and explicitly instead | ||
| if znfuel < 0.0: | ||
| raise ValueError(f"znfuel is negative: {znfuel}") |
| if znfuel < 0.0: | ||
| raise ValueError(f"znfuel is negative: {znfuel}") |
| # Check for any negative temperature in profile: always fatal eventually, | ||
| # report explicitly at source | ||
| if (tempe < 0).any(): | ||
| raise ValueError("Negative temperature in plasma profile") |
| if (tempe < 0).any(): | ||
| raise ValueError("Negative temperature in plasma profile") |
| # Check for any negative temperature in profile: always fatal eventually, | ||
| # report explicitly at source | ||
| if (tempe < 0).any(): | ||
| raise ValueError("Negative temperature in plasma profile") |
chris-ashe
left a comment
There was a problem hiding this comment.
Co-pilot is recommending adding new negative tests cases to not allow this to silently regress. Its also asking to use ProcessValueError which I think may be incorrect to do in this case
timothy-nunn
left a comment
There was a problem hiding this comment.
Agree with Chris that co-pilot is pretty spot on. Although I think we should using a ProcessValueError here
Both of these unphysical possibilities are always eventually fatal during model evaluation, but were previously confusing due to only causing indirect downstream errors (e.g. in bootstrap current calculation). Now they raise exceptions at source.