mantatech-sdk 0.5b0.dev65__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- manta/__init__.light.py +22 -0
- manta/__init__.py +83 -0
- manta/__main__.py +21 -0
- manta/apis/__init__.py +7 -0
- manta/apis/async_user_api.py +6458 -0
- manta/apis/graph.py +498 -0
- manta/apis/module.py +316 -0
- manta/apis/results.py +251 -0
- manta/apis/swarm.py +206 -0
- manta/apis/user_api.py +1016 -0
- manta/cli/__init__.py +1 -0
- manta/cli/commands/__init__.py +1 -0
- manta/cli/commands/base_handler.py +229 -0
- manta/cli/commands/doc.py +192 -0
- manta/cli/commands/install.py +346 -0
- manta/cli/commands/sdk.py +9 -0
- manta/cli/commands/sdk_cluster.py +211 -0
- manta/cli/commands/sdk_config.py +347 -0
- manta/cli/commands/sdk_globals.py +280 -0
- manta/cli/commands/sdk_logs.py +174 -0
- manta/cli/commands/sdk_main.py +167 -0
- manta/cli/commands/sdk_module.py +516 -0
- manta/cli/commands/sdk_nodes.py +168 -0
- manta/cli/commands/sdk_original.py +3873 -0
- manta/cli/commands/sdk_results.py +265 -0
- manta/cli/commands/sdk_swarm.py +454 -0
- manta/cli/commands/sdk_user.py +234 -0
- manta/cli/commands/status.py +292 -0
- manta/cli/component_detector.py +112 -0
- manta/cli/config_manager.py +445 -0
- manta/cli/main.py +265 -0
- manta/cli/utils/__init__.py +27 -0
- manta/cli/utils/converters.py +140 -0
- manta/clients/cluster_management_client.py +486 -0
- manta/clients/local_client.py +149 -0
- manta/clients/module_management_client.py +217 -0
- manta/clients/swarm_management_client.py +562 -0
- manta/clients/user_management_client.py +395 -0
- manta/clients/world_client.py +195 -0
- manta/light/__init__.py +31 -0
- manta/light/globals.py +245 -0
- manta/light/local.py +407 -0
- manta/light/logging_config.py +39 -0
- manta/light/path.py +116 -0
- manta/light/results.py +236 -0
- manta/light/task.py +100 -0
- manta/light/utils.py +217 -0
- manta/light/world.py +177 -0
- mantatech_sdk-0.5b0.dev65.dist-info/METADATA +1039 -0
- mantatech_sdk-0.5b0.dev65.dist-info/RECORD +54 -0
- mantatech_sdk-0.5b0.dev65.dist-info/WHEEL +5 -0
- mantatech_sdk-0.5b0.dev65.dist-info/entry_points.txt +2 -0
- mantatech_sdk-0.5b0.dev65.dist-info/licenses/LICENSE +683 -0
- mantatech_sdk-0.5b0.dev65.dist-info/top_level.txt +1 -0
manta/light/world.py
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import os
|
|
3
|
+
from typing import List, Optional
|
|
4
|
+
|
|
5
|
+
from ..clients.world_client import WorldClient
|
|
6
|
+
from manta_common.build.common.system import EnvId
|
|
7
|
+
from manta_common.build.common.tasks import TaskScheduling
|
|
8
|
+
from manta_common.conversions import ID
|
|
9
|
+
from manta_common.event_loop import EventLoopManager
|
|
10
|
+
from .globals import Globals
|
|
11
|
+
from .logging_config import configure_logging
|
|
12
|
+
from .results import Results
|
|
13
|
+
|
|
14
|
+
__all__ = ["World"]
|
|
15
|
+
|
|
16
|
+
configure_logging()
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class World:
|
|
20
|
+
"""
|
|
21
|
+
World service for accessing values with other nodes
|
|
22
|
+
|
|
23
|
+
The :code:`World` service allows the user to interact with collective values
|
|
24
|
+
during a :class:`Swarm <manta.swarm.Swarm>` iteration
|
|
25
|
+
|
|
26
|
+
Parameters should not be fulfill manually. Instead, it is managed during the
|
|
27
|
+
deployment of the task by the :code:`Node`.
|
|
28
|
+
|
|
29
|
+
Parameters
|
|
30
|
+
----------
|
|
31
|
+
host : Optional[str]
|
|
32
|
+
Manager host
|
|
33
|
+
port : Optional[int]
|
|
34
|
+
Manager port
|
|
35
|
+
swarm_id : Optional[ID]
|
|
36
|
+
Swarm ID
|
|
37
|
+
task_id : Optional[ID]
|
|
38
|
+
Task ID
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
__slots__ = [
|
|
42
|
+
"swarm_id",
|
|
43
|
+
"task_id",
|
|
44
|
+
"logger",
|
|
45
|
+
"results",
|
|
46
|
+
"globals",
|
|
47
|
+
"world_client",
|
|
48
|
+
"loop_manager",
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
def __init__(
|
|
52
|
+
self,
|
|
53
|
+
host: Optional[str] = None,
|
|
54
|
+
port: Optional[int] = None,
|
|
55
|
+
swarm_id: Optional[ID] = None,
|
|
56
|
+
task_id: Optional[ID] = None,
|
|
57
|
+
):
|
|
58
|
+
# Retrieve environment variables for RPC host and port
|
|
59
|
+
host = host or os.getenv("RPC_HOST", "host.docker.internal")
|
|
60
|
+
port = int(port or os.getenv("RPC_PORT", 50051))
|
|
61
|
+
self.task_id = task_id or ID(os.getenv("TASK_ID"))
|
|
62
|
+
self.swarm_id = swarm_id or ID(os.getenv("SWARM_ID"))
|
|
63
|
+
|
|
64
|
+
self.logger = logging.getLogger(__name__)
|
|
65
|
+
|
|
66
|
+
self.logger.info(
|
|
67
|
+
f"World configured with Host: {host}, Port: {port},"
|
|
68
|
+
f" Task ID: {self.task_id},"
|
|
69
|
+
f" Swarm ID: {self.swarm_id}"
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
self.world_client = WorldClient(host=host, port=port)
|
|
73
|
+
self.loop_manager = EventLoopManager.get_instance()
|
|
74
|
+
|
|
75
|
+
self.results = Results(
|
|
76
|
+
world_client=self.world_client,
|
|
77
|
+
swarm_id=self.swarm_id,
|
|
78
|
+
task_id=self.task_id,
|
|
79
|
+
)
|
|
80
|
+
self.globals = Globals(
|
|
81
|
+
world_client=self.world_client, swarm_id=self.swarm_id, task_id=self.task_id
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
def schedule_next_iter(self, node_ids: List[str], task_to_schedule_alias: str):
|
|
85
|
+
"""
|
|
86
|
+
Schedule the next iteration
|
|
87
|
+
|
|
88
|
+
Parameters
|
|
89
|
+
----------
|
|
90
|
+
node_ids : List[str]
|
|
91
|
+
The list of node ids to schedule the next iteration for
|
|
92
|
+
task_to_schedule_alias : str
|
|
93
|
+
The task to schedule for the next iteration
|
|
94
|
+
|
|
95
|
+
Examples
|
|
96
|
+
--------
|
|
97
|
+
|
|
98
|
+
From :class:`Task <manta_light.task.Task>` attribute:
|
|
99
|
+
|
|
100
|
+
>>> self.world.schedule_next_iter(
|
|
101
|
+
... node_ids=selected_nodes, task_to_schedule_alias="worker"
|
|
102
|
+
... )
|
|
103
|
+
"""
|
|
104
|
+
self.loop_manager.run_coroutine(
|
|
105
|
+
self.async_schedule_next_iter(node_ids, task_to_schedule_alias)
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
def stop_swarm(self):
|
|
109
|
+
"""
|
|
110
|
+
Stop the swarm
|
|
111
|
+
|
|
112
|
+
Examples
|
|
113
|
+
--------
|
|
114
|
+
|
|
115
|
+
From :class:`Task <manta_light.task.Task>` attribute:
|
|
116
|
+
|
|
117
|
+
>>> self.world.stop_swarm()
|
|
118
|
+
"""
|
|
119
|
+
self.loop_manager.run_coroutine(self.async_stop_swarm())
|
|
120
|
+
|
|
121
|
+
def __str__(self): # pragma: no cover
|
|
122
|
+
return f"World(host={self.world_client.host}, port={self.world_client.port}, swarm_id={self.swarm_id}, task_id={self.task_id})"
|
|
123
|
+
|
|
124
|
+
def __repr__(self): # pragma: no cover
|
|
125
|
+
return str(self)
|
|
126
|
+
|
|
127
|
+
# Asynchronous methods
|
|
128
|
+
|
|
129
|
+
async def async_schedule_next_iter(
|
|
130
|
+
self, node_ids: List[str], task_to_schedule_alias: str
|
|
131
|
+
):
|
|
132
|
+
"""
|
|
133
|
+
Schedule the next iteration
|
|
134
|
+
|
|
135
|
+
Parameters
|
|
136
|
+
----------
|
|
137
|
+
node_ids : List[str]
|
|
138
|
+
The list of node ids to schedule the next iteration for
|
|
139
|
+
task_to_schedule_alias : str
|
|
140
|
+
The task to schedule for the next iteration
|
|
141
|
+
|
|
142
|
+
Examples
|
|
143
|
+
--------
|
|
144
|
+
|
|
145
|
+
Same as :meth:`schedule_next_iter <manta_light.world.World.schedule_next_iter>`
|
|
146
|
+
but asynchronous:
|
|
147
|
+
|
|
148
|
+
>>> await self.world.async_schedule_next_iter(
|
|
149
|
+
... node_ids=selected_nodes, task_to_schedule_alias="worker"
|
|
150
|
+
... )
|
|
151
|
+
"""
|
|
152
|
+
await self.world_client.schedule_task(
|
|
153
|
+
TaskScheduling(
|
|
154
|
+
task_id=self.task_id.oid,
|
|
155
|
+
node_ids=[ID(node_id).oid for node_id in node_ids],
|
|
156
|
+
task_to_schedule_alias=task_to_schedule_alias,
|
|
157
|
+
swarm_id=self.swarm_id.oid,
|
|
158
|
+
)
|
|
159
|
+
)
|
|
160
|
+
self.logger.info("Schedule next iteration")
|
|
161
|
+
|
|
162
|
+
async def async_stop_swarm(self):
|
|
163
|
+
"""
|
|
164
|
+
Stop the swarm
|
|
165
|
+
|
|
166
|
+
Examples
|
|
167
|
+
--------
|
|
168
|
+
|
|
169
|
+
Same as :meth:`stop_swarm <manta_light.world.World.stop_swarm>`
|
|
170
|
+
but asynchronous:
|
|
171
|
+
|
|
172
|
+
>>> await self.world.async_stop_swarm()
|
|
173
|
+
"""
|
|
174
|
+
await self.world_client.stop_swarm(
|
|
175
|
+
EnvId(swarm_id=self.swarm_id.oid, task_id=self.task_id.oid)
|
|
176
|
+
)
|
|
177
|
+
self.logger.info("Stop swarm response")
|