Skip to main content

scientific_workflow/runtime/
summary.rs

1//! Read-only successful runtime summaries.
2
3use std::path::{Path, PathBuf};
4
5/// Successful completion facts for one crate-level run.
6#[derive(Clone, Debug)]
7pub struct RunSummary {
8    pub(crate) output_directory: PathBuf,
9    pub(crate) replicates: Box<[ReplicateRunSummary]>,
10}
11
12impl RunSummary {
13    /// Returns the uniquely inferred execution output directory.
14    pub fn output_directory(&self) -> &Path {
15        &self.output_directory
16    }
17
18    /// Returns successful replicate summaries in ascending index order.
19    pub fn replicates(&self) -> &[ReplicateRunSummary] {
20        &self.replicates
21    }
22}
23
24/// Successful completion facts for one replicate.
25#[derive(Clone, Debug)]
26pub struct ReplicateRunSummary {
27    pub(crate) index: u64,
28    pub(crate) output_directory: PathBuf,
29    pub(crate) phases: Box<[PhaseRunSummary]>,
30}
31
32impl ReplicateRunSummary {
33    /// Returns the zero-based replicate index.
34    pub const fn index(&self) -> u64 {
35        self.index
36    }
37
38    /// Returns the isolated replicate output directory.
39    pub fn output_directory(&self) -> &Path {
40        &self.output_directory
41    }
42
43    /// Returns phase summaries in dependency execution order.
44    pub fn phases(&self) -> &[PhaseRunSummary] {
45        &self.phases
46    }
47}
48
49/// Successful completion facts for one phase.
50#[derive(Clone, Debug)]
51pub struct PhaseRunSummary {
52    pub(crate) name: Box<str>,
53    pub(crate) tasks: Box<[TaskRunSummary]>,
54}
55
56impl PhaseRunSummary {
57    /// Returns the stable phase key.
58    pub fn name(&self) -> &str {
59        &self.name
60    }
61
62    /// Returns task summaries in deterministic plan order.
63    pub fn tasks(&self) -> &[TaskRunSummary] {
64        &self.tasks
65    }
66}
67
68/// Kind of workload completed by a task.
69#[non_exhaustive]
70#[derive(Clone, Copy, Debug, Eq, PartialEq)]
71pub enum TaskRunKind {
72    /// A registered scientific execution-unit invocation.
73    Model,
74    /// An external executable program invocation.
75    Program,
76}
77
78/// Successful completion facts for one model inside an execution unit.
79#[derive(Clone, Debug)]
80pub struct ModelRunSummary {
81    pub(crate) identity: Box<str>,
82    pub(crate) final_iteration: u64,
83    pub(crate) output_directory: PathBuf,
84}
85
86impl ModelRunSummary {
87    /// Returns the stable model identity supplied by the execution unit.
88    pub fn identity(&self) -> &str {
89        &self.identity
90    }
91
92    /// Returns this model's final scientific iteration.
93    pub const fn final_iteration(&self) -> u64 {
94        self.final_iteration
95    }
96
97    /// Returns this model's completed recording directory.
98    pub fn output_directory(&self) -> &Path {
99        &self.output_directory
100    }
101}
102
103/// Successful completion facts for one generic task invocation.
104#[derive(Clone, Debug)]
105pub struct TaskRunSummary {
106    pub(crate) identity: Box<str>,
107    pub(crate) kind: TaskRunKind,
108    pub(crate) model: Option<Box<str>>,
109    pub(crate) program: Option<PathBuf>,
110    pub(crate) program_kind: Option<Box<str>>,
111    pub(crate) python_script: Option<PathBuf>,
112    pub(crate) final_iteration: Option<u64>,
113    pub(crate) models: Box<[ModelRunSummary]>,
114    pub(crate) output_directory: PathBuf,
115}
116
117impl TaskRunSummary {
118    /// Returns the study-inferred task identity.
119    pub fn identity(&self) -> &str {
120        &self.identity
121    }
122
123    /// Returns whether this task executed a model or a program.
124    pub const fn kind(&self) -> TaskRunKind {
125        self.kind
126    }
127
128    /// Returns the registered model key for a model task.
129    pub fn model(&self) -> Option<&str> {
130        self.model.as_deref()
131    }
132
133    /// Returns the resolved launcher executable for a program task.
134    ///
135    /// For a nested Python declaration this is its interpreter or environment
136    /// manager; durable `program.json` retains the canonical script path.
137    pub fn program(&self) -> Option<&Path> {
138        self.program.as_deref()
139    }
140
141    /// Returns the resolved program workload kind (`program` or `python`).
142    pub fn program_kind(&self) -> Option<&str> {
143        self.program_kind.as_deref()
144    }
145
146    /// Returns the canonical script path for a nested Python task.
147    pub fn python_script(&self) -> Option<&Path> {
148        self.python_script.as_deref()
149    }
150
151    /// Returns the maximum final model iteration for a scientific task.
152    pub const fn final_iteration(&self) -> Option<u64> {
153        self.final_iteration
154    }
155
156    /// Returns independently recorded model results in stable unit order.
157    ///
158    /// A standalone model produces one entry, an ensemble produces one entry
159    /// per model, and a program task produces none.
160    pub fn models(&self) -> &[ModelRunSummary] {
161        &self.models
162    }
163
164    /// Returns the task output root or program workspace directory.
165    ///
166    /// This is also the recording directory for a one-model execution unit.
167    /// Use [`Self::models`] for every per-model recording path.
168    pub fn output_directory(&self) -> &Path {
169        &self.output_directory
170    }
171}