Spaces:
Sleeping
Sleeping
Yuchen Yuan
Claude Opus 4.7 (1M context)
Fix Fidelity on parameterized circuits + QuBound threshold + Backend shots
286193c Download frontend/src/lib/nodeCatalog.ts from qudastudio/app: direct link, hf CLI and curl.
- Browser
- Download file 16.7 kB
-
https://huggingface.co/spaces/qudastudio/app/resolve/main/frontend/src/lib/nodeCatalog.ts
- Command line
-
hf download hf://spaces/qudastudio/app/frontend/src/lib/nodeCatalog.ts
-
curl -L -o nodeCatalog.ts https://huggingface.co/spaces/qudastudio/app/resolve/main/frontend/src/lib/nodeCatalog.ts
16.7 kB
| // 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"; | |
| 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"; | |
| /** Short human-friendly caption (~3-5 words) shown under the label. */ | |
| 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 quantum program", | |
| description: "Parameterized QuantumCircuit (uploaded .qpy or a demo sample).", | |
| icon: Atom, | |
| accent: "text-accent", | |
| accentRing: "border-accent/50", | |
| defaultCount: 1, | |
| }, | |
| { | |
| kind: "fake_backend", | |
| label: "Noisy simulator", | |
| family: "backend", | |
| tagline: "local IBM-chip simulator", | |
| 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: "Number of times the circuit is run and measured. Picked up from ctx by downstream blocks that actually sample (e.g. Fidelity in `sampled` mode). 1024 is the Qiskit default; bigger means lower shot noise but proportionally slower runs.", | |
| }, | |
| ], | |
| }, | |
| { | |
| 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: "Measurement count used by downstream sampling blocks. Same units as Noisy simulator's shots; live mode falls back to Noisy simulator on this deployment.", | |
| }, | |
| ], | |
| }, | |
| { | |
| kind: "qucad", | |
| label: "QuCAD", | |
| family: "algorithm", | |
| tagline: "noise-aware pruning", | |
| description: "ADMM-based noise-aware VQC sparsification (weights pushed to 0 under target noise).", | |
| 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: { | |
| 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: "predict today's error bound", | |
| description: "LSTM over 14 days of calibration history; predicts today's error bound. 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: { | |
| 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 redundant gates", | |
| description: "QAOA-optimized lookup table that folds redundant parametric gates.", | |
| icon: Shrink, | |
| accent: "text-accent4", | |
| accentRing: "border-accent4/50", | |
| 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: "recommend shot count", | |
| description: | |
| "Noise-aware shot-count recommender. Predicts the smallest shot count that meets a target fidelity bound (with statistical confidence, z=1.645) on a chosen IBM calibration snapshot. 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: "noiseless vs sampled", | |
| description: "Estimates the |0…0⟩-state fidelity. Two methods: noiseless statevector (fast, ignores backend noise) or sampled shots from the noisy backend (uses backend's shots, has shot noise).", | |
| 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, transpiled gate counts, and 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; | |
| } | |