nvflare.apis.fl_component module¶
- class FLComponent[source]¶
Bases:
StatePersistable
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.
- fire_event(event_type: str, fl_ctx: FLContext)[source]¶
Fires an event.
- Parameters:
event_type (str) – The type of event.
fl_ctx (FLContext) – FLContext information.
- fire_fed_event(event_type: str, event_data: Shareable, fl_ctx: FLContext, targets=None)[source]¶
Fires a federation event.
A federation event means that the event will be sent to different sites. For example, if fire a federation event on the server side, one can decide what clients to send via the parameter targets. If fire a federation event on the client side, the event will be sent to the server.
- Parameters:
event_type (str) – The type of event.
event_data (Shareable) – The data of this fed event.
fl_ctx (FLContext) – FLContext information.
targets – The targets to send to. It is only used when fire federation event from server side.
- handle_event(event_type: str, fl_ctx: FLContext)[source]¶
Handles events.
- Parameters:
event_type (str) – event type fired by workflow.
fl_ctx (FLContext) – FLContext information.
- log_critical(fl_ctx: FLContext, msg: str, fire_event=True)[source]¶
Logs a message with logger.critical.
- Parameters:
fl_ctx (FLContext) – FLContext information.
msg (str) – The message to log.
fire_event (bool) – Whether to fire a log event.
- log_debug(fl_ctx: FLContext, msg: str, fire_event=False)[source]¶
Logs a message with logger.debug.
- Parameters:
fl_ctx (FLContext) – FLContext information.
msg (str) – The message to log.
fire_event (bool) – Whether to fire a log event.
- log_error(fl_ctx: FLContext, msg: str, fire_event=True)[source]¶
Logs a message with logger.error.
- Parameters:
fl_ctx (FLContext) – FLContext information.
msg (str) – The message to log.
fire_event (bool) – Whether to fire a log event.
- log_exception(fl_ctx: FLContext, msg: str, fire_event=False)[source]¶
Logs exception message with logger.error.
- Parameters:
fl_ctx (FLContext) – FLContext information.
msg (str) – The message to log.
fire_event (bool) – Whether to fire a log event. Unused.
- log_info(fl_ctx: FLContext, msg: str, fire_event=False)[source]¶
Logs a message with logger.info.
These log_XXX methods are implemented because we want to have a unified way of logging messages. For example, in this method, we are using generate_log_message to add the FLContext information into the message. And we can decide whether to fire a log event afterwards.
- Parameters:
fl_ctx (FLContext) – FLContext information.
msg (str) – The message to log.
fire_event (bool) – Whether to fire a log event.
- log_warning(fl_ctx: FLContext, msg: str, fire_event=True)[source]¶
Logs a message with logger.warning.
- Parameters:
fl_ctx (FLContext) – FLContext information.
msg (str) – The message to log.
fire_event (bool) – Whether to fire a log event.
- property name¶