Add pulse timings dataclass - #4497
Conversation
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
…operties for PF coil active phases
…roved timing management
…d timing management
…mproved pulse timing management
…nd integrate point abbreviations for improved clarity in timing management
…ings dataclass for improved clarity in timing representation
| 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): |
There was a problem hiding this comment.
| def pfpwr(self, output: bool, PulseTimings: PulseTimings = PulseTimings): | |
| def pfpwr(self, output: bool, pulse_timings: PulseTimings): |
| output: | ||
|
|
||
| """ | ||
| pulse_timings = PulseTimings |
There was a problem hiding this comment.
| pulse_timings = PulseTimings |
| ) | ||
|
|
||
| power.pfpwr(output=False) | ||
| power.pfpwr(output=False, PulseTimings=pfpwrparam.pulse_timings) |
There was a problem hiding this comment.
| power.pfpwr(output=False, PulseTimings=pfpwrparam.pulse_timings) | |
| power.pfpwr(output=False, pulse_timings=pfpwrparam.pulse_timings) |
| self.pfpwr(output=True) | ||
| self.pfpwr( | ||
| output=True, | ||
| PulseTimings=PulseTimings( |
There was a problem hiding this comment.
| PulseTimings=PulseTimings( | |
| pulse_timings=PulseTimings( |
| "Between Pulse", | ||
| "Restart Pulse", | ||
| ], | ||
| pulse_timings.point_labels, |
There was a problem hiding this comment.
This has always been the case and is not caused by this PR
| return len(self.total_pulse_cumulative) | ||
|
|
||
| @property | ||
| def n_pulse_points_intervals_total(self) -> int: |
There was a problem hiding this comment.
This doesn't seem to be getting used anywhere ?
|
|
||
| @dataclass(frozen=True, slots=True) | ||
| class PulseTimings: | ||
| """Class to hold the timing parameters for a pulsed reactor.""" |
There was a problem hiding this comment.
| """Class to hold the timing parameters for a pulsed reactor.""" | |
| """Dataclass to hold the timing parameters for a pulsed reactor.""" |
| 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): |
There was a problem hiding this comment.
Can pulse_timings be added to the docstring please
| 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", | ||
| ) |
There was a problem hiding this comment.
Since these are constants, can they be moved to the top of this file instead please?
There was a problem hiding this comment.
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


This pull request refactors how pulse timing and cumulative time points are handled throughout the codebase by introducing and consistently applying the
PulseTimingsclass. 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 newPulseTimingsclass, ensuring consistent time axis generation and annotation across all plots.Updated model logic in
physics.pyandpfcoil.pyto usePulseTimingsfor 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 passPulseTimingsas 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
PulseTimingsfor axis tick labels and time column headers.Cleanup and removal of legacy code:
times_variables.pyand related model files, reducing code redundancy.Checklist
I confirm that I have completed the following checks: