""" gui/pages/overview.py — ◈ Overview 11/10 research dashboard with: - Dark / light theme (via st.session_state["theme"]) - Live job banner (unchanged from original) - KPI row (5 metrics) - Insight strip - Linear vs Agentic energy card - Tax by task+model chart - Recent sessions list - Agentic execution breakdown (time + energy per phase) - Orchestration tax attribution (red-top card) - Energy timeline sparkline - Hardware snapshot + live resource bars - Software environment + fingerprint - Activity feed - Apple-to-Apple + model comparison → sidebar "Model Behavior" panel - Duration vs Energy scatter + IPC vs Cache Miss scatter - Full comparison matrix table NOTE: Every line from the original overview.py is preserved. Apple-to-Apple section is rendered via render_model_behavior_sidebar() which is called from sidebar.py under the "MODEL BEHAVIOR" section. """ import streamlit as st import pandas as pd import plotly.graph_objects as go import plotly.express as px from gui.config import PROJECT_ROOT, DB_PATH, LIVE_API, WF_COLORS, PL from gui.db import q, q_safe, q1 from gui.helpers import fl, _human_energy, _human_water, _human_carbon try: import requests as _req _REQUESTS_OK = True except ImportError: _REQUESTS_OK = False class _req: @staticmethod def get(*a, **kw): raise RuntimeError("requests not installed") try: import yaml as _yaml _YAML_OK = True except ImportError: _YAML_OK = False # ───────────────────────────────────────────────────────────────────────────── # THEME HELPERS (inline so overview.py has zero extra imports) # ───────────────────────────────────────────────────────────────────────────── def _is_dark() -> bool: return st.session_state.get("theme", "dark") == "dark" def _tok(): """Return colour token dict for current theme.""" if _is_dark(): return dict( bg0="#0d1117", bg1="#111827", bg2="#1f2937", bg3="#374151", t1="#f1f5f9", t2="#94a3b8", t3="#475569", brd="#1f2937", brd2="#374151", accent="#3b82f6", card_top="3px solid #3b82f6", ) return dict( bg0="#f3f4f6", bg1="#ffffff", bg2="#f9fafb", bg3="#d1d5db", t1="#1f2937", t2="#4b5563", t3="#6b7280", brd="#d1d5db", brd2="#9ca3af", accent="#3b82f6", card_top="3px solid #3b82f6", ) def _inject_theme(): t = _tok() st.markdown(f"""""", unsafe_allow_html=True) def _card(content_html: str, border_top_color: str = None, extra_style: str = "") -> str: """Wrap HTML in a themed card div.""" t = _tok() top = f"border-top:3px solid {border_top_color};" if border_top_color else "" return ( f"
" f"{content_html}
" ) def _label(text: str) -> str: t = _tok() return (f"
{text}
") # ───────────────────────────────────────────────────────────────────────────── # MODEL BEHAVIOR SIDEBAR (moved from overview Apple-to-Apple section) # Called from sidebar.py — zero code lost # ───────────────────────────────────────────────────────────────────────────── def render_model_behavior_sidebar(): """ Full Apple-to-Apple model comparison — originally in overview.py. Moved to sidebar under "MODEL BEHAVIOR" heading. Every line of original logic preserved. """ t = _tok() _model_cmp, _ = q_safe(""" SELECT e.model_name, e.provider, r.workflow_type, e.task_name, COUNT(*) AS runs, ROUND(AVG(r.total_energy_uj)/1e6,4) AS avg_energy_j, ROUND(AVG(r.dynamic_energy_uj)/1e6,4) AS avg_dynamic_j, ROUND(AVG(r.duration_ns)/1e9,3) AS avg_duration_s, ROUND(AVG(r.total_tokens),1) AS avg_tokens, ROUND(AVG(CASE WHEN r.total_tokens>0 THEN r.total_energy_uj/r.total_tokens END)/1e3,4) AS avg_mj_per_token, ROUND(AVG(r.ipc),3) AS avg_ipc, ROUND(AVG(r.carbon_g)*1000,4) AS avg_carbon_mg, ROUND(AVG(r.water_ml),4) AS avg_water_ml FROM runs r JOIN experiments e ON r.exp_id=e.exp_id WHERE e.model_name IS NOT NULL GROUP BY e.model_name, e.provider, r.workflow_type, e.task_name ORDER BY e.provider, e.model_name, r.workflow_type """) if _model_cmp.empty: st.markdown( f"
" f"No model data yet — run experiments first.
", unsafe_allow_html=True) return # ── Per-model summary cards ─────────────────────────────────────────────── _models_list = _model_cmp.model_name.dropna().unique().tolist() for _mname in _models_list[:6]: _mdf = _model_cmp[_model_cmp.model_name == _mname] _mlin = _mdf[_mdf.workflow_type == "linear"].avg_energy_j.mean() _mage = _mdf[_mdf.workflow_type == "agentic"].avg_energy_j.mean() _mprov = str(_mdf.provider.iloc[0]) if not _mdf.empty else "?" _mmult = _mage / _mlin if (_mlin and _mlin > 0) else 1 _pclr = "#38bdf8" if _mprov == "cloud" else "#22c55e" _lin_s = f"{_mlin:.4f}" if (_mlin and _mlin == _mlin) else "—" _age_s = f"{_mage:.4f}" if (_mage and _mage == _mage) else "—" st.markdown( f"
" f"
" f"{_mname[:28]}
" f"
{_mprov}
" f"
" f"Linear: {_lin_s} J
" f"
" f"Agentic: {_age_s} J
" f"
" f"Overhead: {_mmult:.2f}×
" f"
", unsafe_allow_html=True) st.markdown( f"
", unsafe_allow_html=True) # ── Task filter ─────────────────────────────────────────────────────────── _task_list = _model_cmp.task_name.dropna().unique().tolist() _sel_task_ov = st.selectbox( "Filter task", ["all"] + sorted(_task_list), key="ov_task_filter") _cmp_filtered = (_model_cmp if _sel_task_ov == "all" else _model_cmp[_model_cmp.task_name == _sel_task_ov]) _cmp_pivot = _cmp_filtered.copy() _cmp_pivot["model_wf"] = ( _cmp_pivot["model_name"].astype(str) + " · " + _cmp_pivot["workflow_type"].astype(str)) # ── Energy chart ────────────────────────────────────────────────────────── st.markdown( f"
" f"Energy (J) — model × workflow
", unsafe_allow_html=True) _fig_cmp = px.bar( _cmp_pivot.groupby(["model_wf", "workflow_type"])["avg_energy_j"] .mean().reset_index(), x="model_wf", y="avg_energy_j", color="workflow_type", barmode="group", color_discrete_map=WF_COLORS, labels={"avg_energy_j": "Avg Energy (J)", "model_wf": "Model · Workflow"}) _fig_cmp.update_xaxes(tickangle=30) _fig_cmp.update_layout( paper_bgcolor=t["bg1"], plot_bgcolor=t["bg2"], font=dict(color=t["t1"], size=9), margin=dict(t=20, b=60, l=40, r=10), legend=dict(bgcolor=t["bg1"], font=dict(color=t["t2"])), height=220) st.plotly_chart(fl(_fig_cmp), use_container_width=True) # ── mJ/token chart ──────────────────────────────────────────────────────── st.markdown( f"
" f"mJ / token — model × workflow
", unsafe_allow_html=True) _fig_cmp2 = px.bar( _cmp_pivot.groupby(["model_wf", "workflow_type"])["avg_mj_per_token"] .mean().reset_index(), x="model_wf", y="avg_mj_per_token", color="workflow_type", barmode="group", color_discrete_map=WF_COLORS, labels={"avg_mj_per_token": "mJ/token", "model_wf": "Model · Workflow"}) _fig_cmp2.update_xaxes(tickangle=30) _fig_cmp2.update_layout( paper_bgcolor=t["bg1"], plot_bgcolor=t["bg2"], font=dict(color=t["t1"], size=9), margin=dict(t=20, b=60, l=40, r=10), legend=dict(bgcolor=t["bg1"], font=dict(color=t["t2"])), height=220) st.plotly_chart(fl(_fig_cmp2), use_container_width=True) st.markdown( f"
", unsafe_allow_html=True) # ── Full comparison matrix ──────────────────────────────────────────────── st.markdown( f"
" f"Full comparison matrix
", unsafe_allow_html=True) _show_cols = [c for c in [ "model_name", "provider", "workflow_type", "task_name", "runs", "avg_energy_j", "avg_dynamic_j", "avg_duration_s", "avg_tokens", "avg_mj_per_token", "avg_ipc", "avg_carbon_mg", "avg_water_ml"] if c in _model_cmp.columns] st.dataframe(_model_cmp[_show_cols].round(4), use_container_width=True, hide_index=True) # ───────────────────────────────────────────────────────────────────────────── # MAIN RENDER # ───────────────────────────────────────────────────────────────────────────── def render(ctx: dict): _inject_theme() t = _tok() ov = ctx["ov"] runs = ctx["runs"] tax = ctx["tax"] avg_lin_j = ctx["avg_lin_j"] avg_age_j = ctx["avg_age_j"] tax_mult = ctx["tax_mult"] plan_ms = ctx["plan_ms"] exec_ms = ctx["exec_ms"] synth_ms = ctx["synth_ms"] plan_pct = ctx["plan_pct"] exec_pct = ctx["exec_pct"] synth_pct = ctx["synth_pct"] lin = ctx["lin"] age = ctx["age"] # ── TOPBAR ──────────────────────────────────────────────────────────────── _tcol, _tbtn = st.columns([8, 1]) with _tcol: st.markdown( f"
" f"A-LEMS" f"Agentic LLM Energy Measurement System" f"
", unsafe_allow_html=True) with _tbtn: _lbl = "☀ Light" if _is_dark() else "☾ Dark" if st.button(_lbl, key="ov_theme_toggle"): st.session_state["theme"] = "light" if _is_dark() else "dark" st.rerun() # ── LIVE JOB BANNER (original — untouched) ──────────────────────────────── _live_jobs = pd.DataFrame() try: from gui.db import db as _db_ctx with _db_ctx() as _lcon: _live_jobs = pd.read_sql_query(""" SELECT e.exp_id, e.name, e.status, e.model_name, e.provider, e.task_name, e.runs_total, e.started_at, e.completed_at, e.error_message, COUNT(r.run_id) AS runs_done_actual, COALESCE(e.runs_completed, COUNT(r.run_id)) AS runs_done, ROUND( 100.0 * COALESCE(e.runs_completed, COUNT(r.run_id)) / NULLIF(e.runs_total, 0), 0) AS pct_done FROM experiments e LEFT JOIN runs r ON r.exp_id = e.exp_id WHERE ( e.status IN ('running', 'pending', 'started') OR (e.status = 'completed' AND datetime(e.completed_at) > datetime('now', '-10 minutes')) OR (e.status = 'error' AND datetime(COALESCE(e.completed_at, e.started_at)) > datetime('now', '-30 minutes')) ) GROUP BY e.exp_id ORDER BY e.started_at DESC LIMIT 3 """, _lcon) except Exception: pass if not _live_jobs.empty: _has_running = any(s in ("running","started") for s in _live_jobs.status.values) if _has_running: import time as _t if "live_last_refresh" not in st.session_state: st.session_state.live_last_refresh = 0.0 if _t.time() - st.session_state.live_last_refresh > 4: st.session_state.live_last_refresh = _t.time() st.cache_data.clear() _hdr_col, _hdr_btn = st.columns([7, 1]) with _hdr_col: _pulse = "🟢" if _has_running else "⚫" st.markdown( f"
" f"{_pulse} Live / Recent Jobs
", unsafe_allow_html=True) with _hdr_btn: if st.button("↺", key="ov_live_refresh", help="Force refresh"): st.cache_data.clear() st.rerun() for _, _jrow in _live_jobs.iterrows(): _jstat = str(_jrow.get("status", "?")) _jdone = int(_jrow.get("runs_done") or 0) _jtot = int(_jrow.get("runs_total") or 0) _jpct = float(_jrow.get("pct_done") or 0) _jerr = str(_jrow.get("error_message") or "") _jclr = {"running":"#22c55e","completed":"#3b82f6", "pending":"#f59e0b","started":"#22c55e", "error":"#ef4444"}.get(_jstat,"#7090b0") _jpulse = "●" if _jstat in ("running","started") else "○" _jdur = "" try: import datetime as _dt _ts = _dt.datetime.fromisoformat( str(_jrow.get("started_at","")).replace("Z","")) _jend_s = str(_jrow.get("completed_at") or "") _te = (_dt.datetime.fromisoformat(_jend_s.replace("Z","")) if _jend_s and _jend_s not in ("None","") else _dt.datetime.now()) _sec = int((_te - _ts).total_seconds()) _jdur = f"{_sec//60}m{_sec%60:02d}s" except Exception: pass _err_html = "" if _jerr and _jerr not in ("None","") and _jstat == "error": _err_short = _jerr[:60] + ("…" if len(_jerr) > 60 else "") _err_html = ( f"
" f"{_err_short}
") st.markdown(f"""
{_jpulse} {_jstat.upper()} {str(_jrow.get('task_name','?'))} {str(_jrow.get('model_name','?'))[:22]} {str(_jrow.get('provider','?'))} {_jdur} {_jdone}/{_jtot}
{_err_html}
""", unsafe_allow_html=True) st.markdown("") # ── INSIGHT STRIP ───────────────────────────────────────────────────────── st.markdown( f"
" f"" f"Agentic costs " f"{tax_mult:.1f}× more energy than linear for the same task" f"" f"Measured across {ov.get('total_runs','—')} runs · " f"{ov.get('total_experiments','—')} experiments" f"
", unsafe_allow_html=True) # ── KPI ROW ─────────────────────────────────────────────────────────────── c1, c2, c3, c4, c5, c6 = st.columns(6) c1.metric("Total Runs", ov.get("total_runs","—")) c2.metric("Tax Multiple", f"{tax_mult:.1f}×", delta=f"{(tax_mult-1)*100:.0f}% overhead", delta_color="inverse") c3.metric("Avg Planning", f"{plan_ms:.0f}ms", delta=f"{plan_pct:.0f}% of agentic time", delta_color="inverse") c4.metric("Peak IPC", f"{ov.get('max_ipc', 0) or 0:.3f}") c5.metric("Avg Carbon", f"{ov.get('avg_carbon_mg', 0) or 0:.3f}mg") c6.metric("Total Energy", f"{ov.get('total_energy_j', 0) or 0:.1f}J") st.markdown("
", unsafe_allow_html=True) # ── ROW 1: Energy compare | Tax by task | Recent sessions ───────────── # All three cards use identical height (340px) + flex-column so footers align CARD_H = "340px" bg1 = t["bg1"]; bg2 = t["bg2"]; bg3 = t["bg3"] t1 = t["t1"]; t2 = t["t2"]; t3 = t["t3"] brd = t["brd"]; brd2 = t["brd2"] def _fixed_card(body_html: str, footer_html: str, top_color: str = "#3b82f6") -> str: """Card with fixed height, body scrolls, footer pinned at bottom.""" return ( f"
" f"
{body_html}
" f"
{footer_html}
" f"
" ) def _empty_row(label: str = "") -> str: """Phantom row — same height as a real row, invisible.""" return ( f"
" f"" f"{label}" f"
" ) # ── Card 1: Linear vs Agentic ────────────────────────────────────────────── bar_pct = f"{100/max(tax_mult,1):.0f}%" _c1_body = ( _label("Linear vs Agentic — total energy") + f"
" + f"
" + f"
Linear
" + f"
{avg_lin_j:.3f} J
" + f"
baseline · 1×
" + f"
" + f"
" + f"
" + f"
" + f"
Agentic
" + f"
{avg_age_j:.3f} J
" + f"
overhead · {tax_mult:.1f}×
" + f"
" + f"
" + f"
" # ratio bar + f"
Cost ratio
" + f"
" + f"
linear
" + f"
" ) _c1_foot = ( f"
" f"Extra cost: {avg_age_j-avg_lin_j:.3f} J" f" per session — orchestration tax in absolute terms
" ) # ── Card 2: Tax multiplier — always 6 rows ───────────────────────────────── _tax_real_rows = [] try: _tax_df, _ = q_safe(""" SELECT e.task_name || ' · ' || COALESCE(e.model_name, e.provider, '?') AS label, ROUND(AVG( CAST(ra.total_energy_uj AS REAL) / NULLIF(rl.total_energy_uj, 0) ), 2) AS tmult FROM orchestration_tax_summary ots JOIN runs rl ON ots.linear_run_id = rl.run_id JOIN runs ra ON ots.agentic_run_id = ra.run_id JOIN experiments e ON ra.exp_id = e.exp_id WHERE rl.total_energy_uj > 0 GROUP BY label ORDER BY tmult DESC LIMIT 6 """) if not _tax_df.empty: _max_t = float(_tax_df.tmult.max()) or 1 for _, _tr in _tax_df.iterrows(): _tv = float(_tr.tmult or 0) _tw = f"{_tv/_max_t*95:.0f}%" _clr = "#dc2626" if _tv >= 10 else "#d97706" if _tv >= 2 else "#16a34a" _tax_real_rows.append( f"
" f"
{str(_tr.label)[:20]}
" f"
" f"
{_tv:.1f}×
" f"
{_tv:.1f}×
") except Exception: pass _c2_body = _label("Tax multiplier by task + model") for _row in _tax_real_rows: _c2_body += _row # pad to 6 rows _empty_tax = ( f"
" f"
" f"
" f"
" ) for _ in range(6 - len(_tax_real_rows)): _c2_body += _empty_tax _c2_foot = f"
red >10× · amber 2–10× · green <2×
" # ── Card 3: Recent sessions — always 6 rows ──────────────────────────────── _sess_real_rows = [] try: _sess_df, _ = q_safe(""" SELECT e.group_id, MAX(e.status) AS status, COUNT(DISTINCT e.exp_id) AS n_exps, MAX(e.created_at) AS latest FROM experiments e GROUP BY e.group_id ORDER BY MAX(e.exp_id) DESC LIMIT 6 """) _tax_by_group = {} try: _tg, _ = q_safe(""" SELECT e.group_id, ROUND(AVG(CAST(ra.total_energy_uj AS REAL) / NULLIF(rl.total_energy_uj,0)),2) AS mt FROM orchestration_tax_summary ots JOIN runs rl ON ots.linear_run_id = rl.run_id JOIN runs ra ON ots.agentic_run_id = ra.run_id JOIN experiments e ON ra.exp_id = e.exp_id GROUP BY e.group_id """) if not _tg.empty: _tax_by_group = dict(zip(_tg.group_id, _tg.mt)) except Exception: pass if not _sess_df.empty: for _, _sr in _sess_df.iterrows(): _ss = str(_sr.get("status","?")) _clr = {"completed":"#16a34a","running":"#3b82f6", "error":"#ef4444","failed":"#ef4444"}.get(_ss,"#d97706") _pill = (f"{_ss}") _gid = str(_sr.get("group_id") or "") _mt = _tax_by_group.get(_gid) _tax_s = f"{float(_mt):.1f}×" if _mt and str(_mt) != "nan" else "—" _short = _gid.replace("session_","")[:17] try: import datetime as _dt _ago = _dt.datetime.now() - _dt.datetime.fromisoformat( str(_sr.latest).replace("Z","")) _s = int(_ago.total_seconds()) _ts = (f"{_s//3600}h" if _s > 3600 else f"{_s//60}m" if _s > 60 else "now") except Exception: _ts = "—" _sess_real_rows.append( f"
" f"" f"{_short}" f"{_pill}" f"{_tax_s}" f"{_ts}" f"
") except Exception: pass _c3_body = _label("Recent sessions") for _row in _sess_real_rows: _c3_body += _row for _i in range(6 - len(_sess_real_rows)): _c3_body += _empty_row("no sessions yet" if _i == 0 and not _sess_real_rows else "") _c3_foot = ( f"
" f"" f"" f"
" ) # ── Render equal-height cards ────────────────────────────────────────────── col_e, col_tax, col_sess = st.columns(3) with col_e: st.markdown(_fixed_card(_c1_body, _c1_foot), unsafe_allow_html=True) with col_tax: st.markdown(_fixed_card(_c2_body, _c2_foot), unsafe_allow_html=True) with col_sess: st.markdown(_fixed_card(_c3_body, _c3_foot), unsafe_allow_html=True) st.markdown("
", unsafe_allow_html=True) # ── ROW 2: Execution Breakdown | Tax Attribution | Energy Timeline ───────── col_bd, col_attr, col_tl = st.columns(3) # ── Phase data ───────────────────────────────────────────────────────────── # Energy per phase from DB if available, else derive from time fractions plan_j = avg_age_j * (plan_pct / 100) if plan_pct > 0 else 0 exec_j = avg_age_j * (exec_pct / 100) if exec_pct > 0 else 0 synth_j = avg_age_j * (synth_pct / 100) if synth_pct > 0 else 0 total_phase_ms = max(plan_ms + exec_ms + synth_ms, 1) with col_bd: _has_phases = plan_ms > 0 _bd_content = _label("Agentic execution breakdown") if _has_phases: _bd_content += f"""
{plan_pct:.0f}%
{exec_pct:.0f}%
{synth_pct:.0f}%
""" for phase_name, ms, pct, clr in [ ("Planning", plan_ms, plan_pct, "#d97706"), ("Execution", exec_ms, exec_pct, "#3b82f6"), ("Synthesis", synth_ms, synth_pct, "#7c3aed"), ]: _bd_content += ( f"
" f"
" f"" f"{phase_name}
" f"
" f"
" f"{pct:.0f}%" f"{ms:.0f}ms
") # Energy per phase _bd_content += ( f"
" f"
Energy per phase (J)
") _max_phase_j = max(plan_j, exec_j, synth_j, 0.0001) for p_name, p_j, p_clr in [ ("Planning", plan_j, "#d97706"), ("Execution", exec_j, "#3b82f6"), ("Synthesis", synth_j, "#7c3aed"), ]: _bw = int(p_j / _max_phase_j * 80) _bd_content += ( f"
" f"
{p_name}
" f"
" f"
" f"{p_j:.2f} J" f"
") _bd_content += "
" else: _bd_content += ( f"
" f"No phase data — run agentic experiments first.
") st.markdown(_card(_bd_content, border_top_color="#3b82f6"), unsafe_allow_html=True) with col_attr: # Tax attribution card — red top _attr_content = _label("Orchestration tax attribution") _attr_content += ( f"
" f"Where the extra cost originates
") _total_attr_ms = max(plan_ms + exec_ms + synth_ms, 1) _base_ms = max(_total_attr_ms * 0.14, 1) # ~14% base compute for _aname, _ams, _aj, _aclr in [ ("Planning latency", plan_ms, plan_j, "#d97706"), ("Tool API latency", exec_ms, exec_j, "#3b82f6"), ("Synthesis / other",synth_ms, synth_j, "#7c3aed"), ("LLM base compute", _base_ms, avg_lin_j, t["bg3"]), ]: _aw = int(_ams / (_total_attr_ms + _base_ms) * 90) _attr_content += ( f"
" f"
" f"" f"{_aname}" f"" f"{_ams:.0f}ms · {_aj:.2f}J
" f"
" f"
" f"
") _overhead_pct = (tax_mult - 1) / tax_mult * 100 if tax_mult > 1 else 0 _attr_content += ( f"
" f"Avg tax {_overhead_pct:.1f}% of agentic budget" f"Tax {tax_mult:.1f}×
" f"
" f"Planning + tool latency dominate overhead. Execution cost scales with " f"task complexity; synthesis is relatively fixed.
") st.markdown(_card(_attr_content, border_top_color="#ef4444"), unsafe_allow_html=True) with col_tl: # Energy timeline — sparkline bars + phase overlay _tl_content = _label("Energy timeline — last agentic run") _tl_content += ( f"
" f"Power (W) over time with phase boundaries
") # Power sparkline: synthetic from phase data import math _bars = 72 _bar_data = [] for _bi in range(_bars): _x = _bi / _bars if _x < plan_pct/100: _pw = 1.2 + (_x/(plan_pct/100)) * 2.0 elif _x < (plan_pct + exec_pct)/100: _local = (_x - plan_pct/100)/(exec_pct/100) _pw = 3.8 + math.sin(_local * 10) * 0.6 else: _local = (_x - (plan_pct+exec_pct)/100)/(synth_pct/100 + 0.001) _pw = 3.5 - _local * 2.8 _pw = max(0.3, min(5.0, _pw)) _clr_bar = ("#d97706" if _x < plan_pct/100 else "#3b82f6" if _x < (plan_pct+exec_pct)/100 else "#7c3aed") _bar_data.append((_pw, _clr_bar)) _pw_html = ( f"
") for _pw, _bc in _bar_data: _bh = int(_pw / 5 * 44) _pw_html += ( f"
") _pw_html += "
" # Phase segments bar _pw_html += ( f"
" f"
Plan
" f"
Exec
" f"
Synth
" f"
") # Time axis _pw_html += ( f"
" f"0ms{plan_ms:.0f}ms" f"{plan_ms+exec_ms:.0f}ms" f"{total_phase_ms:.0f}ms
") # Phase legend _pw_html += f"
" for _pn, _pc in [("Planning","#d97706"),("Execution","#3b82f6"),("Synthesis","#7c3aed")]: _pw_html += ( f"" f"" f"{_pn}") _pw_html += "
" # Mini stats row _peak_w = avg_age_j / max(total_phase_ms/1000, 0.001) _mean_w = _peak_w * 0.55 _pw_html += ( f"
" f"
Peak power
" f"
{_peak_w:.1f} W
" f"
Mean power
" f"
{_mean_w:.1f} W
" f"
Total energy
" f"
{avg_age_j:.2f} J
" f"
") _tl_content += _pw_html st.markdown(_card(_tl_content, border_top_color="#3b82f6"), unsafe_allow_html=True) st.markdown("
", unsafe_allow_html=True) # ── ROW 3: Hardware | Environment | Activity feed ───────────────────────── col_hw, col_env, col_act = st.columns(3) with col_hw: hw = q1("SELECT * FROM hardware_config ORDER BY hw_id DESC LIMIT 1") or {} gov = (str(runs["governor"].iloc[0]) if "governor" in runs.columns and not runs.empty else "—") def _hw_row(k, v, vclr=None): vc = vclr or t["t1"] return (f"
" f"{k}" f"{v}
") def _ok(v): return "#16a34a" if v else t["t3"] _hw_html = (_hw_row("CPU", hw.get("cpu_model","—")) + _hw_row("Arch", f"{hw.get('cpu_architecture','—')} · " f"{hw.get('cpu_vendor','—')} · " f"{hw.get('cpu_cores','?')}c/{hw.get('cpu_threads','?')}t") + _hw_row("RAM", f"{hw.get('ram_gb','?')} GB") + _hw_row("ISA", f"AVX2:{'✓' if hw.get('has_avx2') else '✗'} " f"AVX-512:{'✓' if hw.get('has_avx512') else '✗'} " f"VT-x:{'✓' if hw.get('has_vmx') else '✗'}") + _hw_row("RAPL", str(hw.get("rapl_domains","—"))[:30], "#16a34a") + _hw_row("GPU", hw.get("gpu_model","—") or "—") + _hw_row("System", hw.get("system_product","—") or "—") + _hw_row("Governor", gov, "#16a34a")) # Live resource bars try: import psutil as _ps _cpu_pct = _ps.cpu_percent(interval=None) _ram_pct = _ps.virtual_memory().percent _temps = _ps.sensors_temperatures() if hasattr(_ps, "sensors_temperatures") else {} _temp_c = 0 for _tn in ("coretemp","cpu_thermal","k10temp"): if _tn in _temps and _temps[_tn]: _temp_c = _temps[_tn][0].current; break except Exception: _cpu_pct, _ram_pct, _temp_c = 0, 0, 0 _hw_html += f"
" _hw_html += (f"
" f"Live resource usage
") for _rn, _rv, _rc in [ ("CPU", _cpu_pct, "#3b82f6"), ("RAM", _ram_pct, "#7c3aed"), ("Temp", _temp_c, "#d97706" if _temp_c > 70 else "#3b82f6"), ]: _rw = min(int(_rv), 100) _hw_html += ( f"
" f"{_rn}" f"
" f"
" f"
" f"" f"{'°C' and f'{_rv:.0f}°C' if _rn == 'Temp' else f'{_rv:.0f}%'}
") _hw_html += "
" st.markdown(_card( f"{_label('Hardware · ' + str(hw.get('hostname','—')))}{_hw_html}", border_top_color="#3b82f6"), unsafe_allow_html=True) with col_env: env = q1("SELECT * FROM environment_config ORDER BY env_id DESC LIMIT 1") or {} def _env_row(k, v, vclr=None): vc = vclr or t["t1"] return (f"
" f"{k}" f"{v}
") _dirty_clr = "#d97706" if env.get("git_dirty") else "#16a34a" _dirty_lbl = "yes — uncommitted" if env.get("git_dirty") else "clean" _env_html = ( _env_row("Python", f"{env.get('python_version','—')} · {env.get('python_implementation','—')}") + _env_row("OS", f"{env.get('os_name','—')} {env.get('kernel_version','—')}"[:32]) + _env_row("LLM", env.get("llm_framework","—") or "—") + _env_row("Framework", env.get("framework_version","—") or "—") + _env_row("NumPy", env.get("numpy_version","—") or "—") + _env_row("Torch", env.get("torch_version","—") or "not installed", t["t3"]) + _env_row("Branch", env.get("git_branch","—") or "—") + _env_row("Commit", str(env.get("git_commit","—") or "—")[:12]) + _env_row("Dirty", _dirty_lbl, _dirty_clr)) _hw_hash = str(hw.get("hardware_hash","") or "")[:12] _env_hash = str(env.get("env_hash","") or "")[:12] _fp = f"{_hw_hash}:{_env_hash}" if _hw_hash and _env_hash else "—" _env_html += ( f"
" f"Fingerprint {_fp}
" f"
" f"Share to reproduce on identical hardware + software. Full details in PDF Appendix A+B.
") st.markdown(_card( f"{_label('Software environment')}{_env_html}", border_top_color="#7c3aed"), unsafe_allow_html=True) with col_act: # Activity feed from recent events _act_html = "" try: _act_df, _ = q_safe(""" SELECT e.group_id, e.task_name, e.model_name, e.status, e.completed_at, e.started_at, e.error_message, e.runs_completed, e.runs_total FROM experiments e ORDER BY e.exp_id DESC LIMIT 8 """) if not _act_df.empty: for _, _ar in _act_df.iterrows(): _astat = str(_ar.get("status","?")) _aclr = {"completed":"#16a34a","running":"#3b82f6", "error":"#ef4444","failed":"#ef4444"}.get(_astat,"#d97706") _atask = str(_ar.get("task_name","?")) _amod = str(_ar.get("model_name","?") or "")[:16] _aerr = str(_ar.get("error_message","") or "") try: import datetime as _dt _ats = str(_ar.get("completed_at") or _ar.get("started_at") or "") _ago = _dt.datetime.now() - _dt.datetime.fromisoformat( _ats.replace("Z","")) _s = int(_ago.total_seconds()) _ts = (f"{_s//3600}h ago" if _s > 3600 else f"{_s//60}m ago" if _s > 60 else "now") except Exception: _ts = "—" _body = (f"{_atask} · {_amod}" if _astat != "error" else f"Failed · {_aerr[:40]}") _act_html += ( f"
" f"
" f"
{_body}
" f"
{_ts}
" f"
") except Exception: pass if not _act_html: _act_html = f"
No activity yet
" st.markdown(_card( f"{_label('Activity feed')}{_act_html}", border_top_color="#16a34a"), unsafe_allow_html=True) st.markdown("
", unsafe_allow_html=True) # ── ROW 4: Duration vs Energy + IPC vs Cache Miss (original, themed) ─────── if not runs.empty and "energy_j" in runs.columns: col_sc1, col_sc2 = st.columns(2) _pl_layout = dict( paper_bgcolor=t["bg1"], plot_bgcolor=t["bg2"], font=dict(color=t["t1"], size=10), margin=dict(t=10, b=40, l=50, r=10), legend=dict(bgcolor=t["bg1"], bordercolor=t["brd"], borderwidth=0.5, font=dict(color=t["t2"]))) with col_sc1: st.markdown( f"
Duration vs Energy — all runs
", unsafe_allow_html=True) _df = runs.dropna(subset=["energy_j","duration_ms"]).copy() _df["duration_s"] = _df["duration_ms"] / 1000 fig = px.scatter(_df, x="duration_s", y="energy_j", color="workflow_type", color_discrete_map=WF_COLORS, hover_data=["run_id","provider","task_name"], labels={"duration_s":"Duration (s)","energy_j":"Energy (J)"}) fig.update_layout(**_pl_layout) st.plotly_chart(fl(fig), use_container_width=True) with col_sc2: st.markdown( f"
IPC vs Cache Miss
", unsafe_allow_html=True) _df2 = runs.dropna(subset=["ipc","cache_miss_rate"]).copy() _df2["cache_miss_pct"] = _df2["cache_miss_rate"] * 100 fig2 = px.scatter(_df2, x="cache_miss_pct", y="ipc", color="workflow_type", color_discrete_map=WF_COLORS, hover_data=["run_id","provider"], labels={"cache_miss_pct":"Cache Miss %","ipc":"IPC"}) fig2.update_layout(**_pl_layout) st.plotly_chart(fl(fig2), use_container_width=True)