Giter Club home page Giter Club logo

quirk's Introduction

Build Status

Quirk is a toy quantum circuit simulator, intended to help people in learning about quantum computing.

If you want to quickly explore the behavior of a small quantum circuit, Quirk is the tool for you. There's no installing or configuring or scripting: just go to algassert.com/quirk, drag gates onto the circuit, and the output displays will update in real time.

(If you're still trying to understand what a quantum circuit even is, then I recommend the video series Quantum Computing for the Determined. Quirk assumes you already know background facts like "each wire represents a qubit".)

Defining features:

  • Runs in web browsers.
  • Drag-and-drop circuit editing.
  • Reacts, simulates, and animates in real time.
  • Inline state displays.
  • Bookmarkable / linkable circuits.
  • Up to 16 qubits.

Notable limitations:

Try it out:

algassert.com/quirk

Examples

Basic usage demo:

Demo

Grover search circuit with chance and sample displays (showing that the chance of success increases):

Grover search

Quantum teleportation circuit with Bloch sphere displays (showing that the qubit at the top has ended up at the bottom):

Quantum teleportation

Building

If you want to modify Quirk, this is how you get the code and turn your changes into working html/javascript.

  1. Have git and Node.js installed.

    sudo add-apt-repository universe

    sudo apt-get update

    sudo apt-get install --yes git npm nodejs-legacy

  2. Clone the repository.

    git clone https://github.com/Strilanc/Quirk.git

  3. Install the dev dependencies.

    cd Quirk

    npm install

  4. (Optional) Make your changes. Run the tests.

    npm run test-firefox

  5. Build the output.

    npm run build

  6. Confirm the output works by opening out/quirk.html with a web browser.

    firefox out/quirk.html

  7. Copy out/quirk.html to wherever you want.

Disclaimer

Quirk is not an official Google product.

quirk's People

Contributors

dependabot[bot] avatar ebraminio avatar marwahaha avatar qw3rtman avatar secor avatar stonecypher avatar strilanc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

quirk's Issues

Rework controls and gate motion

Currently control nodes apply to entire columns and are dragged around separately from gates. This is not ideal: it forces extra columns when doing independent CNOTs, it adds extra clicks and drags for moving things around, and internally the way it affects the tensor product is... "unique".

Current ideas to improve:

  • Have "upward" and "downward" control nodes. When they're dragged onto the circuit, they link to the next gate in their facing direction (and no others). (What about "both ways"? "full column"? Next-two-above?)
  • Dragging the control nodes around breaks them away from linked gates, but dragging the gate brings the control node along for the ride. Similarly, gates can't be moved into an existing link (they must go to either side), but control nodes can be.
  • Swap gates should never be unpaired. Come in as a 2-qubit gate that allows its ends to be dragged vertically apart, and then moves as if it was an n-qubit gate.

Allow user to create custom gates

It would be useful to be able to make custom gates.

A few possible ideas:

  • Free-form text entry of coefficients, with a singular value decomposition to repair any non-unitaryness.
  • Drag a box around existing circuit area.
  • How to allow for time-sensitivity?
  • How to allow for gates that can apply to any number of qubits?

Get source maps working

The code is going through three transformations (traceur, concat, uglify). Figuring out which file line 13473 is from by hand is annoying. Get each transformation step's sourcemap bits working.

Optimize gate tooltip drawing

Drawing the gate tooltips is currently literally slower than the 12-qubit simulation and superposition-drawing. The problem is probably the bloch sphere bit.

Improve the things-not-working experience

  • Use a textbox instead of a drawn box for error info, so the information can be trivially copied
  • Have a fallback CircuitStats that allows the circuit to still be edited and drawn, even though the outputs aren't working
  • Detect GPU pipeline failing on startup, warn user about it, and tell them to complain
  • Provide a mailto: link as well as a github issues link
  • Include the JSON'd circuit and a screenshot of the canvas in the error info?

Resize while dragging to make fit

When dragging a sparse multi-qubit gate (e.g. a swap) as a single unit, the individual gates making it up could get closer together if doing so will let the thing fit on the circuit.

Change number of wires

Currently forced to use 3 wires. Would be better if adding/removing wires was possible, with appropriate changes in displayed information.

Fix mobile touch interaction

Although touch interaction works fine on my windows laptop with a touch screen, it is completely broken on my nexus phone. Gates are somehow hard to pick up, and tend to drop during a drag. Often I try to grab a gate and instead scroll the screen. Figure out why, and fix it.

Control wires should get pushed when they overlap a wide gate

Currently, a controlled-not whose control wire crosses over a 2x2 density matrix will not cause a spacer column to be inserted. The result is the wire being in the way of the density matrix display, and possible confusion over whether or not it is conditioning the display.

Extract the logic used to draw the control wires into functions, and re-use those functions to cause spacers to be introduced in this situation.

Optimize computation of mixed states

Computing a density matrix from the full superposition basically amounts to a matrix adjoint-squaring. The matrix has a column for each kept-value configuration and a row for each not-kept-value configuration, so it usually ends up highly rectangular (many more rows than columns).

Currently the code computes the density matrix by doing the full matrix multiplication in a single shader by nesting as many loops as necessary. This is probably the wrong approach. It's unclear if using a fold-based approach would be better, or if computationsof the mixed state of each wire can be overlayed in a useful way. Investigate.

Support multi-wire gates

The code only supports single-wire gates (+ control wires). What about gates that apply to multiple wires, like the swap gate or big QFTs?

Scrolling

Long circuits go off the edge of the screen. Being able to scroll would let them get much longer.

Might cause performance issues.

Restore tests for CircuitStats

The unit tests for CircuitStats were commented out during the shader refactor, and need to be polished back into working condition.

Measurement gate

A measurement gate would be useful, even if it is exactly equivalent to a controlled-not onto an otherwise unused qubit.

Add number tooltips to displays

When the user hovers over one of the state displays, the numeric representation of the value they are hovering over should be shown as a tooltip.

Push NaN threshold up a bit

Showing the state of an X^t on one wire, conditioned on a wire that's been hit with H H, shows rounding noise instead of NaN.

Focused visualization

If the visualizations are going to continue to be useful past 5-6 qubits, there needs to be a way to filter them down. A few ideas:

  • A "quantum peek" gate could show the amplitudes on a wire. Not sure how to deal with superposition. Easiest would be to say "in superposition" whenever there's more than one case to handle (after taking the controls into account).
  • Animating the state visualalization when an operation is highlighted. Gray out the not-affected-due-to-controls amplitudes. Show pairings when dealing with a single qubit gate, to make it clearer how the values are interacting.
  • Arranging the states with a space filling curve, instead of directly by their binary index, might make the same operation on another qubit "look" the same.
  • Amplify sizes when everything is small?

Sparse matrix optimizations

Single-wire gates have sparse matrices. Taking advantage of that could give significant performance boosts and allow more wires.

Quantum peek gate

The peek gate can give per-write conditional probabilities, but seeing intermediate partial quantum states would also be useful.

Round drag offset once gates start snapping to the circuit

When a single-qubit gate starts snapping to the circuit, the vertical height where it switches between wires seems wrong. This is because the grab-offset is not the relevant part anymore.

When snapping starts, round the drag offset to the nearest 'center of wire' offset.

Increment/decrement gates

Incrementing could be done significantly cheaper if it was a single gate that touched multiple qubits and acted like a shift in texture-land.

Gates on top of each other

Currently can't, for example, put two hadamard gates in the same vertical column. Causes circuits to unnecessarily spread out horizontally.

Test and fix precision fallback code

Apparently gl.getShaderPrecisionFormat returns null or undefined in some cases, so the current code just crashes when high precision isn't supported. The webgl code needs to be tested on lower capability machines. Ideally automatically.

Look for services that can run CI tests including webgl on a variety of machines.

Test webglcontextrestored recovery code

There's a bunch of code intended to work when webglcontextlost/webglcontextrestored happens, but it's not exercised.

(Every once in awhile I leave Quirk alone, come back later, and the canvas is blank until I interact with it. This might be related?)

Saving / loading

Should be able to come back to a circuit later, or on another machine.

Current idea is to just have an auto-updating anchor element that always points to the "current" circuit, so saving is just a matter of bookmarking. Most of the code is already done, but it was de-activated by the ES6 rewriting noise.

Gate modifiers (square root, inverse)

Being able to hit gates with modifier tools might make the interface sparser by removing the need for having all the various square roots and inverses available up front...?

Encountered error: Error: c: malformed URI sequence in src/main.js

Hello Strilanc,

it was mostly working well enough for me, but when trying to return to a url via my history I got a another error.

URL
http://algorithmicassertions.com/quirk#circuit={%22cols%22:[[%22X%22,%22%E2%80%A2%22,%22X%22],[1,%22X^%E2%85%93%22,%22X^%E2%85%93%22],[1,1,%22X^%E2%85%93%22],[%22Bloch%22,%22Bloch%22,%22Bloch%22],[1,%22%E2%80%A2%22,%22%E2%80%A2%22,%22X%22],[1,%22%E2%97%A6%22,%22%E2%97%A6%22,%22X%22]]}

BROWSER USER AGENT
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:38.0) Gecko/20100101 Firefox/38.0

ERROR OBJECT
Error: c: malformed URI sequence in src/main.js

ERROR LOCATION
[email protected]:957:1
[email protected]:958:29
@src.min.js:960:53
[email protected]:23:13
[email protected]:28:49
@src.min.js:1607:89

Show link instead of error when history push/replace isn't allowed

When Quirk is running in a context where history modification violates the same-origin policy (e.g. when running locally from a file:// uri), it shows the error box every time the circuit is modified due to an exception being thrown when touching the history. Instead, it should fall back to a 'current circuit' link.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.