HUB
Sign inSign up
magicstate-lab logo

credkellar/magicstate-lab

By credkellar

•Updated 7 days ago

MagicState-Lab: magic state lab - M2 entropy, 15-to-1 distillation map, T injection. Sim only!

Image
Machine learning & AI
Developer tools
Data science
1

43

credkellar/magicstate-lab repository overview

⁠MagicState-Lab ✨⚛️

Magic State Lab — Stabilizer Rényi Entropy, the Bravyi–Kitaev 15-to-1 Distillation Map, and T-Gate Injection — by Darion Kellar

Educational magic state lab in ONE pure-Python file: for pure states of one and two qubits it builds the density matrix, measures every Pauli expectation value Tr(ρP) from the state itself, and evaluates the stabilizer Rényi entropy M2 = −log2((1/2ⁿ) Σ_P |⟨P⟩|⁴). Stabilizer states (|0⟩, |+⟩, |+i⟩, |++⟩, the Bell state) compute to M2 = 0; the T state computes to 0.415037499279, matching −log2(3/4) to 1e-12; the H-type state matches the same value and the body-diagonal state matches log2(3/2) = 0.584962500721. M2 is additive on the nose: |T⟩⊗|0⟩ = 0.415037499279 and |T⟩⊗|T⟩ = 0.830074998558. Distillation is the Bravyi–Kitaev 15-to-1 protocol's known leading-order error map p → 35p³, applied exactly as a map — the 15-qubit Reed–Muller circuit is NOT simulated qubit-by-qubit, and the lab says so wherever the map appears. Iterated from p₀ = 0.10 the error falls 0.035 → 0.001500625 → 1.182727e-07 → 5.79e-20, reaching 1e-6 in 3 rounds (3,375 raw states) and 1e-12 in 4 rounds (50,625); the threshold is located by bisection at 0.169030850946 = 1/√35, and above it the same map amplifies (0.25 → 0.546875 → 5.724430). Injection IS simulated in full: the two-qubit gate-teleportation circuit (CNOT, measure, S correction) runs on density matrices with both branches carried exactly — a perfect ancilla returns |T⟩⟨T| itself, depolarizing noise gives ε_out = p/2 exactly, and phase-flip noise gives ε_out = p, both printed. A from-scratch distance-weighted kNN classifier routes supply batches from the lab's own policy.

Pure Python standard library. Zero dependencies. Zero network. Honest scope: no state was distilled on real hardware, no device error rate is certified, no fault-tolerant computer is claimed, and every real-world 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 M2 Threshold

  • 🐍 Python 3.12, pure standard library (math, hashlib, itertools, json, sys) — zero dependencies, zero network, deterministic (double-run byte-identical)
  • ⚛️ Density-matrix core from scratch: a complex matrix kit (products, daggers, Kronecker products), unitary conjugation UρU†, exact projective measurement with both branches carried, and partial traces — refereed against the CNOT truth table and product-state traces before any lab number trusts it
  • ✨ Stabilizer Rényi entropy: M2 = −log2((1/2ⁿ) Σ_P |⟨P⟩|⁴) over all 4ⁿ Pauli strings, cross-graded against the independent Bloch-vector closed form 1 + x⁴ + y⁴ + z⁴ on 20 tilted states
  • 🧪 Distillation as a map: p → 35p³ iterated in the open, threshold bisected on the map itself, overhead counted as 15^rounds raw states
  • 🔀 Injection as a circuit: CNOT (data → ancilla), Z measurement, S correction (the identity S·T† = T is itself a check), branch probabilities exactly 1/2
  • 🧠 TinyML kNN supply classifier (from scratch, stdlib, distance-weighted): no-magic / inject-ready / distill-first / above-threshold from (M2, log₁₀ p), 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 density-matrix arithmetic on one and two qubits inside one offline file. Real-hardware injection and distillation are permanent HOLD gates, not features. 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 hardware is controlled, ever: real processors, state injectors, and distillation factories 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 expectation value can be read, checked, and diffed. Performance here means honest algorithms — exact branch-carrying measurement instead of Monte Carlo sampling, and a bisection that grades the threshold against 1/√35 — all deterministic and byte-identical between runs.
⁠🛠️ 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/magicstate-lab:latest
  • 🧪 Tests: pytest (22 tests) + the built-in CHECKS suite (49 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

Tag summary
Recent tags
Content type
Image
Digest
sha256:729acdd53…
Size
41.3 MB
Last updated
7 days ago
docker pull credkellar/magicstate-lab:latest