Learn from zero, part 2: steps 3-5 + handoff (marker: learn-complete)
Browse filesStep3Bell "Two qubits, one fate": the fixed Bell recipe on two wires
(BellRecipe.tsx, read-only SVG), two dials whose needles snap TOGETHER
on every draw, and a 2x2 PairGrid (the Tally idiom folded into the
fourfold table) where only 00/11 ever populate — a certainty claim the
exact sim licenses. "Break the link" swaps CX for H(x)H (NOT mere
deletion, which would pin q1 at 0) so all four cells fill as the
honest independent contrast; both marginal dials read 50% in both
modes — only the joint tally reveals the link.
Step4Noise "Real machines misread": same recipe + grid, a perfect/
noisy machine switch (applyReadoutNoise, seeded) with an eps slider
(0-15%): 01/10 leak warn-tinted counts and the live agreement score
(reported pair == drawn pair; ~88% at 6% noise since both bits must
survive) is fidelity in miniature, bridged to the Noisy simulator
block by name.
Step5Certainty "How many looks is enough?": the noisy agreement score
becomes the estimand, drawn as a live mini funnel in the theater's
exact grammar (per-batch wilson95 interval bars, convergence envelope,
ink point path, fixed axis; 460x200). "look x50" buys a batch; "auto
to +-2pp" is optional stopping made tactile (stop line + "the rest of
the budget is yours to keep"). Handoff footer (marker learn-complete)
sets quda.learnLabDone and either closes or opens the guided lessons
directly on L1 via the new store bridge pendingLessonKey.
Entry/handoff completion: board empty state and tour slide 5 now point
at BOTH tracks ("New to quantum? Start from zero" first); LessonCard
L1 carries the back-pointer line; the TopBar Learn dropdown shows a
check on completed tracks (lib/learnProgress.ts over quda.learnLabDone
/ quda.lessonsDone).
Shared pieces: useDrawLoop (30ms batch stagger + reduced-motion sync
path, extracted from step 1's idiom), PairGrid, BellRecipe; Dial snap
unified at ~200ms; glossary gains entanglement + noise. New test lanes
in check_quantum_toy.test.ts assert the step 3-5 claims: Bell tally
never disagrees, H(x)H fills all four cells, agreement ~= (1-eps)^2,
and the step-5 stop batch is deterministic. Gates: tsc, build,
VITE_ANON build (markers present, no name leakage), 5 node lanes, 86
backend tests.
- docs/EVIDENCE_WORKBENCH.md +28 -6
- frontend/scripts/check_quantum_toy.test.ts +66 -0
- frontend/src/components/LearnLab.tsx +30 -23
- frontend/src/components/LessonCard.tsx +21 -2
- frontend/src/components/MultiverseBoard.tsx +11 -1
- frontend/src/components/TopBar.tsx +16 -4
- frontend/src/components/WelcomeTour.tsx +15 -3
- frontend/src/components/learn/BellRecipe.tsx +148 -0
- frontend/src/components/learn/Dial.tsx +5 -4
- frontend/src/components/learn/PairGrid.tsx +65 -0
- frontend/src/components/learn/Step3Bell.tsx +201 -0
- frontend/src/components/learn/Step4Noise.tsx +214 -0
- frontend/src/components/learn/Step5Certainty.tsx +403 -0
- frontend/src/components/learn/useDrawLoop.ts +46 -0
- frontend/src/lib/glossary.ts +4 -0
- frontend/src/lib/learnProgress.ts +44 -0
- frontend/src/lib/store.ts +9 -0
|
@@ -1076,8 +1076,7 @@ itself only via APP_NAME, so anon builds show the neutral codename).
|
|
| 1076 |
localStorage `quda.lessonsDone`; glossary terms carry TipIcons.
|
| 1077 |
*Learn from zero (2026-07-12, marker `learn-lab`):* the track
|
| 1078 |
BEFORE the guided lessons, for readers who do not know what a
|
| 1079 |
-
qubit is. Six steps
|
| 1080 |
-
second pass: CX/Bell, readout noise, shots→wilson95) as a full
|
| 1081 |
center-column overlay (components/LearnLab.tsx, same pattern as
|
| 1082 |
board/theater; step components in components/learn/; progress in
|
| 1083 |
localStorage `quda.learnLabStep`). It never touches the pipeline:
|
|
@@ -1091,10 +1090,33 @@ itself only via APP_NAME, so anon builds show the neutral codename).
|
|
| 1091 |
drawn with the lean's odds (the system's tallies-not-truths
|
| 1092 |
premise, planted in step 1), gates steer the lean on a wire. One
|
| 1093 |
bold idea sentence + one guiding line + one interactive per step;
|
| 1094 |
-
percentages only; TipIcons where qubit/measurement/shots
|
| 1095 |
-
appear.
|
| 1096 |
-
|
| 1097 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1098 |
2. **GMU theme removed entirely** — theme.ts (ThemeKey = light|dark),
|
| 1099 |
index.css token block, vite.config.ts %THEME_KEYS% (now always
|
| 1100 |
["dark"]) and the anon CSS-stripping generateBundle hook (nothing
|
|
|
|
| 1076 |
localStorage `quda.lessonsDone`; glossary terms carry TipIcons.
|
| 1077 |
*Learn from zero (2026-07-12, marker `learn-lab`):* the track
|
| 1078 |
BEFORE the guided lessons, for readers who do not know what a
|
| 1079 |
+
qubit is. Six steps, complete since the second pass, as a full
|
|
|
|
| 1080 |
center-column overlay (components/LearnLab.tsx, same pattern as
|
| 1081 |
board/theater; step components in components/learn/; progress in
|
| 1082 |
localStorage `quda.learnLabStep`). It never touches the pipeline:
|
|
|
|
| 1090 |
drawn with the lean's odds (the system's tallies-not-truths
|
| 1091 |
premise, planted in step 1), gates steer the lean on a wire. One
|
| 1092 |
bold idea sentence + one guiding line + one interactive per step;
|
| 1093 |
+
percentages only; TipIcons where qubit/measurement/shots/
|
| 1094 |
+
entanglement/noise/fidelity/interval first appear. Steps 3-5
|
| 1095 |
+
(marker `learn-complete`): step 3 measures the pre-wired Bell
|
| 1096 |
+
recipe — both needles snap TOGETHER, only 00/11 populate the 2×2
|
| 1097 |
+
PairGrid, and "break the link" swaps CX for H⊗H (NOT mere
|
| 1098 |
+
deletion, which would pin q1 at 0 — see BellRecipe.tsx) so all
|
| 1099 |
+
four cells fill as the honest independent contrast; step 4 adds a
|
| 1100 |
+
perfect/noisy machine switch (applyReadoutNoise, eps slider
|
| 1101 |
+
0-15%) — 01/10 leak warn-tinted counts and the live agreement
|
| 1102 |
+
score (reported pair == drawn pair; ≈88% at 6% noise, both bits
|
| 1103 |
+
must survive) is fidelity in miniature, bridged explicitly to the
|
| 1104 |
+
Noisy simulator block; step 5 plots that score as a LIVE mini
|
| 1105 |
+
funnel in the theater's exact grammar (per-batch wilson95
|
| 1106 |
+
interval bars + convergence envelope + point path, fixed axis,
|
| 1107 |
+
460×200) with "look ×50" and "auto to ±2pp" optional stopping
|
| 1108 |
+
(stop line + "the rest of the budget is yours to keep"). All
|
| 1109 |
+
step 3-5 claims are asserted in scripts/check_quantum_toy.test.ts
|
| 1110 |
+
(Bell tally certainty, H⊗H contrast, agreement ≈ (1−eps)²,
|
| 1111 |
+
deterministic stop batch). Handoff design: step 5's footer marks
|
| 1112 |
+
localStorage `quda.learnLabDone` and either closes or opens the
|
| 1113 |
+
guided lessons DIRECTLY on L1 (store bridge `pendingLessonKey`;
|
| 1114 |
+
L1's card carries the back-pointer "fresh from the basics? this
|
| 1115 |
+
one runs the real thing"). Entry points: the TopBar "Learn"
|
| 1116 |
+
dropdown — "Start from zero" / "Guided experiments", each with a
|
| 1117 |
+
✓ once its track completes (lib/learnProgress.ts) — plus the
|
| 1118 |
+
board's empty state ("New to quantum? Start from zero" before the
|
| 1119 |
+
guided-experiments button) and tour slide 5 (both tracks).
|
| 1120 |
2. **GMU theme removed entirely** — theme.ts (ThemeKey = light|dark),
|
| 1121 |
index.css token block, vite.config.ts %THEME_KEYS% (now always
|
| 1122 |
["dark"]) and the anon CSS-stripping generateBundle hook (nothing
|
|
@@ -23,6 +23,7 @@ import {
|
|
| 23 |
zero1,
|
| 24 |
zero2,
|
| 25 |
} from "../src/lib/quantumToy.ts";
|
|
|
|
| 26 |
|
| 27 |
const close = (a: number, b: number, eps = 1e-12) =>
|
| 28 |
assert.ok(Math.abs(a - b) < eps, `${a} !~ ${b}`);
|
|
@@ -93,4 +94,69 @@ const close = (a: number, b: number, eps = 1e-12) =>
|
|
| 93 |
);
|
| 94 |
}
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
console.log("check_quantum_toy: all assertions passed");
|
|
|
|
| 23 |
zero1,
|
| 24 |
zero2,
|
| 25 |
} from "../src/lib/quantumToy.ts";
|
| 26 |
+
import { wilson95 } from "../src/lib/stats.ts";
|
| 27 |
|
| 28 |
const close = (a: number, b: number, eps = 1e-12) =>
|
| 29 |
assert.ok(Math.abs(a - b) < eps, `${a} !~ ${b}`);
|
|
|
|
| 94 |
);
|
| 95 |
}
|
| 96 |
|
| 97 |
+
// -- step 3's certainty claim: a Bell TALLY never disagrees ------------------
|
| 98 |
+
// "N looks: 00 and 11 only — never a disagreement" is stated with
|
| 99 |
+
// certainty in the UI, so it must hold for every draw, not on average.
|
| 100 |
+
{
|
| 101 |
+
const bell = applyCX(applyH2(zero2(), 0));
|
| 102 |
+
const tally = measureMany(bell, 500, mulberry32(20260703));
|
| 103 |
+
assert.equal((tally["01"] ?? 0) + (tally["10"] ?? 0), 0);
|
| 104 |
+
assert.equal((tally["00"] ?? 0) + (tally["11"] ?? 0), 500);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
// -- step 3's contrast: break-the-link = H⊗H, exactly uniform ---------------
|
| 108 |
+
// (H on both qubits, NOT just deleting CX — deleting it alone would
|
| 109 |
+
// pin q1 at 0; see components/learn/BellRecipe.tsx.) All four cells
|
| 110 |
+
// must actually populate in a modest seeded tally.
|
| 111 |
+
{
|
| 112 |
+
const indep = applyH2(applyH2(zero2(), 0), 1);
|
| 113 |
+
for (const p of probs(indep)) close(p, 0.25);
|
| 114 |
+
const tally = measureMany(indep, 400, mulberry32(20260703));
|
| 115 |
+
for (const bits of ["00", "01", "10", "11"])
|
| 116 |
+
assert.ok((tally[bits] ?? 0) > 0, `cell ${bits} never filled`);
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
// -- step 4's agreement score: reported-vs-drawn match rate ≈ (1−eps)² ------
|
| 120 |
+
// Both bits must survive readout for the pair to match, so at 6%
|
| 121 |
+
// noise the honest score sits near 88%, not 94% — the UI's live
|
| 122 |
+
// number must track this (seeded, so also deterministic).
|
| 123 |
+
{
|
| 124 |
+
const bell = applyCX(applyH2(zero2(), 0));
|
| 125 |
+
const rng = mulberry32(20260704);
|
| 126 |
+
const N = 4000;
|
| 127 |
+
let match = 0;
|
| 128 |
+
for (let i = 0; i < N; i++) {
|
| 129 |
+
const ideal = measureOnce(bell, rng);
|
| 130 |
+
if (applyReadoutNoise(ideal, 0.06, rng) === ideal) match += 1;
|
| 131 |
+
}
|
| 132 |
+
assert.ok(Math.abs(match / N - 0.8836) < 0.02, `agreement ${match / N}`);
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
// -- step 5's stop rule: wilson95 half-width hits ±2pp inside the budget -----
|
| 136 |
+
// Replays Step5Certainty's exact accumulation (seed, batch size,
|
| 137 |
+
// interval rule) and checks the auto-stop story: the target is
|
| 138 |
+
// reached before the 2000-look budget, and a second replay stops at
|
| 139 |
+
// the identical batch (deterministic funnel).
|
| 140 |
+
{
|
| 141 |
+
const run = (): number => {
|
| 142 |
+
const bell = applyCX(applyH2(zero2(), 0));
|
| 143 |
+
const rng = mulberry32(20260705);
|
| 144 |
+
let matches = 0;
|
| 145 |
+
let looks = 0;
|
| 146 |
+
while (looks < 2000) {
|
| 147 |
+
for (let i = 0; i < 50; i++) {
|
| 148 |
+
const ideal = measureOnce(bell, rng);
|
| 149 |
+
if (applyReadoutNoise(ideal, 0.06, rng) === ideal) matches += 1;
|
| 150 |
+
}
|
| 151 |
+
looks += 50;
|
| 152 |
+
const [lo, hi] = wilson95(matches, looks);
|
| 153 |
+
if ((hi - lo) / 2 <= 0.02) return looks;
|
| 154 |
+
}
|
| 155 |
+
return -1;
|
| 156 |
+
};
|
| 157 |
+
const stopA = run();
|
| 158 |
+
assert.ok(stopA > 0, "±2pp never reached inside the 2000-look budget");
|
| 159 |
+
assert.equal(stopA, run()); // bit-identical replay
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
console.log("check_quantum_toy: all assertions passed");
|
|
@@ -1,9 +1,13 @@
|
|
| 1 |
import { useEffect, useState, type ComponentType } from "react";
|
| 2 |
import { ChevronLeft, ChevronRight, Sparkles, X } from "lucide-react";
|
|
|
|
| 3 |
import { useApp } from "../lib/store";
|
| 4 |
import { Step0Lean } from "./learn/Step0Lean";
|
| 5 |
import { Step1Measure } from "./learn/Step1Measure";
|
| 6 |
import { Step2Gates } from "./learn/Step2Gates";
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
/**
|
| 9 |
* Learn from zero (marker: learn-lab) — the beginner track that sits
|
|
@@ -24,11 +28,15 @@ import { Step2Gates } from "./learn/Step2Gates";
|
|
| 24 |
* guiding line (≤25 words), then the interactive. Task language, no
|
| 25 |
* formulas, percentages only; glossary TipIcons where a quantum term
|
| 26 |
* first appears (qubit → step 0, measurement → step 1, shots/gates →
|
| 27 |
-
* step 2).
|
| 28 |
*
|
| 29 |
-
* Steps 3–5
|
| 30 |
-
*
|
| 31 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
*/
|
| 33 |
const STEP_LS = "quda.learnLabStep";
|
| 34 |
|
|
@@ -47,14 +55,6 @@ interface LearnStep {
|
|
| 47 |
Comp: ComponentType<StepProps>;
|
| 48 |
}
|
| 49 |
|
| 50 |
-
function StepStub() {
|
| 51 |
-
return (
|
| 52 |
-
<div className="panel-alt p-6 text-center text-sm text-mute">
|
| 53 |
-
This step is still being written — the earlier ones work today.
|
| 54 |
-
</div>
|
| 55 |
-
);
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
const STEPS: LearnStep[] = [
|
| 59 |
{
|
| 60 |
title: "A bit that can lean",
|
|
@@ -77,24 +77,26 @@ const STEPS: LearnStep[] = [
|
|
| 77 |
"Put X and H gates on the wire and watch the dial at the end respond. Try H twice.",
|
| 78 |
Comp: Step2Gates,
|
| 79 |
},
|
| 80 |
-
// --- steps 3-5: second pass fills these (keep titles in sync) -----
|
| 81 |
{
|
| 82 |
title: "Two qubits, one fate",
|
| 83 |
-
idea: "
|
| 84 |
-
guide:
|
| 85 |
-
|
|
|
|
| 86 |
},
|
| 87 |
{
|
| 88 |
title: "Real machines misread",
|
| 89 |
-
idea: "
|
| 90 |
-
guide:
|
| 91 |
-
|
|
|
|
| 92 |
},
|
| 93 |
{
|
| 94 |
title: "How many looks is enough?",
|
| 95 |
-
idea: "More looks buy narrower
|
| 96 |
-
guide:
|
| 97 |
-
|
|
|
|
| 98 |
},
|
| 99 |
];
|
| 100 |
|
|
@@ -225,7 +227,12 @@ export function LearnLab() {
|
|
| 225 |
<button
|
| 226 |
type="button"
|
| 227 |
className="btn text-xs"
|
| 228 |
-
onClick={() =>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
>
|
| 230 |
Done — back to the workbench
|
| 231 |
</button>
|
|
|
|
| 1 |
import { useEffect, useState, type ComponentType } from "react";
|
| 2 |
import { ChevronLeft, ChevronRight, Sparkles, X } from "lucide-react";
|
| 3 |
+
import { markLearnLabDone } from "../lib/learnProgress";
|
| 4 |
import { useApp } from "../lib/store";
|
| 5 |
import { Step0Lean } from "./learn/Step0Lean";
|
| 6 |
import { Step1Measure } from "./learn/Step1Measure";
|
| 7 |
import { Step2Gates } from "./learn/Step2Gates";
|
| 8 |
+
import { Step3Bell } from "./learn/Step3Bell";
|
| 9 |
+
import { Step4Noise } from "./learn/Step4Noise";
|
| 10 |
+
import { Step5Certainty } from "./learn/Step5Certainty";
|
| 11 |
|
| 12 |
/**
|
| 13 |
* Learn from zero (marker: learn-lab) — the beginner track that sits
|
|
|
|
| 28 |
* guiding line (≤25 words), then the interactive. Task language, no
|
| 29 |
* formulas, percentages only; glossary TipIcons where a quantum term
|
| 30 |
* first appears (qubit → step 0, measurement → step 1, shots/gates →
|
| 31 |
+
* step 2, entanglement → 3, noise/fidelity → 4, interval → 5).
|
| 32 |
*
|
| 33 |
+
* Steps 3–5 (second pass; marker learn-complete lives in step 5):
|
| 34 |
+
* the Bell pair with a break-the-link contrast (Step3Bell), readout
|
| 35 |
+
* noise + the agreement score (Step4Noise), and how-many-looks with
|
| 36 |
+
* live wilson95 intervals in the theater's funnel grammar
|
| 37 |
+
* (Step5Certainty). Step 5 completes the track: quda.learnLabDone is
|
| 38 |
+
* set (TopBar shows a ✓) and the handoff either opens the guided
|
| 39 |
+
* lessons directly on L1 (store bridge pendingLessonKey) or closes.
|
| 40 |
*/
|
| 41 |
const STEP_LS = "quda.learnLabStep";
|
| 42 |
|
|
|
|
| 55 |
Comp: ComponentType<StepProps>;
|
| 56 |
}
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
const STEPS: LearnStep[] = [
|
| 59 |
{
|
| 60 |
title: "A bit that can lean",
|
|
|
|
| 77 |
"Put X and H gates on the wire and watch the dial at the end respond. Try H twice.",
|
| 78 |
Comp: Step2Gates,
|
| 79 |
},
|
|
|
|
| 80 |
{
|
| 81 |
title: "Two qubits, one fate",
|
| 82 |
+
idea: "Linked qubits answer together — see one, know the other.",
|
| 83 |
+
guide:
|
| 84 |
+
"Measure the pre-wired pair: both needles always land on the same side. Then break the link and watch all four cells fill.",
|
| 85 |
+
Comp: Step3Bell,
|
| 86 |
},
|
| 87 |
{
|
| 88 |
title: "Real machines misread",
|
| 89 |
+
idea: "Noise makes machines misread — fidelity is the honesty score.",
|
| 90 |
+
guide:
|
| 91 |
+
"Measure on the perfect machine, then switch to the noisy one — watch 01 and 10 leak in. Slide the noise to feel the dose.",
|
| 92 |
+
Comp: Step4Noise,
|
| 93 |
},
|
| 94 |
{
|
| 95 |
title: "How many looks is enough?",
|
| 96 |
+
idea: "More looks buy narrower certainty — buy only what you need.",
|
| 97 |
+
guide:
|
| 98 |
+
"Buy looks in batches of 50 and watch the band narrow — or let auto-stop call it at ±2 points.",
|
| 99 |
+
Comp: Step5Certainty,
|
| 100 |
},
|
| 101 |
];
|
| 102 |
|
|
|
|
| 227 |
<button
|
| 228 |
type="button"
|
| 229 |
className="btn text-xs"
|
| 230 |
+
onClick={() => {
|
| 231 |
+
// Reaching the last step and leaving through this
|
| 232 |
+
// button counts as completing the track too.
|
| 233 |
+
markLearnLabDone();
|
| 234 |
+
setOpen(false);
|
| 235 |
+
}}
|
| 236 |
>
|
| 237 |
Done — back to the workbench
|
| 238 |
</button>
|
|
@@ -9,6 +9,7 @@ import {
|
|
| 9 |
X,
|
| 10 |
} from "lucide-react";
|
| 11 |
import { gloss } from "../lib/glossary";
|
|
|
|
| 12 |
import { LESSONS, type Lesson, type LessonKey } from "../lib/lessons";
|
| 13 |
import { listRuns } from "../lib/runStore";
|
| 14 |
import { useApp } from "../lib/store";
|
|
@@ -33,8 +34,6 @@ import { TipIcon } from "./TipIcon";
|
|
| 33 |
* Progress persists in localStorage "quda.lessonsDone".
|
| 34 |
*/
|
| 35 |
|
| 36 |
-
const DONE_LS = "quda.lessonsDone";
|
| 37 |
-
|
| 38 |
function loadDone(): Set<LessonKey> {
|
| 39 |
try {
|
| 40 |
const raw = JSON.parse(localStorage.getItem(DONE_LS) ?? "[]");
|
|
@@ -79,6 +78,18 @@ export function LessonCard() {
|
|
| 79 |
lessonRuns.current = [];
|
| 80 |
};
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
const launch = (l: Lesson, idx: number) => {
|
| 83 |
const step = l.steps[idx];
|
| 84 |
const first = lessonRuns.current[0];
|
|
@@ -213,6 +224,14 @@ export function LessonCard() {
|
|
| 213 |
</div>
|
| 214 |
) : (
|
| 215 |
<div className="p-3">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
<p className="text-[11px] leading-snug text-ink">{lesson.question}</p>
|
| 217 |
<div className="mt-1.5 flex flex-wrap gap-1">
|
| 218 |
{lesson.terms.map((t) => (
|
|
|
|
| 9 |
X,
|
| 10 |
} from "lucide-react";
|
| 11 |
import { gloss } from "../lib/glossary";
|
| 12 |
+
import { LESSONS_DONE_LS as DONE_LS } from "../lib/learnProgress";
|
| 13 |
import { LESSONS, type Lesson, type LessonKey } from "../lib/lessons";
|
| 14 |
import { listRuns } from "../lib/runStore";
|
| 15 |
import { useApp } from "../lib/store";
|
|
|
|
| 34 |
* Progress persists in localStorage "quda.lessonsDone".
|
| 35 |
*/
|
| 36 |
|
|
|
|
|
|
|
| 37 |
function loadDone(): Set<LessonKey> {
|
| 38 |
try {
|
| 39 |
const raw = JSON.parse(localStorage.getItem(DONE_LS) ?? "[]");
|
|
|
|
| 78 |
lessonRuns.current = [];
|
| 79 |
};
|
| 80 |
|
| 81 |
+
// Handoff bridge: the learn-from-zero track asks us to open directly
|
| 82 |
+
// on a lesson (Step5Certainty sets pendingLessonKey before flipping
|
| 83 |
+
// lessonsOpen). Consume-and-clear, one shot.
|
| 84 |
+
const pendingKey = useApp((s) => s.pendingLessonKey);
|
| 85 |
+
useEffect(() => {
|
| 86 |
+
if (!open || pendingKey == null) return;
|
| 87 |
+
if (LESSONS.some((l) => l.key === pendingKey))
|
| 88 |
+
pickLesson(pendingKey as LessonKey);
|
| 89 |
+
useApp.getState().setPendingLessonKey(null);
|
| 90 |
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
| 91 |
+
}, [open, pendingKey]);
|
| 92 |
+
|
| 93 |
const launch = (l: Lesson, idx: number) => {
|
| 94 |
const step = l.steps[idx];
|
| 95 |
const first = lessonRuns.current[0];
|
|
|
|
| 224 |
</div>
|
| 225 |
) : (
|
| 226 |
<div className="p-3">
|
| 227 |
+
{/* back-pointer for learn-from-zero graduates: L1 is the
|
| 228 |
+
designed landing spot of the step-5 handoff */}
|
| 229 |
+
{lesson.key === "L1" && (
|
| 230 |
+
<p className="text-[10px] text-mute mb-1">
|
| 231 |
+
Fresh from the basics? This one runs the real thing — a live
|
| 232 |
+
pipeline, archived like any run.
|
| 233 |
+
</p>
|
| 234 |
+
)}
|
| 235 |
<p className="text-[11px] leading-snug text-ink">{lesson.question}</p>
|
| 236 |
<div className="mt-1.5 flex flex-wrap gap-1">
|
| 237 |
{lesson.terms.map((t) => (
|
|
@@ -55,6 +55,7 @@ import {
|
|
| 55 |
Plus,
|
| 56 |
Repeat,
|
| 57 |
RotateCcw,
|
|
|
|
| 58 |
Workflow,
|
| 59 |
X,
|
| 60 |
} from "lucide-react";
|
|
@@ -918,13 +919,22 @@ export function MultiverseBoard() {
|
|
| 918 |
>
|
| 919 |
<Workflow className="w-3.5 h-3.5" /> Define a configuration
|
| 920 |
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 921 |
<button
|
| 922 |
type="button"
|
| 923 |
className="btn"
|
| 924 |
title="Four guided micro-experiments — each runs one pipeline and points at the evidence it produced"
|
| 925 |
onClick={() => useApp.getState().setLessonsOpen(true)}
|
| 926 |
>
|
| 927 |
-
<GraduationCap className="w-3.5 h-3.5" />
|
| 928 |
</button>
|
| 929 |
</div>
|
| 930 |
</div>
|
|
|
|
| 55 |
Plus,
|
| 56 |
Repeat,
|
| 57 |
RotateCcw,
|
| 58 |
+
Sparkles,
|
| 59 |
Workflow,
|
| 60 |
X,
|
| 61 |
} from "lucide-react";
|
|
|
|
| 919 |
>
|
| 920 |
<Workflow className="w-3.5 h-3.5" /> Define a configuration
|
| 921 |
</button>
|
| 922 |
+
<button
|
| 923 |
+
type="button"
|
| 924 |
+
className="btn"
|
| 925 |
+
title="Six tiny interactives on a toy simulator — nothing assumed, not even what a qubit is"
|
| 926 |
+
onClick={() => useApp.getState().setLearnLabOpen(true)}
|
| 927 |
+
>
|
| 928 |
+
<Sparkles className="w-3.5 h-3.5" /> New to quantum? Start
|
| 929 |
+
from zero
|
| 930 |
+
</button>
|
| 931 |
<button
|
| 932 |
type="button"
|
| 933 |
className="btn"
|
| 934 |
title="Four guided micro-experiments — each runs one pipeline and points at the evidence it produced"
|
| 935 |
onClick={() => useApp.getState().setLessonsOpen(true)}
|
| 936 |
>
|
| 937 |
+
<GraduationCap className="w-3.5 h-3.5" /> Guided experiments
|
| 938 |
</button>
|
| 939 |
</div>
|
| 940 |
</div>
|
|
@@ -1,11 +1,12 @@
|
|
| 1 |
import { useCallback, useRef, useState } from "react";
|
| 2 |
import { useApp } from "../lib/store";
|
| 3 |
-
import { Activity, Compass, GraduationCap, PanelLeft, PanelRight, Zap } from "lucide-react";
|
| 4 |
import { APP_NAME, APP_TAGLINE } from "../lib/anon";
|
| 5 |
import { ClaimsMapButton } from "./ClaimsMap";
|
| 6 |
import { ThemeSwitcher } from "./ThemeSwitcher";
|
| 7 |
import { TipIcon } from "./TipIcon";
|
| 8 |
import { useDismissOn } from "../lib/useDismissOn";
|
|
|
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Top application bar — deliberately minimal since Wave P (the system
|
|
@@ -27,11 +28,16 @@ import { useDismissOn } from "../lib/useDismissOn";
|
|
| 27 |
* (LearnLab, marker learn-lab) teaches what a qubit even IS on the
|
| 28 |
* toy simulator; "Guided experiments" (LessonCard) runs the real
|
| 29 |
* pipeline. The from-zero track lists first because it is the one a
|
| 30 |
-
* reader with no background needs first.
|
|
|
|
| 31 |
function LearnMenu() {
|
| 32 |
const [open, setOpen] = useState(false);
|
| 33 |
const rootRef = useRef<HTMLDivElement>(null);
|
| 34 |
useDismissOn(open, rootRef, useCallback(() => setOpen(false), []));
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
const pick = (which: "zero" | "lessons") => {
|
| 36 |
const app = useApp.getState();
|
| 37 |
if (which === "zero") app.setLearnLabOpen(true);
|
|
@@ -64,8 +70,11 @@ function LearnMenu() {
|
|
| 64 |
onClick={() => pick("zero")}
|
| 65 |
className="w-full text-left px-2 py-1.5 rounded-md hover:bg-surfaceAlt transition-colors"
|
| 66 |
>
|
| 67 |
-
<span className="
|
| 68 |
Start from zero
|
|
|
|
|
|
|
|
|
|
| 69 |
</span>
|
| 70 |
<span className="block text-[10px] text-mute leading-snug">
|
| 71 |
What a qubit even is — six tiny interactives, nothing assumed.
|
|
@@ -77,8 +86,11 @@ function LearnMenu() {
|
|
| 77 |
onClick={() => pick("lessons")}
|
| 78 |
className="w-full text-left px-2 py-1.5 rounded-md hover:bg-surfaceAlt transition-colors"
|
| 79 |
>
|
| 80 |
-
<span className="
|
| 81 |
Guided experiments
|
|
|
|
|
|
|
|
|
|
| 82 |
</span>
|
| 83 |
<span className="block text-[10px] text-mute leading-snug">
|
| 84 |
Four micro-experiments in the real pipeline — sampling, noise,
|
|
|
|
| 1 |
import { useCallback, useRef, useState } from "react";
|
| 2 |
import { useApp } from "../lib/store";
|
| 3 |
+
import { Activity, Check, Compass, GraduationCap, PanelLeft, PanelRight, Zap } from "lucide-react";
|
| 4 |
import { APP_NAME, APP_TAGLINE } from "../lib/anon";
|
| 5 |
import { ClaimsMapButton } from "./ClaimsMap";
|
| 6 |
import { ThemeSwitcher } from "./ThemeSwitcher";
|
| 7 |
import { TipIcon } from "./TipIcon";
|
| 8 |
import { useDismissOn } from "../lib/useDismissOn";
|
| 9 |
+
import { areLessonsDone, isLearnLabDone } from "../lib/learnProgress";
|
| 10 |
|
| 11 |
/**
|
| 12 |
* Top application bar — deliberately minimal since Wave P (the system
|
|
|
|
| 28 |
* (LearnLab, marker learn-lab) teaches what a qubit even IS on the
|
| 29 |
* toy simulator; "Guided experiments" (LessonCard) runs the real
|
| 30 |
* pipeline. The from-zero track lists first because it is the one a
|
| 31 |
+
* reader with no background needs first. Completed tracks carry a ✓
|
| 32 |
+
* (lib/learnProgress flags, re-read every time the menu opens). */
|
| 33 |
function LearnMenu() {
|
| 34 |
const [open, setOpen] = useState(false);
|
| 35 |
const rootRef = useRef<HTMLDivElement>(null);
|
| 36 |
useDismissOn(open, rootRef, useCallback(() => setOpen(false), []));
|
| 37 |
+
// Completion ticks — read on open (localStorage is the source of
|
| 38 |
+
// truth; step 5 / the last lesson write it, possibly this session).
|
| 39 |
+
const zeroDone = open && isLearnLabDone();
|
| 40 |
+
const lessonsDone = open && areLessonsDone();
|
| 41 |
const pick = (which: "zero" | "lessons") => {
|
| 42 |
const app = useApp.getState();
|
| 43 |
if (which === "zero") app.setLearnLabOpen(true);
|
|
|
|
| 70 |
onClick={() => pick("zero")}
|
| 71 |
className="w-full text-left px-2 py-1.5 rounded-md hover:bg-surfaceAlt transition-colors"
|
| 72 |
>
|
| 73 |
+
<span className="flex items-center gap-1 text-xs text-ink font-medium">
|
| 74 |
Start from zero
|
| 75 |
+
{zeroDone && (
|
| 76 |
+
<Check className="w-3 h-3 text-ok" aria-label="completed" />
|
| 77 |
+
)}
|
| 78 |
</span>
|
| 79 |
<span className="block text-[10px] text-mute leading-snug">
|
| 80 |
What a qubit even is — six tiny interactives, nothing assumed.
|
|
|
|
| 86 |
onClick={() => pick("lessons")}
|
| 87 |
className="w-full text-left px-2 py-1.5 rounded-md hover:bg-surfaceAlt transition-colors"
|
| 88 |
>
|
| 89 |
+
<span className="flex items-center gap-1 text-xs text-ink font-medium">
|
| 90 |
Guided experiments
|
| 91 |
+
{lessonsDone && (
|
| 92 |
+
<Check className="w-3 h-3 text-ok" aria-label="completed" />
|
| 93 |
+
)}
|
| 94 |
</span>
|
| 95 |
<span className="block text-[10px] text-mute leading-snug">
|
| 96 |
Four micro-experiments in the real pipeline — sampling, noise,
|
|
@@ -554,7 +554,18 @@ function TrySlide({ onDone }: { onDone: () => void }) {
|
|
| 554 |
to the URL for the streaming-evidence teaser.
|
| 555 |
</p>
|
| 556 |
<p className="mt-1 text-[11px] text-mute">
|
| 557 |
-
New to quantum
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 558 |
<button
|
| 559 |
type="button"
|
| 560 |
className="underline decoration-dotted hover:text-ink"
|
|
@@ -563,9 +574,10 @@ function TrySlide({ onDone }: { onDone: () => void }) {
|
|
| 563 |
onDone();
|
| 564 |
}}
|
| 565 |
>
|
| 566 |
-
|
| 567 |
</button>{" "}
|
| 568 |
-
— four
|
|
|
|
| 569 |
</p>
|
| 570 |
</SlideShell>
|
| 571 |
);
|
|
|
|
| 554 |
to the URL for the streaming-evidence teaser.
|
| 555 |
</p>
|
| 556 |
<p className="mt-1 text-[11px] text-mute">
|
| 557 |
+
New to quantum?{" "}
|
| 558 |
+
<button
|
| 559 |
+
type="button"
|
| 560 |
+
className="underline decoration-dotted hover:text-ink"
|
| 561 |
+
onClick={() => {
|
| 562 |
+
useApp.getState().setLearnLabOpen(true);
|
| 563 |
+
onDone();
|
| 564 |
+
}}
|
| 565 |
+
>
|
| 566 |
+
Start from zero
|
| 567 |
+
</button>{" "}
|
| 568 |
+
— six tiny interactives, nothing assumed. Then{" "}
|
| 569 |
<button
|
| 570 |
type="button"
|
| 571 |
className="underline decoration-dotted hover:text-ink"
|
|
|
|
| 574 |
onDone();
|
| 575 |
}}
|
| 576 |
>
|
| 577 |
+
Guided experiments
|
| 578 |
</button>{" "}
|
| 579 |
+
— four micro-lessons in the real pipeline. Both live under "Learn"
|
| 580 |
+
in the top bar.
|
| 581 |
</p>
|
| 582 |
</SlideShell>
|
| 583 |
);
|
|
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* The fixed two-slot Bell recipe on two wires, read-only — steps 3
|
| 3 |
+
* and 4 share it. Slot 1: H on q0 (the mix). Slot 2: either the CX
|
| 4 |
+
* link (control dot on q0, ⊕ target on q1 — exactly the default
|
| 5 |
+
* wiring of lib/quantumToy.ts applyCX) or, with `broken`, an H on q1
|
| 6 |
+
* instead. NOTE the "break the link" contrast is H⊗H, not merely
|
| 7 |
+
* deleting CX: deleting it alone would pin q1 at 0 forever (only
|
| 8 |
+
* 00/10 could show), which reads as "q1 is dead", not "the qubits
|
| 9 |
+
* are independent". Giving each qubit its OWN mix keeps both dials
|
| 10 |
+
* at 50% and lets all four cells fill — the honest independent
|
| 11 |
+
* contrast to the linked pair.
|
| 12 |
+
*/
|
| 13 |
+
export function BellRecipe({
|
| 14 |
+
broken = false,
|
| 15 |
+
className = "w-full max-w-[290px]",
|
| 16 |
+
}: {
|
| 17 |
+
broken?: boolean;
|
| 18 |
+
className?: string;
|
| 19 |
+
}) {
|
| 20 |
+
const edge = "rgb(var(--color-edge))";
|
| 21 |
+
const accent = "rgb(var(--color-accent))";
|
| 22 |
+
const ink = "rgb(var(--color-ink))";
|
| 23 |
+
const mute = "rgb(var(--color-mute))";
|
| 24 |
+
const y0 = 30;
|
| 25 |
+
const y1 = 82;
|
| 26 |
+
const xH = 96; // slot 1 center
|
| 27 |
+
const xL = 186; // slot 2 center
|
| 28 |
+
const chip = (x: number, y: number) => (
|
| 29 |
+
<g>
|
| 30 |
+
<rect
|
| 31 |
+
x={x - 15}
|
| 32 |
+
y={y - 15}
|
| 33 |
+
width={30}
|
| 34 |
+
height={30}
|
| 35 |
+
rx={7}
|
| 36 |
+
fill={accent}
|
| 37 |
+
fillOpacity={0.12}
|
| 38 |
+
stroke={accent}
|
| 39 |
+
strokeOpacity={0.5}
|
| 40 |
+
/>
|
| 41 |
+
<text
|
| 42 |
+
x={x}
|
| 43 |
+
y={y + 4.5}
|
| 44 |
+
textAnchor="middle"
|
| 45 |
+
fontSize="13"
|
| 46 |
+
className="font-mono"
|
| 47 |
+
fill={accent}
|
| 48 |
+
>
|
| 49 |
+
H
|
| 50 |
+
</text>
|
| 51 |
+
</g>
|
| 52 |
+
);
|
| 53 |
+
return (
|
| 54 |
+
<svg
|
| 55 |
+
viewBox="0 0 290 108"
|
| 56 |
+
className={className}
|
| 57 |
+
role="img"
|
| 58 |
+
aria-label={
|
| 59 |
+
broken
|
| 60 |
+
? "recipe: a mix on q0 and a mix on q1 — no link between the qubits"
|
| 61 |
+
: "recipe: a mix on q0, then a controlled flip linking q0 to q1"
|
| 62 |
+
}
|
| 63 |
+
>
|
| 64 |
+
{[
|
| 65 |
+
{ y: y0, q: "q0" },
|
| 66 |
+
{ y: y1, q: "q1" },
|
| 67 |
+
].map(({ y, q }) => (
|
| 68 |
+
<g key={q}>
|
| 69 |
+
<text
|
| 70 |
+
x={2}
|
| 71 |
+
y={y + 3.5}
|
| 72 |
+
fontSize="10"
|
| 73 |
+
className="font-mono"
|
| 74 |
+
fill={mute}
|
| 75 |
+
>
|
| 76 |
+
{q}
|
| 77 |
+
</text>
|
| 78 |
+
<line x1={22} y1={y} x2={288} y2={y} stroke={edge} strokeWidth={2} />
|
| 79 |
+
<rect
|
| 80 |
+
x={30}
|
| 81 |
+
y={y - 11}
|
| 82 |
+
width={22}
|
| 83 |
+
height={22}
|
| 84 |
+
rx={5}
|
| 85 |
+
fill="rgb(var(--color-surface))"
|
| 86 |
+
stroke={edge}
|
| 87 |
+
/>
|
| 88 |
+
<text
|
| 89 |
+
x={41}
|
| 90 |
+
y={y + 3.5}
|
| 91 |
+
textAnchor="middle"
|
| 92 |
+
fontSize="11"
|
| 93 |
+
className="font-mono"
|
| 94 |
+
fill={ink}
|
| 95 |
+
>
|
| 96 |
+
0
|
| 97 |
+
</text>
|
| 98 |
+
</g>
|
| 99 |
+
))}
|
| 100 |
+
{chip(xH, y0)}
|
| 101 |
+
{broken ? (
|
| 102 |
+
<g>
|
| 103 |
+
{/* the removed link leaves an empty dashed slot on q0 */}
|
| 104 |
+
<rect
|
| 105 |
+
x={xL - 15}
|
| 106 |
+
y={y0 - 15}
|
| 107 |
+
width={30}
|
| 108 |
+
height={30}
|
| 109 |
+
rx={7}
|
| 110 |
+
fill="none"
|
| 111 |
+
stroke={edge}
|
| 112 |
+
strokeDasharray="3 3"
|
| 113 |
+
/>
|
| 114 |
+
{chip(xL, y1)}
|
| 115 |
+
</g>
|
| 116 |
+
) : (
|
| 117 |
+
<g>
|
| 118 |
+
<line x1={xL} y1={y0} x2={xL} y2={y1} stroke={accent} strokeWidth={2} />
|
| 119 |
+
<circle cx={xL} cy={y0} r={5} fill={accent} />
|
| 120 |
+
<circle
|
| 121 |
+
cx={xL}
|
| 122 |
+
cy={y1}
|
| 123 |
+
r={10}
|
| 124 |
+
fill="none"
|
| 125 |
+
stroke={accent}
|
| 126 |
+
strokeWidth={2}
|
| 127 |
+
/>
|
| 128 |
+
<line
|
| 129 |
+
x1={xL}
|
| 130 |
+
y1={y1 - 10}
|
| 131 |
+
x2={xL}
|
| 132 |
+
y2={y1 + 10}
|
| 133 |
+
stroke={accent}
|
| 134 |
+
strokeWidth={2}
|
| 135 |
+
/>
|
| 136 |
+
<line
|
| 137 |
+
x1={xL - 10}
|
| 138 |
+
y1={y1}
|
| 139 |
+
x2={xL + 10}
|
| 140 |
+
y2={y1}
|
| 141 |
+
stroke={accent}
|
| 142 |
+
strokeWidth={2}
|
| 143 |
+
/>
|
| 144 |
+
</g>
|
| 145 |
+
)}
|
| 146 |
+
</svg>
|
| 147 |
+
);
|
| 148 |
+
}
|
|
@@ -9,8 +9,9 @@ import { useCallback, useRef, useState } from "react";
|
|
| 9 |
* - `onChange` present → draggable (pointer capture; the whole svg is
|
| 10 |
* the hit target) and keyboard-adjustable (role=slider, arrows ±5pp).
|
| 11 |
* Absent → a read-only display dial (step 2's wire-end readout).
|
| 12 |
-
* - `snapped` (0|1) overrides the needle to a pole with a
|
| 13 |
-
* transition —
|
|
|
|
| 14 |
* showing the lean underneath, so collapse reads as "the needle
|
| 15 |
* left the lean", not "the lean changed".
|
| 16 |
* - Needle motion is one CSS transform transition (disabled while
|
|
@@ -150,7 +151,7 @@ export function Dial({
|
|
| 150 |
transition: dragging
|
| 151 |
? "none"
|
| 152 |
: snapped != null
|
| 153 |
-
? "transform
|
| 154 |
: "transform 240ms cubic-bezier(.2,.8,.3,1)",
|
| 155 |
}}
|
| 156 |
>
|
|
@@ -172,7 +173,7 @@ export function Dial({
|
|
| 172 |
snapped != null
|
| 173 |
? "rgb(var(--color-warn))"
|
| 174 |
: "rgb(var(--color-accent))",
|
| 175 |
-
transition: "fill
|
| 176 |
}}
|
| 177 |
/>
|
| 178 |
</g>
|
|
|
|
| 9 |
* - `onChange` present → draggable (pointer capture; the whole svg is
|
| 10 |
* the hit target) and keyboard-adjustable (role=slider, arrows ±5pp).
|
| 11 |
* Absent → a read-only display dial (step 2's wire-end readout).
|
| 12 |
+
* - `snapped` (0|1) overrides the needle to a pole with a snap
|
| 13 |
+
* transition (~200ms — the track-wide collapse timing, shared with
|
| 14 |
+
* step 3's pair of dials) — measurement collapse. The tinted arc keeps
|
| 15 |
* showing the lean underneath, so collapse reads as "the needle
|
| 16 |
* left the lean", not "the lean changed".
|
| 17 |
* - Needle motion is one CSS transform transition (disabled while
|
|
|
|
| 151 |
transition: dragging
|
| 152 |
? "none"
|
| 153 |
: snapped != null
|
| 154 |
+
? "transform 200ms cubic-bezier(.3,.9,.4,1)"
|
| 155 |
: "transform 240ms cubic-bezier(.2,.8,.3,1)",
|
| 156 |
}}
|
| 157 |
>
|
|
|
|
| 173 |
snapped != null
|
| 174 |
? "rgb(var(--color-warn))"
|
| 175 |
: "rgb(var(--color-accent))",
|
| 176 |
+
transition: "fill 200ms linear",
|
| 177 |
}}
|
| 178 |
/>
|
| 179 |
</g>
|
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* 2×2 outcome grid for the two-qubit steps — the Tally idiom (mono
|
| 3 |
+
* bitstring label, proportional bar, count) rearranged into the
|
| 4 |
+
* fourfold table a pair of bits actually has, so agreement (00/11,
|
| 5 |
+
* the Bell diagonal) and disagreement (01/10) sit on opposite
|
| 6 |
+
* diagonals of one small square. Color semantics shared with the
|
| 7 |
+
* rest of the system: populated expected cells tint accent; `leak`
|
| 8 |
+
* marks off-diagonal counts as readout misreads (step 4) and tints
|
| 9 |
+
* them warn instead. Row order is fixed so cells never jump.
|
| 10 |
+
*/
|
| 11 |
+
const ORDER = ["00", "01", "10", "11"] as const;
|
| 12 |
+
|
| 13 |
+
export function PairGrid({
|
| 14 |
+
counts,
|
| 15 |
+
leak = false,
|
| 16 |
+
}: {
|
| 17 |
+
counts: Record<string, number>;
|
| 18 |
+
/** Step 4: off-diagonal counts are misreads → warn tint. In step 3
|
| 19 |
+
* they are honest outcomes of the unlinked recipe → accent. */
|
| 20 |
+
leak?: boolean;
|
| 21 |
+
}) {
|
| 22 |
+
const total = ORDER.reduce((a, k) => a + (counts[k] ?? 0), 0);
|
| 23 |
+
const max = Math.max(1, ...ORDER.map((k) => counts[k] ?? 0));
|
| 24 |
+
return (
|
| 25 |
+
<div
|
| 26 |
+
className="grid grid-cols-2 gap-1.5 w-full max-w-[260px]"
|
| 27 |
+
role="group"
|
| 28 |
+
aria-label={`pair outcomes after ${total} looks`}
|
| 29 |
+
>
|
| 30 |
+
{ORDER.map((bits) => {
|
| 31 |
+
const c = counts[bits] ?? 0;
|
| 32 |
+
const agree = bits === "00" || bits === "11";
|
| 33 |
+
const isLeak = leak && !agree && c > 0;
|
| 34 |
+
return (
|
| 35 |
+
<div
|
| 36 |
+
key={bits}
|
| 37 |
+
className={`rounded-md border px-2 py-1.5 transition-colors ${
|
| 38 |
+
isLeak
|
| 39 |
+
? "border-warn/50 bg-warn/5"
|
| 40 |
+
: c > 0
|
| 41 |
+
? "border-accent/40 bg-accent/5"
|
| 42 |
+
: "border-edge bg-surfaceAlt/40"
|
| 43 |
+
}`}
|
| 44 |
+
aria-label={`outcome ${bits}: ${c}`}
|
| 45 |
+
>
|
| 46 |
+
<div className="flex items-center justify-between text-[10px]">
|
| 47 |
+
<span className={`font-mono ${c > 0 ? "text-ink" : "text-mute"}`}>
|
| 48 |
+
{bits}
|
| 49 |
+
</span>
|
| 50 |
+
<span className="font-mono text-mute tabular-nums">{c}</span>
|
| 51 |
+
</div>
|
| 52 |
+
<div className="mt-1 h-1.5 rounded bg-surfaceAlt overflow-hidden">
|
| 53 |
+
<div
|
| 54 |
+
className={`h-full transition-[width] duration-150 ease-out ${
|
| 55 |
+
isLeak ? "bg-warn/70" : "bg-accent/60"
|
| 56 |
+
}`}
|
| 57 |
+
style={{ width: `${(c / max) * 100}%` }}
|
| 58 |
+
/>
|
| 59 |
+
</div>
|
| 60 |
+
</div>
|
| 61 |
+
);
|
| 62 |
+
})}
|
| 63 |
+
</div>
|
| 64 |
+
);
|
| 65 |
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useEffect, useRef, useState } from "react";
|
| 2 |
+
import { Eye, Link2, Link2Off, RotateCcw } from "lucide-react";
|
| 3 |
+
import { gloss } from "../../lib/glossary";
|
| 4 |
+
import {
|
| 5 |
+
applyCX,
|
| 6 |
+
applyH2,
|
| 7 |
+
measureOnce,
|
| 8 |
+
mulberry32,
|
| 9 |
+
probs,
|
| 10 |
+
zero2,
|
| 11 |
+
type State2,
|
| 12 |
+
} from "../../lib/quantumToy";
|
| 13 |
+
import { TipIcon } from "../TipIcon";
|
| 14 |
+
import { BellRecipe } from "./BellRecipe";
|
| 15 |
+
import { Dial } from "./Dial";
|
| 16 |
+
import { PairGrid } from "./PairGrid";
|
| 17 |
+
import { useDrawLoop } from "./useDrawLoop";
|
| 18 |
+
|
| 19 |
+
/**
|
| 20 |
+
* Step 3 — "Two qubits, one fate." The fixed Bell recipe (H on q0,
|
| 21 |
+
* then CX — see BellRecipe for the wiring and for why "break the
|
| 22 |
+
* link" swaps in H⊗H rather than just deleting CX) feeds one exact
|
| 23 |
+
* two-qubit state; every look samples ONE four-way outcome and snaps
|
| 24 |
+
* BOTH needles to its bits — with the link, always the same side
|
| 25 |
+
* (the exact sim puts literally zero amplitude on 01/10, so "never a
|
| 26 |
+
* disagreement" is a certainty claim, like step 2's H·H). Both
|
| 27 |
+
* marginal dials read 50% in BOTH modes — that near-paradox is the
|
| 28 |
+
* point: each qubit alone looks identical, only the JOINT tally
|
| 29 |
+
* (the 2×2 grid) reveals the link.
|
| 30 |
+
*
|
| 31 |
+
* Seeded rng, reset on reset/toggle → every replay of a mode is
|
| 32 |
+
* deterministic. Batch animation timing lives in useDrawLoop.
|
| 33 |
+
*/
|
| 34 |
+
const SEED = 20260703;
|
| 35 |
+
const EMPTY: Record<string, number> = { "00": 0, "01": 0, "10": 0, "11": 0 };
|
| 36 |
+
|
| 37 |
+
function recipeState(broken: boolean): State2 {
|
| 38 |
+
const mixed = applyH2(zero2(), 0);
|
| 39 |
+
return broken ? applyH2(mixed, 1) : applyCX(mixed);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
export function Step3Bell() {
|
| 43 |
+
const [broken, setBroken] = useState(false);
|
| 44 |
+
const [counts, setCounts] = useState<Record<string, number>>({ ...EMPTY });
|
| 45 |
+
const [snap, setSnap] = useState<[0 | 1, 0 | 1] | null>(null);
|
| 46 |
+
const rng = useRef(mulberry32(SEED));
|
| 47 |
+
const unsnap = useRef<ReturnType<typeof setTimeout> | null>(null);
|
| 48 |
+
|
| 49 |
+
useEffect(
|
| 50 |
+
() => () => {
|
| 51 |
+
if (unsnap.current) clearTimeout(unsnap.current);
|
| 52 |
+
},
|
| 53 |
+
[],
|
| 54 |
+
);
|
| 55 |
+
|
| 56 |
+
const settle = () => {
|
| 57 |
+
if (unsnap.current) clearTimeout(unsnap.current);
|
| 58 |
+
unsnap.current = setTimeout(() => setSnap(null), 380);
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
const { running, run, stop } = useDrawLoop(() => {
|
| 62 |
+
const bits = measureOnce(recipeState(broken), rng.current);
|
| 63 |
+
setCounts((c) => ({ ...c, [bits]: (c[bits] ?? 0) + 1 }));
|
| 64 |
+
setSnap([bits[0] === "1" ? 1 : 0, bits[1] === "1" ? 1 : 0]);
|
| 65 |
+
settle();
|
| 66 |
+
});
|
| 67 |
+
|
| 68 |
+
const reset = () => {
|
| 69 |
+
stop();
|
| 70 |
+
if (unsnap.current) clearTimeout(unsnap.current);
|
| 71 |
+
setSnap(null);
|
| 72 |
+
setCounts({ ...EMPTY });
|
| 73 |
+
rng.current = mulberry32(SEED);
|
| 74 |
+
};
|
| 75 |
+
|
| 76 |
+
const toggleLink = () => {
|
| 77 |
+
// Different distribution → fresh deterministic tally.
|
| 78 |
+
setBroken((b) => !b);
|
| 79 |
+
reset();
|
| 80 |
+
};
|
| 81 |
+
|
| 82 |
+
const state = recipeState(broken);
|
| 83 |
+
const p = probs(state);
|
| 84 |
+
const pQ0 = p[2] + p[3]; // P(q0 reads 1) — 50% in both modes
|
| 85 |
+
const pQ1 = p[1] + p[3];
|
| 86 |
+
const total = Object.values(counts).reduce((a, b) => a + b, 0);
|
| 87 |
+
const disagree = (counts["01"] ?? 0) + (counts["10"] ?? 0);
|
| 88 |
+
|
| 89 |
+
return (
|
| 90 |
+
<div className="flex flex-col items-center gap-3">
|
| 91 |
+
<div className="flex flex-wrap items-center justify-center gap-x-6 gap-y-3">
|
| 92 |
+
<div className="flex flex-col items-center gap-1 max-w-[300px]">
|
| 93 |
+
<BellRecipe broken={broken} />
|
| 94 |
+
<p className="text-[10px] text-mute text-center leading-snug flex items-start gap-1">
|
| 95 |
+
<span>
|
| 96 |
+
{broken
|
| 97 |
+
? "no link — each qubit mixes and answers alone"
|
| 98 |
+
: "the second gate links them: whatever q0 answers, q1 must match"}
|
| 99 |
+
</span>
|
| 100 |
+
<TipIcon hint={gloss("entanglement")} size={10} />
|
| 101 |
+
</p>
|
| 102 |
+
</div>
|
| 103 |
+
<div className="flex items-start gap-4">
|
| 104 |
+
<div className="flex flex-col items-center">
|
| 105 |
+
<Dial value={pQ0} snapped={snap?.[0] ?? null} size={120} />
|
| 106 |
+
<div className="text-[10px] text-mute -mt-1 font-mono">q0</div>
|
| 107 |
+
</div>
|
| 108 |
+
<div className="flex flex-col items-center">
|
| 109 |
+
<Dial value={pQ1} snapped={snap?.[1] ?? null} size={120} />
|
| 110 |
+
<div className="text-[10px] text-mute -mt-1 font-mono">q1</div>
|
| 111 |
+
</div>
|
| 112 |
+
</div>
|
| 113 |
+
</div>
|
| 114 |
+
|
| 115 |
+
<div className="flex flex-wrap items-center justify-center gap-1.5">
|
| 116 |
+
<button
|
| 117 |
+
type="button"
|
| 118 |
+
className="btn-primary !px-2.5 !py-1 text-xs disabled:opacity-40"
|
| 119 |
+
disabled={running}
|
| 120 |
+
onClick={() => run(1)}
|
| 121 |
+
>
|
| 122 |
+
<Eye className="w-3.5 h-3.5" /> measure ×1
|
| 123 |
+
</button>
|
| 124 |
+
<button
|
| 125 |
+
type="button"
|
| 126 |
+
className="btn !px-2.5 !py-1 text-xs disabled:opacity-40"
|
| 127 |
+
disabled={running}
|
| 128 |
+
onClick={() => run(20)}
|
| 129 |
+
>
|
| 130 |
+
×20
|
| 131 |
+
</button>
|
| 132 |
+
<button
|
| 133 |
+
type="button"
|
| 134 |
+
className="btn !px-2.5 !py-1 text-xs disabled:opacity-40"
|
| 135 |
+
disabled={running}
|
| 136 |
+
onClick={() => run(100)}
|
| 137 |
+
>
|
| 138 |
+
auto-run 100
|
| 139 |
+
</button>
|
| 140 |
+
<button
|
| 141 |
+
type="button"
|
| 142 |
+
className="btn-ghost text-xs disabled:opacity-40"
|
| 143 |
+
disabled={running || total === 0}
|
| 144 |
+
onClick={reset}
|
| 145 |
+
aria-label="Reset the tally"
|
| 146 |
+
>
|
| 147 |
+
<RotateCcw className="w-3 h-3" /> reset
|
| 148 |
+
</button>
|
| 149 |
+
<button
|
| 150 |
+
type="button"
|
| 151 |
+
aria-pressed={broken}
|
| 152 |
+
disabled={running}
|
| 153 |
+
onClick={toggleLink}
|
| 154 |
+
className={`btn !px-2.5 !py-1 text-xs disabled:opacity-40 ${
|
| 155 |
+
broken ? "!border-warn/50 !text-warn" : ""
|
| 156 |
+
}`}
|
| 157 |
+
title={
|
| 158 |
+
broken
|
| 159 |
+
? "Put the CX link back — the pair answers together again"
|
| 160 |
+
: "Remove the link and give each qubit its own mix instead"
|
| 161 |
+
}
|
| 162 |
+
>
|
| 163 |
+
{broken ? (
|
| 164 |
+
<>
|
| 165 |
+
<Link2 className="w-3.5 h-3.5" /> relink them
|
| 166 |
+
</>
|
| 167 |
+
) : (
|
| 168 |
+
<>
|
| 169 |
+
<Link2Off className="w-3.5 h-3.5" /> break the link
|
| 170 |
+
</>
|
| 171 |
+
)}
|
| 172 |
+
</button>
|
| 173 |
+
</div>
|
| 174 |
+
|
| 175 |
+
<PairGrid counts={counts} />
|
| 176 |
+
|
| 177 |
+
<p
|
| 178 |
+
className="text-[11px] text-mute text-center tabular-nums"
|
| 179 |
+
aria-live="polite"
|
| 180 |
+
>
|
| 181 |
+
{total === 0 ? (
|
| 182 |
+
<>no looks yet — measure the pair to fill the grid</>
|
| 183 |
+
) : broken ? (
|
| 184 |
+
<>
|
| 185 |
+
{total} look{total === 1 ? "" : "s"}:{" "}
|
| 186 |
+
<span className="text-ink font-mono">{disagree}</span>{" "}
|
| 187 |
+
disagreement{disagree === 1 ? "" : "s"} — no link, each qubit
|
| 188 |
+
answers alone
|
| 189 |
+
</>
|
| 190 |
+
) : (
|
| 191 |
+
<>
|
| 192 |
+
{total} look{total === 1 ? "" : "s"}:{" "}
|
| 193 |
+
<span className="text-ink font-mono">00</span> and{" "}
|
| 194 |
+
<span className="text-ink font-mono">11</span> only — never a
|
| 195 |
+
disagreement
|
| 196 |
+
</>
|
| 197 |
+
)}
|
| 198 |
+
</p>
|
| 199 |
+
</div>
|
| 200 |
+
);
|
| 201 |
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useRef, useState } from "react";
|
| 2 |
+
import { Eye, RotateCcw } from "lucide-react";
|
| 3 |
+
import { gloss } from "../../lib/glossary";
|
| 4 |
+
import {
|
| 5 |
+
applyCX,
|
| 6 |
+
applyH2,
|
| 7 |
+
applyReadoutNoise,
|
| 8 |
+
measureOnce,
|
| 9 |
+
mulberry32,
|
| 10 |
+
zero2,
|
| 11 |
+
} from "../../lib/quantumToy";
|
| 12 |
+
import { TipIcon } from "../TipIcon";
|
| 13 |
+
import { BellRecipe } from "./BellRecipe";
|
| 14 |
+
import { PairGrid } from "./PairGrid";
|
| 15 |
+
import { useDrawLoop } from "./useDrawLoop";
|
| 16 |
+
|
| 17 |
+
/**
|
| 18 |
+
* Step 4 — "Real machines misread." Same Bell recipe, same 2×2 grid,
|
| 19 |
+
* but now a machine switch: the perfect machine reports each draw
|
| 20 |
+
* as-is, the noisy one pushes every reported bit through
|
| 21 |
+
* applyReadoutNoise (the symmetric readout-error model — the same
|
| 22 |
+
* model the backend's fake devices carry, measured from real device
|
| 23 |
+
* calibration). The 01/10 cells LEAK warn-tinted counts, and the
|
| 24 |
+
* agreement score = fraction of looks whose REPORTED pair matches
|
| 25 |
+
* what the machine actually drew — an honest per-draw fidelity the
|
| 26 |
+
* learner watches degrade as the eps slider rises (at 6% noise the
|
| 27 |
+
* score settles near 88%, because BOTH bits must survive:
|
| 28 |
+
* 0.94 × 0.94). Machine/eps changes reset the seeded rng, so every
|
| 29 |
+
* setting replays deterministically.
|
| 30 |
+
*/
|
| 31 |
+
const SEED = 20260704;
|
| 32 |
+
const BELL = applyCX(applyH2(zero2(), 0));
|
| 33 |
+
const EMPTY: Record<string, number> = { "00": 0, "01": 0, "10": 0, "11": 0 };
|
| 34 |
+
|
| 35 |
+
export function Step4Noise() {
|
| 36 |
+
const [noisy, setNoisy] = useState(false);
|
| 37 |
+
const [eps, setEps] = useState(0.06);
|
| 38 |
+
const [counts, setCounts] = useState<Record<string, number>>({ ...EMPTY });
|
| 39 |
+
const [matches, setMatches] = useState(0);
|
| 40 |
+
const rng = useRef(mulberry32(SEED));
|
| 41 |
+
|
| 42 |
+
const { running, run, stop } = useDrawLoop(() => {
|
| 43 |
+
const ideal = measureOnce(BELL, rng.current);
|
| 44 |
+
const shown = noisy ? applyReadoutNoise(ideal, eps, rng.current) : ideal;
|
| 45 |
+
setCounts((c) => ({ ...c, [shown]: (c[shown] ?? 0) + 1 }));
|
| 46 |
+
if (shown === ideal) setMatches((m) => m + 1);
|
| 47 |
+
});
|
| 48 |
+
|
| 49 |
+
const reset = () => {
|
| 50 |
+
stop();
|
| 51 |
+
setCounts({ ...EMPTY });
|
| 52 |
+
setMatches(0);
|
| 53 |
+
rng.current = mulberry32(SEED);
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
const pickMachine = (n: boolean) => {
|
| 57 |
+
if (n === noisy) return;
|
| 58 |
+
setNoisy(n);
|
| 59 |
+
reset(); // different reporting → fresh deterministic tally
|
| 60 |
+
};
|
| 61 |
+
|
| 62 |
+
const setNoise = (e: number) => {
|
| 63 |
+
setEps(e);
|
| 64 |
+
reset();
|
| 65 |
+
};
|
| 66 |
+
|
| 67 |
+
const total = Object.values(counts).reduce((a, b) => a + b, 0);
|
| 68 |
+
const leaked = (counts["01"] ?? 0) + (counts["10"] ?? 0);
|
| 69 |
+
const agreePct = total > 0 ? Math.round((matches / total) * 100) : 100;
|
| 70 |
+
const epsPct = Math.round(eps * 100);
|
| 71 |
+
|
| 72 |
+
return (
|
| 73 |
+
<div className="flex flex-col items-center gap-3">
|
| 74 |
+
<div className="flex flex-wrap items-center justify-center gap-x-6 gap-y-2">
|
| 75 |
+
<BellRecipe className="w-full max-w-[240px]" />
|
| 76 |
+
<div className="flex flex-col items-center gap-2">
|
| 77 |
+
<div className="flex items-center gap-1.5">
|
| 78 |
+
<div
|
| 79 |
+
role="group"
|
| 80 |
+
aria-label="which machine reports the outcomes"
|
| 81 |
+
className="flex items-center rounded-lg border border-edge overflow-hidden"
|
| 82 |
+
>
|
| 83 |
+
<button
|
| 84 |
+
type="button"
|
| 85 |
+
aria-pressed={!noisy}
|
| 86 |
+
disabled={running}
|
| 87 |
+
onClick={() => pickMachine(false)}
|
| 88 |
+
className={`px-2.5 py-1 text-xs transition-colors disabled:opacity-40 ${
|
| 89 |
+
!noisy
|
| 90 |
+
? "bg-accent/15 text-ink"
|
| 91 |
+
: "text-mute hover:text-ink"
|
| 92 |
+
}`}
|
| 93 |
+
>
|
| 94 |
+
perfect machine
|
| 95 |
+
</button>
|
| 96 |
+
<button
|
| 97 |
+
type="button"
|
| 98 |
+
aria-pressed={noisy}
|
| 99 |
+
disabled={running}
|
| 100 |
+
onClick={() => pickMachine(true)}
|
| 101 |
+
className={`px-2.5 py-1 text-xs transition-colors disabled:opacity-40 ${
|
| 102 |
+
noisy ? "bg-warn/15 text-ink" : "text-mute hover:text-ink"
|
| 103 |
+
}`}
|
| 104 |
+
>
|
| 105 |
+
noisy machine
|
| 106 |
+
</button>
|
| 107 |
+
</div>
|
| 108 |
+
<TipIcon hint={gloss("noise")} size={11} />
|
| 109 |
+
</div>
|
| 110 |
+
<label
|
| 111 |
+
className={`flex items-center gap-2 text-[10px] text-mute ${
|
| 112 |
+
noisy ? "" : "opacity-40"
|
| 113 |
+
}`}
|
| 114 |
+
>
|
| 115 |
+
machine noise
|
| 116 |
+
<input
|
| 117 |
+
type="range"
|
| 118 |
+
min={0}
|
| 119 |
+
max={15}
|
| 120 |
+
step={1}
|
| 121 |
+
value={epsPct}
|
| 122 |
+
disabled={!noisy || running}
|
| 123 |
+
onChange={(e) => setNoise(Number(e.target.value) / 100)}
|
| 124 |
+
className="w-28 accent-[rgb(var(--color-warn))]"
|
| 125 |
+
aria-label="machine noise, percent of bits misread"
|
| 126 |
+
/>
|
| 127 |
+
<span className="font-mono text-ink tabular-nums w-8">
|
| 128 |
+
{epsPct}%
|
| 129 |
+
</span>
|
| 130 |
+
</label>
|
| 131 |
+
</div>
|
| 132 |
+
</div>
|
| 133 |
+
|
| 134 |
+
<div className="flex flex-wrap items-center justify-center gap-1.5">
|
| 135 |
+
<button
|
| 136 |
+
type="button"
|
| 137 |
+
className="btn-primary !px-2.5 !py-1 text-xs disabled:opacity-40"
|
| 138 |
+
disabled={running}
|
| 139 |
+
onClick={() => run(1)}
|
| 140 |
+
>
|
| 141 |
+
<Eye className="w-3.5 h-3.5" /> measure ×1
|
| 142 |
+
</button>
|
| 143 |
+
<button
|
| 144 |
+
type="button"
|
| 145 |
+
className="btn !px-2.5 !py-1 text-xs disabled:opacity-40"
|
| 146 |
+
disabled={running}
|
| 147 |
+
onClick={() => run(20)}
|
| 148 |
+
>
|
| 149 |
+
×20
|
| 150 |
+
</button>
|
| 151 |
+
<button
|
| 152 |
+
type="button"
|
| 153 |
+
className="btn !px-2.5 !py-1 text-xs disabled:opacity-40"
|
| 154 |
+
disabled={running}
|
| 155 |
+
onClick={() => run(100)}
|
| 156 |
+
>
|
| 157 |
+
auto-run 100
|
| 158 |
+
</button>
|
| 159 |
+
<button
|
| 160 |
+
type="button"
|
| 161 |
+
className="btn-ghost text-xs disabled:opacity-40"
|
| 162 |
+
disabled={running || total === 0}
|
| 163 |
+
onClick={reset}
|
| 164 |
+
aria-label="Reset the tally"
|
| 165 |
+
>
|
| 166 |
+
<RotateCcw className="w-3 h-3" /> reset
|
| 167 |
+
</button>
|
| 168 |
+
</div>
|
| 169 |
+
|
| 170 |
+
<PairGrid counts={counts} leak />
|
| 171 |
+
|
| 172 |
+
{total > 0 && (
|
| 173 |
+
<p className="text-[11px] text-center tabular-nums" aria-live="polite">
|
| 174 |
+
<span className="text-mute">agreement score: </span>
|
| 175 |
+
<span className="font-mono text-ok">{agreePct}%</span>
|
| 176 |
+
{noisy ? (
|
| 177 |
+
<>
|
| 178 |
+
<span className="text-mute"> — on a perfect machine it is </span>
|
| 179 |
+
<span className="font-mono text-ink">100%</span>
|
| 180 |
+
</>
|
| 181 |
+
) : (
|
| 182 |
+
<span className="text-mute">
|
| 183 |
+
{" "}
|
| 184 |
+
— this machine reports every draw as it happened
|
| 185 |
+
</span>
|
| 186 |
+
)}{" "}
|
| 187 |
+
<TipIcon hint={gloss("fidelity")} size={10} />
|
| 188 |
+
</p>
|
| 189 |
+
)}
|
| 190 |
+
<p className="text-[11px] text-mute text-center tabular-nums">
|
| 191 |
+
{total === 0 ? (
|
| 192 |
+
<>no looks yet — the grid and the score fill as you measure</>
|
| 193 |
+
) : noisy ? (
|
| 194 |
+
<>
|
| 195 |
+
{total} look{total === 1 ? "" : "s"}:{" "}
|
| 196 |
+
<span className="text-warn font-mono">{leaked}</span> misread
|
| 197 |
+
{leaked === 1 ? "" : "s"} leaked into 01/10
|
| 198 |
+
</>
|
| 199 |
+
) : (
|
| 200 |
+
<>
|
| 201 |
+
{total} look{total === 1 ? "" : "s"}: 00 and 11 only — this
|
| 202 |
+
machine never misreads
|
| 203 |
+
</>
|
| 204 |
+
)}
|
| 205 |
+
</p>
|
| 206 |
+
|
| 207 |
+
<p className="text-[11px] leading-snug text-mute border-l-2 border-accent/50 pl-2 max-w-md">
|
| 208 |
+
The workbench's <span className="text-ink">Noisy simulator</span>{" "}
|
| 209 |
+
block is exactly this — its misread rates measured on real device
|
| 210 |
+
data.
|
| 211 |
+
</p>
|
| 212 |
+
</div>
|
| 213 |
+
);
|
| 214 |
+
}
|
|
@@ -0,0 +1,403 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useEffect, useRef, useState } from "react";
|
| 2 |
+
import { Eye, GraduationCap, RotateCcw, Target } from "lucide-react";
|
| 3 |
+
import { gloss } from "../../lib/glossary";
|
| 4 |
+
import { markLearnLabDone } from "../../lib/learnProgress";
|
| 5 |
+
import {
|
| 6 |
+
applyCX,
|
| 7 |
+
applyH2,
|
| 8 |
+
applyReadoutNoise,
|
| 9 |
+
measureOnce,
|
| 10 |
+
mulberry32,
|
| 11 |
+
zero2,
|
| 12 |
+
} from "../../lib/quantumToy";
|
| 13 |
+
import { wilson95 } from "../../lib/stats";
|
| 14 |
+
import { useApp } from "../../lib/store";
|
| 15 |
+
import { TipIcon } from "../TipIcon";
|
| 16 |
+
|
| 17 |
+
/**
|
| 18 |
+
* Step 5 — "How many looks is enough?" Step 4's noisy Bell agreement
|
| 19 |
+
* score (eps pinned at 6%) becomes the quantity under estimation, and
|
| 20 |
+
* the display is a LIVE mini funnel in the Evidence Theater's exact
|
| 21 |
+
* visual grammar — per-batch vertical 95% Wilson interval bars
|
| 22 |
+
* (lib/stats.ts wilson95, THE system-wide interval), a shaded
|
| 23 |
+
* convergence envelope, an ink point path, opacity ramping toward
|
| 24 |
+
* now — at postcard size (460×200 viewBox), so when the learner meets
|
| 25 |
+
* the real funnel it already reads as a known object. Fixed y-domain:
|
| 26 |
+
* the axis never re-zooms under the viewer (same theater rule).
|
| 27 |
+
*
|
| 28 |
+
* "auto to ±2pp" is optional stopping made tactile: batches of 50
|
| 29 |
+
* until the Wilson half-width ≤ 2pp (at the true score ≈ 88.4% that
|
| 30 |
+
* lands near 1000 looks, comfortably inside the 2000-look budget),
|
| 31 |
+
* then a stop line — the workbench's precision target, one step
|
| 32 |
+
* early. Reduced motion: the auto run lands in one synchronous
|
| 33 |
+
* update. Seeded rng → the whole trajectory replays exactly.
|
| 34 |
+
*
|
| 35 |
+
* The handoff footer (marker: learn-complete) closes the loop: mark
|
| 36 |
+
* quda.learnLabDone, then either open the guided lessons directly on
|
| 37 |
+
* L1 (store bridge pendingLessonKey) or just close the overlay.
|
| 38 |
+
*/
|
| 39 |
+
const SEED = 20260705;
|
| 40 |
+
const EPS = 0.06;
|
| 41 |
+
const BATCH = 50;
|
| 42 |
+
const BUDGET = 2000;
|
| 43 |
+
const TARGET_HALF = 0.02;
|
| 44 |
+
const BELL = applyCX(applyH2(zero2(), 0));
|
| 45 |
+
|
| 46 |
+
interface Frame {
|
| 47 |
+
looks: number;
|
| 48 |
+
point: number;
|
| 49 |
+
lo: number;
|
| 50 |
+
hi: number;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
// funnel geometry — theater grammar at postcard size
|
| 54 |
+
const W = 460;
|
| 55 |
+
const H = 200;
|
| 56 |
+
const M = { l: 44, r: 12, t: 12, b: 26 };
|
| 57 |
+
const Y_LO = 0.7;
|
| 58 |
+
const Y_HI = 1.0;
|
| 59 |
+
const xOf = (looks: number) => M.l + (looks / BUDGET) * (W - M.l - M.r);
|
| 60 |
+
const yOf = (p: number) =>
|
| 61 |
+
M.t +
|
| 62 |
+
(1 - (Math.min(Y_HI, Math.max(Y_LO, p)) - Y_LO) / (Y_HI - Y_LO)) *
|
| 63 |
+
(H - M.t - M.b);
|
| 64 |
+
const fmtPp = (half: number) => (half * 100).toFixed(1);
|
| 65 |
+
|
| 66 |
+
export function Step5Certainty() {
|
| 67 |
+
const [frames, setFrames] = useState<Frame[]>([]);
|
| 68 |
+
const [stopped, setStopped] = useState<{
|
| 69 |
+
looks: number;
|
| 70 |
+
reached: boolean;
|
| 71 |
+
} | null>(null);
|
| 72 |
+
const [auto, setAuto] = useState(false);
|
| 73 |
+
const rng = useRef(mulberry32(SEED));
|
| 74 |
+
const matchesRef = useRef(0);
|
| 75 |
+
const looksRef = useRef(0);
|
| 76 |
+
const timer = useRef<ReturnType<typeof setInterval> | null>(null);
|
| 77 |
+
|
| 78 |
+
useEffect(
|
| 79 |
+
() => () => {
|
| 80 |
+
if (timer.current) clearInterval(timer.current);
|
| 81 |
+
},
|
| 82 |
+
[],
|
| 83 |
+
);
|
| 84 |
+
|
| 85 |
+
const oneBatch = (): Frame => {
|
| 86 |
+
for (let i = 0; i < BATCH; i++) {
|
| 87 |
+
const ideal = measureOnce(BELL, rng.current);
|
| 88 |
+
const shown = applyReadoutNoise(ideal, EPS, rng.current);
|
| 89 |
+
if (shown === ideal) matchesRef.current += 1;
|
| 90 |
+
}
|
| 91 |
+
looksRef.current += BATCH;
|
| 92 |
+
const [lo, hi] = wilson95(matchesRef.current, looksRef.current);
|
| 93 |
+
return {
|
| 94 |
+
looks: looksRef.current,
|
| 95 |
+
point: matchesRef.current / looksRef.current,
|
| 96 |
+
lo,
|
| 97 |
+
hi,
|
| 98 |
+
};
|
| 99 |
+
};
|
| 100 |
+
|
| 101 |
+
const spent = looksRef.current >= BUDGET;
|
| 102 |
+
|
| 103 |
+
const look50 = () => {
|
| 104 |
+
if (auto || spent) return;
|
| 105 |
+
const fr = oneBatch();
|
| 106 |
+
setFrames((f) => [...f, fr]);
|
| 107 |
+
};
|
| 108 |
+
|
| 109 |
+
const autoTo2pp = () => {
|
| 110 |
+
if (auto || spent || stopped != null) return;
|
| 111 |
+
const step = (): boolean => {
|
| 112 |
+
const fr = oneBatch();
|
| 113 |
+
setFrames((f) => [...f, fr]);
|
| 114 |
+
const half = (fr.hi - fr.lo) / 2;
|
| 115 |
+
if (half <= TARGET_HALF || fr.looks >= BUDGET) {
|
| 116 |
+
setStopped({ looks: fr.looks, reached: half <= TARGET_HALF });
|
| 117 |
+
return true;
|
| 118 |
+
}
|
| 119 |
+
return false;
|
| 120 |
+
};
|
| 121 |
+
const reduced =
|
| 122 |
+
typeof window !== "undefined" &&
|
| 123 |
+
window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
| 124 |
+
if (reduced) {
|
| 125 |
+
// Sync path: the whole accumulation in one update.
|
| 126 |
+
while (!step()) {
|
| 127 |
+
/* batches until the target or the budget */
|
| 128 |
+
}
|
| 129 |
+
return;
|
| 130 |
+
}
|
| 131 |
+
setAuto(true);
|
| 132 |
+
timer.current = setInterval(() => {
|
| 133 |
+
if (step()) {
|
| 134 |
+
if (timer.current) clearInterval(timer.current);
|
| 135 |
+
timer.current = null;
|
| 136 |
+
setAuto(false);
|
| 137 |
+
}
|
| 138 |
+
}, 120);
|
| 139 |
+
};
|
| 140 |
+
|
| 141 |
+
const reset = () => {
|
| 142 |
+
if (timer.current) clearInterval(timer.current);
|
| 143 |
+
timer.current = null;
|
| 144 |
+
setAuto(false);
|
| 145 |
+
setFrames([]);
|
| 146 |
+
setStopped(null);
|
| 147 |
+
rng.current = mulberry32(SEED);
|
| 148 |
+
matchesRef.current = 0;
|
| 149 |
+
looksRef.current = 0;
|
| 150 |
+
};
|
| 151 |
+
|
| 152 |
+
const handoff = (toLessons: boolean) => {
|
| 153 |
+
markLearnLabDone();
|
| 154 |
+
const app = useApp.getState();
|
| 155 |
+
app.setLearnLabOpen(false);
|
| 156 |
+
if (toLessons) {
|
| 157 |
+
app.setPendingLessonKey("L1");
|
| 158 |
+
app.setLessonsOpen(true);
|
| 159 |
+
}
|
| 160 |
+
};
|
| 161 |
+
|
| 162 |
+
const last = frames.length > 0 ? frames[frames.length - 1] : null;
|
| 163 |
+
const lastHalf = last ? (last.hi - last.lo) / 2 : null;
|
| 164 |
+
const env =
|
| 165 |
+
frames.length > 1
|
| 166 |
+
? frames.map((f) => `${xOf(f.looks)},${yOf(f.hi)}`).join(" ") +
|
| 167 |
+
" " +
|
| 168 |
+
[...frames]
|
| 169 |
+
.reverse()
|
| 170 |
+
.map((f) => `${xOf(f.looks)},${yOf(f.lo)}`)
|
| 171 |
+
.join(" ")
|
| 172 |
+
: "";
|
| 173 |
+
|
| 174 |
+
return (
|
| 175 |
+
<div className="flex flex-col items-center gap-3">
|
| 176 |
+
<div className="w-full max-w-[460px]">
|
| 177 |
+
<div className="text-[10px] uppercase tracking-wider text-mute mb-1 flex items-center gap-1">
|
| 178 |
+
agreement score vs looks — noisy machine, 6% noise{" "}
|
| 179 |
+
<TipIcon hint={gloss("ci")} size={10} />
|
| 180 |
+
</div>
|
| 181 |
+
<svg
|
| 182 |
+
viewBox={`0 0 ${W} ${H}`}
|
| 183 |
+
className="w-full"
|
| 184 |
+
role="img"
|
| 185 |
+
aria-label={
|
| 186 |
+
last
|
| 187 |
+
? `evidence funnel: after ${last.looks} looks the agreement score is ${Math.round(last.point * 100)}% with a 95% interval of ± ${fmtPp(lastHalf ?? 0)} percentage points${stopped?.reached ? `, stopped at the ±2 point target` : ""}`
|
| 188 |
+
: "empty evidence funnel — no looks bought yet"
|
| 189 |
+
}
|
| 190 |
+
>
|
| 191 |
+
{/* y gridlines, fixed domain (the axis never re-zooms) */}
|
| 192 |
+
{[0.7, 0.8, 0.9, 1.0].map((g) => (
|
| 193 |
+
<g key={g}>
|
| 194 |
+
<line
|
| 195 |
+
x1={M.l}
|
| 196 |
+
x2={W - M.r}
|
| 197 |
+
y1={yOf(g)}
|
| 198 |
+
y2={yOf(g)}
|
| 199 |
+
stroke="rgb(var(--color-edge))"
|
| 200 |
+
strokeWidth={1}
|
| 201 |
+
opacity={0.55}
|
| 202 |
+
/>
|
| 203 |
+
<text
|
| 204 |
+
x={M.l - 5}
|
| 205 |
+
y={yOf(g) + 3}
|
| 206 |
+
textAnchor="end"
|
| 207 |
+
fontSize={9}
|
| 208 |
+
fill="rgb(var(--color-mute))"
|
| 209 |
+
>
|
| 210 |
+
{Math.round(g * 100)}%
|
| 211 |
+
</text>
|
| 212 |
+
</g>
|
| 213 |
+
))}
|
| 214 |
+
{/* x axis: the looks budget */}
|
| 215 |
+
<line
|
| 216 |
+
x1={M.l}
|
| 217 |
+
x2={W - M.r}
|
| 218 |
+
y1={H - M.b}
|
| 219 |
+
y2={H - M.b}
|
| 220 |
+
stroke="rgb(var(--color-mute))"
|
| 221 |
+
strokeWidth={1}
|
| 222 |
+
/>
|
| 223 |
+
{[0, 500, 1000, 1500, 2000].map((t) => (
|
| 224 |
+
<g key={t}>
|
| 225 |
+
<line
|
| 226 |
+
x1={xOf(t)}
|
| 227 |
+
x2={xOf(t)}
|
| 228 |
+
y1={H - M.b}
|
| 229 |
+
y2={H - M.b + 4}
|
| 230 |
+
stroke="rgb(var(--color-mute))"
|
| 231 |
+
strokeWidth={1}
|
| 232 |
+
/>
|
| 233 |
+
<text
|
| 234 |
+
x={xOf(t)}
|
| 235 |
+
y={H - M.b + 14}
|
| 236 |
+
textAnchor="middle"
|
| 237 |
+
fontSize={9}
|
| 238 |
+
fill="rgb(var(--color-mute))"
|
| 239 |
+
>
|
| 240 |
+
{t === 0 ? "0 looks" : t}
|
| 241 |
+
</text>
|
| 242 |
+
</g>
|
| 243 |
+
))}
|
| 244 |
+
{/* convergence envelope — the funnel silhouette */}
|
| 245 |
+
{frames.length > 1 && (
|
| 246 |
+
<polygon
|
| 247 |
+
points={env}
|
| 248 |
+
fill="rgb(var(--color-accent))"
|
| 249 |
+
opacity={0.1}
|
| 250 |
+
/>
|
| 251 |
+
)}
|
| 252 |
+
{/* per-batch Wilson intervals, opacity ramping toward now */}
|
| 253 |
+
{frames.map((f, i) => (
|
| 254 |
+
<line
|
| 255 |
+
key={f.looks}
|
| 256 |
+
x1={xOf(f.looks)}
|
| 257 |
+
x2={xOf(f.looks)}
|
| 258 |
+
y1={yOf(f.hi)}
|
| 259 |
+
y2={yOf(f.lo)}
|
| 260 |
+
stroke="rgb(var(--color-accent))"
|
| 261 |
+
strokeWidth={2.5}
|
| 262 |
+
strokeLinecap="round"
|
| 263 |
+
opacity={0.35 + (0.55 * (i + 1)) / frames.length}
|
| 264 |
+
>
|
| 265 |
+
<title>{`after ${f.looks} looks: ${(f.point * 100).toFixed(1)}%, 95% interval ± ${fmtPp((f.hi - f.lo) / 2)}pp`}</title>
|
| 266 |
+
</line>
|
| 267 |
+
))}
|
| 268 |
+
{/* point path */}
|
| 269 |
+
{frames.length > 1 && (
|
| 270 |
+
<polyline
|
| 271 |
+
points={frames
|
| 272 |
+
.map((f) => `${xOf(f.looks)},${yOf(f.point)}`)
|
| 273 |
+
.join(" ")}
|
| 274 |
+
fill="none"
|
| 275 |
+
stroke="rgb(var(--color-ink))"
|
| 276 |
+
strokeWidth={1}
|
| 277 |
+
opacity={0.55}
|
| 278 |
+
/>
|
| 279 |
+
)}
|
| 280 |
+
{frames.map((f, i) => (
|
| 281 |
+
<circle
|
| 282 |
+
key={f.looks}
|
| 283 |
+
cx={xOf(f.looks)}
|
| 284 |
+
cy={yOf(f.point)}
|
| 285 |
+
r={i === frames.length - 1 ? 3.5 : 2.2}
|
| 286 |
+
fill="rgb(var(--color-accent))"
|
| 287 |
+
/>
|
| 288 |
+
))}
|
| 289 |
+
{/* the stop line — optional stopping made visible */}
|
| 290 |
+
{stopped?.reached && (
|
| 291 |
+
<g>
|
| 292 |
+
<line
|
| 293 |
+
x1={xOf(stopped.looks)}
|
| 294 |
+
x2={xOf(stopped.looks)}
|
| 295 |
+
y1={M.t}
|
| 296 |
+
y2={H - M.b}
|
| 297 |
+
stroke="rgb(var(--color-ok))"
|
| 298 |
+
strokeWidth={1.5}
|
| 299 |
+
strokeDasharray="4 3"
|
| 300 |
+
/>
|
| 301 |
+
<text
|
| 302 |
+
x={xOf(stopped.looks) + 4}
|
| 303 |
+
y={M.t + 9}
|
| 304 |
+
fontSize={9}
|
| 305 |
+
fill="rgb(var(--color-ok))"
|
| 306 |
+
>
|
| 307 |
+
stopped: ±2pp
|
| 308 |
+
</text>
|
| 309 |
+
</g>
|
| 310 |
+
)}
|
| 311 |
+
</svg>
|
| 312 |
+
</div>
|
| 313 |
+
|
| 314 |
+
<div className="flex flex-wrap items-center justify-center gap-1.5">
|
| 315 |
+
<button
|
| 316 |
+
type="button"
|
| 317 |
+
className="btn-primary !px-2.5 !py-1 text-xs disabled:opacity-40"
|
| 318 |
+
disabled={auto || spent}
|
| 319 |
+
onClick={look50}
|
| 320 |
+
>
|
| 321 |
+
<Eye className="w-3.5 h-3.5" /> look ×50
|
| 322 |
+
</button>
|
| 323 |
+
<button
|
| 324 |
+
type="button"
|
| 325 |
+
className="btn !px-2.5 !py-1 text-xs disabled:opacity-40"
|
| 326 |
+
disabled={auto || spent || stopped != null}
|
| 327 |
+
onClick={autoTo2pp}
|
| 328 |
+
title="Keep buying batches until the 95% interval is at most ±2 percentage points wide"
|
| 329 |
+
>
|
| 330 |
+
<Target className="w-3.5 h-3.5" /> auto to ±2pp
|
| 331 |
+
</button>
|
| 332 |
+
<button
|
| 333 |
+
type="button"
|
| 334 |
+
className="btn-ghost text-xs disabled:opacity-40"
|
| 335 |
+
disabled={auto || frames.length === 0}
|
| 336 |
+
onClick={reset}
|
| 337 |
+
aria-label="Reset the funnel"
|
| 338 |
+
>
|
| 339 |
+
<RotateCcw className="w-3 h-3" /> reset
|
| 340 |
+
</button>
|
| 341 |
+
</div>
|
| 342 |
+
|
| 343 |
+
<p
|
| 344 |
+
className="text-[11px] text-mute text-center tabular-nums"
|
| 345 |
+
aria-live="polite"
|
| 346 |
+
>
|
| 347 |
+
{last == null ? (
|
| 348 |
+
<>no looks yet — every look costs, so buy them in batches of 50</>
|
| 349 |
+
) : stopped?.reached ? (
|
| 350 |
+
<>
|
| 351 |
+
stopped: ±2pp reached after{" "}
|
| 352 |
+
<span className="text-ink font-mono">{stopped.looks}</span> looks —
|
| 353 |
+
the rest of the budget is yours to keep
|
| 354 |
+
</>
|
| 355 |
+
) : stopped != null ? (
|
| 356 |
+
<>
|
| 357 |
+
budget spent at {stopped.looks} looks before ±2pp — sometimes
|
| 358 |
+
certainty costs more than you have
|
| 359 |
+
</>
|
| 360 |
+
) : (
|
| 361 |
+
<>
|
| 362 |
+
after <span className="text-ink font-mono">{last.looks}</span>{" "}
|
| 363 |
+
looks: <span className="text-ink font-mono">
|
| 364 |
+
{Math.round(last.point * 100)}%
|
| 365 |
+
</span>{" "}
|
| 366 |
+
± <span className="text-ink font-mono">{fmtPp(lastHalf ?? 0)}</span>
|
| 367 |
+
pp — still narrowing
|
| 368 |
+
</>
|
| 369 |
+
)}
|
| 370 |
+
</p>
|
| 371 |
+
|
| 372 |
+
{/* handoff — the whole track lands here (marker: learn-complete) */}
|
| 373 |
+
<div
|
| 374 |
+
data-marker="learn-complete"
|
| 375 |
+
className="w-full border-t border-edge/60 pt-3 mt-1 flex flex-col items-center gap-2"
|
| 376 |
+
>
|
| 377 |
+
<p className="text-[11px] text-mute text-center">
|
| 378 |
+
That is the whole workbench:{" "}
|
| 379 |
+
<span className="text-ink">
|
| 380 |
+
real pipelines, honest intervals, evidence you can replay.
|
| 381 |
+
</span>
|
| 382 |
+
</p>
|
| 383 |
+
<div className="flex flex-wrap items-center justify-center gap-1.5">
|
| 384 |
+
<button
|
| 385 |
+
type="button"
|
| 386 |
+
className="btn-primary !px-2.5 !py-1 text-xs"
|
| 387 |
+
onClick={() => handoff(true)}
|
| 388 |
+
>
|
| 389 |
+
<GraduationCap className="w-3.5 h-3.5" /> Try it on a real
|
| 390 |
+
pipeline — Guided experiments
|
| 391 |
+
</button>
|
| 392 |
+
<button
|
| 393 |
+
type="button"
|
| 394 |
+
className="btn !px-2.5 !py-1 text-xs"
|
| 395 |
+
onClick={() => handoff(false)}
|
| 396 |
+
>
|
| 397 |
+
Explore on my own
|
| 398 |
+
</button>
|
| 399 |
+
</div>
|
| 400 |
+
</div>
|
| 401 |
+
</div>
|
| 402 |
+
);
|
| 403 |
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useEffect, useRef, useState } from "react";
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Shared batch-measurement loop for the learn track. Step 1 planted
|
| 5 |
+
* the idiom (draws land one per ~30ms so the tally visibly
|
| 6 |
+
* accumulates; ONE synchronous batch under prefers-reduced-motion);
|
| 7 |
+
* steps 3 and 4 reuse it via this hook so the timing and the
|
| 8 |
+
* reduced-motion sync path stay identical across steps. The step owns
|
| 9 |
+
* every piece of state — this hook only owns the interval timer.
|
| 10 |
+
* `drawOne` is re-read each render (ref), so it may close over state.
|
| 11 |
+
*/
|
| 12 |
+
export function useDrawLoop(drawOne: () => void) {
|
| 13 |
+
const [running, setRunning] = useState(false);
|
| 14 |
+
const timer = useRef<ReturnType<typeof setInterval> | null>(null);
|
| 15 |
+
const draw = useRef(drawOne);
|
| 16 |
+
draw.current = drawOne;
|
| 17 |
+
|
| 18 |
+
const stop = () => {
|
| 19 |
+
if (timer.current) clearInterval(timer.current);
|
| 20 |
+
timer.current = null;
|
| 21 |
+
setRunning(false);
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
+
// Unmount cleanup (returns stop as the destructor).
|
| 25 |
+
useEffect(() => stop, []);
|
| 26 |
+
|
| 27 |
+
const run = (n: number) => {
|
| 28 |
+
if (timer.current) return;
|
| 29 |
+
const reduced =
|
| 30 |
+
typeof window !== "undefined" &&
|
| 31 |
+
window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
| 32 |
+
if (n === 1 || reduced) {
|
| 33 |
+
// Single draw, or the whole batch in one update (sync path).
|
| 34 |
+
for (let i = 0; i < n; i++) draw.current();
|
| 35 |
+
return;
|
| 36 |
+
}
|
| 37 |
+
setRunning(true);
|
| 38 |
+
let i = 0;
|
| 39 |
+
timer.current = setInterval(() => {
|
| 40 |
+
draw.current();
|
| 41 |
+
if (++i >= n) stop();
|
| 42 |
+
}, 30);
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
return { running, run, stop };
|
| 46 |
+
}
|
|
@@ -25,6 +25,10 @@ export const GLOSSARY = {
|
|
| 25 |
"Depth = the longest sequence of operations that must run one after another. Deeper circuits accumulate more noise.",
|
| 26 |
gates:
|
| 27 |
"Gates = the individual operations in the circuit (like instructions in a program).",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
seed:
|
| 29 |
"Seed = the number that fixes all random draws in a run. Re-running with the same (pinned) seed reproduces the result bit-exactly.",
|
| 30 |
ci:
|
|
|
|
| 25 |
"Depth = the longest sequence of operations that must run one after another. Deeper circuits accumulate more noise.",
|
| 26 |
gates:
|
| 27 |
"Gates = the individual operations in the circuit (like instructions in a program).",
|
| 28 |
+
entanglement:
|
| 29 |
+
"Entanglement = a link between qubits prepared together: measure one and the other's answer is fixed too. Two-qubit gates like the controlled flip (CX) create it.",
|
| 30 |
+
noise:
|
| 31 |
+
"Noise = the small random errors a real machine adds \u2014 misfired operations, misread qubits. It blurs every tally; the agreement (fidelity) score says how much survives.",
|
| 32 |
seed:
|
| 33 |
"Seed = the number that fixes all random draws in a run. Re-running with the same (pinned) seed reproduces the result bit-exactly.",
|
| 34 |
ci:
|
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Cross-surface completion flags for the two learn tracks. Three
|
| 2 |
+
// surfaces need them far from where they are written (the TopBar
|
| 3 |
+
// Learn menu's checkmarks, the LessonCard's own progress list, the
|
| 4 |
+
// LearnLab handoff), so the localStorage keys live here — one source,
|
| 5 |
+
// same private-mode tolerance as the rest of the app's persistence.
|
| 6 |
+
|
| 7 |
+
import { LESSONS } from "./lessons";
|
| 8 |
+
|
| 9 |
+
/** "1" once the learn-from-zero track's step 5 hands off (any of its
|
| 10 |
+
* exit buttons — the two handoff actions or the frame's Done). */
|
| 11 |
+
export const LEARN_LAB_DONE_LS = "quda.learnLabDone";
|
| 12 |
+
/** JSON array of completed LessonKeys — written by LessonCard. */
|
| 13 |
+
export const LESSONS_DONE_LS = "quda.lessonsDone";
|
| 14 |
+
|
| 15 |
+
export function markLearnLabDone(): void {
|
| 16 |
+
try {
|
| 17 |
+
localStorage.setItem(LEARN_LAB_DONE_LS, "1");
|
| 18 |
+
} catch {
|
| 19 |
+
/* private mode — session-scoped progress is fine */
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
export function isLearnLabDone(): boolean {
|
| 24 |
+
try {
|
| 25 |
+
return localStorage.getItem(LEARN_LAB_DONE_LS) === "1";
|
| 26 |
+
} catch {
|
| 27 |
+
return false;
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
/** True when EVERY guided lesson is done (the track-level checkmark —
|
| 32 |
+
* per-lesson state stays LessonCard's business). */
|
| 33 |
+
export function areLessonsDone(): boolean {
|
| 34 |
+
try {
|
| 35 |
+
const raw: unknown = JSON.parse(
|
| 36 |
+
localStorage.getItem(LESSONS_DONE_LS) ?? "[]",
|
| 37 |
+
);
|
| 38 |
+
return (
|
| 39 |
+
Array.isArray(raw) && LESSONS.every((l) => raw.includes(l.key))
|
| 40 |
+
);
|
| 41 |
+
} catch {
|
| 42 |
+
return false;
|
| 43 |
+
}
|
| 44 |
+
}
|
|
@@ -192,6 +192,13 @@ interface AppState {
|
|
| 192 |
* TopBar Learn menu) live far from the App mount. */
|
| 193 |
learnLabOpen: boolean;
|
| 194 |
setLearnLabOpen: (v: boolean) => void;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
/**
|
| 196 |
* Theater overlay comparison (marker: theater-overlay). When two
|
| 197 |
* archived runs of the SAME configuration both carry sampled traces,
|
|
@@ -449,6 +456,8 @@ export const useApp = create<AppState>((set) => ({
|
|
| 449 |
setLessonsOpen: (v) => set({ lessonsOpen: v }),
|
| 450 |
learnLabOpen: false,
|
| 451 |
setLearnLabOpen: (v) => set({ learnLabOpen: v }),
|
|
|
|
|
|
|
| 452 |
theaterOverlayIds: null,
|
| 453 |
setTheaterOverlay: (ids) =>
|
| 454 |
set({ theaterOverlayIds: ids, ...(ids ? { theaterOpen: true } : {}) }),
|
|
|
|
| 192 |
* TopBar Learn menu) live far from the App mount. */
|
| 193 |
learnLabOpen: boolean;
|
| 194 |
setLearnLabOpen: (v: boolean) => void;
|
| 195 |
+
/** One-shot bridge from the learn-from-zero handoff into the guided
|
| 196 |
+
* lessons: LearnLab step 5 (Step5Certainty) sets a LessonKey here
|
| 197 |
+
* before flipping lessonsOpen; LessonCard consumes and clears it,
|
| 198 |
+
* opening directly on that lesson instead of the list. Plain
|
| 199 |
+
* string so the store never imports lib/lessons. */
|
| 200 |
+
pendingLessonKey: string | null;
|
| 201 |
+
setPendingLessonKey: (k: string | null) => void;
|
| 202 |
/**
|
| 203 |
* Theater overlay comparison (marker: theater-overlay). When two
|
| 204 |
* archived runs of the SAME configuration both carry sampled traces,
|
|
|
|
| 456 |
setLessonsOpen: (v) => set({ lessonsOpen: v }),
|
| 457 |
learnLabOpen: false,
|
| 458 |
setLearnLabOpen: (v) => set({ learnLabOpen: v }),
|
| 459 |
+
pendingLessonKey: null,
|
| 460 |
+
setPendingLessonKey: (k) => set({ pendingLessonKey: k }),
|
| 461 |
theaterOverlayIds: null,
|
| 462 |
setTheaterOverlay: (ids) =>
|
| 463 |
set({ theaterOverlayIds: ids, ...(ids ? { theaterOpen: true } : {}) }),
|