Skip to content

Commit b76a2e9

Browse files
authored
Merge pull request #45 from hyroai/fix-infer-sink
fix infer_sink: multiple future edges are to a single destination, then that is the sink
2 parents 2e93e48 + 8d09d16 commit b76a2e9

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

computation_graph/composers/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ def filter_computation_errors(*args):
107107
)
108108

109109

110+
_destinations = gamla.compose(set, gamla.map(base_types.edge_destination))
111+
112+
110113
def _infer_sink(graph_or_node: base_types.NodeOrGraph) -> base_types.ComputationNode:
111114
if isinstance(graph_or_node, base_types.ComputationNode):
112115
return graph_or_node
@@ -130,8 +133,8 @@ def _infer_sink(graph_or_node: base_types.NodeOrGraph) -> base_types.Computation
130133
assert len(result) == 1
131134
return gamla.head(result)
132135

133-
assert len(graph_or_node) == 1, graph_without_future_edges
134-
return graph_or_node[0].destination
136+
assert len(_destinations(graph_or_node)) == 1, graph_or_node
137+
return base_types.edge_destination(graph_or_node[0])
135138

136139

137140
def make_first(*graphs: base_types.CallableOrNodeOrGraph) -> base_types.GraphType:

computation_graph/composers/composers_test.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from computation_graph import composers, graph_runners
1+
import computation_graph.graph
2+
from computation_graph import base_types, composers, graph_runners
23

34

45
def test_unary_composition_with_graph_destination():
@@ -11,6 +12,20 @@ def test_unary_composition_with_graph_destination():
1112
assert result == -1
1213

1314

15+
def test_infer_sink_edge_case_all_future_edges_with_single_destination():
16+
s = computation_graph.graph.make_source()
17+
18+
def c_b(c, b):
19+
return b
20+
21+
two_future_edges_single_dest = base_types.merge_graphs(
22+
composers.compose_left_source(s, "c", c_b),
23+
composers.compose_left_source(s, "b", c_b),
24+
)
25+
26+
composers.compose_left_unary(two_future_edges_single_dest, lambda x: x)
27+
28+
1429
def test_ambiguity_does_not_blow_up():
1530
counter = 0
1631

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
setuptools.setup(
88
name="computation-graph",
99
python_requires=">=3",
10-
version="37",
10+
version="38",
1111
long_description=_LONG_DESCRIPTION,
1212
long_description_content_type="text/markdown",
1313
packages=setuptools.find_namespace_packages(),

0 commit comments

Comments
 (0)