Skip to main content

ScientificModel

Trait ScientificModel 

Source
pub trait ScientificModel:
    Send
    + Sized
    + 'static {
    type Constants: DeserializeOwned + 'static;

    // Required methods
    fn initialize(
        constants: Self::Constants,
        schema: &SystemStateSchema,
    ) -> TaskResult<Self>;
    fn state(&self) -> &SystemState;
    fn is_complete(&self) -> bool;
    fn step(&mut self) -> TaskResult;

    // Provided methods
    fn observation_plan(
        _constants: &Self::Constants,
    ) -> TaskResult<ObservationPlan> { ... }
    fn target_iteration(&self) -> Option<u64> { ... }
}
Expand description

A stateful scientific workload initialized from config-supplied constants.

§Direct state ownership

The implementing model must directly own the SystemState returned by ScientificModel::state for its entire execution. Rust traits cannot express field-level structural ownership, so this requirement is semantic; the task runtime enforces the observable parts by requiring a stable state address and the exact schema allocation supplied to Self::initialize. Returning a temporary, swapping the state owner, or changing schemas is a contract violation.

The #[scientific_workflow::model("key")] attribute only registers the implementation under a manifest key. It does not generate, wrap, proxy, or provide access to model state. The model defines an ordinary SystemState field, initializes its concrete payloads, and returns a direct borrow of that field from Self::state. Coupled fields remain ordinary typed tuple borrows through SystemState::borrow_payloads and SystemState::borrow_payloads_mut; no field-access macro is involved.

A successful Self::step represents exactly one scientifically observable transition and must strictly advance the state’s iteration. Workflow observes the initial state, every successful step, and the final state automatically. Implementations do not report progress or invoke the observation plan themselves.

Required Associated Types§

Source

type Constants: DeserializeOwned + 'static

One complete set of model constants supplied by config.

Constants need not implement Send or Sync: Study and Runtime independently decode and consume their equivalent owned instances on the thread performing that operation. The model itself remains Send, and TaskResult errors remain Send + Sync for worker handoff.

Required Methods§

Source

fn initialize( constants: Self::Constants, schema: &SystemStateSchema, ) -> TaskResult<Self>

Builds a fully initialized model from a fresh decode of the same resolved constants value and the selected, centrally loaded state schema.

The returned model must already contain a usable, fully populated state created from this exact schema allocation. No state observation occurs until this method succeeds.

Source

fn state(&self) -> &SystemState

Borrows the model’s directly owned canonical state.

This method must be side-effect free and must return the same state owner and schema allocation throughout execution.

Source

fn is_complete(&self) -> bool

Reports whether no further scientific transition is required.

This method must be side-effect free. Once it returns true during one execution, Workflow performs the final observation without calling Self::step again.

Source

fn step(&mut self) -> TaskResult

Performs exactly one scientifically observable transition.

Success must strictly increase SystemState::time’s iteration while preserving the state owner and schema. Failure must not claim a completed transition: Workflow emits neither a successful-step snapshot nor a successful-step observation for an error result.

Provided Methods§

Source

fn observation_plan(_constants: &Self::Constants) -> TaskResult<ObservationPlan>

Defines the scientific observations recorded for this model.

The default records every declared state field at every iteration. Implementations may derive stream selection and sampling cadence from model constants. This function is called once with Study’s preflight constants instance; Study binds and retains the resulting plan for execution, then drops that instance. It must not perform external side effects.

Source

fn target_iteration(&self) -> Option<u64>

Optionally reports the expected final iteration for inferred progress.

The default is unknown. A reported target must be at least the current iteration. Once present during an execution, it must never decrease or disappear. This method must be side-effect free.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§