Skip to content

Commit

Permalink
Add imaginary gate
Browse files Browse the repository at this point in the history
  • Loading branch information
Strilanc committed Jun 8, 2018
1 parent 652c188 commit 5c6167b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
21 changes: 12 additions & 9 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 {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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -126,6 +128,7 @@ Gates.KnownToSerializer = [
ErrorInjectionGate,
ZeroGate,
NeGate,
ImaginaryGate,

...AmplitudeDisplayFamily.all,
...ProbabilityDisplayFamily.all,
Expand Down Expand Up @@ -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<!{hint: !string, gates: !Array<undefined|!Gate>}>} */
Expand Down
26 changes: 26 additions & 0 deletions src/gates/Joke_ImaginaryGate.js
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion src/gates/Joke_ZeroGate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)).
Expand Down
2 changes: 1 addition & 1 deletion test/circuit/Serializer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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^⅟₃₂",
Expand Down

0 comments on commit 5c6167b

Please sign in to comment.