nvflare.apis.server_engine_spec module
- class ServerEngineSpec[source]
Bases:
EngineSpec,ABC- abstract add_component(component_id: str, component)[source]
Add a component into the system.
- Parameters:
component_id – component ID
component – component object
Returns:
- 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 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_component(component_id: str) object[source]
Retrieve the system component from the engine.
- Parameters:
component_id – component ID
- Returns:
component object
- 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 multicast_aux_requests(topic: str, target_requests: dict[str, Shareable], timeout: float, fl_ctx: FLContext, optional: bool = False, secure: bool = False) dict[source]
Send requests to specified clients via the aux channel.
Implementation: simply calls the AuxRunner’s multicast_aux_requests method.
- Parameters:
topic – topic of the request
target_requests – requests of the target clients. Different target can have different request.
timeout – amount of time to wait for responses. 0 means fire and forget.
fl_ctx – FL context
optional – whether this request is optional
secure – whether to send the aux request in P2P secure
Returns: a dict of replies (client name => reply Shareable)
- 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:
- register_app_command(topic: str, cmd_func, *args, **kwargs)[source]
Register app command handler.
- Parameters:
topic – topic of the command to be handled
cmd_func – the function to handle the app command
*args – optional args to be passed to the cmd_func
**kwargs – optional kwargs to be passed to the cmd_func
Returns: None
- 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 AuxRunner’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, client_sites, fl_ctx: FLContext)[source]
To send the start client run commands to the clients
- Parameters:
client_sites – client sites
job – job object
fl_ctx – FLContext
Returns: