qsharp-lang 1.25.3-dev → 1.25.5-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 +1 -1
- package/dist/katas-content.generated.md.js +1 -1
- package/docs/Microsoft.Quantum.Core/IsRangeEmpty.md +1 -1
- package/docs/Microsoft.Quantum.Core/Length.md +1 -1
- package/docs/Microsoft.Quantum.Core/RangeEnd.md +1 -1
- package/docs/Microsoft.Quantum.Core/RangeStart.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 +1 -1
- package/docs/Std.Canon/ApplyOperationPowerCA.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/ApplyQPE.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/MapPauliAxis.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/BigIntAsInt.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/Complex.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/ConfigureQubitLoss.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/SX.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/RoundHalfAwayFromZero.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/IsLossResult.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/MResetZChecked.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/EnableMemoryComputeArchitecture.md +1 -1
- package/docs/Std.ResourceEstimation/EndEstimateCaching.md +1 -1
- package/docs/Std.ResourceEstimation/EndRepeatEstimates.md +1 -1
- package/docs/Std.ResourceEstimation/LeastFrequentlyUsed.md +1 -1
- package/docs/Std.ResourceEstimation/LeastRecentlyUsed.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/nodejs/qsc_wasm.cjs +2 -2
- package/lib/nodejs/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 +2 -1
- package/ux/atoms/index.css +2 -1
- package/ux/atoms/layout.ts +59 -17
- package/ux/circuit-vis/angleExpression.ts +133 -0
- package/ux/circuit-vis/contextMenu.ts +8 -73
- package/ux/circuit-vis/events.ts +41 -1
- package/ux/circuit-vis/formatters/inputFormatter.ts +14 -6
- package/ux/circuit-vis/index.ts +12 -4
- package/ux/circuit-vis/panel.ts +65 -28
- package/ux/circuit-vis/sqore.ts +30 -16
- package/ux/circuit-vis/state-viz/stateViz.ts +763 -0
- package/ux/circuit-vis/state-viz/stateVizController.ts +285 -0
- package/ux/circuit-vis/state-viz/worker/index.ts +18 -0
- package/ux/circuit-vis/state-viz/worker/stateCompute.ts +260 -0
- package/ux/circuit-vis/state-viz/worker/stateVizPrep.ts +152 -0
- package/ux/circuit.tsx +17 -28
- package/ux/data.ts +5 -3
- package/ux/histogram.tsx +11 -5
- package/ux/index.ts +2 -0
- package/ux/qdk-theme.css +15 -0
- package/ux/qsharp-circuit.css +311 -1
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
|
|
4
|
+
// State visualization controller for the circuit side panel.
|
|
5
|
+
// Responsible for: ensuring the state panel exists, coordinating async state
|
|
6
|
+
// computation + rendering, suppressing stale renders, and managing the loading
|
|
7
|
+
// spinner/dev toolbar wiring.
|
|
8
|
+
|
|
9
|
+
// Here is a general overview of the flow for the state visualization:
|
|
10
|
+
// panel.ts
|
|
11
|
+
// └─ ensureStateVisualization(...)
|
|
12
|
+
// └─ stateVizController.ts (loading spinner, request-id cancellation, retries)
|
|
13
|
+
// ├─ computeStateVizColumnsFromCurrentModelAsync(...)
|
|
14
|
+
// │ ├─ getCurrentCircuitModel(...) from events.ts
|
|
15
|
+
// │ ├─ if compute callback is provided (via DrawOptions.editor):
|
|
16
|
+
// │ │ computeStateVizColumnsForCircuitModel(...)
|
|
17
|
+
// │ │ (e.g., VS Code webview uses a Web Worker)
|
|
18
|
+
// │ │ └─ editor.tsx → stateComputeWorker.ts
|
|
19
|
+
// │ │ ├─ uses state-viz/worker/stateCompute.ts (compute ampMap)
|
|
20
|
+
// │ │ └─ uses state-viz/worker/stateVizPrep.ts (prep columns)
|
|
21
|
+
// │ └─ else fallback (main thread):
|
|
22
|
+
// │ ├─ state-viz/worker/stateCompute.ts (compute ampMap)
|
|
23
|
+
// │ └─ state-viz/worker/stateVizPrep.ts (prep columns)
|
|
24
|
+
// └─ updateStatePanelFromColumns(...) (render)
|
|
25
|
+
// stateViz.ts
|
|
26
|
+
|
|
27
|
+
import {
|
|
28
|
+
createStatePanel,
|
|
29
|
+
updateStatePanelFromColumns,
|
|
30
|
+
renderBlankStatePanel,
|
|
31
|
+
renderMessageStatePanel,
|
|
32
|
+
setStatePanelLoading,
|
|
33
|
+
} from "./stateViz.js";
|
|
34
|
+
|
|
35
|
+
import { getCurrentCircuitModel } from "../events.js";
|
|
36
|
+
import type { Circuit } from "../circuit.js";
|
|
37
|
+
import {
|
|
38
|
+
computeAmpMapForCircuit,
|
|
39
|
+
UnsupportedStateComputeError,
|
|
40
|
+
} from "./worker/stateCompute.js";
|
|
41
|
+
import {
|
|
42
|
+
prepareStateVizColumnsFromAmpMap,
|
|
43
|
+
type PrepareStateVizOptions,
|
|
44
|
+
} from "./worker/stateVizPrep.js";
|
|
45
|
+
import type { StateColumn } from "./stateViz.js";
|
|
46
|
+
|
|
47
|
+
const DEFAULT_MIN_PROB_THRESHOLD = 0.0;
|
|
48
|
+
const MAX_QUBITS_FOR_STATE_VIZ = 20;
|
|
49
|
+
|
|
50
|
+
type StateVizController = {
|
|
51
|
+
requestRenderState: () => void;
|
|
52
|
+
setComputeCallback: (cb?: ComputeStateVizColumnsForCircuitModel) => void;
|
|
53
|
+
setHostContainer: (container: HTMLElement) => void;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
type ComputeStateVizColumnsForCircuitModel = (
|
|
57
|
+
model: Circuit,
|
|
58
|
+
opts?: PrepareStateVizOptions,
|
|
59
|
+
) => Promise<StateColumn[]>;
|
|
60
|
+
|
|
61
|
+
export function ensureStateVisualization(
|
|
62
|
+
container: HTMLElement,
|
|
63
|
+
computeStateVizColumnsForCircuitModel?: ComputeStateVizColumnsForCircuitModel,
|
|
64
|
+
): void {
|
|
65
|
+
// Ensure a right-side state panel exists.
|
|
66
|
+
if (container.querySelector(".state-panel") == null) {
|
|
67
|
+
const statePanel = createStatePanel();
|
|
68
|
+
container.appendChild(statePanel);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const panelElem = container.querySelector(
|
|
72
|
+
".state-panel",
|
|
73
|
+
) as HTMLElement | null;
|
|
74
|
+
if (!panelElem) return;
|
|
75
|
+
|
|
76
|
+
const existingController = (panelElem as any)._stateVizController as
|
|
77
|
+
| StateVizController
|
|
78
|
+
| undefined;
|
|
79
|
+
|
|
80
|
+
if (existingController) {
|
|
81
|
+
// Sqore calls createPanel() on every edit (it re-renders the SVG). Keep a
|
|
82
|
+
// single state-viz controller per panel element so in-flight renders from
|
|
83
|
+
// previous calls can't toggle loading off underneath new renders.
|
|
84
|
+
existingController.setHostContainer(container);
|
|
85
|
+
existingController.setComputeCallback(
|
|
86
|
+
computeStateVizColumnsForCircuitModel,
|
|
87
|
+
);
|
|
88
|
+
existingController.requestRenderState();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Captured, mutable inputs that can be updated by future calls to
|
|
93
|
+
// ensureStateVisualization(...).
|
|
94
|
+
let hostContainer: HTMLElement = container;
|
|
95
|
+
let computeCallback: ComputeStateVizColumnsForCircuitModel | undefined =
|
|
96
|
+
computeStateVizColumnsForCircuitModel;
|
|
97
|
+
|
|
98
|
+
let renderRequestId = 0;
|
|
99
|
+
let loadingTimer: number | null = null;
|
|
100
|
+
let hideLoadingTimer: number | null = null;
|
|
101
|
+
let activeLoadingRequestId = 0;
|
|
102
|
+
let loadingShownAtMs = 0;
|
|
103
|
+
|
|
104
|
+
const clearLoadingTimer = () => {
|
|
105
|
+
if (loadingTimer != null) {
|
|
106
|
+
clearTimeout(loadingTimer);
|
|
107
|
+
loadingTimer = null;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const clearHideLoadingTimer = () => {
|
|
112
|
+
if (hideLoadingTimer != null) {
|
|
113
|
+
clearTimeout(hideLoadingTimer);
|
|
114
|
+
hideLoadingTimer = null;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const beginLoadingForRequest = (requestId: number) => {
|
|
119
|
+
// Always point loading at the newest request.
|
|
120
|
+
activeLoadingRequestId = requestId;
|
|
121
|
+
clearLoadingTimer();
|
|
122
|
+
clearHideLoadingTimer();
|
|
123
|
+
|
|
124
|
+
// If we're already showing loading (e.g., rapid edits), keep it on.
|
|
125
|
+
if (panelElem.classList.contains("loading")) return;
|
|
126
|
+
|
|
127
|
+
// Avoid flicker for fast computations by delaying the spinner.
|
|
128
|
+
loadingTimer = setTimeout(() => {
|
|
129
|
+
if (activeLoadingRequestId !== requestId) return;
|
|
130
|
+
loadingShownAtMs = performance.now();
|
|
131
|
+
setStatePanelLoading(panelElem, true);
|
|
132
|
+
}, 200) as unknown as number;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const endLoadingForRequest = (requestId: number) => {
|
|
136
|
+
if (activeLoadingRequestId !== requestId) return;
|
|
137
|
+
clearLoadingTimer();
|
|
138
|
+
|
|
139
|
+
// If loading was never shown (fast compute), there's nothing to hide.
|
|
140
|
+
if (!panelElem.classList.contains("loading")) {
|
|
141
|
+
activeLoadingRequestId = 0;
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Avoid flicker: once visible, keep loading on briefly, and debounce the
|
|
146
|
+
// hide so rapid successive edits don't flash the spinner.
|
|
147
|
+
const minVisibleMs = 250;
|
|
148
|
+
const hideDebounceMs = 150;
|
|
149
|
+
const elapsed = performance.now() - (loadingShownAtMs || 0);
|
|
150
|
+
const remainingVisible = Math.max(0, minVisibleMs - elapsed);
|
|
151
|
+
|
|
152
|
+
clearHideLoadingTimer();
|
|
153
|
+
hideLoadingTimer = setTimeout(() => {
|
|
154
|
+
if (activeLoadingRequestId !== requestId) return;
|
|
155
|
+
activeLoadingRequestId = 0;
|
|
156
|
+
setStatePanelLoading(panelElem, false);
|
|
157
|
+
}, remainingVisible + hideDebounceMs) as unknown as number;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const renderState = async (panel: HTMLElement): Promise<void> => {
|
|
161
|
+
const requestId = ++renderRequestId;
|
|
162
|
+
|
|
163
|
+
try {
|
|
164
|
+
beginLoadingForRequest(requestId);
|
|
165
|
+
|
|
166
|
+
// If we were previously showing a message (e.g., unsupported/too many
|
|
167
|
+
// qubits), clear it immediately so the loading overlay can be shown while
|
|
168
|
+
// the new request is computing.
|
|
169
|
+
if (panel.classList.contains("message")) {
|
|
170
|
+
renderBlankStatePanel(panel);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Determine current wire count and SVG for this render from the DOM.
|
|
174
|
+
const circuitSvg = hostContainer.querySelector(
|
|
175
|
+
"svg.qviz",
|
|
176
|
+
) as SVGElement | null;
|
|
177
|
+
|
|
178
|
+
const columns = await computeStateVizColumnsFromCurrentModelAsync(
|
|
179
|
+
{
|
|
180
|
+
minProbThreshold: DEFAULT_MIN_PROB_THRESHOLD,
|
|
181
|
+
},
|
|
182
|
+
circuitSvg,
|
|
183
|
+
computeCallback,
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
// Ignore late results if a newer render request started.
|
|
187
|
+
if (requestId !== renderRequestId) return;
|
|
188
|
+
|
|
189
|
+
if (columns == null) {
|
|
190
|
+
// Model isn't ready for this render yet (events not enabled), or the
|
|
191
|
+
// model corresponds to a different SVG (during a re-render). Keep the
|
|
192
|
+
// panel blank for non-empty circuits so the loading overlay can show;
|
|
193
|
+
// show a message state only when the circuit is truly empty.
|
|
194
|
+
const wiresGroup = circuitSvg?.querySelector(".wires");
|
|
195
|
+
const wireCount = wiresGroup ? wiresGroup.children.length : 0;
|
|
196
|
+
if (wireCount <= 0) {
|
|
197
|
+
renderMessageStatePanel(panel);
|
|
198
|
+
} else {
|
|
199
|
+
renderBlankStatePanel(panel);
|
|
200
|
+
}
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (columns.length > 0) {
|
|
205
|
+
updateStatePanelFromColumns(panel, columns);
|
|
206
|
+
} else {
|
|
207
|
+
// Empty model: show a message state.
|
|
208
|
+
renderMessageStatePanel(panel);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return;
|
|
212
|
+
} catch (e) {
|
|
213
|
+
// Ignore cancellation from host worker termination.
|
|
214
|
+
if (requestId !== renderRequestId) return;
|
|
215
|
+
|
|
216
|
+
const err = e as Error;
|
|
217
|
+
if (err?.name === "AbortError") {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (err?.name === "UnsupportedStateComputeError") {
|
|
221
|
+
renderMessageStatePanel(panel, err.message);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
renderMessageStatePanel(
|
|
225
|
+
panel,
|
|
226
|
+
"State visualization is unavailable for this circuit.",
|
|
227
|
+
);
|
|
228
|
+
return;
|
|
229
|
+
} finally {
|
|
230
|
+
endLoadingForRequest(requestId);
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const requestRenderState = () => {
|
|
235
|
+
void renderState(panelElem);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
(panelElem as any)._stateVizController = {
|
|
239
|
+
requestRenderState,
|
|
240
|
+
setComputeCallback: (cb?: ComputeStateVizColumnsForCircuitModel) => {
|
|
241
|
+
computeCallback = cb;
|
|
242
|
+
},
|
|
243
|
+
setHostContainer: (c: HTMLElement) => {
|
|
244
|
+
hostContainer = c;
|
|
245
|
+
},
|
|
246
|
+
} satisfies StateVizController;
|
|
247
|
+
|
|
248
|
+
// Re-render when the circuit model becomes available. The circuit SVG is
|
|
249
|
+
// replaced before `enableEvents(...)` runs, so computing state immediately in
|
|
250
|
+
// `createPanel(...)` would otherwise risk using a stale model.
|
|
251
|
+
try {
|
|
252
|
+
container.addEventListener("qsharp:circuit:modelReady", () => {
|
|
253
|
+
requestRenderState();
|
|
254
|
+
});
|
|
255
|
+
} catch {
|
|
256
|
+
// ignore
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Initial render.
|
|
260
|
+
void renderState(panelElem);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
async function computeStateVizColumnsFromCurrentModelAsync(
|
|
264
|
+
opts: PrepareStateVizOptions = {},
|
|
265
|
+
expectedCircuitSvg?: SVGElement | null,
|
|
266
|
+
computeStateVizColumnsForCircuitModel?: ComputeStateVizColumnsForCircuitModel,
|
|
267
|
+
): Promise<StateColumn[] | null> {
|
|
268
|
+
const model = getCurrentCircuitModel(expectedCircuitSvg);
|
|
269
|
+
if (!model) return null;
|
|
270
|
+
if (model.qubits.length === 0) return [];
|
|
271
|
+
|
|
272
|
+
if (model.qubits.length > MAX_QUBITS_FOR_STATE_VIZ) {
|
|
273
|
+
throw new UnsupportedStateComputeError(
|
|
274
|
+
`Too many qubits for state visualization (limit: ${MAX_QUBITS_FOR_STATE_VIZ}). This circuit has ${model.qubits.length} qubits.`,
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (computeStateVizColumnsForCircuitModel) {
|
|
279
|
+
return await computeStateVizColumnsForCircuitModel(model, opts);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Fallback: compute and prepare on the main thread.
|
|
283
|
+
const ampMap = computeAmpMapForCircuit(model.qubits, model.componentGrid);
|
|
284
|
+
return prepareStateVizColumnsFromAmpMap(ampMap as any, opts);
|
|
285
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
// Worker-safe exports for state visualization.
|
|
5
|
+
// Intentionally avoids importing UI modules (DOM/CSS).
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
computeAmpMapForCircuit,
|
|
9
|
+
UnsupportedStateComputeError,
|
|
10
|
+
type AmpMap,
|
|
11
|
+
} from "./stateCompute.js";
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
prepareStateVizColumnsFromAmpMap,
|
|
15
|
+
type PrepareStateVizOptions,
|
|
16
|
+
} from "./stateVizPrep.js";
|
|
17
|
+
|
|
18
|
+
export type { Circuit as CircuitModel } from "../../circuit.js";
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
|
|
4
|
+
// Core state computation for circuit-vis.
|
|
5
|
+
// Implements a small statevector simulator that evaluates the circuit model and
|
|
6
|
+
// produces an amplitude map. Intentionally avoids DOM/visualization concerns so
|
|
7
|
+
// it can run on the main thread or in a Web Worker.
|
|
8
|
+
|
|
9
|
+
import type { ComponentGrid, Operation, Qubit } from "../../circuit.js";
|
|
10
|
+
import { evaluateAngleExpression } from "../../angleExpression.js";
|
|
11
|
+
|
|
12
|
+
// This holds the complex amplitudes of the different basis states.
|
|
13
|
+
export type AmpMap = Record<string, { re: number; im: number }>;
|
|
14
|
+
|
|
15
|
+
export class UnsupportedStateComputeError extends Error {
|
|
16
|
+
constructor(message: string) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = "UnsupportedStateComputeError";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Small complex helpers
|
|
23
|
+
class Complex {
|
|
24
|
+
constructor(
|
|
25
|
+
public re: number,
|
|
26
|
+
public im: number,
|
|
27
|
+
) {}
|
|
28
|
+
static add(a: Complex, b: Complex) {
|
|
29
|
+
return new Complex(a.re + b.re, a.im + b.im);
|
|
30
|
+
}
|
|
31
|
+
static mul(a: Complex, b: Complex) {
|
|
32
|
+
return new Complex(a.re * b.re - a.im * b.im, a.re * b.im + a.im * b.re);
|
|
33
|
+
}
|
|
34
|
+
static conj(a: Complex) {
|
|
35
|
+
return new Complex(a.re, -a.im);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function adjointMat2(mat: Complex[]): Complex[] {
|
|
40
|
+
// 2x2 matrix stored as [m00, m01, m10, m11].
|
|
41
|
+
// Adjoint is conjugate transpose: [[conj(m00), conj(m10)], [conj(m01), conj(m11)]].
|
|
42
|
+
return [
|
|
43
|
+
Complex.conj(mat[0]),
|
|
44
|
+
Complex.conj(mat[2]),
|
|
45
|
+
Complex.conj(mat[1]),
|
|
46
|
+
Complex.conj(mat[3]),
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Matrices for single-qubit gates
|
|
51
|
+
const GATE = {
|
|
52
|
+
X: [
|
|
53
|
+
new Complex(0, 0),
|
|
54
|
+
new Complex(1, 0),
|
|
55
|
+
new Complex(1, 0),
|
|
56
|
+
new Complex(0, 0),
|
|
57
|
+
],
|
|
58
|
+
Y: [
|
|
59
|
+
new Complex(0, 0),
|
|
60
|
+
new Complex(0, -1),
|
|
61
|
+
new Complex(0, 1),
|
|
62
|
+
new Complex(0, 0),
|
|
63
|
+
],
|
|
64
|
+
Z: [
|
|
65
|
+
new Complex(1, 0),
|
|
66
|
+
new Complex(0, 0),
|
|
67
|
+
new Complex(0, 0),
|
|
68
|
+
new Complex(-1, 0),
|
|
69
|
+
],
|
|
70
|
+
H: [
|
|
71
|
+
new Complex(Math.SQRT1_2, 0),
|
|
72
|
+
new Complex(Math.SQRT1_2, 0),
|
|
73
|
+
new Complex(Math.SQRT1_2, 0),
|
|
74
|
+
new Complex(-Math.SQRT1_2, 0),
|
|
75
|
+
],
|
|
76
|
+
S: [
|
|
77
|
+
new Complex(1, 0),
|
|
78
|
+
new Complex(0, 0),
|
|
79
|
+
new Complex(0, 0),
|
|
80
|
+
new Complex(0, 1),
|
|
81
|
+
], // [[1,0],[0,i]]
|
|
82
|
+
T: [
|
|
83
|
+
new Complex(1, 0),
|
|
84
|
+
new Complex(0, 0),
|
|
85
|
+
new Complex(0, 0),
|
|
86
|
+
new Complex(Math.SQRT1_2, Math.SQRT1_2),
|
|
87
|
+
],
|
|
88
|
+
SX: [
|
|
89
|
+
// sqrt(X)
|
|
90
|
+
new Complex(0.5, 0.5),
|
|
91
|
+
new Complex(0.5, -0.5),
|
|
92
|
+
new Complex(0.5, -0.5),
|
|
93
|
+
new Complex(0.5, 0.5),
|
|
94
|
+
],
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
function rotationX(theta: number) {
|
|
98
|
+
const c = Math.cos(theta / 2);
|
|
99
|
+
const s = Math.sin(theta / 2);
|
|
100
|
+
return [
|
|
101
|
+
new Complex(c, 0),
|
|
102
|
+
new Complex(0, -s),
|
|
103
|
+
new Complex(0, -s),
|
|
104
|
+
new Complex(c, 0),
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
function rotationY(theta: number) {
|
|
108
|
+
const c = Math.cos(theta / 2);
|
|
109
|
+
const s = Math.sin(theta / 2);
|
|
110
|
+
return [
|
|
111
|
+
new Complex(c, 0),
|
|
112
|
+
new Complex(-s, 0),
|
|
113
|
+
new Complex(s, 0),
|
|
114
|
+
new Complex(c, 0),
|
|
115
|
+
];
|
|
116
|
+
}
|
|
117
|
+
function rotationZ(theta: number) {
|
|
118
|
+
const eNeg = new Complex(Math.cos(-theta / 2), Math.sin(-theta / 2));
|
|
119
|
+
const ePos = new Complex(Math.cos(theta / 2), Math.sin(theta / 2));
|
|
120
|
+
return [eNeg, new Complex(0, 0), new Complex(0, 0), ePos];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function parseTheta(op: Operation): number | undefined {
|
|
124
|
+
const arg = op.args?.[0];
|
|
125
|
+
if (!arg) return undefined;
|
|
126
|
+
const v = evaluateAngleExpression(arg);
|
|
127
|
+
return v;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function applySingleQubit(
|
|
131
|
+
state: Complex[],
|
|
132
|
+
target: number,
|
|
133
|
+
mat: Complex[],
|
|
134
|
+
controls: number[] = [],
|
|
135
|
+
): void {
|
|
136
|
+
const N = state.length;
|
|
137
|
+
const mask = 1 << target;
|
|
138
|
+
for (let i = 0; i < N; i += 2 * mask) {
|
|
139
|
+
for (let j = 0; j < mask; j++) {
|
|
140
|
+
const i0 = i + j;
|
|
141
|
+
const i1 = i + j + mask;
|
|
142
|
+
const okControls = controls.every((c) => ((i0 >> c) & 1) === 1);
|
|
143
|
+
if (!okControls) continue;
|
|
144
|
+
const a0 = state[i0];
|
|
145
|
+
const a1 = state[i1];
|
|
146
|
+
const n0 = Complex.add(Complex.mul(mat[0], a0), Complex.mul(mat[1], a1));
|
|
147
|
+
const n1 = Complex.add(Complex.mul(mat[2], a0), Complex.mul(mat[3], a1));
|
|
148
|
+
state[i0] = n0;
|
|
149
|
+
state[i1] = n1;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function computeAmpMapForCircuit(
|
|
155
|
+
qubits: Qubit[],
|
|
156
|
+
componentGrid: ComponentGrid,
|
|
157
|
+
): AmpMap {
|
|
158
|
+
const n = qubits.length;
|
|
159
|
+
if (n === 0) return {};
|
|
160
|
+
const dim = 1 << n;
|
|
161
|
+
const state: Complex[] = new Array(dim);
|
|
162
|
+
for (let i = 0; i < dim; i++) state[i] = new Complex(0, 0);
|
|
163
|
+
state[0] = new Complex(1, 0);
|
|
164
|
+
|
|
165
|
+
for (const col of componentGrid) {
|
|
166
|
+
for (const op of col.components) {
|
|
167
|
+
switch (op.kind) {
|
|
168
|
+
case "unitary": {
|
|
169
|
+
const targetQubits = op.targets.map((r) => r.qubit);
|
|
170
|
+
const controls = (op.controls ?? []).map((r) => r.qubit);
|
|
171
|
+
const isAdjoint = op.isAdjoint ?? false;
|
|
172
|
+
if (targetQubits.length !== 1) {
|
|
173
|
+
// Unsupported multi-qubit unitary: skip
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
const t = targetQubits[0];
|
|
177
|
+
let mat: Complex[] | undefined;
|
|
178
|
+
switch (op.gate) {
|
|
179
|
+
case "X":
|
|
180
|
+
mat = GATE.X;
|
|
181
|
+
break;
|
|
182
|
+
case "Y":
|
|
183
|
+
mat = GATE.Y;
|
|
184
|
+
break;
|
|
185
|
+
case "Z":
|
|
186
|
+
mat = GATE.Z;
|
|
187
|
+
break;
|
|
188
|
+
case "H":
|
|
189
|
+
mat = GATE.H;
|
|
190
|
+
break;
|
|
191
|
+
case "S":
|
|
192
|
+
mat = GATE.S;
|
|
193
|
+
break;
|
|
194
|
+
case "T":
|
|
195
|
+
mat = GATE.T;
|
|
196
|
+
break;
|
|
197
|
+
case "SX":
|
|
198
|
+
mat = GATE.SX;
|
|
199
|
+
break;
|
|
200
|
+
case "Rx": {
|
|
201
|
+
const th = parseTheta(op);
|
|
202
|
+
if (th !== undefined) mat = rotationX(th);
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
case "Ry": {
|
|
206
|
+
const th = parseTheta(op);
|
|
207
|
+
if (th !== undefined) mat = rotationY(th);
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
case "Rz": {
|
|
211
|
+
const th = parseTheta(op);
|
|
212
|
+
if (th !== undefined) mat = rotationZ(th);
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
default:
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
if (mat) {
|
|
219
|
+
mat = isAdjoint ? adjointMat2(mat) : mat;
|
|
220
|
+
applySingleQubit(state, t, mat, controls);
|
|
221
|
+
}
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
case "ket": {
|
|
225
|
+
// Reset is non-unitary and generally produces mixed states.
|
|
226
|
+
// The state visualizer currently only supports pure state vectors.
|
|
227
|
+
if (op.gate === "0") {
|
|
228
|
+
throw new UnsupportedStateComputeError(
|
|
229
|
+
"State visualization does not currently support measurement or ResetZ / |0⟩ reset operations.",
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
case "measurement": {
|
|
235
|
+
// Measurement is non-unitary and generally produces mixed states.
|
|
236
|
+
// The state visualizer currently only supports pure state vectors.
|
|
237
|
+
throw new UnsupportedStateComputeError(
|
|
238
|
+
"State visualization does not currently support measurement or ResetZ / |0⟩ reset operations.",
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const ampMap: AmpMap = {};
|
|
246
|
+
const eps = 1e-12;
|
|
247
|
+
for (let i = 0; i < dim; i++) {
|
|
248
|
+
const a = state[i];
|
|
249
|
+
const p = a.re * a.re + a.im * a.im;
|
|
250
|
+
if (p > eps) {
|
|
251
|
+
// Build bitstring label (editor qubit 0 is the most significant/leftmost bit)
|
|
252
|
+
let bits = "";
|
|
253
|
+
for (let q = 0; q < n; q++) {
|
|
254
|
+
bits += (i >> q) & 1 ? "1" : "0";
|
|
255
|
+
}
|
|
256
|
+
ampMap[bits] = { re: a.re, im: a.im };
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return ampMap;
|
|
260
|
+
}
|