Skip to content

Commit

Permalink
added deterministic order of creating nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
klemen1999 committed May 7, 2024
1 parent 76c0dce commit 4ec56bc
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions luxonis_train/utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,20 +265,22 @@ def validate_packet(data: Packet[Tensor], protocol: type[BaseModel]) -> Packet[T
# TEST:
def traverse_graph(
graph: dict[str, list[str]], nodes: dict[str, T]
) -> Generator[tuple[str, T, list[str], set[str]], None, None]:
) -> Generator[tuple[str, T, list[str], list[str]], None, None]:
"""Traverses the graph in topological order.
@type graph: dict[str, list[str]]
@param graph: Graph in a format of a dictionary of predecessors. Keys are node
names, values are inputs to the node (list of node names).
@type nodes: dict[str, T]
@param nodes: Dictionary mapping node names to node objects.
@rtype: Generator[tuple[str, T, list[str], set[str]], None, None]
@rtype: Generator[tuple[str, T, list[str], list[str]], None, None]
@return: Generator of tuples containing node name, node object, node dependencies
and unprocessed nodes.
@raises RuntimeError: If the graph is malformed.
"""
unprocessed_nodes = set(nodes.keys())
unprocessed_nodes = sorted(
set(nodes.keys())
) # sort the set to allow reproducibility
processed: set[str] = set()

while unprocessed_nodes:
Expand Down

0 comments on commit 4ec56bc

Please sign in to comment.