nvflare.client.defs module

exception AgentClosed[source]

Bases: Exception

exception CallStateError[source]

Bases: Exception

class FlareAgent[source]

Bases: ABC

abstract get_task(timeout=None)[source]

Get a task from FLARE. This is a blocking call.

If timeout is specified, this call is blocked only for the specified amount of time. If timeout is not specified, this call is blocked forever until a task is received or agent is closed.

Parameters:

timeout – amount of time to block

Returns: None if no task is available during before timeout; or a Task object if task is available. :raises AgentClosed exception if the agent is closed before timeout.: :raises CallStateError exception if the call is not made properly.:

Note: the application must make the call only when it is just started or after a previous task’s result has been submitted.

abstract start()[source]
abstract stop()[source]
submit_result(result: TaskResult) bool[source]

Submit the result of the current task. This is a blocking call. The agent will try to send the result to flare site until it is successfully sent or the task is aborted or the agent is closed.

Parameters:

result – result to be submitted

Returns: whether the result is submitted successfully Raises: the CallStateError exception if the submit_result call is not made properly.

Notes: the application must only make this call after the received task is processed. The call can only be made a single time regardless whether the submission is successful.

class MetaKey[source]

Bases: object

CURRENT_ROUND = 'current_round'
DATA_KIND = 'data_kind'
FILTER_HISTORY = 'filter_history'
INITIAL_METRICS = 'initial_metrics'
NUM_STEPS_CURRENT_ROUND = 'NUM_STEPS_CURRENT_ROUND'
PROCESSED_ALGORITHM = 'PROCESSED_ALGORITHM'
PROCESSED_KEYS = 'PROCESSED_KEYS'
TOTAL_ROUND = 'total_round'
class MsgHeader[source]

Bases: object

RC = 'rc'
TASK_ID = 'task_id'
TASK_NAME = 'task_name'
class PayloadKey[source]

Bases: object

DATA = 'data'
META = 'meta'
class RC[source]

Bases: object

BAD_TASK_DATA = 'BAD_TASK_DATA'
EXECUTION_EXCEPTION = 'EXECUTION_EXCEPTION'
OK = 'OK'
class Task(task_name: str, task_id: str, meta: dict, data)[source]

Bases: object

class TaskResult(meta: dict, data, return_code='OK')[source]

Bases: object

agent_site_fqcn(site_name: str, agent_id: str, job_id=None)[source]