pub trait StrategyContext {
// Required methods
fn num_workers(&self) -> usize;
fn execute_on_worker(
&self,
worker_idx: usize,
plan: &Value,
input: &Value,
y: Option<&Value>,
) -> Result<HashMap<String, Value>>;
fn get_state(
&self,
worker_idx: usize,
node_ids: &[String],
) -> Result<HashMap<String, Value>>;
fn set_state(
&self,
worker_idx: usize,
states: &HashMap<String, Value>,
) -> Result<()>;
fn get_gradients(
&self,
worker_idx: usize,
node_ids: &[String],
) -> Result<HashMap<String, Value>>;
fn apply_gradients(
&self,
worker_idx: usize,
gradients: &HashMap<String, Value>,
) -> Result<()>;
}Expand description
Context provided to strategy executors. Abstracts worker communication — the strategy doesn’t know about WS/HTTP.
Required Methods§
Sourcefn num_workers(&self) -> usize
fn num_workers(&self) -> usize
Number of available workers.
Sourcefn execute_on_worker(
&self,
worker_idx: usize,
plan: &Value,
input: &Value,
y: Option<&Value>,
) -> Result<HashMap<String, Value>>
fn execute_on_worker( &self, worker_idx: usize, plan: &Value, input: &Value, y: Option<&Value>, ) -> Result<HashMap<String, Value>>
Execute a plan on a specific worker (by index). Returns trained states.
Sourcefn get_state(
&self,
worker_idx: usize,
node_ids: &[String],
) -> Result<HashMap<String, Value>>
fn get_state( &self, worker_idx: usize, node_ids: &[String], ) -> Result<HashMap<String, Value>>
Get trained states from a worker.
Sourcefn set_state(
&self,
worker_idx: usize,
states: &HashMap<String, Value>,
) -> Result<()>
fn set_state( &self, worker_idx: usize, states: &HashMap<String, Value>, ) -> Result<()>
Set states on a worker (e.g. after aggregation).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".