nvflare.apis.server_engine_spec module

class ServerEngineSpec[source]

Bases: ABC

abstract cancel_client_resources(resource_check_results: Dict[str, Tuple[bool, str]], resource_reqs: Dict[str, dict])[source]

Cancels the request resources for the job.

Parameters
  • resource_check_results – A dict of {client_name: client_check_result} where client_check_result is a tuple of {client check OK, resource reserve token if any}

  • resource_reqs – A dict of {client_name: resource requirements dict}

abstract check_client_resources(resource_reqs: Dict[str, dict]) Dict[str, Tuple[bool, Optional[str]]][source]

Sends the check_client_resources requests to the clients.

Parameters

resource_reqs – A dict of {client_name: resource requirements dict}

Returns

client_check_result} where client_check_result

is a tuple of {client check OK, resource reserve token if any}

Return type

A dict of {client_name

fire_and_forget_aux_request(targets: [], topic: str, request: Shareable, fl_ctx: FLContext) dict[source]
abstract fire_event(event_type: str, fl_ctx: FLContext)[source]
abstract get_client_name_from_token(token: str) str[source]

Gets client name from a client login token.

abstract get_clients() List[Client][source]
abstract get_component(component_id: str) object[source]
abstract get_widget(widget_id: str) Widget[source]

Get the widget with the specified ID.

Parameters

widget_id – ID of the widget

Returns: the widget or None if not found

abstract get_workspace() Workspace[source]
abstract new_context() FLContext[source]
abstract persist_components(fl_ctx: FLContext, completed: bool)[source]

To persist the FL running components

Parameters
  • fl_ctx – FLContext

  • completed – flag to indicate where the run is complete

Returns:

abstract register_aux_message_handler(topic: str, message_handle_func)[source]

Register aux message handling function with specified topics.

Exception is raised when:

a handler is already registered for the topic; bad topic - must be a non-empty string bad message_handle_func - must be callable

Implementation Note:

This method should simply call the ServerAuxRunner’s register_aux_message_handler method.

Parameters
  • topic – the topic to be handled by the func

  • message_handle_func – the func to handle the message. Must follow aux_message_handle_func_signature.

abstract restore_components(snapshot: RunSnapshot, fl_ctx: FLContext)[source]

To restore the FL components from the saved snapshot

Parameters
  • snapshot – RunSnapshot

  • fl_ctx – FLContext

Returns:

abstract send_aux_request(targets: [], topic: str, request: Shareable, timeout: float, fl_ctx: FLContext) dict[source]

Send a request to specified clients via the aux channel.

Implementation: simply calls the ServerAuxRunner’s send_aux_request method.

Parameters
  • targets – target clients. None or empty list means all clients

  • topic – topic of the request

  • request – request to be sent

  • timeout – number of secs to wait for replies. 0 means fire-and-forget.

  • fl_ctx – FL context

Returns: a dict of replies (client name => reply Shareable)

abstract start_client_job(job_id, client_sites)[source]

To send the start client run commands to the clients

Parameters
  • client_sites – client sites

  • job_id – job_id

Returns:

abstract sync_clients_from_main_process()[source]

To fetch the participating clients from the main parent process

Returns: clients

abstract validate_clients(client_names: List[str]) Tuple[List[Client], List[str]][source]

Validate specified client names.

Parameters

client_names – list of names to be validated

Returns: a list of validate clients and a list of invalid client names