nvflare.client.api module

clear(ctx: APIContext | None = None)[source]

Clears the cache.

get_config(ctx: APIContext | None = None) Dict[source]

Gets the ClientConfig dictionary.

Returns:

A dict of the configuration used in Client API.

get_context(ctx: APIContext | None = None) APIContext[source]

Gets an APIContext.

Parameters:

ctx (Optional[APIContext]) – The context to use, if None means use default context. Defaults to None.

Raises:

RuntimeError – if can’t get a valid APIContext.

Returns:

An APIContext.

get_job_id(ctx: APIContext | None = None) str[source]

Gets job id.

Returns:

The current job id.

get_site_name(ctx: APIContext | None = None) str[source]

Gets site name.

Returns:

The site name of this client.

get_task_name(ctx: APIContext | None = None) str[source]

Gets task name.

Returns:

The task name.

init(rank: str | int | None = None, config_file: str | None = None) APIContext[source]

Initializes NVFlare Client API environment.

Parameters:
  • rank (str) – local rank of the process. It is only useful when the training script has multiple worker processes. (for example multi GPU)

  • config_file (str) – client api configuration.

Returns:

APIContext

is_evaluate(ctx: APIContext | None = None) bool[source]

Returns whether the current task is an evaluate task.

Returns:

True, if the current task is an evaluate task. False, otherwise.

is_running(ctx: APIContext | None = None) bool[source]

Returns whether the NVFlare system is up and running.

Returns:

True, if the system is up and running. False, otherwise.

is_submit_model(ctx: APIContext | None = None) bool[source]

Returns whether the current task is a submit_model task.

Returns:

True, if the current task is a submit_model. False, otherwise.

is_train(ctx: APIContext | None = None) bool[source]

Returns whether the current task is a training task.

Returns:

True, if the current task is a training task. False, otherwise.

log(key: str, value: Any, data_type: AnalyticsDataType, ctx: APIContext | None = None, **kwargs)[source]

Logs a key value pair.

We suggest users use the high-level APIs in nvflare/client/tracking.py

Parameters:
  • key (str) – key string.

  • value (Any) – value to log.

  • data_type (AnalyticsDataType) – the data type of the “value”.

  • kwargs – additional arguments to be included.

Returns:

whether the key value pair is logged successfully

receive(timeout: float | None = None, ctx: APIContext | None = None) FLModel | None[source]

Receives model from NVFlare side.

Returns:

An FLModel received.

send(model: FLModel, clear_cache: bool = True, ctx: APIContext | None = None) None[source]

Sends the model to NVFlare side.

Parameters:
  • model (FLModel) – The FLModel object to be sent.

  • clear_cache (bool) – Whether to clear the cache after send.

shutdown(ctx: APIContext | None = None)[source]

Releases all threads and resources used by the API and stops operation.

system_info(ctx: APIContext | None = None) Dict[source]

Gets NVFlare system information.

System information will be available after a valid FLModel is received. It does not retrieve information actively.

Note

system information includes job id and site name.

Returns:

A dict of system information.