qsharp-lang 1.15.2-dev → 1.15.4-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/katas-content.generated.js +5 -5
- package/dist/katas-content.generated.md.js +5 -5
- package/dist/samples.generated.js +6 -0
- package/dist/shared/legacyCircuitUpdate.js +1 -0
- package/dist/shared/register.d.ts +5 -5
- 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/ApplyOperationPowerA.md +25 -0
- 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 +2 -1
- package/docs/Std.Convert/BigIntAsBoolArray.md +1 -1
- package/docs/Std.Convert/BigIntAsInt.md +30 -0
- 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 +2 -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 +8 -5
- package/docs/Std.Math/RoundHalfAwayFromZero.md +27 -0
- 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 +3 -2
- 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/docs/toc.yml +3 -0
- package/lib/node/qsc_wasm.cjs +2 -2
- package/lib/node/qsc_wasm.d.cts +3 -6
- package/lib/node/qsc_wasm_bg.wasm +0 -0
- package/lib/web/qsc_wasm.d.ts +3 -6
- 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/circuitManipulation.ts +31 -9
- package/ux/circuit-vis/contextMenu.ts +42 -18
- package/ux/circuit-vis/draggable.ts +3 -3
- package/ux/circuit-vis/events.ts +21 -6
- package/ux/circuit-vis/formatters/formatUtils.ts +3 -3
- package/ux/circuit-vis/formatters/gateFormatter.ts +106 -65
- package/ux/circuit-vis/formatters/inputFormatter.ts +9 -31
- package/ux/circuit-vis/formatters/registerFormatter.ts +4 -4
- package/ux/circuit-vis/{metadata.ts → gateRenderData.ts} +4 -4
- package/ux/circuit-vis/panel.ts +31 -32
- package/ux/circuit-vis/process.ts +114 -106
- package/ux/circuit-vis/register.ts +1 -1
- package/ux/circuit-vis/sqore.ts +14 -10
- package/ux/circuit-vis/utils.ts +56 -4
- package/ux/circuit.tsx +7 -1
- package/ux/qsharp-circuit.css +353 -334
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { GateRenderData, GateType } from "../gateRenderData";
|
|
5
5
|
import {
|
|
6
6
|
minGateWidth,
|
|
7
7
|
gateHeight,
|
|
@@ -26,58 +26,68 @@ import {
|
|
|
26
26
|
dashedBox,
|
|
27
27
|
} from "./formatUtils";
|
|
28
28
|
|
|
29
|
+
import { mathChars } from "../utils";
|
|
30
|
+
|
|
29
31
|
/**
|
|
30
|
-
* Given an array of operations
|
|
32
|
+
* Given an array of operations render data, return the SVG representation.
|
|
31
33
|
*
|
|
32
|
-
* @param
|
|
34
|
+
* @param renderData 2D array of rendering data for gates.
|
|
33
35
|
* @param nestedDepth Depth of nested operations (used in classically controlled and grouped operations).
|
|
34
36
|
*
|
|
35
37
|
* @returns SVG representation of operations.
|
|
36
38
|
*/
|
|
37
39
|
const formatGates = (
|
|
38
|
-
|
|
40
|
+
renderData: GateRenderData[][],
|
|
39
41
|
nestedDepth = 0,
|
|
40
42
|
): SVGElement => {
|
|
41
|
-
const formattedGates: SVGElement[] =
|
|
42
|
-
.map((col) => col.map((
|
|
43
|
+
const formattedGates: SVGElement[] = renderData
|
|
44
|
+
.map((col) => col.map((renderData) => formatGate(renderData, nestedDepth)))
|
|
43
45
|
.flat();
|
|
44
46
|
return group(formattedGates);
|
|
45
47
|
};
|
|
46
48
|
|
|
47
49
|
/**
|
|
48
|
-
* Takes in an operation's
|
|
50
|
+
* Takes in an operation's rendering data and formats it into SVG.
|
|
49
51
|
*
|
|
50
|
-
* @param
|
|
52
|
+
* @param renderData The rendering data of the gate.
|
|
51
53
|
* @param nestedDepth Depth of nested operations (used in classically controlled and grouped operations).
|
|
52
54
|
*
|
|
53
55
|
* @returns SVG representation of gate.
|
|
54
56
|
*/
|
|
55
|
-
const formatGate = (
|
|
56
|
-
|
|
57
|
+
const formatGate = (
|
|
58
|
+
renderData: GateRenderData,
|
|
59
|
+
nestedDepth = 0,
|
|
60
|
+
): SVGElement => {
|
|
61
|
+
const { type, x, controlsY, targetsY, label, displayArgs, width } =
|
|
62
|
+
renderData;
|
|
57
63
|
switch (type) {
|
|
58
64
|
case GateType.Measure:
|
|
59
|
-
return _createGate([_measure(x, controlsY[0])],
|
|
65
|
+
return _createGate([_measure(x, controlsY[0])], renderData, nestedDepth);
|
|
60
66
|
case GateType.Unitary:
|
|
61
67
|
return _createGate(
|
|
62
68
|
[_unitary(label, x, targetsY as number[][], width, displayArgs)],
|
|
63
|
-
|
|
69
|
+
renderData,
|
|
64
70
|
nestedDepth,
|
|
65
71
|
);
|
|
66
72
|
case GateType.X:
|
|
67
|
-
return _createGate([_x(
|
|
73
|
+
return _createGate([_x(renderData)], renderData, nestedDepth);
|
|
68
74
|
case GateType.Ket:
|
|
69
|
-
return _createGate([_ket(label,
|
|
75
|
+
return _createGate([_ket(label, renderData)], renderData, nestedDepth);
|
|
70
76
|
case GateType.Swap:
|
|
71
77
|
return controlsY.length > 0
|
|
72
|
-
? _controlledGate(
|
|
73
|
-
: _createGate(
|
|
78
|
+
? _controlledGate(renderData, nestedDepth)
|
|
79
|
+
: _createGate(
|
|
80
|
+
[_swap(renderData, nestedDepth)],
|
|
81
|
+
renderData,
|
|
82
|
+
nestedDepth,
|
|
83
|
+
);
|
|
74
84
|
case GateType.Cnot:
|
|
75
85
|
case GateType.ControlledUnitary:
|
|
76
|
-
return _controlledGate(
|
|
86
|
+
return _controlledGate(renderData, nestedDepth);
|
|
77
87
|
case GateType.Group:
|
|
78
|
-
return _groupedOperations(
|
|
88
|
+
return _groupedOperations(renderData, nestedDepth);
|
|
79
89
|
case GateType.ClassicalControlled:
|
|
80
|
-
return _classicalControlled(
|
|
90
|
+
return _classicalControlled(renderData);
|
|
81
91
|
default:
|
|
82
92
|
throw new Error(`ERROR: unknown gate (${label}) of type ${type}.`);
|
|
83
93
|
}
|
|
@@ -86,23 +96,24 @@ const formatGate = (metadata: Metadata, nestedDepth = 0): SVGElement => {
|
|
|
86
96
|
/**
|
|
87
97
|
* Groups SVG elements into a gate SVG group.
|
|
88
98
|
*
|
|
89
|
-
* @param svgElems
|
|
90
|
-
* @param
|
|
99
|
+
* @param svgElems - Array of SVG elements that make up the gate.
|
|
100
|
+
* @param renderData - Render data containing information about the gate, such as data attributes.
|
|
101
|
+
* @param nestedDepth - Depth of nested operation.
|
|
91
102
|
*
|
|
92
103
|
* @returns SVG representation of a gate.
|
|
93
104
|
*/
|
|
94
105
|
const _createGate = (
|
|
95
106
|
svgElems: SVGElement[],
|
|
96
|
-
|
|
107
|
+
renderData: GateRenderData,
|
|
97
108
|
nestedDepth: number,
|
|
98
109
|
): SVGElement => {
|
|
99
|
-
const { dataAttributes } =
|
|
110
|
+
const { dataAttributes } = renderData || {};
|
|
100
111
|
const attributes: { [attr: string]: string } = { class: "gate" };
|
|
101
112
|
Object.entries(dataAttributes || {}).forEach(
|
|
102
113
|
([attr, val]) => (attributes[`data-${attr}`] = val),
|
|
103
114
|
);
|
|
104
115
|
|
|
105
|
-
const zoomBtn: SVGElement | null = _zoomButton(
|
|
116
|
+
const zoomBtn: SVGElement | null = _zoomButton(renderData, nestedDepth);
|
|
106
117
|
if (zoomBtn != null) svgElems = svgElems.concat([zoomBtn]);
|
|
107
118
|
return group(svgElems, attributes);
|
|
108
119
|
};
|
|
@@ -111,19 +122,19 @@ const _createGate = (
|
|
|
111
122
|
* Returns the expand/collapse button for an operation if it can be zoomed-in or zoomed-out,
|
|
112
123
|
* respectively. If neither are allowed, return `null`.
|
|
113
124
|
*
|
|
114
|
-
* @param
|
|
125
|
+
* @param renderData Operation render data.
|
|
115
126
|
* @param nestedDepth Depth of nested operation.
|
|
116
127
|
*
|
|
117
128
|
* @returns SVG element for expand/collapse button if needed, or null otherwise.
|
|
118
129
|
*/
|
|
119
130
|
const _zoomButton = (
|
|
120
|
-
|
|
131
|
+
renderData: GateRenderData,
|
|
121
132
|
nestedDepth: number,
|
|
122
133
|
): SVGElement | null => {
|
|
123
|
-
if (
|
|
134
|
+
if (renderData == undefined) return null;
|
|
124
135
|
|
|
125
|
-
const [x1, y1] = _gatePosition(
|
|
126
|
-
let { dataAttributes } =
|
|
136
|
+
const [x1, y1] = _gatePosition(renderData, nestedDepth);
|
|
137
|
+
let { dataAttributes } = renderData;
|
|
127
138
|
dataAttributes = dataAttributes || {};
|
|
128
139
|
|
|
129
140
|
const expanded = "expanded" in dataAttributes;
|
|
@@ -154,16 +165,16 @@ const _zoomButton = (
|
|
|
154
165
|
/**
|
|
155
166
|
* Calculate position of gate.
|
|
156
167
|
*
|
|
157
|
-
* @param
|
|
168
|
+
* @param renderData Operation render data.
|
|
158
169
|
* @param nestedDepth Depth of nested operations.
|
|
159
170
|
*
|
|
160
171
|
* @returns Coordinates of gate: [x1, y1, x2, y2].
|
|
161
172
|
*/
|
|
162
173
|
const _gatePosition = (
|
|
163
|
-
|
|
174
|
+
renderData: GateRenderData,
|
|
164
175
|
nestedDepth: number,
|
|
165
176
|
): [number, number, number, number] => {
|
|
166
|
-
const { x, width, type, targetsY } =
|
|
177
|
+
const { x, width, type, targetsY } = renderData;
|
|
167
178
|
|
|
168
179
|
const ys = targetsY?.flatMap((y) => y as number[]) || [];
|
|
169
180
|
const maxY = Math.max(...ys);
|
|
@@ -225,6 +236,31 @@ const _measure = (x: number, y: number): SVGElement => {
|
|
|
225
236
|
return group([mBox, mArc, meter]);
|
|
226
237
|
};
|
|
227
238
|
|
|
239
|
+
const use_katex = true;
|
|
240
|
+
|
|
241
|
+
function _style_gate_text(gate: SVGTextElement) {
|
|
242
|
+
if (!use_katex) return;
|
|
243
|
+
let label = gate.textContent || "";
|
|
244
|
+
|
|
245
|
+
// In general, use the regular math font
|
|
246
|
+
gate.classList.add("qs-maintext");
|
|
247
|
+
|
|
248
|
+
// Wrap any latin or greek letters in tspan with KaTeX_Math font
|
|
249
|
+
// Style the entire Greek + Coptic block (https://unicodeplus.com/block/0370)
|
|
250
|
+
// Note this deliberately leaves ASCII digits [0-9] non-italic
|
|
251
|
+
const italicChars = /[a-zA-Z\u{0370}-\u{03ff}]+/gu;
|
|
252
|
+
|
|
253
|
+
label = label.replace(italicChars, `<tspan class='qs-mathtext'>$&</tspan>`);
|
|
254
|
+
|
|
255
|
+
// Replace a trailing ' with the proper unicode dagger symbol
|
|
256
|
+
label = label.replace(
|
|
257
|
+
/'$/,
|
|
258
|
+
`<tspan dx="2" dy="-3" style="font-size: 0.8em;">${mathChars.dagger}</tspan>`,
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
gate.innerHTML = label;
|
|
262
|
+
}
|
|
263
|
+
|
|
228
264
|
/**
|
|
229
265
|
* Creates the SVG for a unitary gate on an arbitrary number of qubits.
|
|
230
266
|
*
|
|
@@ -302,12 +338,15 @@ const _unitaryBox = (
|
|
|
302
338
|
uBox.setAttribute("class", cssClass);
|
|
303
339
|
}
|
|
304
340
|
const labelY = y + height / 2 - (displayArgs == null ? 0 : 7);
|
|
305
|
-
const labelText
|
|
341
|
+
const labelText = text(label, x, labelY);
|
|
342
|
+
_style_gate_text(labelText);
|
|
343
|
+
|
|
306
344
|
const elems = [uBox, labelText];
|
|
307
345
|
if (displayArgs != null) {
|
|
308
346
|
const argStrY = y + height / 2 + 8;
|
|
309
347
|
|
|
310
|
-
const argButton
|
|
348
|
+
const argButton = text(displayArgs, x, argStrY, argsFontSize);
|
|
349
|
+
_style_gate_text(argButton);
|
|
311
350
|
argButton.setAttribute("class", "arg-button");
|
|
312
351
|
elems.push(argButton);
|
|
313
352
|
}
|
|
@@ -315,18 +354,18 @@ const _unitaryBox = (
|
|
|
315
354
|
};
|
|
316
355
|
|
|
317
356
|
/**
|
|
318
|
-
* Creates the SVG for a SWAP gate on y coords given by
|
|
357
|
+
* Creates the SVG for a SWAP gate on y coords given by `renderData`.
|
|
319
358
|
*
|
|
320
|
-
* @param
|
|
321
|
-
* @param
|
|
359
|
+
* @param renderData - The render data containing information about the gate, including position and targets.
|
|
360
|
+
* @param nestedDepth - The depth of nested operations (used for adjusting padding and positioning).
|
|
322
361
|
*
|
|
323
362
|
* @returns SVG representation of SWAP gate.
|
|
324
363
|
*/
|
|
325
|
-
const _swap = (
|
|
326
|
-
const { x, targetsY } =
|
|
364
|
+
const _swap = (renderData: GateRenderData, nestedDepth: number): SVGElement => {
|
|
365
|
+
const { x, targetsY } = renderData;
|
|
327
366
|
|
|
328
367
|
// Get SVGs of crosses
|
|
329
|
-
const [x1, y1, x2, y2] = _gatePosition(
|
|
368
|
+
const [x1, y1, x2, y2] = _gatePosition(renderData, nestedDepth);
|
|
330
369
|
const ys = targetsY?.flatMap((y) => y as number[]) || [];
|
|
331
370
|
|
|
332
371
|
const bg: SVGElement = box(x1, y1, x2, y2, "gate-swap");
|
|
@@ -339,11 +378,12 @@ const _swap = (metadata: Metadata, nestedDepth: number): SVGElement => {
|
|
|
339
378
|
/**
|
|
340
379
|
* Creates the SVG for an X gate
|
|
341
380
|
*
|
|
381
|
+
* @param renderData - The render data containing information about the gate, including position and targets.
|
|
382
|
+
*
|
|
342
383
|
* @returns SVG representation of X gate.
|
|
343
384
|
*/
|
|
344
|
-
|
|
345
|
-
const
|
|
346
|
-
const { x, targetsY } = metadata;
|
|
385
|
+
const _x = (renderData: GateRenderData): SVGElement => {
|
|
386
|
+
const { x, targetsY } = renderData;
|
|
347
387
|
const ys = targetsY.flatMap((y) => y as number[]);
|
|
348
388
|
return _oplus(x, ys[0]);
|
|
349
389
|
};
|
|
@@ -352,14 +392,14 @@ const _x = (metadata: Metadata, _: number): SVGElement => {
|
|
|
352
392
|
* Creates the SVG for a ket notation (e.g "|0⟩" or "|1⟩") gate.
|
|
353
393
|
*
|
|
354
394
|
* @param label The label for the ket notation (e.g., "0" or "1").
|
|
355
|
-
* @param
|
|
395
|
+
* @param renderData The render data containing information about the gate's position and appearance.
|
|
356
396
|
*
|
|
357
397
|
* @returns SVG representation of the ket notation gate.
|
|
358
398
|
*/
|
|
359
|
-
const _ket = (label: string,
|
|
360
|
-
const { x, targetsY, width } =
|
|
399
|
+
const _ket = (label: string, renderData: GateRenderData): SVGElement => {
|
|
400
|
+
const { x, targetsY, width } = renderData;
|
|
361
401
|
const gate = _unitary(
|
|
362
|
-
`|${label}
|
|
402
|
+
`|${label}${mathChars.rangle}`,
|
|
363
403
|
x,
|
|
364
404
|
targetsY as number[][],
|
|
365
405
|
width,
|
|
@@ -367,7 +407,7 @@ const _ket = (label: string, metadata: Metadata): SVGElement => {
|
|
|
367
407
|
false,
|
|
368
408
|
"gate-ket",
|
|
369
409
|
);
|
|
370
|
-
gate.querySelector("text")!.
|
|
410
|
+
gate.querySelector("text")!.classList.add("ket-text");
|
|
371
411
|
return gate;
|
|
372
412
|
};
|
|
373
413
|
|
|
@@ -399,17 +439,17 @@ const _cross = (x: number, y: number): SVGElement => {
|
|
|
399
439
|
/**
|
|
400
440
|
* Produces the SVG representation of a controlled gate on multiple qubits.
|
|
401
441
|
*
|
|
402
|
-
* @param
|
|
442
|
+
* @param renderData Render data of controlled gate.
|
|
403
443
|
*
|
|
404
444
|
* @returns SVG representation of controlled gate.
|
|
405
445
|
*/
|
|
406
446
|
const _controlledGate = (
|
|
407
|
-
|
|
447
|
+
renderData: GateRenderData,
|
|
408
448
|
nestedDepth: number,
|
|
409
449
|
): SVGElement => {
|
|
410
450
|
const targetGateSvgs: SVGElement[] = [];
|
|
411
|
-
const { type, x, controlsY, label, displayArgs, width } =
|
|
412
|
-
let { targetsY } =
|
|
451
|
+
const { type, x, controlsY, label, displayArgs, width } = renderData;
|
|
452
|
+
let { targetsY } = renderData;
|
|
413
453
|
|
|
414
454
|
// Get SVG for target gates
|
|
415
455
|
switch (type) {
|
|
@@ -442,7 +482,7 @@ const _controlledGate = (
|
|
|
442
482
|
vertLine.style.pointerEvents = "none";
|
|
443
483
|
const svg: SVGElement = _createGate(
|
|
444
484
|
[vertLine, ...controlledDotsSvg, ...targetGateSvgs],
|
|
445
|
-
|
|
485
|
+
renderData,
|
|
446
486
|
nestedDepth,
|
|
447
487
|
);
|
|
448
488
|
return svg;
|
|
@@ -467,42 +507,43 @@ const _oplus = (x: number, y: number, r = 15): SVGElement => {
|
|
|
467
507
|
/**
|
|
468
508
|
* Generates the SVG for a group of nested operations.
|
|
469
509
|
*
|
|
470
|
-
* @param
|
|
510
|
+
* @param renderData Render data of gate.
|
|
471
511
|
* @param nestedDepth Depth of nested operations (used in classically controlled and grouped operations).
|
|
472
512
|
*
|
|
473
513
|
* @returns SVG representation of gate.
|
|
474
514
|
*/
|
|
475
515
|
const _groupedOperations = (
|
|
476
|
-
|
|
516
|
+
renderData: GateRenderData,
|
|
477
517
|
nestedDepth: number,
|
|
478
518
|
): SVGElement => {
|
|
479
|
-
const { children } =
|
|
480
|
-
const [x1, y1, x2, y2] = _gatePosition(
|
|
519
|
+
const { children } = renderData;
|
|
520
|
+
const [x1, y1, x2, y2] = _gatePosition(renderData, nestedDepth);
|
|
481
521
|
|
|
482
522
|
// Draw dashed box around children gates
|
|
483
523
|
const box: SVGElement = dashedBox(x1, y1, x2, y2);
|
|
484
524
|
const elems: SVGElement[] = [box];
|
|
485
525
|
if (children != null)
|
|
486
|
-
elems.push(formatGates(children as
|
|
487
|
-
return _createGate(elems,
|
|
526
|
+
elems.push(formatGates(children as GateRenderData[][], nestedDepth + 1));
|
|
527
|
+
return _createGate(elems, renderData, nestedDepth);
|
|
488
528
|
};
|
|
489
529
|
|
|
490
530
|
/**
|
|
491
531
|
* Generates the SVG for a classically controlled group of operations.
|
|
492
532
|
*
|
|
493
|
-
* @param
|
|
533
|
+
* @param renderData Render data of gate.
|
|
494
534
|
* @param padding Padding within dashed box.
|
|
495
535
|
*
|
|
496
536
|
* @returns SVG representation of gate.
|
|
497
537
|
*/
|
|
498
538
|
const _classicalControlled = (
|
|
499
|
-
|
|
539
|
+
renderData: GateRenderData,
|
|
500
540
|
padding: number = groupBoxPadding,
|
|
501
541
|
): SVGElement => {
|
|
502
|
-
const { controlsY, dataAttributes } =
|
|
503
|
-
const targetsY: number[] =
|
|
504
|
-
const children:
|
|
505
|
-
|
|
542
|
+
const { controlsY, dataAttributes } = renderData;
|
|
543
|
+
const targetsY: number[] = renderData.targetsY as number[];
|
|
544
|
+
const children: GateRenderData[][][] =
|
|
545
|
+
renderData.children as GateRenderData[][][];
|
|
546
|
+
let { x, width } = renderData;
|
|
506
547
|
|
|
507
548
|
const controlY = controlsY[0];
|
|
508
549
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
3
|
|
|
4
4
|
import { Qubit } from "../circuit";
|
|
5
|
-
import { RegisterType, RegisterMap,
|
|
5
|
+
import { RegisterType, RegisterMap, RegisterRenderData } from "../register";
|
|
6
6
|
import {
|
|
7
7
|
leftPadding,
|
|
8
8
|
startY,
|
|
@@ -10,10 +10,11 @@ import {
|
|
|
10
10
|
classicalRegHeight,
|
|
11
11
|
} from "../constants";
|
|
12
12
|
import { group, text } from "./formatUtils";
|
|
13
|
+
import { mathChars } from "../utils";
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* `formatInputs` takes in an array of Qubits and outputs the SVG string of formatted
|
|
16
|
-
* qubit wires and a mapping from register IDs to register
|
|
17
|
+
* qubit wires and a mapping from register IDs to register rendering data.
|
|
17
18
|
*
|
|
18
19
|
* @param qubits List of declared qubits.
|
|
19
20
|
*
|
|
@@ -45,7 +46,7 @@ const formatInputs = (
|
|
|
45
46
|
|
|
46
47
|
// Add classical wires
|
|
47
48
|
registers[id].children = Array.from(Array(numResults), () => {
|
|
48
|
-
const clsReg:
|
|
49
|
+
const clsReg: RegisterRenderData = {
|
|
49
50
|
type: RegisterType.Classical,
|
|
50
51
|
y: currY,
|
|
51
52
|
};
|
|
@@ -71,38 +72,15 @@ const formatInputs = (
|
|
|
71
72
|
const _qubitInput = (y: number, subscript?: string): SVGElement => {
|
|
72
73
|
const el: SVGElement = text("", leftPadding, y, 16);
|
|
73
74
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"
|
|
77
|
-
"tspan",
|
|
78
|
-
);
|
|
79
|
-
mainText.textContent = "|𝜓";
|
|
75
|
+
const subtext = subscript
|
|
76
|
+
? `<tspan baseline-shift="sub" font-size="65%">${subscript}</tspan>`
|
|
77
|
+
: "";
|
|
80
78
|
|
|
81
|
-
|
|
82
|
-
if (subscript) {
|
|
83
|
-
const subscriptText = document.createElementNS(
|
|
84
|
-
"http://www.w3.org/2000/svg",
|
|
85
|
-
"tspan",
|
|
86
|
-
);
|
|
87
|
-
subscriptText.textContent = subscript;
|
|
88
|
-
subscriptText.setAttribute("baseline-shift", "sub");
|
|
89
|
-
subscriptText.setAttribute("font-size", "65%");
|
|
90
|
-
mainText.appendChild(subscriptText);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Add the closing part of the text
|
|
94
|
-
const closingText = document.createElementNS(
|
|
95
|
-
"http://www.w3.org/2000/svg",
|
|
96
|
-
"tspan",
|
|
97
|
-
);
|
|
98
|
-
closingText.textContent = "⟩";
|
|
99
|
-
|
|
100
|
-
// Append all parts to the main SVG text element
|
|
101
|
-
el.appendChild(mainText);
|
|
102
|
-
el.appendChild(closingText);
|
|
79
|
+
el.innerHTML = `|<tspan class="qs-mathtext">${mathChars.psi}</tspan>${subtext}${mathChars.rangle}</tspan>`;
|
|
103
80
|
|
|
104
81
|
el.setAttribute("text-anchor", "start");
|
|
105
82
|
el.setAttribute("dominant-baseline", "middle");
|
|
83
|
+
el.classList.add("qs-maintext");
|
|
106
84
|
return el;
|
|
107
85
|
};
|
|
108
86
|
|
|
@@ -3,22 +3,22 @@
|
|
|
3
3
|
|
|
4
4
|
import { RegisterMap } from "../register";
|
|
5
5
|
import { regLineStart } from "../constants";
|
|
6
|
-
import {
|
|
6
|
+
import { GateRenderData, GateType } from "../gateRenderData";
|
|
7
7
|
import { group, line } from "./formatUtils";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Generate the SVG representation of the qubit register wires in `registers` and the classical wires
|
|
11
11
|
* stemming from each measurement gate.
|
|
12
12
|
*
|
|
13
|
-
* @param registers Map from register IDs to register
|
|
14
|
-
* @param measureGates Array of measurement
|
|
13
|
+
* @param registers Map from register IDs to register render data.
|
|
14
|
+
* @param measureGates Array of measurement gate render data.
|
|
15
15
|
* @param endX End x coord.
|
|
16
16
|
*
|
|
17
17
|
* @returns SVG representation of register wires.
|
|
18
18
|
*/
|
|
19
19
|
const formatRegisters = (
|
|
20
20
|
registers: RegisterMap,
|
|
21
|
-
measureGates:
|
|
21
|
+
measureGates: GateRenderData[],
|
|
22
22
|
endX: number,
|
|
23
23
|
): SVGElement => {
|
|
24
24
|
const formattedRegs: SVGElement[] = [];
|
|
@@ -15,7 +15,7 @@ export enum GateType {
|
|
|
15
15
|
Swap,
|
|
16
16
|
/** X gate. */
|
|
17
17
|
X,
|
|
18
|
-
/** |0
|
|
18
|
+
/** |0⟩or |1⟩ gate. */
|
|
19
19
|
Ket,
|
|
20
20
|
/** Single/multi qubit unitary gate. */
|
|
21
21
|
Unitary,
|
|
@@ -30,10 +30,10 @@ export enum GateType {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* Rendering data used to store information pertaining to a given
|
|
34
34
|
* operation for rendering its corresponding SVG.
|
|
35
35
|
*/
|
|
36
|
-
export interface
|
|
36
|
+
export interface GateRenderData {
|
|
37
37
|
/** Gate type. */
|
|
38
38
|
type: GateType;
|
|
39
39
|
/** Centre x coord for gate position. */
|
|
@@ -52,7 +52,7 @@ export interface Metadata {
|
|
|
52
52
|
/** Gate width. */
|
|
53
53
|
width: number;
|
|
54
54
|
/** Children operations as part of group. */
|
|
55
|
-
children?:
|
|
55
|
+
children?: GateRenderData[][] | GateRenderData[][][];
|
|
56
56
|
/** Custom data attributes to attach to gate element. */
|
|
57
57
|
dataAttributes?: DataAttributes;
|
|
58
58
|
}
|
package/ux/circuit-vis/panel.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
verticalGap,
|
|
10
10
|
} from "./constants";
|
|
11
11
|
import { formatGate } from "./formatters/gateFormatter";
|
|
12
|
-
import { GateType,
|
|
12
|
+
import { GateType, GateRenderData } from "./gateRenderData";
|
|
13
13
|
import { getGateWidth } from "./utils";
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -83,7 +83,7 @@ const _createToolbox = (): HTMLElement => {
|
|
|
83
83
|
let prefixX = 0;
|
|
84
84
|
let prefixY = 0;
|
|
85
85
|
const gateElems = Object.keys(toolboxGateDictionary).map((key, index) => {
|
|
86
|
-
const { width: gateWidth } =
|
|
86
|
+
const { width: gateWidth } = toRenderData(toolboxGateDictionary[key], 0, 0);
|
|
87
87
|
|
|
88
88
|
// Increment prefixX for every gate, and reset after 2 gates (2 columns)
|
|
89
89
|
if (index % 2 === 0 && index !== 0) {
|
|
@@ -169,19 +169,19 @@ const _title = (text: string): HTMLElement => {
|
|
|
169
169
|
};
|
|
170
170
|
|
|
171
171
|
/**
|
|
172
|
-
* Wrapper to generate
|
|
172
|
+
* Wrapper to generate render data based on _opToRenderData with mock registers and limited support
|
|
173
173
|
* @param operation Operation object
|
|
174
174
|
* @param x x coordinate at starting point from the left
|
|
175
175
|
* @param y y coordinate at starting point from the top
|
|
176
|
-
* @returns
|
|
176
|
+
* @returns GateRenderData object
|
|
177
177
|
*/
|
|
178
|
-
const
|
|
178
|
+
const toRenderData = (
|
|
179
179
|
operation: Operation | undefined,
|
|
180
180
|
x: number,
|
|
181
181
|
y: number,
|
|
182
|
-
):
|
|
182
|
+
): GateRenderData => {
|
|
183
183
|
const target = y + 1 + gateHeight / 2; // offset by 1 for top padding
|
|
184
|
-
const
|
|
184
|
+
const renderData: GateRenderData = {
|
|
185
185
|
type: GateType.Invalid,
|
|
186
186
|
x: x + 1 + minGateWidth / 2, // offset by 1 for left padding
|
|
187
187
|
controlsY: [],
|
|
@@ -190,54 +190,54 @@ const toMetadata = (
|
|
|
190
190
|
width: -1,
|
|
191
191
|
};
|
|
192
192
|
|
|
193
|
-
if (operation === undefined) return
|
|
193
|
+
if (operation === undefined) return renderData;
|
|
194
194
|
|
|
195
195
|
switch (operation.kind) {
|
|
196
196
|
case "unitary": {
|
|
197
197
|
const { gate, controls } = operation;
|
|
198
198
|
|
|
199
199
|
if (gate === "SWAP") {
|
|
200
|
-
|
|
200
|
+
renderData.type = GateType.Swap;
|
|
201
201
|
} else if (controls && controls.length > 0) {
|
|
202
|
-
|
|
202
|
+
renderData.type =
|
|
203
203
|
gate === "X" ? GateType.Cnot : GateType.ControlledUnitary;
|
|
204
|
-
|
|
204
|
+
renderData.label = gate;
|
|
205
205
|
if (gate !== "X") {
|
|
206
|
-
|
|
206
|
+
renderData.targetsY = [[target]];
|
|
207
207
|
}
|
|
208
208
|
} else if (gate === "X") {
|
|
209
|
-
|
|
210
|
-
|
|
209
|
+
renderData.type = GateType.X;
|
|
210
|
+
renderData.label = gate;
|
|
211
211
|
} else {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
212
|
+
renderData.type = GateType.Unitary;
|
|
213
|
+
renderData.label = gate;
|
|
214
|
+
renderData.targetsY = [[target]];
|
|
215
215
|
}
|
|
216
216
|
break;
|
|
217
217
|
}
|
|
218
218
|
case "measurement":
|
|
219
|
-
|
|
220
|
-
|
|
219
|
+
renderData.type = GateType.Measure;
|
|
220
|
+
renderData.controlsY = [target];
|
|
221
221
|
break;
|
|
222
222
|
case "ket":
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
223
|
+
renderData.type = GateType.Ket;
|
|
224
|
+
renderData.label = operation.gate;
|
|
225
|
+
renderData.targetsY = [[target]];
|
|
226
226
|
break;
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
if (operation.args !== undefined && operation.args.length > 0)
|
|
230
|
-
|
|
230
|
+
renderData.displayArgs = operation.args[0];
|
|
231
231
|
|
|
232
|
-
|
|
233
|
-
|
|
232
|
+
renderData.width = getGateWidth(renderData);
|
|
233
|
+
renderData.x = x + 1 + renderData.width / 2; // offset by 1 for left padding
|
|
234
234
|
|
|
235
|
-
return
|
|
235
|
+
return renderData;
|
|
236
236
|
};
|
|
237
237
|
|
|
238
238
|
/**
|
|
239
239
|
* Generate an SVG gate element for the Toolbox panel based on the type of gate.
|
|
240
|
-
* This function retrieves the operation
|
|
240
|
+
* This function retrieves the operation render data from the gate dictionary,
|
|
241
241
|
* formats the gate, and returns the corresponding SVG element.
|
|
242
242
|
*
|
|
243
243
|
* @param gateDictionary - The dictionary containing gate operations.
|
|
@@ -255,9 +255,9 @@ const _gate = (
|
|
|
255
255
|
): SVGElement => {
|
|
256
256
|
const gate = gateDictionary[type];
|
|
257
257
|
if (gate == null) throw new Error(`Gate ${type} not available`);
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
const gateElem = formatGate(
|
|
258
|
+
const renderData = toRenderData(gate, x, y);
|
|
259
|
+
renderData.dataAttributes = { type: type };
|
|
260
|
+
const gateElem = formatGate(renderData).cloneNode(true) as SVGElement;
|
|
261
261
|
gateElem.setAttribute("toolbox-item", "true");
|
|
262
262
|
|
|
263
263
|
return gateElem;
|
|
@@ -322,7 +322,6 @@ const toolboxGateDictionary: GateDictionary = {
|
|
|
322
322
|
H: _makeUnitary("H"),
|
|
323
323
|
SX: _makeUnitary("SX"),
|
|
324
324
|
Reset: _makeKet("0"),
|
|
325
|
-
ResetOne: _makeKet("1"),
|
|
326
325
|
Measure: _makeMeasurement("Measure"),
|
|
327
326
|
};
|
|
328
327
|
|
|
@@ -330,4 +329,4 @@ toolboxGateDictionary["RX"].params = [{ name: "theta", type: "Double" }];
|
|
|
330
329
|
toolboxGateDictionary["RY"].params = [{ name: "theta", type: "Double" }];
|
|
331
330
|
toolboxGateDictionary["RZ"].params = [{ name: "theta", type: "Double" }];
|
|
332
331
|
|
|
333
|
-
export { createPanel, toolboxGateDictionary,
|
|
332
|
+
export { createPanel, toolboxGateDictionary, toRenderData };
|