vantage6.algorithm.tools.mock_client.MockAlgorithmClient#

class MockAlgorithmClient(datasets, module, collaboration_id=None, organization_ids=None, node_ids=None)#

Bases: object

The MockAlgorithmClient mimics the behaviour of the AlgorithmClient. It can be used to mock the behaviour of the AlgorithmClient and its communication with the server.

Parameters:
  • datasets (list[list[dict]]) –

    A list that contains the datasets that are used in the mocked algorithm. The inner list contains the datasets for each organization; the outer list is for each organization. A single dataset should be described as a dictionary with the same keys as in a node configuration:

    • database: str (path to file or SQL connection string) or pd.DataFrame

    • db_type (str, e.g. “csv” or “sql”)

    There are also a number of keys that are optional but may be required depending on the database type: - query: str (required for SQL/Sparql databases) - sheet_name: str (optional for Excel databases) - preprocessing: dict (optional, see the documentation for

    preprocessing for more information)

    Note that if the database is a pandas DataFrame, the type and input_data keys are not required.

  • module (str) – The name of the module that contains the algorithm.

  • collaboration_id (int, optional) – Sets the mocked collaboration id to this value. Defaults to 1.

  • organization_ids (list[int], optional) – Set the organization ids to this value. The first value is used for this organization, the rest for child tasks. Defaults to [0, 1, 2, ..].

  • node_ids (list[int], optional) – Set the node ids to this value. The first value is used for this node, the rest for child tasks. Defaults to [0, 1, 2, …].

__init__(datasets, module, collaboration_id=None, organization_ids=None, node_ids=None)#

Methods

__init__(datasets, module[, ...])

wait_for_results(task_id[, interval])

Mock waiting for results - just return the results as tasks are completed synchronously in the mock client.

class Collaboration(parent)#

Bases: SubClient

Collaboration subclient for the MockAlgorithmClient

get(is_encrypted=True)#

Get mocked collaboration

Parameters:

is_encrypted (bool) – Whether the collaboration is encrypted or not. Default True.

Returns:

A mocked collaboration.

Return type:

dict

class Node(parent)#

Bases: SubClient

Node subclient for the MockAlgorithmClient

get(is_online=True)#

Get mocked node

Parameters:

is_online (bool) – Whether the node is online or not. Default True.

Returns:

A mocked node.

Return type:

dict

class Organization(parent)#

Bases: SubClient

Organization subclient for the MockAlgorithmClient

get(id_)#

Get mocked organization by ID

Parameters:

id (int) – The id of the organization.

Returns:

A mocked organization.

Return type:

dict

list()#

Get mocked organizations in the collaboration.

Returns:

A list of mocked organizations in the collaboration.

Return type:

list[dict]

class Result(parent)#

Bases: SubClient

Result subclient for the MockAlgorithmClient

from_task(task_id)#

Return the results of the task with the given id.

Parameters:

task_id (int) – The id of the task.

Returns:

The results of the task.

Return type:

list[Any]

get(id_)#

Get mocked result by ID

Parameters:

id (int) – The id of the result.

Returns:

A mocked result.

Return type:

Any

class Run(parent)#

Bases: SubClient

Run subclient for the MockAlgorithmClient

from_task(task_id)#

Get mocked runs by task ID

Parameters:

task_id (int) – The id of the task.

Returns:

A list of mocked runs.

Return type:

list[dict]

get(id_)#

Get mocked run by ID

Parameters:

id (int) – The id of the run.

Returns:

A mocked run.

Return type:

dict

class SubClient(parent)#

Bases: object

Create sub groups of commands using this SubClient

Parameters:

parent (MockAlgorithmClient) – The parent client

class Task(parent)#

Bases: SubClient

Task subclient for the MockAlgorithmClient

create(input_, organizations, name='mock', description='mock')#

Create a new task with the MockProtocol and return the task id.

Parameters:
  • input (dict) – The input data that is passed to the algorithm. This should at least contain the key ‘method’ which is the name of the method that should be called. Other keys depend on the algorithm.

  • organizations (list[int]) – A list of organization ids that should run the algorithm.

  • name (str, optional) – The name of the task, by default “mock”

  • description (str, optional) – The description of the task, by default “mock”

Returns:

A dictionary with information on the created task.

Return type:

task

get(task_id)#

Return the task with the given id.

Parameters:

task_id (int) – The id of the task.

Returns:

The task details.

Return type:

dict

wait_for_results(task_id, interval=1)#

Mock waiting for results - just return the results as tasks are completed synchronously in the mock client.

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

  • interval (float) – Interval in seconds between checking for new results. This is ignored in the mock client but included to match the signature of the AlgorithmClient.

Returns:

List of task results.

Return type:

list