sera-2 1.21.1__py3-none-any.whl → 1.21.2__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.
@@ -41,6 +41,11 @@ class DirectedComputingGraph:
41
41
  ):
42
42
  self.graph = graph
43
43
  self.type_service = type_service
44
+ self.node2descendants: dict[str, list[DCGNode]] = {}
45
+
46
+ for u in graph.iter_nodes():
47
+ self.node2descendants[u.id] = graph.descendants(u.id)
48
+ self.node2descendants[u.id].append(u)
44
49
 
45
50
  @staticmethod
46
51
  def from_flows(
@@ -179,7 +184,7 @@ class DirectedComputingGraph:
179
184
  def execute(
180
185
  self,
181
186
  input: dict[ComputeFnId, tuple],
182
- output: set[str],
187
+ output: Optional[set[str]] = None,
183
188
  context: Optional[
184
189
  dict[str, Callable | Any] | Callable[[], dict[str, Any]]
185
190
  ] = None,
@@ -203,6 +208,9 @@ class DirectedComputingGraph:
203
208
  else:
204
209
  context = {k: v() if callable(v) else v for k, v in context.items()}
205
210
 
211
+ if output is None:
212
+ output = set()
213
+
206
214
  # This is a quick reactive algorithm, we may be able to do it better.
207
215
  # The idea is when all inputs of a function is available, we can execute a function.
208
216
  # We assume that the memory is large enough to hold all the functions and their inputs
@@ -211,25 +219,25 @@ class DirectedComputingGraph:
211
219
  # we execute the computing nodes
212
220
  # when it's finished, we put the outgoing edges into a stack.
213
221
  runtimes: dict[NodeId, NodeRuntime] = {}
222
+ for id in input.keys():
223
+ for u in self.node2descendants[id]:
224
+ if u.id in input:
225
+ # user provided input should supersede the context
226
+ n_provided_args = len(input[u.id])
227
+ n_consumed_context = n_provided_args - len(u.required_args)
228
+ else:
229
+ n_consumed_context = 0
214
230
 
215
- for u in self.graph.iter_nodes():
216
- if u.id in input:
217
- # user provided input should supersede the context
218
- n_provided_args = len(input[u.id])
219
- n_consumed_context = n_provided_args - len(u.required_args)
220
- else:
221
- n_consumed_context = 0
222
-
223
- node_context = tuple(
224
- (
225
- context[name]
226
- if name in context
227
- else u.required_context_default_args[name]
231
+ node_context = tuple(
232
+ (
233
+ context[name]
234
+ if name in context
235
+ else u.required_context_default_args[name]
236
+ )
237
+ for name in u.required_context[n_consumed_context:]
228
238
  )
229
- for name in u.required_context[n_consumed_context:]
230
- )
231
239
 
232
- runtimes[u.id] = NodeRuntime.from_node(self.graph, u, node_context)
240
+ runtimes[u.id] = NodeRuntime.from_node(self.graph, u, node_context)
233
241
  stack: list[NodeId] = []
234
242
 
235
243
  for id, args in input.items():
@@ -321,24 +329,25 @@ class DirectedComputingGraph:
321
329
  # when it's finished, we put the outgoing edges into a stack.
322
330
  runtimes: dict[NodeId, NodeRuntime] = {}
323
331
 
324
- for u in self.graph.iter_nodes():
325
- if u.id in input:
326
- # user provided input should supersede the context
327
- n_provided_args = len(input[u.id])
328
- n_consumed_context = n_provided_args - len(u.required_args)
329
- else:
330
- n_consumed_context = 0
332
+ for id in input.keys():
333
+ for u in self.node2descendants[id]:
334
+ if u.id in input:
335
+ # user provided input should supersede the context
336
+ n_provided_args = len(input[u.id])
337
+ n_consumed_context = n_provided_args - len(u.required_args)
338
+ else:
339
+ n_consumed_context = 0
331
340
 
332
- node_context = tuple(
333
- (
334
- context[name]
335
- if name in context
336
- else u.required_context_default_args[name]
341
+ node_context = tuple(
342
+ (
343
+ context[name]
344
+ if name in context
345
+ else u.required_context_default_args[name]
346
+ )
347
+ for name in u.required_context[n_consumed_context:]
337
348
  )
338
- for name in u.required_context[n_consumed_context:]
339
- )
349
+ runtimes[u.id] = NodeRuntime.from_node(self.graph, u, node_context)
340
350
 
341
- runtimes[u.id] = NodeRuntime.from_node(self.graph, u, node_context)
342
351
  stack: list[NodeId] = []
343
352
 
344
353
  for id, args in input.items():
sera/misc/_utils.py CHANGED
@@ -417,3 +417,5 @@ async def replay_events(
417
417
  await dcg.execute_async(
418
418
  input={innode: (record,)}, context={"session": session}
419
419
  )
420
+
421
+ await session.commit()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: sera-2
3
- Version: 1.21.1
3
+ Version: 1.21.2
4
4
  Summary:
5
5
  Author: Binh Vu
6
6
  Author-email: bvu687@gmail.com
@@ -9,7 +9,7 @@ sera/libs/api_test_helper.py,sha256=3tRr8sLN4dBSrHgKAHMmyoENI0xh7K_JLel8AvujU7k,
9
9
  sera/libs/base_orm.py,sha256=5hOH_diUeaABm3cpE2-9u50VRqG1QW2osPQnvVHIhIA,3365
10
10
  sera/libs/base_service.py,sha256=NY-PLiaS1SXs2Pp3yVsdGnpJGUxKbHb0qzCCguhgPP4,6432
11
11
  sera/libs/directed_computing_graph/__init__.py,sha256=xiF5_I1y9HtQ-cyq02iwkRYgEZvxBB8YIvysCHCLBco,1290
12
- sera/libs/directed_computing_graph/_dcg.py,sha256=miclcxik67CbJpb8slvUOcdWLQH67msqder7JpOoiTw,14870
12
+ sera/libs/directed_computing_graph/_dcg.py,sha256=nQf9MhnTkFU2-dxhv_PFThz9L61Nn8cvYIOoMq0OVb8,15352
13
13
  sera/libs/directed_computing_graph/_edge.py,sha256=iBq6cpLWWyuD99QWTHVEh8naWUJrR4WJJuq5iuCrwHo,1026
14
14
  sera/libs/directed_computing_graph/_flow.py,sha256=6v39yKPIDYrQ3KvFqjeAWs88-oQSnDTaED2F3LF2z_I,478
15
15
  sera/libs/directed_computing_graph/_fn_signature.py,sha256=73iPUITcRKW0-l6sqjwMSk_FZnJESaKOmUKDGHTOh9Q,1598
@@ -28,7 +28,7 @@ sera/make/make_python_services.py,sha256=0ZpWLwQ7Nwfn8BXAikAB4JRpNknpSJyJgY5b1cj
28
28
  sera/make/make_typescript_model.py,sha256=CZc_LMigy7e6tP-6bJ5gHZlHYeyRtU_CNR4s64x51xE,71369
29
29
  sera/misc/__init__.py,sha256=L70kdXM5WmtMpgLlQISnGmrLgn241TQF0zFXFPi3Xzk,727
30
30
  sera/misc/_formatter.py,sha256=aCGYL08l8f3aLODHxSocxBBwkRYEo3K1QzCDEn3suj0,1685
31
- sera/misc/_utils.py,sha256=7vDhG1_hEdA4enTtL6gg5evBEg397kuxZ5ZtXC9PBWo,12939
31
+ sera/misc/_utils.py,sha256=8J-2z_3n6VQB8DuDrm7wKEq880x3BZLz9kbukORMuas,12971
32
32
  sera/models/__init__.py,sha256=vJC5Kzo_N7wd16ocNPy1VvAZDGNiWeiAhWJ4ihATKvA,780
33
33
  sera/models/_class.py,sha256=1J4Bd_LanzhhDWwZFHWGtFYD7lupe_alaB3D02ebNDI,2862
34
34
  sera/models/_collection.py,sha256=nLlP85OfEhfj4pFAYxB5ZvtBN6EdPSWPJ5ZFh5SSEC4,2686
@@ -42,6 +42,6 @@ sera/models/_parse.py,sha256=9iaW-8Ajq8e440FrTJ-X9oivHJJ447kPU-ZqffFxSvw,12649
42
42
  sera/models/_property.py,sha256=9yMDxrmbyuF6-29lQjiq163Xzwbk75TlmGBpu0NLpkI,7485
43
43
  sera/models/_schema.py,sha256=VxJEiqgVvbXgcSUK4UW6JnRcggk4nsooVSE6MyXmfNY,1636
44
44
  sera/typing.py,sha256=m4rir-fB6Cgcm7_ZSXXcNdla2LJgq96WXxtTTrDaJno,1058
45
- sera_2-1.21.1.dist-info/METADATA,sha256=ojxFGoSzu_QLUSvtKfl6pE86Qd2eCg6QStYYiFbykGw,936
46
- sera_2-1.21.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
47
- sera_2-1.21.1.dist-info/RECORD,,
45
+ sera_2-1.21.2.dist-info/METADATA,sha256=8jE5v1c-64MjGwTRTiPto2OD5tjYlZEkGtkmMkyZ2tk,936
46
+ sera_2-1.21.2.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
47
+ sera_2-1.21.2.dist-info/RECORD,,