nvflare.recipe.spec module

class ExecEnv(extra: dict | None = None)[source]

Bases: ABC

Constructor of ExecEnv

Parameters:

extra – a dict of extra properties

abstract abort_job(job_id: str) None[source]

Abort a running job.

Parameters:

job_id – The job ID to abort.

abstract deploy(job: FedJob) str[source]

Deploy a FedJob and return an execution response.

Parameters:

job – The FedJob to deploy.

Returns:

The job ID.

Return type:

str

get_extra_prop(prop_name: str, default=None)[source]

Get the specified extra property.

Parameters:
  • prop_name – name of the property

  • default – the default value to return if the named property does not exist.

Returns: value of the property or the default

abstract get_job_result(job_id: str, timeout: float = 0.0) str | None[source]

Get the result workspace of a job.

Parameters:
  • job_id – The job ID to get results for.

  • timeout – The timeout for the job to complete. Defaults to 0.0 (no timeout).

Returns:

The result workspace path if job completed, None if still running or stopped early.

Return type:

Optional[str]

abstract get_job_status(job_id: str) str | None[source]

Get the status of a job.

Parameters:

job_id – The job ID to check status for.

Returns:

The status of the job, or None if not supported.

Return type:

Optional[str]

class Recipe(job: FedJob)[source]

Bases: ABC

This is base class of a recipe. Recipes are implemented by jobs. A concrete recipe must provide the job for recipe implementation.

Parameters:

job – the job that implements the recipe.

add_client_input_filter(filter: Filter, tasks: List[str] | None = None, clients: List[str] | None = None)[source]

Add a filter to clients for incoming tasks from the server.

Parameters:
  • filter – the filter to be added

  • tasks – tasks that the filter applies to

  • clients – client names to add, if None, all clients will be added.

Returns: None

add_client_output_filter(filter: Filter, tasks: List[str] | None = None, clients: List[str] | None = None)[source]

Add a filter to clients for outgoing result to server.

Parameters:
  • filter – the filter to be added

  • tasks – tasks that the filter applies to

  • clients – client names to add, if None, all clients will be added.

Returns: None

add_decomposers(decomposers: List[str | Decomposer])[source]

Add decomposers to the job

Parameters:

decomposers – spec of decomposers. Can be class names or Decomposer objects

Returns: None

add_server_input_filter(filter: Filter, tasks: List[str] | None = None)[source]

Add a filter to server for incoming task result from clients. .

Parameters:
  • filter – the filter to be added

  • tasks – tasks that the filter applies to

Returns: None

add_server_output_filter(filter: Filter, tasks: List[str] | None = None)[source]

Add a filter to the server for outgoing tasks to clients.

Parameters:
  • filter – the filter to be added

  • tasks – tasks that the filter applies to

Returns: None

execute(env: ExecEnv, server_exec_params: dict = None, client_exec_params: dict = None) Run[source]

Execute the recipe in a specified execution environment.

Parameters:
  • env – the execution environment

  • server_exec_params – execution params for the server

  • client_exec_params – execution params for clients

Returns: Run to get job ID and execution results

export(job_dir: str, server_exec_params: dict | None = None, client_exec_params: dict | None = None, env: ExecEnv | None = None)[source]

Export the recipe to a job definition.

Parameters:
  • job_dir – directory where the job will be exported to.

  • server_exec_params – execution params for the server

  • client_exec_params – execution params for clients

  • env – the environment that the exported job will be running in

Returns: None

process_env(env: ExecEnv)[source]