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