Skip to content

Commit

Permalink
Development leading to v2.2 Strilanc#404
Browse files Browse the repository at this point in the history
  • Loading branch information
Strilanc authored Mar 25, 2019
2 parents 34fdf99 + ab8fc9a commit be6b213
Show file tree
Hide file tree
Showing 64 changed files with 1,795 additions and 646 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ sudo: false
language: node_js
node_js: 5.1
install: npm install
branches:
only: master
before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
Expand Down
Binary file added doc/MANUAL_amp-display.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/MANUAL_bloch-display.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/MANUAL_chance-display.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/MANUAL_circuit-editing-area.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/MANUAL_controlled-display.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/MANUAL_controlled-epr-display.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/MANUAL_density-display.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/MANUAL_measurement-types.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/MANUAL_menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/MANUAL_state-channel-duality.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/MANUAL_various-displays.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion html/export.partial.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@
<button tabindex="102" id="download-offline-copy-button" style="width:600px; height:60px;">Download ...</button>
</div>

<strong>JSON</strong> - Parsable representation of current circuit.
<strong>Circuit JSON</strong> - Parsable representation of current circuit.
<div style="margin: 10px 0 0 20px;">
<button tabindex="103" id="export-json-copy-button">Copy to Clipboard</button>&nbsp;&nbsp;<span id="export-json-copy-result"></span>
<br>
<pre tabindex="104" id="export-circuit-json-pre" style="overflow:auto; max-width:600px; max-height:60px; border: 1px solid black; padding:5px; margin:2px;"></pre>
</div>

<br>
<strong>Simulation Data JSON</strong> - Output amplitudes, detector results, display data, etc.
<div style="margin: 10px 0 0 20px;">
<button tabindex="105" id="export-amplitudes-button">Generate and Copy to Clipboard</button>&nbsp;<span id="export-amplitudes-result"></span>
<input type="checkbox" tabindex="106" id="export-amplitudes-use-amps" style="float: right; margin-right: 10px;">
<label style="float: right" for="export-amplitudes-use-amps">Skip output amplitudes</label>
<br>
<pre tabindex="107" id="export-amplitudes-pre" style="overflow:auto; max-width:600px; max-height:60px; border: 1px solid black; padding:5px; margin:2px;"></pre>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion html/forge.partial.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<td></td>
<td>
<style scoped>
input[type="checkbox"]:not(:checked) + label {
input[id="gate-forge-matrix-fix"]:not(:checked) + label {
font-weight: bold;
background-color: pink;
}
Expand Down
29 changes: 21 additions & 8 deletions html/menu.partial.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div id="menu-div" style="display:block;">
<div id="menu-overlay" style="position:fixed; left: 0; top: 0; height: 100vh; width: 100vw; background: rgba(0, 0, 0, 0.7);">
<div id="menu-overlay" style="position:fixed; left: 0; top: 0; height: 100vh; width: 100vw; background: rgba(0, 0, 0, 0.8);">
</div>
<div style="position:absolute; top:20px; left:50px; margin:0;">
<div style="display:inline-block; padding:20px; background-color:white; border:1px solid black; text-align:center;">
Expand All @@ -11,23 +11,35 @@
A drag-and-drop quantum circuit simulator.

<div style="margin:20px;">
<div id="loading-div" style="color:#D90; font-size:40px; display:block; height:120px; width:344px;">
<div id="loading-div" style="color:#D90; font-size:40px; display:block; height:120px; width:410px;">
Loading...
</div>
<button tabindex="50" id="close-menu-button" style="width:344px; height:120px; font-size:20px; display:none;">Edit Circuit</button>
<button tabindex="50" id="close-menu-button" style="width:410px; height:120px; font-size:20px; display:none;">Edit Circuit</button>
</div>

<div style="display:inline-block; text-align:center; border:1px solid black; padding:4px; margin-right:64px;">
<a tabindex="51" href="https://www.youtube.com/watch?v=aloFwlBUwsQ">
<div style="display:inline-block; text-align:center; border:1px solid black; padding:2px;">
<a tabindex="51" href="https://github.com/Strilanc/Quirk/wiki/How-to-use-Quirk">
<div style="width:128px;">
<svg version="1.1" viewBox="0 0 20 25" width="48" height="48">
<text x="5" y="9" style="font-size: 8px;">???</text>
  <path d="M0 0 h20 v25 h-20 v-25 M3 13 h14 M3 17 h14 M3 21 h14" stroke="black" fill="transparent"></path>
</svg>
<div>How to Use</div>
</div>
</a>
</div>

<div style="display:inline-block; text-align:center; border:1px solid black; padding:2px;">
<a tabindex="52" href="https://www.youtube.com/watch?v=aloFwlBUwsQ">
<div style="width:128px;">
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAACt0lEQVQoz+3SP09TYRQG8IOL4RsgSNvbv4C4uMAkLgbippEw6CKwqIuGwW/gZEI6kIiDo0MnEk1MmEBLRQFbCnJLa6WlFK6K2kKrBarH55p7TUWa1vgm8pqe5Jc0vbfneZ+8JWYmmUl9+FqBWoFagf+hwP5Jn/TUQw/cgmG4Dz54DH4IQQwSkIaMgf+Q+bu0sStm7PYbWT4je9g4i36meio3a+2eOrgBGeBDKmOcse63Aql29yiwJO79cvjVE+4+YMn0/SyQbHNPA0tm+sfhV9rcdmBJOehNq2sQWFKDFG91eYEl5aXXLS4fsKR8FPM4A8BCtLq3hO2qToCiHqcKLMJOKrW3NnTzZbTFlRO1swKVlt1ODViEr9ks65NPpQor/VeCyx5XQdTuMjSKuBw5YBHMAvoU9/Z4MxzejvdeDOJZUVTGPjlS8UGUYkkBc/JbW7weCGRi53rm8c43kXk6euV0sCgHFTBv46OmcXp8/F3kTNeCyExadDhYlHIFSm/jbTLJqbGx9aWOjoiITFpw2FmUSgXM2/iwscFaIsHRgf7I32ZS2G5nUaopoM+237+61Nm5JCKT5hU7i1LxLxQKaerprrDITAopCotSrsAXVX0f6e4OiswyUdCmsCj7C+wkk9no+QtzeFYUmVOK5qxKDlgEs8CupuWjly7P4LtdUbvLyNGsVdGARSisJArxq9dmZ232gqidFWg0Y7GpwEJYlbywXdVR6UWzbQpYUlP0vNnmA5aUj6aPW73AkvLSsybrALCkBijQZFWAJaWQPlONlgCwZAJkztNGSy+wZHqpdJ4cs4wAS2KEDprJBssgJIEPqU24DnVUbiYamo/AKeiH23AXHsAjmISQIQ4J0CBjyAJX4bPx/idjh27R2DsBD43MUbgDQ3AWjv52YGaWWq1ArUCtQK3Av/UdR/1BF+14cggAAAAASUVORK5CYII=">
<div>Tutorial Video</div>
</div>
</a>
</div>

<div style="display:inline-block; text-align:center; border:1px solid black; padding:4px;">
<a tabindex="52" href="https://github.com/Strilanc/Quirk">
<div style="display:inline-block; text-align:center; border:1px solid black; padding:2px;">
<a tabindex="53" href="https://github.com/Strilanc/Quirk">
<div style="width:128px;">
<svg version="1.1" viewBox="0 0 16 16" width="48" height="48">
<path fill-rule="evenodd"
Expand All @@ -39,7 +51,7 @@
</a>
</div>
</div>
<div style="display:inline-block; vertical-align:top; line-height:1.8; padding:15px 15px 15px 5px; background-color:#DDD; border:1px solid gray; margin:10px 0 0 -5px;">
<div style="display:inline-block; vertical-align:top; line-height:1.8; padding:13px 15px 13px 5px; background-color:#DDD; border:1px solid gray; margin:0 0 0 -5px;">
Example Circuits<br>
<a id="example-anchor-grover">Grover Search</a><br>
<a id="example-anchor-shor">Shor Period Finding</a><br>
Expand All @@ -50,6 +62,7 @@
<a id="example-symmetry-break">Symmetry Breaking</a><br>
<a id="example-qft">Quantum Fourier Transform</a><br>
<a id="example-addition">Reversible Addition</a><br>
<a id="example-anchor-distill">Magic State Distillation</a><br>
</div>
</div>
</div>
2 changes: 2 additions & 0 deletions src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,6 @@ Config.DEFAULT_STROKE_THICKNESS = 1;
Config.CHECK_WEB_GL_ERRORS_EVEN_ON_HOT_PATHS = false;
Config.SEMI_STABLE_RANDOM_VALUE_LIFETIME_MILLIS = 300;

Config.IGNORED_WEBGL_INFO_TERMS = [];

export {Config}
2 changes: 1 addition & 1 deletion src/base/Equate.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,4 @@ function equate_Objects(subject, other) {
return true;
}

export {equate}
export {equate, equate_Maps}
3 changes: 3 additions & 0 deletions src/circuit/CircuitComputeUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import {CircuitEvalContext} from "src/circuit/CircuitEvalContext.js"
import {CircuitShaders} from "src/circuit/CircuitShaders.js"
import {DetailedError} from "src/base/DetailedError.js"
import {KetTextureUtil} from "src/circuit/KetTextureUtil.js"
import {Controls} from "src/circuit/Controls.js"
import {GateBuilder} from "src/circuit/Gate.js"
Expand Down Expand Up @@ -83,6 +84,8 @@ function advanceStateWithCircuit(ctx, circuitDefinition, collectStats) {
}
};

circuitDefinition.applyInitialStateOperations(ctx);

// Apply each column in the circuit.
for (let col = 0; col < circuitDefinition.columns.length; col++) {
_advanceStateWithCircuitDefinitionColumn(
Expand Down
91 changes: 83 additions & 8 deletions src/circuit/CircuitDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import {Config} from "src/Config.js"
import {Controls} from "src/circuit/Controls.js"
import {CustomGateSet} from "src/circuit/CustomGateSet.js"
import {DetailedError} from "src/base/DetailedError.js"
import {equate_Maps} from "src/base/Equate.js";
import {Gate} from "src/circuit/Gate.js"
import {GateColumn} from "src/circuit/GateColumn.js"
import {GateShaders} from "src/circuit/GateShaders.js"
import {Gates} from "src/gates/AllGates.js"
import {Gates, INITIAL_STATES_TO_GATES} from "src/gates/AllGates.js"
import {Point} from "src/math/Point.js"
import {seq, Seq} from "src/base/Seq.js"
import {Util} from "src/base/Util.js"
Expand All @@ -39,13 +40,15 @@ class CircuitDefinition {
* @param {undefined|!Map.<!string, *>=} outerContext
* @param {!CustomGateSet} customGateSet
* @param {!boolean} isNested
* @param {!Map.<!int, !string>} customInitialValues
*/
constructor(numWires,
columns,
outerRowOffset=0,
outerContext=new Map(),
customGateSet=new CustomGateSet(),
isNested=false) {
isNested=false,
customInitialValues=new Map()) {
if (numWires < 0) {
throw new DetailedError("Bad numWires", {numWires})
}
Expand All @@ -69,6 +72,17 @@ class CircuitDefinition {
this.outerRowOffset = outerRowOffset;
this.outerContext = outerContext;
this.isNested = isNested;
/** @type {!Map.<!int, !string>} */
this.customInitialValues = new Map();
for (let [k, v] of customInitialValues.entries()) {
if (!Number.isInteger(k) || k < 0) {
throw new DetailedError('Initial state key out of range.', {customInitialValues, numWires});
}
if (k >= this.numWires) {
continue;
}
this.customInitialValues.set(k, v);
}

/**
* @type {!Array.<!Array.<undefined|!string>>}
Expand Down Expand Up @@ -126,6 +140,38 @@ class CircuitDefinition {
return !this.columns.every(e => !e.hasControl(-1));
}

/**
* @param {!int} wire
* @returns {!CircuitDefinition}
*/
withSwitchedInitialStateOn(wire) {
let m = new Map([...this.customInitialValues.entries()]);
let v = m.get(wire);
let cycle = [...INITIAL_STATES_TO_GATES.keys()];
let newVal = cycle[(cycle.indexOf(v) + 1) % cycle.length];
if (newVal === undefined) {
m.delete(wire);
} else {
m.set(wire, newVal);
}
return this.withInitialStates(m);
}

/**
* @param {!Map.<!int, *>} map
* @returns {!CircuitDefinition}
*/
withInitialStates(map) {
return new CircuitDefinition(
this.numWires,
this.columns,
this.outerRowOffset,
this.outerContext,
this.customGateSet,
this.isNested,
map);
}

/**
* @returns {!boolean}
*/
Expand Down Expand Up @@ -194,7 +240,8 @@ class CircuitDefinition {
outerRowOffset,
outerContext,
this.customGateSet,
true);
true,
this.customInitialValues);
}

/**
Expand Down Expand Up @@ -235,7 +282,8 @@ class CircuitDefinition {
}
return other instanceof CircuitDefinition &&
this.numWires === other.numWires &&
seq(this.columns).isEqualTo(seq(other.columns), Util.CUSTOM_IS_EQUAL_TO_EQUALITY);
seq(this.columns).isEqualTo(seq(other.columns), Util.CUSTOM_IS_EQUAL_TO_EQUALITY) &&
equate_Maps(this.customInitialValues, other.customInitialValues);
}

/**
Expand Down Expand Up @@ -355,7 +403,9 @@ class CircuitDefinition {
cols,
this.outerRowOffset,
this.outerContext,
this.customGateSet);
this.customGateSet,
false,
this.customInitialValues);
}

/**
Expand Down Expand Up @@ -508,7 +558,9 @@ class CircuitDefinition {
seq(this.columns).filterWithIndex((e, i) => used.has(i)).toArray(),
this.outerRowOffset,
this.outerContext,
this.customGateSet);
this.customGateSet,
false,
this.customInitialValues);
}

/**
Expand All @@ -527,7 +579,9 @@ class CircuitDefinition {
])),
this.outerRowOffset,
this.outerContext,
this.customGateSet);
this.customGateSet,
false,
this.customInitialValues);
}

/**
Expand All @@ -539,6 +593,9 @@ class CircuitDefinition {
for (let c of this.columns) {
best = Math.max(best, c.minimumRequiredWireCount());
}
for (let usedWire of this.customInitialValues.keys()) {
best = Math.max(best, usedWire + 1);
}
return best;
}

Expand Down Expand Up @@ -845,6 +902,22 @@ class CircuitDefinition {
return this._colRowDisabledReason[col][row];
}

/**
* @param {!CircuitEvalContext} ctx
* @return {void}
*/
applyInitialStateOperations(ctx) {
for (let wire = 0; wire < this.numWires; wire++) {
let state = this.customInitialValues.get(wire);
if (!INITIAL_STATES_TO_GATES.has(state)) {
throw new DetailedError('Unrecognized initial state.', {state});
}
for (let gate of INITIAL_STATES_TO_GATES.get(state)) {
GateShaders.applyMatrixOperation(ctx.withRow(ctx.row + wire), gate.knownMatrixAt(ctx.time))
}
}
}

/**
* @param {!int} colIndex
* @param {!CircuitEvalContext} ctx
Expand Down Expand Up @@ -964,7 +1037,9 @@ class CircuitDefinition {
this.columns,
this.outerRowOffset,
this.outerContext,
this.customGateSet.withGate(gate));
this.customGateSet.withGate(gate),
false,
this.customInitialValues);
}

/**
Expand Down
Loading

0 comments on commit be6b213

Please sign in to comment.