Skip to content

Conversation

@OceanNuclear
Copy link
Contributor

Description

Patches away the RuntimeWarning caused by sqrt(p_plant_electric_net_mw/1200), where p_plant_electric_net_mw may cross over to negative values briefly during the optimization process (but is expected to always converge on a positive value).

Checklist

I confirm that I have completed the following checks:

  • My changes follow the PROCESS style guide
  • I have justified any large differences in the regression tests caused by this pull request in the comments.
  • I have added new tests where appropriate for the changes I have made. (N/A)
  • If I have had to change any existing unit or integration tests, I have justified this change in the pull request comments.
  • If I have made documentation changes, I have checked they render correctly. (N/A)
  • I have added documentation for my change, if appropriate. (N/A)

@OceanNuclear OceanNuclear requested a review from a team as a code owner January 26, 2026 14:54
@OceanNuclear
Copy link
Contributor Author

Closes #4024

@codecov-commenter
Copy link

codecov-commenter commented Jan 26, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.50%. Comparing base (ac78fdb) to head (0f6eb3a).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
process/costs.py 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4065      +/-   ##
==========================================
- Coverage   46.60%   46.50%   -0.11%     
==========================================
  Files         122      124       +2     
  Lines       28711    28961     +250     
==========================================
+ Hits        13381    13468      +87     
- Misses      15330    15493     +163     

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

@timothy-nunn timothy-nunn linked an issue Jan 28, 2026 that may be closed by this pull request
@timothy-nunn timothy-nunn self-assigned this Jan 28, 2026
@je-cook je-cook added the Cost model Relating to cost models label Feb 2, 2026
Copy link
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.

I've spoken with quite a few people about this, some of these comments and concerns are written in the original issue.

The model is clearly flawed because it uses net electric to try and estimate the O&M cost. This is done because all O&M models in the literature are fits on data from existing fission/gas plants. I suspect net electric is used here as a loose proxy for plant complexity.

My suggestion is to accept and merge this PR because it will fix the negative square root, and does no harm: the cost model will produce a NaN if given a negative number and so producing a 0 instead is no worse.

An issue should be created where we can discuss and plan how to produce more realistic O&M costs that rely on something a bit more meaningful that net electric.

@geograham @j-a-foster how does this sound to you? If we all agree, I will merge this PR, create an issue and we can discuss our concerns further there and plan if/how we want to fix it.

process/costs.py Outdated

annoam = cost_variables.ucoam[cost_variables.lsa - 1] * np.sqrt(
heat_transport_variables.p_plant_electric_net_mw / 1200.0e0
np.clip(heat_transport_variables.p_plant_electric_net_mw, 0, np.inf)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add a warning when the net electric is negative and the value will be clipped?

@geograham
Copy link
Collaborator

I've spoken with quite a few people about this, some of these comments and concerns are written in the original issue.

The model is clearly flawed because it uses net electric to try and estimate the O&M cost. This is done because all O&M models in the literature are fits on data from existing fission/gas plants. I suspect net electric is used here as a loose proxy for plant complexity.

My suggestion is to accept and merge this PR because it will fix the negative square root, and does no harm: the cost model will produce a NaN if given a negative number and so producing a 0 instead is no worse.

An issue should be created where we can discuss and plan how to produce more realistic O&M costs that rely on something a bit more meaningful that net electric.

@geograham @j-a-foster how does this sound to you? If we all agree, I will merge this PR, create an issue and we can discuss our concerns further there and plan if/how we want to fix it.

I think this makes sense - a warning about clipped net electric in the meantime is also a good idea.

@OceanNuclear
Copy link
Contributor Author

Funnily enough that might bring us almost full circle back to issue #4024; but in some way progress is still made by identifying the bug. @timothy-nunn If you're happy with @geograham 's solution then I'll add a warning back in.

@timothy-nunn
Copy link
Collaborator

timothy-nunn commented Feb 12, 2026

Funnily enough that might bring us almost full circle back to issue #4024; but in some way progress is still made by identifying the bug. @timothy-nunn If you're happy with @geograham 's solution then I'll add a warning back in.

Hi @OceanNuclear, I think lets add the warning. This warning won't be a cryptic 'divide by 0' warning and it will reported as a model warning (logger.warning) and so it will be a lot more useful than the previous divide by 0 warning.

… of the method coelc to warn in case p_plant_electric_net_mw is negative. Also caught a third place where sqrt_p_plant_electric_net_mw is needed .(missed earlier as it was commented out)
Copy link
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.

Just improving the clarity of the error message

Clarified what's the purpose of the calculation inside the warning.

Co-authored-by: Timothy <75321887+timothy-nunn@users.noreply.github.com>
Copy link
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.

The /1200 was in the square root before

@timothy-nunn timothy-nunn removed the request for review from j-a-foster February 12, 2026 11:42
@timothy-nunn timothy-nunn merged commit 44702b1 into main Feb 12, 2026
10 checks passed
@timothy-nunn timothy-nunn deleted the ocean/pc-4024 branch February 12, 2026 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Cost model Relating to cost models

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Divide by zero warnings in costs.py

5 participants