esd-services-api-client 2.5.2__py3-none-any.whl → 2.5.4__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.
- esd_services_api_client/__init__.py +1 -1
- esd_services_api_client/nexus/algorithms/forked_algorithm.py +64 -15
- {esd_services_api_client-2.5.2.dist-info → esd_services_api_client-2.5.4.dist-info}/METADATA +1 -1
- {esd_services_api_client-2.5.2.dist-info → esd_services_api_client-2.5.4.dist-info}/RECORD +6 -6
- {esd_services_api_client-2.5.2.dist-info → esd_services_api_client-2.5.4.dist-info}/LICENSE +0 -0
- {esd_services_api_client-2.5.2.dist-info → esd_services_api_client-2.5.4.dist-info}/WHEEL +0 -0
@@ -64,19 +64,61 @@ class ForkedAlgorithm(NexusObject[TPayload, AlgorithmResult]):
|
|
64
64
|
self,
|
65
65
|
metrics_provider: MetricsProvider,
|
66
66
|
logger_factory: LoggerFactory,
|
67
|
-
forks: list[RemoteAlgorithm],
|
68
67
|
*input_processors: InputProcessor,
|
69
68
|
cache: InputCache,
|
70
69
|
):
|
71
70
|
super().__init__(metrics_provider, logger_factory)
|
72
71
|
self._input_processors = input_processors
|
73
|
-
self._forks = forks
|
74
72
|
self._cache = cache
|
73
|
+
self._inputs: dict = {}
|
74
|
+
|
75
|
+
@property
|
76
|
+
def inputs(self) -> dict:
|
77
|
+
"""
|
78
|
+
Inputs generated for this algorithm run.
|
79
|
+
"""
|
80
|
+
return self._inputs
|
81
|
+
|
82
|
+
@abstractmethod
|
83
|
+
async def _get_forks(self, **kwargs) -> list[RemoteAlgorithm]:
|
84
|
+
"""
|
85
|
+
Resolve forks to be used in this run, if any
|
86
|
+
"""
|
87
|
+
|
88
|
+
@abstractmethod
|
89
|
+
async def _main_run(self, **kwargs) -> AlgorithmResult:
|
90
|
+
"""
|
91
|
+
Logic to use for the main run - if this node is the root node - **this result** will be returned to the client.
|
92
|
+
"""
|
93
|
+
|
94
|
+
@abstractmethod
|
95
|
+
async def _fork_run(self, **kwargs) -> AlgorithmResult:
|
96
|
+
"""
|
97
|
+
Logic to use for the fork - if this node is **NOT** the root node - **result will be ignored by the client**.
|
98
|
+
"""
|
99
|
+
|
100
|
+
@abstractmethod
|
101
|
+
async def _is_forked(self, **kwargs) -> bool:
|
102
|
+
"""
|
103
|
+
Determine if this is the main run or a fork run.
|
104
|
+
"""
|
105
|
+
|
106
|
+
async def _default_inputs(self, **kwargs) -> dict:
|
107
|
+
"""
|
108
|
+
Generate inputs by invoking all processors.
|
109
|
+
"""
|
110
|
+
return await self._cache.resolve(*self._input_processors, **kwargs)
|
75
111
|
|
76
112
|
@abstractmethod
|
77
|
-
async def
|
113
|
+
async def _main_inputs(self, **kwargs) -> dict:
|
78
114
|
"""
|
79
|
-
|
115
|
+
Sets inputs for the main run - if this node is the root node
|
116
|
+
"""
|
117
|
+
|
118
|
+
@abstractmethod
|
119
|
+
async def _fork_inputs(self, **kwargs) -> dict:
|
120
|
+
"""
|
121
|
+
Sets inputs for the forked run - if this node is **NOT** the root node
|
80
122
|
"""
|
81
123
|
|
82
124
|
@property
|
@@ -96,29 +138,36 @@ class ForkedAlgorithm(NexusObject[TPayload, AlgorithmResult]):
|
|
96
138
|
},
|
97
139
|
)
|
98
140
|
async def _measured_run(**run_args) -> AlgorithmResult:
|
99
|
-
|
141
|
+
if await self._is_forked(**run_args):
|
142
|
+
return await self._fork_run(**run_args)
|
100
143
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
)
|
144
|
+
return await self._main_run(**run_args)
|
145
|
+
|
146
|
+
if self._is_forked(**kwargs):
|
147
|
+
self._inputs = await self._fork_inputs(**kwargs)
|
106
148
|
else:
|
149
|
+
self._inputs = await self._main_inputs(**kwargs)
|
150
|
+
|
151
|
+
# evaluate if additional forks will be spawned
|
152
|
+
forks = await partial(self._get_forks, **self._inputs, **kwargs)()
|
153
|
+
|
154
|
+
if len(forks) > 0:
|
107
155
|
self._logger.info(
|
108
|
-
"
|
156
|
+
"Forking node with: {forks}, after the node run",
|
157
|
+
forks=",".join([fork.alias() for fork in forks]),
|
109
158
|
)
|
110
|
-
|
111
|
-
|
159
|
+
else:
|
160
|
+
self._logger.info("Leaf algorithm node: proceeding with this node run only")
|
112
161
|
|
113
162
|
run_result = await partial(
|
114
163
|
_measured_run,
|
115
|
-
**
|
164
|
+
**self._inputs,
|
116
165
|
metric_tags=self._metric_tags,
|
117
166
|
metrics_provider=self._metrics_provider,
|
118
167
|
logger=self._logger,
|
119
168
|
)()
|
120
169
|
|
121
170
|
# now await callback scheduling
|
122
|
-
await asyncio.wait([fork.run(**kwargs) for fork in
|
171
|
+
await asyncio.wait([fork.run(**kwargs) for fork in forks])
|
123
172
|
|
124
173
|
return run_result
|
@@ -1,4 +1,4 @@
|
|
1
|
-
esd_services_api_client/__init__.py,sha256=
|
1
|
+
esd_services_api_client/__init__.py,sha256=OqC4BvvpuCqq2sdLwMTrnBpukF1nqdDDjPoTEYsYxOc,648
|
2
2
|
esd_services_api_client/beast/__init__.py,sha256=zNhXcHSP5w4P9quM1XP4oXVJEccvC_VScG41TZ0GzZ8,723
|
3
3
|
esd_services_api_client/beast/v3/__init__.py,sha256=FtumtInoDyCCRE424Llqv8QZLRuwXzj-smyfu1od1nc,754
|
4
4
|
esd_services_api_client/beast/v3/_connector.py,sha256=VqxiCzJWKERh42aZAIphzmOEG5cdOcKM0DQzG7eQ_-8,11479
|
@@ -26,7 +26,7 @@ esd_services_api_client/nexus/algorithms/__init__.py,sha256=yMvLFSqg5eUKOXI0zMFX
|
|
26
26
|
esd_services_api_client/nexus/algorithms/_baseline_algorithm.py,sha256=24ALLx4Bxlgi0EwZB1a0SJeEwBUWKj7CGad-CpIygU0,2925
|
27
27
|
esd_services_api_client/nexus/algorithms/_remote_algorithm.py,sha256=nQDQ2si-_-B2QdtBC8IwSM8YyNwfIhrCMto6g87BcnQ,3900
|
28
28
|
esd_services_api_client/nexus/algorithms/distributed.py,sha256=vkKSCsd480RKwrtu3uZ2iU1bh593fkgBcOBrcb9cLjA,1702
|
29
|
-
esd_services_api_client/nexus/algorithms/forked_algorithm.py,sha256=
|
29
|
+
esd_services_api_client/nexus/algorithms/forked_algorithm.py,sha256=IXgdt-d2qdAuRXCHtqNVHXVvvRbr8VaxoQWwlyIbzAw,5786
|
30
30
|
esd_services_api_client/nexus/algorithms/minimalistic.py,sha256=tSYXodIW-_Aje-_ZyYUoWAThcZIeE4_kMvMINsT4Lb8,1644
|
31
31
|
esd_services_api_client/nexus/algorithms/recursive.py,sha256=uaCCl4q-st_KqbcmkdOJedJ0nAjbJvn6jdZEdW0_0ss,2007
|
32
32
|
esd_services_api_client/nexus/configurations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -47,7 +47,7 @@ esd_services_api_client/nexus/input/payload_reader.py,sha256=Kq0xN1Shyqv71v6Ykcr
|
|
47
47
|
esd_services_api_client/nexus/telemetry/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
48
48
|
esd_services_api_client/nexus/telemetry/recorder.py,sha256=j4x-wOSNZHkFco-ENlKtSm22d4WGHmuzKMnzvGQAtlQ,4849
|
49
49
|
esd_services_api_client/nexus/telemetry/user_telemetry_recorder.py,sha256=NOcb2l1SkMHinBXSrfbiBZSpufzhBWkuh3Px3NXrkcg,4997
|
50
|
-
esd_services_api_client-2.5.
|
51
|
-
esd_services_api_client-2.5.
|
52
|
-
esd_services_api_client-2.5.
|
53
|
-
esd_services_api_client-2.5.
|
50
|
+
esd_services_api_client-2.5.4.dist-info/LICENSE,sha256=0gS6zXsPp8qZhzi1xaGCIYPzb_0e8on7HCeFJe8fOpw,10693
|
51
|
+
esd_services_api_client-2.5.4.dist-info/METADATA,sha256=yz8gR67mWFjiWQG05AvG-FZfqtKSZhp40I0bvvdKgLc,1232
|
52
|
+
esd_services_api_client-2.5.4.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
53
|
+
esd_services_api_client-2.5.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|