File size: 18,011 Bytes
1ee2bb3 fd88622 1ee2bb3 94039f2 79cd0aa 1ee2bb3 fd88622 1ee2bb3 94039f2 1ee2bb3 c50b89a bd3a155 1ee2bb3 94039f2 d9de684 a2227a5 1ee2bb3 fa80903 1ee2bb3 c50b89a 79cd0aa 1ee2bb3 36d22d6 1ee2bb3 c50b89a 36d22d6 1ee2bb3 286193c 1ee2bb3 94039f2 cadac03 94039f2 286193c 79cd0aa 286193c 94039f2 1ee2bb3 4087daa 1ee2bb3 286193c 79cd0aa 286193c 1ee2bb3 bd3a155 79cd0aa 1ee2bb3 94039f2 cadac03 94039f2 cadac03 94039f2 cadac03 94039f2 79cd0aa 1ee2bb3 c50b89a 79cd0aa 1ee2bb3 286193c 79cd0aa 1ee2bb3 c50b89a 79cd0aa 1ee2bb3 79cd0aa 1ee2bb3 fd88622 c50b89a fd88622 79cd0aa fd88622 94039f2 cadac03 94039f2 cadac03 94039f2 fd88622 1ee2bb3 79cd0aa 1ee2bb3 286193c 1ee2bb3 bd3a155 79cd0aa 1ee2bb3 74b7708 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 | // Single source of truth for what kinds of nodes exist in the pipeline.
// Backend types must stay in sync with backend/app/schemas.py NodeType.
import type { LucideIcon } from "lucide-react";
import {
Atom,
Cpu,
Gauge,
LineChart,
PackageCheck,
Server,
Shrink,
Target,
Waypoints,
} from "lucide-react";
import { NOISE_SNAPSHOTS } from "./qshotSnapshots";
import { GLOSSARY } from "./glossary";
export type NodeKind =
| "input_circuit"
| "ibm_backend"
| "fake_backend"
| "qucad"
| "qubound"
| "compvqc"
| "qshot"
| "fidelity"
| "output";
/** Schema describing one editable parameter on a node.
*
* Drives `<NodeParamEditor>` — when a `NodeSpec` lists `params`, the
* block on the canvas renders an inline editor instead of a static
* read-out of `defaultData`. Keep this list narrow on purpose: only
* expose the knobs the algorithm's author considered user-tunable in
* the original code (the function arguments of `predict()` /
* `run_qucad_*` etc., NOT the module-level constants used during
* training). Touching the latter would invalidate bundled state.
*/
export type NodeParamSpec =
| {
key: string;
label: string;
type: "select";
options: { value: string; label: string }[];
/** Optional one-line hint shown under the field. */
hint?: string;
}
| {
key: string;
label: string;
type: "number" | "int";
min?: number;
max?: number;
step?: number;
/** Decimals shown in the inline current-value chip. Defaults to
* 2 for `number`, 0 for `int`. */
displayPrecision?: number;
hint?: string;
};
export interface NodeSpec {
kind: NodeKind;
label: string;
family: "source" | "backend" | "algorithm" | "metric" | "sink";
/** Palette-tile microcopy. BUDGET: must read complete within two
* 9px lines at the tile's 108px width (≈12 chars/line) — the tile
* clamps at 2 lines, so anything longer ellipsizes mid-thought
* ("predict today's erro…"). The full thought belongs in
* `description`, which is the tile's hover tooltip. */
tagline: string;
/** Long-form description: hover tooltip on the palette tile and
* subtitle text on the canvas node. */
description: string;
icon: LucideIcon;
accent: string; // tailwind text color
accentRing: string; // tailwind ring/border color
defaultData?: Record<string, unknown>;
defaultCount?: 0 | 1; // how many copies are auto-placed on canvas reset
/** When present, the canvas node renders an inline editor in place of
* the static param read-out. Order matters — params render top-to-
* bottom in the order listed here. */
params?: NodeParamSpec[];
/** Optional link to the paper this block implements. Surfaces as a small
* external-link icon on the node card and palette tile.
*
* `bibtex` is the copy-to-clipboard string for the Papers popover.
* Keep the author list up-to-date here — this is what visitors will
* paste into their .bib file.
*/
paper?: {
url: string;
title: string;
venue: string;
bibtex: string;
};
}
export const NODE_CATALOG: NodeSpec[] = [
{
kind: "input_circuit",
label: "Input circuit",
family: "source",
tagline: "your circuit",
description:
"The program under test — a quantum circuit, possibly with trainable parameters (uploaded .qpy or a built-in sample).",
icon: Atom,
accent: "text-accent",
accentRing: "border-accent/50",
defaultCount: 1,
},
{
kind: "fake_backend",
label: "Noisy simulator",
family: "backend",
tagline: "simulated IBM chip",
description:
"Simulates a real IBM quantum chip with its measured noise. Runs locally, no IBM account needed.",
icon: Server,
accent: "text-accent",
accentRing: "border-accent/40",
defaultData: { backend_name: "FakeFez", shots: 1024 },
defaultCount: 1,
// Backend handler in workflow_service supports three Heron-family
// fakes (FakeFez / FakeMarrakesh / FakeTorino). Adding more requires
// extending `_load_fake_backend` in tandem.
params: [
{
key: "backend_name",
label: "Fake backend",
type: "select",
options: [
{ value: "FakeFez", label: "FakeFez · 156q (Heron r2)" },
{ value: "FakeMarrakesh", label: "FakeMarrakesh · 156q (Heron r2)" },
{ value: "FakeTorino", label: "FakeTorino · 133q (Heron r1)" },
],
hint: "Each option is a simulated copy of a real IBM chip. The choice mainly affects which gate-error rates and qubit connectivity the noise model uses.",
},
{
key: "shots",
label: "Shots",
type: "int",
min: 1,
max: 65536,
step: 1,
hint: `${GLOSSARY.shots} Used by downstream blocks that actually sample (e.g. Fidelity in "sampled" mode); 1024 is the common default.`,
},
],
},
{
kind: "ibm_backend",
label: "IBM live backend",
family: "backend",
tagline: "fresh IBM calibration",
description: "Fresh calibration from the IBM Quantum Platform (requires token). Circuits still run on the local noisy simulator — this block only refreshes the noise model.",
icon: Cpu,
accent: "text-warn",
accentRing: "border-warn/40",
defaultData: { backend_name: "ibm_fez", shots: 1024 },
params: [
{
key: "shots",
label: "Shots",
type: "int",
min: 1,
max: 65536,
step: 1,
hint: `${GLOSSARY.shots} Same units as the Noisy simulator's shots; live mode falls back to the simulator on this deployment.`,
},
],
},
{
kind: "qucad",
label: "QuCAD",
family: "algorithm",
tagline: "noise-aware pruning",
description:
"Noise-aware pruning: learns which trainable parameters to delete so the smaller circuit holds up better under the target machine's noise (ADMM optimizer).",
icon: Waypoints,
accent: "text-accent2",
accentRing: "border-accent2/50",
defaultData: { iterations: 3, lam: 0.005, rho: 500.0 },
// ADMM hyperparameters from the QuCAD paper: more iterations and a
// higher λ tend to push weights more aggressively to zero (sparser
// circuit) at the cost of training time; ρ is the standard ADMM
// penalty weight. Defaults match the original training script.
params: [
{
key: "iterations",
label: "ADMM iterations",
type: "int",
min: 1,
max: 20,
step: 1,
hint: "More iterations → tighter convergence, slower run.",
},
{
key: "lam",
label: "Regularisation λ",
type: "number",
min: 0.0001,
max: 0.05,
step: 0.001,
displayPrecision: 4,
hint: "Larger λ → more aggressive pruning (fewer surviving gates).",
},
{
key: "rho",
label: "ADMM penalty ρ",
type: "number",
min: 10,
max: 5000,
step: 10,
displayPrecision: 0,
hint: "Internal penalty weight for the ADMM solver; default is usually fine.",
},
],
// Paper metadata identifies the group's prior work — folded out of
// double-anonymous builds at compile time (see lib/anon.ts).
...(import.meta.env.VITE_ANON === "1"
? {}
: {
paper: {
url: "https://arxiv.org/abs/2304.04666",
title:
"Battle Against Fluctuating Quantum Noise: Compression-Aided Framework to Enable Robust Quantum Neural Network",
venue: "ICCAD 2023",
bibtex: `@inproceedings{qucad2023,
title = {Battle Against Fluctuating Quantum Noise: Compression-Aided Framework to Enable Robust Quantum Neural Network},
author = {Antony Maria, Jovin and Jiang, Weiwen},
booktitle = {2023 IEEE/ACM International Conference on Computer-Aided Design (ICCAD)},
year = {2023},
eprint = {2304.04666},
archivePrefix = {arXiv},
}`,
},
}),
},
{
kind: "qubound",
label: "QuBound",
family: "algorithm",
tagline: "error bound",
description:
"Predicts today's error bound from the machine's last 14 days of measured error rates (a small learned model). Set a threshold to get a pass/fail decision.",
icon: LineChart,
accent: "text-accent3",
accentRing: "border-accent3/50",
defaultData: { cache_backend: "ibm_fez", threshold: 0 },
params: [
{
key: "threshold",
label: "Acceptance threshold",
type: "number",
min: 0,
max: 1,
step: 0.01,
displayPrecision: 3,
hint: "Acceptable upper bound on predicted error. 0 disables the pass/fail decision and shows the predicted bound only. Typical values: 0.05 (strict) to 0.20 (lenient).",
},
],
// Paper metadata identifies the group's prior work — folded out of
// double-anonymous builds at compile time (see lib/anon.ts).
...(import.meta.env.VITE_ANON === "1"
? {}
: {
paper: {
url: "https://arxiv.org/abs/2507.17043",
title:
"Computational Performance Bounds Prediction in Quantum Computing with Unstable Noise",
venue: "IEEE TCAD 2025",
bibtex: `@article{qubound2025,
title = {Computational Performance Bounds Prediction in Quantum Computing with Unstable Noise},
author = {Antony Maria, Jovin and Jiang, Weiwen},
journal = {IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems},
year = {2025},
eprint = {2507.17043},
archivePrefix = {arXiv},
}`,
},
}),
},
{
kind: "compvqc",
label: "CompressVQC",
family: "algorithm",
tagline: "fold gates",
description:
"Circuit compression: merges redundant rotation operations via a precomputed lookup table, so the same computation uses fewer operations.",
icon: Shrink,
accent: "text-accent4",
accentRing: "border-accent4/50",
// Paper metadata identifies the group's prior work — folded out of
// double-anonymous builds at compile time (see lib/anon.ts).
...(import.meta.env.VITE_ANON === "1"
? {}
: {
paper: {
url: "https://arxiv.org/abs/2207.01578",
title: "Quantum Neural Network Compression",
venue: "ICCAD 2022",
bibtex: `@inproceedings{compressvqc2022,
title = {Quantum Neural Network Compression},
author = {Hu, Zhirui and Dong, Peiyan and Wang, Zhepeng and Lin, Youzuo and Wang, Yanzhi and Jiang, Weiwen},
booktitle = {2022 IEEE/ACM International Conference on Computer-Aided Design (ICCAD)},
year = {2022},
eprint = {2207.01578},
archivePrefix = {arXiv},
}`,
},
}),
},
{
kind: "qshot",
label: "Qshot",
family: "algorithm",
tagline: "shot count",
description:
"Recommends how many repeated measurements (shots) are needed to meet a target accuracy, with statistical confidence, on a chosen day's machine noise. Self-contained — no upstream backend required.",
icon: Target,
accent: "text-warn",
accentRing: "border-warn/40",
// Default: pittsburgh_1 snapshot + 95% of converged fidelity, matches
// the author's example_usage.py defaults. Users can tweak either from
// the block's parameter panel.
defaultData: {
noise_snapshot: "pittsburgh_1",
alpha: 0.95,
},
// The two user-facing knobs of QshotRecommender.predict(). Other
// arguments (k_struct / k_pf / pilot_points / pilot_reps) are model
// hyperparameters the author tuned during training; touching them
// would invalidate the bundled clusters, so they're deliberately
// not exposed.
params: [
{
key: "noise_snapshot",
label: "Noise snapshot",
type: "select",
options: NOISE_SNAPSHOTS.map((s) => ({
value: s.key,
label: s.label,
})),
hint: "A real IBM chip's calibration captured on a specific date — different days have different noise levels, so the recommended shot count shifts too.",
},
{
key: "alpha",
label: "Target fidelity α",
type: "number",
min: 0.5,
max: 0.99,
step: 0.01,
displayPrecision: 2,
hint: "Fraction of the best-possible accuracy you want. 0.95 = aim for 95% — higher means stricter and more shots.",
},
],
},
{
kind: "fidelity",
label: "Fidelity",
family: "metric",
tagline: "how close to ideal?",
description:
"Scores how close the noisy result is to the ideal one (0–1, higher is better). Two methods: exact noise-free calculation, or sampled measurements from the noisy machine (carries measurement uncertainty).",
icon: Gauge,
accent: "text-ok",
accentRing: "border-ok/40",
defaultData: { method: "statevector", unbound_param_policy: "bind_zero" },
params: [
{
key: "method",
label: "Method",
type: "select",
options: [
{ value: "statevector", label: "Statevector (noiseless)" },
{ value: "sampled", label: "Sampled from noisy backend" },
],
hint: "Statevector gives the noiseless probability of the |0…0⟩ outcome. Sampled actually runs the (bound) circuit on the upstream backend with N shots and observes the count fraction — this is what real hardware would give and uses the backend's noise model.",
},
{
key: "unbound_param_policy",
label: "Unbound parameters",
type: "select",
options: [
{ value: "bind_zero", label: "Bind to zero (default)" },
{ value: "error", label: "Refuse with error" },
],
hint: "Parametric circuits (e.g. ry_chain_6q) have unbound parameters. `bind_zero` substitutes zero so a number comes out; `error` refuses and asks you to bind upstream so the result reflects your actual intent.",
},
],
},
{
kind: "output",
label: "Output",
family: "sink",
tagline: "final metrics & diagram",
description:
"Final circuit, its operation counts after compiling for the target machine, and the aggregated metrics.",
icon: PackageCheck,
accent: "text-ink",
accentRing: "border-mute/40",
defaultCount: 1,
},
];
export const NODE_BY_KIND = Object.fromEntries(
NODE_CATALOG.map((n) => [n.kind, n]),
) as Record<NodeKind, NodeSpec>;
// ---------------------------------------------------------------------
// User-plugin support
// ---------------------------------------------------------------------
//
// Plugin manifests come from the backend at runtime; we synthesize a
// NodeSpec on the fly so the rest of the UI can treat them like a
// built-in block.
import { Package } from "lucide-react";
import type { PluginManifest } from "./api";
/** A NodeSpec extension marker so render code knows this is user-
* uploaded (renders generic icon + first-letter badge with the
* plugin's chosen color, and shows a "delete" affordance). */
export interface PluginNodeSpec extends NodeSpec {
isPlugin: true;
/** First letter or two of the label, shown as a colored badge. */
initials: string;
/** Plugin's chosen accent colour (raw hex). */
pluginColor: string;
}
/** Build a NodeSpec from a backend-served plugin manifest. The
* resulting spec slots into NODE_CATALOG-shaped consumers without
* conditionals at the call site — only render code that wants the
* plugin badge needs to check ``isPlugin``. */
export function synthesizePluginSpec(m: PluginManifest): PluginNodeSpec {
const initials = m.label
.replace(/[^A-Za-z0-9]/g, "")
.slice(0, 2)
.toUpperCase() || "?";
// We deliberately don't carry the plugin's colour through the
// existing Tailwind ``accent``/``accentRing`` slots (those expect
// class names); instead the QNode render uses ``pluginColor``
// directly as an inline style on the badge.
return {
kind: m.kind as NodeKind,
label: m.label,
family: m.family,
tagline: m.tagline,
description: m.description || `User plugin (${m.kind}).`,
icon: Package,
accent: "text-ink",
accentRing: "border-edge",
// Plugin manifest params share the same shape as NodeParamSpec.
params: m.params.length > 0 ? (m.params as NodeParamSpec[]) : undefined,
defaultData: {},
isPlugin: true,
initials,
pluginColor: m.color,
};
}
/** Look up the spec for a node kind, falling back to a synthesized
* plugin spec if it's user-uploaded. Returns undefined for unknown
* kinds (so callers can show an "orphan plugin" state — e.g. the
* user opened a share-link that references a plugin they don't
* have installed). */
export function resolveNodeSpec(
kind: string,
plugins: PluginManifest[],
): NodeSpec | PluginNodeSpec | undefined {
const builtin = NODE_BY_KIND[kind as NodeKind];
if (builtin) return builtin;
const m = plugins.find((p) => p.kind === kind);
return m ? synthesizePluginSpec(m) : undefined;
}
/** Same as resolveNodeSpec but never returns undefined — produces a
* best-effort "missing plugin" placeholder so render code doesn't
* have to handle nulls. */
export function resolveNodeSpecOrPlaceholder(
kind: string,
plugins: PluginManifest[],
): NodeSpec | PluginNodeSpec {
const found = resolveNodeSpec(kind, plugins);
if (found) return found;
return {
kind: kind as NodeKind,
label: kind,
family: "algorithm",
tagline: "missing plugin",
description: `No plugin with kind="${kind}" is installed in this browser.`,
icon: Package,
accent: "text-danger",
accentRing: "border-danger/40",
isPlugin: true,
initials: "?",
pluginColor: "#dc2626",
} as PluginNodeSpec;
}
|