From c91b071c47339d2cf778d6cc918a48f14a23b962 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Fri, 9 Jun 2023 12:09:52 +1000 Subject: [PATCH] fix(nodes): use DFS with preorder traversal --- invokeai/app/services/graph.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/invokeai/app/services/graph.py b/invokeai/app/services/graph.py index 6a093d0bf6..94be8225da 100644 --- a/invokeai/app/services/graph.py +++ b/invokeai/app/services/graph.py @@ -1131,13 +1131,13 @@ class GraphExecutionState(BaseModel): """Gets the deepest node that is ready to be executed""" g = self.execution_graph.nx_graph() - # we need to traverse the graph in from bottom up - reversed_sorted_nodes = reversed(list(nx.topological_sort(g))) + # Depth-first search with pre-order traversal is a depth-first topological sort + sorted_nodes = nx.dfs_preorder_nodes(g) next_node = next( ( n - for n in reversed_sorted_nodes + for n in sorted_nodes if n not in self.executed # the node must not already be executed... and all((e[0] in self.executed for e in g.in_edges(n))) # ...and all its inputs must be executed ),