Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
How to use Quirk
Quirk is a drag-and-drop quantum circuit simulator. Quirk is open source, free to use, and all you need to run it is access to the web. A live version of Quirk is available at algassert.com/quirk, but you can also get the code from github.com/Strilanc/Quirk and build your own version.
Quirk is great for working with small circuits. State displays update in real time as you change the circuit, the visual style gives a reasonable intuitive feel of what the quantum state is doing, and the general experience is fast and interactive.
Using Quirk mostly amounts to dragging gates from the toolboxes, dropping those gates into the circuit, and looking at the state displays inside and to the right of the circuit.
Building your first Circuit
Go to algassert.com/quirk and, after Quirk loads, click the large 'Edit Circuit' button. You should now be staring at an empty circuit (except for the default state displays) bordered by two toolbox areas:
You add gates to the circuit by dragging them from the toolbox, so lets do that.
Find the X gate in the top toolbox, and drag one onto the second wire of the circuit:
Notice that the output displays have changed. The green box on the second wire now says "ON" instead of "OFF". That's because the X gate is the quantum version of a NOT gate; it toggles between the ON and OFF states. If you add a second X gate to the wire, the state will toggle back to OFF.
By itself, an X gate is not particularly interesting or useful. But conditional X gates, that only apply if some other wires are on, are really really useful. In Quirk, you condition gates by placing a Control gate in the same column.
Find the Control gate in the top toolbox (look for a big black dot), and drag one onto the circuit. Put the control on the first wire, directly above the X gate on the second wire.
Two things just happened.
First, to match convention, the X gate is now being drawn as a circle with a plus inside.
More importantly, the X gate on the second wire will now only apply if the first wire is ON.
Since the first wire is
OFF, the X gate is not applying, nothing is happening to the input state of
OFF, OFF, and so the output state is also
To activate the controlled-not (the "CNOT"), drag an X gate (i.e. a NOT gate) onto the first wire, to the left of the control.
To summarize what's happening:
- The state starts as
- The X gate toggles the first wire, advancing the state to
- The CNOT's control is satisfied, so it toggles the second wire, advancing the state to
- That's it.
They may not look like much, but X gates and controls are extremely powerful. All classical computation can be done with just these two elements, assuming you have enough workspace.
In Quirk, extra workspace (i.e. more qubits / more wires) appears whenever you are dragging a gate. To keep that extra wire around, drop a gate on it. Otherwise, to keep the circuit compact, the extra wire will disappear after you drop the gate somewhere else.
To add many extra wires, just repeat. Grab a gate, drop it on the extra wire, grab the gate again, drop it on to the extra extra wire, and so forth. Quirk lets you keep doing this up to a maximum of 16 wires.
Add three wires to your circuit by repeatedly grabbing the CNOT's X gate and dropping it onto the extra wire that appears.
- Replace Not with H.
- Teleportation steps.
- Intermediate state displays.
- Reading/resizing chance display.
- Reading bloch spheres.
- Reading amplitude display.
- Density display.
- Sample display.