SciPost logo

SciPost Submission Page

How to Write a Simulator for Quantum Circuits from Scratch: A Tutorial

by Michael J. McGuffin, Jean-Marc Robert, Kazuki Ikeda

Submission summary

Authors (as registered SciPost users): Michael McGuffin
Submission information
Preprint Link: scipost_202508_00028v1  (pdf)
Code repository: https://github.com/MJMcGuffin/muqcs.js
Date submitted: Aug. 11, 2025, 6:58 p.m.
Submitted by: Michael McGuffin
Submitted to: SciPost Physics Lecture Notes
Ontological classification
Academic field: Physics
Specialties:
  • Quantum Physics
Approach: Computational

Abstract

We guide a competent programmer through the programming of a quantum circuit simulator, supporting quantum logic gates with arbitrary control qubits on 20+ qubits, assuming no previous knowledge of quantum computing. We explain qubit-wise multiplication for updating the state vector; how to compute partial traces on arbitrary subsets of qubits to find reduced density matrices; and computing qubit phase and purity. A sample implementation in JavaScript is provided, which also demonstrates how to compute von Neumann entropy, concurrence (to quantify entanglement), and magic, with source code much smaller and easier to study than other popular software packages.

Current status:
Awaiting resubmission

Reports on this Submission

Report #1 by Anonymous (Referee 1) on 2026-1-6 (Contributed Report)

Disclosure of Generative AI use

The referee discloses that the following generative AI tools have been used in the preparation of this report:

Used to refine grammar of report.

Report

In this lecture note, the authors provide an introductory tutorial on simulating quantum circuits on a personal laptop using Javascript, without the requirement of installing any packages or libraries. In particular, the main focus of the lecture note is not to compete in functionalities with existing full-featured frameworks, but rather focus on the implementation of the underlying algorithms in building a quantum circuit simulator. The lecture note includes a self-contained section on the basic operations and conventions that are used in quantum mechanics and quantum computation, which is beneficial for people who have minimal or zero background in these areas. The authors also emphasize on the time complexity of various algorithms used to perform quantum circuit computations.

The targeted audience of this lecture note is software engineers with minimal exposure to quantum computing. However, it will also be beneficial to readers who have a solid background in quantum mechanics but with minimal programming experience. To better accommodate a broader range of backgrounds, I suggest to including the following details to the lecture note:

  1. The console output of the code that represents the quantum circuit in Figure 1:

n = 3; // number of qubits $\psi$ = $( | 0 \rangle^ {\otimes {\rm n}} )$; // initialization $\psi$ = qubitWiseMultiply(n,Hadamard,1,$\psi$); $\psi$ = qubitWiseMultiply(n,PauliX,2,$\psi$); $\psi$ = qubitWiseMultiply(n,PauliX,0,$\psi$,[[1,true]]); $\psi$ = qubitWiseMultiply(n,PauliZ,0,$\psi$); $\psi$ = qubitWiseMultiply(n,PauliX,2,$\psi$,[[1,true]]);

and Figure 4 respectively:

n = 3; // number of qubits $\psi$ = $( | 0 \rangle^ {\otimes {\rm n}} )$; // initialization $\psi$ = qubitWiseMultiply(n,Hadamard,0,$\psi$); $\psi$ = applySwap(n,0,2,$\psi$); $\psi$ = qubitWiseMultiply(n,PauliX,1,$\psi$,[[2,false]]); $\psi$ = qubitWiseMultiply(n,PauliX,0,$\psi$,[[1,true]]); $\psi$ = qubitWiseMultiply(n,PauliY,0,$\psi$); $\psi$ = applySwap(n,1,2,$\psi$,[[0,true]]); $\psi$ = qubitWiseMultiply(n,PauliZ,1,$\psi$);

  1. Include a section or appendix on the code structure of the index.html file, outlining the main Javascript classes (Util, Complex, CMatrix, Sim) and how users can call functions and view results of console output. This will be helpful for physics learners who like to verify the behavior of the quantum circuit simulator and explore various gate applications.

  2. (Optional) Include 1 or 2 consistency checks with existing frameworks, such as IBM Quantum Composer or Quirk. The authors are welcome to include images of their own frontend webpage design for illustration purposes.

I recommend the manuscript to be published in SciPost Physics Lecture Notes after revision.

Requested changes

Pleaser refer to report.

Recommendation

Ask for minor revision

  • validity: good
  • significance: good
  • originality: good
  • clarity: high
  • formatting: good
  • grammar: excellent

Login to report or comment