// Gate-level circuit diff — per-qubit lanes, LCS-merged token order. // Lives inside SignatureCard, collapsed behind a
: the // channel strip answers "how much changed", this view answers // "WHICH gates, on WHICH lanes" — the QuCAD-pruned / CompVQC-folded // evidence a reader wants before believing a signature. // // Encoding (consistent with the delta strip's goal-anchored colors): // kept — neutral dimmed chip (context, not the story) // removed — ok/green + strikethrough (pruning is the optimizer's // goal; decrease=ok everywhere in this vocabulary) // added — warn/amber (growth is the thing to scrutinize) // 2-qubit partners carry their role suffix (·c control / ·t target) // so a cx shows up on BOTH lanes and reads correctly on each. // Payload is capped server-side (12 qubits / 600 ops) — over the cap // we show a one-line pointer back to the channel strip. import type { TransformationPayload } from "./TransformationSignature"; interface GateDiffEntry { op: string; s: "kept" | "removed" | "added"; } export interface GateDiffPayload { truncated: boolean; reason?: string; qubits?: Record; n_kept?: number; n_removed?: number; n_added?: number; } export function gateDiffOf( t: TransformationPayload | null | undefined, ): GateDiffPayload | null { const g = (t as unknown as Record | null | undefined) ?.gate_diff; if (!g || typeof g !== "object") return null; return g as GateDiffPayload; } const CHIP: Record = { kept: { cls: "bg-surfaceAlt border-edge text-mute opacity-70", title: "unchanged by this step", }, removed: { cls: "bg-ok/10 border-ok/40 text-ok line-through", title: "removed by this step", }, added: { cls: "bg-warn/10 border-warn/40 text-warn", title: "added by this step", }, }; export default function CircuitDiff({ t, defaultOpen = false, }: { t: TransformationPayload; /** Scenario F5 boots the diff expanded (initial state only — the * user can still toggle it; React never re-asserts the attribute * because the vdom value doesn't change). */ defaultOpen?: boolean; }) { const g = gateDiffOf(t); if (!g) return null; if (g.truncated) { return (
circuit too large for gate-level diff (shown up to 12 qubits / 600 gates) — see the channel strip above
); } const lanes = Object.entries(g.qubits ?? {}).sort( (a, b) => Number(a[0]) - Number(b[0]), ); if (lanes.length === 0) return null; const nRemoved = g.n_removed ?? 0; const nAdded = g.n_added ?? 0; return (
Gate-level diff · {nRemoved} removed · {nAdded} added
{lanes.map(([qi, ops]) => (
q{qi}
{ops.map((e, i) => ( {e.op} ))}
))}
); }