nvflare.app_common.utils.fl_component_wrapper module

class FLComponentWrapper[source]

Bases: FLComponent

Init FLComponent.

The FLComponent is the base class of all FL Components. (executors, controllers, responders, filters, aggregators, and widgets are all FLComponents)

FLComponents have the capability to handle and fire events and contain various methods for logging.

STATE = None
abort()[source]

Called by the framework for the Learner to gracefully abort the current task.

This could be caused by multiple reasons: - user issued the abort command to stop the whole job - Controller runs into some condition that requires the job to be aborted

critical(msg: str)[source]

Convenience method for logging a CRITICAL message with contextual info

Parameters:

msg – the message to be logged

Returns:

debug(msg: str)[source]

Convenience method for logging a DEBUG message with contextual info

Parameters:

msg – the message to be logged

Returns:

error(msg: str)[source]

Convenience method for logging an ERROR message with contextual info

Parameters:

msg – the message to be logged

Returns:

event(event_type)[source]

Fires an event.

Parameters:

event_type (str) – The type of event.

exception(msg: str)[source]

Convenience method for logging an EXCEPTION message with contextual info

Parameters:

msg – the message to be logged

Returns:

finalize()[source]

Called by the framework to finalize the Learner (close/release resources gracefully) when the job is finished.

After this call, the Learner will be destroyed.

Args:

get_component(component_id: str) Any[source]

Get the specified component from the context

Parameters:

component_id – ID of the component

Returns: the specified component if it is defined; or None if not.

get_context_prop(key: str, default=None)[source]

Convenience method for getting specified property from the FL Context.

Parameters:
  • key – name of the property

  • default – default value if the prop doesn’t exist in FL Context

Returns: value of the prop if it exists in the context; or the specified default if it doesn’t.

get_shareable_header(key: str, default=None)[source]

Convenience method for getting specified header from the shareable.

Parameters:
  • key – name of the header

  • default – default value if the header doesn’t exist

Returns: value of the header if it exists in the shareable; or the specified default if it doesn’t.

info(msg: str)[source]

Convenience method for logging an INFO message with contextual info

Parameters:

msg – the message to be logged

Returns:

initialize()[source]

Called by the framework to initialize the Learner object. This is called before the Learner can train or validate. This is called only once.

is_aborted() bool[source]

Check whether the task has been asked to abort by the framework.

Returns: whether the task has been asked to abort by the framework

panic(reason: str)[source]

Signals a fatal condition that could cause the RUN to end.

Parameters:

reason (str) – The reason for panic.

stop_task(reason: str)[source]

Stop the current task. This method is to be called by the Learner’s training or validation code when it runs into a situation that the task processing cannot continue.

Parameters:

reason – why the task cannot continue

Returns:

warning(msg: str)[source]

Convenience method for logging a WARNING message with contextual info

Parameters:

msg – the message to be logged

Returns: