Skip to content

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

Open
jonmaddock wants to merge 2 commits intomainfrom
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 2 commits intomainfrom
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
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.15%. Comparing base (9af55b4) to head (83985ef).

Files with missing lines Patch % Lines
process/models/physics/bootstrap_current.py 50.00% 1 Missing ⚠️
process/models/physics/physics.py 50.00% 1 Missing ⚠️
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.
📢 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a 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 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.

# 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}")
Comment on lines +1167 to +1168
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")
Comment on lines +1475 to +1476
if (tempe < 0).any():
raise ValueError("Negative temperature in plasma profile")
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")
Copy link
Copy Markdown
Collaborator

@chris-ashe chris-ashe left a comment

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

Copy link
Copy Markdown
Collaborator

@timothy-nunn timothy-nunn left a comment

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
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