computation-graph 52__tar.gz → 53__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-52 → computation-graph-53}/PKG-INFO +1 -1
- {computation-graph-52 → computation-graph-53}/computation_graph/composers/duplication.py +39 -2
- {computation-graph-52 → computation-graph-53}/computation_graph/graph.py +20 -1
- {computation-graph-52 → computation-graph-53}/computation_graph/graph_test.py +98 -0
- {computation-graph-52 → computation-graph-53}/computation_graph.egg-info/PKG-INFO +1 -1
- {computation-graph-52 → computation-graph-53}/setup.py +1 -1
- {computation-graph-52 → computation-graph-53}/LICENSE.md +0 -0
- {computation-graph-52 → computation-graph-53}/README.md +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph/__init__.py +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph/base_types.py +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph/composers/__init__.py +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph/composers/composers_test.py +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph/composers/condition.py +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph/composers/condition_test.py +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph/composers/debug.py +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph/composers/lift.py +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph/composers/logic.py +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph/composers/memory.py +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph/composers/memory_test.py +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph/graph_runners.py +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph/legacy.py +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph/run.py +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph/signature.py +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph/trace/__init__.py +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph/trace/ascii.py +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph/trace/graphviz.py +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph/trace/graphviz_test.py +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph/trace/mermaid.py +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph/trace/trace_utils.py +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph.egg-info/SOURCES.txt +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph.egg-info/dependency_links.txt +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph.egg-info/requires.txt +0 -0
- {computation-graph-52 → computation-graph-53}/computation_graph.egg-info/top_level.txt +0 -0
- {computation-graph-52 → computation-graph-53}/pyproject.toml +0 -0
- {computation-graph-52 → computation-graph-53}/setup.cfg +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
import functools
|
|
3
3
|
import inspect
|
|
4
|
+
from typing import Dict
|
|
4
5
|
|
|
5
6
|
import gamla
|
|
6
7
|
|
|
@@ -20,6 +21,7 @@ def duplicate_function(func):
|
|
|
20
21
|
def inner(*args, **kwargs):
|
|
21
22
|
return func(*args, **kwargs)
|
|
22
23
|
|
|
24
|
+
inner.__name__ = f"duplicate of {inner.__name__}"
|
|
23
25
|
return inner
|
|
24
26
|
|
|
25
27
|
|
|
@@ -42,8 +44,8 @@ _duplicate_node = gamla.compose_left(
|
|
|
42
44
|
graph.make_computation_node,
|
|
43
45
|
)
|
|
44
46
|
|
|
47
|
+
|
|
45
48
|
_node_to_duplicated_node = gamla.compose_left(
|
|
46
|
-
graph.get_all_nodes,
|
|
47
49
|
gamla.remove(base_types.node_is_terminal),
|
|
48
50
|
gamla.map(gamla.pair_right(_duplicate_node)),
|
|
49
51
|
dict,
|
|
@@ -51,7 +53,7 @@ _node_to_duplicated_node = gamla.compose_left(
|
|
|
51
53
|
)
|
|
52
54
|
|
|
53
55
|
duplicate_graph = gamla.compose_left(
|
|
54
|
-
gamla.pair_with(_node_to_duplicated_node),
|
|
56
|
+
gamla.pair_with(gamla.compose_left(graph.get_all_nodes, _node_to_duplicated_node)),
|
|
55
57
|
gamla.star(
|
|
56
58
|
lambda get_duplicated_node, graph: gamla.pipe(
|
|
57
59
|
graph,
|
|
@@ -68,3 +70,38 @@ duplicate_graph = gamla.compose_left(
|
|
|
68
70
|
duplicate_function_or_graph = gamla.ternary(
|
|
69
71
|
gamla.is_instance(tuple), duplicate_graph, duplicate_function
|
|
70
72
|
)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def safe_replace_sources(
|
|
76
|
+
source_to_replacement_dict: Dict[
|
|
77
|
+
base_types.CallableOrNode, base_types.CallableOrNodeOrGraph
|
|
78
|
+
],
|
|
79
|
+
cg: base_types.GraphType,
|
|
80
|
+
) -> base_types.GraphType:
|
|
81
|
+
source_to_replacement_dict = gamla.keymap(graph.make_computation_node)(
|
|
82
|
+
source_to_replacement_dict
|
|
83
|
+
)
|
|
84
|
+
reachable_to_duplicate_map = gamla.pipe(
|
|
85
|
+
gamla.graph_traverse_many(
|
|
86
|
+
source_to_replacement_dict.keys(), graph.traverse_forward(cg)
|
|
87
|
+
),
|
|
88
|
+
gamla.remove(gamla.contains(source_to_replacement_dict.keys())),
|
|
89
|
+
_node_to_duplicated_node,
|
|
90
|
+
)
|
|
91
|
+
get_node_replacement = gamla.compose_left(
|
|
92
|
+
gamla.lazyjuxt(
|
|
93
|
+
gamla.dict_to_getter_with_default(None)(source_to_replacement_dict),
|
|
94
|
+
reachable_to_duplicate_map,
|
|
95
|
+
gamla.identity,
|
|
96
|
+
),
|
|
97
|
+
gamla.find(gamla.identity),
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
def update_edge(e: base_types.ComputationEdge) -> base_types.GraphType:
|
|
101
|
+
dest = base_types.edge_destination(e)
|
|
102
|
+
g = graph.replace_node(dest, get_node_replacement(dest))((e,))
|
|
103
|
+
for source in base_types.edge_sources(e):
|
|
104
|
+
g = graph.replace_source(source, get_node_replacement(source), g)
|
|
105
|
+
return g
|
|
106
|
+
|
|
107
|
+
return gamla.reduce(lambda updated_cg, e: updated_cg + update_edge(e), (), cg)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import dataclasses
|
|
2
|
-
from typing import Callable, FrozenSet
|
|
2
|
+
from typing import Callable, FrozenSet, Tuple
|
|
3
3
|
|
|
4
4
|
import gamla
|
|
5
5
|
from gamla.optimized import sync as opt_gamla
|
|
@@ -148,6 +148,25 @@ def _replace_source_in_edges(
|
|
|
148
148
|
)
|
|
149
149
|
|
|
150
150
|
|
|
151
|
+
traverse_forward: Callable[
|
|
152
|
+
[base_types.GraphType],
|
|
153
|
+
Callable[[base_types.CallableOrNode], Tuple[base_types.ComputationNode, ...]],
|
|
154
|
+
] = gamla.compose_left(
|
|
155
|
+
gamla.mapcat(
|
|
156
|
+
gamla.compose_left(
|
|
157
|
+
gamla.juxt(base_types.edge_sources, base_types.edge_destination),
|
|
158
|
+
gamla.explode(0),
|
|
159
|
+
)
|
|
160
|
+
),
|
|
161
|
+
gamla.groupby_many_reduce(
|
|
162
|
+
gamla.compose_left(gamla.head, gamla.wrap_tuple),
|
|
163
|
+
lambda destinations, e: (*(destinations if destinations else ()), e[1]),
|
|
164
|
+
),
|
|
165
|
+
gamla.dict_to_getter_with_default(()),
|
|
166
|
+
gamla.before(make_computation_node),
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
|
|
151
170
|
@gamla.curry
|
|
152
171
|
def replace_source(
|
|
153
172
|
original: base_types.CallableOrNode,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import asyncio
|
|
2
|
+
from typing import Dict
|
|
2
3
|
|
|
3
4
|
import gamla
|
|
4
5
|
import pytest
|
|
@@ -802,3 +803,100 @@ def test_ambig_edges_assertion_in_merge_graphs_active_only_when_env_var_is_activ
|
|
|
802
803
|
composers.compose_left_unary(lambda: 1, a),
|
|
803
804
|
composers.compose_left_unary(lambda: 1, a),
|
|
804
805
|
)
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
def a():
|
|
809
|
+
pass
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
def b(x):
|
|
813
|
+
pass
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
def c(x):
|
|
817
|
+
pass
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
def d(x, y):
|
|
821
|
+
pass
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
def kuky():
|
|
825
|
+
pass
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
def kuku():
|
|
829
|
+
pass
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
t = graph.make_terminal("t", lambda x: x)
|
|
833
|
+
|
|
834
|
+
g = (
|
|
835
|
+
composers.compose_left(a, c)
|
|
836
|
+
+ composers.compose_left(c, d, key="x")
|
|
837
|
+
+ composers.compose_left(b, d, key="y")
|
|
838
|
+
+ composers.compose_left_future(d, b, "x", "bla")
|
|
839
|
+
+ composers.compose_left(a, t)
|
|
840
|
+
)
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
@pytest.mark.parametrize(
|
|
844
|
+
"to_replace,expected_edges_strs",
|
|
845
|
+
[
|
|
846
|
+
pytest.param(
|
|
847
|
+
{a: kuky},
|
|
848
|
+
{
|
|
849
|
+
"kuky----x---->duplicate of c",
|
|
850
|
+
"kuky----x---->t",
|
|
851
|
+
"duplicate of c----x---->duplicate of d",
|
|
852
|
+
"when_memory_unavailable----x---->duplicate of b",
|
|
853
|
+
"duplicate of d....x....>duplicate of b",
|
|
854
|
+
"duplicate of b----y---->duplicate of d",
|
|
855
|
+
},
|
|
856
|
+
id="replace source node",
|
|
857
|
+
),
|
|
858
|
+
pytest.param(
|
|
859
|
+
{c: kuky},
|
|
860
|
+
{
|
|
861
|
+
"a----x---->kuky",
|
|
862
|
+
"a----x---->t",
|
|
863
|
+
"kuky----x---->duplicate of d",
|
|
864
|
+
"when_memory_unavailable----x---->duplicate of b",
|
|
865
|
+
"duplicate of d....x....>duplicate of b",
|
|
866
|
+
"duplicate of b----y---->duplicate of d",
|
|
867
|
+
},
|
|
868
|
+
id="replace node not in cycle",
|
|
869
|
+
),
|
|
870
|
+
pytest.param(
|
|
871
|
+
{b: kuky},
|
|
872
|
+
{
|
|
873
|
+
"a----x---->c",
|
|
874
|
+
"a----x---->t",
|
|
875
|
+
"c----x---->duplicate of d",
|
|
876
|
+
"when_memory_unavailable----x---->kuky",
|
|
877
|
+
"duplicate of d....x....>kuky",
|
|
878
|
+
"kuky----y---->duplicate of d",
|
|
879
|
+
},
|
|
880
|
+
id="replace node in cycle",
|
|
881
|
+
),
|
|
882
|
+
pytest.param(
|
|
883
|
+
{a: kuku, b: kuky},
|
|
884
|
+
{
|
|
885
|
+
"duplicate of c----x---->duplicate of d",
|
|
886
|
+
"duplicate of d....x....>kuky",
|
|
887
|
+
"kuku----x---->duplicate of c",
|
|
888
|
+
"kuku----x---->t",
|
|
889
|
+
"kuky----y---->duplicate of d",
|
|
890
|
+
"when_memory_unavailable----x---->kuky",
|
|
891
|
+
},
|
|
892
|
+
id="replace multiple nodes - duplicate reachables once",
|
|
893
|
+
),
|
|
894
|
+
],
|
|
895
|
+
)
|
|
896
|
+
def test_safe_replace_node(
|
|
897
|
+
to_replace: Dict[base_types.CallableOrNode, base_types.CallableOrNodeOrGraph],
|
|
898
|
+
expected_edges_strs: str,
|
|
899
|
+
):
|
|
900
|
+
assert expected_edges_strs == {
|
|
901
|
+
str(e) for e in duplication.safe_replace_sources(to_replace, g)
|
|
902
|
+
}
|
|
@@ -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="53",
|
|
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
|
|
File without changes
|
{computation-graph-52 → computation-graph-53}/computation_graph.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|