QSim is a web application to design, simulate, and visualize quantum circuits. Build circuits with common quantum gates, run simulations, inspect probabilities/counts, and see single-qubit states on Bloch spheres. It’s aimed at learners and enthusiasts for interactive experimentation.
- Circuit Builder UI with gate palette
- Supported gates: Hadamard, PauliX, PauliY, PauliZ, RX, RY, RZ, CNOT, Swap, Toffoli, ControlledPhaseShift, Oracle, Diffusion
- Visual circuit grid with per-qubit timeline, pagination, status bar, and accessible controls
- Robust gate validation with clear error messages (arity, ranges, distinct multi‑qubit targets, conditional overlap checks)
- Conditional gates (measure a qubit and apply only if outcome matches)
- Simulation
- Probabilities and measurement counts via configurable shots
- Per-qubit Bloch sphere parameters (computed from reduced single‑qubit expectations)
- Sparse-state engine with defensive arity assertions and range checks
- Optional per‑step normalization for robustness (configurable)
- Persistence and portability
- Save/Load from browser storage
- Import/Export circuits as JSON
- Export circuit diagram as PNG
- Export amplitudes as CSV
- Shareable URL generation
- Node.js 18 or higher
- npm (or yarn/pnpm)
-
Clone the repository:
git clone https://github.com/neuralsorcerer/qsim.git
-
Navigate to the project directory:
cd qsim -
Install dependencies:
npm install
-
Start the development server:
npm run dev
-
Open your browser and navigate to: http://localhost:5173
npm run lintnpm run build- The production build will be output to the
dist/directory.
npm run previewThis serves the contents of dist/ locally for verification.
- Simulation memory/time grows as O(2^n). Very large n or deep circuits can hang a tab.
- Before running very large configurations, the app asks for confirmation (state size ≥ 2^18 or depth > 128).
- Wide global operators (Oracle/Diffusion) impact performance more than local 1–2 qubit gates.
- Optional:
VITE_DEBUG: set totrueto enable additional debug logging in the app.VITE_NORMALIZE_EACH_STEP: set tofalseto skip normalization after each gate for performance. Defaults totruefor robustness. Measurements always renormalize.
Create a .env or .env.local file at the project root, for example:
VITE_DEBUG=true
VITE_NORMALIZE_EACH_STEP=true- Defensive arity assertions: a k‑qubit gate must target exactly k qubits (derived from matrix size 2^k).
- Multi‑qubit gates require distinct target qubits; conditional qubit cannot overlap targets.
- Input ranges are validated (qubit indices and initial basis state).
This project is licensed under the Apache License - see the LICENSE file for details.
