Saved in:
Bibliographic Details
Main Authors: McGuffin, Michael J., Robert, Jean-Marc, Ikeda, Kazuki
Format: Preprint
Published: 2025
Subjects:
Online Access:https://arxiv.org/abs/2506.08142
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866909644976291840
author McGuffin, Michael J.
Robert, Jean-Marc
Ikeda, Kazuki
author_facet McGuffin, Michael J.
Robert, Jean-Marc
Ikeda, Kazuki
contents 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 https://github.com/MJMcGuffin/muqcs.js , which also demonstrates how to compute von Neumann entropy, concurrence (to quantify entanglement), and magic, while remaining much smaller and easier to study than other popular software packages.
format Preprint
id arxiv_https___arxiv_org_abs_2506_08142
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle How to Write a Simulator for Quantum Circuits from Scratch: A Tutorial
McGuffin, Michael J.
Robert, Jean-Marc
Ikeda, Kazuki
Quantum Physics
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 https://github.com/MJMcGuffin/muqcs.js , which also demonstrates how to compute von Neumann entropy, concurrence (to quantify entanglement), and magic, while remaining much smaller and easier to study than other popular software packages.
title How to Write a Simulator for Quantum Circuits from Scratch: A Tutorial
topic Quantum Physics
url https://arxiv.org/abs/2506.08142