
My Quantum Circuit Simulator: Quirk - dmit
http://algorithmicassertions.com/2016/05/22/quirk.html
======
stared
Interesting! (For me it looks like "Nielsen Chuang in your browser".)

As I am curious since I am developing some quantum simulation on my own
([https://github.com/stared/quantum-game](https://github.com/stared/quantum-
game) \- one photon, but spatial degrees of freedom and more physical
interactions).

Side remark - for plotting states:

\- did you consider using colors (see
[http://nbviewer.jupyter.org/github/qutip/qutip-
notebooks/blo...](http://nbviewer.jupyter.org/github/qutip/qutip-
notebooks/blob/master/examples/example-qubism-and-schmidt-plots.ipynb))?

\- is there some slider, so I can lookup state at any stage (not only the last
one)?

~~~
Strilanc
> _did you consider using colors_

I did consider it, but I never experimented with it. For a small number of
qubits, I think oriented circles are much clearer. Then they get gradually
worse as you move up towards 16 qubits. Once the amplitudes get close to
pixel-sized, you're probably forced to use color if you want to show a decent
1-to-1 representation.

Some of the downsides:

\- Color-blind unfriendly.

\- Worse absolute accuracy at a glance. I can guess the absolute angle of a
short line to within a couple degrees (~100 distinguishable buckets). For hues
that's probably more like 20-30 buckets, though relative comparisons would
still be ~100 buckets accurate. The angular velocity at a glance probably also
suffers.

\- Circular motion, where the center is not at 0 (e.g. watch the X^t gate),
won't look quite so circular.

\- I already use color to hint at meaning (green is densities/probabilities,
blue is amplitudes, yellow is volatility).

> _is there some slider, so I can lookup state at any stage (not only the last
> one)?_

Drag an amplitude display (the green 'Amps' thing in the toolbox) onto the
circuit. Put it where you want to see the state. Resize it to cover
everything.

(At the moment the inline displays are limited to covering 8 qubits. I was
worried about performance when they get large. It'll be fixed in the future.)

 _Edit_ : Gah, there's a bug where the amplitude display is showing 'NaN'
unless all the covered qubits are not entirely Off. Not sure how that slipped
in.

 _Edit #2_ : Oh, it's happening on my work machine but not on my home machine.
So probably related to webgl being terrible.

~~~
bmer
I am a newb dev, so I am curious to know what you used to build the simulator.
You name-dropped webgl, but what else is needed to put together something like
this, with the nice drop down menus, the drag and drop, and all that?

~~~
Strilanc
The drag-and-drop is done from scratch. Quirk just listens to browser events
like mousedown/mousemove/mouseup and turns that into manipulations of the
circuit. Getting it to work well across all the browsers, and modes of
interactions, is quite finicky. For example, mobile browsers refused to not
scroll even if `event.preventDefault()` was called, so I had to overlay the
drag targets with transparent divs that have `touch-action: none`.

Quirk doesn't have menus.. you might be thinking of the recording of Davy's
simulator? Those menus also look custom-made. I actually wouldn't call them
"nice", because they lack important polish. Read this:
[http://bjk5.com/post/44698559168/breaking-down-amazons-
mega-...](http://bjk5.com/post/44698559168/breaking-down-amazons-mega-
dropdown)

I'm sure there are libraries for menus and things like that, but I generally
prefer to try to do it myself unless those libraries have a _really_ good
interface.

~~~
wybiral
> I actually wouldn't call them "nice"

You're being polite... Those drop downs are hideous!

------
lordnacho
What's a good primer for understanding this? Given I have an EE degree, but
only very basic quantum mechanics?

~~~
Strilanc
The post [and me, since I wrote it] recommends the video series Quantum
Computing for the Determined [1].

If you're more familiar with physics than programming, Leonard Susskind's
'Quantum Mechanics: The Theoretical Minimum' [2] might work better. But I
agree with Scott Aaronson that learning about quantum information before
learning about quantum physics is easier than the opposite direction [3]:

> _There are two ways to teach quantum mechanics. The first way -- which for
> most physicists today is still the only way -- follows the historical order
> in which the ideas were discovered. [...]_

> _Today, in the quantum information age, the fact that all the physicists had
> to learn quantum this way seems increasingly humorous. For example, I 've
> had experts in quantum field theory -- people who've spent years calculating
> path integrals of mind-boggling complexity -- ask me to explain the Bell
> inequality to them. That's like Andrew Wiles asking me to explain the
> Pythagorean Theorem. [...]_

> _The second way [...] starts directly from the conceptual core -- namely, a
> certain generalization of probability theory to allow minus signs._

1:
[https://www.youtube.com/playlist?list=PL1826E60FD05B44E4](https://www.youtube.com/playlist?list=PL1826E60FD05B44E4)

2: [http://www.amazon.com/Quantum-Mechanics-Theoretical-
Leonard-...](http://www.amazon.com/Quantum-Mechanics-Theoretical-Leonard-
Susskind/dp/0465062903)

3:
[http://www.scottaaronson.com/democritus/lec9.html](http://www.scottaaronson.com/democritus/lec9.html)

~~~
archgoon
> But I agree with Scott Aaronson that learning about quantum information
> before learning about quantum physics is easier than the opposite direction.

I'm unconvinced that this is anything but Scott's personal opinion. Basically
all teaching methodology advocates for concrete examples over abstract
concepts. You can't get much more abstract than generalization of probability
theory to allow minus signs.

It might work well for some people, and I'm happy it worked for you.

~~~
nhaliday
I don't really think the physical approach is any more concrete than Scott
Aaronson's approach (at least in the way most people talk about concreteness
wrt pedagogy). The point of having examples is to illustrate how general
principles work in practice by specializing. You can do this just fine in
quantum information/computation by discussing particular algorithms, problems,
etc.

Frankly having taken both QC courses and QM courses, I found the physics-
oriented exposition used a bunch of verbiage to phrase things in an
experimental/physical way without really specializing the mathematical objects
in any sense (eg, Stern-Gerlach experiments). That particular sort of
concreteness can be helpful in other parts of physics, but physical intuition
is weak to nonexistent in QM.

Anyway, I'm nowhere near a physicist so take my review with a grain of salt.

------
gue5t
Why does this site's header image seem to say "Bugs" (in near-white text)
around (763,108)?

~~~
Strilanc
It's just a joke about bugs being subtle and hard to find despite hiding in
plain sight. I'm kind of impressed you spotted it; I wasn't sure anyone ever
would (it's harder to see on some monitors than others).

------
wybiral
This looks great!

I noticed that custom gates were on your "work in progress" list. Does that
include being able to reuse a circuit as a gate in another circuit? That's a
killer feature for me. Being able to "abstract away" things like the Grover
diffuse operation. That, or even copy & paste functionality to speed up
designing those repetitions.

~~~
Strilanc
Yes, that's one of the things I plan to do [1].

(You can copy individual gate parts by holding shift as you grab them. I'm
considering adding ctrl as a another modifier, meaning 'grab the whole
column'. I understand that these modifiers are not discoverable.)

(At the moment, when I want to make a really large repetitive circuit, I copy
the URL into a text editor and do my copy pasting there. I understand that it
would be totally ridiculous to expect users to do that.)

1:
[https://github.com/Strilanc/Quirk/issues/148](https://github.com/Strilanc/Quirk/issues/148)

~~~
wybiral
Being able to copy & paste a column would speed up design. Certain quantum
algorithms rely heavily on repeated application so not having a shorthand
feels tedious.

Ideally, from my perspective as a user, I'd like some kind of selection box
that I can drag over a portion of the circuit and duplicate everything
highlighted.

PS: I like that you maintain the circuit in a URL linkable form. Very handy!

~~~
Strilanc
There's a few gates that you can _only_ create by editing the URL ;).

Examples include the X-axis post-selection gates "|+⟩⟨+|" and "|-⟩⟨-|", some
square-wave gates "X^⌈t⌉" and "X^⌈t-¼⌉" that were made redundant by the
counting gate, the impossible universal-not gate "__unstable__UniversalNot"
[1], and the error injection gate "__error__".

1:
[http://physics.stackexchange.com/a/247178/911](http://physics.stackexchange.com/a/247178/911)

------
westoncb
Very nice. I know nothing about quantum circuits, but just as a piece of
software this is very cool.

My one criticism: there's something about the visual style of the interactive
elements that makes them appear non-interactive until interacted with. The
whole application initially looked like a static image to me before I started
clicking around and fiddling with it.

~~~
Strilanc
Thanks, that's useful to know.

------
vonklaus
This is awesome. If you want a cool side project, you should definitely make
this into a kerbal space program like game where you build quantum computers &
optimization patterns. It would probably be super fun for you to build and
also a fairly profitable venture given you have much of the codebase writeen.

------
bmer
Can someone do a back of the napkin calculation to compare the performance of
a quantum simulator with the real deal?

