Skip to main content

ScientificModel

Trait ScientificModel 

Source
pub trait ScientificModel:
    Send
    + Sized
    + 'static {
    type Constants: DeserializeOwned + Send + Sync + '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.

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 + Send + Sync + 'static

One complete set of model constants supplied by config.

Required Methods§

Source

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

Builds a fully initialized model from resolved constants and the runtime-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 during effect-free Study preflight; Study binds and retains that exact plan for execution. 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§