Skip to content

4198 raise exceptions on negative fuel ion charge density and temperature profile elements#4217

Open
jonmaddock wants to merge 6 commits into
mainfrom
4198-raise-exceptions-on-negative-fuel-ion-charge-density-and-temperature-profile-elements
Open

4198 raise exceptions on negative fuel ion charge density and temperature profile elements#4217
jonmaddock wants to merge 6 commits into
mainfrom
4198-raise-exceptions-on-negative-fuel-ion-charge-density-and-temperature-profile-elements

Conversation

@jonmaddock

Copy link
Copy Markdown
Contributor

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.

@jonmaddock
jonmaddock requested a review from a team as a code owner May 1, 2026 14:27
@jonmaddock
jonmaddock requested a review from chris-ashe May 1, 2026 14:28
@codecov-commenter

codecov-commenter commented May 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.64%. Comparing base (84679f5) to head (8e81ca2).

Files with missing lines Patch % Lines
process/models/physics/physics.py 50.00% 1 Missing ⚠️
process/models/physics/profiles.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4217   +/-   ##
=======================================
  Coverage   48.64%   48.64%           
=======================================
  Files         151      151           
  Lines       29703    29708    +5     
=======================================
+ Hits        14449    14452    +3     
- Misses      15254    15256    +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 znfuel becomes 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.

Comment thread process/models/physics/physics.py Outdated
Comment thread process/models/physics/physics.py Outdated
Comment on lines +1167 to +1168
if znfuel < 0.0:
raise ValueError(f"znfuel is negative: {znfuel}")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree: we can't have regression tests for every eventuality. I don't think a unit test here adds any real benefit.

Comment thread process/models/physics/bootstrap_current.py Outdated
Comment on lines +1475 to +1476
if (tempe < 0).any():
raise ValueError("Negative temperature in plasma profile")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is silly, as this is would only "regress" if someone deleted this exception.

Comment on lines +1473 to +1476
# 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 chris-ashe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 timothy-nunn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with Chris that co-pilot is pretty spot on. Although I think we should using a ProcessValueError here

@timothy-nunn timothy-nunn self-assigned this May 5, 2026
jonmaddock and others added 4 commits July 24, 2026 11:30
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…harge-density-and-temperature-profile-elements

@timothy-nunn timothy-nunn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy with changes. Will await @chris-ashe since he also reviewed before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Raise exceptions on negative fuel ion charge density and temperature profile elements

5 participants