Hey guys, quick question. Is there a simple way to...
# general
v
Hey guys, quick question. Is there a simple way to get the topologically sorted list of nodes from an Driver/Execution?
t
I'm not sure, but if you do
Driver.list_available_variables()
I think they are topologically sorted. Note that the order is not deterministic though. If you have DAG
Copy code
A -> B
A -> C
You might get
[A, B, C]
or
[A, C, B]
v
It does not, unfortunately. It returns alphabetically sorted I think. If you have:
Copy code
C -> B -> A
It returns A, B, C
e
Ughh, yeah, I thought we had this
You're not the first to ask
s
Yeah this returns the order in the internal dictionary by order of entry. @Victor Bouzas one of the “get upstream / downstream” driver functions might get what you want. Since that actually does a walk of the graph - confirmed.
e
Hmm, I think that’s in the right order, but there’s a (semi) internal-facing utility function that you can use. I think it’s fair to confirm ordering — it’s not specified so we can change it.
Copy code
from hamilton.execution.graph_functions import topologically_sort_nodes

dr = driver.Builder()....build()
graph = dr.graph
nodes_sorted = [HamiltonNode.from_node(n) for n in topologically_sort_nodes(list(graph.nodes.values()))]
This should be a decent workaround until the ticket I just opened, which seems reasonable https://github.com/DAGWorks-Inc/hamilton/issues/1293
v
Hi guys, thanks for the help. This workaround works for me :)