QSBench commited on
Commit
f4b18e4
·
verified ·
1 Parent(s): b6043a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -4
app.py CHANGED
@@ -134,7 +134,6 @@ def enrich_dataframe(df: pd.DataFrame) -> pd.DataFrame:
134
  qasm_df = df[qasm_source].apply(qasm_features).apply(pd.Series)
135
  df = pd.concat([df, qasm_df], axis=1)
136
 
137
- # Create error targets
138
  for basis in ["Z", "X", "Y"]:
139
  ideal_col = f"ideal_expval_{basis}_global"
140
  noisy_col = f"noisy_expval_{basis}_global"
@@ -263,6 +262,49 @@ def train_regressor(
263
  return fig_z, metrics_text, fig_x, fig_y, None
264
 
265
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
  CUSTOM_CSS = """
267
  .gradio-container {
268
  max-width: 1400px !important;
@@ -277,6 +319,25 @@ with gr.Blocks(title=APP_TITLE) as demo:
277
  gr.Markdown(APP_SUBTITLE)
278
 
279
  with gr.Tabs():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
280
  with gr.TabItem("🧠 Regression Training"):
281
  feature_picker = gr.CheckboxGroup(
282
  label="Input features (circuit structure + topology)",
@@ -299,7 +360,6 @@ with gr.Blocks(title=APP_TITLE) as demo:
299
  with gr.TabItem("📖 Guide"):
300
  gr.Markdown("Guide will be added in the next step.")
301
 
302
- # Footer с твоими ссылками
303
  gr.Markdown("---")
304
  gr.Markdown(
305
  "### 🔗 Links\n"
@@ -308,20 +368,38 @@ with gr.Blocks(title=APP_TITLE) as demo:
308
  "[GitHub](https://github.com/QSBench)"
309
  )
310
 
311
- # Callbacks (те же, что раньше)
312
  def sync_features():
313
  df = load_single_dataset()
314
  features = get_available_feature_columns(df)
315
  defaults = default_feature_selection(features)
316
  return gr.update(choices=features, value=defaults)
317
 
 
 
 
 
 
 
 
 
 
 
 
 
318
  run_btn.click(
319
  train_regressor,
320
  [feature_picker, test_size, max_iter, max_depth, seed],
321
  [plot_z, metrics, plot_x, plot_y],
322
  )
323
 
324
- demo.load(sync_features, outputs=[feature_picker])
 
 
 
 
 
 
325
 
326
  if __name__ == "__main__":
327
  demo.launch(theme=gr.themes.Soft(), css=CUSTOM_CSS)
 
134
  qasm_df = df[qasm_source].apply(qasm_features).apply(pd.Series)
135
  df = pd.concat([df, qasm_df], axis=1)
136
 
 
137
  for basis in ["Z", "X", "Y"]:
138
  ideal_col = f"ideal_expval_{basis}_global"
139
  noisy_col = f"noisy_expval_{basis}_global"
 
262
  return fig_z, metrics_text, fig_x, fig_y, None
263
 
264
 
265
+ # ======================= EXPLORER FUNCTIONS =======================
266
+ def build_dataset_profile(df: pd.DataFrame) -> str:
267
+ return (
268
+ f"### Dataset profile\n\n"
269
+ f"**Rows:** {len(df):,} \n"
270
+ f"**Columns:** {len(df.columns):,} \n"
271
+ f"**Classes / Noise:** amplitude_damping"
272
+ )
273
+
274
+
275
+ def refresh_explorer(dataset_key: str, split_name: str):
276
+ df = load_single_dataset()
277
+ splits = df["split"].dropna().unique().tolist() if "split" in df.columns else ["train"]
278
+ if not splits:
279
+ splits = ["train"]
280
+ if split_name not in splits:
281
+ split_name = splits[0]
282
+
283
+ filtered = df[df["split"] == split_name] if "split" in df.columns else df
284
+ display_df = filtered.head(12).copy()
285
+
286
+ raw_qasm = display_df["qasm_raw"].iloc[0] if not display_df.empty and "qasm_raw" in display_df.columns else "// N/A"
287
+ transpiled_qasm = display_df["qasm_transpiled"].iloc[0] if not display_df.empty and "qasm_transpiled" in display_df.columns else "// N/A"
288
+
289
+ profile_box = build_dataset_profile(df)
290
+ summary_box = (
291
+ f"### Split summary\n\n"
292
+ f"**Dataset:** `{dataset_key}` \n"
293
+ f"**Label:** `amplitude_damping` \n"
294
+ f"**Available splits:** {', '.join(splits)} \n"
295
+ f"**Preview rows:** {len(display_df)}"
296
+ )
297
+
298
+ return (
299
+ gr.update(choices=splits, value=split_name),
300
+ display_df,
301
+ raw_qasm,
302
+ transpiled_qasm,
303
+ profile_box,
304
+ summary_box,
305
+ )
306
+
307
+
308
  CUSTOM_CSS = """
309
  .gradio-container {
310
  max-width: 1400px !important;
 
319
  gr.Markdown(APP_SUBTITLE)
320
 
321
  with gr.Tabs():
322
+ with gr.TabItem("🔎 Explorer"):
323
+ dataset_dropdown = gr.Dropdown(
324
+ list(REPO_CONFIG.keys()),
325
+ value="amplitude_damping",
326
+ label="Dataset",
327
+ )
328
+ split_dropdown = gr.Dropdown(
329
+ ["train"],
330
+ value="train",
331
+ label="Split",
332
+ )
333
+ profile_box = gr.Markdown(value="### Loading dataset...")
334
+ summary_box = gr.Markdown(value="### Loading split summary...")
335
+ explorer_df = gr.Dataframe(label="Preview", interactive=False)
336
+
337
+ with gr.Row():
338
+ raw_qasm = gr.Code(label="Raw QASM", language=None)
339
+ transpiled_qasm = gr.Code(label="Transpiled QASM", language=None)
340
+
341
  with gr.TabItem("🧠 Regression Training"):
342
  feature_picker = gr.CheckboxGroup(
343
  label="Input features (circuit structure + topology)",
 
360
  with gr.TabItem("📖 Guide"):
361
  gr.Markdown("Guide will be added in the next step.")
362
 
 
363
  gr.Markdown("---")
364
  gr.Markdown(
365
  "### 🔗 Links\n"
 
368
  "[GitHub](https://github.com/QSBench)"
369
  )
370
 
371
+ # ======================= CALLBACKS =======================
372
  def sync_features():
373
  df = load_single_dataset()
374
  features = get_available_feature_columns(df)
375
  defaults = default_feature_selection(features)
376
  return gr.update(choices=features, value=defaults)
377
 
378
+ dataset_dropdown.change(
379
+ refresh_explorer,
380
+ [dataset_dropdown, split_dropdown],
381
+ [split_dropdown, explorer_df, raw_qasm, transpiled_qasm, profile_box, summary_box],
382
+ )
383
+ split_dropdown.change(
384
+ refresh_explorer,
385
+ [dataset_dropdown, split_dropdown],
386
+ [split_dropdown, explorer_df, raw_qasm, transpiled_qasm, profile_box, summary_box],
387
+ )
388
+ dataset_dropdown.change(sync_features, [dataset_dropdown], [feature_picker])
389
+
390
  run_btn.click(
391
  train_regressor,
392
  [feature_picker, test_size, max_iter, max_depth, seed],
393
  [plot_z, metrics, plot_x, plot_y],
394
  )
395
 
396
+ demo.load(
397
+ refresh_explorer,
398
+ [dataset_dropdown, split_dropdown],
399
+ [split_dropdown, explorer_df, raw_qasm, transpiled_qasm, profile_box, summary_box],
400
+ )
401
+ demo.load(sync_features, [dataset_dropdown], [feature_picker])
402
+
403
 
404
  if __name__ == "__main__":
405
  demo.launch(theme=gr.themes.Soft(), css=CUSTOM_CSS)