Skip to main content

scientific_workflow/
lib.rs

1//! Rust primitives for reproducible scientific workflows.
2//!
3//! `scientific-workflow` provides the data and execution foundations needed to
4//! describe scientific systems, record their evolution, and organize scoped
5//! computational work. The crate is intentionally divided by responsibility:
6//! state representation, in-memory state time series, storage, orchestration, and
7//! language bridges remain separate modules rather than accumulating behind
8//! one monolithic interface.
9//!
10//! # Current modules
11//!
12//! [`configuration`] provides the standard `config/{fixed,sweep,paths}.json`
13//! project layout, deterministic Cartesian or explicit-case task expansion,
14//! complete cheap task-configuration handles, exact sweep-value selection,
15//! named path resolution, and byte-exact source export.
16//! [`project`] combines task configuration with either a project-owned
17//! `config/state.json` schema or a canonical schema supplied by a fixed-model
18//! crate as one immutable [`project::ScientificProject`]. [`execution`] creates
19//! collision-resistant or caller-named execution scopes and deterministic task
20//! recording paths without taking ownership away from storage writers.
21//! [`artifact`] atomically publishes and verifies content-addressed immutable
22//! bytes while leaving their scientific representation to consumer crates.
23//! [`runtime`] provides phase-based bounded scheduling and one process-wide
24//! human-facing display for registered tasks. Task workloads retain ownership
25//! of all scientific I/O. [`rng_record`] provides only
26//! validated, persisted RNG provenance records; random generation remains an
27//! application responsibility.
28//!
29//! [`system_state`] provides:
30//!
31//! - JSON-defined, immutable field layouts;
32//! - optional natural-language field descriptions without persisted Rust types;
33//! - heterogeneous concrete Rust payloads behind a typed API;
34//! - clone-free payload insertion, mutation, and extraction;
35//! - explicit per-payload cloning of complete states;
36//! - mutable, checked time-point progression.
37//!
38//! Type erasure and boxing remain internal to that module. Consumer crates
39//! work with their original concrete payload types.
40//!
41//! [`time_series`] provides the in-memory analysis collection for complete,
42//! ordered states. It enforces shared-layout identity and increasing simulation
43//! indices, offers a lightweight borrowed view, and permits field-level
44//! mutation without exposing mutable state time. It deliberately performs no
45//! serialization, chunking, or filesystem IO.
46//!
47//! [`storage`] provides named partial-state streams with writer-owned sampling
48//! intervals, borrowed JSON encoding only when due, bounded asynchronous
49//! persistence through one worker per recording, byte-targeted chunking, atomic recording
50//! metadata, automatic operational timing, terminal summaries, name-selected payload
51//! decoders, and verified full-series or latest-state reconstruction.
52//! Import [`prelude::basics`] for these scientific primitives and
53//! [`prelude::runtime`] only at orchestration boundaries.
54//!
55//! # Basic use
56//!
57//! ```no_run
58//! use scientific_workflow::prelude::basics::*;
59//!
60//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
61//! let spec = SystemStateSchema::load_json_template("state.json")?;
62//! let mut state = spec.create_empty_state(SimulationTime::from_iteration(0));
63//!
64//! assert!(
65//!     state
66//!         .insert_payload("population", vec![10_u64, 20, 30])?
67//!         .is_none()
68//! );
69//! state
70//!     .payload_mut::<Vec<u64>>("population")?
71//!     .push(40);
72//! let time = state.advance_simulation_time(None)?;
73//! assert_eq!(time.iteration(), 1);
74//! let population = state.take_payload::<Vec<u64>>("population")?;
75//!
76//! assert_eq!(population, vec![10, 20, 30, 40]);
77//! # Ok(())
78//! # }
79//! ```
80//!
81//! Future orchestration-layer features will organize scoped workflow execution
82//! without changing the public state-value ownership or storage contracts.
83
84mod clock;
85
86pub mod artifact;
87pub mod configuration;
88pub mod execution;
89pub mod prelude;
90pub mod project;
91pub mod rng_record;
92pub mod runtime;
93pub mod storage;
94pub mod system_state;
95pub mod time_series;