Skip to content

Graph traversal

traverse_graph_ensuring_parents_are_reached_first(graph, start_node) ΒΆ

This function works under assumption of common super-input node in the graph - otherwise, there is no common entry point to put as start_node.

Source code in inference/core/workflows/execution_engine/v1/compiler/graph_traversal.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def traverse_graph_ensuring_parents_are_reached_first(
    graph: DiGraph,
    start_node: str,
) -> List[str]:
    """
    This function works under assumption of common super-input node in the graph - otherwise,
    there is no common entry point to put as `start_node`.
    """
    graph_copy = graph.copy()
    distance_key = "distance"
    graph_copy = assign_max_distances_from_start(
        graph=graph_copy,
        start_node=start_node,
        distance_key=distance_key,
    )
    nodes_groups = group_nodes_by_sorted_key_value(graph=graph_copy, key=distance_key)
    return [node for node_group in nodes_groups for node in node_group]