scientific-workflow 0.18.1

Configuration-driven scientific tasks, typed state, and durable recordings
Documentation
//! Scientific Workflow: feature-selected execution, verified artifacts and socket tools.
//!
//! Default features are `runtime` and `macros`. Use `default-features = false`
//! with `client` for a lightweight socket SDK, or `protocol` for wire types only.
//! `cli` builds `workflow`; `dashboard` builds `workflow-dashboard` without the
//! engine when defaults are disabled. `full` includes all Rust tools. `python`
//! builds the native companion from this same package. The standalone procedural
//! macro implementation remains an optional dependency behind `macros`.
//!
//! Scientific applications register execution units and call `run(Path::new("."))`.
//! Inputs use `wf_configs/study.json`, `runtime.json`, and `parameters.json`.
//! Execution, storage and scientific contracts are unchanged by package consolidation.

#![cfg_attr(feature = "macros", doc = include_str!("unit-authoring.md"))]
#![deny(missing_docs, rustdoc::broken_intra_doc_links)]

extern crate self as scientific_workflow;

#[cfg(test)]
#[cfg(feature = "runtime")]
mod composition;
#[cfg(feature = "runtime")]
mod error;
#[cfg(test)]
#[cfg(feature = "runtime")]
mod test_support;

#[cfg(feature = "runtime")]
pub mod config;
#[cfg(feature = "runtime")]
pub mod observation;
#[cfg(feature = "runtime")]
pub mod persistence;
#[cfg(feature = "runtime")]
pub mod prelude;
#[cfg(feature = "runtime")]
mod runtime;
#[cfg(feature = "runtime")]
pub use runtime::RuntimeError;
#[cfg(feature = "runtime")]
pub mod artifact;
#[cfg(feature = "runtime")]
pub mod campaign;
#[cfg(feature = "runtime")]
mod engine;
#[cfg(feature = "runtime")]
pub mod provenance;
#[cfg(feature = "runtime")]
pub mod registry;
#[cfg(feature = "runtime")]
pub mod seal;
#[cfg(feature = "runtime")]
pub mod state;
#[cfg(feature = "runtime")]
mod storage;
#[cfg(feature = "runtime")]
pub mod study;
#[cfg(feature = "runtime")]
pub mod task;
#[cfg(feature = "runtime")]
mod workspace;
#[cfg(feature = "runtime")]
pub use engine::RunHandle;

#[cfg(feature = "runtime")]
pub use error::WorkflowError;
#[cfg(feature = "macros")]
pub use scientific_workflow_macros::execution_unit;
#[cfg(feature = "runtime")]
pub use task::{
    ExecutionUnit, InitializationContext, MemberCompletion, MemberView, SeedError, UnitResult,
};

/// Starts an independent engine for the input folder after complete validation and capture.
///
/// The explicit runtime interface selects headless launch or a separate dashboard.
/// `--wait` waits for the actual terminal outcome; ordinary launch returns after
/// socket readiness. Model-linked runners also accept `--workflow-check INPUT`
/// and `--workflow-start INPUT`. Authored inputs remain unchanged.
#[cfg(feature = "runtime")]
pub fn run(project_root: &std::path::Path) -> Result<(), WorkflowError> {
    engine::application(project_root)
}

/// Validates and expands a study without executing tasks or creating output.
#[cfg(feature = "runtime")]
pub fn check(input: &std::path::Path) -> Result<CheckReport, WorkflowError> {
    if input.join("campaign.json").is_file() {
        let plan = campaign::CampaignPlan::load(input)?;
        plan.check()?;
        return Ok(CheckReport {
            kind: "campaign".into(),
            studies: plan.studies().map(str::to_owned).collect(),
            tasks: None,
            threads: None,
        });
    }
    let study = study::StudyPlan::load(input)?;
    runtime::check_prerequisites(&study)?;
    Ok(CheckReport {
        kind: "study".into(),
        studies: vec!["study".into()],
        tasks: Some(study.plan_summary().phases().map(|p| p.tasks().len()).sum()),
        threads: Some(study.threads()),
    })
}
/// Validation-only summary. No execution or destination allocation occurs.
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
#[cfg(feature = "runtime")]
pub struct CheckReport {
    /// StudyPlan or campaign.
    pub kind: String,
    /// Validated member identifiers, in declaration order.
    pub studies: Vec<String>,
    /// Expanded standalone task count.
    pub tasks: Option<usize>,
    /// Standalone budget; campaigns have no shared compute budget.
    pub threads: Option<usize>,
}

/// Captures inputs and starts an independent engine, returning after socket readiness.
#[cfg(feature = "runtime")]
pub fn start(input: &std::path::Path) -> Result<RunHandle, WorkflowError> {
    engine::start(input)
}

/// Opens an authoritative run for verified artifact access.
#[cfg(feature = "runtime")]
pub fn open_run(
    location: &artifact::StorageLocation,
    id: &str,
) -> std::io::Result<artifact::RunArchive> {
    artifact::RunArchive::open(location, id)
}

/// Implementation details used by Workflow's declaration macros.
///
/// This namespace is public only because procedural macro expansion occurs in
/// the application crate. It is not a supported application API.
#[doc(hidden)]
#[cfg(feature = "runtime")]
pub mod __private {
    pub use crate::task::ExecutionUnitRegistration;
    pub use inventory;
}

/// Applies guarded sealing after verifying preservation evidence. Optional replay
/// uses an explicitly supplied scientific reproduction service.
#[cfg(feature = "runtime")]
pub fn seal_run(
    location: &artifact::StorageLocation,
    id: &str,
    workspace: &std::path::Path,
    reproducer: Option<&dyn seal::ReproductionRunner>,
) -> std::io::Result<seal::SealReport> {
    seal::execute(location, id, workspace, reproducer)
}

/// Executes the complete captured graph and applies study-defined comparisons.
/// The verification run is itself retained and sealed after a successful comparison.
#[cfg(feature = "runtime")]
pub fn reproduce_run(
    location: &artifact::StorageLocation,
    id: &str,
    workspace: &std::path::Path,
) -> std::io::Result<seal::ReproductionEvidence> {
    use seal::ReproductionRunner;
    engine::CapturedReproducer {
        workspace: workspace.into(),
    }
    .reproduce(&open_run(location, id)?)
}

/// Seals after an explicitly requested full captured reproduction and scientific comparison.
#[cfg(feature = "runtime")]
pub fn seal_run_with_reproduction(
    location: &artifact::StorageLocation,
    id: &str,
    workspace: &std::path::Path,
) -> std::io::Result<seal::SealReport> {
    let runner = engine::CapturedReproducer {
        workspace: workspace.join("reproduction-check"),
    };
    seal::execute(location, id, workspace, Some(&runner))
}

/// Reconnectable socket controls, independent of execution.
#[cfg(feature = "client")]
pub mod client;
/// Versioned socket framing and wire data, independent of execution.
#[cfg(feature = "protocol")]
pub mod protocol;
#[cfg(feature = "client")]
pub use client::RunClient;
#[cfg(feature = "python")]
mod python;