Skip to main content

Context

Struct Context 

Source
pub struct Context {
    pub mode: RunMode,
    pub event_bus: Arc<EventBus>,
    pub run_id: String,
    pub graph_info: GraphInfo,
    pub transport: Option<Arc<dyn Transport>>,
    pub data_store: Option<Arc<dyn DataStore>>,
    pub spill_threshold: usize,
    pub seed: Option<i64>,
    pub driver: Option<EffectDriver>,
    /* private fields */
}
Expand description

Execution context passed to filters during runtime.

Node outputs are stored as VirtualValues — they may be materialized in memory, cached on disk, or deferred (not yet computed). The executor resolves them on demand when a downstream node needs the data.

Fields§

§mode: RunMode

Fit or forward. See RunMode.

§event_bus: Arc<EventBus>

Event bus for emitting runtime events.

§run_id: String

Current run ID.

§graph_info: GraphInfo

Graph topology for input resolution.

§transport: Option<Arc<dyn Transport>>

Optional transport for distributed plans.

§data_store: Option<Arc<dyn DataStore>>

Optional data store for persisting intermediate results.

§spill_threshold: usize

Minimum value size (bytes) to spill to DataStore instead of keeping in memory. Default: 0 (disabled — all values stay in memory).

§seed: Option<i64>

Experiment seed for this run. Hashed into every cache key so each seed owns an independent cache line (a 5-seed study is 5 resumable computations, not one).

§driver: Option<EffectDriver>

Performs and journals step effects. Only needed when the plan contains a step; a purely computational graph leaves it unset.

The steps themselves are not here: they live in the same NodeCatalog as the filters, which the executor already receives. Keeping a second registry in the context is what let the branch arm decide a node’s kind by asking whether it happened to be in it.

Implementations§

Source§

impl Context

Source

pub fn new(event_bus: Arc<EventBus>, run_id: impl Into<String>) -> Self

A forward-mode context with empty topology and no optional components; the with_* builders add what the run needs.

Source

pub fn with_driver(self, driver: EffectDriver) -> Self

Register the effect driver an effectful plan needs.

The driver should already carry its catalog (crate::effects::EffectDriver::with_catalog) if a step may fan out dynamically — whoever builds the driver knows which catalog it serves; the context does not.

Source

pub fn with_graph_info(self, info: GraphInfo) -> Self

Set the topology used for input resolution.

Source

pub fn fitting(self, y: Option<Value>) -> Self

Make this a fit: trainable nodes learn from y before computing.

Source

pub fn record_state(&mut self, node_id: &str, state: Value)

Record a state a node just learned.

Stored under the same __state_{id} key the worker and the session already read, and appended to execution_order like any other write: that list is how execute_parallel works out what a branch contributed, so a state written inside a branch that skipped it would be dropped at the join. Readers asking “which node ran last” filter reserved keys out — see somatize_core::keys::is_reserved.

Source

pub fn with_seed(self, seed: Option<i64>) -> Self

Set the experiment seed (hashed into every cache key).

Source

pub fn with_transport(self, transport: Arc<dyn Transport>) -> Self

Set the transport a plan with Remote nodes executes through.

Source

pub fn with_data_store(self, store: Arc<dyn DataStore>) -> Self

Set the data store used for spilling and remote data movement.

Source

pub fn with_spill_threshold(self, bytes: usize) -> Self

Set spill threshold: values larger than this (in bytes) are offloaded to the DataStore and replaced with a VirtualValue::Cached reference. Requires a DataStore to be set via with_data_store().

Source

pub fn execution_order(&self) -> &[String]

The nodes that ran, in the order they ran.

Includes the run’s reserved keys (see somatize_core::keys); filter them out with keys::is_reserved if you want node ids only.

Source

pub fn into_outputs(self) -> HashMap<String, Value>

Every materialized value this run produced, keyed by node id.

Consumes the context, because the point of asking is that the run is over. Lazy values that were never resolved are skipped.

Source

pub fn get(&self, node_id: &str) -> Option<&Value>

Get the materialized Value for a node, if present and materialized.

Source

pub fn get_virtual(&self, node_id: &str) -> Option<&VirtualValue>

Get the raw VirtualValue for a node.

Source

pub fn set(&mut self, node_id: impl Into<String>, value: Value)

Store a materialized value for a node.

Source

pub fn set_virtual(&mut self, node_id: impl Into<String>, vv: VirtualValue)

Store a virtual value (which may be deferred or cached).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

The receiver as &dyn Any, ready for downcast_ref.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more