How to Write a Simulator for Quantum Circuits from Scratch: A Tutorial
Michael J. McGuffin, Jean-Marc Robert, Kazuki Ikeda

TL;DR
This tutorial teaches programmers how to build a simple, open-source quantum circuit simulator from scratch, covering key algorithms and providing a complete JavaScript implementation for circuits up to 20+ qubits.
Contribution
It provides a detailed, step-by-step guide to creating a quantum simulator with core algorithms, optimizations, and practical examples, enhancing understanding beyond using pre-made tools.
Findings
Able to simulate various quantum gates and circuits up to 20+ qubits
Includes algorithms for state vector updates and partial trace calculations
Provides tools to compute quantum statistics like entropy and entanglement
Abstract
This tutorial guides a competent programmer through the crafting of a quantum circuit simulator from scratch, even for readers with almost no prior experience in quantum computing. Open source simulators for quantum circuits already exist, but a deeper understanding is gained by writing ones own. With roughly 1000-2000 lines of code, one can simulate Hadamard, Pauli X, Y, Z, SWAP, and other quantum logic gates, with arbitrary combinations of control and anticontrol qubits, on circuits of up to 20+ qubits, with no special libraries, on a personal computer. We explain key algorithms for a simulator, in particular: qubit-wise multiplication for updating the state vector, and partial trace for finding a reduced density matrix. We also discuss optimizations, and how to compute qubit phase, purity, and other statistics. A complete example implementation in JavaScript is available at…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Code & Models
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsQuantum Computing Algorithms and Architecture · Quantum-Dot Cellular Automata · Quantum Information and Cryptography
