Skip to content

Conversation

@chris-ashe
Copy link
Collaborator

@chris-ashe chris-ashe commented Jan 20, 2026

This pull request introduces a new PlasmaBeta class to centralize and standardize plasma beta calculations across the codebase. The changes refactor existing code to use this class, update dependencies, and add new unit tests for its methods. The most important changes are grouped below:

Core Refactoring and Architecture:

  • Added a new PlasmaBeta class to process.physics and refactored the codebase to use this class for all plasma beta-related calculations, replacing previous standalone functions.

  • Updated the initialization of major classes (main.py, stellarator.py) to instantiate and pass PlasmaBeta objects where needed, ensuring consistent access to beta calculations throughout the application.
    Code Cleanup and Removal:

  • Removed the now-obsolete fast_alpha_beta function from process/physics_functions.py, migrating its logic to the new PlasmaBeta class.

  • Updated all usages of beta calculation functions to use the new class methods, including replacing calls in the Stellarator model.

Testing and Validation:

  • Refactored unit tests in test_physics.py and test_stellarator.py to use the new PlasmaBeta class and its methods, ensuring all previous tests remain valid and comprehensive.
  • Added new unit tests for additional PlasmaBeta methods, such as calculate_normalised_beta and calculate_plasma_energy_from_beta, to improve coverage and reliability.

Dependency and Import Updates:

  • Cleaned up imports in affected files to remove unused beta calculation functions and ensure all references point to the new PlasmaBeta class.

These changes improve maintainability by centralizing plasma beta logic, reduce code duplication, and enhance test coverage.## Description

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.
  • 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.
  • I have added documentation for my change, if appropriate.

@chris-ashe chris-ashe self-assigned this Jan 20, 2026
@chris-ashe chris-ashe added Physics Relating to the physics models Refactor labels Jan 20, 2026
@codecov-commenter
Copy link

codecov-commenter commented Jan 20, 2026

Codecov Report

❌ Patch coverage is 35.39823% with 73 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.70%. Comparing base (5ea7543) to head (434b971).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
process/physics.py 34.86% 71 Missing ⚠️
process/main.py 50.00% 1 Missing ⚠️
process/stellarator.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4053      +/-   ##
==========================================
+ Coverage   46.49%   46.70%   +0.20%     
==========================================
  Files         123      123              
  Lines       28777    29124     +347     
==========================================
+ Hits        13381    13603     +222     
- Misses      15396    15521     +125     

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

@chris-ashe chris-ashe force-pushed the create_beta_class branch 3 times, most recently from 3057b2c to 0d66af1 Compare January 21, 2026 08:36
… redundant function from physics_functions.py
@chris-ashe chris-ashe marked this pull request as ready for review January 21, 2026 10:11
Comment on lines +8587 to +8597
@property
def beta_norm_max_model_map(self):
"""Mapping of beta norm max model indices to their calculated values."""
return {
0: physics_variables.beta_norm_max,
1: physics_variables.beta_norm_max_wesson,
2: physics_variables.beta_norm_max_original_scaling,
3: physics_variables.beta_norm_max_menard,
4: physics_variables.beta_norm_max_thloreus,
5: physics_variables.beta_norm_max_stambaugh,
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you turn this into an Enum

Comment on lines +8781 to +8782
@staticmethod
def calculate_beta_limit_from_norm(
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the speed impact of no longer JIT compiling this method?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you move the calculations that are not depended on into the new Beta class and add run and output methods to this class.

That way in the caller we can do models.beta.run() (or models.beta.output()) which will run the Beta model (and output if appropriate). Some of the variables will need a bit of untangling (e.g. beta_poloidal_vol_avg which is used later on in physics to calculate f_c_plasma_bootstrap_sakai) but this can be done in a later PR.

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

Labels

Physics Relating to the physics models Refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants