7.5. Algorithm client and tools#

7.5.1. Algorithm Client#

vantage6.algorithm.client#

class AlgorithmClient(token, *args, **kwargs)#

Bases: ClientBase

Interface to communicate between the algorithm container and the central server via a local proxy server.

An algorithm container cannot communicate directly to the central server as it has no internet connection. The algorithm can, however, talk to a local proxy server which has interface to the central server. This way we make sure that the algorithm container does not share details with others, and we also can encrypt the results for a specific receiver. Thus, this not a interface to the central server but to the local proxy server - however, the interface looks identical to make it easier to use.

Parameters:
  • token (str) – JWT (container) token, generated by the node the algorithm container runs on

  • *args – Arguments passed to the parent ClientBase class.

  • **kwargs – Arguments passed to the parent ClientBase class.

class Collaboration(parent)#

Bases: SubClient

Get information about the collaboration.

get()#

Get the collaboration data.

Returns:

Dictionary containing the collaboration data.

Return type:

dict

class Node(parent)#

Bases: SubClient

Get information about the node.

get()#

Get the node data.

Returns:

Dictionary containing data on the node this algorithm is running on.

Return type:

dict

class Organization(parent)#

Bases: SubClient

Get information about organizations in the collaboration.

get(id_)#

Get an organization by ID.

Parameters:

id (int) – ID of the organization to retrieve

Returns:

Dictionary containing the organization data.

Return type:

dict

list()#

Obtain all organization in the collaboration.

The container runs in a Node which is part of a single collaboration. This method retrieves all organization data that are within that collaboration. This can be used to target specific organizations in a collaboration.

Returns:

List of organizations in the collaboration.

Return type:

list[dict]

class Result(parent)#

Bases: SubClient

Result client for the algorithm container.

This client is used to get results from the central server.

from_task(task_id)#

Obtain results from a specific task at the server.

Containers are allowed to obtain the results of their children (having the same job_id at the server). The permissions are checked at te central server.

Results are decrypted by the proxy server and decoded here before returning them to the algorithm.

Parameters:

task_id (int) – ID of the task from which you want to obtain the results

Returns:

List of results. The type of the results depends on the algorithm.

Return type:

list[Any]

get(id_)#

Obtain a specific result from the central server.

Parameters:

id (int) – ID of the algorithm run of which the result should be obtained.

Returns:

Result of the algorithm run.

Return type:

Any

class Run(parent)#

Bases: SubClient

Algorithm Run client for the algorithm container.

This client is used to obtain algorithm runs of tasks with the same job_id from the central server.

from_task(task_id)#

Obtain algorithm runs from a specific task at the server.

Containers are allowed to obtain the runs of their children (having the same job_id at the server). The permissions are checked at te central server.

Note that the returned results are not decrypted. The algorithm is responsible for decrypting the results.

Parameters:

task_id (int) – ID of the task from which you want to obtain the algorithm runs

Returns:

List of algorithm run data. The type of the results depends on the algorithm.

Return type:

list

get(id_)#

Obtain a specific algorithm run from the central server.

Parameters:

id (int) – ID of the algorithm run that should be obtained.

Returns:

Algorithm run data.

Return type:

dict

class Task(parent)#

Bases: SubClient

A task client for the algorithm container.

It provides functions to get task information and create new tasks.

create(input_, organizations=None, name='subtask', description=None)#

Create a new (child) task at the central server.

Containers are allowed to create child tasks (having the same job_id) at the central server. The docker image must be the same as the docker image of this container self.

Parameters:
  • input (bytes) – Input to the task. Should be b64 encoded.

  • organizations (list[int]) – List of organization IDs that should execute the task.

  • name (str, optional) – Name of the subtask

  • description (str, optional) – Description of the subtask

Returns:

Dictionary containing information on the created task

Return type:

dict

get(task_id)#

Retrieve a task at the central server.

Parameters:

task_id (int) – ID of the task to retrieve

Returns:

Dictionary containing the task information

Return type:

dict

class VPN(parent)#

Bases: SubClient

A VPN client for the algorithm container.

It provides functions to obtain the IP addresses of other containers.

get_addresses(only_children=False, only_parent=False, include_children=False, include_parent=False, label=None)#

Get information about the VPN IP addresses and ports of other algorithm containers involved in the current task. These addresses can be used to send VPN communication to.

Parameters:
  • only_children (bool, optional) – Only return the IP addresses of the children of the current task, by default False. Incompatible with only_parent.

  • only_parent (bool, optional) – Only return the IP address of the parent of the current task, by default False. Incompatible with only_children.

  • include_children (bool, optional) – Include the IP addresses of the children of the current task, by default False. Incompatible with only_parent, superseded by only_children.

  • include_parent (bool, optional) – Include the IP address of the parent of the current task, by default False. Incompatible with only_children, superseded by only_parent.

  • label (str, optional) – The label of the port you are interested in, which is set in the algorithm Dockerfile. If this parameter is set, only the ports with this label will be returned.

Returns:

List of dictionaries containing the IP address and port number, and other information to identify the containers. If obtaining the VPN addresses from the server fails, a dictionary with a ‘message’ key is returned instead.

Return type:

list[dict] | dict

get_child_addresses()#

Get the IP addresses and port numbers of the children of the current task.

Returns:

List of dictionaries containing the IP address and port number, and other information to identify the containers. If obtaining the VPN addresses from the server fails, a dictionary with a ‘message’ key is returned instead.

Return type:

List[dict]

get_parent_address()#

Get the IP address and port number of the parent of the current task.

Returns:

Dictionary containing the IP address and port number, and other information to identify the containers. If obtaining the VPN addresses from the server fails, a dictionary with a ‘message’ key is returned instead.

Return type:

dict

authenticate(credentials=None, path=None)#

Overwrite base authenticate function to prevent algorithm containers from trying to authenticate, which they would be unable to do (they are already provided with a token on container startup).

Function parameters have only been included to make the interface identical to the parent class. They are not used.

Parameters:
  • credentials (dict) – Credentials to authenticate with.

  • path (str) – Path to the credentials file.

Raises:

NotImplementedError – Always.

Return type:

None

refresh_token()#

Overwrite base refresh_token function to prevent algorithm containers from trying to refresh their token, which they would be unable to do.

Raises:

NotImplementedError – Always.

Return type:

None

request(*args, **kwargs)#

Make a request to the central server. This overwrites the parent function so that containers will not try to refresh their token, which they would be unable to do.

Parameters:
  • *args – Arguments passed to the parent ClientBase.request function.

  • **kwargs – Arguments passed to the parent ClientBase.request function.

Returns:

Response from the central server.

Return type:

dict

wait_for_results(task_id, interval=1)#

Poll the central server until results are available and then return them.

Parameters:
  • task_id (int) – ID of the task for which the results should be obtained.

  • interval (float) – Interval in seconds to wait between checking server for results.

Returns:

List of task results.

Return type:

list

7.5.2. Algorithm tools#

vantage6.tools.wrappers#

vantage6.tools.wrap#

vantage6.tools.mock_client#

vantage6.tools.util#