chore: show merge loop in figure (#1105)

This commit is contained in:
Tim
2025-07-22 17:02:56 +08:00
committed by GitHub
parent 1f142cc5d8
commit 9f7a4280dc
2 changed files with 13 additions and 4 deletions
+9 -1
View File
@@ -588,7 +588,15 @@ def summarize_win():
final_trace_loop_id = max_id
while "record" not in state.data[final_trace_loop_id]:
final_trace_loop_id -= 1
st.pyplot(trace_figure(state.data[final_trace_loop_id]["record"]["trace"]))
merge_loops = []
for loop_id in state.llm_data.keys():
if "direct_exp_gen" not in state.llm_data[loop_id]:
continue
if "scenarios.data_science.proposal.exp_gen.merge:trace" in [
i["obj"]["uri"] for i in state.llm_data[loop_id]["direct_exp_gen"]["no_tag"] if "uri" in i["obj"]
]:
merge_loops.append(loop_id)
st.pyplot(trace_figure(state.data[final_trace_loop_id]["record"]["trace"], merge_loops))
df = pd.DataFrame(
columns=[
"Component",
+4 -3
View File
@@ -598,7 +598,7 @@ def curve_figure(scores: pd.DataFrame) -> go.Figure:
return fig
def trace_figure(trace: Trace):
def trace_figure(trace: Trace, merge_loops: list = []):
G = nx.DiGraph()
# Calculate the number of ancestors for each node (root node is 0, more ancestors means lower level)
@@ -610,7 +610,7 @@ def trace_figure(trace: Trace):
"""
Convert to index in the queue (enque id) to loop_idx for easier understanding.
"""
if hasattr(trace, "idx2loop_id"):
if hasattr(trace, "idx2loop_id") and idx in trace.idx2loop_id:
# FIXME: only keep me after it is stable. Just for compatibility.
return f"L{trace.idx2loop_id[idx]} ({idx})"
return f"L{idx}"
@@ -684,7 +684,8 @@ def trace_figure(trace: Trace):
pos[node] = (x, y)
fig, ax = plt.subplots(figsize=(8, 6))
nx.draw(G, pos, with_labels=True, arrows=True, node_color="skyblue", node_size=100, font_size=5, ax=ax)
color_map = ["tomato" if node in [get_display_name(idx) for idx in merge_loops] else "skyblue" for node in G]
nx.draw(G, pos, with_labels=True, arrows=True, node_color=color_map, node_size=100, font_size=5, ax=ax)
return fig