Sample code for quantum computing projects

This sample code is in Mathematica, which is a terrible language to use for these projects — I used it out of habit.  More appropriate languages are Python, MATLAB, C++, Fortran… and most students who have done these projects have used one of these (Python has been most popular).

Even if you don’t know Mathematica, by scanning through the pdf’s posted here you can see the sort of output you should be getting (in light typeface) and get some ideas from the code (in boldface).

If you have Mathematica installed, you should be able to download the .nb files and run them.

Note added 11/1/21: The links below are broken. If you really want this Mathematica code (you should use Python instead!) please email me at

Sample code for Parts 1 and 2 other than Shor’s algorithm: Quantum computing.pdf  Quantum computing.nb

Sample code for Shor’s algorithm: Shor algorithm.pdf  Shor algorithm.nb

Sample code for Part 3 other than the surface code: by03.pdf  byo3.nb

Sample code for simulating the surface code: byo3 surf.pdf  byo3 surf.nb

Code to make pictures of surface code computers: Surface code draw.pdf  Surface code draw.nb