nvflare.app_common.workflows.wf_controller module

class WFController(*args, persistor_id: str = 'persistor', **kwargs)[source]

Bases: ModelController, ABC

Workflow Controller API for FLModel-based ModelController.

Parameters:

persistor_id (str, optional) – ID of the persistor component. Defaults to “”.

load_model()[source]

Load initial model from persistor. If persistor is not configured, returns empty FLModel.

Returns:

FLModel

abstract run()[source]

Main run routine for the controller workflow.

save_model(model: FLModel)[source]

Saves model with persistor. If persistor is not configured, does not save.

Parameters:

model (FLModel) – model to save.

Returns:

None

send_model(task_name: str = 'train', data: FLModel | None = None, targets: List[str] | None = None, timeout: int = 0, wait_time_after_min_received: int = 10, callback: Callable[[FLModel], None] | None = None) None[source]

Send a task with data to targets (non-blocking). Callback is called when a result is received.

Parameters:
  • task_name (str, optional) – name of the task. Defaults to “train”.

  • data (FLModel, optional) – FLModel to be sent to clients. Defaults to None.

  • targets (List[str], optional) – the list of target client names or None (all clients). Defaults to None.

  • timeout (int, optional) – time to wait for clients to perform task. Defaults to 0 (never time out).

  • wait_time_after_min_received (int, optional) – time to wait after minimum number of client responses have been received. Defaults to 10.

  • callback (Callable[[FLModel], None], optional) – callback when a result is received. Defaults to None.

Returns:

None

send_model_and_wait(task_name: str = 'train', data: FLModel | None = None, targets: List[str] | None = None, timeout: int = 0, wait_time_after_min_received: int = 10) List[FLModel][source]

Send a task with data to targets and wait for results.

Parameters:
  • task_name (str, optional) – name of the task. Defaults to “train”.

  • data (FLModel, optional) – FLModel to be sent to clients. Defaults to None.

  • targets (List[str], optional) – the list of target client names or None (all clients). Defaults to None.

  • timeout (int, optional) – time to wait for clients to perform task. Defaults to 0 (never time out).

  • wait_time_after_min_received (int, optional) – time to wait after minimum number of client responses have been received. Defaults to 10.

Returns:

List[FLModel]