Yuchen Yuan commited on
Commit
2316315
·
1 Parent(s): 8e6747e

Auto-connect: per-algorithm backend warnings; tour drift fixes

Browse files

Auto-connect was using a single blanket "algorithms that need a noise
model will error at run time" warning for any canvas missing a backend.
That's only true for QuCAD; QuBound and CompressVQC silently fall back
to FakeFez, and Qshot ignores ctx["backend"] entirely (uses its own
bundled noise snapshots). Replace the blanket line with per-algorithm
advisories driven by an ALGO_BACKEND_DEPENDENCY table:
- qucad: "required" (hard error without backend)
- qubound, compvqc: "optional" (soft fallback to FakeFez)
- qshot: "ignored" (warns the OTHER way: backend wired in front of a
qshot-only chain is dead weight)

Also drop the misleading "noise profile" dashed-edge label on
backend → qshot edges (the edge has no semantic meaning for qshot).
Backend → qucad/qubound/compvqc still gets the dashed sidechain
styling.

Tour slides drifted relative to the current four-algorithm lineup:
- WelcomeSlide named only QuCAD/QuBound/CompressVQC; add Qshot.
- PipelineSlide split algorithms into "mutate circuit" vs "emit metric"
but Qshot fits neither cleanly; rewrite to put Qshot's shot-count
recommendation alongside QuBound's bound and Fidelity.
- TrySlide timing copy still said "two minutes" for cold QuBound and
didn't mention Qshot warmup; align with ResultsPane (1-3 minutes,
both QuBound and Qshot). Add a fourth try-it example
(ry_chain_6q + Qshot) and surface the Auto-connect button in
"Build your own".

Add frontend/scripts/smoke_test_autoconnect.ts (15 corner cases) for
regression-eyeballing future autoConnect changes.

frontend/scripts/smoke_test_autoconnect.ts ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Smoke test for autoConnect's corner cases. Print-and-eyeball style
2
+ // rather than assertion-based — the lab repo doesn't have a JS test
3
+ // runner wired up. Run with `npx tsx scripts/smoke_test_autoconnect.ts`
4
+ // from the frontend dir whenever you change autoConnect.ts; eyeball
5
+ // the output for: per-algorithm backend warnings (qucad hard-error,
6
+ // qubound/compvqc soft fallback, qshot self-contained), the dashed
7
+ // "noise profile" edge styling on backend → algorithm edges (skipped
8
+ // for qshot), and the source/sink/multi-backend advisory bullets.
9
+
10
+ import type { Edge, Node } from "@xyflow/react";
11
+ import type { QNodeData } from "../src/components/QNode";
12
+ import { autoConnect } from "../src/lib/autoConnect";
13
+ import type { NodeKind } from "../src/lib/nodeCatalog";
14
+
15
+ let counter = 0;
16
+ function n(kind: NodeKind, x = (counter += 100)): Node<QNodeData> {
17
+ return {
18
+ id: `n${counter}`,
19
+ type: "qnode",
20
+ position: { x, y: 0 },
21
+ data: { kind },
22
+ };
23
+ }
24
+
25
+ function run(label: string, nodes: Node<QNodeData>[], edges: Edge[] = []) {
26
+ counter = 0;
27
+ // Re-key positions so `n()` wasn't using stale counter
28
+ nodes.forEach((node, i) => {
29
+ node.id = `n${i + 1}`;
30
+ node.position = { x: (i + 1) * 100, y: 0 };
31
+ });
32
+ const r = autoConnect(nodes, edges);
33
+ console.log(`\n--- ${label} ---`);
34
+ console.log(` connected=${r.connected}, edges=${r.edges.length}, replaced=${r.replacedCount}`);
35
+ for (const w of r.warnings) console.log(` ⚠ ${w}`);
36
+ for (const e of r.edges) {
37
+ const dashed = (e.style as { strokeDasharray?: string } | undefined)?.strokeDasharray ? " (dashed)" : "";
38
+ const lbl = e.label ? ` [${e.label}]` : "";
39
+ console.log(` → ${e.source} → ${e.target}${lbl}${dashed}`);
40
+ }
41
+ }
42
+
43
+ // 1. empty canvas
44
+ run("1. empty canvas", []);
45
+
46
+ // 2. single block (input only)
47
+ run("2. single block", [n("input_circuit")]);
48
+
49
+ // 3. happy path — full QuCAD pipeline
50
+ run("3. full QuCAD pipeline", [
51
+ n("input_circuit"),
52
+ n("fake_backend"),
53
+ n("qucad"),
54
+ n("fidelity"),
55
+ n("output"),
56
+ ]);
57
+
58
+ // 4. QuCAD with NO backend → should emit hard warning
59
+ run("4. QuCAD without backend (hard error case)", [
60
+ n("input_circuit"),
61
+ n("qucad"),
62
+ n("output"),
63
+ ]);
64
+
65
+ // 5. QuBound with NO backend → soft fallback warning
66
+ run("5. QuBound without backend (soft fallback)", [
67
+ n("input_circuit"),
68
+ n("qubound"),
69
+ n("output"),
70
+ ]);
71
+
72
+ // 6. CompressVQC with NO backend → soft fallback warning
73
+ run("6. CompressVQC without backend (soft fallback)", [
74
+ n("input_circuit"),
75
+ n("compvqc"),
76
+ n("output"),
77
+ ]);
78
+
79
+ // 7. Qshot alone (no backend) → no backend warning at all
80
+ run("7. Qshot only (self-contained, no warnings expected)", [
81
+ n("input_circuit"),
82
+ n("qshot"),
83
+ n("output"),
84
+ ]);
85
+
86
+ // 8. Qshot WITH a backend → backend-ignored warning + plain (non-dashed) edge
87
+ run("8. Qshot + backend (backend should be flagged ignored, edge undashed)", [
88
+ n("input_circuit"),
89
+ n("fake_backend"),
90
+ n("qshot"),
91
+ n("output"),
92
+ ]);
93
+
94
+ // 9. mix: QuCAD + Qshot, no backend → only QuCAD complains
95
+ run("9. QuCAD + Qshot, no backend (only QuCAD should hard-warn)", [
96
+ n("input_circuit"),
97
+ n("qucad"),
98
+ n("qshot"),
99
+ n("output"),
100
+ ]);
101
+
102
+ // 10. mix: QuBound + CompressVQC + QuCAD, no backend
103
+ run("10. QuBound + CompressVQC + QuCAD, no backend", [
104
+ n("input_circuit"),
105
+ n("qubound"),
106
+ n("compvqc"),
107
+ n("qucad"),
108
+ n("output"),
109
+ ]);
110
+
111
+ // 11. multiple backends (last-wins warning)
112
+ run("11. two backends (last-wins warning)", [
113
+ n("input_circuit"),
114
+ n("fake_backend"),
115
+ n("ibm_backend"),
116
+ n("qucad"),
117
+ n("output"),
118
+ ]);
119
+
120
+ // 12. multiple sources
121
+ run("12. two sources", [
122
+ n("input_circuit"),
123
+ n("input_circuit"),
124
+ n("fake_backend"),
125
+ n("qucad"),
126
+ n("output"),
127
+ ]);
128
+
129
+ // 13. no sink
130
+ run("13. no Output", [
131
+ n("input_circuit"),
132
+ n("fake_backend"),
133
+ n("qucad"),
134
+ ]);
135
+
136
+ // 14. backend → qubound (legitimate noise sidechain, should be DASHED)
137
+ run("14. fake_backend → qubound (dashed expected)", [
138
+ n("input_circuit"),
139
+ n("fake_backend"),
140
+ n("qubound"),
141
+ n("output"),
142
+ ]);
143
+
144
+ // 15. existing edges replacement
145
+ run(
146
+ "15. canvas with existing edges (replacedCount > 0)",
147
+ [
148
+ n("input_circuit"),
149
+ n("fake_backend"),
150
+ n("qucad"),
151
+ n("output"),
152
+ ],
153
+ [
154
+ { id: "old1", source: "n1", target: "n2" },
155
+ { id: "old2", source: "n2", target: "n3" },
156
+ ],
157
+ );
frontend/src/components/tour/PipelineSlide.tsx CHANGED
@@ -37,8 +37,9 @@ export function PipelineSlide() {
37
  State between blocks
38
  </div>
39
  <span className="text-mute">
40
- Each algorithm block may mutate the circuit in-place (CompressVQC,
41
- QuCAD) or emit a metric attached to the output (QuBound, Fidelity).
 
42
  </span>
43
  </div>
44
  <div className="panel-alt p-3">
 
37
  State between blocks
38
  </div>
39
  <span className="text-mute">
40
+ Each algorithm block either rewrites the circuit (QuCAD,
41
+ CompressVQC) or attaches a number to the output (QuBound's
42
+ error bound, Qshot's shot count, Fidelity).
43
  </span>
44
  </div>
45
  <div className="panel-alt p-3">
frontend/src/components/tour/TrySlide.tsx CHANGED
@@ -16,9 +16,11 @@ export function TrySlide() {
16
  Pick one of the sample circuits on the left, then hit{" "}
17
  <span className="kbd">Run pipeline</span> in the canvas toolbar.
18
  Default pipelines on the built-in samples hit a precomputed cache
19
- and return instantly. Switch in <span className="text-ink">QuBound</span>{" "}
20
- with a cache miss and the run can take about two minutes on HF's
21
- shared CPU while it trains the LSTM — don't close the tab.
 
 
22
  </p>
23
  </div>
24
 
@@ -44,6 +46,10 @@ export function TrySlide() {
44
  <span className="text-ink">qaoa_maxcut_4</span> + CompressVQC →
45
  see how many rotations can be folded.
46
  </li>
 
 
 
 
47
  </ul>
48
  </div>
49
 
@@ -56,7 +62,11 @@ export function TrySlide() {
56
  </div>
57
  <ul className="text-[12px] text-mute space-y-1.5 leading-relaxed">
58
  <li>Drag blocks from the strip at the top of the canvas.</li>
59
- <li>Connect their handles left-to-right.</li>
 
 
 
 
60
  <li>
61
  Hover a block to reveal the <span className="kbd">×</span>{" "}
62
  delete button.
 
16
  Pick one of the sample circuits on the left, then hit{" "}
17
  <span className="kbd">Run pipeline</span> in the canvas toolbar.
18
  Default pipelines on the built-in samples hit a precomputed cache
19
+ and return instantly. A cold{" "}
20
+ <span className="text-ink">QuBound</span> (LSTM training) or{" "}
21
+ <span className="text-ink">Qshot</span> (HDBSCAN warmup + pilot
22
+ measurements) run on HF's shared CPU can take 1–3&nbsp;minutes —
23
+ don't close the tab.
24
  </p>
25
  </div>
26
 
 
46
  <span className="text-ink">qaoa_maxcut_4</span> + CompressVQC →
47
  see how many rotations can be folded.
48
  </li>
49
+ <li>
50
+ <span className="text-ink">ry_chain_6q</span> + Qshot →
51
+ get a recommended shot count for a target fidelity.
52
+ </li>
53
  </ul>
54
  </div>
55
 
 
62
  </div>
63
  <ul className="text-[12px] text-mute space-y-1.5 leading-relaxed">
64
  <li>Drag blocks from the strip at the top of the canvas.</li>
65
+ <li>
66
+ Connect their handles left-to-right, or hit{" "}
67
+ <span className="kbd">Auto-connect</span> in the toolbar to
68
+ wire a sensible chain in one click.
69
+ </li>
70
  <li>
71
  Hover a block to reveal the <span className="kbd">×</span>{" "}
72
  delete button.
frontend/src/components/tour/WelcomeSlide.tsx CHANGED
@@ -1,8 +1,11 @@
1
  // Tour slide 1: intro. Big title + tagline + animated atom emblem.
2
  //
3
- // Copy avoids hard-coding a specific number of algorithms ("three") — the
4
- // lab ships new research modules regularly, so anything we write here
5
- // should survive adding a fourth/fifth block without copy edits.
 
 
 
6
 
7
  import { Sparkles } from "lucide-react";
8
 
@@ -29,9 +32,9 @@ export function WelcomeSlide() {
29
  >
30
  JQub lab
31
  </a>{" "}
32
- at George Mason University — currently QuCAD, QuBound, and
33
- CompressVQC, with more to come — applied to a quantum circuit
34
- of your choice.
35
  </p>
36
  <p className="text-sm text-mute leading-relaxed">
37
  Build a pipeline by dragging blocks, hit{" "}
 
1
  // Tour slide 1: intro. Big title + tagline + animated atom emblem.
2
  //
3
+ // Copy avoids hard-coding a specific number of algorithms ("three" /
4
+ // "four") — the lab ships new research modules regularly, so anything
5
+ // we write here should survive adding the next block without a copy
6
+ // edit. We do list current block names by hand because that's more
7
+ // informative than a generic "research modules"; just remember to add
8
+ // the new name to the list when a new algorithm block lands.
9
 
10
  import { Sparkles } from "lucide-react";
11
 
 
32
  >
33
  JQub lab
34
  </a>{" "}
35
+ at George Mason University — currently QuCAD, QuBound,
36
+ CompressVQC, and Qshot, with more to come — applied to a
37
+ quantum circuit of your choice.
38
  </p>
39
  <p className="text-sm text-mute leading-relaxed">
40
  Build a pipeline by dragging blocks, hit{" "}
frontend/src/lib/autoConnect.ts CHANGED
@@ -35,7 +35,7 @@
35
 
36
  import type { Edge, Node } from "@xyflow/react";
37
  import type { QNodeData } from "../components/QNode";
38
- import { NODE_BY_KIND, type NodeSpec } from "./nodeCatalog";
39
 
40
  type Family = NodeSpec["family"];
41
 
@@ -50,6 +50,34 @@ const FAMILY_ORDER: Family[] = [
50
  "sink",
51
  ];
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  export interface AutoConnectResult {
54
  /** New edge array to replace the current one (empty if nothing to do). */
55
  edges: Edge[];
@@ -129,12 +157,15 @@ export function autoConnect(
129
 
130
  // ---- advisory warnings about the composition ----
131
  //
132
- // Semantics rest on two facts about the runner in workflow_service.py:
133
  // (1) Every backend handler writes `ctx["backend"] = backend`, so a
134
  // later backend node wipes an earlier one — "last wins".
135
  // (2) Input-circuit handlers only emit a summary step, they don't
136
  // replace `ctx["circuit"]`. So extra Input nodes are merely
137
  // redundant (duplicate summary rows), not actively wrong.
 
 
 
138
  if (buckets.source.length === 0) {
139
  warnings.push("No Input circuit — pipeline has no clear starting point.");
140
  } else if (buckets.source.length > 1) {
@@ -142,15 +173,57 @@ export function autoConnect(
142
  `${buckets.source.length} Input circuits — extras produce duplicate summary rows.`,
143
  );
144
  }
145
- if (buckets.backend.length === 0 && buckets.algorithm.length > 0) {
146
- warnings.push(
147
- "No backend — algorithms that need a noise model will error at run time.",
 
 
 
 
 
 
 
 
 
 
148
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  } else if (buckets.backend.length > 1) {
150
  warnings.push(
151
  `${buckets.backend.length} backends linked in series — only the rightmost one is used downstream.`,
152
  );
153
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  if (buckets.sink.length === 0) {
155
  warnings.push("No Output block — final metrics will not be aggregated.");
156
  }
@@ -181,6 +254,12 @@ export function autoConnect(
181
  // so readers of the graph can tell "this block feeds calibration data,
182
  // not a transformed circuit" at a glance. Inspired by Jovin's original
183
  // flowChartProto, which dashed the same edge.
 
 
 
 
 
 
184
  const edges: Edge[] = [];
185
  for (let i = 0; i < chain.length - 1; i++) {
186
  const src = chain[i];
@@ -188,7 +267,9 @@ export function autoConnect(
188
  const srcFamily = NODE_BY_KIND[src.data.kind]?.family;
189
  const dstFamily = NODE_BY_KIND[dst.data.kind]?.family;
190
  const isNoiseSidechain =
191
- srcFamily === "backend" && dstFamily === "algorithm";
 
 
192
  edges.push({
193
  id: `auto-${src.id}-${dst.id}`,
194
  source: src.id,
 
35
 
36
  import type { Edge, Node } from "@xyflow/react";
37
  import type { QNodeData } from "../components/QNode";
38
+ import { NODE_BY_KIND, type NodeKind, type NodeSpec } from "./nodeCatalog";
39
 
40
  type Family = NodeSpec["family"];
41
 
 
50
  "sink",
51
  ];
52
 
53
+ // Per-algorithm dependency on an upstream backend, derived from the
54
+ // runtime handlers in backend/app/services/workflow_service.py. Three
55
+ // possible relationships:
56
+ //
57
+ // - "required": handler hard-errors without ctx["backend"]
58
+ // (currently only QuCAD).
59
+ // - "optional": handler silently falls back to FakeFez when no
60
+ // backend is connected (QuBound, CompressVQC).
61
+ // - "ignored": handler is self-contained and ignores ctx["backend"]
62
+ // even if one is wired (Qshot — uses its own bundled
63
+ // noise snapshots).
64
+ //
65
+ // Keeping this here means Auto-connect's warnings can be specific
66
+ // instead of issuing a one-size-fits-all "algorithms that need a noise
67
+ // model will error" line that's wrong for everything except QuCAD.
68
+ const ALGO_BACKEND_DEPENDENCY: Record<NodeKind, "required" | "optional" | "ignored" | undefined> = {
69
+ qucad: "required",
70
+ qubound: "optional",
71
+ compvqc: "optional",
72
+ qshot: "ignored",
73
+ // Non-algorithm kinds: undefined (irrelevant to backend dependency).
74
+ input_circuit: undefined,
75
+ ibm_backend: undefined,
76
+ fake_backend: undefined,
77
+ fidelity: undefined,
78
+ output: undefined,
79
+ };
80
+
81
  export interface AutoConnectResult {
82
  /** New edge array to replace the current one (empty if nothing to do). */
83
  edges: Edge[];
 
157
 
158
  // ---- advisory warnings about the composition ----
159
  //
160
+ // Semantics rest on three facts about the runner in workflow_service.py:
161
  // (1) Every backend handler writes `ctx["backend"] = backend`, so a
162
  // later backend node wipes an earlier one — "last wins".
163
  // (2) Input-circuit handlers only emit a summary step, they don't
164
  // replace `ctx["circuit"]`. So extra Input nodes are merely
165
  // redundant (duplicate summary rows), not actively wrong.
166
+ // (3) Algorithms differ on whether they need a backend — see
167
+ // ALGO_BACKEND_DEPENDENCY above. Auto-connect warns specifically
168
+ // per algorithm rather than issuing a blanket "no backend" line.
169
  if (buckets.source.length === 0) {
170
  warnings.push("No Input circuit — pipeline has no clear starting point.");
171
  } else if (buckets.source.length > 1) {
 
173
  `${buckets.source.length} Input circuits — extras produce duplicate summary rows.`,
174
  );
175
  }
176
+
177
+ // Backend-dependency warnings, one per offending algorithm. We split
178
+ // them so the user sees concrete consequences ("QuCAD will error",
179
+ // "QuBound will fall back to FakeFez") instead of a single vague
180
+ // bullet.
181
+ const hasBackend = buckets.backend.length > 0;
182
+ const algoKinds = buckets.algorithm.map((n) => n.data.kind);
183
+ if (!hasBackend) {
184
+ const requiredKinds = algoKinds.filter(
185
+ (k) => ALGO_BACKEND_DEPENDENCY[k] === "required",
186
+ );
187
+ const optionalKinds = algoKinds.filter(
188
+ (k) => ALGO_BACKEND_DEPENDENCY[k] === "optional",
189
  );
190
+ for (const k of requiredKinds) {
191
+ warnings.push(
192
+ `${NODE_BY_KIND[k].label} requires a backend node upstream and will error at run time.`,
193
+ );
194
+ }
195
+ if (optionalKinds.length > 0) {
196
+ const labels = optionalKinds
197
+ .map((k) => NODE_BY_KIND[k].label)
198
+ .join(" and ");
199
+ warnings.push(
200
+ `${labels} will fall back to FakeFez since no backend is connected.`,
201
+ );
202
+ }
203
  } else if (buckets.backend.length > 1) {
204
  warnings.push(
205
  `${buckets.backend.length} backends linked in series — only the rightmost one is used downstream.`,
206
  );
207
  }
208
+
209
+ // Self-contained algorithms (Qshot) ignore upstream backends. If the
210
+ // user wired a backend in front of a chain that contains only
211
+ // self-contained algorithms, that backend node is dead weight —
212
+ // worth flagging so the user doesn't expect it to influence the
213
+ // result.
214
+ if (
215
+ hasBackend &&
216
+ algoKinds.length > 0 &&
217
+ algoKinds.every((k) => ALGO_BACKEND_DEPENDENCY[k] === "ignored")
218
+ ) {
219
+ const ignoredLabels = Array.from(new Set(algoKinds))
220
+ .map((k) => NODE_BY_KIND[k].label)
221
+ .join(" / ");
222
+ warnings.push(
223
+ `${ignoredLabels} is self-contained — the backend node will be ignored at run time.`,
224
+ );
225
+ }
226
+
227
  if (buckets.sink.length === 0) {
228
  warnings.push("No Output block — final metrics will not be aggregated.");
229
  }
 
254
  // so readers of the graph can tell "this block feeds calibration data,
255
  // not a transformed circuit" at a glance. Inspired by Jovin's original
256
  // flowChartProto, which dashed the same edge.
257
+ //
258
+ // Exception: Qshot (kind === "qshot") is self-contained and ignores
259
+ // ctx["backend"] entirely. Putting a "noise profile" label on a
260
+ // backend → qshot edge would be a lie. We still draw the edge so the
261
+ // chain stays visually connected (and Auto-connect emits the "Qshot
262
+ // is self-contained" warning above), but with a plain undashed style.
263
  const edges: Edge[] = [];
264
  for (let i = 0; i < chain.length - 1; i++) {
265
  const src = chain[i];
 
267
  const srcFamily = NODE_BY_KIND[src.data.kind]?.family;
268
  const dstFamily = NODE_BY_KIND[dst.data.kind]?.family;
269
  const isNoiseSidechain =
270
+ srcFamily === "backend" &&
271
+ dstFamily === "algorithm" &&
272
+ ALGO_BACKEND_DEPENDENCY[dst.data.kind] !== "ignored";
273
  edges.push({
274
  id: `auto-${src.id}-${dst.id}`,
275
  source: src.id,