Skip to main content

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 { 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//!         Ok(Self {
36//!             state: schema.create_empty_state(StateTime::from_iteration(0)),
37//!             steps: constants.steps,
38//!         })
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//!         self.state.advance_time(None)?;
45//!         Ok(())
46//!     }
47//! }
48//! ```
49//!
50//! # Ownership boundaries
51//!
52//! - [`config`] alone reads and parses project JSON and supplies typed model
53//!   constants.
54//! - [`study`] composes parsed declarations, state semantics, and compiled model
55//!   registrations into immutable, output-free intent.
56//! - [`runtime`] consumes a completed Study and owns active execution/output.
57//! - [`task`] owns the model contract and automatic observation boundaries.
58//! - [`state`] owns canonical scientific state and schema.
59//! - [`observation`] owns scientific observation meaning, not persistence mechanics.
60//! - [`persistence`] owns automatic durable output and verified reading.
61//! - [`ui`] owns automatic terminal presentation of Runtime facts.
62//! - [`error`] owns complete-workflow Study/Runtime error composition.
63//!
64//! The crate-level [`run`] facade performs the sole ordinary transition from
65//! project root to Study to Runtime. `Study` is the ultimate coordinator of
66//! declared intent; runtime is the ultimate coordinator of active execution.
67//! Advanced integrations use each module's `advanced` scope. [`prelude`] only
68//! aggregates those module-owned APIs and crate conveniences.
69//!
70//! Persistence write construction and output allocation are internal and are
71//! not available to model authors.
72//!
73//! This crate is pre-1.0 test software and may make coordinated API changes.
74
75#![deny(missing_docs, rustdoc::broken_intra_doc_links)]
76
77extern crate self as scientific_workflow;
78
79mod clock;
80pub mod error;
81
82pub mod config;
83pub mod observation;
84pub mod persistence;
85pub mod prelude;
86pub mod runtime;
87pub mod state;
88pub mod study;
89pub mod task;
90pub mod ui;
91
92pub use error::basic::WorkflowError;
93pub use scientific_workflow_macros::model;
94
95/// Loads, preflights, and executes the Workflow project rooted at
96/// `project_root`.
97///
98/// This is the sole ordinary application entry point. Project loading and
99/// Study compilation finish before Runtime receives the validated immutable
100/// Study. Successful completion returns `()`; advanced integrations can load
101/// a [`study::advanced::Study`] and call [`runtime::advanced::execute`] to
102/// retain a read-only run summary.
103pub fn run(project_root: &std::path::Path) -> Result<(), WorkflowError> {
104    let study = study::advanced::Study::load(project_root)?;
105    runtime::advanced::execute(study)?;
106    Ok(())
107}
108
109/// Implementation details used by Workflow's declaration macros.
110///
111/// This namespace is public only because procedural macro expansion occurs in
112/// the application crate. It is not a supported application API.
113#[doc(hidden)]
114pub mod __private {
115    pub use crate::task::advanced::ModelRegistration;
116    pub use inventory;
117}