nvflare.client.ipc_agent module¶
- class IPCAgent(root_url: str, flare_site_name: str, agent_id: str, workspace_dir: str, secure_mode=False, submit_result_timeout=30.0, flare_site_heartbeat_timeout=60.0, job_id=None, flare_site_url=None)[source]¶
Bases:
FlareAgent
Constructor of Flare Agent. The agent is responsible for communicating with the Flare Client Job cell (CJ) to get task and to submit task result.
- Parameters:
root_url – the URL to the server parent cell (SP)
flare_site_name – the CJ’s site name (client name)
agent_id – the unique ID of the agent
workspace_dir – directory that contains startup folder and comm_config.json
secure_mode – whether the connection is in secure mode or not
submit_result_timeout – when submitting task result, how long to wait for response from the CJ
flare_site_heartbeat_timeout – max time allowed for missing heartbeats from CJ
job_id – ID of the current Flare Job. Only needed for child-based communication with CJ
flare_site_url – URL for connection to CJ. Only needed for child-based communication with CJ
- 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.
- start()[source]¶
Start the agent. This method must be called to enable CJ/Agent communication.
Returns: None
- stop()[source]¶
Stop the agent. After this is called, there will be no more communications between CJ and agent.
Returns: None
- 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.