├── .github
└── workflows
│ └── ci.yml
├── .gitignore
├── CONTRIBUTING.md
├── GruntFile.js
├── LICENSE
├── PuppeteerRunTests.js
├── PuppeteerScreenshotCircuit.js
├── README.md
├── doc
├── MANUAL_amp-display.png
├── MANUAL_bloch-display.png
├── MANUAL_chance-display.png
├── MANUAL_circuit-editing-area.png
├── MANUAL_controlled-display.png
├── MANUAL_controlled-epr-display.png
├── MANUAL_density-display.png
├── MANUAL_measurement-types.png
├── MANUAL_menu.png
├── MANUAL_state-channel-duality.png
├── MANUAL_various-displays.png
├── README.md
├── README_Demo.gif
├── README_Grover.gif
├── README_Teleportation.gif
└── favicon.ico
├── html
├── error.partial.html
├── export.partial.html
├── forge.partial.html
├── menu.partial.html
└── quirk.template.html
├── karma.test.conf.js
├── karma.test_perf.conf.js
├── package-lock.json
├── package.json
├── src
├── Config.js
├── base
│ ├── CooldownThrottle.js
│ ├── Describe.js
│ ├── DetailedError.js
│ ├── Equate.js
│ ├── Format.js
│ ├── Obs.js
│ ├── RestartableRng.js
│ ├── Revision.js
│ ├── Seq.js
│ └── Util.js
├── browser
│ ├── Clipboard.js
│ ├── EventUtil.js
│ ├── HistoryPusher.js
│ ├── MouseWatcher.js
│ ├── Polyfills.js
│ ├── SaveFile.js
│ └── TouchScrollBlocker.js
├── circuit
│ ├── CircuitComputeUtil.js
│ ├── CircuitDefinition.js
│ ├── CircuitEvalContext.js
│ ├── CircuitShaders.js
│ ├── CircuitStats.js
│ ├── Controls.js
│ ├── CustomGateSet.js
│ ├── Gate.js
│ ├── GateCheckArgs.js
│ ├── GateColumn.js
│ ├── GateShaders.js
│ ├── KetShaderUtil.js
│ ├── KetTextureUtil.js
│ └── Serializer.js
├── draw
│ ├── CachablePainting.js
│ ├── GateDrawParams.js
│ ├── GatePainting.js
│ ├── MathPainter.js
│ ├── Painter.js
│ └── WidgetPainter.js
├── fallback.js
├── gates
│ ├── AllGates.js
│ ├── AmplitudeDisplay.js
│ ├── ArithmeticGates.js
│ ├── BitCountGates.js
│ ├── BlochSphereDisplay.js
│ ├── ComparisonGates.js
│ ├── Controls.js
│ ├── CountingGates.js
│ ├── CycleBitsGates.js
│ ├── Debug_ErrorInjectionGate.js
│ ├── DensityMatrixDisplay.js
│ ├── Detector.js
│ ├── ExponentiatingGates.js
│ ├── FourierTransformGates.js
│ ├── HalfTurnGates.js
│ ├── Impossible_UniversalNotGate.js
│ ├── IncrementGates.js
│ ├── InputGates.js
│ ├── InterleaveBitsGates.js
│ ├── Joke_ImaginaryGate.js
│ ├── Joke_MysteryGate.js
│ ├── Joke_NeGate.js
│ ├── Joke_ZeroGate.js
│ ├── MeasurementGate.js
│ ├── ModularAdditionGates.js
│ ├── ModularIncrementGates.js
│ ├── ModularMultiplicationGates.js
│ ├── ModularMultiplyAccumulateGates.js
│ ├── MultiplicationGates.js
│ ├── MultiplyAccumulateGates.js
│ ├── ParametrizedRotationGates.js
│ ├── PhaseGradientGates.js
│ ├── PivotFlipGates.js
│ ├── PostSelectionGates.js
│ ├── PoweringGates.js
│ ├── ProbabilityDisplay.js
│ ├── QuarterTurnGates.js
│ ├── ReverseBitsGate.js
│ ├── SampleDisplay.js
│ ├── SpacerGate.js
│ ├── SwapGateHalf.js
│ ├── VariousXGates.js
│ ├── VariousYGates.js
│ ├── VariousZGates.js
│ └── XorGates.js
├── issues.js
├── main.js
├── math
│ ├── Axis.js
│ ├── Complex.js
│ ├── FormulaParser.js
│ ├── Matrix.js
│ ├── Point.js
│ └── Rect.js
├── ui
│ ├── DisplayedCircuit.js
│ ├── DisplayedInspector.js
│ ├── DisplayedToolbox.js
│ ├── Hand.js
│ ├── clear.js
│ ├── exports.js
│ ├── forge.js
│ ├── menu.js
│ ├── sim.js
│ ├── title.js
│ ├── undo.js
│ └── url.js
└── webgl
│ ├── ShaderCoders.js
│ ├── ShaderCoders_Base.js
│ ├── ShaderCoders_intoBytes.js
│ ├── ShaderCoders_intoFloats.js
│ ├── Shaders.js
│ ├── WglArg.js
│ ├── WglConfiguredShader.js
│ ├── WglContext.js
│ ├── WglMortalValueSlot.js
│ ├── WglShader.js
│ ├── WglTexture.js
│ ├── WglTexturePool.js
│ ├── WglTextureTrader.js
│ └── WglUtil.js
├── test
├── CircuitOperationTestUtil.js
├── KarmaTestRunner.test.js
├── TestUtil.js
├── base
│ ├── Describe.test.js
│ ├── DetailedError.test.js
│ ├── Equate.test.js
│ ├── Format.test.js
│ ├── Obs.test.js
│ ├── RestartableRng.test.js
│ ├── Revision.test.js
│ ├── Seq.test.js
│ └── Util.test.js
├── circuit
│ ├── CircuitComputeUtil.test.js
│ ├── CircuitDefinition.test.js
│ ├── CircuitShaders.test.js
│ ├── CircuitStats.test.js
│ ├── Controls.test.js
│ ├── Gate.test.js
│ ├── GateColumn.test.js
│ ├── GateShaders.test.js
│ ├── KetShaderUtil.test.js
│ └── Serializer.test.js
├── gates
│ ├── AllGates.test.js
│ ├── AmplitudeDisplay.test.js
│ ├── ArithmeticGates.test.js
│ ├── BitCountGates.test.js
│ ├── ComparisonGates.test.js
│ ├── Controls.test.js
│ ├── CycleBitsGates.test.js
│ ├── DensityMatrixDisplay.test.js
│ ├── Detector.test.js
│ ├── ExponentiatingGates.test.js
│ ├── FourierTransformGates.test.js
│ ├── Impossible_UniversalNotGate.test.js
│ ├── IncrementGates.test.js
│ ├── InputGates.test.js
│ ├── InterleaveBitsGates.test.js
│ ├── ModularAdditionGates.test.js
│ ├── ModularIncrementGates.test.js
│ ├── ModularMultiplicationGates.test.js
│ ├── ModularMultiplyAccumulateGates.test.js
│ ├── MultiplicationGates.test.js
│ ├── MultiplyAccumulateGates.test.js
│ ├── ParametrizedRotationGates.test.js
│ ├── PhaseGradientGates.test.js
│ ├── PivotFlipGates.test.js
│ ├── ProbabilityDisplay.test.js
│ ├── SampleDisplay.test.js
│ └── XorGates.test.js
├── math
│ ├── Axis.test.js
│ ├── Complex.test.js
│ ├── Matrix.test.js
│ ├── Point.test.js
│ └── Rect.test.js
├── ui
│ ├── DisplayedCircuit.test.js
│ ├── MathPainter.test.js
│ ├── Painter.test.js
│ ├── WidgetPainter.test.js
│ └── forge.test.js
└── webgl
│ ├── ShaderCoders.test.js
│ ├── ShaderCoders_Base.test.js
│ ├── ShaderCoders_intoBytes.test.js
│ ├── ShaderCoders_intoFloats.test.js
│ ├── Shaders.test.js
│ ├── WglArg.test.js
│ ├── WglShader.test.js
│ ├── WglTexture.test.js
│ └── WglTexturePool.test.js
└── test_perf
├── CircuitStats.perf.js
├── DisplayedInspector.perf.js
├── KarmaTestRunner.perf.js
├── TestPerfUtil.js
└── test_page.template.html
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: ci
2 | on: [push, pull_request]
3 | jobs:
4 | build-and-run-unit-tests:
5 | runs-on: ubuntu-latest
6 | steps:
7 | - uses: actions/checkout@v2
8 | - uses: actions/setup-node@v1
9 | with:
10 | node-version: 12.x
11 | - run: npm install
12 | - run: grunt build-test-page
13 | - run: node PuppeteerRunTests.js
14 | screenshot-circuit:
15 | runs-on: ubuntu-latest
16 | steps:
17 | - uses: actions/checkout@v2
18 | - uses: actions/setup-node@v1
19 | with:
20 | node-version: 12.x
21 | - run: npm install
22 | - run: npm run build
23 | - run: node PuppeteerScreenshotCircuit.js
24 | - uses: actions/upload-artifact@v2
25 | with:
26 | name: screenshot
27 | path: screenshot.png
28 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/*
2 | node_modules/*
3 | out/*
4 | .eslintrc
5 | *.git_ignore.js
6 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to Contribute
2 |
3 | We'd love to accept your patches and contributions to this project. There are
4 | just a few small guidelines you need to follow.
5 |
6 | ## Contributor License Agreement
7 |
8 | Contributions to this project must be accompanied by a Contributor License
9 | Agreement. You (or your employer) retain the copyright to your contribution,
10 | this simply gives us permission to use and redistribute your contributions as
11 | part of the project. Head over to
2 |
3 | [](https://travis-ci.org/Strilanc/Quirk)
4 |
5 | Quirk is a toy quantum circuit simulator, intended to help people in learning about quantum computing.
6 |
7 | If you want to quickly explore the behavior of a small quantum circuit, Quirk is the tool for you.
8 | There's no installing or configuring or scripting: just go to **[algassert.com/quirk](http://algassert.com/quirk)**, drag gates onto the circuit, and the output displays will update in real time.
9 |
10 | (If you're still trying to understand what a quantum circuit *even is*, then I recommend the video series [Quantum Computing for the Determined](https://www.youtube.com/playlist?list=PL1826E60FD05B44E4).
11 | Quirk assumes you already know background facts like "each wire represents a qubit".)
12 |
13 | **Defining features**:
14 |
15 | - Runs in web browsers.
16 | - Drag-and-drop circuit editing.
17 | - Reacts, simulates, and animates in real time.
18 | - Inline state displays.
19 | - Bookmarkable / linkable circuits.
20 | - Up to 16 qubits.
21 |
22 | **Notable limitations**:
23 |
24 | - Can't recohere measured qubits (because measurement is implemented as a hack based on the [deferred measurement principle](https://en.wikipedia.org/wiki/Deferred_Measurement_Principle)).
25 |
26 | **Try it out**:
27 |
28 | **[algassert.com/quirk](http://algassert.com/quirk)**
29 |
30 | # Examples
31 |
32 | **Basic usage demo**:
33 |
34 | 
35 |
36 | **Grover search circuit** with chance and sample displays (showing that the chance of success increases):
37 |
38 | 
39 |
40 | **Quantum teleportation circuit** with Bloch sphere displays (showing that the qubit at the top has ended up at the bottom):
41 |
42 | 
43 |
44 | # Building
45 |
46 | If you want to modify Quirk, this is how you get the code and turn your changes into working html/javascript.
47 |
48 | 1. Have [git](https://git-scm.com/) and [Node.js](https://nodejs.org/en/download/) installed.
49 |
50 | `sudo add-apt-repository universe`
51 |
52 | `sudo apt-get update`
53 |
54 | `sudo apt-get install --yes git npm nodejs-legacy`
55 |
56 | 2. Clone the repository.
57 |
58 | `git clone https://github.com/Strilanc/Quirk.git`
59 |
60 | 3. Install the dev dependencies.
61 |
62 | `cd Quirk`
63 |
64 | `npm install`
65 |
66 | 4. (*Optional*) Make your changes. Run the tests.
67 |
68 | `npm run test-firefox`
69 |
70 | 5. Build the output.
71 |
72 | `npm run build`
73 |
74 | 6. Confirm the output works by opening `out/quirk.html` with a web browser.
75 |
76 | `firefox out/quirk.html`
77 |
78 | 7. Copy `out/quirk.html` to wherever you want.
79 |
80 | # Disclaimer
81 |
82 | Quirk is not an official Google product.
83 |
--------------------------------------------------------------------------------
/doc/MANUAL_amp-display.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Strilanc/Quirk/8833791294e642795c8717038e84940a74b19a64/doc/MANUAL_amp-display.png
--------------------------------------------------------------------------------
/doc/MANUAL_bloch-display.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Strilanc/Quirk/8833791294e642795c8717038e84940a74b19a64/doc/MANUAL_bloch-display.png
--------------------------------------------------------------------------------
/doc/MANUAL_chance-display.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Strilanc/Quirk/8833791294e642795c8717038e84940a74b19a64/doc/MANUAL_chance-display.png
--------------------------------------------------------------------------------
/doc/MANUAL_circuit-editing-area.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Strilanc/Quirk/8833791294e642795c8717038e84940a74b19a64/doc/MANUAL_circuit-editing-area.png
--------------------------------------------------------------------------------
/doc/MANUAL_controlled-display.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Strilanc/Quirk/8833791294e642795c8717038e84940a74b19a64/doc/MANUAL_controlled-display.png
--------------------------------------------------------------------------------
/doc/MANUAL_controlled-epr-display.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Strilanc/Quirk/8833791294e642795c8717038e84940a74b19a64/doc/MANUAL_controlled-epr-display.png
--------------------------------------------------------------------------------
/doc/MANUAL_density-display.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Strilanc/Quirk/8833791294e642795c8717038e84940a74b19a64/doc/MANUAL_density-display.png
--------------------------------------------------------------------------------
/doc/MANUAL_measurement-types.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Strilanc/Quirk/8833791294e642795c8717038e84940a74b19a64/doc/MANUAL_measurement-types.png
--------------------------------------------------------------------------------
/doc/MANUAL_menu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Strilanc/Quirk/8833791294e642795c8717038e84940a74b19a64/doc/MANUAL_menu.png
--------------------------------------------------------------------------------
/doc/MANUAL_state-channel-duality.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Strilanc/Quirk/8833791294e642795c8717038e84940a74b19a64/doc/MANUAL_state-channel-duality.png
--------------------------------------------------------------------------------
/doc/MANUAL_various-displays.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Strilanc/Quirk/8833791294e642795c8717038e84940a74b19a64/doc/MANUAL_various-displays.png
--------------------------------------------------------------------------------
/doc/README.md:
--------------------------------------------------------------------------------
1 | **Basic Actions**
2 |
3 | - **add gate**: `drag` gate from toolbox to circuit
4 | - **move gate**: `drag` gate in circuit
5 | - **remove gate**: `drag` gate out of circuit **OR** `middle-click` gate
6 | - **undo**: `ctrl + Z` **OR** click 'undo' button
7 | - **redo**: `ctrl + shift + Z` **OR** `ctrl + Y` **OR** click 'redo' button
8 | - **save circuit**: bookmark the page with your browser
9 | - **load circuit**: open the bookmark
10 | - **add qubit**: `drag` gate onto extra wire that appears while dragging
11 | - **remove qubit**: re-arrange gates so that the bottom wire is unused
12 | - **show intermediate state**: `drag` a display gate onto the circuit
13 | - **view tips**: `hover` with mouse **OR** awkwardly tap-hold with finger
14 |
15 | **Advanced Actions**
16 |
17 | - **copy gate**: `shift + drag` gate in circuit
18 | - **move column**: `ctrl + drag` in circuit
19 | - **copy column**: `ctrl + shift + drag` in circuit
20 | - **create custom gate**: click 'Make Gate' button
21 | - **remove custom gate**: [crummy support] have to use undo or clear all or manually edit URL
22 |
23 | **Conventions**
24 |
25 | - Coordinates
26 | - Right-handed
27 | - X is +right/-left
28 | - Y is +forward/-backward
29 | - Z is +up/-down
30 | - Ordering
31 | - Top wire is the low bit. Bottom wire is the high bit.
32 | - Kets are big-endian. |00101⟩ is 5, not 20.
33 | - Listed/grided values are in ascending row-major order from top left to bottom right.
34 | - Colors
35 | - Blue: amplitudes
36 | - Green: probabilities / densities
37 | - Yellow: change / varying
38 | - Orange: focused
39 | - Red: error / attention
40 |
--------------------------------------------------------------------------------
/doc/README_Demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Strilanc/Quirk/8833791294e642795c8717038e84940a74b19a64/doc/README_Demo.gif
--------------------------------------------------------------------------------
/doc/README_Grover.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Strilanc/Quirk/8833791294e642795c8717038e84940a74b19a64/doc/README_Grover.gif
--------------------------------------------------------------------------------
/doc/README_Teleportation.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Strilanc/Quirk/8833791294e642795c8717038e84940a74b19a64/doc/README_Teleportation.gif
--------------------------------------------------------------------------------
/doc/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Strilanc/Quirk/8833791294e642795c8717038e84940a74b19a64/doc/favicon.ico
--------------------------------------------------------------------------------
/html/error.partial.html:
--------------------------------------------------------------------------------
1 |
9 |10 | 54 | 55 | 56 | --------------------------------------------------------------------------------