Globals - Share values between nodes

class manta_light.globals.Globals(host: str, port: int, swarm_id: PairId, task_id: PairId, chunk_size: int = 1048576)

Class which deals with global manipulation (getter and setter)

Parameters:
  • host (str) – Manager host

  • port (int) – Manager port

  • task_id (str) – Task ID

  • chunk_size (int) – Chunk size

__getitem__(tag: str) dict

Get the results of a Task

Parameters:

tag (str) – The tag of the result to get

Returns:

The response from the world service

Return type:

dict

Examples

Inside a Task class, you can access globals defined by a Swarm by using the attribute self.world automatically defined by Task:

>>> weights = self.world.globals["global_model_params"]
async _get_global(service: WorldStub, request: GlobalTag) GlobalValue

Get global from the database

Parameters:
  • service (WorldStub) – Service

  • request (GlobalTag) – Global tag

Returns:

Global value

Return type:

GlobalValue

async async_get(tag: str)

Get the results of tasks

Parameters:

tag (str) – The tag of the result to get

Returns:

The response from the world service

Return type:

dict

Examples

Same as __getitem__ but asynchronous.

>>> weights = await self.world.globals.async_get(
...     "global_model_params"
... )
async async_set(tag: str, result: dict)

Set a result of a task

Parameters:
  • tag (str) – The tag of the result to set

  • result (dict) – The result to set

Examples

Same as __setitem__ but asynchronous.

>>> await self.world.globals.async_set(
...     "global_model_params",
...     new_weights
... )