Laborator commited on
Commit
b3e83ce
·
verified ·
1 Parent(s): 1493021

deploy: sync from qverify d3b1f83

Browse files
Files changed (4) hide show
  1. README.md +7 -0
  2. app.py +22 -0
  3. data/hardware_runs.json +164 -0
  4. gallery.py +124 -0
README.md CHANGED
@@ -54,6 +54,13 @@ IBM hardware credit is shared across all users on the Open Plan
54
  (approximately 10 minutes of quantum time per month total). The simulator
55
  path runs locally in the Space container and has no external cost.
56
 
 
 
 
 
 
 
 
57
  ## What is not in this Space
58
 
59
  The translator — Gemma 4 E4B with grammar-constrained generation — converts
 
54
  (approximately 10 minutes of quantum time per month total). The simulator
55
  path runs locally in the Space container and has no external cost.
56
 
57
+ A **Verified on IBM Quantum Hardware** gallery further down the page lists past
58
+ Grover verification runs executed on Heron r2 devices (`ibm_fez`,
59
+ `ibm_kingston`), each with its Job ID linked to the public IBM Quantum
60
+ Workloads dashboard so anyone can confirm it. Two runs are featured with their
61
+ full CNF, mode, verdict, and measured counts; the remainder are listed as
62
+ verified runs with backend, date, shots, and circuit depth.
63
+
64
  ## What is not in this Space
65
 
66
  The translator — Gemma 4 E4B with grammar-constrained generation — converts
app.py CHANGED
@@ -657,6 +657,26 @@ The JSON above is the verifier's full output. Reading it:
657
  """
658
 
659
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
660
  with gr.Blocks(title="QVerify · Quantum Logic Verifier") as demo:
661
  gr.HTML(_HERO_HTML)
662
  gr.Markdown(_INTRO_MD)
@@ -770,6 +790,8 @@ with gr.Blocks(title="QVerify · Quantum Logic Verifier") as demo:
770
  " for methodology.\n\n" + _load_benchmark_summaries()
771
  )
772
  gr.Markdown("---")
 
 
773
  gr.Markdown(
774
  "### About\n\n"
775
  "**This Space demos the verifier component of QVerify.** A CNF "
 
657
  """
658
 
659
 
660
+ def _render_gallery_md() -> str:
661
+ """Render the IBM hardware gallery as Markdown.
662
+
663
+ Loaded by file path (like safety.py) because gallery.py sits at the Space
664
+ root on Hugging Face but under space/ locally; a plain ``import gallery``
665
+ would not resolve in both layouts.
666
+ """
667
+ import importlib.util as _ilu
668
+
669
+ here = Path(__file__).resolve().parent
670
+ for candidate in (here / "gallery.py", here / "space" / "gallery.py"):
671
+ if candidate.exists():
672
+ spec = _ilu.spec_from_file_location("_qv_gallery", candidate)
673
+ assert spec is not None and spec.loader is not None
674
+ module = _ilu.module_from_spec(spec)
675
+ spec.loader.exec_module(module)
676
+ return str(module.render_gallery())
677
+ return "## Verified on IBM Quantum Hardware\n\n_Gallery data unavailable._\n"
678
+
679
+
680
  with gr.Blocks(title="QVerify · Quantum Logic Verifier") as demo:
681
  gr.HTML(_HERO_HTML)
682
  gr.Markdown(_INTRO_MD)
 
790
  " for methodology.\n\n" + _load_benchmark_summaries()
791
  )
792
  gr.Markdown("---")
793
+ gr.Markdown(_render_gallery_md())
794
+ gr.Markdown("---")
795
  gr.Markdown(
796
  "### About\n\n"
797
  "**This Space demos the verifier component of QVerify.** A CNF "
data/hardware_runs.json ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "job_id": "d7sd2aiudops7396mu40",
4
+ "backend": "ibm_fez",
5
+ "date": "2026-05-04",
6
+ "shots": 1024,
7
+ "depth": 112,
8
+ "atoms": 2,
9
+ "tier": "verified"
10
+ },
11
+ {
12
+ "job_id": "d7qifecf3ras73b5r7g0",
13
+ "backend": "ibm_fez",
14
+ "date": "2026-05-02",
15
+ "shots": 1024,
16
+ "depth": 122,
17
+ "atoms": 2,
18
+ "tier": "verified"
19
+ },
20
+ {
21
+ "job_id": "d7q9fl43lfgs73fgthc0",
22
+ "backend": "ibm_fez",
23
+ "date": "2026-05-01",
24
+ "shots": 1024,
25
+ "depth": 357,
26
+ "atoms": 2,
27
+ "tier": "verified"
28
+ },
29
+ {
30
+ "job_id": "d7q961poagoc73fj6oag",
31
+ "backend": "ibm_fez",
32
+ "date": "2026-05-01",
33
+ "shots": 1024,
34
+ "depth": 360,
35
+ "atoms": 2,
36
+ "tier": "featured",
37
+ "cnf": "(P ∨ Q) ∧ (¬P ∨ Q)",
38
+ "mode": "consistency",
39
+ "verdict": "consistent",
40
+ "notes": "Saturated formula (3/4 satisfying): the histogram is near-uniform, so the classical post-check walks past the top bitstring to a satisfier at rank #2.",
41
+ "counts_top": [
42
+ [
43
+ "00",
44
+ 292
45
+ ],
46
+ [
47
+ "01",
48
+ 263
49
+ ],
50
+ [
51
+ "11",
52
+ 254
53
+ ]
54
+ ]
55
+ },
56
+ {
57
+ "job_id": "d7p1tu6dvl0c738oflbg",
58
+ "backend": "ibm_kingston",
59
+ "date": "2026-04-29",
60
+ "shots": 1024,
61
+ "depth": 109,
62
+ "atoms": 2,
63
+ "tier": "verified"
64
+ },
65
+ {
66
+ "job_id": "d7p1qlj9ak2c739r6dr0",
67
+ "backend": "ibm_kingston",
68
+ "date": "2026-04-29",
69
+ "shots": 1024,
70
+ "depth": 117,
71
+ "atoms": 2,
72
+ "tier": "verified"
73
+ },
74
+ {
75
+ "job_id": "d7p1ifj9ak2c739r63i0",
76
+ "backend": "ibm_kingston",
77
+ "date": "2026-04-29",
78
+ "shots": 1024,
79
+ "depth": 111,
80
+ "atoms": 2,
81
+ "tier": "verified"
82
+ },
83
+ {
84
+ "job_id": "d7p1georor3c73c0jf3g",
85
+ "backend": "ibm_kingston",
86
+ "date": "2026-04-29",
87
+ "shots": 1024,
88
+ "depth": 101,
89
+ "atoms": 2,
90
+ "tier": "verified"
91
+ },
92
+ {
93
+ "job_id": "d7p0h4gror3c73c0i240",
94
+ "backend": "ibm_kingston",
95
+ "date": "2026-04-29",
96
+ "shots": 1024,
97
+ "depth": 109,
98
+ "atoms": 2,
99
+ "tier": "verified"
100
+ },
101
+ {
102
+ "job_id": "d7ouncj9ak2c739r27ng",
103
+ "backend": "ibm_kingston",
104
+ "date": "2026-04-29",
105
+ "shots": 1024,
106
+ "depth": 112,
107
+ "atoms": 2,
108
+ "tier": "verified"
109
+ },
110
+ {
111
+ "job_id": "d7ou7bm0b9ts73cisnog",
112
+ "backend": "ibm_fez",
113
+ "date": "2026-04-29",
114
+ "shots": 1024,
115
+ "depth": 106,
116
+ "atoms": 2,
117
+ "tier": "verified"
118
+ },
119
+ {
120
+ "job_id": "d7otdj39ak2c739r0lr0",
121
+ "backend": "ibm_fez",
122
+ "date": "2026-04-29",
123
+ "shots": 1024,
124
+ "depth": 116,
125
+ "atoms": 2,
126
+ "tier": "verified"
127
+ },
128
+ {
129
+ "job_id": "d7o7dsqk4prs73dt4s6g",
130
+ "backend": "ibm_fez",
131
+ "date": "2026-04-28",
132
+ "shots": 1024,
133
+ "depth": 389,
134
+ "atoms": 2,
135
+ "tier": "featured",
136
+ "cnf": "(P ∨ Q) ∧ (¬P ∨ Q)",
137
+ "mode": "consistency",
138
+ "verdict": "consistent",
139
+ "notes": "First end-to-end hardware smoke test. 3 of 4 assignments satisfy; consistency mode reports no contradiction.",
140
+ "counts_top": [
141
+ [
142
+ "11",
143
+ 314
144
+ ],
145
+ [
146
+ "01",
147
+ 272
148
+ ],
149
+ [
150
+ "00",
151
+ 226
152
+ ]
153
+ ]
154
+ },
155
+ {
156
+ "job_id": "d7o74p62jamc73bpa3sg",
157
+ "backend": "ibm_fez",
158
+ "date": "2026-04-28",
159
+ "shots": 1024,
160
+ "depth": 357,
161
+ "atoms": 2,
162
+ "tier": "verified"
163
+ }
164
+ ]
gallery.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Pure rendering for the "Verified on IBM Quantum Hardware" gallery.
2
+
3
+ No Gradio and no I/O beyond :func:`load_runs`. Everything returns Markdown so
4
+ the same output renders inside ``gr.Markdown()`` in the Space and can be
5
+ exported into the README later. The single source of truth is
6
+ ``space/data/hardware_runs.json``.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import json
12
+ from pathlib import Path
13
+ from typing import Any
14
+
15
+ WORKLOADS_URL = "https://quantum.cloud.ibm.com/workloads?search="
16
+
17
+ # depth >= threshold -> "deep Grover" group; below -> "shallow".
18
+ DEEP_DEPTH_THRESHOLD = 200
19
+
20
+ _DEFAULT_DATA = Path(__file__).resolve().parent / "data" / "hardware_runs.json"
21
+
22
+
23
+ def load_runs(path: str | Path | None = None) -> list[dict[str, Any]]:
24
+ """Load gallery runs from the JSON data file.
25
+
26
+ Returns an empty list when the file is missing, unreadable, or malformed,
27
+ so the renderer can show a clean empty state instead of raising.
28
+ """
29
+ target = Path(path) if path is not None else _DEFAULT_DATA
30
+ try:
31
+ data = json.loads(target.read_text(encoding="utf-8"))
32
+ except (OSError, json.JSONDecodeError):
33
+ return []
34
+ if not isinstance(data, list):
35
+ return []
36
+ return [dict(entry) for entry in data if isinstance(entry, dict)]
37
+
38
+
39
+ def group_by_depth(runs: list[dict[str, Any]]) -> dict[str, list[dict[str, Any]]]:
40
+ """Split runs into ``deep`` and ``shallow`` Grover groups, each newest-first."""
41
+ deep = [r for r in runs if _depth(r) >= DEEP_DEPTH_THRESHOLD]
42
+ shallow = [r for r in runs if _depth(r) < DEEP_DEPTH_THRESHOLD]
43
+ deep.sort(key=lambda r: str(r.get("date", "")), reverse=True)
44
+ shallow.sort(key=lambda r: str(r.get("date", "")), reverse=True)
45
+ return {"deep": deep, "shallow": shallow}
46
+
47
+
48
+ def render_featured_card(run: dict[str, Any]) -> str:
49
+ """Render a featured run as Markdown: CNF, mode, verdict, counts, notes."""
50
+ job_id = str(run.get("job_id", ""))
51
+ counts = run.get("counts_top") or []
52
+ counts_str = " · ".join(f"`{bs}`×{n}" for bs, n in counts) if counts else "n/a"
53
+ return (
54
+ f"**`{run.get('cnf', '')}`** — {run.get('mode', '')} mode -> "
55
+ f"**{run.get('verdict', '')}** \n"
56
+ f"`{run.get('backend', '')}` · {run.get('atoms', '?')} atoms · "
57
+ f"{run.get('shots', '?')} shots · depth {run.get('depth', '?')} · "
58
+ f"{run.get('date', '')} \n"
59
+ f"Top measurements: {counts_str} \n"
60
+ f"{run.get('notes', '')} \n"
61
+ f"[Verify job `{job_id}` on IBM Quantum]({WORKLOADS_URL}{job_id})"
62
+ )
63
+
64
+
65
+ def render_verified_card(run: dict[str, Any]) -> str:
66
+ """Render a verified run as one honest line — no invented CNF or verdict."""
67
+ job_id = str(run.get("job_id", ""))
68
+ return (
69
+ f"- **Verified on hardware** — {run.get('atoms', '?')}-atom CNF · "
70
+ f"{run.get('shots', '?')} shots · depth {run.get('depth', '?')} · "
71
+ f"{run.get('date', '')} · `{run.get('backend', '')}` · "
72
+ f"[`{job_id}`]({WORKLOADS_URL}{job_id})"
73
+ )
74
+
75
+
76
+ def render_gallery(runs: list[dict[str, Any]] | None = None) -> str:
77
+ """Render the full gallery section as Markdown.
78
+
79
+ Pass ``runs`` explicitly (used by tests) or omit to load the default data
80
+ file. An empty or missing list yields a friendly empty-state message with
81
+ no broken cards.
82
+ """
83
+ if runs is None:
84
+ runs = load_runs()
85
+ if not runs:
86
+ return (
87
+ "## Verified on IBM Quantum Hardware\n\n_No verified hardware runs are recorded yet._\n"
88
+ )
89
+
90
+ groups = group_by_depth(runs)
91
+ parts: list[str] = [
92
+ "## Verified on IBM Quantum Hardware",
93
+ "",
94
+ "Every run below executed a Grover verification circuit on an IBM Heron "
95
+ "r2 processor and is publicly verifiable at the linked Job ID.",
96
+ "",
97
+ ]
98
+
99
+ for key, title in (("deep", "Deep Grover circuits"), ("shallow", "Shallow Grover circuits")):
100
+ bucket = groups[key]
101
+ if not bucket:
102
+ continue
103
+ parts.append(f"### {title} (depth {_depth_range(bucket)})")
104
+ parts.append("")
105
+ for run in bucket:
106
+ if run.get("tier") == "featured":
107
+ parts.append(render_featured_card(run))
108
+ else:
109
+ parts.append(render_verified_card(run))
110
+ parts.append("")
111
+
112
+ return "\n".join(parts).rstrip() + "\n"
113
+
114
+
115
+ def _depth(run: dict[str, Any]) -> int:
116
+ try:
117
+ return int(run.get("depth", 0))
118
+ except (TypeError, ValueError):
119
+ return 0
120
+
121
+
122
+ def _depth_range(runs: list[dict[str, Any]]) -> str:
123
+ depths = [_depth(r) for r in runs]
124
+ return f"{min(depths)}-{max(depths)}" if depths else "n/a"