Skip to content

Commit

Permalink
Implement X/Y/Z detectors and detect-control-reset gates
Browse files Browse the repository at this point in the history
  • Loading branch information
Strilanc committed Jun 8, 2018
1 parent 48c57df commit 652c188
Show file tree
Hide file tree
Showing 9 changed files with 355 additions and 46 deletions.
1 change: 0 additions & 1 deletion src/circuit/Gate.js
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,6 @@ class GateBuilder {
markAsControlExpecting(bit) {
this.gate._controlBit = bit;
this.gate.isControlWireSource = true;
this.gate._isDefinitelyUnitary = true;
this.gate.interestedInControls = false;
return this;
}
Expand Down
27 changes: 21 additions & 6 deletions src/circuit/GateColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,21 @@ class GateColumn {
return this.gates.every(e => e === undefined);
}

hasControl(inputMeasureMask) {
return this.hasCoherentControl(inputMeasureMask) || this.hasMeasuredControl(inputMeasureMask);
/**
* @param {!int} inputMeasureMask
* @param {!int} ignoreMask
* @returns {!boolean}
*/
hasControl(inputMeasureMask=0, ignoreMask=0) {
return this.hasCoherentControl(inputMeasureMask | ignoreMask) ||
this.hasMeasuredControl(inputMeasureMask & ~ignoreMask);
}

hasCoherentControl(inputMeasureMask) {
/**
* @param {!int} inputMeasureMask
* @returns {!boolean}
*/
hasCoherentControl(inputMeasureMask=0) {
for (let i = 0; i < this.gates.length; i++) {
if ((inputMeasureMask & (1 << i)) === 0 &&
this.gates[i] !== undefined &&
Expand All @@ -84,7 +94,11 @@ class GateColumn {
return false;
}

hasMeasuredControl(inputMeasureMask) {
/**
* @param {!int} inputMeasureMask
* @returns {!boolean}
*/
hasMeasuredControl(inputMeasureMask=0) {
for (let i = 0; i < this.gates.length; i++) {
if ((inputMeasureMask & (1 << i)) !== 0 &&
this.gates[i] !== undefined &&
Expand Down Expand Up @@ -380,8 +394,9 @@ class GateColumn {
// without getting the wrong answer, at least).
let hasSingleResult = gate === Gates.PostSelectionGates.PostSelectOn
|| gate === Gates.PostSelectionGates.PostSelectOff
|| gate === Gates.Detector;
if (!this.hasControl() && hasSingleResult) {
|| gate === Gates.Detectors.ZDetector
|| gate === Gates.Detectors.ZDetectControlClear;
if (!this.hasControl(0, 1 << row) && hasSingleResult) {
state.measureMask &= ~(1<<row);
return;
}
Expand Down
16 changes: 12 additions & 4 deletions src/gates/AllGates.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {ProbabilityDisplayFamily} from "src/gates/ProbabilityDisplay.js"
import {QuarterTurnGates} from "src/gates/QuarterTurnGates.js"
import {ReverseBitsGateFamily} from "src/gates/ReverseBitsGate.js"
import {SampleDisplayFamily} from "src/gates/SampleDisplay.js"
import {Detector} from "src/gates/Detector.js"
import {Detectors} from "src/gates/Detector.js"
import {SpacerGate} from "src/gates/SpacerGate.js"
import {SwapGateHalf} from "src/gates/SwapGateHalf.js"
import {UniversalNotGate} from "src/gates/Impossible_UniversalNotGate.js"
Expand Down Expand Up @@ -109,7 +109,7 @@ Gates.PostSelectionGates = PostSelectionGates;
Gates.Powering = PoweringGates;
Gates.QuarterTurns = QuarterTurnGates;
Gates.ReverseBitsGateFamily = ReverseBitsGateFamily;
Gates.Detector = Detector;
Gates.Detectors = Detectors;
Gates.SpacerGate = SpacerGate;
Gates.UniversalNot = UniversalNotGate;
Gates.XorGates = XorGates;
Expand All @@ -120,7 +120,6 @@ Gates.KnownToSerializer = [
...Controls.all,
...InputGates.all,
MeasurementGate,
Detector,
SwapGateHalf,
SpacerGate,
UniversalNotGate,
Expand All @@ -139,6 +138,7 @@ Gates.KnownToSerializer = [
...ComparisonGates.all,
...CountingGates.all,
...CycleBitsGates.all,
...Detectors.all,
...ExponentiatingGates.all,
...FourierTransformGates.all,
...HalfTurnGates.all,
Expand Down Expand Up @@ -244,7 +244,15 @@ Gates.TopToolboxGroups = [
gates: [
ZeroGate, MysteryGateMaker(),
NeGate, undefined,
SpacerGate, undefined
SpacerGate, undefined,
]
},
{
hint: 'Sample',
gates: [
Detectors.ZDetector, Detectors.ZDetectControlClear,
Detectors.YDetector, Detectors.YDetectControlClear,
Detectors.XDetector, Detectors.XDetectControlClear,
]
}
];
Expand Down
6 changes: 6 additions & 0 deletions src/gates/Controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Controls.Control = new GateBuilder().
setBlurb("Conditions on a qubit being ON.\nGates in the same column only apply to states meeting the condition.").
promiseHasNoNetEffectOnStateVector().
markAsControlExpecting(true).
promiseEffectIsUnitary().
setDrawer(args => {
if (args.isInToolbox || args.isHighlighted) {
GatePainting.paintBackground(args);
Expand All @@ -41,6 +42,7 @@ Controls.AntiControl = new GateBuilder().
setBlurb("Conditions on a qubit being OFF.\nGates in the same column only apply to states meeting the condition.").
promiseHasNoNetEffectOnStateVector().
markAsControlExpecting(false).
promiseEffectIsUnitary().
setDrawer(args => {
if (args.isInToolbox || args.isHighlighted) {
GatePainting.paintBackground(args);
Expand All @@ -64,6 +66,7 @@ Controls.XAntiControl = new GateBuilder().
HalfTurnGates.H.customOperation).
setActualEffectToUpdateFunc(() => {}).
promiseEffectIsStable().
promiseEffectIsUnitary().
setDrawer(args => {
if (args.isInToolbox || args.isHighlighted) {
GatePainting.paintBackground(args);
Expand All @@ -88,6 +91,7 @@ Controls.XControl = new GateBuilder().
HalfTurnGates.H.customOperation).
setActualEffectToUpdateFunc(() => {}).
promiseEffectIsStable().
promiseEffectIsUnitary().
setDrawer(args => {
if (args.isInToolbox || args.isHighlighted) {
GatePainting.paintBackground(args);
Expand All @@ -113,6 +117,7 @@ Controls.YAntiControl = new GateBuilder().
ctx => GateShaders.applyMatrixOperation(ctx, QuarterTurnGates.SqrtXBackward._knownMatrix)).
setActualEffectToUpdateFunc(() => {}).
promiseEffectIsStable().
promiseEffectIsUnitary().
setDrawer(args => {
if (args.isInToolbox || args.isHighlighted) {
GatePainting.paintBackground(args);
Expand Down Expand Up @@ -141,6 +146,7 @@ Controls.YControl = new GateBuilder().
ctx => GateShaders.applyMatrixOperation(ctx, QuarterTurnGates.SqrtXBackward._knownMatrix)).
setActualEffectToUpdateFunc(() => {}).
promiseEffectIsStable().
promiseEffectIsUnitary().
setDrawer(ctx => {
if (ctx.isInToolbox || ctx.isHighlighted) {
GatePainting.paintBackground(ctx);
Expand Down
Loading

0 comments on commit 652c188

Please sign in to comment.