Skip to content

Commit 5e5a449

Browse files
authored
Fix collect visualization edge styling (#1651)
1 parent 50a0354 commit 5e5a449

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

hamilton/graph.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,13 @@ def _get_edge_style(from_type: str, to_type: str) -> dict:
437437

438438
return edge_style
439439

440+
def _is_collect_dependency_edge(dependency_node: node.Node, target_node: node.Node) -> bool:
441+
"""Returns true for the edge that feeds a Collect[...] dependency."""
442+
return (
443+
target_node.node_role == node.NodeType.COLLECT
444+
and dependency_node.name == target_node.collect_dependency
445+
)
446+
440447
def _get_legend(
441448
node_types: set[str], extra_legend_nodes: dict[tuple[str, str], dict[str, str]]
442449
):
@@ -648,7 +655,6 @@ def _insert_space_after_colon(col: str) -> str:
648655
# create edges
649656
input_sets = dict()
650657
for n in nodes:
651-
to_type = "collect" if n.node_role == node.NodeType.COLLECT else ""
652658
to_modifiers = node_modifiers.get(n.name, set())
653659

654660
input_nodes = set()
@@ -664,6 +670,7 @@ def _insert_space_after_colon(col: str) -> str:
664670
continue
665671

666672
from_type = "expand" if d.node_role == node.NodeType.EXPAND else ""
673+
to_type = "collect" if _is_collect_dependency_edge(d, n) else ""
667674
dependency_modifiers = node_modifiers.get(d.name, set())
668675
edge_style = _get_edge_style(from_type, to_type)
669676
if (

tests/test_graph.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import tests.resources.display_name_list_functions
4343
import tests.resources.dummy_functions
4444
import tests.resources.dummy_functions_module_override
45+
import tests.resources.dynamic_parallelism.parallel_collect_multiple_arguments
4546
import tests.resources.extract_column_nodes
4647
import tests.resources.extract_columns_execution_count
4748
import tests.resources.functions_with_generics
@@ -1198,6 +1199,32 @@ def test_function_graph_display_config_node():
11981199
assert any(line.startswith("\tX") for line in dot.body)
11991200

12001201

1202+
def test_function_graph_display_collect_edges_only_style_collected_dependency():
1203+
config = {}
1204+
fg = graph.FunctionGraph.from_modules(
1205+
tests.resources.dynamic_parallelism.parallel_collect_multiple_arguments, config=config
1206+
)
1207+
1208+
assert fg.nodes["summed"].node_role == NodeType.COLLECT
1209+
assert fg.nodes["summed"].collect_dependency == "double"
1210+
1211+
dot = fg.display(set(fg.get_nodes()), output_file_path=None, config=config)
1212+
1213+
edge_lines = {
1214+
line.strip().split(" [", 1)[0]: line.strip() for line in dot.body if " -> " in line
1215+
}
1216+
assert edge_lines["double -> summed"] == "double -> summed [arrowtail=crow dir=both]"
1217+
assert edge_lines["not_to_repeat -> summed"] == "not_to_repeat -> summed"
1218+
assert (
1219+
edge_lines["something_else_not_to_repeat -> summed"]
1220+
== "something_else_not_to_repeat -> summed"
1221+
)
1222+
assert (
1223+
edge_lines["number_to_repeat -> double"]
1224+
== "number_to_repeat -> double [arrowhead=crow arrowtail=none dir=both]"
1225+
)
1226+
1227+
12011228
# TODO use high-level visualization dot as fixtures for reuse across tests
12021229
def test_display_config_node():
12031230
"""Check if config is displayed by high-level hamilton.driver.display..."""

0 commit comments

Comments
 (0)