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/// Successful result of the workload completed by a task.
69#[non_exhaustive]
70#[derive(Clone, Debug)]
71pub enum TaskRunKind {
72    /// A registered scientific execution-unit invocation and its members.
73    ExecutionUnit {
74        /// Registration key used to select the execution unit.
75        execution_unit: Box<str>,
76        /// Independently recorded member results in stable unit order.
77        members: Box<[MemberRunSummary]>,
78    },
79    /// An external executable or Python program invocation.
80    Program {
81        /// Resolved launcher executable.
82        executable: PathBuf,
83        /// Canonical script path when this was a nested Python task.
84        python_script: Option<PathBuf>,
85    },
86    /// Workflow's reserved conversion of prerequisite recordings to NumPy arrays.
87    Npy {
88        /// Resolved Python interpreter used to launch the standard converter.
89        launcher: PathBuf,
90        /// Standard execution-level directory containing manifests and arrays.
91        processed_directory: PathBuf,
92    },
93}
94
95/// Successful completion facts for one member inside an execution unit.
96#[derive(Clone, Debug)]
97pub struct MemberRunSummary {
98    pub(crate) identity: Box<str>,
99    pub(crate) final_iteration: u64,
100    pub(crate) output_directory: PathBuf,
101}
102
103impl MemberRunSummary {
104    /// Returns the stable member identity supplied by the execution unit.
105    pub fn identity(&self) -> &str {
106        &self.identity
107    }
108
109    /// Returns this member's final scientific iteration.
110    pub const fn final_iteration(&self) -> u64 {
111        self.final_iteration
112    }
113
114    /// Returns this member's completed recording directory.
115    pub fn output_directory(&self) -> &Path {
116        &self.output_directory
117    }
118}
119
120/// Successful completion facts for one generic task invocation.
121#[derive(Clone, Debug)]
122pub struct TaskRunSummary {
123    pub(crate) identity: Box<str>,
124    pub(crate) kind: TaskRunKind,
125    pub(crate) output_directory: PathBuf,
126    pub(crate) configuration: usize,
127}
128
129impl TaskRunSummary {
130    /// Returns the study-inferred task identity.
131    pub fn identity(&self) -> &str {
132        &self.identity
133    }
134
135    /// Returns the completed workload and its variant-specific result.
136    pub const fn kind(&self) -> &TaskRunKind {
137        &self.kind
138    }
139
140    /// Returns the task output root or program workspace directory.
141    ///
142    /// This is also the recording directory for a one-member execution unit.
143    /// Match [`Self::kind`] for every per-member recording path.
144    pub fn output_directory(&self) -> &Path {
145        &self.output_directory
146    }
147
148    pub(crate) fn final_iteration(&self) -> Option<u64> {
149        match &self.kind {
150            TaskRunKind::ExecutionUnit { members, .. } => {
151                members.iter().map(MemberRunSummary::final_iteration).max()
152            }
153            TaskRunKind::Program { .. } | TaskRunKind::Npy { .. } => None,
154        }
155    }
156
157    pub(crate) const fn configuration(&self) -> usize {
158        self.configuration
159    }
160}