From 5c6167b013626905d1c5383d4dcb79fb60289d2a Mon Sep 17 00:00:00 2001 From: Craig Gidney Date: Fri, 8 Jun 2018 01:23:10 -0300 Subject: [PATCH] Add imaginary gate --- src/gates/AllGates.js | 21 ++++++++++++--------- src/gates/Joke_ImaginaryGate.js | 26 ++++++++++++++++++++++++++ src/gates/Joke_ZeroGate.js | 2 +- test/circuit/Serializer.test.js | 2 +- 4 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 src/gates/Joke_ImaginaryGate.js diff --git a/src/gates/AllGates.js b/src/gates/AllGates.js index 9e5c04be..73a9f46c 100644 --- a/src/gates/AllGates.js +++ b/src/gates/AllGates.js @@ -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 {ImaginaryGate} from "src/gates/Joke_ImaginaryGate.js" import {IncrementGates} from "src/gates/IncrementGates.js" import {InputGates} from "src/gates/InputGates.js" import {InterleaveBitsGates} from "src/gates/InterleaveBitsGates.js" @@ -89,6 +90,7 @@ Gates.ErrorInjection = ErrorInjectionGate; Gates.Exponentiating = ExponentiatingGates; Gates.FourierTransformGates = FourierTransformGates; Gates.HalfTurns = HalfTurnGates; +Gates.ImaginaryGate = ImaginaryGate; Gates.IncrementGates = IncrementGates; Gates.InputGates = InputGates; Gates.InterleaveBitsGates = InterleaveBitsGates; @@ -126,6 +128,7 @@ Gates.KnownToSerializer = [ ErrorInjectionGate, ZeroGate, NeGate, + ImaginaryGate, ...AmplitudeDisplayFamily.all, ...ProbabilityDisplayFamily.all, @@ -240,21 +243,21 @@ Gates.TopToolboxGroups = [ ] }, { - hint: 'Silly', + hint: 'Sampling', gates: [ - ZeroGate, MysteryGateMaker(), - NeGate, undefined, - SpacerGate, undefined, + Detectors.ZDetector, Detectors.ZDetectControlClear, + Detectors.YDetector, Detectors.YDetectControlClear, + Detectors.XDetector, Detectors.XDetectControlClear, ] }, { - hint: 'Sample', + hint: 'Silly', gates: [ - Detectors.ZDetector, Detectors.ZDetectControlClear, - Detectors.YDetector, Detectors.YDetectControlClear, - Detectors.XDetector, Detectors.XDetectControlClear, + ZeroGate, MysteryGateMaker(), + NeGate, ImaginaryGate, + SpacerGate, undefined, ] - } + }, ]; /** @type {!Array}>} */ diff --git a/src/gates/Joke_ImaginaryGate.js b/src/gates/Joke_ImaginaryGate.js new file mode 100644 index 00000000..e80db31d --- /dev/null +++ b/src/gates/Joke_ImaginaryGate.js @@ -0,0 +1,26 @@ +// Copyright 2017 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import {GateBuilder} from "src/circuit/Gate.js" +import {Matrix} from "src/math/Matrix.js" +import {Complex} from "src/math/Complex.js" + +const ImaginaryGate = new GateBuilder(). + setSerializedIdAndSymbol("i"). + setTitle("Imaginary Gate"). + setBlurb("Phases everything by i."). + setKnownEffectToMatrix(Matrix.square(Complex.I, 0, 0, Complex.I)). + gate; + +export {ImaginaryGate} diff --git a/src/gates/Joke_ZeroGate.js b/src/gates/Joke_ZeroGate.js index 5b099897..e5b47bb0 100644 --- a/src/gates/Joke_ZeroGate.js +++ b/src/gates/Joke_ZeroGate.js @@ -19,7 +19,7 @@ import {Matrix} from "src/math/Matrix.js" /** @type {!Gate} */ const ZeroGate = new GateBuilder(). setSerializedIdAndSymbol("0"). - setTitle("Zero Gate"). + setTitle("Nothing Gate"). setBlurb("Destroys the universe."). setDrawer(GatePainting.makeLocationIndependentGateDrawer('#666')). setKnownEffectToMatrix(Matrix.square(0, 0, 0, 0)). diff --git a/test/circuit/Serializer.test.js b/test/circuit/Serializer.test.js index 8a9786fc..79577e9a 100644 --- a/test/circuit/Serializer.test.js +++ b/test/circuit/Serializer.test.js @@ -191,7 +191,7 @@ const IDS_THAT_SHOULD_BE_KNOWN = [ "revinputA1", "revinputA2", "revinputA3", "revinputA4", "revinputA5", "revinputA6", "revinputA7", "revinputA8", "revinputA9", "revinputA10", "revinputA11", "revinputA12", "revinputA13", "revinputA14", "revinputA15", "revinputA16", "revinputB1", "revinputB2", "revinputB3", "revinputB4", "revinputB5", "revinputB6", "revinputB7", "revinputB8", "revinputB9", "revinputB10", "revinputB11", "revinputB12", "revinputB13", "revinputB14", "revinputB15", "revinputB16", "__error__", - "0", "NeGate", + "0", "NeGate", "i", "H", "X", "Y", "Z", "X^½", "X^⅓", "X^¼", "X^⅛", "X^⅟₁₆", "X^⅟₃₂",