nvflare.apis.server_engine_spec module

class ServerEngineSpec[source]

Bases: EngineSpec, ABC

abstract cancel_client_resources(resource_check_results: Dict[str, Tuple[bool, str]], resource_reqs: Dict[str, dict], fl_ctx: FLContext)[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 (is_resource_enough, resource reserve token if any)

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

  • fl_ctx – FLContext

abstract check_client_resources(job: Job, resource_reqs: Dict[str, dict], fl_ctx: FLContext) Dict[str, Tuple[bool, str | None]][source]

Sends the check_client_resources requests to the clients.

Parameters:
  • job – job object

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

  • fl_ctx – FLContext

Returns:

client_check_result}.

client_check_result is a tuple of (is_resource_enough, token); is_resource_enough is a bool indicates whether there is enough resources; token is for resource reservation / cancellation for this check request.

Return type:

A dict of {client_name

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

Gets the client name from client login token.

Parameters:

token – client login token

Returns:

Client name

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, optional=False, secure=False) 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

  • optional – whether this message is optional

  • secure – send the aux request in a secure way

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

abstract start_client_job(job_id, client_sites, fl_ctx: FLContext)[source]

To send the start client run commands to the clients

Parameters:
  • client_sites – client sites

  • job_id – job_id

  • fl_ctx – FLContext

Returns:

abstract sync_clients_from_main_process()[source]

To fetch the participating clients from the main parent process

Returns: clients

abstract update_job_run_status()[source]

To update the job run status to parent process.