Skip to content

Commit a25db70

Browse files
Treat nodes with missing parents as top-level so they are printed
Signed-off-by: Anuradha Karuppiah <26330987+AnuradhaKaruppiah@users.noreply.github.com>
1 parent f60a9fa commit a25db70

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

packages/nvidia_nat_eval/scripts/print_atif_function_tree.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,26 @@ def _print_tree(nodes: dict[str, NodeStats]) -> None:
114114
for child_ids in by_parent.values():
115115
child_ids.sort(key=lambda fid: nodes[fid].function_name)
116116

117-
roots = [fid for fid, node in nodes.items() if (node.parent_id in (None, "", "root")) and fid != "root"]
117+
roots = [
118+
fid for fid, node in nodes.items()
119+
if (
120+
fid != "root" and (
121+
node.parent_id in (None, "", "root") or
122+
node.parent_id not in nodes
123+
))
124+
]
118125
roots.sort(key=lambda fid: nodes[fid].function_name)
119126

127+
covered: set[str] = set()
128+
120129
def rec(function_id: str, prefix: str, is_last: bool, visited: set[str]) -> None:
121130
if function_id in visited:
122131
branch = "└─ " if is_last else "├─ "
123132
print(f"{prefix}{branch}<cycle> [{function_id}]")
124133
return
125134
visited = set(visited)
126135
visited.add(function_id)
136+
covered.add(function_id)
127137

128138
node = nodes[function_id]
129139
branch = "└─ " if is_last else "├─ "
@@ -146,6 +156,11 @@ def rec(function_id: str, prefix: str, is_last: bool, visited: set[str]) -> None
146156
for i, root_id in enumerate(roots):
147157
rec(root_id, "", i == len(roots) - 1, set())
148158

159+
# Ensure disconnected/cyclic components are still surfaced as top-level entries.
160+
remaining_roots = sorted((fid for fid in nodes if fid not in covered), key=lambda fid: nodes[fid].function_name)
161+
for i, root_id in enumerate(remaining_roots):
162+
rec(root_id, "", i == len(remaining_roots) - 1, set())
163+
149164

150165
def main() -> None:
151166
parser = argparse.ArgumentParser(description="Print ATIF function ancestry tree from workflow_output_atif.json")

packages/nvidia_nat_eval/scripts/print_ist_function_tree.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,26 @@ def _print_tree(nodes: dict[str, NodeStats]) -> None:
105105
for child_ids in by_parent.values():
106106
child_ids.sort(key=lambda fid: nodes[fid].function_name)
107107

108-
roots = [fid for fid, node in nodes.items() if (node.parent_id in (None, "", "root")) and fid != "root"]
108+
roots = [
109+
fid for fid, node in nodes.items()
110+
if (
111+
fid != "root" and (
112+
node.parent_id in (None, "", "root") or
113+
node.parent_id not in nodes
114+
))
115+
]
109116
roots.sort(key=lambda fid: nodes[fid].function_name)
110117

118+
covered: set[str] = set()
119+
111120
def rec(function_id: str, prefix: str, is_last: bool, visited: set[str]) -> None:
112121
if function_id in visited:
113122
branch = "└─ " if is_last else "├─ "
114123
print(f"{prefix}{branch}<cycle> [{function_id}]")
115124
return
116125
visited = set(visited)
117126
visited.add(function_id)
127+
covered.add(function_id)
118128

119129
node = nodes[function_id]
120130
branch = "└─ " if is_last else "├─ "
@@ -137,6 +147,11 @@ def rec(function_id: str, prefix: str, is_last: bool, visited: set[str]) -> None
137147
for i, root_id in enumerate(roots):
138148
rec(root_id, "", i == len(roots) - 1, set())
139149

150+
# Ensure disconnected/cyclic components are still surfaced as top-level entries.
151+
remaining_roots = sorted((fid for fid in nodes if fid not in covered), key=lambda fid: nodes[fid].function_name)
152+
for i, root_id in enumerate(remaining_roots):
153+
rec(root_id, "", i == len(remaining_roots) - 1, set())
154+
140155

141156
def main() -> None:
142157
parser = argparse.ArgumentParser(description="Print legacy IST function ancestry tree from workflow_output.json")

0 commit comments

Comments
 (0)