Skip to content

Commit 4ac360e

Browse files
committed
fix issues with metric weight flicker
1 parent b8dbad9 commit 4ac360e

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

ml_peg/app/utils/register_callbacks.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ def register_tab_table_callbacks(table_id) -> None:
7373
Output(table_id, "data"),
7474
Output(table_id, "style_data_conditional"),
7575
Input(f"{table_id}-weight-store", "data"),
76+
Input("all-tabs", "value"),
7677
State(table_id, "data"),
77-
prevent_initial_call=True,
78+
prevent_initial_call="initial_duplicate",
7879
)
7980
def update_table_scores(
80-
stored_weights: dict[str, float], table_data: list[dict]
81+
stored_weights: dict[str, float], tabs_value: str, table_data: list[dict]
8182
) -> list[dict]:
8283
"""
8384
Update scores table score and rankings when data store updates.
@@ -86,6 +87,8 @@ def update_table_scores(
8687
----------
8788
stored_weights
8889
Stored weight values for `table_id`.
90+
tabs_value
91+
Selected tab value (unused; triggers recompute on tab change).
8992
table_data
9093
Data from `table_id` to be updated.
9194
@@ -157,12 +160,16 @@ def register_benchmark_to_category_callback(
157160
@callback(
158161
Output(category_table_id, "data", allow_duplicate=True),
159162
Output(category_table_id, "style_data_conditional", allow_duplicate=True),
160-
Input(benchmark_table_id, "data"),
163+
Input(f"{benchmark_table_id}-weight-store", "data"),
164+
Input("all-tabs", "value"),
165+
State(benchmark_table_id, "data"),
161166
State(category_table_id, "data"),
162167
State(f"{category_table_id}-weight-store", "data"),
163168
prevent_initial_call="initial_duplicate",
164169
)
165170
def update_category_from_benchmark(
171+
benchmark_weights: dict[str, float] | None,
172+
tabs_value: str,
166173
benchmark_data: list[dict],
167174
category_data: list[dict],
168175
category_weights: dict[str, float] | None,
@@ -172,8 +179,12 @@ def update_category_from_benchmark(
172179
173180
Parameters
174181
----------
182+
benchmark_weights
183+
Metric weight mapping for the benchmark table.
184+
tabs_value
185+
Selected tab value (unused; triggers recompute on tab switch).
175186
benchmark_data
176-
Rows from the benchmark table containing per-MLIP scores.
187+
Rows from the benchmark table containing metric columns and Score.
177188
category_data
178189
Current rows for the category summary table.
179190
category_weights
@@ -184,11 +195,14 @@ def update_category_from_benchmark(
184195
list[dict]
185196
Updated category table data and style tuple.
186197
"""
187-
if not benchmark_data or not category_data:
198+
# Only handle metric-weight updates; ignore tab-change mounts/renders
199+
if ctx.triggered_id != f"{benchmark_table_id}-weight-store":
188200
raise PreventUpdate
189201

190-
# Map MLIP -> Score from benchmark table
191-
benchmark_scores = {row["MLIP"]: row.get("Score") for row in benchmark_data}
202+
# Compute MLIP -> Score using latest metric weights for deterministic update
203+
b_weights = benchmark_weights if benchmark_weights else {}
204+
recomputed = calc_scores([row.copy() for row in benchmark_data], b_weights)
205+
benchmark_scores = {row["MLIP"]: row.get("Score") for row in recomputed}
192206

193207
# Inject into the appropriate column for each MLIP
194208
for row in category_data:

0 commit comments

Comments
 (0)