fl4health.reporting.json_reporter module

class FileReporter(run_id=None, output_folder=PosixPath('metrics'))[source]

Bases: BaseReporter

__init__(run_id=None, output_folder=PosixPath('metrics'))[source]

Reports data each round and saves as a json.

Parameters:
  • run_id (str | None, optional) – the identifier for the run which these metrics are from. If left as None will check if an id is provided during initialize, otherwise uses a UUID.

  • output_folder (str | Path) – the folder to save the metrics to. The metrics will be saved in a file named {output_folder}/{run_id}.json. Optional, default is “metrics”.

dump()[source]
Return type:

None

initialize(**kwargs)[source]

Method for initializing reporters with client/server information

This method is called once by the client or server during initialization.

Parameters:

kwargs (Any) – arbitrary keyword arguments containing information from the client or server that might be useful for initializing the reporter. This information should be treated as optional and this method should work even if no keyword arguments are passed.

Return type:

None

report(data, round=None, epoch=None, step=None)[source]

A method called by clients or servers to send data to the reporter.

The report method is called by the client/server at frequent intervals (ie step, epoch, round) and sometimes outside of a FL round (for high level summary data). The json reporter is hardcoded to report at the ‘round’ level and therefore ignores calls to the report method made every epoch or every step.

Parameters:
  • data (dict) – The data to maybe report from the server or client.

  • round (int | None, optional) – The current FL round. If None, this indicates that the method was called outside of a round (e.g. for summary information). Defaults to None.

  • epoch (int | None, optional) – The current epoch. If None then this method was not called within the scope of an epoch. Defaults to None.

  • step (int | None, optional) – The current step (total). If None then this method was called outside the scope of a training or evaluation step (eg. at the end of an epoch or round) Defaults to None.

Return type:

None

shutdown()[source]

Called by the client/server on shutdown.

Return type:

None

class JsonReporter(run_id=None, output_folder=PosixPath('metrics'))[source]

Bases: FileReporter

dump()[source]

Dumps the current metrics to a JSON file at {output_folder}/{run_id.json}

Return type:

None