nvflare.app_common.resource_managers.auto_clean_resource_manager module

class AutoCleanResourceManager(resources: dict, expiration_period: int = 30, check_period: float = 1.0)[source]

Bases: ResourceManagerSpec, FLComponent, ABC

AutoCleanResourceManager implementation.

It will automatically clean up reserved resources.

Parameters:
  • resources (dict) – Specify the list of resources unit

  • expiration_period (int) – Number of seconds to hold the resources reserved. default to 30. If check_resources is called but after “expiration_period” no allocate resource is called, then the reserved resources will be released.

  • check_period (float) – Number of seconds to check for expired resources. default to 1.0.

allocate_resources(resource_requirement: dict, token: str, fl_ctx: FLContext) dict[source]

Allocates resources.

Note

resource requirements and resources may be different things.

Parameters:
  • resource_requirement – a dict that specifies resource requirement

  • token – a resource reservation token returned by check_resources

  • fl_ctx – the FLContext

Returns:

A dict of allocated resources

cancel_resources(resource_requirement: dict, token: str, fl_ctx: FLContext)[source]

Cancels reserved resources if any.

Parameters:
  • resource_requirement – a dict that specifies resource requirement

  • token – a resource reservation token returned by check_resources

  • fl_ctx – the FLContext

Note

If check_resource didn’t return a token, then don’t need to call this method

check_resources(resource_requirement: dict, fl_ctx: FLContext)[source]

Checks whether the specified resource requirement can be satisfied.

Parameters:
  • resource_requirement – a dict that specifies resource requirement

  • fl_ctx – the FLContext

Returns:

A tuple of (is_resource_enough, token).

is_resource_enough is a bool indicates whether there is enough resources; token is for resource reservation / cancellation for this check request.

free_resources(resources: dict, token: str, fl_ctx: FLContext)[source]

Frees resources.

Parameters:
  • resources – resources to be freed

  • token – a resource reservation token returned by check_resources

  • fl_ctx – the FLContext

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.

report_resources(fl_ctx)[source]

Reports resources.