Educational quantum phase estimation lab in ONE pure-Python file: the full QPE circuit built from scratch on a classical statevector simulator β counting register, controlled-U^(2^k) as exact matrix powers, an inverse QFT graded against the direct DFT definition before it is trusted β with outcome probabilities read exactly off the final statevector, never sampled. When theta sits on the 2^t grid the distribution is a delta (theta = 13/32 at t = 5 gives probability 1.000000 on outcome 13); off-grid, the peak follows the Dirichlet kernel P = (1/2^(2t)) Β· sinΒ²(2^t ΟΞ΄) / sinΒ²(ΟΞ΄) and the simulator matches that closed form to ~1e-15 at five graded points (worst diff 4.7e-15). A precision ledger prices every accuracy claim (t bits cost 2^t β 1 controlled-U applications β 255 at t = 8 for a 0.00390625 grid), a labelled toy converts a rotation eigenphase recovered from the trace into an "energy" E = β2ΟΞΈ/Ο (error 0.170796 at t = 3 shrinking to 0.023534 at t = 8, inside the grid bound at every t), superposition inputs return both eigenphases with their Born weights (0.472807 and 0.472807) with leakage printed, and a from-scratch kNN classifier labels runs exact / confident / leaky / under-resolved from features the simulator itself measured.
Pure Python standard library. Zero dependencies. Zero network. Honest scope: the phases belong to LABELLED toy unitaries, the energy conversion is a labelled scale, and the simulator is classical β it pays 2^n amplitudes (512 at t = 8) for everything. No molecule's energy was computed, no quantum hardware ran, and no speedup is claimed. Every chemistry / hardware / cryptography / production use is a permanent HOLD gate (14 total).
β π§° Tech Stack Badges & Full Architecture Tech Stack
π Python 3.12, pure standard library (cmath, math, hashlib, json, sys) β zero dependencies, zero network, deterministic (double-run byte-identical)
ποΈ Quantum core: a from-scratch statevector simulator (single-qubit, controlled-2Γ2, controlled-phase, and swap gates by index arithmetic), controlled-U^(2^k) by repeated squaring, and an inverse QFT graded against the direct DFT definition in CHECKS
π Analysis core: the Dirichlet kernel P = (1/2^(2t)) Β· sinΒ²(2^t ΟΞ΄) / sinΒ²(ΟΞ΄) evaluated independently of the simulator and compared peak-by-peak; the rotation eigenphase recovered from the trace Ξ± = arccos(tr/2)
π§ TinyML kNN run classifier (from scratch, stdlib): exact / confident / leaky / under-resolved from (t, distance-to-grid in cells, peak probability), labels from the lab's own policy
πͺ Council seats: Gemini Argon 4 DECIDER (names-only, tighten-only) + Muse advisor (never overrides HOLD) + Google Flow plan-only (rendered = False, live = 0)
π« Not applicable β honestly. No blockchain, no Web3, no tokens: the "infrastructure" in this lab is a simulated counting register and a fractions-free phase readout inside one offline file. Cryptographic use is a permanent HOLD gate, not a feature. No fake badges here.
β βοΈ Platform Support & Hardware Architecture
π₯οΈ Pure Python β runs anywhere Python 3.12+ runs (Linux, macOS, Windows), plus the python:3.12-slim Docker image
π No quantum hardware is touched, ever: real QPUs, cloud quantum services, and cryogenic plant are permanent HOLD gates (see the gate table below)
π« No low-level code β honestly. No C, no C++, no GPU, no compiled extensions: this is one interpreted Python file on purpose, so every amplitude can be read, checked, and diffed. Performance here means honest counting β the simulator's own exponential cost (2^(t+1) amplitudes) is printed in the ledger wherever a size appears, and it is never merged with the gate-count story into a "speedup" headline.
π« None β honestly. No cloud provider is used or needed: the lab runs fully offline on your own machine or in a local Docker container. Docker Hub appears only as the registry the publish workflow pushes the image to.
Exact phases, delta distributions β theta = 13/32 at t = 5 returns outcome 13 with probability 1.000000 and 0.000000 elsewhere; theta = 0 and theta = 6/16 check the same way. A whole number of turns per controlled power interferes onto exactly one cell.
Dirichlet grading β off-grid peaks match the closed form (1/2^(2t)) Β· sinΒ²(2^t ΟΞ΄) / sinΒ²(ΟΞ΄) at (t, theta) = (4, 0.31), (5, 0.3), (6, 0.707), (7, 0.1234), (8, 0.3) with worst disagreement 4.7e-15; at the worst offset (half a cell) the peak still holds β₯ 4/ΟΒ² β 0.405.
Within-1-cell table, oscillations kept β for theta = 0.3 the probability of landing within one cell runs 0.836857 / 0.930739 / 0.827948 / 0.929893 / 0.827395 / 0.929840 for t = 3..8: it oscillates with the fractional offset while the cell size halves β printed as measured.
Precision ledger β t = 3: grid 0.125, 7 controlled-U applications, 16 amplitudes. t = 8: grid 0.00390625, 255 controlled-U applications, 28 inverse-QFT controlled phases, 512 amplitudes. Accuracy is bought, and the price is printed.
Toy energy readout β rotation eigenphase from the trace (theta = 0.111408 for alpha = 0.7 rad), E = β2ΟΞΈ/Ο with labelled Ο = 0.5 gives E_true = β1.400000; estimate error 0.170796 (t = 3β5) β 0.025553 (t = 6) β 0.023534 (t = 8), inside the halving grid bound (1.570796 β 0.049087) at every t.
TinyML kNN classifier β exact / confident / leaky / under-resolved from (t, distance-to-grid, peak probability); scenario features are measured from real simulator runs, and kNN-vs-policy agreement is asserted on all 1,155 training-grid rows.
Advisory seats β Gemini Argon 4 DECIDER (names-only, tighten-only, sha256 trace), Muse advisor (can never override HOLD), Google Flow plan-only (rendered = False, live = 0).