pub struct Worker {
pub id: WorkerId,
pub capabilities: Capabilities,
/* private fields */
}Expand description
Worker state: manages execution of plans received from a coordinator.
Fields§
§id: WorkerIdThe identity this worker registers and reports under.
capabilities: CapabilitiesWhat this worker can run, announced to the coordinator at registration.
Implementations§
Source§impl Worker
impl Worker
Sourcepub fn new(id: impl Into<String>, capabilities: Capabilities) -> Self
pub fn new(id: impl Into<String>, capabilities: Capabilities) -> Self
A worker with an in-memory cache, an empty catalog, and per-worker
temp/env directories derived from id. Filters arrive later, with
the plans; the interpreter defaults to $SOMA_PYTHON, then
python3 — see Worker::with_python for why that matters.
Sourcepub fn with_python(self, python: impl Into<String>) -> Self
pub fn with_python(self, python: impl Into<String>) -> Self
Run filters in this interpreter rather than whatever python3
resolves to.
An embedding process should pass its own sys.executable: it is
the interpreter that pickled the filters, so it is the only one
certain to unpickle them.
Sourcepub fn with_cache(self, cache: Arc<dyn CacheStore>) -> Self
pub fn with_cache(self, cache: Arc<dyn CacheStore>) -> Self
Set a custom cache store (e.g. tiered or shared).
Sourcepub fn with_data_store(self, store: Arc<dyn DataStore>) -> Self
pub fn with_data_store(self, store: Arc<dyn DataStore>) -> Self
Set a persistent DataStore (S3, Zarr, etc.) for large data references.
Sourcepub fn with_temp_dir(self, path: PathBuf) -> Self
pub fn with_temp_dir(self, path: PathBuf) -> Self
Set a custom temp directory for HTTP bulk uploads.
Sourcepub fn temp_store(&self) -> &Arc<LocalDataStore>
pub fn temp_store(&self) -> &Arc<LocalDataStore>
Get the temp store (for HTTP upload endpoint).
Sourcepub fn register_filter(
&mut self,
node_id: impl Into<String>,
filter: Box<dyn Filter>,
)
pub fn register_filter( &mut self, node_id: impl Into<String>, filter: Box<dyn Filter>, )
Register a filter that this worker can execute.
Sourcepub fn get_filter(&self, node_id: &str) -> Option<Arc<dyn Filter>>
pub fn get_filter(&self, node_id: &str) -> Option<Arc<dyn Filter>>
Get a filter by node_id.
Sourcepub fn get_filter_state(&self, node_id: &str) -> Arc<Value>
pub fn get_filter_state(&self, node_id: &str) -> Arc<Value>
Get trained state for a filter.
Sourcepub fn read_states(&self, node_ids: &[String]) -> Result<HashMap<String, Value>>
pub fn read_states(&self, node_ids: &[String]) -> Result<HashMap<String, Value>>
Trained state of one or more nodes, read from the Python process.
The four methods below back the wire messages of the same names.
They existed on PythonProcess and in the daemon script from the
start; what was missing was anything calling them, so
soma-worker/src/server.rs answered all four with “not implemented
for SubprocessFilter” and DataParallel could not run.
Sourcepub fn write_states(&mut self, states: &HashMap<String, Value>) -> Result<()>
pub fn write_states(&mut self, states: &HashMap<String, Value>) -> Result<()>
Load states into the Python process (and the catalog beside it).
Sourcepub fn read_gradients(
&self,
node_ids: &[String],
) -> Result<HashMap<String, Value>>
pub fn read_gradients( &self, node_ids: &[String], ) -> Result<HashMap<String, Value>>
Gradients currently held by each node’s parameters.
Sourcepub fn write_gradients(&self, gradients: &HashMap<String, Value>) -> Result<()>
pub fn write_gradients(&self, gradients: &HashMap<String, Value>) -> Result<()>
Apply aggregated gradients to each node’s parameters.
Sourcepub fn set_filter_state(&mut self, node_id: &str, state: Value)
pub fn set_filter_state(&mut self, node_id: &str, state: Value)
Set trained state for a filter.
Sourcepub fn wrap_output(&self, output: Value) -> OutputDelivery
pub fn wrap_output(&self, output: Value) -> OutputDelivery
Wrap output in the right delivery: inline for small, DataRef for large.
Sourcepub fn registration_message(&self) -> WorkerToCoordinator
pub fn registration_message(&self) -> WorkerToCoordinator
Build a registration message.
Sourcepub fn execute_plan(&mut self, plan: &SerializedPlan) -> PlanResult
pub fn execute_plan(&mut self, plan: &SerializedPlan) -> PlanResult
Execute a serialized plan.
If the plan contains serialized filter definitions, they are registered temporarily for this execution (alongside any pre-registered filters).
In Fit mode: fits each filter (topological order), stores trained states, then forwards to propagate outputs. Returns states so the client can cache them.
In Forward mode: executes the compiled plan directly.
Sourcepub fn matches_target(&self, target: &RemoteTarget) -> bool
pub fn matches_target(&self, target: &RemoteTarget) -> bool
Check if this worker matches a remote target.
Auto Trait Implementations§
impl Freeze for Worker
impl !RefUnwindSafe for Worker
impl Send for Worker
impl Sync for Worker
impl Unpin for Worker
impl UnsafeUnpin for Worker
impl !UnwindSafe for Worker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more