quaim / frontend /src /lib /presets.ts
TheYuchen
Board/theater/export: overlay stacking, figure honesty, export text metrics
77fb334
Raw History Blame Contribute Delete
5.87 kB
// Preset pipelines that populate the canvas on boot / on "Load preset".
//
// Each preset is described declaratively (what nodes and edges, no
// positions). `buildPresetGraph` turns that into React Flow node/edge
// objects with a simple left-to-right chain layout, so adding a new
// preset only requires editing this file.
import type { Edge, Node } from "@xyflow/react";
import type { NodeKind } from "./nodeCatalog";
import { NODE_BY_KIND } from "./nodeCatalog";
import type { QNodeData } from "../components/QNode";
export interface PresetNodeSpec {
id: string;
kind: NodeKind;
/** Optional param overrides on top of the kind's `defaultData`. */
params?: Record<string, unknown>;
}
export interface PresetEdgeSpec {
source: string;
target: string;
}
export interface PipelinePreset {
key: string;
label: string;
/** One-line description shown in the preset dropdown. */
tagline: string;
nodes: PresetNodeSpec[];
edges: PresetEdgeSpec[];
/** Optional sample-circuit key (must match a `circuits/samples/{key}`
* on the backend). Loading this preset will also auto-load that
* sample so the user lands on a circuit the preset is meant for —
* used by Qshot to land users on a 5–8q circuit by default instead
* of the global default `bell_state` (2q, would force GNN fallback). */
defaultCircuit?: string;
}
export const PIPELINE_PRESETS: PipelinePreset[] = [
{
key: "qubound",
label: "QuBound",
tagline: "Predict today's fidelity bound from calibration history",
nodes: [
{ id: "n1", kind: "input_circuit" },
{ id: "n2", kind: "fake_backend" },
{ id: "n3", kind: "qubound" },
{ id: "n4", kind: "output" },
],
edges: [
{ source: "n1", target: "n2" },
{ source: "n2", target: "n3" },
{ source: "n3", target: "n4" },
],
},
{
key: "qucad",
label: "QuCAD",
tagline: "ADMM pruning on VQC weights, plus a fidelity check",
nodes: [
{ id: "n1", kind: "input_circuit" },
{ id: "n2", kind: "fake_backend" },
{ id: "n3", kind: "qucad" },
{ id: "n4", kind: "fidelity" },
{ id: "n5", kind: "output" },
],
edges: [
{ source: "n1", target: "n2" },
{ source: "n2", target: "n3" },
{ source: "n3", target: "n4" },
{ source: "n4", target: "n5" },
],
},
{
key: "compvqc",
label: "CompressVQC",
tagline: "Fold redundant parametric gates, then check fidelity",
nodes: [
{ id: "n1", kind: "input_circuit" },
{ id: "n2", kind: "fake_backend" },
{ id: "n3", kind: "compvqc" },
{ id: "n4", kind: "fidelity" },
{ id: "n5", kind: "output" },
],
edges: [
{ source: "n1", target: "n2" },
{ source: "n2", target: "n3" },
{ source: "n3", target: "n4" },
{ source: "n4", target: "n5" },
],
},
{
key: "qshot",
label: "Qshot",
// Auto-load ry_chain_6q (6q HEA) so the preset lands inside Qshot's
// 5-8q training range out of the box. Without this, Qshot on the
// global default bell_state (2q) immediately falls through to the
// GNN extrapolation path and the user sees a "best guess" warn
// banner that isn't really representative of Qshot's main path.
tagline: "Recommend a shot count for a 5-8 qubit circuit",
nodes: [
{ id: "n1", kind: "input_circuit" },
{ id: "n2", kind: "qshot" },
// First-party presets must pass their own preflight: without an
// output sink this one shipped with a standing lint warning
// (audit S2).
{ id: "n3", kind: "output" },
],
edges: [
{ source: "n1", target: "n2" },
{ source: "n2", target: "n3" },
],
defaultCircuit: "ry_chain_6q",
},
{
key: "full",
label: "Full stack",
tagline: "QuCAD + CompressVQC + QuBound + Fidelity, end-to-end",
nodes: [
{ id: "n1", kind: "input_circuit" },
{ id: "n2", kind: "fake_backend" },
{ id: "n3", kind: "qucad" },
{ id: "n4", kind: "compvqc" },
{ id: "n5", kind: "qubound" },
{ id: "n6", kind: "fidelity" },
{ id: "n7", kind: "output" },
],
edges: [
{ source: "n1", target: "n2" },
{ source: "n2", target: "n3" },
{ source: "n3", target: "n4" },
{ source: "n4", target: "n5" },
{ source: "n5", target: "n6" },
{ source: "n6", target: "n7" },
],
},
];
// Default pipeline shown on first load. QuCAD is preferred over QuBound
// here because (a) its precomputed-cache hit for default circuits returns
// instantly, and (b) on a cache miss its ADMM pass on small circuits is
// still sub-second, whereas QuBound's LSTM-based bound predictor can take
// tens of seconds on the shared HF CPU even with the 14-day calibration
// cache warmed up. Better first impression for drive-by visitors.
export const DEFAULT_PRESET_KEY = "qucad";
export const PRESET_BY_KEY: Record<string, PipelinePreset> = Object.fromEntries(
PIPELINE_PRESETS.map((p) => [p.key, p]),
);
/**
* Convert a preset into React Flow nodes/edges, laid out as a simple
* left-to-right chain with fixed horizontal spacing. Long chains just
* extend further right — React Flow's fitView handles the zoom.
*/
export function buildPresetGraph(preset: PipelinePreset): {
nodes: Node<QNodeData>[];
edges: Edge[];
} {
const START_X = 80;
const SPACING_X = 260;
const Y = 120;
const nodes: Node<QNodeData>[] = preset.nodes.map((pn, i) => ({
id: pn.id,
type: "qnode",
position: { x: START_X + i * SPACING_X, y: Y },
data: {
kind: pn.kind,
params: {
...(NODE_BY_KIND[pn.kind].defaultData ?? {}),
...(pn.params ?? {}),
},
},
}));
const edges: Edge[] = preset.edges.map((pe, i) => ({
id: `e${i + 1}`,
source: pe.source,
target: pe.target,
}));
return { nodes, edges };
}