TheYuchen commited on
Commit
a892a99
·
1 Parent(s): 7fa375a

Wave I: re-record bell demo records under batched draw scheme

Browse files

The Wave I per-batch seed schedule makes pre-Wave-I sampled records
non-replayable (a single 2048-shot draw != 8 seeded 256-shot draws).
Re-recorded all 14 bell_state demo records (512 + 2048, incl. the
same-seed replay pair) against the live API via the resumable script;
each now carries the per-batch trace and replays bit-exact. The 3
vqc_2q_small (QuCAD) records still carry old-scheme numbers — the
loader degrades gracefully (omits the funnel, keeps the CI bar);
finish them with scripts/rerecord_demo_archive.py on an idle Space.
Doc: migration status + live regression numbers recorded.

docs/EVIDENCE_WORKBENCH.md CHANGED
@@ -169,7 +169,19 @@ test_gate_diff 14, test_workflow_helpers 11, test_seed_coverage 8).
169
  2048-shot draw with the node seed is a different random variable
170
  than 8 seeded 256-shot draws — the bundled demo archive was
171
  re-recorded against the live Space (scripts/rerecord_demo_archive
172
- .py preserves run_ids/lineage/created_at, swaps responses).
 
 
 
 
 
 
 
 
 
 
 
 
173
  20. **SSE progress protocol** — during a sampled step the stream
174
  interleaves `{"step_progress": {node_id, batch_i, n_batches,
175
  shots_done, successes, point, ci95}}` events between StepResults
@@ -225,6 +237,19 @@ a bit-exact PREFIX of the full run's trace, min-2-batches guard,
225
  1/√n narrowing, stream-vs-eager bit-equality, pipeline-level
226
  early-stop replay).
227
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
  ## Not done yet (ordered backlog)
229
 
230
  * **Phase 3.5 leftovers** — pick-which-fidelity-node in comparison,
 
169
  2048-shot draw with the node seed is a different random variable
170
  than 8 seeded 256-shot draws — the bundled demo archive was
171
  re-recorded against the live Space (scripts/rerecord_demo_archive
172
+ .py preserves run_ids/lineage/created_at, swaps responses;
173
+ RESUMABLE — walks records, caching each via the pinned step cache,
174
+ exits on a per-record timeout so the sandbox's ~40 s process cap
175
+ can't truncate a long batch). Migration status at this commit:
176
+ 14/17 done (all bell_state 512+2048, the same-seed replay pair);
177
+ the 3 vqc_2q_small records (QuCAD → sampled) still carry the old
178
+ single-draw numbers — their sampled step lacks `trace`, so the
179
+ loader simply omits the funnel and keeps the CI bar (verified
180
+ graceful). Finish them with the script when the Space is idle:
181
+ QuCAD's per-request noise-model build outlives a 40 s client
182
+ window, so it needs an uninterrupted long-lived request. This is
183
+ demo scaffolding, not a feature dependency — the live-run
184
+ assertions below hold on the deployed build regardless.
185
  20. **SSE progress protocol** — during a sampled step the stream
186
  interleaves `{"step_progress": {node_id, batch_i, n_batches,
187
  shots_done, successes, point, ci95}}` events between StepResults
 
237
  1/√n narrowing, stream-vs-eager bit-equality, pipeline-level
238
  early-stop replay).
239
 
240
+ Live regression (deployed build, bell_state on FakeFez): a streamed
241
+ 2048-shot run with no target delivered 8 step_progress frames arriving
242
+ BEFORE the fidelity StepResult (widths 0.122→0.086→0.070→… narrowing
243
+ monotonically across batches, ~14 s apart while sampling), final
244
+ distribution.shots == 2048, trace length 8; the replayed record's
245
+ per-batch (shots_done, successes) matched the live frames bit-for-bit
246
+ [(256,125),(512,255),(768,375),…]. A precision_target=0.05 run stopped
247
+ at 512/2048 shots (2/8 batches, half-width 0.0430 ≤ 0.05, point
248
+ 0.4648); its pinned replay AND an independent recomputation under a
249
+ 0.048 target both reproduced point 0.4648 / 238 successes / 512 shots
250
+ and the identical batch trace — optional stopping is bit-exactly
251
+ replayable.
252
+
253
  ## Not done yet (ordered backlog)
254
 
255
  * **Phase 3.5 leftovers** — pick-which-fidelity-node in comparison,
frontend/src/data/demoArchive.json CHANGED
The diff for this file is too large to render. See raw diff
 
scripts/rerecord_demo_archive.py CHANGED
@@ -18,6 +18,15 @@ Replaced: steps, ok, final_metrics, app_version. Same-seed replay
18
  pairs keep their defining property automatically — same seed, same
19
  batched draws.
20
 
 
 
 
 
 
 
 
 
 
21
  Usage: python3 scripts/rerecord_demo_archive.py [base_url]
22
  (default base_url: https://jqub21-quaim.hf.space)
23
  """
@@ -37,30 +46,36 @@ ARCHIVE = (
37
  )
38
 
39
 
40
- def _post(path: str, payload: dict | None = None, timeout: float = 240) -> dict:
41
  req = urllib.request.Request(
42
  f"{BASE}{path}",
43
  data=json.dumps(payload).encode() if payload is not None else b"",
44
  headers={"Content-Type": "application/json"},
45
  method="POST",
46
  )
47
- with urllib.request.urlopen(req, timeout=timeout) as r:
48
- return json.loads(r.read())
 
 
49
 
50
 
51
  def main() -> None:
52
  entries = json.loads(ARCHIVE.read_text())
53
  t_start = time.time()
 
54
  # One circuit handle per sample key is enough — the server store
55
  # is content-addressed per upload, and runs only need a valid id.
56
  circuit_ids: dict[str, str] = {}
57
  for idx, rec in enumerate(entries):
 
 
58
  resp = rec["response"]
59
  root_seed = resp["root_seed"]
60
  assert root_seed is not None, f"record {idx} has no root seed"
61
  sk = rec["sampleKey"]
62
  if sk not in circuit_ids:
63
- circuit_ids[sk] = _post(f"/api/circuits/samples/{sk}")["circuit_id"]
 
64
  body = {
65
  "circuit_id": circuit_ids[sk],
66
  "nodes": [
@@ -73,13 +88,24 @@ def main() -> None:
73
  "use_live_ibm": False,
74
  "seed": int(root_seed),
75
  }
76
- new = _post("/api/workflow/run", body)
 
 
 
 
 
 
 
 
 
77
  assert new["ok"], f"record {idx} re-ran with errors: {new['steps']}"
78
  assert new["root_seed"] == root_seed and new["seed_mode"] == "pinned"
79
  resp["steps"] = new["steps"]
80
  resp["ok"] = new["ok"]
81
  resp["final_metrics"] = new["final_metrics"]
82
  resp["app_version"] = new["app_version"]
 
 
83
  # run_id / circuit_id deliberately NOT taken from `new` — see
84
  # module docstring (lineage edges reference the old run_ids).
85
  print(
@@ -87,8 +113,7 @@ def main() -> None:
87
  f"ok={new['ok']} ({time.time() - t_start:.1f}s elapsed)",
88
  flush=True,
89
  )
90
- ARCHIVE.write_text(json.dumps(entries, separators=(",", ":")))
91
- print(f"wrote {ARCHIVE} ({ARCHIVE.stat().st_size} bytes)")
92
 
93
 
94
  if __name__ == "__main__":
 
18
  pairs keep their defining property automatically — same seed, same
19
  batched draws.
20
 
21
+ RESUMABLE by design: every record is seed-pinned, so the server's
22
+ pinned step cache makes a re-request of an already-computed record
23
+ instant. The script walks records in order, updating the archive file
24
+ and a state file after each success; on a per-record timeout it exits
25
+ (the fired request keeps computing server-side) and the next
26
+ invocation picks up where it left off — run it repeatedly until it
27
+ prints ALL DONE. This shape exists because the dev sandbox caps any
28
+ one process at ~40 s.
29
+
30
  Usage: python3 scripts/rerecord_demo_archive.py [base_url]
31
  (default base_url: https://jqub21-quaim.hf.space)
32
  """
 
46
  )
47
 
48
 
49
+ def _post(path: str, payload: dict | None = None, timeout: float = 240):
50
  req = urllib.request.Request(
51
  f"{BASE}{path}",
52
  data=json.dumps(payload).encode() if payload is not None else b"",
53
  headers={"Content-Type": "application/json"},
54
  method="POST",
55
  )
56
+ return urllib.request.urlopen(req, timeout=timeout)
57
+
58
+
59
+ STATE = Path("/tmp/rerecord_state.json")
60
 
61
 
62
  def main() -> None:
63
  entries = json.loads(ARCHIVE.read_text())
64
  t_start = time.time()
65
+ start = json.loads(STATE.read_text())["done"] if STATE.exists() else 0
66
  # One circuit handle per sample key is enough — the server store
67
  # is content-addressed per upload, and runs only need a valid id.
68
  circuit_ids: dict[str, str] = {}
69
  for idx, rec in enumerate(entries):
70
+ if idx < start:
71
+ continue
72
  resp = rec["response"]
73
  root_seed = resp["root_seed"]
74
  assert root_seed is not None, f"record {idx} has no root seed"
75
  sk = rec["sampleKey"]
76
  if sk not in circuit_ids:
77
+ with _post(f"/api/circuits/samples/{sk}", timeout=30) as r:
78
+ circuit_ids[sk] = json.loads(r.read())["circuit_id"]
79
  body = {
80
  "circuit_id": circuit_ids[sk],
81
  "nodes": [
 
88
  "use_live_ibm": False,
89
  "seed": int(root_seed),
90
  }
91
+ try:
92
+ with _post("/api/workflow/run", body, timeout=42) as r:
93
+ new = json.loads(r.read())
94
+ except Exception as exc: # fired; server keeps computing + caches
95
+ print(
96
+ f"[{idx + 1}/{len(entries)}] {sk} pending "
97
+ f"({type(exc).__name__}) — re-run the script to resume",
98
+ flush=True,
99
+ )
100
+ return
101
  assert new["ok"], f"record {idx} re-ran with errors: {new['steps']}"
102
  assert new["root_seed"] == root_seed and new["seed_mode"] == "pinned"
103
  resp["steps"] = new["steps"]
104
  resp["ok"] = new["ok"]
105
  resp["final_metrics"] = new["final_metrics"]
106
  resp["app_version"] = new["app_version"]
107
+ ARCHIVE.write_text(json.dumps(entries, separators=(",", ":")))
108
+ STATE.write_text(json.dumps({"done": idx + 1}))
109
  # run_id / circuit_id deliberately NOT taken from `new` — see
110
  # module docstring (lineage edges reference the old run_ids).
111
  print(
 
113
  f"ok={new['ok']} ({time.time() - t_start:.1f}s elapsed)",
114
  flush=True,
115
  )
116
+ print(f"ALL DONE — wrote {ARCHIVE} ({ARCHIVE.stat().st_size} bytes)")
 
117
 
118
 
119
  if __name__ == "__main__":