Alexander Cai
06/14/2024, 2:00 PMwhat_is_upstream_of
return the nodes in? Is there any way to get the list of nodes required to compute a target node in topological order?Elijah Ben Izzy
06/14/2024, 2:11 PMwhat_is_upstream_of
does not currently guarentee order. Re: topological sort, this is a very reasonable request (and adding a guarentee or a parameter makes a lot of sense).
There are a few approaches you could consider — one should be pretty simple, writing an example.Elijah Ben Izzy
06/14/2024, 2:16 PMdr
that is your driver.
>>> graph = {n.name: list(n.optional_dependencies) + list(n.required_dependencies) for n in dr.what_is_upstream_of("confusion_matrix")}
>>> from graphlib import TopologicalSorter
>>> top_sorted = list(TopologicalSorter(graph).static_order())
>>> top_sorted
['iris_data', 'test_size_fraction', 'gamma', 'shuffle_train_test_split', 'feature_matrix', 'target', 'target_names', 'prefit_clf', 'train_test_split_func', 'y_train', 'y_test', 'X_test', 'X_train', 'y_test_with_labels', 'fit_clf', 'predicted_output', 'predicted_output_with_labels', 'confusion_matrix']
Thierry Jean
06/14/2024, 2:16 PMElijah Ben Izzy
06/14/2024, 2:16 PMThierry Jean
06/14/2024, 2:17 PMdef topological_sort(nodes):
"""Sort the nodes for nice output display"""
def dfs(node, visited, stack):
visited.add(node)
for neighbor in graph.get(node, []):
if neighbor not in visited:
dfs(neighbor, visited, stack)
stack.append(node)
graph = {n.name: set([*n.required_dependencies, *n.optional_dependencies]) for n in nodes}
visited = set()
stack = []
for node in graph:
if node not in visited:
dfs(node, visited, stack)
return stack
Alexander Cai
06/14/2024, 2:17 PMElijah Ben Izzy
06/14/2024, 2:19 PMAlexander Cai
06/17/2024, 1:48 PMnode.Node
instead of HamiltonNode
. https://github.com/DAGWorks-Inc/hamilton/blob/b2aeedc2999fad7ee260c6e67520b8ba1348ca8a/hamilton/execution/graph_functions.py#L15
Would the intended behaviour be to always return a sorted graph from the lineage operations?Thierry Jean
06/17/2024, 2:04 PMAlexander Cai
06/17/2024, 2:42 PM