Skip to content

Add pulse timings dataclass - #4497

Open
chris-ashe wants to merge 13 commits into
mainfrom
add_pulse_timings_dataclass
Open

Add pulse timings dataclass#4497
chris-ashe wants to merge 13 commits into
mainfrom
add_pulse_timings_dataclass

Conversation

@chris-ashe

@chris-ashe chris-ashe commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

This pull request refactors how pulse timing and cumulative time points are handled throughout the codebase by introducing and consistently applying the PulseTimings class. This change improves code clarity, reduces duplication, and centralizes pulse timing logic, making it easier to maintain and extend. The update affects plotting routines, model calculations, and output formatting for pulse-related data.

Pulse timing refactor and centralization:

  • Replaced manual cumulative time calculations in plotting functions (e.g., plot_current_profiles_over_time, plot_system_power_profiles_over_time, plot_cs_stress_time_profile) with usage of the new PulseTimings class, ensuring consistent time axis generation and annotation across all plots.

  • Updated model logic in physics.py and pfcoil.py to use PulseTimings for all derived pulse timing values, such as total pulse time, plasma-present time, and no-burn time, removing duplicated cumulative sum logic.

  • Modified power system models (power.py) to pass PulseTimings as an argument to the PF coil power calculation routines (pfpwr), ensuring all power calculations use unified pulse timing data.
    Output and labeling improvements:

  • Standardized the use of pulse time labels and cumulative time points in output routines and plot annotations, using properties from PulseTimings for axis tick labels and time column headers.

Cleanup and removal of legacy code:

  • Removed legacy time label arrays and manual cumulative time calculations from times_variables.py and related model files, reducing code redundancy.

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

codecov-commenter commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.67677% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.21%. Comparing base (6dbb302) to head (2e00492).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
process/core/io/plot/summary.py 14.28% 18 Missing ⚠️
process/models/pfcoil.py 16.66% 5 Missing ⚠️
process/models/pulse.py 90.90% 5 Missing ⚠️
process/models/physics/physics.py 33.33% 2 Missing ⚠️
process/models/power.py 85.71% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4497      +/-   ##
==========================================
- Coverage   49.30%   49.21%   -0.09%     
==========================================
  Files         151      152       +1     
  Lines       29611    29836     +225     
==========================================
+ Hits        14599    14684      +85     
- Misses      15012    15152     +140     

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

@chris-ashe
chris-ashe marked this pull request as ready for review August 4, 2026 12:31
@chris-ashe
chris-ashe requested a review from a team as a code owner August 4, 2026 12:31
@clmould clmould self-assigned this Aug 5, 2026
Comment thread process/models/power.py
Comment thread process/models/power.py Outdated
Comment thread process/models/power.py Outdated
Comment thread tests/unit/models/test_power.py Outdated
Comment thread process/models/power.py Outdated
Comment thread process/core/io/plot/summary.py
Comment thread process/models/pulse.py Outdated
return len(self.total_pulse_cumulative)

@property
def n_pulse_points_intervals_total(self) -> int:

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.

This doesn't seem to be getting used anywhere ?

Comment thread process/models/pulse.py Outdated
Comment thread process/models/power.py Outdated
Comment thread process/models/pulse.py
Comment on lines +32 to +49
point_abbreviations: ClassVar[tuple[str, ...]] = (
"BOP",
"EOR",
"BOF",
"EOF",
"EOP",
"Dwell",
)

point_labels: ClassVar[tuple[str, ...]] = (
"Coil precharge",
"$I_{\\text{p}}$ Ramp-Up",
"Fusion ramp",
"Burn",
"$I_{\\text{p}}$ ramp-down",
"Dwell",
"Restart pulse",
)

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.

Since these are constants, can they be moved to the top of this file instead please?

@chris-ashe chris-ashe Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I believe it is best to keep them as class variables contained withing the dataclass. Meaning everything is kept in one place. I have added a __post_init__ that checks that the number of labels always matches the number of points in the dataclass. This also means everything is in one place and checked if we ever want to add or change the time points

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.

This makes sense to keep them here. Could the variable names be capitalised please? Since they are still behaving as constants, so would make it clearer to a user

…naming and enhance validation in PulseTimings dataclass
Comment thread process/models/pulse.py
Comment thread process/models/pulse.py Outdated
Comment thread process/models/power.py Outdated
chris-ashe and others added 2 commits August 11, 2026 10:08
Co-authored-by: clmould <86794332+clmould@users.noreply.github.com>
@chris-ashe
chris-ashe requested a review from clmould August 11, 2026 09:08

@clmould clmould 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.

Just 1 small change
Also could you fix the pre-commit failure too please?

Comment thread process/models/pulse.py
Comment on lines +32 to +49
point_abbreviations: ClassVar[tuple[str, ...]] = (
"BOP",
"EOR",
"BOF",
"EOF",
"EOP",
"Dwell",
)

point_labels: ClassVar[tuple[str, ...]] = (
"Coil precharge",
"$I_{\\text{p}}$ Ramp-Up",
"Fusion ramp",
"Burn",
"$I_{\\text{p}}$ ramp-down",
"Dwell",
"Restart pulse",
)

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.

This makes sense to keep them here. Could the variable names be capitalised please? Since they are still behaving as constants, so would make it clearer to a user

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants