Skip to content

Commit

Permalink
Merge pull request Strilanc#373 from Strilanc/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Strilanc authored Aug 15, 2017
2 parents 0ba0b2e + 870234f commit 95d154b
Show file tree
Hide file tree
Showing 23 changed files with 328 additions and 169 deletions.
6 changes: 2 additions & 4 deletions html/quirk.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<html>
<head lang="en">
<meta charset="UTF-8">
<meta name="keywords" content="quantum,simulator,circuit,quirk">
<meta name="description" content="Quirk is a toy quantum circuit simulator for exploring and understanding small quantum circuits.">
<meta name="keywords" content="quantum,circuit,simulator,quirk">
<meta name="description" content="Quirk is an open-source drag-and-drop quantum circuit simulator for exploring and understanding small quantum circuits.">
<title>Quirk: Quantum Circuit Simulator</title>
<link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAJGUlEQVRYw6WXa2xUZRrHf+fM6ZyZdmY6M50yhdJSoLWtWUkLQmvF1W2AaAvpiss2Gy9LrLIJGq/EWyKJbnYDiTHRbDXULWtEN1sNYMuWRaAuKoyASitgOr1bLG1HhplhzrRz6XTOfmjniG3xts/59J7znuf5v+9z+z8CPyBNTU3U1tYCUFFRgc/vswIlQCFQDjimt3qBk0AX0GG32QMul2uWjrlEuNaH5uZmampqKCouShpFNsr3RsPRnLKKsrx0W7pceF1hNkBPb4+il/T+lv0tF2Wj3B0NR/dMq+lwd7oDSV0/GUBjYyN1dXVJ4w/mLMlZs/WRratMVpPV6XTiPuum7NYyPAMeAJyLnZz66BRFy4rweDyEAqFA/av1p4f6h44Cb7g73YGkzpmimwtAd0+31ZHpKF+Qt2D7fXX3bdm2fVvxdddfZ8hakMVA5wCKpFBcWIzP4wMga1EWvaO9iOMiJWUl5OXnGW5ff/vS9PT0m1ApiEVjl10uV8Dr9UZ+FMD0qTevX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FHWdcR117gY7GxkZtUNFYcUtLC16vN+LIdLgHewfFwcFBkzPDmZtqTtWYsV7SM+oZxZ5hn0XLw6EwIyMjLFm6BIPRoPm868su6l+pP/7J4U/+Bbzp7nQHkox4zrkgCeJC/4XO9o52WVTFxXn5eXpZlpENMr4RH+6LbvLz8r9Hy4+dPIZVbyW3IBdBELSA2/X6rr1fnfnqJeDQdKz9+GS0c+fOyO7G3V/LKXLbZ59+Fjr24THV6XBm+Hw+w7z58/Bd8DFv/jxGvhkhFothtpoZ7h4mZ2mOt6+nL7X7q+7A8089/3HbwbZ/KAHlz+5O9/dmgV88nOqN+j/EwjHH+jvXl07GJ235+flmgK7urouSTlIOthw8Jxvl8f97OP0J4znAuhnbDyeN/pzx/H9hJ0Pb7MiyZAAAAABJRU5ErkJggg==">

Expand All @@ -12,8 +12,6 @@
<!-- End Analytics -->
</head>
<body style="margin: 0">
<!-- INCLUDE LOADING PART -->

<!-- Primary content -->
<div id="inspectorDiv" style="display: none">
<!-- Buttons -->
Expand Down
19 changes: 12 additions & 7 deletions src/gates/AllGates.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {ErrorInjectionGate} from "src/gates/Debug_ErrorInjectionGate.js"
import {ExponentiatingGates} from "src/gates/ExponentiatingGates.js"
import {FourierTransformGates} from "src/gates/FourierTransformGates.js"
import {HalfTurnGates} from "src/gates/HalfTurnGates.js"
import {IncrementGates} from "src/gates/IncrementGates.js"
import {InputGates} from "src/gates/InputGates.js"
import {InterleaveBitsGates} from "src/gates/InterleaveBitsGates.js"
import {MeasurementGate} from "src/gates/MeasurementGate.js"
Expand Down Expand Up @@ -87,6 +88,7 @@ Gates.ErrorInjection = ErrorInjectionGate;
Gates.Exponentiating = ExponentiatingGates;
Gates.FourierTransformGates = FourierTransformGates;
Gates.HalfTurns = HalfTurnGates;
Gates.IncrementGates = IncrementGates;
Gates.InputGates = InputGates;
Gates.InterleaveBitsGates = InterleaveBitsGates;
Gates.ModularIncrementGates = ModularIncrementGates;
Expand Down Expand Up @@ -137,6 +139,7 @@ Gates.KnownToSerializer = [
...ExponentiatingGates.all,
...FourierTransformGates.all,
...HalfTurnGates.all,
...IncrementGates.all,
...InterleaveBitsGates.all,
...ModularAdditionGates.all,
...ModularIncrementGates.all,
Expand Down Expand Up @@ -265,28 +268,30 @@ Gates.BottomToolboxGroups = [
]
},
{
hint: 'Fourier',
hint: 'Frequency',
gates: [
FourierTransformGates.FourierTransformFamily.ofSize(2),
FourierTransformGates.InverseFourierTransformFamily.ofSize(2),
undefined, undefined,
PhaseGradientGates.PhaseGradientFamily.ofSize(2), PhaseGradientGates.PhaseDegradientFamily.ofSize(2),
undefined, undefined,
PhaseGradientGates.PhaseGradientFamily.ofSize(2),
PhaseGradientGates.PhaseDegradientFamily.ofSize(2),
PhaseGradientGates.DynamicPhaseGradientFamily.ofSize(2),
PhaseGradientGates.DynamicPhaseDegradientFamily.ofSize(2),
]
},
{
hint: "Inputs",
gates: [
InputGates.InputAFamily.ofSize(2), InputGates.InputRevAFamily.ofSize(2),
InputGates.InputBFamily.ofSize(2), InputGates.InputRevBFamily.ofSize(2),
InputGates.InputAFamily.ofSize(2), InputGates.SetA,
InputGates.InputBFamily.ofSize(2), InputGates.SetB,
InputGates.InputRFamily.ofSize(2), InputGates.SetR,
InputGates.SetA, InputGates.SetB,
undefined, undefined,
]
},
{
hint: 'Arithmetic',
gates: [
ArithmeticGates.IncrementFamily.ofSize(2), ArithmeticGates.DecrementFamily.ofSize(2),
IncrementGates.IncrementFamily.ofSize(2), IncrementGates.DecrementFamily.ofSize(2),
ArithmeticGates.PlusAFamily.ofSize(2), ArithmeticGates.MinusAFamily.ofSize(2),
MultiplyAccumulateGates.MultiplyAddInputsFamily.ofSize(2),
MultiplyAccumulateGates.MultiplySubtractInputsFamily.ofSize(2),
Expand Down
28 changes: 1 addition & 27 deletions src/gates/ArithmeticGates.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ const chunkedScaledAdditionPermutationMaker = (span, factor) => e => {
return a + (b << sa);
};

const offsetShader = ketShaderPermute(
'uniform float amount;',
'return mod(out_id - amount + span, span);');

const ADDITION_SHADER = ketShaderPermute(
`
uniform float factor;
Expand All @@ -44,26 +40,6 @@ const ADDITION_SHADER = ketShaderPermute(
d = mod(d, span);
return mod(out_id + span - d, span);`);

ArithmeticGates.IncrementFamily = Gate.buildFamily(1, 16, (span, builder) => builder.
setSerializedId("inc" + span).
setSymbol("+1").
setTitle("Increment Gate").
setBlurb("Adds 1 to the little-endian number represented by a block of qubits.").
setActualEffectToShaderProvider(ctx => offsetShader.withArgs(
...ketArgs(ctx, span),
WglArg.float("amount", +1))).
setKnownEffectToPermutation(t => (t + 1) & ((1 << span) - 1)));

ArithmeticGates.DecrementFamily = Gate.buildFamily(1, 16, (span, builder) => builder.
setSerializedId("dec" + span).
setSymbol("−1").
setTitle("Decrement Gate").
setBlurb("Subtracts 1 from the little-endian number represented by a block of qubits.").
setActualEffectToShaderProvider(ctx => offsetShader.withArgs(
...ketArgs(ctx, span),
WglArg.float("amount", -1))).
setKnownEffectToPermutation(t => (t - 1) & ((1 << span) - 1)));

ArithmeticGates.Legacy_AdditionFamily = Gate.buildFamily(2, 16, (span, builder) => builder.
setSerializedId("add" + span).
setSymbol("b+=a").
Expand Down Expand Up @@ -111,12 +87,10 @@ ArithmeticGates.MinusAFamily = Gate.buildFamily(1, 16, (span, builder) => builde
setKnownEffectToParametrizedPermutation((v, a) => (v - a) & ((1 << span) - 1)));

ArithmeticGates.all = [
...ArithmeticGates.IncrementFamily.all,
...ArithmeticGates.DecrementFamily.all,
...ArithmeticGates.Legacy_AdditionFamily.all,
...ArithmeticGates.Legacy_SubtractionFamily.all,
...ArithmeticGates.PlusAFamily.all,
...ArithmeticGates.MinusAFamily.all,
];

export {ArithmeticGates, offsetShader}
export {ArithmeticGates}
2 changes: 1 addition & 1 deletion src/gates/CountingGates.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {Point} from "src/math/Point.js"
import {ketArgs} from "src/circuit/KetShaderUtil.js"
import {WglArg} from "src/webgl/WglArg.js"

import {offsetShader} from "src/gates/ArithmeticGates.js"
import {offsetShader} from "src/gates/IncrementGates.js"
import {makeCycleBitsPermutation, cycleBitsShader} from "src/gates/CycleBitsGates.js"

let CountingGates = {};
Expand Down
36 changes: 36 additions & 0 deletions src/gates/IncrementGates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {Gate} from "src/circuit/Gate.js"
import {ketArgs, ketShaderPermute} from "src/circuit/KetShaderUtil.js"
import {WglArg} from "src/webgl/WglArg.js"

let IncrementGates = {};

const offsetShader = ketShaderPermute(
'uniform float amount;',
'return mod(out_id - amount + span, span);');

IncrementGates.IncrementFamily = Gate.buildFamily(1, 16, (span, builder) => builder.
setSerializedId("inc" + span).
setSymbol("+1").
setTitle("Increment Gate").
setBlurb("Adds 1 to the little-endian number represented by a block of qubits.").
setActualEffectToShaderProvider(ctx => offsetShader.withArgs(
...ketArgs(ctx, span),
WglArg.float("amount", +1))).
setKnownEffectToPermutation(t => (t + 1) & ((1 << span) - 1)));

IncrementGates.DecrementFamily = Gate.buildFamily(1, 16, (span, builder) => builder.
setSerializedId("dec" + span).
setSymbol("−1").
setTitle("Decrement Gate").
setBlurb("Subtracts 1 from the little-endian number represented by a block of qubits.").
setActualEffectToShaderProvider(ctx => offsetShader.withArgs(
...ketArgs(ctx, span),
WglArg.float("amount", -1))).
setKnownEffectToPermutation(t => (t - 1) & ((1 << span) - 1)));

IncrementGates.all = [
...IncrementGates.IncrementFamily.all,
...IncrementGates.DecrementFamily.all,
];

export {IncrementGates, offsetShader}
13 changes: 2 additions & 11 deletions src/gates/Joke_NeGate.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,17 @@

import {GateBuilder} from "src/circuit/Gate.js"
import {Matrix} from "src/math/Matrix.js"
import {Point} from "src/math/Point.js"
import {GatePainting} from "src/draw/GatePainting.js"

const NeGate = new GateBuilder().
setSerializedId("NeGate").
setSymbol("-I").
setTitle("Ne-Gate").
setBlurb("Negates all amplitudes.").
setDrawer(args => {
GatePainting.paintLocationIndependentFrame(args);
let {x, y} = args.rect.center();
args.painter.print(
"-I",
x,
y,
'center',
'middle',
'black',
'16px monospace',
args.rect.w,
args.rect.h);
args.painter.strokeLine(new Point(x - 6, y), new Point(x + 6, y), 'black', 2);
}).
setKnownEffectToMatrix(Matrix.square(-1, 0, 0, -1)).
gate;
Expand Down
4 changes: 2 additions & 2 deletions src/gates/MultiplicationGates.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ MultiplicationGates.TimesAFamily = Gate.buildFamily(1, 16, (span, builder) => bu
setSymbol("×A").
setTitle("Multiplication Gate").
setBlurb("Multiplies the target by input A.\n" +
"No effect if the multiplication would be irreversible.").
"No effect if the input is even (would be irreversible).").
setRequiredContextKeys("Input Range A").
setActualEffectToShaderProvider(ctx => MULTIPLICATION_SHADER.withArgs(...ketArgs(ctx, span, ['A']))).
setKnownEffectToParametrizedPermutation((x, a) => modularMultiply(x, a, 1<<span)));
Expand All @@ -66,7 +66,7 @@ MultiplicationGates.TimesAInverseFamily = Gate.buildFamily(1, 16, (span, builder
setSymbol("×A^-1").
setTitle("Inverse Multiplication Gate").
setBlurb("Inverse-multiplies the target by input A (modulo 2^n).\n" +
"No effect if the multiplication would be irreversible.").
"No effect if the input is even (would be irreversible).").
setRequiredContextKeys("Input Range A").
setKnownEffectToParametrizedPermutation((x, a) => modularUnmultiply(x, a, 1<<span)).
setActualEffectToShaderProvider(ctx => INVERSE_MULTIPLICATION_SHADER.withArgs(...ketArgs(ctx, span, ['A']))));
Expand Down
4 changes: 2 additions & 2 deletions src/gates/MultiplyAccumulateGates.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ MultiplyAccumulateGates.MultiplySubtractInputsFamily = Gate.buildFamily(1, 16, (

MultiplyAccumulateGates.SquareAddInputFamily = Gate.buildFamily(1, 16, (span, builder) => builder.
setSerializedId("+=AA" + span).
setSymbol("+=A^2").
setSymbol("+A^2").
setTitle("Square-Add Gate [Input A]").
setBlurb("Adds the square of input A into the qubits covered by this gate.").
setRequiredContextKeys('Input Range A').
Expand All @@ -136,7 +136,7 @@ MultiplyAccumulateGates.SquareAddInputFamily = Gate.buildFamily(1, 16, (span, bu

MultiplyAccumulateGates.SquareSubtractInputFamily = Gate.buildFamily(1, 16, (span, builder) => builder.
setSerializedId("-=AA" + span).
setSymbol("-=A^2").
setSymbol("-A^2").
setTitle("Square-Subtract Gate [Input A]").
setBlurb("Subtracts the square of input A out of the qubits covered by this gate.").
setRequiredContextKeys('Input Range A').
Expand Down
38 changes: 31 additions & 7 deletions src/gates/PhaseGradientGates.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
// limitations under the License.

import {Gate} from "src/circuit/Gate.js"
import {GatePainting} from "src/draw/GatePainting.js"
import {ketArgs, ketShaderPhase} from "src/circuit/KetShaderUtil.js"
import {WglArg} from "src/webgl/WglArg.js"
import {WglConfiguredShader} from "src/webgl/WglConfiguredShader.js"

const PHASE_GRADIENT_SHADER = ketShaderPhase(
'uniform float factor;',
Expand All @@ -28,27 +28,51 @@ let PhaseGradientGates = {};

PhaseGradientGates.PhaseGradientFamily = Gate.buildFamily(1, 16, (span, builder) => builder.
setSerializedId("PhaseGradient" + span).
setSymbol("e^iπ%").
setTitle("Phase Gradient Gate").
setBlurb("Phases by an amount proportional to the target value.").
setSymbol("Grad^½").
setTitle("Half Gradient Gate").
setBlurb("Phases the target by an amount proportional its value.").
setActualEffectToShaderProvider(ctx => PHASE_GRADIENT_SHADER.withArgs(
...ketArgs(ctx, span),
WglArg.float("factor", Math.PI / (1 << span)))).
setKnownEffectToPhaser(k => k / (2 << span)));

PhaseGradientGates.PhaseDegradientFamily = Gate.buildFamily(1, 16, (span, builder) => builder.
setSerializedId("PhaseUngradient" + span).
setSymbol("e^-iπ%").
setTitle("Inverse Phase Gradient Gate").
setBlurb("Counter-phases by an amount proportional to the target value.").
setSymbol("Grad^-½").
setTitle("Inverse Half Gradient Gate").
setBlurb("Counter-phases the target by an amount proportional its value.").
setActualEffectToShaderProvider(ctx => PHASE_GRADIENT_SHADER.withArgs(
...ketArgs(ctx, span),
WglArg.float("factor", -Math.PI / (1 << span)))).
setKnownEffectToPhaser(k => -k / (2 << span)));

PhaseGradientGates.DynamicPhaseGradientFamily = Gate.buildFamily(1, 16, (span, builder) => builder.
setSerializedId("grad^t" + span).
setSymbol("Grad^t").
setTitle("Cycling Gradient Gate").
setBlurb("Phases the target by a cycling amount proportional its value.").
setActualEffectToShaderProvider(ctx => PHASE_GRADIENT_SHADER.withArgs(
...ketArgs(ctx, span),
WglArg.float("factor", ctx.time * Math.PI * 2))).
promiseEffectOnlyPhases().
setDrawer(GatePainting.makeCycleDrawer(-1, -1)));

PhaseGradientGates.DynamicPhaseDegradientFamily = Gate.buildFamily(1, 16, (span, builder) => builder.
setSerializedId("grad^-t" + span).
setSymbol("Grad^-t").
setTitle("Inverse Cycling Gradient Gate").
setBlurb("Counter-phases the target by a cycling amount proportional its value.").
setActualEffectToShaderProvider(ctx => PHASE_GRADIENT_SHADER.withArgs(
...ketArgs(ctx, span),
WglArg.float("factor", -ctx.time * Math.PI * 2))).
promiseEffectOnlyPhases().
setDrawer(GatePainting.makeCycleDrawer(1, -1)));

PhaseGradientGates.all = [
...PhaseGradientGates.PhaseGradientFamily.all,
...PhaseGradientGates.PhaseDegradientFamily.all,
...PhaseGradientGates.DynamicPhaseGradientFamily.all,
...PhaseGradientGates.DynamicPhaseDegradientFamily.all,
];

export {PhaseGradientGates, PHASE_GRADIENT_SHADER}
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ canvasDiv.addEventListener('mousedown', ev => {
let newHand = displayed.get().hand.withPos(eventPosRelativeTo(ev, canvas));
let newInspector = syncArea(displayed.get()).
withHand(newHand).
afterGrabbing(false, false). // Grab the gate.
afterGrabbing(false, false, true). // Grab the gate.
withHand(newHand). // Lose the gate.
afterTidyingUp().
withJustEnoughWires(newHand, 0);
Expand Down
4 changes: 2 additions & 2 deletions src/math/Complex.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ class Complex {

/**
* Returns a complex number with the given magnitude and phase.
* @param {!number} magnitude
* @param {!number} phase
* @param {!number} magnitude Distance from origin.
* @param {!number} phase Phase in radians.
* @returns {!Complex}
*/
static polar(magnitude, phase) {
Expand Down
17 changes: 14 additions & 3 deletions src/ui/DisplayedCircuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class DisplayedCircuit {
*/
desiredWidth(forTooltip=false) {
if (forTooltip) {
return this.gateRect(1, this.circuitDefinition.columns.length).x + CIRCUIT_OP_LEFT_SPACING;
return this.opRect(this.circuitDefinition.columns.length - 1).right() + CIRCUIT_OP_LEFT_SPACING;
}
return this._rectForSuperpositionDisplay().right() + 101;
}
Expand Down Expand Up @@ -948,13 +948,24 @@ class DisplayedCircuit {
* @param {!Hand} hand
* @param {!boolean=false} duplicate
* @param {!boolean=false} wholeColumn
* @param {!boolean=false} ignoreResizeTabs
* @returns {!{newCircuit: !DisplayedCircuit, newHand: !Hand}}
*/
tryGrab(hand, duplicate=false, wholeColumn=false) {
tryGrab(hand, duplicate=false, wholeColumn=false, ignoreResizeTabs=false) {
if (wholeColumn) {
return this._tryGrabWholeColumn(hand, duplicate) || {newCircuit: this, newHand: hand};
}
let {newCircuit, newHand} = this._tryGrabResizeTab(hand) || {newCircuit: this, newHand: hand};

let newHand = hand;
let newCircuit = this;
if (!ignoreResizeTabs) {
let resizing = this._tryGrabResizeTab(hand);
if (resizing !== undefined) {
newHand = resizing.newHand;
newCircuit = resizing.newCircuit;
}
}

return newCircuit._tryGrabGate(newHand, duplicate) || {newCircuit, newHand};
}

Expand Down
5 changes: 3 additions & 2 deletions src/ui/DisplayedInspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,16 @@ class DisplayedInspector {
/**
* @param {!boolean=false} duplicate
* @param {!boolean=false} wholeCol
* @param {!boolean=false} ignoreResizeTabs
* @returns {!DisplayedInspector}
*/
afterGrabbing(duplicate=false, wholeCol=false) {
afterGrabbing(duplicate=false, wholeCol=false, ignoreResizeTabs=false) {
let hand = this.hand;
let circuit = this.displayedCircuit;

hand = this.displayedToolboxTop.tryGrab(hand);
hand = this.displayedToolboxBottom.tryGrab(hand);
let obj = circuit.tryGrab(hand, duplicate, wholeCol);
let obj = circuit.tryGrab(hand, duplicate, wholeCol, ignoreResizeTabs);
hand = obj.newHand;
circuit = obj.newCircuit;

Expand Down
Loading

0 comments on commit 95d154b

Please sign in to comment.