Skip to content

Add figure of merit enum#4272

Open
chris-ashe wants to merge 9 commits into
mainfrom
add_figure_merit_enum
Open

Add figure of merit enum#4272
chris-ashe wants to merge 9 commits into
mainfrom
add_figure_merit_enum

Conversation

@chris-ashe
Copy link
Copy Markdown
Collaborator

@chris-ashe chris-ashe commented May 22, 2026

This pull request refactors how figures of merit (FoM) are represented and used throughout the PROCESS codebase. The main improvement is the introduction of a new FiguresOfMerit enumeration in numerics.py, replacing the previous use of the lablmm list and scattered constants. This makes the code more maintainable, type-safe, and easier to extend. All references to figures of merit in both code and documentation have been updated to use this new enum, and related descriptions and logic have been centralized.

Core Refactoring:

  • Introduced the FiguresOfMerit enum in process/data_structure/numerics.py to represent all available figures of merit, each with an associated integer value and description.
  • Removed the legacy lablmm list and the OBJECTIVE_NAMES dictionary, updating all code to use the new enum for descriptions and names.

Code Updates:

  • Refactored all code references to figures of merit to use FiguresOfMerit, including in init.py, scan.py, and plotting modules, ensuring consistent and clear usage.
  • Updated the objective function for case 5 to use big_q_plasma directly, aligning with the new enum's semantics.

Documentation Updates:

  • Updated documentation to reference FiguresOfMerit instead of lablmm, and clarified instructions for adding new figures of merit.

These changes modernize and centralize how figures of merit are handled, making future extensions and maintenance significantly easier.## 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.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 22, 2026

Codecov Report

❌ Patch coverage is 44.59459% with 41 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.17%. Comparing base (46626d2) to head (5547521).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
process/core/solver/objectives.py 2.56% 38 Missing ⚠️
process/core/io/plot/summary.py 33.33% 2 Missing ⚠️
process/core/scan.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4272      +/-   ##
==========================================
+ Coverage   50.13%   50.17%   +0.04%     
==========================================
  Files         151      151              
  Lines       29349    29378      +29     
==========================================
+ Hits        14714    14741      +27     
- Misses      14635    14637       +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.

@chris-ashe chris-ashe marked this pull request as ready for review May 22, 2026 15:42
@chris-ashe chris-ashe requested a review from a team as a code owner May 22, 2026 15:42
Copilot AI review requested due to automatic review settings May 22, 2026 15:42
@chris-ashe chris-ashe changed the title Add figure merit enum Add figure of merit enum May 22, 2026
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 refactors PROCESS’s “figure of merit” (FoM) handling by introducing a centralized FiguresOfMerit IntEnum in process/data_structure/numerics.py, replacing the legacy lablmm list and the OBJECTIVE_NAMES mapping, and updating call sites in the solver, scan/output, plotting, and documentation.

Changes:

  • Adds FiguresOfMerit enum (ID + description) and removes lablmm initialization/usage.
  • Refactors objective evaluation and various outputs/plots to derive FoM labels from the enum.
  • Updates documentation to refer to FiguresOfMerit rather than lablmm.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
process/data_structure/numerics.py Introduces FiguresOfMerit enum and removes legacy lablmm list.
process/core/solver/objectives.py Replaces OBJECTIVE_NAMES and switches FoM selection logic to enum-based dispatch.
process/core/scan.py Uses enum descriptions for objective function naming in post-optimise output.
process/core/io/plot/summary.py Replaces objective-name mapping with enum usage in plot headers/cover page text.
process/core/io/plot/solutions.py Uses enum descriptions when falling back to minmax for older MFiles.
process/core/init.py Uses enum descriptions when printing the run summary header.
documentation/source/io/input-guide.md Updates minmax help text to reference FiguresOfMerit.
documentation/source/development/add-vars.md Updates “add FoM” instructions to point to numerics.py + enum.
Comments suppressed due to low confidence (1)

process/core/solver/objectives.py:55

  • objective_function compares against enum members that don't exist in FiguresOfMerit (e.g. TF_PF_COIL_POWER, FUSION_GAIN, INJECTED_POWER, PLANT_AVAILABILITY, etc.). This will raise AttributeError at runtime. Update these comparisons to use the actual enum member names defined in process/data_structure/numerics.py (or rename the enum members to match the names used here) so the mapping for cases 4/5/11/15/16/18/19 is consistent.
    if figure_of_merit == FiguresOfMerit.MAJOR_RADIUS:
        objective_metric = 0.2 * physics_variables.rmajor
    elif figure_of_merit == FiguresOfMerit.NEUTRON_WALL_LOAD:
        objective_metric = physics_variables.pflux_fw_neutron_mw
    elif figure_of_merit == FiguresOfMerit.TF_PF_COIL_POWER:
        objective_metric = (tfcoil_variables.tfcmw + 1e-3 * data.pf_power.srcktpm) / 10.0
    elif figure_of_merit == FiguresOfMerit.FUSION_GAIN:
        objective_metric = data.current_drive.big_q_plasma
    elif figure_of_merit == FiguresOfMerit.COST_OF_ELECTRICITY:

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread process/core/scan.py
)

objf_name = f'"{numerics.lablmm[abs(numerics.minmax) - 1]}"'
objf_name = f'"{FiguresOfMerit(abs(numerics.minmax)).description}"'
Comment thread process/core/init.py
fom_string = data_structure.numerics.lablmm[
abs(data_structure.numerics.minmax) - 1
]
fom_string = FiguresOfMerit(abs(data_structure.numerics.minmax)).description
Comment on lines 448 to 451
numerics.init_numerics()
objf_list = {
numerics.lablmm[int(abs(minmax)) - 1] for minmax in diffs_df["minmax"]
FiguresOfMerit(abs(minmax)).description for minmax in diffs_df["minmax"]
}
Comment on lines 7824 to 7826
else (
f"!{OBJECTIVE_NAMES[abs(int(mfile.get('minmax', scan=-1)))]}",
f"!{FiguresOfMerit(abs(int(mfile.get('minmax', scan=-1)))).name}",
"Optimising:",
Comment thread process/core/solver/objectives.py Outdated
Comment on lines 41 to 42
figure_of_merit = FiguresOfMerit(abs(minmax))

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

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Comment thread process/core/solver/objectives.py Outdated
elif figure_of_merit == FiguresOfMerit.FUSION_GAIN_BURN_TIME:
objective_metric = -0.5 * (data.current_drive.big_q_plasma / 20.0) - 0.5 * (
data.times.t_plant_pulse_burn / 7200.0
)
Comment thread documentation/source/io/input-guide.md
chris-ashe and others added 3 commits May 22, 2026 17:07
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants