scientific-workflow 0.17.1

Configuration-driven scientific tasks, typed state, and durable recordings
Documentation
//! Immutable strictly serial campaign planning.
use crate::config::{CampaignDeclaration, RuntimeSettings};
use std::{
    io,
    path::{Path, PathBuf},
};
/// Read-only ordered campaign intent; each study owns its entire compute budget.
#[derive(Clone, Debug)]
pub struct CampaignPlan {
    pub(crate) root: PathBuf,
    pub(crate) declaration: CampaignDeclaration,
    pub(crate) settings: RuntimeSettings,
}
impl CampaignPlan {
    /// Loads strict campaign configuration without creating output or executing tasks.
    pub fn load(input: &Path) -> Result<Self, crate::WorkflowError> {
        let root = input.canonicalize()?;
        let (declaration, settings) =
            crate::config::load_campaign(&root).map_err(crate::study::StudyError::from)?;
        Ok(Self {
            root,
            declaration,
            settings,
        })
    }
    /// Authored input folder.
    pub fn input(&self) -> &Path {
        &self.root
    }
    /// StudyPlan IDs in the only permitted execution order.
    pub fn studies(&self) -> impl ExactSizeIterator<Item = &str> {
        self.declaration.studies.iter().map(|m| m.id.as_str())
    }
    /// Whether failed studies allow later members to begin.
    pub fn continue_on_failure(&self) -> bool {
        self.declaration.continue_on_failure
    }
    /// Validates every member through its model-linked runner. This never invokes start.
    pub fn check(&self) -> io::Result<()> {
        for member in &self.declaration.studies {
            let runner = if member.runner.is_absolute() {
                member.runner.clone()
            } else {
                self.root.join(&member.runner)
            };
            let result = std::process::Command::new(runner)
                .arg("--workflow-check")
                .arg(self.root.join(&member.input))
                .output()?;
            if !result.status.success() {
                return Err(io::Error::other(format!(
                    "campaign member {} failed check: {}",
                    member.id,
                    String::from_utf8_lossy(&result.stderr)
                )));
            }
        }
        Ok(())
    }
}