hchevva commited on
Commit
f10100d
·
verified ·
1 Parent(s): 7147dfc

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +58 -14
  2. requirements.txt +2 -1
app.py CHANGED
@@ -13,7 +13,12 @@ from quread.llm_explain_openai import explain_with_gpt4o
13
  from quread.circuit_diagram import draw_circuit_svg
14
  from quread.cost_guard import allow_request
15
  from quread.export_pdf import md_to_pdf
16
- from quread.heatmap import make_metric_heatmap, HeatmapConfig
 
 
 
 
 
17
  from quread.metrics import (
18
  compute_metrics_from_csv,
19
  to_metrics_csv,
@@ -467,6 +472,11 @@ with gr.Blocks(theme=theme, css=CSS, title="Quread.ai — State Vector Studio")
467
  value="activity_count",
468
  label="Metric",
469
  )
 
 
 
 
 
470
  chip_rows = gr.Slider(2, 64, value=8, step=1, label="Chip rows")
471
  chip_cols = gr.Slider(2, 64, value=8, step=1, label="Chip cols")
472
  metric_threshold = gr.Slider(
@@ -659,6 +669,7 @@ with gr.Blocks(theme=theme, css=CSS, title="Quread.ai — State Vector Studio")
659
  rows,
660
  cols,
661
  metric,
 
662
  calibration_text,
663
  activity_w,
664
  gate_error_w,
@@ -670,7 +681,7 @@ with gr.Blocks(theme=theme, css=CSS, title="Quread.ai — State Vector Studio")
670
  metric_thr,
671
  focus_qubit,
672
  top_k,
673
- ):
674
  csv_text = to_csv(qc.history) # must exist from Task 2A
675
  cfg = HeatmapConfig(rows=int(rows), cols=int(cols))
676
  weights, thresholds = _metric_controls_to_models(
@@ -682,17 +693,49 @@ with gr.Blocks(theme=theme, css=CSS, title="Quread.ai — State Vector Studio")
682
  warning_thr,
683
  critical_thr,
684
  )
685
- fig = make_metric_heatmap(
686
- csv_text=csv_text,
687
- n_qubits=int(n_qubits),
688
- metric=str(metric),
689
- cfg=cfg,
690
- calibration_json=str(calibration_text or ""),
691
- state_vector=np.asarray(qc.state, dtype=complex),
692
- weights=weights,
693
- thresholds=thresholds,
694
- highlight_threshold=(None if float(metric_thr) <= 0 else float(metric_thr)),
695
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
696
  metrics, meta = compute_metrics_from_csv(
697
  csv_text,
698
  int(n_qubits),
@@ -702,7 +745,7 @@ with gr.Blocks(theme=theme, css=CSS, title="Quread.ai — State Vector Studio")
702
  thresholds=thresholds,
703
  )
704
  hotspot_rows = _hotspot_rows(metrics, int(n_qubits), int(top_k))
705
- note = []
706
  skipped = int(meta.get("skipped_rows", 0))
707
  if skipped:
708
  note.append(f"Skipped malformed CSV rows: {skipped}")
@@ -757,6 +800,7 @@ with gr.Blocks(theme=theme, css=CSS, title="Quread.ai — State Vector Studio")
757
  chip_rows,
758
  chip_cols,
759
  heat_metric,
 
760
  calibration_json,
761
  w_activity,
762
  w_gate,
 
13
  from quread.circuit_diagram import draw_circuit_svg
14
  from quread.cost_guard import allow_request
15
  from quread.export_pdf import md_to_pdf
16
+ from quread.heatmap import (
17
+ make_metric_heatmap,
18
+ make_metric_heatmap_plotly,
19
+ plotly_available,
20
+ HeatmapConfig,
21
+ )
22
  from quread.metrics import (
23
  compute_metrics_from_csv,
24
  to_metrics_csv,
 
472
  value="activity_count",
473
  label="Metric",
474
  )
475
+ heat_render_mode = gr.Dropdown(
476
+ choices=["interactive", "static"],
477
+ value="interactive",
478
+ label="Render mode",
479
+ )
480
  chip_rows = gr.Slider(2, 64, value=8, step=1, label="Chip rows")
481
  chip_cols = gr.Slider(2, 64, value=8, step=1, label="Chip cols")
482
  metric_threshold = gr.Slider(
 
669
  rows,
670
  cols,
671
  metric,
672
+ render_mode,
673
  calibration_text,
674
  activity_w,
675
  gate_error_w,
 
681
  metric_thr,
682
  focus_qubit,
683
  top_k,
684
+ ):
685
  csv_text = to_csv(qc.history) # must exist from Task 2A
686
  cfg = HeatmapConfig(rows=int(rows), cols=int(cols))
687
  weights, thresholds = _metric_controls_to_models(
 
693
  warning_thr,
694
  critical_thr,
695
  )
696
+ threshold_value = None if float(metric_thr) <= 0 else float(metric_thr)
697
+ render_choice = str(render_mode or "interactive").strip().lower()
698
+ notes = []
699
+
700
+ if render_choice == "interactive":
701
+ if plotly_available():
702
+ fig = make_metric_heatmap_plotly(
703
+ csv_text=csv_text,
704
+ n_qubits=int(n_qubits),
705
+ metric=str(metric),
706
+ cfg=cfg,
707
+ calibration_json=str(calibration_text or ""),
708
+ state_vector=np.asarray(qc.state, dtype=complex),
709
+ weights=weights,
710
+ thresholds=thresholds,
711
+ highlight_threshold=threshold_value,
712
+ )
713
+ else:
714
+ fig = make_metric_heatmap(
715
+ csv_text=csv_text,
716
+ n_qubits=int(n_qubits),
717
+ metric=str(metric),
718
+ cfg=cfg,
719
+ calibration_json=str(calibration_text or ""),
720
+ state_vector=np.asarray(qc.state, dtype=complex),
721
+ weights=weights,
722
+ thresholds=thresholds,
723
+ highlight_threshold=threshold_value,
724
+ )
725
+ notes.append("Plotly unavailable in this runtime; using static heatmap.")
726
+ else:
727
+ fig = make_metric_heatmap(
728
+ csv_text=csv_text,
729
+ n_qubits=int(n_qubits),
730
+ metric=str(metric),
731
+ cfg=cfg,
732
+ calibration_json=str(calibration_text or ""),
733
+ state_vector=np.asarray(qc.state, dtype=complex),
734
+ weights=weights,
735
+ thresholds=thresholds,
736
+ highlight_threshold=threshold_value,
737
+ )
738
+
739
  metrics, meta = compute_metrics_from_csv(
740
  csv_text,
741
  int(n_qubits),
 
745
  thresholds=thresholds,
746
  )
747
  hotspot_rows = _hotspot_rows(metrics, int(n_qubits), int(top_k))
748
+ note = notes
749
  skipped = int(meta.get("skipped_rows", 0))
750
  if skipped:
751
  note.append(f"Skipped malformed CSV rows: {skipped}")
 
800
  chip_rows,
801
  chip_cols,
802
  heat_metric,
803
+ heat_render_mode,
804
  calibration_json,
805
  w_activity,
806
  w_gate,
requirements.txt CHANGED
@@ -1,6 +1,7 @@
1
  gradio>=4.0.0
2
  numpy
3
  matplotlib
 
4
  requests
5
  huggingface_hub>=0.30.0
6
  transformers==4.45.2
@@ -9,4 +10,4 @@ optimum[onnxruntime]>=1.20.0
9
  onnxruntime>=1.17.0
10
  openai>=1.0.0
11
  markdown
12
- reportlab
 
1
  gradio>=4.0.0
2
  numpy
3
  matplotlib
4
+ plotly>=5.0.0
5
  requests
6
  huggingface_hub>=0.30.0
7
  transformers==4.45.2
 
10
  onnxruntime>=1.17.0
11
  openai>=1.0.0
12
  markdown
13
+ reportlab