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 [VirtualValue]s — 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: RunModeFit or forward. See RunMode.
event_bus: Arc<EventBus>Event bus for emitting runtime events.
run_id: StringCurrent run ID.
graph_info: GraphInfoGraph 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: usizeMinimum 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
impl Context
Sourcepub fn new(event_bus: Arc<EventBus>, run_id: impl Into<String>) -> Self
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.
Sourcepub fn with_driver(self, driver: EffectDriver) -> Self
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.
Sourcepub fn with_graph_info(self, info: GraphInfo) -> Self
pub fn with_graph_info(self, info: GraphInfo) -> Self
Set the topology used for input resolution.
Sourcepub fn fitting(self, y: Option<Value>) -> Self
pub fn fitting(self, y: Option<Value>) -> Self
Make this a fit: trainable nodes learn from y before computing.
Sourcepub fn record_state(&mut self, node_id: &str, state: Value)
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].
Sourcepub fn with_seed(self, seed: Option<i64>) -> Self
pub fn with_seed(self, seed: Option<i64>) -> Self
Set the experiment seed (hashed into every cache key).
Sourcepub fn with_transport(self, transport: Arc<dyn Transport>) -> Self
pub fn with_transport(self, transport: Arc<dyn Transport>) -> Self
Set the transport a plan with Remote nodes executes through.
Sourcepub fn with_data_store(self, store: Arc<dyn DataStore>) -> Self
pub fn with_data_store(self, store: Arc<dyn DataStore>) -> Self
Set the data store used for spilling and remote data movement.
Sourcepub fn with_spill_threshold(self, bytes: usize) -> Self
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().
Sourcepub fn execution_order(&self) -> &[String]
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.
Sourcepub fn into_outputs(self) -> HashMap<String, Value>
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.
Sourcepub fn get(&self, node_id: &str) -> Option<&Value>
pub fn get(&self, node_id: &str) -> Option<&Value>
Get the materialized Value for a node, if present and materialized.
Sourcepub fn get_virtual(&self, node_id: &str) -> Option<&VirtualValue>
pub fn get_virtual(&self, node_id: &str) -> Option<&VirtualValue>
Get the raw VirtualValue for a node.
Sourcepub fn set(&mut self, node_id: impl Into<String>, value: Value)
pub fn set(&mut self, node_id: impl Into<String>, value: Value)
Store a materialized value for a node.
Sourcepub fn set_virtual(&mut self, node_id: impl Into<String>, vv: VirtualValue)
pub fn set_virtual(&mut self, node_id: impl Into<String>, vv: VirtualValue)
Store a virtual value (which may be deferred or cached).