HUB
Sign inSign up
variationalquantum-lab logo

credkellar/variationalquantum-lab

By credkellar

โ€ขUpdated 17 days ago

VariationalQuantum-Lab: VQE + QAOA lab - exact-graded energies, 3-optimizer race, measured plateaus!

Image
Machine learning & AI
Developer tools
Data science
1

123

credkellar/variationalquantum-lab repository overview

โ VariationalQuantum-Lab โš›๏ธ๐Ÿ“‰

Variational Quantum Algorithms Lab โ€” by Darion Kellar

Educational variational quantum algorithms lab in ONE pure-Python file: a from-scratch statevector simulator (<= 8 qubits, no numpy), a hardware-efficient RY + CNOT ansatz, exact parameter-shift gradients, and three from-scratch optimizers โ€” gradient descent, Nelder-Mead, random-restart โ€” raced on a 4-qubit transverse-field Ising chain and graded against the EXACT ground energy from full diagonalization of the same Hamiltonian (Jacobi eigensolver, also from scratch). QAOA runs on a 4-node MaxCut graph (brute-force optimum 4) at p=1 and p=2. Barren plateaus are measured, not named: gradient variance falls 83x from 2 to 8 qubits for a global cost (fitted slope -0.316 log10/qubit, a x0.484 factor per qubit), and far more gently for the local TFIM cost (slope -0.142) โ€” cost locality as a measured fact.

Pure Python standard library. Zero dependencies. Zero network. Honest scope: this is an exact CLASSICAL simulation of tiny systems at 2^n cost โ€” that cost is the lesson. No quantum advantage is claimed, no hardware is touched, the noise section is a LABELLED toy depolarizing model, and every real-world claim (advantage, production optimization, drug/materials discovery, certified chemistry) is a permanent HOLD gate (14 total).

โ ๐Ÿณ Quick start

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

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

Run a specific command instead:

docker run --rm credkellar/variationalquantum-lab:latest python3 main.py checks   # CHECKS 54/54
docker run --rm credkellar/variationalquantum-lab:latest python3 main.py vqe      # VQE vs exact, both Hamiltonians
docker run --rm credkellar/variationalquantum-lab:latest python3 main.py race     # the 3-optimizer race table
docker run --rm credkellar/variationalquantum-lab:latest python3 main.py qaoa     # MaxCut ratios p=1 / p=2
docker run --rm credkellar/variationalquantum-lab:latest python3 main.py plateau  # measured gradient variances + fits
docker run --rm credkellar/variationalquantum-lab:latest python3 main.py classify # kNN trainability report
docker run --rm credkellar/variationalquantum-lab:latest python3 main.py holds    # 14 HOLD gates

โ ๐Ÿ”ฌ What's inside

  • Statevector simulator โ€” <= 8 qubits of pure-Python complex amplitudes; RY / RX / Hadamard / CNOT gates and Pauli-string expectations, every operation visible and countable.
  • Exact grading โ€” the ground energies (TFIM-4: -4.758770; H2-style toy: -1.851296) come from a from-scratch complex Jacobi diagonalization of the same Hamiltonians VQE runs on. The variational principle is asserted, never assumed: no reported energy beats the exact ground.
  • The optimizer race โ€” same seeded start, same ansatz: gradient descent (exact parameter-shift gradients, best-ever tracking) lands a 1.38e-03 gap in 3,751 evaluations; random-restart (6 seeded Nelder-Mead runs) lands 4.97e-03 in 1,801; single Nelder-Mead lands 1.16e-01 in 900. Quality per evaluation, printed as a table.
  • Parameter-shift, proven exact โ€” gradients use the shift rule (generator eigenvalues +-1/2) and the checks assert agreement with central finite differences to < 1e-6.
  • QAOA MaxCut โ€” square-plus-diagonal graph, brute-force optimum 4 of 5: p=1 reaches ratio 0.8093, p=2 reaches 0.9355 (warm-started from the p=1 optimum, so the improvement is earned, and asserted).
  • Barren plateaus, measured โ€” 32 seeded samples per point: global-cost gradient variance 2.647e-01 at 2 qubits -> 3.190e-03 at 8 (83x decay, fit x0.484/qubit); local TFIM cost decays only x0.721/qubit. A depth scan at 8 qubits shows the plateau already entered at shallow depth.
  • Noise honesty โ€” a LABELLED toy depolarizing model (shrink (1-p) per layer) puts a hard floor under reportable energies: at p=0.02/layer the floor sits 0.0543 above the exact ground, and no optimizer can report below it.
  • TinyML kNN classifier โ€” trainable / hard / barren from (qubits, depth, measured gradient variance); labels generated by a threshold model fitted to the plateau measurements themselves.
  • 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: 40 passed
  • Built-in checks: CHECKS 54/54
  • 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/variationalquantum-lab:latest
Tag summary
Recent tags
Content type
Image
Digest
sha256:c979c2403โ€ฆ
Size
41.6 MB
Last updated
17 days ago
docker pull credkellar/variationalquantum-lab:latest