flip.nvflare.components.flip_server_event_handler

Classes

ServerEventHandler

ServerEventHandler is a generic component that handles system events triggered by nvflare

Module Contents

class flip.nvflare.components.flip_server_event_handler.ServerEventHandler(model_id: str = '', validation_json_generator_id: str = 'json_generator', persist_and_cleanup_id: str = 'persist_and_cleanup', flip: flip.FLIP = FLIP())

Bases: nvflare.apis.fl_component.FLComponent

ServerEventHandler is a generic component that handles system events triggered by nvflare or custom flip events. It executes logic inside its own event handler but may also call other component’s event handlers directly to overcome the non-deterministic order in which nvflare handles events i.e handling ValidationJsonGenerator component events.

Parameters:
  • model_id (str, optional) – ID of the model. When empty, the model ID is resolved lazily from job metadata via get_flip_model_id on first status update.

  • validation_json_generator_id (str, optional) – Component ID for the validation JSON generator.

  • persist_and_cleanup_id (str, optional) – Component ID for the persist-and-cleanup component.

  • flip (FLIP, optional) – FLIP client instance.

_model_id_fallback = ''
_model_id: str | None = None
validation_json_generator_id = 'json_generator'
validation_json_generator = None
persist_and_cleanup_id = 'persist_and_cleanup'
persist_and_cleanup = None
flip
fatal_error = False
final_status: flip.constants.ModelStatus | None = None
_resolve_model_id(fl_ctx: nvflare.apis.fl_context.FLContext) str

Resolve model ID lazily from job metadata, falling back to the constructor arg.

Parameters:

fl_ctx (FLContext) – The FL context for the current job.

Returns:

The resolved model ID.

Return type:

str

_update_status(fl_ctx: nvflare.apis.fl_context.FLContext, status: flip.constants.ModelStatus | None) None

Resolve model ID lazily and update training status.

Parameters:
  • fl_ctx (FLContext) – The FL context for the current job.

  • status (ModelStatus | None) – The new model status to set.

_relay_round_event(fl_ctx: nvflare.apis.fl_context.FLContext, event: flip.schemas.FLLogEvent) None

Relay a stock round boundary to the hub as a typed fact.

Facts only — display text is composed hub-side. NVFLARE’s CURRENT_ROUND prop is 0-based; the wire contract is 1-based. ROUND_AGGREGATED counts come from the sticky props seeded here at round start (“0 of m”) and overwritten by the FLIP ScatterAndGather controller as it accepts client results.

Parameters:
  • fl_ctx (FLContext) – The FL context carrying the round props.

  • event (FLLogEvent) – ROUND_STARTED or ROUND_AGGREGATED.

_expected_client_count(fl_ctx: nvflare.apis.fl_context.FLContext) int | None

Best-effort count of the clients targeted this round; None when unavailable.

Parameters:

fl_ctx (FLContext) – The FL context to read the engine from.

Returns:

len(engine.get_clients()), or None when the engine cannot be read (the round then closes with the uncounted wording).

Return type:

int | None

_evaluation_wholly_failed() bool

Whether this is an evaluation job in which every validate task failed.

Training jobs wire the base ValidationJsonGenerator, which tracks no failures, so the isinstance check also serves as the “is this an evaluation job” test.

Returns:

True when the evaluation produced failures and no results at all.

Return type:

bool

_terminal_status(default: flip.constants.ModelStatus) flip.constants.ModelStatus

Resolve the run’s terminal status, most salient cause first.

A recorded fatal system error is the root cause and outranks everything. A user-requested abort outranks the evaluation failures it necessarily caused (aborting a run cancels its in-flight validate tasks, which must not be reported as ERROR). An evaluation in which every validate task failed outranks default — otherwise a wholly failed run reports success on an empty results file (FLIP#754), or reports a trailing upload failure as its cause.

Parameters:

default (ModelStatus) – The status to use when no failure cause is recorded — the outcome of the upload itself.

Returns:

The status to report to the hub.

Return type:

ModelStatus

handle_event(event_type: str, fl_ctx: nvflare.apis.fl_context.FLContext) None
__set_dependencies(fl_ctx: nvflare.apis.fl_context.FLContext) None