Skip to content

Add pulse timings dataclass - #4497

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

Add pulse timings dataclass#4497
chris-ashe wants to merge 11 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 65.71429% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.23%. Comparing base (6dbb302) to head (438f7ee).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
process/core/io/plot/summary.py 13.04% 20 Missing ⚠️
process/models/pulse.py 89.65% 6 Missing ⚠️
process/models/pfcoil.py 16.66% 5 Missing ⚠️
process/models/physics/physics.py 25.00% 3 Missing ⚠️
process/models/power.py 85.71% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4497      +/-   ##
==========================================
- Coverage   49.30%   49.23%   -0.07%     
==========================================
  Files         151      152       +1     
  Lines       29611    29810     +199     
==========================================
+ Hits        14599    14677      +78     
- Misses      15012    15133     +121     

☔ 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

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.

Atm power_profiles_over_time() is still calculating t_steps within:

Image

but since pf_active_cumulative has replaced this, can pf_active_cumulative be an input to power_profiles_over_time()?

Comment thread process/models/power.py Outdated
return e_loss_pf_store_j + e_loss_pf_psu_j + e_loss_pf_bus_j

def pfpwr(self, output: bool):
def pfpwr(self, output: bool, PulseTimings: PulseTimings = PulseTimings):

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.

Suggested change
def pfpwr(self, output: bool, PulseTimings: PulseTimings = PulseTimings):
def pfpwr(self, output: bool, pulse_timings: PulseTimings):

Comment thread process/models/power.py Outdated
output:

"""
pulse_timings = PulseTimings

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.

Suggested change
pulse_timings = PulseTimings

Comment thread tests/unit/models/test_power.py Outdated
)

power.pfpwr(output=False)
power.pfpwr(output=False, PulseTimings=pfpwrparam.pulse_timings)

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.

Suggested change
power.pfpwr(output=False, PulseTimings=pfpwrparam.pulse_timings)
power.pfpwr(output=False, pulse_timings=pfpwrparam.pulse_timings)

Comment thread process/models/power.py Outdated
self.pfpwr(output=True)
self.pfpwr(
output=True,
PulseTimings=PulseTimings(

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.

Suggested change
PulseTimings=PulseTimings(
pulse_timings=PulseTimings(

"Between Pulse",
"Restart Pulse",
],
pulse_timings.point_labels,

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.

Some overlap again in the labels

Image

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.

This has always been the case and is not caused by this PR

Comment thread process/models/pulse.py
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

@dataclass(frozen=True, slots=True)
class PulseTimings:
"""Class to hold the timing parameters for a pulsed reactor."""

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.

Suggested change
"""Class to hold the timing parameters for a pulsed reactor."""
"""Dataclass to hold the timing parameters for a pulsed reactor."""

Comment thread process/models/power.py Outdated
return e_loss_pf_store_j + e_loss_pf_psu_j + e_loss_pf_bus_j

def pfpwr(self, output: bool):
def pfpwr(self, output: bool, PulseTimings: PulseTimings = PulseTimings):

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.

Can pulse_timings be added to the docstring 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.

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

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

…naming and enhance validation in PulseTimings dataclass
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