HUB
Sign inSign up
quantumcompiler-lab logo

credkellar/quantumcompiler-lab

By credkellar

•Updated 17 days ago

QuantumCompiler-Lab: teaching transpiler - passes, Euler + Toffoli decomposition, routing. Sim only!

Image
Machine learning & AI
Developer tools
Data science
1

105

credkellar/quantumcompiler-lab repository overview

⁠QuantumCompiler-Lab 🧮⚛️

Quantum Circuit Compiler / Transpiler Lab — by Darion Kellar

Educational quantum circuit compiler in ONE pure-Python file: a tiny circuit IR (H, X, Y, Z, S, T, RX/RY/RZ, CNOT, CZ, SWAP, Toffoli), conservative compiler passes written from scratch (gate cancellation, rotation merging, commutation-based reordering from an explicit safe table), decompositions (any 2x2 unitary to RZ-RY-RZ Euler form with asserted reconstruction; Toffoli to the standard 6-CNOT form), qubit mapping/routing on line and ring coupling graphs with SWAP overhead counted, before/after metrics for every pass, and an exact statevector simulator (≤ 6 qubits, hand-written complex matrix ops) that proves the optimized circuit equals the original on every basis input.

Pure Python standard library. Zero dependencies. Zero network. Honest scope: this is a teaching transpiler on toy circuits — it is not Qiskit, targets no hardware, submits nothing anywhere, and models no calibration, crosstalk, or device noise. Simulated equivalence is exact for these toy circuits (demo max deviation ~2e-16); it is not a hardware fidelity claim. Every real-hardware / production / advantage claim is a permanent HOLD gate (14 total).

⁠🐳 Quick start

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

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

Run a specific command instead:

docker run --rm credkellar/quantumcompiler-lab:latest python3 main.py checks    # CHECKS 55/55
docker run --rm credkellar/quantumcompiler-lab:latest python3 main.py passes    # per-pass metrics, demo circuit
docker run --rm credkellar/quantumcompiler-lab:latest python3 main.py decompose # Euler + Toffoli decomposition
docker run --rm credkellar/quantumcompiler-lab:latest python3 main.py route     # line vs ring SWAP routing
docker run --rm credkellar/quantumcompiler-lab:latest python3 main.py equiv     # all-basis equivalence bundle
docker run --rm credkellar/quantumcompiler-lab:latest python3 main.py classify  # kNN circuit-cost classifier
docker run --rm credkellar/quantumcompiler-lab:latest python3 main.py holds     # 14 HOLD gates

⁠🔬 What's inside

  • Circuit IR + metrics — JSON-friendly gates on n qubits; depth by per-qubit layer scheduling, gate count, multi-qubit count, SWAP count, and 2Q ratio reported before/after every pass.
  • Gate cancellation — adjacent identical self-inverse pairs (H·H, X·X, CNOT·CNOT…) removed with a stack pass, so one removal can expose the next pair.
  • Rotation merging — adjacent same-axis rotations combine (RZ 0.2 + RZ 0.7 → RZ 0.9); opposite rotations cancel outright.
  • Commutation reordering, lite and provably safe — an explicit table only: Z-family through a CNOT control, X-family through a CNOT target, Z-family through CZ, disjoint qubits. A swap happens only when it brings a cancellable/mergeable pair together. X on a control is refused, in the open.
  • The demo, graded — 12 gates / depth 7 / 2Q 3 in → 3 gates / depth 2 / 2Q 1 out, with the full statevector equivalence check over all 16 basis inputs at max deviation ~2e-16.
  • Euler decomposition — any 2x2 unitary (hand-written complex matrix ops) → global phase × RZ·RY·RZ, reconstruction asserted (sample deviation 2.8e-16; identity, H, X, T edge cases included).
  • Toffoli decomposition — the standard exact form: 6 CNOTs, T/TDG/H dressing, verified against the Toffoli truth table and by full equivalence (deviation 3.1e-16).
  • Routing — line vs ring coupling graphs, BFS shortest paths, SWAP insertion with a tracked logical→physical mapping: a distance-3 CNOT costs 2 SWAPs on a line, 0 on a ring; routed output is proven equivalent after the final mapping is applied.
  • TinyML kNN classifier — cheap / moderate / expensive from (depth, 2Q ratio, SWAP overhead); training labels generated by the lab's own distilled cost model.
  • 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: 56 passed
  • Built-in checks: CHECKS 55/55
  • 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/quantumcompiler-lab:latest
Tag summary
Recent tags
Content type
Image
Digest
sha256:11510a516…
Size
41.5 MB
Last updated
17 days ago
docker pull credkellar/quantumcompiler-lab:latest