Quantum Blocks Lab is an interactive teaching app for building and visualizing small quantum circuits. It presents gates as draggable blocks, runs the circuit step by step, and explains each qubit through probabilities, basis-state amplitudes, and simple Bloch-sphere visuals.
The main app is a static browser app, so it can run from static/index.html or be deployed directly to GitHub Pages. A Python/Qiskit server is also included for local comparison and API-based simulation experiments.
- Block-programming circuit builder with click-to-add and drag-and-drop gate placement
- Configurable input register with 1 to 5 qubits
- Gate palette for Hadamard, Pauli X/Y/Z, S, T, RX/RY/RZ, CX, CZ, Swap, Controlled-Swap, and measurement
- Per-gate editors for target qubits, control qubits, rotation angles, and measurement axes
- Conflict checks so multi-qubit gates do not overlap invalidly inside the same circuit column
- Built-in Bell-state demo using
Honq0followed byCX q0 -> q1 - Step timeline showing the initial state and every active gate result
- Animated circuit playback through each state snapshot
- Top basis-state display with probability bars, complex amplitudes, and phase angles
- Per-qubit probability summaries using red for
|0>and blue for|1> - Canvas Bloch-sphere cards for local single-qubit vectors
- Entanglement detection through reduced-state purity; entangled qubits hide the local Bloch vector
- Measurement along X, Y, or Z axes with deterministic collapse to the more likely outcome
- Static GitHub Pages deployment workflow
.
├── app.py
├── requirements.txt
├── static/
│ ├── index.html
│ ├── app.js
│ └── styles.css
└── .github/
└── workflows/
└── pages.yml
Defines the app shell: the header, qubit controls, block palette, circuit workspace, timeline, story panel, global state panel, and Bloch-sphere card templates.
Contains the current production simulator and UI behavior. It manages app state, gate configuration, drag-and-drop placement, validation, timeline rendering, animation, complex-number math, statevector evolution, measurement collapse, amplitude reporting, and single-qubit reduced-state summaries.
Styles the lab interface, including the responsive page layout, gate palette categories, circuit slots, gate editor, story timeline, amplitude bars, and Bloch-sphere cards.
Provides an optional local Python server on 127.0.0.1:8000. It serves the static app and exposes:
GET /api/configfor gate metadata and max-qubit configurationPOST /api/simulatefor Qiskit-backed statevector simulation
The static app does not depend on this server for normal GitHub Pages use.
Lists the Python dependency needed by the optional backend:
qiskit>=2.3,<3
Deploys the static/ directory to GitHub Pages whenever changes are pushed to main or master, or when the workflow is run manually.
The simplest path is to open:
static/index.html
You can also serve the static folder from the repo root:
python3 -m http.server 8000 --directory staticThen open:
Use this mode when you want to compare the browser simulator with the Python implementation or call the local API routes.
- Create and activate a virtual environment:
python3 -m venv .venv
source .venv/bin/activate- Install dependencies:
python3 -m pip install -r requirements.txt- Start the server:
python3 app.py- Open:
When app.py is running, fetch the gate configuration:
curl -s http://127.0.0.1:8000/api/configRun a Bell-state simulation:
curl -s -X POST http://127.0.0.1:8000/api/simulate \
-H "Content-Type: application/json" \
-d '{
"numQubits": 2,
"initialBits": [0, 0],
"gates": [
{ "type": "h", "target": 0 },
{ "type": "cx", "control": 0, "target": 1 }
]
}'The response includes normalized gates, simulation snapshots, per-qubit reports, nonzero amplitudes, phase angles, and measurement details when applicable.
- Push this project to a GitHub repository.
- In the repository settings, open Pages.
- Set Source to GitHub Actions.
- Push to
mainormaster, or manually run Deploy static lab to GitHub Pages.
The workflow publishes only the static/ directory.
- The lab supports up to 5 qubits to keep the statevector small and the interface readable.
- Displayed basis labels use app order:
q0,q1,q2, and so on from left to right. - The browser simulator and Python server both use little-endian qubit indexing internally while formatting labels for the app's visible qubit order.
- Measurement is intentionally deterministic for teaching: the app collapses to the more likely outcome, and exact ties resolve to
0. - A Bloch vector is shown only when the single-qubit reduced state is pure enough to be represented locally. For entangled qubits, the card reports the probabilities and purity while hiding the local vector.