runnable 0.1.0__py3-none-any.whl → 0.3.0__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.
- runnable/__init__.py +34 -0
- runnable/catalog.py +141 -0
- runnable/cli.py +272 -0
- runnable/context.py +34 -0
- runnable/datastore.py +687 -0
- runnable/defaults.py +182 -0
- runnable/entrypoints.py +448 -0
- runnable/exceptions.py +94 -0
- runnable/executor.py +421 -0
- runnable/experiment_tracker.py +139 -0
- runnable/extensions/catalog/__init__.py +21 -0
- runnable/extensions/catalog/file_system/__init__.py +0 -0
- runnable/extensions/catalog/file_system/implementation.py +227 -0
- runnable/extensions/catalog/k8s_pvc/__init__.py +0 -0
- runnable/extensions/catalog/k8s_pvc/implementation.py +16 -0
- runnable/extensions/catalog/k8s_pvc/integration.py +59 -0
- runnable/extensions/executor/__init__.py +725 -0
- runnable/extensions/executor/argo/__init__.py +0 -0
- runnable/extensions/executor/argo/implementation.py +1183 -0
- runnable/extensions/executor/argo/specification.yaml +51 -0
- runnable/extensions/executor/k8s_job/__init__.py +0 -0
- runnable/extensions/executor/k8s_job/implementation_FF.py +259 -0
- runnable/extensions/executor/k8s_job/integration_FF.py +69 -0
- runnable/extensions/executor/local/__init__.py +0 -0
- runnable/extensions/executor/local/implementation.py +70 -0
- runnable/extensions/executor/local_container/__init__.py +0 -0
- runnable/extensions/executor/local_container/implementation.py +361 -0
- runnable/extensions/executor/mocked/__init__.py +0 -0
- runnable/extensions/executor/mocked/implementation.py +189 -0
- runnable/extensions/experiment_tracker/__init__.py +0 -0
- runnable/extensions/experiment_tracker/mlflow/__init__.py +0 -0
- runnable/extensions/experiment_tracker/mlflow/implementation.py +94 -0
- runnable/extensions/nodes.py +655 -0
- runnable/extensions/run_log_store/__init__.py +0 -0
- runnable/extensions/run_log_store/chunked_file_system/__init__.py +0 -0
- runnable/extensions/run_log_store/chunked_file_system/implementation.py +106 -0
- runnable/extensions/run_log_store/chunked_k8s_pvc/__init__.py +0 -0
- runnable/extensions/run_log_store/chunked_k8s_pvc/implementation.py +21 -0
- runnable/extensions/run_log_store/chunked_k8s_pvc/integration.py +61 -0
- runnable/extensions/run_log_store/db/implementation_FF.py +157 -0
- runnable/extensions/run_log_store/db/integration_FF.py +0 -0
- runnable/extensions/run_log_store/file_system/__init__.py +0 -0
- runnable/extensions/run_log_store/file_system/implementation.py +136 -0
- runnable/extensions/run_log_store/generic_chunked.py +541 -0
- runnable/extensions/run_log_store/k8s_pvc/__init__.py +0 -0
- runnable/extensions/run_log_store/k8s_pvc/implementation.py +21 -0
- runnable/extensions/run_log_store/k8s_pvc/integration.py +56 -0
- runnable/extensions/secrets/__init__.py +0 -0
- runnable/extensions/secrets/dotenv/__init__.py +0 -0
- runnable/extensions/secrets/dotenv/implementation.py +100 -0
- runnable/extensions/secrets/env_secrets/__init__.py +0 -0
- runnable/extensions/secrets/env_secrets/implementation.py +42 -0
- runnable/graph.py +464 -0
- runnable/integration.py +205 -0
- runnable/interaction.py +404 -0
- runnable/names.py +546 -0
- runnable/nodes.py +501 -0
- runnable/parameters.py +183 -0
- runnable/pickler.py +102 -0
- runnable/sdk.py +472 -0
- runnable/secrets.py +95 -0
- runnable/tasks.py +395 -0
- runnable/utils.py +630 -0
- runnable-0.3.0.dist-info/METADATA +437 -0
- runnable-0.3.0.dist-info/RECORD +69 -0
- {runnable-0.1.0.dist-info → runnable-0.3.0.dist-info}/WHEEL +1 -1
- runnable-0.3.0.dist-info/entry_points.txt +44 -0
- runnable-0.1.0.dist-info/METADATA +0 -16
- runnable-0.1.0.dist-info/RECORD +0 -6
- /runnable/{.gitkeep → extensions/__init__.py} +0 -0
- {runnable-0.1.0.dist-info → runnable-0.3.0.dist-info}/LICENSE +0 -0
runnable/exceptions.py
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
class RunLogExistsError(Exception): # pragma: no cover
|
2
|
+
"""
|
3
|
+
Exception class
|
4
|
+
Args:
|
5
|
+
Exception ([type]): [description]
|
6
|
+
"""
|
7
|
+
|
8
|
+
def __init__(self, run_id):
|
9
|
+
super().__init__()
|
10
|
+
self.message = f"Run id for {run_id} is already found in the datastore"
|
11
|
+
|
12
|
+
|
13
|
+
class RunLogNotFoundError(Exception): # pragma: no cover
|
14
|
+
"""
|
15
|
+
Exception class
|
16
|
+
Args:
|
17
|
+
Exception ([type]): [description]
|
18
|
+
"""
|
19
|
+
|
20
|
+
def __init__(self, run_id):
|
21
|
+
super().__init__()
|
22
|
+
self.message = f"Run id for {run_id} is not found in the datastore"
|
23
|
+
|
24
|
+
|
25
|
+
class StepLogNotFoundError(Exception): # pragma: no cover
|
26
|
+
"""
|
27
|
+
Exception class
|
28
|
+
Args:
|
29
|
+
Exception ([type]): [description]
|
30
|
+
"""
|
31
|
+
|
32
|
+
def __init__(self, run_id, name):
|
33
|
+
super().__init__()
|
34
|
+
self.message = f"Step log for {name} is not found in the datastore for Run id: {run_id}"
|
35
|
+
|
36
|
+
|
37
|
+
class BranchLogNotFoundError(Exception): # pragma: no cover
|
38
|
+
"""
|
39
|
+
Exception class
|
40
|
+
Args:
|
41
|
+
Exception ([type]): [description]
|
42
|
+
"""
|
43
|
+
|
44
|
+
def __init__(self, run_id, name):
|
45
|
+
super().__init__()
|
46
|
+
self.message = f"Branch log for {name} is not found in the datastore for Run id: {run_id}"
|
47
|
+
|
48
|
+
|
49
|
+
class NodeNotFoundError(Exception): # pragma: no cover
|
50
|
+
"""
|
51
|
+
Exception class
|
52
|
+
Args:
|
53
|
+
Exception ([type]): [description]
|
54
|
+
"""
|
55
|
+
|
56
|
+
def __init__(self, name):
|
57
|
+
super().__init__()
|
58
|
+
self.message = f"Node of name {name} is not found the graph"
|
59
|
+
|
60
|
+
|
61
|
+
class BranchNotFoundError(Exception): # pragma: no cover
|
62
|
+
"""
|
63
|
+
Exception class
|
64
|
+
Args:
|
65
|
+
Exception ([type]): [description]
|
66
|
+
"""
|
67
|
+
|
68
|
+
def __init__(self, name):
|
69
|
+
super().__init__()
|
70
|
+
self.message = f"Branch of name {name} is not found the graph"
|
71
|
+
|
72
|
+
|
73
|
+
class TerminalNodeError(Exception): # pragma: no cover
|
74
|
+
def __init__(self):
|
75
|
+
super().__init__()
|
76
|
+
self.message = "Terminal Nodes do not have next node"
|
77
|
+
|
78
|
+
|
79
|
+
class SecretNotFoundError(Exception): # pragma: no cover
|
80
|
+
"""
|
81
|
+
Exception class
|
82
|
+
Args:
|
83
|
+
Exception ([type]): [description]
|
84
|
+
"""
|
85
|
+
|
86
|
+
def __init__(self, secret_name, secret_setting):
|
87
|
+
super().__init__()
|
88
|
+
self.message = f"No secret found by name:{secret_name} in {secret_setting}"
|
89
|
+
|
90
|
+
|
91
|
+
class ExecutionFailedError(Exception): # pragma: no cover
|
92
|
+
def __init__(self, run_id: str):
|
93
|
+
super().__init__()
|
94
|
+
self.message = f"Execution failed for run id: {run_id}"
|
runnable/executor.py
ADDED
@@ -0,0 +1,421 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
import logging
|
4
|
+
import os
|
5
|
+
from abc import ABC, abstractmethod
|
6
|
+
from typing import TYPE_CHECKING, Any, Dict, List, Optional
|
7
|
+
|
8
|
+
from pydantic import BaseModel, ConfigDict
|
9
|
+
|
10
|
+
import runnable.context as context
|
11
|
+
from runnable import defaults
|
12
|
+
from runnable.datastore import DataCatalog, RunLog, StepLog
|
13
|
+
from runnable.defaults import TypeMapVariable
|
14
|
+
from runnable.graph import Graph
|
15
|
+
|
16
|
+
if TYPE_CHECKING: # pragma: no cover
|
17
|
+
from runnable.extensions.nodes import TaskNode
|
18
|
+
from runnable.nodes import BaseNode
|
19
|
+
|
20
|
+
logger = logging.getLogger(defaults.LOGGER_NAME)
|
21
|
+
|
22
|
+
|
23
|
+
class BaseExecutor(ABC, BaseModel):
|
24
|
+
"""
|
25
|
+
The skeleton of an executor class.
|
26
|
+
Any implementation of an executor should inherit this class and over-ride accordingly.
|
27
|
+
|
28
|
+
There is a extension available in runnable/extensions/executor/__init__.py
|
29
|
+
which implements the most common functionality which is easier to
|
30
|
+
extend/override in most scenarios.
|
31
|
+
|
32
|
+
"""
|
33
|
+
|
34
|
+
service_name: str = ""
|
35
|
+
service_type: str = "executor"
|
36
|
+
|
37
|
+
overrides: dict = {}
|
38
|
+
|
39
|
+
# TODO: This needs to go away
|
40
|
+
_previous_run_log: Optional[RunLog] = None
|
41
|
+
_single_step: str = ""
|
42
|
+
_local: bool = False # This is a flag to indicate whether the executor is local or not.
|
43
|
+
|
44
|
+
_context_step_log = None # type : StepLog
|
45
|
+
_context_node = None # type: BaseNode
|
46
|
+
model_config = ConfigDict(extra="forbid")
|
47
|
+
|
48
|
+
@property
|
49
|
+
def _context(self):
|
50
|
+
return context.run_context
|
51
|
+
|
52
|
+
@abstractmethod
|
53
|
+
def _get_parameters(self) -> Dict[str, Any]:
|
54
|
+
"""
|
55
|
+
Get the parameters for the execution.
|
56
|
+
The parameters can be defined in parameters file and can be overridden by environment variables.
|
57
|
+
|
58
|
+
Returns:
|
59
|
+
Dict[str, Any]: The parameters for the execution.
|
60
|
+
"""
|
61
|
+
...
|
62
|
+
|
63
|
+
# TODO: This needs to go away
|
64
|
+
@abstractmethod
|
65
|
+
def _set_up_for_re_run(self, parameters: Dict[str, Any]) -> None:
|
66
|
+
"""
|
67
|
+
Set up the executor for using a previous execution.
|
68
|
+
|
69
|
+
Retrieve the older run log, error out if it does not exist.
|
70
|
+
Sync the catalogs from the previous run log with the current one.
|
71
|
+
|
72
|
+
Update the parameters of this execution with the previous one. The previous one take precedence.
|
73
|
+
|
74
|
+
Args:
|
75
|
+
parameters (Dict[str, Any]): The parameters for the current execution.
|
76
|
+
"""
|
77
|
+
|
78
|
+
@abstractmethod
|
79
|
+
def _set_up_run_log(self, exists_ok=False):
|
80
|
+
"""
|
81
|
+
Create a run log and put that in the run log store
|
82
|
+
|
83
|
+
If exists_ok, we allow the run log to be already present in the run log store.
|
84
|
+
"""
|
85
|
+
...
|
86
|
+
|
87
|
+
@abstractmethod
|
88
|
+
def prepare_for_graph_execution(self):
|
89
|
+
"""
|
90
|
+
This method should be called prior to calling execute_graph.
|
91
|
+
Perform any steps required before doing the graph execution.
|
92
|
+
|
93
|
+
The most common implementation is to prepare a run log for the run if the run uses local interactive compute.
|
94
|
+
|
95
|
+
But in cases of actual rendering the job specs (eg: AWS step functions, K8's) we check if the services are OK.
|
96
|
+
We do not set up a run log as its not relevant.
|
97
|
+
"""
|
98
|
+
...
|
99
|
+
|
100
|
+
@abstractmethod
|
101
|
+
def prepare_for_node_execution(self):
|
102
|
+
"""
|
103
|
+
Perform any modifications to the services prior to execution of the node.
|
104
|
+
|
105
|
+
Args:
|
106
|
+
node (Node): [description]
|
107
|
+
map_variable (dict, optional): [description]. Defaults to None.
|
108
|
+
"""
|
109
|
+
...
|
110
|
+
|
111
|
+
@abstractmethod
|
112
|
+
def _sync_catalog(self, step_log: StepLog, stage: str, synced_catalogs=None) -> Optional[List[DataCatalog]]:
|
113
|
+
"""
|
114
|
+
1). Identify the catalog settings by over-riding node settings with the global settings.
|
115
|
+
2). For stage = get:
|
116
|
+
Identify the catalog items that are being asked to get from the catalog
|
117
|
+
And copy them to the local compute data folder
|
118
|
+
3). For stage = put:
|
119
|
+
Identify the catalog items that are being asked to put into the catalog
|
120
|
+
Copy the items from local compute folder to the catalog
|
121
|
+
4). Add the items onto the step log according to the stage
|
122
|
+
|
123
|
+
Args:
|
124
|
+
node (Node): The current node being processed
|
125
|
+
step_log (StepLog): The step log corresponding to that node
|
126
|
+
stage (str): One of get or put
|
127
|
+
|
128
|
+
Raises:
|
129
|
+
Exception: If the stage is not in one of get/put
|
130
|
+
|
131
|
+
"""
|
132
|
+
...
|
133
|
+
|
134
|
+
@abstractmethod
|
135
|
+
def get_effective_compute_data_folder(self) -> Optional[str]:
|
136
|
+
"""
|
137
|
+
Get the effective compute data folder for the given stage.
|
138
|
+
If there is nothing to catalog, we return None.
|
139
|
+
|
140
|
+
The default is the compute data folder of the catalog but this can be over-ridden by the node.
|
141
|
+
|
142
|
+
Args:
|
143
|
+
stage (str): The stage we are in the process of cataloging
|
144
|
+
|
145
|
+
|
146
|
+
Returns:
|
147
|
+
Optional[str]: The compute data folder as defined by catalog handler or the node or None.
|
148
|
+
"""
|
149
|
+
...
|
150
|
+
|
151
|
+
@property
|
152
|
+
def step_attempt_number(self) -> int:
|
153
|
+
"""
|
154
|
+
The attempt number of the current step.
|
155
|
+
Orchestrators should use this step to submit multiple attempts of the job.
|
156
|
+
|
157
|
+
Returns:
|
158
|
+
int: The attempt number of the current step. Defaults to 1.
|
159
|
+
"""
|
160
|
+
return int(os.environ.get(defaults.ATTEMPT_NUMBER, 1))
|
161
|
+
|
162
|
+
@abstractmethod
|
163
|
+
def _execute_node(self, node: BaseNode, map_variable: TypeMapVariable = None, **kwargs):
|
164
|
+
"""
|
165
|
+
This is the entry point when we do the actual execution of the function.
|
166
|
+
|
167
|
+
While in interactive execution, we just compute, in 3rd party interactive execution, we need to reach
|
168
|
+
this function.
|
169
|
+
|
170
|
+
In most cases,
|
171
|
+
* We get the corresponding step_log of the node and the parameters.
|
172
|
+
* We sync the catalog to GET any data sets that are in the catalog
|
173
|
+
* We call the execute method of the node for the actual compute and retry it as many times as asked.
|
174
|
+
* If the node succeeds, we get any of the user defined metrics provided by the user.
|
175
|
+
* We sync the catalog to PUT any data sets that are in the catalog.
|
176
|
+
|
177
|
+
Args:
|
178
|
+
node (Node): The node to execute
|
179
|
+
map_variable (dict, optional): If the node is of a map state, map_variable is the value of the iterable.
|
180
|
+
Defaults to None.
|
181
|
+
"""
|
182
|
+
...
|
183
|
+
|
184
|
+
@abstractmethod
|
185
|
+
def execute_node(self, node: BaseNode, map_variable: TypeMapVariable = None, **kwargs):
|
186
|
+
"""
|
187
|
+
The entry point for all executors apart from local.
|
188
|
+
We have already prepared for node execution.
|
189
|
+
|
190
|
+
Args:
|
191
|
+
node (BaseNode): The node to execute
|
192
|
+
map_variable (dict, optional): If the node is part of a map, send in the map dictionary. Defaults to None.
|
193
|
+
|
194
|
+
Raises:
|
195
|
+
NotImplementedError: _description_
|
196
|
+
"""
|
197
|
+
...
|
198
|
+
|
199
|
+
@abstractmethod
|
200
|
+
def add_code_identities(self, node: BaseNode, step_log: StepLog, **kwargs):
|
201
|
+
"""
|
202
|
+
Add code identities specific to the implementation.
|
203
|
+
|
204
|
+
The Base class has an implementation of adding git code identities.
|
205
|
+
|
206
|
+
Args:
|
207
|
+
step_log (object): The step log object
|
208
|
+
node (BaseNode): The node we are adding the step log for
|
209
|
+
"""
|
210
|
+
...
|
211
|
+
|
212
|
+
@abstractmethod
|
213
|
+
def execute_from_graph(self, node: BaseNode, map_variable: TypeMapVariable = None, **kwargs):
|
214
|
+
"""
|
215
|
+
This is the entry point to from the graph execution.
|
216
|
+
|
217
|
+
While the self.execute_graph is responsible for traversing the graph, this function is responsible for
|
218
|
+
actual execution of the node.
|
219
|
+
|
220
|
+
If the node type is:
|
221
|
+
* task : We can delegate to _execute_node after checking the eligibility for re-run in cases of a re-run
|
222
|
+
* success: We can delegate to _execute_node
|
223
|
+
* fail: We can delegate to _execute_node
|
224
|
+
|
225
|
+
For nodes that are internally graphs:
|
226
|
+
* parallel: Delegate the responsibility of execution to the node.execute_as_graph()
|
227
|
+
* dag: Delegate the responsibility of execution to the node.execute_as_graph()
|
228
|
+
* map: Delegate the responsibility of execution to the node.execute_as_graph()
|
229
|
+
|
230
|
+
Transpilers will NEVER use this method and will NEVER call ths method.
|
231
|
+
This method should only be used by interactive executors.
|
232
|
+
|
233
|
+
Args:
|
234
|
+
node (Node): The node to execute
|
235
|
+
map_variable (dict, optional): If the node if of a map state, this corresponds to the value of iterable.
|
236
|
+
Defaults to None.
|
237
|
+
"""
|
238
|
+
...
|
239
|
+
|
240
|
+
@abstractmethod
|
241
|
+
def trigger_job(self, node: BaseNode, map_variable: TypeMapVariable = None, **kwargs):
|
242
|
+
"""
|
243
|
+
Executor specific way of triggering jobs when runnable does both traversal and execution
|
244
|
+
|
245
|
+
Transpilers will NEVER use this method and will NEVER call them.
|
246
|
+
Only interactive executors who need execute_from_graph will ever implement it.
|
247
|
+
|
248
|
+
Args:
|
249
|
+
node (BaseNode): The node to execute
|
250
|
+
map_variable (str, optional): If the node if of a map state, this corresponds to the value of iterable.
|
251
|
+
Defaults to ''.
|
252
|
+
|
253
|
+
NOTE: We do not raise an exception as this method is not required by many extensions
|
254
|
+
"""
|
255
|
+
...
|
256
|
+
|
257
|
+
@abstractmethod
|
258
|
+
def _get_status_and_next_node_name(self, current_node: BaseNode, dag: Graph, map_variable: TypeMapVariable = None):
|
259
|
+
"""
|
260
|
+
Given the current node and the graph, returns the name of the next node to execute.
|
261
|
+
|
262
|
+
The name is always relative the graph that the node resides in.
|
263
|
+
|
264
|
+
If the current node succeeded, we return the next node as per the graph.
|
265
|
+
If the current node failed, we return the on failure node of the node (if provided) or the global one.
|
266
|
+
|
267
|
+
Args:
|
268
|
+
current_node (BaseNode): The current node.
|
269
|
+
dag (Graph): The dag we are traversing.
|
270
|
+
map_variable (dict): If the node belongs to a map branch.
|
271
|
+
"""
|
272
|
+
|
273
|
+
...
|
274
|
+
|
275
|
+
@abstractmethod
|
276
|
+
def execute_graph(self, dag: Graph, map_variable: TypeMapVariable = None, **kwargs):
|
277
|
+
"""
|
278
|
+
The parallelization is controlled by the nodes and not by this function.
|
279
|
+
|
280
|
+
Transpilers should over ride this method to do the translation of dag to the platform specific way.
|
281
|
+
Interactive methods should use this to traverse and execute the dag.
|
282
|
+
- Use execute_from_graph to handle sub-graphs
|
283
|
+
|
284
|
+
Logically the method should:
|
285
|
+
* Start at the dag.start_at of the dag.
|
286
|
+
* Call the self.execute_from_graph(node)
|
287
|
+
* depending upon the status of the execution, either move to the success node or failure node.
|
288
|
+
|
289
|
+
Args:
|
290
|
+
dag (Graph): The directed acyclic graph to traverse and execute.
|
291
|
+
map_variable (dict, optional): If the node if of a map state, this corresponds to the value of the iterable.
|
292
|
+
Defaults to None.
|
293
|
+
"""
|
294
|
+
...
|
295
|
+
|
296
|
+
# TODO: This needs to go away
|
297
|
+
@abstractmethod
|
298
|
+
def _is_step_eligible_for_rerun(self, node: BaseNode, map_variable: TypeMapVariable = None):
|
299
|
+
"""
|
300
|
+
In case of a re-run, this method checks to see if the previous run step status to determine if a re-run is
|
301
|
+
necessary.
|
302
|
+
* True: If its not a re-run.
|
303
|
+
* True: If its a re-run and we failed in the last run or the corresponding logs do not exist.
|
304
|
+
* False: If its a re-run and we succeeded in the last run.
|
305
|
+
|
306
|
+
Most cases, this logic need not be touched
|
307
|
+
|
308
|
+
Args:
|
309
|
+
node (Node): The node to check against re-run
|
310
|
+
map_variable (dict, optional): If the node if of a map state, this corresponds to the value of iterable..
|
311
|
+
Defaults to None.
|
312
|
+
|
313
|
+
Returns:
|
314
|
+
bool: Eligibility for re-run. True means re-run, False means skip to the next step.
|
315
|
+
"""
|
316
|
+
...
|
317
|
+
|
318
|
+
@abstractmethod
|
319
|
+
def send_return_code(self, stage="traversal"):
|
320
|
+
"""
|
321
|
+
Convenience function used by pipeline to send return code to the caller of the cli
|
322
|
+
|
323
|
+
Raises:
|
324
|
+
Exception: If the pipeline execution failed
|
325
|
+
"""
|
326
|
+
...
|
327
|
+
|
328
|
+
@abstractmethod
|
329
|
+
def _resolve_executor_config(self, node: BaseNode):
|
330
|
+
"""
|
331
|
+
The overrides section can contain specific over-rides to an global executor config.
|
332
|
+
To avoid too much clutter in the dag definition, we allow the configuration file to have overrides block.
|
333
|
+
The nodes can over-ride the global config by referring to key in the overrides.
|
334
|
+
|
335
|
+
For example:
|
336
|
+
# configuration.yaml
|
337
|
+
execution:
|
338
|
+
type: cloud-implementation
|
339
|
+
config:
|
340
|
+
k1: v1
|
341
|
+
k3: v3
|
342
|
+
overrides:
|
343
|
+
k2: v2 # Could be a mapping internally.
|
344
|
+
|
345
|
+
# in pipeline definition.yaml
|
346
|
+
dag:
|
347
|
+
steps:
|
348
|
+
step1:
|
349
|
+
overrides:
|
350
|
+
cloud-implementation:
|
351
|
+
k1: value_specific_to_node
|
352
|
+
k2:
|
353
|
+
|
354
|
+
This method should resolve the node_config to {'k1': 'value_specific_to_node', 'k2': 'v2', 'k3': 'v3'}
|
355
|
+
|
356
|
+
Args:
|
357
|
+
node (BaseNode): The current node being processed.
|
358
|
+
|
359
|
+
"""
|
360
|
+
...
|
361
|
+
|
362
|
+
@abstractmethod
|
363
|
+
def execute_job(self, node: TaskNode):
|
364
|
+
"""
|
365
|
+
Executor specific way of executing a job (python function or a notebook).
|
366
|
+
|
367
|
+
Interactive executors should execute the job.
|
368
|
+
Transpilers should write the instructions.
|
369
|
+
|
370
|
+
Args:
|
371
|
+
node (BaseNode): The job node to execute
|
372
|
+
|
373
|
+
Raises:
|
374
|
+
NotImplementedError: Executors should choose to extend this functionality or not.
|
375
|
+
"""
|
376
|
+
...
|
377
|
+
|
378
|
+
@abstractmethod
|
379
|
+
def fan_out(self, node: BaseNode, map_variable: TypeMapVariable = None):
|
380
|
+
"""
|
381
|
+
This method is used to appropriately fan-out the execution of a composite node.
|
382
|
+
This is only useful when we want to execute a composite node during 3rd party orchestrators.
|
383
|
+
|
384
|
+
Reason: Transpilers typically try to run the leaf nodes but do not have any capacity to do anything for the
|
385
|
+
step which is composite. By calling this fan-out before calling the leaf nodes, we have an opportunity to
|
386
|
+
do the right set up (creating the step log, exposing the parameters, etc.) for the composite step.
|
387
|
+
|
388
|
+
All 3rd party orchestrators should use this method to fan-out the execution of a composite node.
|
389
|
+
This ensures:
|
390
|
+
- The dot path notation is preserved, this method should create the step and call the node's fan out to
|
391
|
+
create the branch logs and let the 3rd party do the actual step execution.
|
392
|
+
- Gives 3rd party orchestrators an opportunity to set out the required for running a composite node.
|
393
|
+
|
394
|
+
Args:
|
395
|
+
node (BaseNode): The node to fan-out
|
396
|
+
map_variable (dict, optional): If the node if of a map state,.Defaults to None.
|
397
|
+
|
398
|
+
"""
|
399
|
+
...
|
400
|
+
|
401
|
+
@abstractmethod
|
402
|
+
def fan_in(self, node: BaseNode, map_variable: TypeMapVariable = None):
|
403
|
+
"""
|
404
|
+
This method is used to appropriately fan-in after the execution of a composite node.
|
405
|
+
This is only useful when we want to execute a composite node during 3rd party orchestrators.
|
406
|
+
|
407
|
+
Reason: Transpilers typically try to run the leaf nodes but do not have any capacity to do anything for the
|
408
|
+
step which is composite. By calling this fan-in after calling the leaf nodes, we have an opportunity to
|
409
|
+
act depending upon the status of the individual branches.
|
410
|
+
|
411
|
+
All 3rd party orchestrators should use this method to fan-in the execution of a composite node.
|
412
|
+
This ensures:
|
413
|
+
- Gives the renderer's the control on where to go depending upon the state of the composite node.
|
414
|
+
- The status of the step and its underlying branches are correctly updated.
|
415
|
+
|
416
|
+
Args:
|
417
|
+
node (BaseNode): The node to fan-in
|
418
|
+
map_variable (dict, optional): If the node if of a map state,.Defaults to None.
|
419
|
+
|
420
|
+
"""
|
421
|
+
...
|
@@ -0,0 +1,139 @@
|
|
1
|
+
import contextlib
|
2
|
+
import json
|
3
|
+
import logging
|
4
|
+
import os
|
5
|
+
from abc import ABC, abstractmethod
|
6
|
+
from collections import defaultdict
|
7
|
+
from typing import Any, ContextManager, Dict, Tuple, Union
|
8
|
+
|
9
|
+
from pydantic import BaseModel, ConfigDict
|
10
|
+
|
11
|
+
import runnable.context as context
|
12
|
+
from runnable import defaults
|
13
|
+
from runnable.utils import remove_prefix
|
14
|
+
|
15
|
+
logger = logging.getLogger(defaults.LOGGER_NAME)
|
16
|
+
|
17
|
+
|
18
|
+
def retrieve_step_details(key: str) -> Tuple[str, int]:
|
19
|
+
key = remove_prefix(key, defaults.TRACK_PREFIX)
|
20
|
+
data = key.split(defaults.STEP_INDICATOR)
|
21
|
+
|
22
|
+
key = data[0].lower()
|
23
|
+
step = 0
|
24
|
+
|
25
|
+
if len(data) > 1:
|
26
|
+
step = int(data[1])
|
27
|
+
|
28
|
+
return key, step
|
29
|
+
|
30
|
+
|
31
|
+
def get_tracked_data() -> Dict[str, Any]:
|
32
|
+
tracked_data: Dict[str, Any] = defaultdict(dict)
|
33
|
+
for env_var, value in os.environ.items():
|
34
|
+
if env_var.startswith(defaults.TRACK_PREFIX):
|
35
|
+
key, step = retrieve_step_details(env_var)
|
36
|
+
|
37
|
+
# print(value, type(value))
|
38
|
+
try:
|
39
|
+
value = json.loads(value)
|
40
|
+
except json.decoder.JSONDecodeError:
|
41
|
+
logger.warning(f"Tracker {key} could not be JSON decoded, adding the literal value")
|
42
|
+
|
43
|
+
tracked_data[key][step] = value
|
44
|
+
del os.environ[env_var]
|
45
|
+
|
46
|
+
for key, value in tracked_data.items():
|
47
|
+
if len(value) == 1:
|
48
|
+
tracked_data[key] = value[0]
|
49
|
+
|
50
|
+
return tracked_data
|
51
|
+
|
52
|
+
|
53
|
+
# --8<-- [start:docs]
|
54
|
+
|
55
|
+
|
56
|
+
class BaseExperimentTracker(ABC, BaseModel):
|
57
|
+
"""
|
58
|
+
Base Experiment tracker class definition.
|
59
|
+
"""
|
60
|
+
|
61
|
+
service_name: str = ""
|
62
|
+
service_type: str = "experiment_tracker"
|
63
|
+
|
64
|
+
@property
|
65
|
+
def _context(self):
|
66
|
+
return context.run_context
|
67
|
+
|
68
|
+
model_config = ConfigDict(extra="forbid")
|
69
|
+
|
70
|
+
@property
|
71
|
+
def client_context(self) -> ContextManager:
|
72
|
+
"""
|
73
|
+
Returns the client context.
|
74
|
+
"""
|
75
|
+
return contextlib.nullcontext()
|
76
|
+
|
77
|
+
def publish_data(self, tracked_data: Dict[str, Any]):
|
78
|
+
for key, value in tracked_data.items():
|
79
|
+
if isinstance(value, dict):
|
80
|
+
for key2, value2 in value.items():
|
81
|
+
self.log_metric(key, value2, step=key2)
|
82
|
+
continue
|
83
|
+
self.log_metric(key, value)
|
84
|
+
|
85
|
+
@abstractmethod
|
86
|
+
def log_metric(self, key: str, value: Union[int, float], step: int = 0):
|
87
|
+
"""
|
88
|
+
Sets the metric in the experiment tracking.
|
89
|
+
|
90
|
+
Args:
|
91
|
+
key (str): The key against you want to store the value
|
92
|
+
value (float): The value of the metric
|
93
|
+
step (int): Optional step at which it was recorded
|
94
|
+
|
95
|
+
Raises:
|
96
|
+
NotImplementedError: Base class, hence not implemented
|
97
|
+
"""
|
98
|
+
raise NotImplementedError
|
99
|
+
|
100
|
+
@abstractmethod
|
101
|
+
def log_parameter(self, key: str, value: Any):
|
102
|
+
"""
|
103
|
+
Logs a parameter in the experiment tracking.
|
104
|
+
|
105
|
+
Args:
|
106
|
+
key (str): The key against you want to store the value
|
107
|
+
value (any): The value of the metric
|
108
|
+
|
109
|
+
Raises:
|
110
|
+
NotImplementedError: Base class, hence not implemented
|
111
|
+
"""
|
112
|
+
pass
|
113
|
+
|
114
|
+
|
115
|
+
# --8<-- [end:docs]
|
116
|
+
|
117
|
+
|
118
|
+
class DoNothingTracker(BaseExperimentTracker):
|
119
|
+
"""
|
120
|
+
A Do nothing tracker
|
121
|
+
"""
|
122
|
+
|
123
|
+
service_name: str = "do-nothing"
|
124
|
+
|
125
|
+
def log_metric(self, key: str, value: Union[int, float], step: int = 0):
|
126
|
+
"""
|
127
|
+
Sets the metric in the experiment tracking.
|
128
|
+
|
129
|
+
Args:
|
130
|
+
key (str): The key against you want to store the value
|
131
|
+
value (float): The value of the metric
|
132
|
+
"""
|
133
|
+
...
|
134
|
+
|
135
|
+
def log_parameter(self, key: str, value: Any):
|
136
|
+
"""
|
137
|
+
Since this is a Do nothing tracker, we don't need to log anything.
|
138
|
+
"""
|
139
|
+
...
|
@@ -0,0 +1,21 @@
|
|
1
|
+
from typing import List, Optional
|
2
|
+
|
3
|
+
from runnable.datastore import DataCatalog
|
4
|
+
|
5
|
+
|
6
|
+
def is_catalog_out_of_sync(catalog, synced_catalogs=Optional[List[DataCatalog]]) -> bool:
|
7
|
+
"""
|
8
|
+
Check if the catalog items are out of sync from already cataloged objects.
|
9
|
+
If they are, return False.
|
10
|
+
If the object does not exist or synced catalog does not exist, return True
|
11
|
+
"""
|
12
|
+
if not synced_catalogs:
|
13
|
+
return True # If nothing has been synced in the past
|
14
|
+
|
15
|
+
for synced_catalog in synced_catalogs:
|
16
|
+
if synced_catalog.catalog_relative_path == catalog.catalog_relative_path:
|
17
|
+
if synced_catalog.data_hash == catalog.data_hash:
|
18
|
+
return False
|
19
|
+
return True
|
20
|
+
|
21
|
+
return True # The object does not exist, sync it
|
File without changes
|