mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-08-01 01:27:42 +00:00
chore: show merge loop in figure (#1105)
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user