Skip to main content

Quantum Circuit Simulator

All I wanted for Christmas was a quantum circuit simulator. So I wrote one in Javascript using NumericJS.


Check it out: http://www.davyw.com/quantum


For a good "Hello world" circuit, here's the diagram for a Bell State...
Try evaluating it yourself and see that |00> or |11> are the only possible outcomes.

You can even compile your own circuits into gates to use in other circuits.

Construct a circuit that transforms a single qubit into |0> with 75% probability and |1> with 25% probability, such as:
Then compile that into gate "F" and use it to create a superposition of |00> with 75% prob and |11> with 25% prob, like this:
Let me know if you find any use out of this. And definitely let me know if you find any bugs.

Comments

Arsym said…
Correct me if I'm wrong, but it seems your Pauli-Y gate applies the wrong transformation matrix.
It's doing:
0 1
-1 0

rather than:
0 -i
i 0

Otherwise, it seems like a really solid tool. I'm trying to get the basics of quantum computation, and a simulator should help make things a little more intuitive.
Wybiral said…
Thanks! You are correct, somehow that slipped through the cracks. It's fixed now. I definitely welcome feedback.

I'm working on cleaning up the code some so I can get it all hosted on a version control system so others can review the code and contribute.
ohmygod said…
Can you design one more function to "switch locations of the qubits."? (ex. change the 3rd qubit to be the 2nd qubit, and all the related gates.)

Popular posts from this blog

Procedural music with PyAudio and NumPy

Combining two of my favorite pastimes, programming and music... This is the hacky "reduced to it's basic components" version of a library I've been working on for generating music and dealing with music theory.

Tweaking the harmonics by changing the shape of the harmonic components and ratios can produce some interesting sounds. This one only uses sine waveforms, but a square / saw generator is trivial with numpy.

It takes a second to generate, so don't turn your volume up too loud in anticipation (it may be loud).

import math
import numpy
import pyaudio
import itertools
from scipy import interpolate
from operator import itemgetter


class Note:

NOTES = ['c','c#','d','d#','e','f','f#','g','g#','a','a#','b']

def __init__(self, note, octave=4):
self.octave = octave
if isinstance(note, int):
self.index = note
self.note = Note.NOTES[note]
elif isinstance(note, st…

Build a Feed Reader in Python (Parts 7-9)

Part 07 Adding Jinja2 templates to a flask web application.

 Part 08 Adding static files so we can serve some CSS to style our app.

Part 09 Adding a background task to continuously update the articles while the application is running.

Write a Feed Reader in Python

I just started a new video tutorial series. This time it'll cover the entire process of writing an RSS feed reader in Python from start to finish using the feedparser module, flask, and SQLAlchemy. Expect to see about 3-4 new videos a week until this thing is finished!
Click to watch