modewise_pipeline/
manifest.rs

1use std::collections::BTreeMap;
2
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6use crate::ArtifactKey;
7
8/// What a run did, for provenance: every step's operation, parameters and data keys.
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct RunManifest {
11    pub pipeline: String,
12    pub modewise_version: String,
13    pub inputs: BTreeMap<String, ArtifactKey>,
14    pub steps: Vec<StepRecord>,
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
18pub struct StepRecord {
19    pub id: String,
20    pub op: String,
21    pub op_version: String,
22    pub params: Value,
23    pub inputs: BTreeMap<String, ArtifactKey>,
24    pub outputs: BTreeMap<String, ArtifactKey>,
25    pub cached: bool,
26    /// False for steps with `keep = false`: their outputs were not written to the store.
27    #[serde(default = "stored_by_default")]
28    pub stored: bool,
29    pub seconds: f64,
30}
31
32fn stored_by_default() -> bool {
33    true
34}
35
36impl RunManifest {
37    pub fn to_json(&self) -> String {
38        serde_json::to_string_pretty(self).unwrap_or_default()
39    }
40
41    /// Every step output, by `step.output`.
42    pub fn outputs(&self) -> BTreeMap<String, ArtifactKey> {
43        self.steps
44            .iter()
45            .flat_map(|s| {
46                s.outputs
47                    .iter()
48                    .map(|(o, k)| (format!("{}.{o}", s.id), k.clone()))
49            })
50            .collect()
51    }
52}