scientific_workflow/lib.rs
1//! Configuration-driven scientific workflow execution.
2//!
3//! An ordinary application defines registered [`task::basic::ScientificModel`]
4//! implementations, writes `study.json`, `config/state.json`, and the central
5//! `config/parameters.json`, then calls [`run`] with the project root. Workflow infers task
6//! instances, phase membership, identities, output paths, progress boundaries,
7//! recording lifecycle, and execution mechanics.
8//!
9//! # Ordinary use
10//!
11//! ```no_run
12//! use std::path::Path;
13//!
14//! fn main() -> Result<(), scientific_workflow::WorkflowError> {
15//! scientific_workflow::run(Path::new("."))
16//! }
17//! ```
18//!
19//! A model carries its stable manifest key at its implementation:
20//!
21//! ```
22//! use serde::Deserialize;
23//! use scientific_workflow::prelude::basic::*;
24//!
25//! #[derive(Deserialize)]
26//! struct Constants { initial: u64, steps: u64 }
27//!
28//! struct Model { state: SystemState, steps: u64 }
29//!
30//! #[scientific_workflow::model("example")]
31//! impl ScientificModel for Model {
32//! type Constants = Constants;
33//!
34//! fn initialize(constants: Constants, schema: &SystemStateSchema) -> TaskResult<Self> {
35//! let mut state = schema.create_empty_state(StateTime::from_iteration(0));
36//! state.initialize_payload("population", constants.initial)?;
37//! state.initialize_payload("cumulative_births", 0_u64)?;
38//! Ok(Self { state, steps: constants.steps })
39//! }
40//!
41//! fn state(&self) -> &SystemState { &self.state }
42//! fn is_complete(&self) -> bool { self.state.time().iteration() == self.steps }
43//! fn step(&mut self) -> TaskResult {
44//! let (population, cumulative_births) = self
45//! .state
46//! .borrow_payloads_mut::<(u64, u64)>(
47//! ("population", "cumulative_births"),
48//! )?;
49//! *population += 1;
50//! *cumulative_births += 1;
51//! self.state.advance_time(None)?;
52//! Ok(())
53//! }
54//! }
55//! ```
56//!
57//! # Ownership boundaries
58//!
59//! - [`config`] alone reads and parses project JSON and supplies typed model
60//! constants.
61//! - [`study`] composes parsed declarations, state semantics, and compiled model
62//! registrations into immutable, output-free intent.
63//! - [`runtime`] consumes a completed Study and owns active execution/output.
64//! - [`task`] owns the model contract and automatic observation boundaries.
65//! - [`state`] owns canonical scientific state and schema.
66//! - [`observation`] owns scientific observation meaning, not persistence mechanics.
67//! - [`persistence`] owns automatic durable output and verified reading.
68//! - [`ui`] owns automatic terminal presentation of Runtime facts.
69//! - [`error`] owns complete-workflow Study/Runtime error composition.
70//!
71//! The crate-level [`run`] facade performs the sole ordinary transition from
72//! project root to Study to Runtime. `Study` is the ultimate coordinator of
73//! declared intent; runtime is the ultimate coordinator of active execution.
74//! Advanced integrations use each module's `advanced` scope. [`prelude`] only
75//! aggregates those module-owned APIs and crate conveniences.
76//!
77//! Persistence write construction and output allocation are internal and are
78//! not available to model authors.
79//!
80//! This crate is pre-1.0 test software and may make coordinated API changes.
81
82#![deny(missing_docs, rustdoc::broken_intra_doc_links)]
83
84extern crate self as scientific_workflow;
85
86mod clock;
87pub mod error;
88
89pub mod config;
90pub mod observation;
91pub mod persistence;
92pub mod prelude;
93pub mod runtime;
94pub mod state;
95pub mod study;
96pub mod task;
97pub mod ui;
98
99pub use error::basic::WorkflowError;
100pub use scientific_workflow_macros::model;
101
102/// Loads, preflights, and executes the Workflow project rooted at
103/// `project_root`.
104///
105/// This is the sole ordinary application entry point. Project loading and
106/// Study compilation finish before Runtime receives the validated immutable
107/// Study. Successful completion returns `()`; advanced integrations can load
108/// a [`study::advanced::Study`] and call [`runtime::advanced::execute`] to
109/// retain a read-only run summary.
110pub fn run(project_root: &std::path::Path) -> Result<(), WorkflowError> {
111 let study = study::advanced::Study::load(project_root)?;
112 runtime::advanced::execute(study)?;
113 Ok(())
114}
115
116/// Implementation details used by Workflow's declaration macros.
117///
118/// This namespace is public only because procedural macro expansion occurs in
119/// the application crate. It is not a supported application API.
120#[doc(hidden)]
121pub mod __private {
122 pub use crate::task::advanced::ModelRegistration;
123 pub use inventory;
124}