HUB
Sign inSign up
quantumphaseestimation-lab logo

credkellar/quantumphaseestimation-lab

By credkellar

β€’Updated 17 days ago

QuantumPhaseEstimation-Lab: phase estimation lab - inverse QFT, Dirichlet kernel, cost ledger. Sim!!

Image
Machine learning & AI
Developer tools
Data science
1

217

credkellar/quantumphaseestimation-lab repository overview

⁠QuantumPhaseEstimation-Lab πŸŽ›οΈβš›οΈ

Quantum Phase Estimation Lab β€” by Darion Kellar

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

β πŸ’» Core Programming Languages & Core Systems

Python Stdlib Only Network Deterministic License QPE Dirichlet

  • 🐍 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)
⁠⛓️ Web3 & Infrastructure
  • 🚫 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

Linux macOS Windows

  • πŸ–₯️ 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)
⁠⚑ Low-Level Infrastructure & Performance
  • 🚫 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.
β πŸ› οΈ DevOps & Build Tools

Docker GitHub Actions pytest Git

  • 🐳 Docker (python:3.12-slim), GitHub Actions CI + Docker Publish (delivered in the paste pack)
  • 🎯 Target image: credkellar/quantumphaseestimation-lab:latest
  • πŸ§ͺ Tests: pytest (33 tests) + the built-in CHECKS suite (46 checks) in main.py
⁠☁️ Cloud Providers
  • 🚫 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.

⁠🐳 Quick start

docker pull credkellar/quantumphaseestimation-lab:latest
docker run --rm credkellar/quantumphaseestimation-lab:latest

The default command runs the full demo plus the built-in self-checks (CHECKS 46/46).

Run a specific command instead:

docker run --rm credkellar/quantumphaseestimation-lab:latest python3 main.py checks        # CHECKS 46/46
docker run --rm credkellar/quantumphaseestimation-lab:latest python3 main.py exact         # on-grid phase: the delta distribution (JSON)
docker run --rm credkellar/quantumphaseestimation-lab:latest python3 main.py kernel        # Dirichlet grading + within-1-cell table (JSON)
docker run --rm credkellar/quantumphaseestimation-lab:latest python3 main.py ledger        # precision ledger: bits vs cost (JSON)
docker run --rm credkellar/quantumphaseestimation-lab:latest python3 main.py energy        # rotation eigenphase -> labelled energy (JSON)
docker run --rm credkellar/quantumphaseestimation-lab:latest python3 main.py superposition # non-eigenstate inputs, both peaks (JSON)
docker run --rm credkellar/quantumphaseestimation-lab:latest python3 main.py classify      # kNN verdicts: exact / confident / leaky / under-resolved
docker run --rm credkellar/quantumphaseestimation-lab:latest python3 main.py holds         # 14 HOLD gates

β πŸ”¬ What's inside

  • 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.
  • Superposition honesty β€” |+⟩ into the phase unitary returns both eigenphases (0.500064 at 0, 0.437584 at theta; 0.977249 of the mass within one cell of either peak); |0⟩ into the rotation returns outcomes 7 and 57 at 0.472807 each. Leakage is part of the report.
  • 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).

β βœ… Verified

  • pytest: 33 passed
  • Built-in checks: CHECKS 46/46
  • Deterministic: double-run byte-identical
  • Base image: python:3.12-slim

⁠🏷️ Categories

Science Β· Developer tools Β· Machine learning & AI

  • License: MIT Β© 2026 Darion Kellar
  • Image: credkellar/quantumphaseestimation-lab:latest
Tag summary
Recent tags
Content type
Image
Digest
sha256:302d11b61…
Size
41.4 MB
Last updated
17 days ago
docker pull credkellar/quantumphaseestimation-lab:latest