computation-graph 61__tar.gz → 63__tar.gz
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.
- {computation_graph-61 → computation_graph-63}/PKG-INFO +1 -1
- {computation_graph-61 → computation_graph-63}/computation_graph/composers/debug.py +1 -0
- {computation_graph-61 → computation_graph-63}/computation_graph/composers/duplication.py +6 -6
- {computation_graph-61 → computation_graph-63}/computation_graph/graph_test.py +23 -2
- {computation_graph-61 → computation_graph-63}/computation_graph/run.py +54 -26
- {computation_graph-61 → computation_graph-63}/computation_graph.egg-info/PKG-INFO +1 -1
- {computation_graph-61 → computation_graph-63}/setup.py +1 -1
- {computation_graph-61 → computation_graph-63}/LICENSE.md +0 -0
- {computation_graph-61 → computation_graph-63}/README.md +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph/__init__.py +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph/base_types.py +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph/composers/__init__.py +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph/composers/composers_test.py +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph/composers/condition.py +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph/composers/condition_test.py +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph/composers/lift.py +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph/composers/logic.py +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph/composers/memory.py +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph/composers/memory_test.py +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph/graph.py +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph/graph_runners.py +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph/legacy.py +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph/signature.py +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph/trace/__init__.py +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph/trace/ascii.py +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph/trace/graphviz.py +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph/trace/graphviz_test.py +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph/trace/mermaid.py +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph/trace/trace_utils.py +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph.egg-info/SOURCES.txt +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph.egg-info/dependency_links.txt +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph.egg-info/requires.txt +0 -0
- {computation_graph-61 → computation_graph-63}/computation_graph.egg-info/top_level.txt +0 -0
- {computation_graph-61 → computation_graph-63}/pyproject.toml +0 -0
- {computation_graph-61 → computation_graph-63}/setup.cfg +0 -0
|
@@ -6,6 +6,7 @@ from typing import Dict
|
|
|
6
6
|
import gamla
|
|
7
7
|
|
|
8
8
|
from computation_graph import base_types, graph
|
|
9
|
+
from computation_graph.composers import debug
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
def duplicate_function(func):
|
|
@@ -15,14 +16,13 @@ def duplicate_function(func):
|
|
|
15
16
|
async def inner(*args, **kwargs):
|
|
16
17
|
return await func(*args, **kwargs)
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
else:
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
@functools.wraps(func)
|
|
22
|
+
def inner(*args, **kwargs):
|
|
23
|
+
return func(*args, **kwargs)
|
|
23
24
|
|
|
24
|
-
inner
|
|
25
|
-
return inner
|
|
25
|
+
return debug.name_callable(inner, f"duplicate of {func.__name__}")
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
def _duplicate_computation_edge(get_duplicated_node):
|
|
@@ -276,6 +276,27 @@ def test_raise_unhandled_exception():
|
|
|
276
276
|
graph_runners.nullary_infer_sink(composers.make_first(raises, lambda: 1))
|
|
277
277
|
|
|
278
278
|
|
|
279
|
+
async def test_raise_unhandled_exception_async():
|
|
280
|
+
class MyExceptionError(Exception):
|
|
281
|
+
...
|
|
282
|
+
|
|
283
|
+
@composers.compose_left_dict(
|
|
284
|
+
{"x": composers.compose_left_unary(lambda: 1, lambda x: 1)}
|
|
285
|
+
)
|
|
286
|
+
def raises(x):
|
|
287
|
+
raise MyExceptionError("BAD")
|
|
288
|
+
|
|
289
|
+
@composers.compose_left_dict({"x": lambda: 1})
|
|
290
|
+
async def not_awaited(x):
|
|
291
|
+
raise base_types.SkipComputationError("DAB")
|
|
292
|
+
|
|
293
|
+
with pytest.raises(MyExceptionError, match="BAD"):
|
|
294
|
+
await graph_runners.nullary_infer_sink(
|
|
295
|
+
composers.compose_left_dict({"y": raises, "x": not_awaited}, lambda x, y: 1)
|
|
296
|
+
)
|
|
297
|
+
assert len(asyncio.all_tasks()) == 1
|
|
298
|
+
|
|
299
|
+
|
|
279
300
|
async def test_raise_exception_in_sync_after_async():
|
|
280
301
|
def raises(x):
|
|
281
302
|
raise TypeError("BAD")
|
|
@@ -704,11 +725,11 @@ def test_compose_future():
|
|
|
704
725
|
)(([[{a: 2, b: 2, c: 2}, 9], [{a: 2, b: 2, c: 2}, 25]]))
|
|
705
726
|
|
|
706
727
|
|
|
707
|
-
def test_compose_future_async():
|
|
728
|
+
async def test_compose_future_async():
|
|
708
729
|
a = graph.make_source()
|
|
709
730
|
b = graph.make_source()
|
|
710
731
|
c = graph.make_source()
|
|
711
|
-
graph_runners.variadic_with_state_and_expectations(
|
|
732
|
+
await graph_runners.variadic_with_state_and_expectations(
|
|
712
733
|
base_types.merge_graphs(
|
|
713
734
|
composers.compose_source_unary(_plus_1_async, c),
|
|
714
735
|
composers.compose_source_unary(_times_2, b),
|
|
@@ -226,33 +226,10 @@ def _to_callable_with_side_effect_for_single_and_multiple(
|
|
|
226
226
|
if is_async:
|
|
227
227
|
|
|
228
228
|
async def final_runner(sources_to_values):
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
handled_exceptions,
|
|
232
|
-
topological_sorted_nodes,
|
|
229
|
+
inputs = translate_source_to_placeholder(sources_to_values)
|
|
230
|
+
all_results = await _run_graph_async(
|
|
231
|
+
inputs, handled_exceptions, topological_sorted_nodes
|
|
233
232
|
)
|
|
234
|
-
results_by_is_async = _group_by_is_future(node_to_task_or_result.items())
|
|
235
|
-
async_results = tuple(zip(*results_by_is_async.get(True, ())))
|
|
236
|
-
sync_results = dict(results_by_is_async.get(False, ()))
|
|
237
|
-
|
|
238
|
-
all_results = sync_results
|
|
239
|
-
if async_results:
|
|
240
|
-
for (node, node_result) in zip(
|
|
241
|
-
async_results[0],
|
|
242
|
-
await asyncio.gather(*async_results[1], return_exceptions=True),
|
|
243
|
-
):
|
|
244
|
-
e = node_to_task_or_result[node].exception()
|
|
245
|
-
if not e:
|
|
246
|
-
all_results[node] = node_result
|
|
247
|
-
elif not isinstance(
|
|
248
|
-
e,
|
|
249
|
-
(
|
|
250
|
-
_DepNotFoundError,
|
|
251
|
-
base_types.SkipComputationError,
|
|
252
|
-
*handled_exceptions,
|
|
253
|
-
),
|
|
254
|
-
):
|
|
255
|
-
raise e from e
|
|
256
233
|
|
|
257
234
|
return all_node_side_effects_on_edges(all_results)
|
|
258
235
|
|
|
@@ -505,6 +482,57 @@ def _make_get_node_executor(
|
|
|
505
482
|
return get_executor
|
|
506
483
|
|
|
507
484
|
|
|
485
|
+
async def _run_graph_async(inputs, handled_exceptions, topological_sorted_nodes):
|
|
486
|
+
node_to_task_or_result = inputs.copy()
|
|
487
|
+
unhandled_exception = None
|
|
488
|
+
try:
|
|
489
|
+
for node_executor in topological_sorted_nodes:
|
|
490
|
+
try:
|
|
491
|
+
node_to_task_or_result[node_executor[0]] = node_executor[1](
|
|
492
|
+
node_to_task_or_result, node_executor[0]
|
|
493
|
+
)
|
|
494
|
+
except (
|
|
495
|
+
_DepNotFoundError,
|
|
496
|
+
base_types.SkipComputationError,
|
|
497
|
+
*handled_exceptions,
|
|
498
|
+
):
|
|
499
|
+
pass
|
|
500
|
+
except Exception as exc:
|
|
501
|
+
unhandled_exception = exc
|
|
502
|
+
finally:
|
|
503
|
+
results_by_is_async = _group_by_is_future(node_to_task_or_result.items())
|
|
504
|
+
async_results = tuple(zip(*results_by_is_async.get(True, ())))
|
|
505
|
+
sync_results = dict(results_by_is_async.get(False, ()))
|
|
506
|
+
|
|
507
|
+
all_results = sync_results
|
|
508
|
+
if async_results:
|
|
509
|
+
for (node, node_result) in zip(
|
|
510
|
+
async_results[0],
|
|
511
|
+
await asyncio.gather(*async_results[1], return_exceptions=True),
|
|
512
|
+
):
|
|
513
|
+
task_e = node_to_task_or_result[node].exception()
|
|
514
|
+
if not task_e:
|
|
515
|
+
all_results[node] = node_result
|
|
516
|
+
elif not unhandled_exception and not isinstance(
|
|
517
|
+
task_e,
|
|
518
|
+
(
|
|
519
|
+
_DepNotFoundError,
|
|
520
|
+
base_types.SkipComputationError,
|
|
521
|
+
*handled_exceptions,
|
|
522
|
+
),
|
|
523
|
+
):
|
|
524
|
+
unhandled_exception = task_e
|
|
525
|
+
if unhandled_exception:
|
|
526
|
+
# this trick avoids cyclic reference and garbage collection issues
|
|
527
|
+
try:
|
|
528
|
+
raise unhandled_exception from unhandled_exception
|
|
529
|
+
except Exception as e:
|
|
530
|
+
del node_to_task_or_result
|
|
531
|
+
del unhandled_exception
|
|
532
|
+
raise e from e
|
|
533
|
+
return all_results
|
|
534
|
+
|
|
535
|
+
|
|
508
536
|
def _run_graph(
|
|
509
537
|
inputs: dict,
|
|
510
538
|
handled_exceptions,
|
|
@@ -7,7 +7,7 @@ with open("README.md", "r") as fh:
|
|
|
7
7
|
setuptools.setup(
|
|
8
8
|
name="computation-graph",
|
|
9
9
|
python_requires=">=3",
|
|
10
|
-
version="
|
|
10
|
+
version="63",
|
|
11
11
|
long_description=_LONG_DESCRIPTION,
|
|
12
12
|
long_description_content_type="text/markdown",
|
|
13
13
|
packages=setuptools.find_namespace_packages(),
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{computation_graph-61 → computation_graph-63}/computation_graph.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|