qsharp-lang 1.14.5-dev → 1.15.1-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.d.ts +1 -1
- package/dist/compiler/compiler.d.ts +1 -1
- package/dist/compiler/compiler.js +6 -1
- package/dist/debug-service/debug-service.d.ts +1 -1
- package/dist/debug-service/debug-service.js +6 -1
- package/dist/katas-content.generated.js +1 -1
- package/dist/katas-content.generated.md.js +1 -1
- package/dist/samples.generated.js +1 -1
- package/dist/shared/circuit.d.ts +86 -30
- package/dist/shared/circuit.js +4 -0
- package/dist/shared/legacyCircuitUpdate.d.ts +9 -0
- package/dist/shared/legacyCircuitUpdate.js +312 -0
- package/dist/shared/register.d.ts +3 -5
- package/dist/utils.d.ts +9 -0
- package/dist/utils.js +41 -0
- package/docs/Microsoft.Quantum.Core/Length.md +1 -1
- package/docs/Microsoft.Quantum.Core/Repeated.md +1 -1
- package/docs/Microsoft.Quantum.Core/index.md +1 -1
- package/docs/Std.Arithmetic/AddLE.md +1 -1
- package/docs/Std.Arithmetic/ApplyIfEqualL.md +1 -1
- package/docs/Std.Arithmetic/ApplyIfEqualLE.md +1 -1
- package/docs/Std.Arithmetic/ApplyIfGreaterL.md +1 -1
- package/docs/Std.Arithmetic/ApplyIfGreaterLE.md +1 -1
- package/docs/Std.Arithmetic/ApplyIfGreaterOrEqualL.md +1 -1
- package/docs/Std.Arithmetic/ApplyIfGreaterOrEqualLE.md +1 -1
- package/docs/Std.Arithmetic/ApplyIfLessL.md +1 -1
- package/docs/Std.Arithmetic/ApplyIfLessLE.md +1 -1
- package/docs/Std.Arithmetic/ApplyIfLessOrEqualL.md +1 -1
- package/docs/Std.Arithmetic/ApplyIfLessOrEqualLE.md +1 -1
- package/docs/Std.Arithmetic/FourierTDIncByLE.md +1 -1
- package/docs/Std.Arithmetic/IncByI.md +1 -1
- package/docs/Std.Arithmetic/IncByIUsingIncByLE.md +1 -1
- package/docs/Std.Arithmetic/IncByL.md +1 -1
- package/docs/Std.Arithmetic/IncByLE.md +1 -1
- package/docs/Std.Arithmetic/IncByLEUsingAddLE.md +1 -1
- package/docs/Std.Arithmetic/IncByLUsingIncByLE.md +1 -1
- package/docs/Std.Arithmetic/LookAheadDKRSAddLE.md +1 -1
- package/docs/Std.Arithmetic/MAJ.md +1 -1
- package/docs/Std.Arithmetic/ReflectAboutInteger.md +1 -1
- package/docs/Std.Arithmetic/RippleCarryCGAddLE.md +1 -1
- package/docs/Std.Arithmetic/RippleCarryCGIncByLE.md +1 -1
- package/docs/Std.Arithmetic/RippleCarryTTKIncByLE.md +1 -1
- package/docs/Std.Arithmetic/index.md +1 -1
- package/docs/Std.Arrays/All.md +1 -1
- package/docs/Std.Arrays/Any.md +1 -1
- package/docs/Std.Arrays/Chunks.md +1 -1
- package/docs/Std.Arrays/CircularlyShifted.md +1 -1
- package/docs/Std.Arrays/ColumnAt.md +1 -1
- package/docs/Std.Arrays/Count.md +1 -1
- package/docs/Std.Arrays/Diagonal.md +1 -1
- package/docs/Std.Arrays/DrawMany.md +1 -1
- package/docs/Std.Arrays/Enumerated.md +1 -1
- package/docs/Std.Arrays/Excluding.md +1 -1
- package/docs/Std.Arrays/Filtered.md +1 -1
- package/docs/Std.Arrays/FlatMapped.md +1 -1
- package/docs/Std.Arrays/Flattened.md +1 -1
- package/docs/Std.Arrays/Fold.md +1 -1
- package/docs/Std.Arrays/ForEach.md +1 -1
- package/docs/Std.Arrays/Head.md +1 -1
- package/docs/Std.Arrays/HeadAndRest.md +1 -1
- package/docs/Std.Arrays/IndexOf.md +1 -1
- package/docs/Std.Arrays/IndexRange.md +1 -1
- package/docs/Std.Arrays/Interleaved.md +1 -1
- package/docs/Std.Arrays/IsEmpty.md +1 -1
- package/docs/Std.Arrays/IsRectangularArray.md +1 -1
- package/docs/Std.Arrays/IsSorted.md +1 -1
- package/docs/Std.Arrays/IsSquareArray.md +1 -1
- package/docs/Std.Arrays/Mapped.md +1 -1
- package/docs/Std.Arrays/MappedByIndex.md +1 -1
- package/docs/Std.Arrays/MappedOverRange.md +1 -1
- package/docs/Std.Arrays/Most.md +1 -1
- package/docs/Std.Arrays/MostAndTail.md +1 -1
- package/docs/Std.Arrays/Padded.md +1 -1
- package/docs/Std.Arrays/Partitioned.md +1 -1
- package/docs/Std.Arrays/Rest.md +1 -1
- package/docs/Std.Arrays/Reversed.md +1 -1
- package/docs/Std.Arrays/SequenceI.md +1 -1
- package/docs/Std.Arrays/SequenceL.md +1 -1
- package/docs/Std.Arrays/Sorted.md +1 -1
- package/docs/Std.Arrays/Subarray.md +1 -1
- package/docs/Std.Arrays/Swapped.md +1 -1
- package/docs/Std.Arrays/Tail.md +1 -1
- package/docs/Std.Arrays/Transposed.md +1 -1
- package/docs/Std.Arrays/Unzipped.md +1 -1
- package/docs/Std.Arrays/Where.md +1 -1
- package/docs/Std.Arrays/Windows.md +1 -1
- package/docs/Std.Arrays/Zipped.md +1 -1
- package/docs/Std.Arrays/index.md +1 -1
- package/docs/Std.Canon/ApplyCNOTChain.md +1 -1
- package/docs/Std.Canon/ApplyControlledOnBitString.md +1 -1
- package/docs/Std.Canon/ApplyControlledOnInt.md +1 -1
- package/docs/Std.Canon/ApplyP.md +1 -1
- package/docs/Std.Canon/ApplyPauli.md +1 -1
- package/docs/Std.Canon/ApplyPauliFromBitString.md +1 -1
- package/docs/Std.Canon/ApplyPauliFromInt.md +1 -1
- package/docs/Std.Canon/ApplyQFT.md +1 -1
- package/docs/Std.Canon/ApplyToEach.md +1 -1
- package/docs/Std.Canon/ApplyToEachA.md +1 -1
- package/docs/Std.Canon/ApplyToEachC.md +1 -1
- package/docs/Std.Canon/ApplyToEachCA.md +1 -1
- package/docs/Std.Canon/ApplyXorInPlace.md +1 -1
- package/docs/Std.Canon/ApplyXorInPlaceL.md +1 -1
- package/docs/Std.Canon/CX.md +1 -1
- package/docs/Std.Canon/CY.md +1 -1
- package/docs/Std.Canon/CZ.md +1 -1
- package/docs/Std.Canon/Fst.md +1 -1
- package/docs/Std.Canon/Relabel.md +1 -1
- package/docs/Std.Canon/Snd.md +1 -1
- package/docs/Std.Canon/SwapReverseRegister.md +1 -1
- package/docs/Std.Canon/index.md +1 -1
- package/docs/Std.Convert/BigIntAsBoolArray.md +1 -1
- package/docs/Std.Convert/BoolArrayAsBigInt.md +1 -1
- package/docs/Std.Convert/BoolArrayAsInt.md +1 -1
- package/docs/Std.Convert/BoolArrayAsResultArray.md +1 -1
- package/docs/Std.Convert/BoolAsResult.md +1 -1
- package/docs/Std.Convert/ComplexAsComplexPolar.md +1 -1
- package/docs/Std.Convert/ComplexPolarAsComplex.md +1 -1
- package/docs/Std.Convert/DoubleAsStringWithPrecision.md +1 -1
- package/docs/Std.Convert/IntAsBigInt.md +1 -1
- package/docs/Std.Convert/IntAsBoolArray.md +1 -1
- package/docs/Std.Convert/IntAsDouble.md +1 -1
- package/docs/Std.Convert/ResultArrayAsBoolArray.md +1 -1
- package/docs/Std.Convert/ResultArrayAsInt.md +1 -1
- package/docs/Std.Convert/ResultAsBool.md +1 -1
- package/docs/Std.Convert/index.md +1 -1
- package/docs/Std.Core/Length.md +1 -1
- package/docs/Std.Core/Repeated.md +1 -1
- package/docs/Std.Core/index.md +1 -1
- package/docs/Std.Diagnostics/ApplyIdleNoise.md +1 -1
- package/docs/Std.Diagnostics/BitFlipNoise.md +1 -1
- package/docs/Std.Diagnostics/CheckAllZero.md +1 -1
- package/docs/Std.Diagnostics/CheckOperationsAreEqual.md +1 -1
- package/docs/Std.Diagnostics/CheckZero.md +1 -1
- package/docs/Std.Diagnostics/ConfigurePauliNoise.md +1 -1
- package/docs/Std.Diagnostics/DepolarizingNoise.md +1 -1
- package/docs/Std.Diagnostics/DumpMachine.md +1 -1
- package/docs/Std.Diagnostics/DumpOperation.md +1 -1
- package/docs/Std.Diagnostics/DumpRegister.md +1 -1
- package/docs/Std.Diagnostics/Fact.md +1 -1
- package/docs/Std.Diagnostics/NoNoise.md +1 -1
- package/docs/Std.Diagnostics/PhaseFlipNoise.md +1 -1
- package/docs/Std.Diagnostics/StartCountingFunction.md +1 -1
- package/docs/Std.Diagnostics/StartCountingOperation.md +1 -1
- package/docs/Std.Diagnostics/StartCountingQubits.md +1 -1
- package/docs/Std.Diagnostics/StopCountingFunction.md +1 -1
- package/docs/Std.Diagnostics/StopCountingOperation.md +1 -1
- package/docs/Std.Diagnostics/StopCountingQubits.md +1 -1
- package/docs/Std.Diagnostics/index.md +1 -1
- package/docs/Std.Intrinsic/AND.md +1 -1
- package/docs/Std.Intrinsic/ApplyUnitary.md +1 -1
- package/docs/Std.Intrinsic/CCNOT.md +1 -1
- package/docs/Std.Intrinsic/CNOT.md +1 -1
- package/docs/Std.Intrinsic/Exp.md +1 -1
- package/docs/Std.Intrinsic/H.md +1 -1
- package/docs/Std.Intrinsic/I.md +1 -1
- package/docs/Std.Intrinsic/M.md +1 -1
- package/docs/Std.Intrinsic/Measure.md +1 -1
- package/docs/Std.Intrinsic/Message.md +1 -1
- package/docs/Std.Intrinsic/R.md +1 -1
- package/docs/Std.Intrinsic/R1.md +1 -1
- package/docs/Std.Intrinsic/R1Frac.md +1 -1
- package/docs/Std.Intrinsic/RFrac.md +1 -1
- package/docs/Std.Intrinsic/Reset.md +1 -1
- package/docs/Std.Intrinsic/ResetAll.md +1 -1
- package/docs/Std.Intrinsic/Rx.md +1 -1
- package/docs/Std.Intrinsic/Rxx.md +1 -1
- package/docs/Std.Intrinsic/Ry.md +1 -1
- package/docs/Std.Intrinsic/Ryy.md +1 -1
- package/docs/Std.Intrinsic/Rz.md +1 -1
- package/docs/Std.Intrinsic/Rzz.md +1 -1
- package/docs/Std.Intrinsic/S.md +1 -1
- package/docs/Std.Intrinsic/SWAP.md +1 -1
- package/docs/Std.Intrinsic/T.md +1 -1
- package/docs/Std.Intrinsic/X.md +1 -1
- package/docs/Std.Intrinsic/Y.md +1 -1
- package/docs/Std.Intrinsic/Z.md +1 -1
- package/docs/Std.Intrinsic/index.md +1 -1
- package/docs/Std.Logical/Xor.md +1 -1
- package/docs/Std.Logical/index.md +1 -1
- package/docs/Std.Math/AbsComplex.md +1 -1
- package/docs/Std.Math/AbsComplexPolar.md +1 -1
- package/docs/Std.Math/AbsD.md +1 -1
- package/docs/Std.Math/AbsI.md +1 -1
- package/docs/Std.Math/AbsL.md +1 -1
- package/docs/Std.Math/AbsSquaredComplex.md +1 -1
- package/docs/Std.Math/AbsSquaredComplexPolar.md +1 -1
- package/docs/Std.Math/ApproximateFactorial.md +1 -1
- package/docs/Std.Math/ArcCos.md +1 -1
- package/docs/Std.Math/ArcCosh.md +1 -1
- package/docs/Std.Math/ArcSin.md +1 -1
- package/docs/Std.Math/ArcSinh.md +1 -1
- package/docs/Std.Math/ArcTan.md +1 -1
- package/docs/Std.Math/ArcTan2.md +1 -1
- package/docs/Std.Math/ArcTanh.md +1 -1
- package/docs/Std.Math/ArgComplex.md +1 -1
- package/docs/Std.Math/ArgComplexPolar.md +1 -1
- package/docs/Std.Math/Binom.md +1 -1
- package/docs/Std.Math/BitSizeI.md +1 -1
- package/docs/Std.Math/BitSizeL.md +1 -1
- package/docs/Std.Math/Ceiling.md +1 -1
- package/docs/Std.Math/Complex.md +1 -1
- package/docs/Std.Math/ComplexPolar.md +1 -1
- package/docs/Std.Math/ContinuedFractionConvergentI.md +1 -1
- package/docs/Std.Math/ContinuedFractionConvergentL.md +1 -1
- package/docs/Std.Math/Cos.md +1 -1
- package/docs/Std.Math/Cosh.md +1 -1
- package/docs/Std.Math/DivRemI.md +1 -1
- package/docs/Std.Math/DivRemL.md +1 -1
- package/docs/Std.Math/DividedByC.md +1 -1
- package/docs/Std.Math/DividedByCP.md +1 -1
- package/docs/Std.Math/E.md +1 -1
- package/docs/Std.Math/ExpModI.md +1 -1
- package/docs/Std.Math/ExpModL.md +1 -1
- package/docs/Std.Math/ExtendedGreatestCommonDivisorI.md +1 -1
- package/docs/Std.Math/ExtendedGreatestCommonDivisorL.md +1 -1
- package/docs/Std.Math/FactorialI.md +1 -1
- package/docs/Std.Math/FactorialL.md +1 -1
- package/docs/Std.Math/Floor.md +1 -1
- package/docs/Std.Math/GreatestCommonDivisorI.md +1 -1
- package/docs/Std.Math/GreatestCommonDivisorL.md +1 -1
- package/docs/Std.Math/HammingWeightI.md +1 -1
- package/docs/Std.Math/InverseModI.md +1 -1
- package/docs/Std.Math/InverseModL.md +1 -1
- package/docs/Std.Math/IsCoprimeI.md +1 -1
- package/docs/Std.Math/IsCoprimeL.md +1 -1
- package/docs/Std.Math/IsInfinite.md +1 -1
- package/docs/Std.Math/IsNaN.md +1 -1
- package/docs/Std.Math/LargestFixedPoint.md +1 -1
- package/docs/Std.Math/Lg.md +1 -1
- package/docs/Std.Math/Log.md +1 -1
- package/docs/Std.Math/Log10.md +1 -1
- package/docs/Std.Math/LogFactorialD.md +1 -1
- package/docs/Std.Math/LogGammaD.md +1 -1
- package/docs/Std.Math/LogOf2.md +1 -1
- package/docs/Std.Math/Max.md +1 -1
- package/docs/Std.Math/MaxD.md +1 -1
- package/docs/Std.Math/MaxI.md +1 -1
- package/docs/Std.Math/MaxL.md +1 -1
- package/docs/Std.Math/Min.md +1 -1
- package/docs/Std.Math/MinD.md +1 -1
- package/docs/Std.Math/MinI.md +1 -1
- package/docs/Std.Math/MinL.md +1 -1
- package/docs/Std.Math/MinusC.md +1 -1
- package/docs/Std.Math/MinusCP.md +1 -1
- package/docs/Std.Math/ModulusI.md +1 -1
- package/docs/Std.Math/ModulusL.md +1 -1
- package/docs/Std.Math/NegationC.md +1 -1
- package/docs/Std.Math/NegationCP.md +1 -1
- package/docs/Std.Math/PI.md +1 -1
- package/docs/Std.Math/PNorm.md +1 -1
- package/docs/Std.Math/PNormalized.md +1 -1
- package/docs/Std.Math/PlusC.md +1 -1
- package/docs/Std.Math/PlusCP.md +1 -1
- package/docs/Std.Math/PowC.md +1 -1
- package/docs/Std.Math/PowCP.md +1 -1
- package/docs/Std.Math/RealMod.md +1 -1
- package/docs/Std.Math/Round.md +1 -1
- package/docs/Std.Math/SignD.md +1 -1
- package/docs/Std.Math/SignI.md +1 -1
- package/docs/Std.Math/SignL.md +1 -1
- package/docs/Std.Math/Sin.md +1 -1
- package/docs/Std.Math/Sinh.md +1 -1
- package/docs/Std.Math/SmallestFixedPoint.md +1 -1
- package/docs/Std.Math/Sqrt.md +1 -1
- package/docs/Std.Math/SquaredNorm.md +1 -1
- package/docs/Std.Math/Tan.md +1 -1
- package/docs/Std.Math/Tanh.md +1 -1
- package/docs/Std.Math/TimesC.md +1 -1
- package/docs/Std.Math/TimesCP.md +1 -1
- package/docs/Std.Math/TrailingZeroCountI.md +1 -1
- package/docs/Std.Math/TrailingZeroCountL.md +1 -1
- package/docs/Std.Math/Truncate.md +1 -1
- package/docs/Std.Math/index.md +1 -1
- package/docs/Std.Measurement/MResetEachZ.md +1 -1
- package/docs/Std.Measurement/MResetX.md +1 -1
- package/docs/Std.Measurement/MResetY.md +1 -1
- package/docs/Std.Measurement/MResetZ.md +1 -1
- package/docs/Std.Measurement/MeasureAllZ.md +1 -1
- package/docs/Std.Measurement/MeasureEachZ.md +1 -1
- package/docs/Std.Measurement/MeasureInteger.md +1 -1
- package/docs/Std.Measurement/index.md +1 -1
- package/docs/Std.Random/DrawRandomBool.md +1 -1
- package/docs/Std.Random/DrawRandomDouble.md +1 -1
- package/docs/Std.Random/DrawRandomInt.md +1 -1
- package/docs/Std.Random/index.md +1 -1
- package/docs/Std.Range/IsRangeEmpty.md +1 -1
- package/docs/Std.Range/RangeEnd.md +1 -1
- package/docs/Std.Range/RangeReverse.md +1 -1
- package/docs/Std.Range/RangeStart.md +1 -1
- package/docs/Std.Range/RangeStep.md +1 -1
- package/docs/Std.Range/index.md +1 -1
- package/docs/Std.ResourceEstimation/AccountForEstimates.md +1 -1
- package/docs/Std.ResourceEstimation/AuxQubitCount.md +1 -1
- package/docs/Std.ResourceEstimation/BeginEstimateCaching.md +1 -1
- package/docs/Std.ResourceEstimation/BeginRepeatEstimates.md +1 -1
- package/docs/Std.ResourceEstimation/CczCount.md +1 -1
- package/docs/Std.ResourceEstimation/EndEstimateCaching.md +1 -1
- package/docs/Std.ResourceEstimation/EndRepeatEstimates.md +1 -1
- package/docs/Std.ResourceEstimation/MeasurementCount.md +1 -1
- package/docs/Std.ResourceEstimation/PSSPCLayout.md +1 -1
- package/docs/Std.ResourceEstimation/RepeatEstimates.md +1 -1
- package/docs/Std.ResourceEstimation/RotationCount.md +1 -1
- package/docs/Std.ResourceEstimation/RotationDepth.md +1 -1
- package/docs/Std.ResourceEstimation/SingleVariant.md +1 -1
- package/docs/Std.ResourceEstimation/TCount.md +1 -1
- package/docs/Std.ResourceEstimation/index.md +1 -1
- package/docs/Std.StatePreparation/ApproximatelyPreparePureStateCP.md +1 -1
- package/docs/Std.StatePreparation/PreparePureStateD.md +1 -1
- package/docs/Std.StatePreparation/PrepareUniformSuperposition.md +1 -1
- package/docs/Std.StatePreparation/index.md +1 -1
- package/docs/Std.TableLookup/Select.md +1 -1
- package/docs/Std.TableLookup/index.md +1 -1
- package/docs/index.md +1 -1
- package/lib/node/qsc_wasm.cjs +2 -2
- package/lib/node/qsc_wasm_bg.wasm +0 -0
- package/lib/web/qsc_wasm.js +2 -2
- package/lib/web/qsc_wasm_bg.wasm +0 -0
- package/package.json +1 -1
- package/ux/circuit-vis/circuit.ts +11 -0
- package/ux/circuit-vis/circuitManipulation.ts +549 -0
- package/ux/circuit-vis/constants.ts +7 -0
- package/ux/circuit-vis/contextMenu.ts +376 -0
- package/ux/circuit-vis/draggable.ts +352 -0
- package/ux/circuit-vis/events.ts +818 -0
- package/ux/circuit-vis/formatters/gateFormatter.ts +56 -23
- package/ux/circuit-vis/formatters/inputFormatter.ts +38 -7
- package/ux/circuit-vis/formatters/registerFormatter.ts +12 -30
- package/ux/circuit-vis/index.ts +16 -11
- package/ux/circuit-vis/metadata.ts +3 -1
- package/ux/circuit-vis/panel.ts +333 -0
- package/ux/circuit-vis/process.ts +136 -232
- package/ux/circuit-vis/sqore.ts +231 -116
- package/ux/circuit-vis/utils.ts +269 -1
- package/ux/circuit.tsx +71 -37
- package/ux/data.ts +4 -2
- package/ux/index.ts +1 -1
- package/ux/qsharp-circuit.css +260 -4
- package/ux/circuit-vis/styles.ts +0 -236
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
|
|
4
|
+
import { ComponentGrid, Operation, Unitary } from "./circuit";
|
|
5
|
+
import { CircuitEvents } from "./events";
|
|
6
|
+
import { Register } from "./register";
|
|
7
|
+
import {
|
|
8
|
+
findOperation,
|
|
9
|
+
findParentArray,
|
|
10
|
+
findParentOperation,
|
|
11
|
+
getChildTargets,
|
|
12
|
+
locationStringToIndexes,
|
|
13
|
+
} from "./utils";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Move an operation in the circuit.
|
|
17
|
+
*
|
|
18
|
+
* @param circuitEvents The CircuitEvents instance to handle circuit-related events.
|
|
19
|
+
* @param sourceLocation The location string of the source operation.
|
|
20
|
+
* @param targetLocation The location string of the target position.
|
|
21
|
+
* @param sourceWire The wire index of the source operation.
|
|
22
|
+
* @param targetWire The wire index to move the operation to.
|
|
23
|
+
* @param movingControl Whether the operation is being moved as a control.
|
|
24
|
+
* @param insertNewColumn Whether to insert a new column when adding the operation.
|
|
25
|
+
* @returns The moved operation or null if the move was unsuccessful.
|
|
26
|
+
*/
|
|
27
|
+
const moveOperation = (
|
|
28
|
+
circuitEvents: CircuitEvents,
|
|
29
|
+
sourceLocation: string,
|
|
30
|
+
targetLocation: string,
|
|
31
|
+
sourceWire: number,
|
|
32
|
+
targetWire: number,
|
|
33
|
+
movingControl: boolean,
|
|
34
|
+
insertNewColumn: boolean = false,
|
|
35
|
+
): Operation | null => {
|
|
36
|
+
const originalOperation = findOperation(
|
|
37
|
+
circuitEvents.componentGrid,
|
|
38
|
+
sourceLocation,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
if (originalOperation == null) return null;
|
|
42
|
+
|
|
43
|
+
// Create a deep copy of the source operation
|
|
44
|
+
const newSourceOperation: Operation = JSON.parse(
|
|
45
|
+
JSON.stringify(originalOperation),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
// Update operation's targets and controls
|
|
49
|
+
_moveY(
|
|
50
|
+
circuitEvents,
|
|
51
|
+
newSourceOperation,
|
|
52
|
+
sourceLocation,
|
|
53
|
+
sourceWire,
|
|
54
|
+
targetWire,
|
|
55
|
+
movingControl,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
// Move horizontally
|
|
59
|
+
_moveX(
|
|
60
|
+
circuitEvents,
|
|
61
|
+
newSourceOperation,
|
|
62
|
+
originalOperation,
|
|
63
|
+
targetLocation,
|
|
64
|
+
insertNewColumn,
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const sourceOperationParent = findParentArray(
|
|
68
|
+
circuitEvents.componentGrid,
|
|
69
|
+
sourceLocation,
|
|
70
|
+
);
|
|
71
|
+
if (sourceOperationParent == null) return null;
|
|
72
|
+
_removeOp(circuitEvents, originalOperation, sourceOperationParent);
|
|
73
|
+
|
|
74
|
+
return newSourceOperation;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Move an operation horizontally.
|
|
79
|
+
*
|
|
80
|
+
* @param circuitEvents The CircuitEvents instance to handle circuit-related events.
|
|
81
|
+
* @param sourceOperation The operation to be moved.
|
|
82
|
+
* @param originalOperation The original source operation to be ignored during the check for existing operations.
|
|
83
|
+
* @param targetLocation The location string of the target position.
|
|
84
|
+
* @param insertNewColumn Whether to insert a new column when adding the operation.
|
|
85
|
+
*/
|
|
86
|
+
const _moveX = (
|
|
87
|
+
circuitEvents: CircuitEvents,
|
|
88
|
+
sourceOperation: Operation,
|
|
89
|
+
originalOperation: Operation,
|
|
90
|
+
targetLocation: string,
|
|
91
|
+
insertNewColumn: boolean = false,
|
|
92
|
+
) => {
|
|
93
|
+
const targetOperationParent = findParentArray(
|
|
94
|
+
circuitEvents.componentGrid,
|
|
95
|
+
targetLocation,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const targetLastIndex = locationStringToIndexes(targetLocation).pop();
|
|
99
|
+
|
|
100
|
+
if (targetOperationParent == null || targetLastIndex == null) return;
|
|
101
|
+
|
|
102
|
+
// Insert sourceOperation to target last index
|
|
103
|
+
_addOp(
|
|
104
|
+
circuitEvents,
|
|
105
|
+
sourceOperation,
|
|
106
|
+
targetOperationParent,
|
|
107
|
+
targetLastIndex,
|
|
108
|
+
insertNewColumn,
|
|
109
|
+
originalOperation,
|
|
110
|
+
);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Move an operation vertically by changing its controls and targets.
|
|
115
|
+
*
|
|
116
|
+
* @param circuitEvents The CircuitEvents instance to handle circuit-related events.
|
|
117
|
+
* @param sourceOperation The operation to be moved.
|
|
118
|
+
* @param sourceLocation The location string of the source operation.
|
|
119
|
+
* @param sourceWire The wire index of the source operation.
|
|
120
|
+
* @param targetWire The wire index to move the operation to.
|
|
121
|
+
* @param movingControl Whether the operation is being moved as a control.
|
|
122
|
+
*/
|
|
123
|
+
const _moveY = (
|
|
124
|
+
circuitEvents: CircuitEvents,
|
|
125
|
+
sourceOperation: Operation,
|
|
126
|
+
sourceLocation: string,
|
|
127
|
+
sourceWire: number,
|
|
128
|
+
targetWire: number,
|
|
129
|
+
movingControl: boolean,
|
|
130
|
+
): void => {
|
|
131
|
+
// Check if the source operation already has a target or control on the target wire
|
|
132
|
+
let registers: Register[];
|
|
133
|
+
switch (sourceOperation.kind) {
|
|
134
|
+
case "unitary":
|
|
135
|
+
registers = [
|
|
136
|
+
...sourceOperation.targets,
|
|
137
|
+
...(sourceOperation.controls || []),
|
|
138
|
+
];
|
|
139
|
+
break;
|
|
140
|
+
case "measurement":
|
|
141
|
+
registers = [...sourceOperation.qubits, ...sourceOperation.results];
|
|
142
|
+
break;
|
|
143
|
+
case "ket":
|
|
144
|
+
registers = sourceOperation.targets;
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (registers.find((target) => target.qubit === targetWire)) {
|
|
149
|
+
// If the target or control already exists, don't move the target/control
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
switch (sourceOperation.kind) {
|
|
154
|
+
case "unitary":
|
|
155
|
+
if (movingControl) {
|
|
156
|
+
sourceOperation.controls?.forEach((control) => {
|
|
157
|
+
if (control.qubit === sourceWire) {
|
|
158
|
+
control.qubit = targetWire;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
sourceOperation.controls = sourceOperation.controls?.sort(
|
|
162
|
+
(a, b) => a.qubit - b.qubit,
|
|
163
|
+
);
|
|
164
|
+
} else {
|
|
165
|
+
sourceOperation.targets = [{ qubit: targetWire }];
|
|
166
|
+
}
|
|
167
|
+
break;
|
|
168
|
+
case "measurement":
|
|
169
|
+
sourceOperation.qubits = [{ qubit: targetWire }];
|
|
170
|
+
// The measurement result is updated later in the _updateMeasurementLines function
|
|
171
|
+
break;
|
|
172
|
+
case "ket":
|
|
173
|
+
sourceOperation.targets = [{ qubit: targetWire }];
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Update parent operation targets
|
|
178
|
+
const parentOperation = findParentOperation(
|
|
179
|
+
circuitEvents.componentGrid,
|
|
180
|
+
sourceLocation,
|
|
181
|
+
);
|
|
182
|
+
if (parentOperation) {
|
|
183
|
+
if (parentOperation.kind === "measurement") {
|
|
184
|
+
// Note: this is very confusing with measurements. Maybe the right thing to do
|
|
185
|
+
// will become more apparent if we implement expandable measurements.
|
|
186
|
+
parentOperation.results = getChildTargets(parentOperation);
|
|
187
|
+
} else if (
|
|
188
|
+
parentOperation.kind === "unitary" ||
|
|
189
|
+
parentOperation.kind === "ket"
|
|
190
|
+
) {
|
|
191
|
+
parentOperation.targets = getChildTargets(parentOperation);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Add an operation into the circuit.
|
|
198
|
+
*
|
|
199
|
+
* @param circuitEvents The CircuitEvents instance to handle circuit-related events.
|
|
200
|
+
* @param sourceOperation The operation to be added.
|
|
201
|
+
* @param targetLocation The location string of the target position.
|
|
202
|
+
* @param targetWire The wire index to add the operation to.
|
|
203
|
+
* @param insertNewColumn Whether to insert a new column when adding the operation.
|
|
204
|
+
* @returns The added operation or null if the addition was unsuccessful.
|
|
205
|
+
*/
|
|
206
|
+
const addOperation = (
|
|
207
|
+
circuitEvents: CircuitEvents,
|
|
208
|
+
sourceOperation: Operation,
|
|
209
|
+
targetLocation: string,
|
|
210
|
+
targetWire: number,
|
|
211
|
+
insertNewColumn: boolean = false,
|
|
212
|
+
): Operation | null => {
|
|
213
|
+
const targetOperationParent = findParentArray(
|
|
214
|
+
circuitEvents.componentGrid,
|
|
215
|
+
targetLocation,
|
|
216
|
+
);
|
|
217
|
+
const targetLastIndex = locationStringToIndexes(targetLocation).pop();
|
|
218
|
+
|
|
219
|
+
if (targetOperationParent == null || targetLastIndex == null) return null;
|
|
220
|
+
// Create a deep copy of the source operation
|
|
221
|
+
const newSourceOperation: Operation = JSON.parse(
|
|
222
|
+
JSON.stringify(sourceOperation),
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
if (newSourceOperation.kind === "measurement") {
|
|
226
|
+
newSourceOperation.qubits = [{ qubit: targetWire }];
|
|
227
|
+
// The measurement result is updated later in the _updateMeasurementLines function
|
|
228
|
+
} else if (
|
|
229
|
+
newSourceOperation.kind === "unitary" ||
|
|
230
|
+
newSourceOperation.kind === "ket"
|
|
231
|
+
) {
|
|
232
|
+
newSourceOperation.targets = [{ qubit: targetWire }];
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
_addOp(
|
|
236
|
+
circuitEvents,
|
|
237
|
+
newSourceOperation,
|
|
238
|
+
targetOperationParent,
|
|
239
|
+
targetLastIndex,
|
|
240
|
+
insertNewColumn,
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
return newSourceOperation;
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Remove an operation from the circuit.
|
|
248
|
+
*
|
|
249
|
+
* @param circuitEvents The CircuitEvents instance to handle circuit-related events.
|
|
250
|
+
* @param sourceLocation The location string of the operation to be removed.
|
|
251
|
+
*/
|
|
252
|
+
const removeOperation = (
|
|
253
|
+
circuitEvents: CircuitEvents,
|
|
254
|
+
sourceLocation: string,
|
|
255
|
+
) => {
|
|
256
|
+
const sourceOperation = findOperation(
|
|
257
|
+
circuitEvents.componentGrid,
|
|
258
|
+
sourceLocation,
|
|
259
|
+
);
|
|
260
|
+
const sourceOperationParent = findParentArray(
|
|
261
|
+
circuitEvents.componentGrid,
|
|
262
|
+
sourceLocation,
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
if (sourceOperation == null || sourceOperationParent == null) return null;
|
|
266
|
+
|
|
267
|
+
// Delete sourceOperation
|
|
268
|
+
_removeOp(circuitEvents, sourceOperation, sourceOperationParent);
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Find and remove operations in-place based on a predicate function.
|
|
273
|
+
*
|
|
274
|
+
* @param componentGrid The grid of components to search through.
|
|
275
|
+
* @param pred The predicate function to determine which operations to remove.
|
|
276
|
+
*/
|
|
277
|
+
const findAndRemoveOperations = (
|
|
278
|
+
componentGrid: ComponentGrid,
|
|
279
|
+
pred: (op: Operation) => boolean,
|
|
280
|
+
) => {
|
|
281
|
+
const inPlaceFilter = (
|
|
282
|
+
grid: ComponentGrid,
|
|
283
|
+
pred: (op: Operation) => boolean,
|
|
284
|
+
) => {
|
|
285
|
+
let i = 0;
|
|
286
|
+
while (i < grid.length) {
|
|
287
|
+
let j = 0;
|
|
288
|
+
while (j < grid[i].components.length) {
|
|
289
|
+
if (!pred(grid[i].components[j])) {
|
|
290
|
+
grid[i].components.splice(j, 1);
|
|
291
|
+
} else {
|
|
292
|
+
j++;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (grid[i].components.length === 0) {
|
|
296
|
+
grid.splice(i, 1);
|
|
297
|
+
} else {
|
|
298
|
+
i++;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
const recursivePred = (op: Operation) => {
|
|
304
|
+
if (pred(op)) return true;
|
|
305
|
+
if (op.children) {
|
|
306
|
+
inPlaceFilter(op.children, (child) => !recursivePred(child));
|
|
307
|
+
}
|
|
308
|
+
return false;
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
inPlaceFilter(componentGrid, (op) => !recursivePred(op));
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Add a control to the specified operation on the given wire index.
|
|
316
|
+
*
|
|
317
|
+
* @param op The unitary operation to which the control will be added.
|
|
318
|
+
* @param wireIndex The index of the wire where the control will be added.
|
|
319
|
+
* @returns True if the control was added, false if it already existed.
|
|
320
|
+
*/
|
|
321
|
+
const addControl = (op: Unitary, wireIndex: number): boolean => {
|
|
322
|
+
if (!op.controls) {
|
|
323
|
+
op.controls = [];
|
|
324
|
+
}
|
|
325
|
+
const existingControl = op.controls.find(
|
|
326
|
+
(control) => control.qubit === wireIndex,
|
|
327
|
+
);
|
|
328
|
+
if (!existingControl) {
|
|
329
|
+
op.controls.push({ qubit: wireIndex });
|
|
330
|
+
op.controls.sort((a, b) => a.qubit - b.qubit);
|
|
331
|
+
return true;
|
|
332
|
+
}
|
|
333
|
+
return false;
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Remove a control from the specified operation on the given wire index.
|
|
338
|
+
*
|
|
339
|
+
* @param op The unitary operation from which the control will be removed.
|
|
340
|
+
* @param wireIndex The index of the wire where the control will be removed.
|
|
341
|
+
* @returns True if the control was removed, false if it did not exist.
|
|
342
|
+
*/
|
|
343
|
+
const removeControl = (op: Unitary, wireIndex: number): boolean => {
|
|
344
|
+
if (op.controls) {
|
|
345
|
+
const controlIndex = op.controls.findIndex(
|
|
346
|
+
(control) => control.qubit === wireIndex,
|
|
347
|
+
);
|
|
348
|
+
if (controlIndex !== -1) {
|
|
349
|
+
op.controls.splice(controlIndex, 1);
|
|
350
|
+
return true;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return false;
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Add an operation to the circuit at the specified location.
|
|
358
|
+
*
|
|
359
|
+
* @param circuitEvents The CircuitEvents instance to handle circuit-related events.
|
|
360
|
+
* @param sourceOperation The operation to be added.
|
|
361
|
+
* @param targetOperationParent The parent grid where the operation will be added.
|
|
362
|
+
* @param targetLastIndex The index within the parent array where the operation will be added.
|
|
363
|
+
* @param insertNewColumn Whether to insert a new column when adding the operation.
|
|
364
|
+
* @param originalOperation The original source operation to be ignored during the check for existing operations.
|
|
365
|
+
*/
|
|
366
|
+
const _addOp = (
|
|
367
|
+
circuitEvents: CircuitEvents,
|
|
368
|
+
sourceOperation: Operation,
|
|
369
|
+
targetOperationParent: ComponentGrid,
|
|
370
|
+
targetLastIndex: [number, number],
|
|
371
|
+
insertNewColumn: boolean = false,
|
|
372
|
+
originalOperation: Operation | null = null,
|
|
373
|
+
) => {
|
|
374
|
+
const [colIndex, opIndex] = targetLastIndex;
|
|
375
|
+
if (targetOperationParent[colIndex] == null) {
|
|
376
|
+
targetOperationParent[colIndex] = { components: [] };
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
insertNewColumn =
|
|
380
|
+
insertNewColumn || _isClassicallyControlled(sourceOperation);
|
|
381
|
+
|
|
382
|
+
// Check if there are any existing operations in the target
|
|
383
|
+
// column within the wire range of the new operation
|
|
384
|
+
if (!insertNewColumn) {
|
|
385
|
+
const [minTarget, maxTarget] = _getMinMaxRegIdx(sourceOperation);
|
|
386
|
+
for (const op of targetOperationParent[colIndex].components) {
|
|
387
|
+
if (op === originalOperation) continue;
|
|
388
|
+
|
|
389
|
+
const [opMinTarget, opMaxTarget] = _getMinMaxRegIdx(op);
|
|
390
|
+
if (
|
|
391
|
+
(opMinTarget >= minTarget && opMinTarget <= maxTarget) ||
|
|
392
|
+
(opMaxTarget >= minTarget && opMaxTarget <= maxTarget) ||
|
|
393
|
+
(minTarget >= opMinTarget && minTarget <= opMaxTarget) ||
|
|
394
|
+
(maxTarget >= opMinTarget && maxTarget <= opMaxTarget)
|
|
395
|
+
) {
|
|
396
|
+
insertNewColumn = true;
|
|
397
|
+
break;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
if (insertNewColumn) {
|
|
403
|
+
targetOperationParent.splice(colIndex, 0, {
|
|
404
|
+
components: [sourceOperation],
|
|
405
|
+
});
|
|
406
|
+
} else {
|
|
407
|
+
targetOperationParent[colIndex].components.splice(
|
|
408
|
+
opIndex,
|
|
409
|
+
0,
|
|
410
|
+
sourceOperation,
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
if (sourceOperation.kind === "measurement") {
|
|
415
|
+
for (const targetWires of sourceOperation.qubits) {
|
|
416
|
+
_updateMeasurementLines(circuitEvents, targetWires.qubit);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Get the minimum and maximum register indices for a given operation.
|
|
423
|
+
* Based on getMinMaxRegIdx in process.ts, but without the numQubits.
|
|
424
|
+
*
|
|
425
|
+
* @param operation The operation for which to get the register indices.
|
|
426
|
+
* @returns A tuple containing the minimum and maximum register indices.
|
|
427
|
+
*/
|
|
428
|
+
const _getMinMaxRegIdx = (operation: Operation): [number, number] => {
|
|
429
|
+
let targets: Register[];
|
|
430
|
+
let controls: Register[];
|
|
431
|
+
switch (operation.kind) {
|
|
432
|
+
case "measurement":
|
|
433
|
+
targets = operation.results;
|
|
434
|
+
controls = operation.qubits;
|
|
435
|
+
break;
|
|
436
|
+
case "unitary":
|
|
437
|
+
targets = operation.targets;
|
|
438
|
+
controls = operation.controls || [];
|
|
439
|
+
break;
|
|
440
|
+
case "ket":
|
|
441
|
+
targets = operation.targets;
|
|
442
|
+
controls = [];
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const ctrls: Register[] = controls || [];
|
|
447
|
+
const qRegs: Register[] = [...ctrls, ...targets].filter(
|
|
448
|
+
({ result }) => result === undefined,
|
|
449
|
+
);
|
|
450
|
+
if (qRegs.length === 0) return [-1, -1];
|
|
451
|
+
const qRegIdxList: number[] = qRegs.map(({ qubit }) => qubit);
|
|
452
|
+
// Pad the contiguous range of registers that it covers.
|
|
453
|
+
const minRegIdx: number = Math.min(...qRegIdxList);
|
|
454
|
+
const maxRegIdx: number = Math.max(...qRegIdxList);
|
|
455
|
+
|
|
456
|
+
return [minRegIdx, maxRegIdx];
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Check if an operation is classically controlled.
|
|
461
|
+
*
|
|
462
|
+
* @param operation The operation for which to get the register indices.
|
|
463
|
+
* @returns True if the operation is classically controlled, false otherwise.
|
|
464
|
+
*/
|
|
465
|
+
const _isClassicallyControlled = (operation: Operation): boolean => {
|
|
466
|
+
if (operation.kind !== "unitary") return false;
|
|
467
|
+
if (operation.controls === undefined) return false;
|
|
468
|
+
const clsControl = operation.controls.find(
|
|
469
|
+
({ result }) => result !== undefined,
|
|
470
|
+
);
|
|
471
|
+
return clsControl !== undefined;
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Remove an operation from the circuit.
|
|
476
|
+
*
|
|
477
|
+
* @param circuitEvents The CircuitEvents instance to handle circuit-related events.
|
|
478
|
+
* @param sourceOperation The operation to be removed.
|
|
479
|
+
* @param sourceOperationParent The parent grid from which the operation will be removed.
|
|
480
|
+
*/
|
|
481
|
+
const _removeOp = (
|
|
482
|
+
circuitEvents: CircuitEvents,
|
|
483
|
+
sourceOperation: Operation,
|
|
484
|
+
sourceOperationParent: ComponentGrid,
|
|
485
|
+
) => {
|
|
486
|
+
if (sourceOperation.dataAttributes === undefined) {
|
|
487
|
+
sourceOperation.dataAttributes = { removed: "true" };
|
|
488
|
+
} else {
|
|
489
|
+
sourceOperation.dataAttributes["removed"] = "true";
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// Find and remove the operation in sourceOperationParent
|
|
493
|
+
for (let colIndex = 0; colIndex < sourceOperationParent.length; colIndex++) {
|
|
494
|
+
const col = sourceOperationParent[colIndex];
|
|
495
|
+
const indexToRemove = col.components.findIndex(
|
|
496
|
+
(operation) =>
|
|
497
|
+
operation.dataAttributes && operation.dataAttributes["removed"],
|
|
498
|
+
);
|
|
499
|
+
if (indexToRemove !== -1) {
|
|
500
|
+
col.components.splice(indexToRemove, 1);
|
|
501
|
+
if (col.components.length === 0) {
|
|
502
|
+
sourceOperationParent.splice(colIndex, 1);
|
|
503
|
+
}
|
|
504
|
+
break;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
if (sourceOperation.kind === "measurement") {
|
|
509
|
+
for (const result of sourceOperation.results) {
|
|
510
|
+
_updateMeasurementLines(circuitEvents, result.qubit);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Update measurement lines for a specific wire.
|
|
517
|
+
*
|
|
518
|
+
* @param circuitEvents The CircuitEvents instance to handle circuit-related events.
|
|
519
|
+
* @param wireIndex The index of the wire to update the measurement lines for.
|
|
520
|
+
*/
|
|
521
|
+
const _updateMeasurementLines = (
|
|
522
|
+
circuitEvents: CircuitEvents,
|
|
523
|
+
wireIndex: number,
|
|
524
|
+
) => {
|
|
525
|
+
let resultIndex = 0;
|
|
526
|
+
for (const col of circuitEvents.componentGrid) {
|
|
527
|
+
for (const comp of col.components) {
|
|
528
|
+
if (comp.kind === "measurement") {
|
|
529
|
+
// Find measurements on the correct wire based on their qubit.
|
|
530
|
+
const qubit = comp.qubits.find((qubit) => qubit.qubit === wireIndex);
|
|
531
|
+
if (qubit) {
|
|
532
|
+
// Remove any existing results and add a new one with the updated index.
|
|
533
|
+
comp.results = [{ qubit: qubit.qubit, result: resultIndex++ }];
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
circuitEvents.qubits[wireIndex].numResults =
|
|
539
|
+
resultIndex > 0 ? resultIndex : undefined;
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
export {
|
|
543
|
+
moveOperation,
|
|
544
|
+
addOperation,
|
|
545
|
+
removeOperation,
|
|
546
|
+
findAndRemoveOperations,
|
|
547
|
+
addControl,
|
|
548
|
+
removeControl,
|
|
549
|
+
};
|
|
@@ -37,3 +37,10 @@ export const labelFontSize = 14;
|
|
|
37
37
|
export const argsFontSize = 12;
|
|
38
38
|
/** Starting x coord for each register wire. */
|
|
39
39
|
export const regLineStart = 40;
|
|
40
|
+
|
|
41
|
+
// Toolbox
|
|
42
|
+
/** Toolbox minimum height */
|
|
43
|
+
export const minToolboxHeight = 150;
|
|
44
|
+
/** Gap between gates in Toolbox Panel */
|
|
45
|
+
export const horizontalGap = 10;
|
|
46
|
+
export const verticalGap = 10;
|