Skip to main content

scientific_workflow/
lib.rs

1//! Scientific Workflow: feature-selected execution, verified artifacts and socket tools.
2//!
3//! Default features are `runtime` and `macros`. Use `default-features = false`
4//! with `client` for a lightweight socket SDK, or `protocol` for wire types only.
5//! `cli` builds `workflow`; `dashboard` builds `workflow-dashboard` without the
6//! engine when defaults are disabled. `full` includes all Rust tools. `python`
7//! builds the native companion from this same package. The standalone procedural
8//! macro implementation remains an optional dependency behind `macros`.
9//!
10//! Scientific applications register execution units and call `run(Path::new("."))`.
11//! Inputs use `wf_configs/study.json`, `runtime.json`, and `parameters.json`.
12//! Execution, storage and scientific contracts are unchanged by package consolidation.
13
14#![cfg_attr(feature = "macros", doc = include_str!("unit-authoring.md"))]
15#![deny(missing_docs, rustdoc::broken_intra_doc_links)]
16
17extern crate self as scientific_workflow;
18
19#[cfg(test)]
20#[cfg(feature = "runtime")]
21mod composition;
22#[cfg(feature = "runtime")]
23mod error;
24#[cfg(test)]
25#[cfg(feature = "runtime")]
26mod test_support;
27
28#[cfg(feature = "runtime")]
29pub mod config;
30#[cfg(feature = "runtime")]
31pub mod observation;
32#[cfg(feature = "runtime")]
33pub mod persistence;
34#[cfg(feature = "runtime")]
35pub mod prelude;
36#[cfg(feature = "runtime")]
37mod runtime;
38#[cfg(feature = "runtime")]
39pub use runtime::RuntimeError;
40#[cfg(feature = "runtime")]
41pub mod artifact;
42#[cfg(feature = "runtime")]
43pub mod campaign;
44#[cfg(feature = "runtime")]
45mod engine;
46#[cfg(feature = "runtime")]
47pub mod provenance;
48#[cfg(feature = "runtime")]
49pub mod registry;
50#[cfg(feature = "runtime")]
51pub mod seal;
52#[cfg(feature = "runtime")]
53pub mod state;
54#[cfg(feature = "runtime")]
55mod storage;
56#[cfg(feature = "runtime")]
57pub mod study;
58#[cfg(feature = "runtime")]
59pub mod task;
60#[cfg(feature = "runtime")]
61mod workspace;
62#[cfg(feature = "runtime")]
63pub use engine::RunHandle;
64
65#[cfg(feature = "runtime")]
66pub use error::WorkflowError;
67#[cfg(feature = "macros")]
68pub use scientific_workflow_macros::execution_unit;
69#[cfg(feature = "runtime")]
70pub use task::{
71    ExecutionUnit, InitializationContext, MemberCompletion, MemberView, SeedError, UnitResult,
72};
73
74/// Starts an independent engine for the input folder after complete validation and capture.
75///
76/// The explicit runtime interface selects headless launch or a separate dashboard.
77/// `--wait` waits for the actual terminal outcome; ordinary launch returns after
78/// socket readiness. Model-linked runners also accept `--workflow-check INPUT`
79/// and `--workflow-start INPUT`. Authored inputs remain unchanged.
80#[cfg(feature = "runtime")]
81pub fn run(project_root: &std::path::Path) -> Result<(), WorkflowError> {
82    engine::application(project_root)
83}
84
85/// Validates and expands a study without executing tasks or creating output.
86#[cfg(feature = "runtime")]
87pub fn check(input: &std::path::Path) -> Result<CheckReport, WorkflowError> {
88    if input.join("campaign.json").is_file() {
89        let plan = campaign::CampaignPlan::load(input)?;
90        plan.check()?;
91        return Ok(CheckReport {
92            kind: "campaign".into(),
93            studies: plan.studies().map(str::to_owned).collect(),
94            tasks: None,
95            threads: None,
96        });
97    }
98    let study = study::StudyPlan::load(input)?;
99    runtime::check_prerequisites(&study)?;
100    Ok(CheckReport {
101        kind: "study".into(),
102        studies: vec!["study".into()],
103        tasks: Some(study.plan_summary().phases().map(|p| p.tasks().len()).sum()),
104        threads: Some(study.threads()),
105    })
106}
107/// Validation-only summary. No execution or destination allocation occurs.
108#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
109#[cfg(feature = "runtime")]
110pub struct CheckReport {
111    /// StudyPlan or campaign.
112    pub kind: String,
113    /// Validated member identifiers, in declaration order.
114    pub studies: Vec<String>,
115    /// Expanded standalone task count.
116    pub tasks: Option<usize>,
117    /// Standalone budget; campaigns have no shared compute budget.
118    pub threads: Option<usize>,
119}
120
121/// Captures inputs and starts an independent engine, returning after socket readiness.
122#[cfg(feature = "runtime")]
123pub fn start(input: &std::path::Path) -> Result<RunHandle, WorkflowError> {
124    engine::start(input)
125}
126
127/// Opens an authoritative run for verified artifact access.
128#[cfg(feature = "runtime")]
129pub fn open_run(
130    location: &artifact::StorageLocation,
131    id: &str,
132) -> std::io::Result<artifact::RunArchive> {
133    artifact::RunArchive::open(location, id)
134}
135
136/// Implementation details used by Workflow's declaration macros.
137///
138/// This namespace is public only because procedural macro expansion occurs in
139/// the application crate. It is not a supported application API.
140#[doc(hidden)]
141#[cfg(feature = "runtime")]
142pub mod __private {
143    pub use crate::task::ExecutionUnitRegistration;
144    pub use inventory;
145}
146
147/// Applies guarded sealing after verifying preservation evidence. Optional replay
148/// uses an explicitly supplied scientific reproduction service.
149#[cfg(feature = "runtime")]
150pub fn seal_run(
151    location: &artifact::StorageLocation,
152    id: &str,
153    workspace: &std::path::Path,
154    reproducer: Option<&dyn seal::ReproductionRunner>,
155) -> std::io::Result<seal::SealReport> {
156    seal::execute(location, id, workspace, reproducer)
157}
158
159/// Executes the complete captured graph and applies study-defined comparisons.
160/// The verification run is itself retained and sealed after a successful comparison.
161#[cfg(feature = "runtime")]
162pub fn reproduce_run(
163    location: &artifact::StorageLocation,
164    id: &str,
165    workspace: &std::path::Path,
166) -> std::io::Result<seal::ReproductionEvidence> {
167    use seal::ReproductionRunner;
168    engine::CapturedReproducer {
169        workspace: workspace.into(),
170    }
171    .reproduce(&open_run(location, id)?)
172}
173
174/// Seals after an explicitly requested full captured reproduction and scientific comparison.
175#[cfg(feature = "runtime")]
176pub fn seal_run_with_reproduction(
177    location: &artifact::StorageLocation,
178    id: &str,
179    workspace: &std::path::Path,
180) -> std::io::Result<seal::SealReport> {
181    let runner = engine::CapturedReproducer {
182        workspace: workspace.join("reproduction-check"),
183    };
184    seal::execute(location, id, workspace, Some(&runner))
185}
186
187/// Reconnectable socket controls, independent of execution.
188#[cfg(feature = "client")]
189pub mod client;
190/// Versioned socket framing and wire data, independent of execution.
191#[cfg(feature = "protocol")]
192pub mod protocol;
193#[cfg(feature = "client")]
194pub use client::RunClient;
195#[cfg(feature = "python")]
196mod python;