qsharp-lang 1.15.0 → 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/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
package/dist/browser.d.ts
CHANGED
|
@@ -24,4 +24,4 @@ export { default as samples } from "./samples.generated.js";
|
|
|
24
24
|
export { log, type LogLevel, type TargetProfile };
|
|
25
25
|
export type { ICompiler, ICompilerWorker, IDebugService, IDebugServiceWorker, ILanguageService, ILanguageServiceWorker, };
|
|
26
26
|
export * as utils from "./utils.js";
|
|
27
|
-
export type {
|
|
27
|
+
export type { CircuitGroup as CircuitData } from "./shared/circuit.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type CircuitGroup as CircuitData } from "../shared/circuit.js";
|
|
2
2
|
import { IDocFile, IOperationInfo, IPackageGraphSources, IProgramConfig as wasmIProgramConfig, TargetProfile, type VSDiagnostic } from "../../lib/web/qsc_wasm.js";
|
|
3
3
|
import { IServiceProxy, ServiceProtocol, ServiceState } from "../workers/common.js";
|
|
4
4
|
import { IQscEventTarget, QscEventData } from "./events.js";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
|
+
import { CURRENT_VERSION, } from "../shared/circuit.js";
|
|
3
4
|
import { log } from "../log.js";
|
|
4
5
|
import { eventStringToMsg } from "./common.js";
|
|
5
6
|
import { makeEvent, } from "./events.js";
|
|
@@ -59,7 +60,11 @@ export class Compiler {
|
|
|
59
60
|
return this.wasm.get_estimates(toWasmProgramConfig(program, "unrestricted"), expr, params);
|
|
60
61
|
}
|
|
61
62
|
async getCircuit(program, simulate, operation) {
|
|
62
|
-
|
|
63
|
+
const circuit = this.wasm.get_circuit(toWasmProgramConfig(program, "unrestricted"), simulate, operation);
|
|
64
|
+
return {
|
|
65
|
+
circuits: [circuit],
|
|
66
|
+
version: CURRENT_VERSION,
|
|
67
|
+
};
|
|
63
68
|
}
|
|
64
69
|
// Returns all autogenerated documentation files for the standard library
|
|
65
70
|
// and loaded project (if requested). This include file names and metadata,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type CircuitGroup as CircuitData } from "../shared/circuit.js";
|
|
2
2
|
import type { IBreakpointSpan, IQuantumState, IStackFrame, IStructStepResult, IVariable } from "../../lib/web/qsc_wasm.js";
|
|
3
3
|
import { ProgramConfig } from "../browser.js";
|
|
4
4
|
import { IQscEventTarget, QscEventData } from "../compiler/events.js";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
|
+
import { CURRENT_VERSION, } from "../shared/circuit.js";
|
|
3
4
|
import { eventStringToMsg } from "../compiler/common.js";
|
|
4
5
|
import { makeEvent, } from "../compiler/events.js";
|
|
5
6
|
import { log } from "../log.js";
|
|
@@ -25,7 +26,11 @@ export class QSharpDebugService {
|
|
|
25
26
|
return state.entries;
|
|
26
27
|
}
|
|
27
28
|
async getCircuit() {
|
|
28
|
-
|
|
29
|
+
const circuit = this.debugService.get_circuit();
|
|
30
|
+
return {
|
|
31
|
+
circuits: [circuit],
|
|
32
|
+
version: CURRENT_VERSION,
|
|
33
|
+
};
|
|
29
34
|
}
|
|
30
35
|
async getStackFrames() {
|
|
31
36
|
return this.debugService.get_stack_frames().frames;
|
|
@@ -1666,7 +1666,7 @@ export default {
|
|
|
1666
1666
|
{
|
|
1667
1667
|
"type": "example",
|
|
1668
1668
|
"id": "multi_qubit_systems__multi_qubit_systems_demo",
|
|
1669
|
-
"code": "namespace Kata {\n import Std.Diagnostics.*;\n\n @EntryPoint()\n operation MultiQubitSystemsDemo() : Unit {\n // This allocates an array of 2 qubits, each of them in state |0⟩.\n // The overall state of the system is |00⟩.\n use qs = Qubit[2];\n // X gate changes the first qubit into state |1⟩.\n X(qs[0]);\n Message(\"The system in now in state |10⟩:\");\n DumpMachine();\n\n // This changes the second qubit into state |+⟩ = (1/sqrt(2))(|0⟩ + |1⟩).\n H(qs[1]);\n Message(\"The system in now in state (1/sqrt(2))(|10⟩ + |11⟩):\");\n DumpMachine();\n\n // This changes the first qubit into state |-⟩ = (1/sqrt(2))(|0⟩ - |1⟩)\n H(qs[0]);\n Message(\"The system in now in state 0.5(|00⟩ + |01⟩ - |10⟩ - |11⟩):\");\n DumpMachine();\n\n // The next lines entangle the qubits (don't worry about what exactly they do for now).\n H(qs[1]);\n CNOT(qs[0], qs[1]);\n Message(\"The system in now in entangled state
|
|
1669
|
+
"code": "namespace Kata {\n import Std.Diagnostics.*;\n\n @EntryPoint()\n operation MultiQubitSystemsDemo() : Unit {\n // This allocates an array of 2 qubits, each of them in state |0⟩.\n // The overall state of the system is |00⟩.\n use qs = Qubit[2];\n // X gate changes the first qubit into state |1⟩.\n X(qs[0]);\n Message(\"The system in now in state |10⟩:\");\n DumpMachine();\n\n // This changes the second qubit into state |+⟩ = (1/sqrt(2))(|0⟩ + |1⟩).\n H(qs[1]);\n Message(\"The system in now in state (1/sqrt(2))(|10⟩ + |11⟩):\");\n DumpMachine();\n\n // This changes the first qubit into state |-⟩ = (1/sqrt(2))(|0⟩ - |1⟩)\n H(qs[0]);\n Message(\"The system in now in state 0.5(|00⟩ + |01⟩ - |10⟩ - |11⟩):\");\n DumpMachine();\n\n // The next lines entangle the qubits (don't worry about what exactly they do for now).\n H(qs[1]);\n CNOT(qs[0], qs[1]);\n Message(\"The system in now in entangled state (1/sqrt(2))(|00⟩ - |11⟩):\");\n DumpMachine();\n\n // This returns the system into state |00⟩.\n ResetAll(qs);\n }\n}\n"
|
|
1670
1670
|
},
|
|
1671
1671
|
{
|
|
1672
1672
|
"type": "text-content",
|
|
@@ -1666,7 +1666,7 @@ export default {
|
|
|
1666
1666
|
{
|
|
1667
1667
|
"type": "example",
|
|
1668
1668
|
"id": "multi_qubit_systems__multi_qubit_systems_demo",
|
|
1669
|
-
"code": "namespace Kata {\n import Std.Diagnostics.*;\n\n @EntryPoint()\n operation MultiQubitSystemsDemo() : Unit {\n // This allocates an array of 2 qubits, each of them in state |0⟩.\n // The overall state of the system is |00⟩.\n use qs = Qubit[2];\n // X gate changes the first qubit into state |1⟩.\n X(qs[0]);\n Message(\"The system in now in state |10⟩:\");\n DumpMachine();\n\n // This changes the second qubit into state |+⟩ = (1/sqrt(2))(|0⟩ + |1⟩).\n H(qs[1]);\n Message(\"The system in now in state (1/sqrt(2))(|10⟩ + |11⟩):\");\n DumpMachine();\n\n // This changes the first qubit into state |-⟩ = (1/sqrt(2))(|0⟩ - |1⟩)\n H(qs[0]);\n Message(\"The system in now in state 0.5(|00⟩ + |01⟩ - |10⟩ - |11⟩):\");\n DumpMachine();\n\n // The next lines entangle the qubits (don't worry about what exactly they do for now).\n H(qs[1]);\n CNOT(qs[0], qs[1]);\n Message(\"The system in now in entangled state
|
|
1669
|
+
"code": "namespace Kata {\n import Std.Diagnostics.*;\n\n @EntryPoint()\n operation MultiQubitSystemsDemo() : Unit {\n // This allocates an array of 2 qubits, each of them in state |0⟩.\n // The overall state of the system is |00⟩.\n use qs = Qubit[2];\n // X gate changes the first qubit into state |1⟩.\n X(qs[0]);\n Message(\"The system in now in state |10⟩:\");\n DumpMachine();\n\n // This changes the second qubit into state |+⟩ = (1/sqrt(2))(|0⟩ + |1⟩).\n H(qs[1]);\n Message(\"The system in now in state (1/sqrt(2))(|10⟩ + |11⟩):\");\n DumpMachine();\n\n // This changes the first qubit into state |-⟩ = (1/sqrt(2))(|0⟩ - |1⟩)\n H(qs[0]);\n Message(\"The system in now in state 0.5(|00⟩ + |01⟩ - |10⟩ - |11⟩):\");\n DumpMachine();\n\n // The next lines entangle the qubits (don't worry about what exactly they do for now).\n H(qs[1]);\n CNOT(qs[0], qs[1]);\n Message(\"The system in now in entangled state (1/sqrt(2))(|00⟩ - |11⟩):\");\n DumpMachine();\n\n // This returns the system into state |00⟩.\n ResetAll(qs);\n }\n}\n"
|
|
1670
1670
|
},
|
|
1671
1671
|
{
|
|
1672
1672
|
"type": "text-content",
|
package/dist/shared/circuit.d.ts
CHANGED
|
@@ -1,20 +1,103 @@
|
|
|
1
1
|
import { Register } from "./register.js";
|
|
2
|
+
/**
|
|
3
|
+
* Current format version.
|
|
4
|
+
*/
|
|
5
|
+
export declare const CURRENT_VERSION = 1;
|
|
6
|
+
export interface CircuitGroup {
|
|
7
|
+
circuits: Circuit[];
|
|
8
|
+
version: number;
|
|
9
|
+
}
|
|
2
10
|
/**
|
|
3
11
|
* Circuit to be visualized.
|
|
4
12
|
*/
|
|
5
13
|
export interface Circuit {
|
|
6
14
|
/** Array of qubit resources. */
|
|
7
15
|
qubits: Qubit[];
|
|
8
|
-
|
|
16
|
+
componentGrid: ComponentGrid;
|
|
17
|
+
}
|
|
18
|
+
export type ComponentGrid = Column[];
|
|
19
|
+
export interface Column {
|
|
20
|
+
components: Component[];
|
|
9
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Represents a component of a circuit. Currently, the only component is an operation.
|
|
24
|
+
* In the future, this may be extended to include other components.
|
|
25
|
+
*/
|
|
26
|
+
export type Component = Operation;
|
|
10
27
|
/**
|
|
11
28
|
* Represents a unique qubit resource bit.
|
|
12
29
|
*/
|
|
13
30
|
export interface Qubit {
|
|
14
31
|
/** Qubit ID. */
|
|
15
32
|
id: number;
|
|
16
|
-
/** Number of
|
|
17
|
-
|
|
33
|
+
/** Number of measurement results associated to the qubit. */
|
|
34
|
+
numResults?: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Base type for operations.
|
|
38
|
+
*/
|
|
39
|
+
export interface BaseOperation {
|
|
40
|
+
/** Gate label. */
|
|
41
|
+
gate: string;
|
|
42
|
+
/** Formatted gate arguments. */
|
|
43
|
+
args?: string[];
|
|
44
|
+
/** The parameters expected for the operation. */
|
|
45
|
+
params?: Parameter[];
|
|
46
|
+
/** Nested operations within this operation. */
|
|
47
|
+
children?: ComponentGrid;
|
|
48
|
+
/** Custom data attributes to attach to gate element.
|
|
49
|
+
Note that this is never written to file, so it is not part of the circuit schema */
|
|
50
|
+
dataAttributes?: DataAttributes;
|
|
51
|
+
/** Whether gate is a conditional operation. */
|
|
52
|
+
isConditional?: boolean;
|
|
53
|
+
/** Specify conditions on when to render operation. */
|
|
54
|
+
conditionalRender?: ConditionalRender;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Represents a measurement operation and the registers it acts on.
|
|
58
|
+
*/
|
|
59
|
+
export interface Measurement extends BaseOperation {
|
|
60
|
+
/** Discriminator for the Operation type */
|
|
61
|
+
kind: "measurement";
|
|
62
|
+
/** The qubit registers the gate measures. */
|
|
63
|
+
qubits: Register[];
|
|
64
|
+
/** The classical registers the gate writes to. */
|
|
65
|
+
results: Register[];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Represents a unitary operation and the registers it acts on.
|
|
69
|
+
*/
|
|
70
|
+
export interface Unitary extends BaseOperation {
|
|
71
|
+
/** Discriminator for the Operation type */
|
|
72
|
+
kind: "unitary";
|
|
73
|
+
/** Target registers the gate acts on. */
|
|
74
|
+
targets: Register[];
|
|
75
|
+
/** Control registers the gate acts on. */
|
|
76
|
+
controls?: Register[];
|
|
77
|
+
/** Whether gate is an adjoint operation. */
|
|
78
|
+
isAdjoint?: boolean;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Represents a gate that sets its targets to a specific state.
|
|
82
|
+
*/
|
|
83
|
+
export interface Ket extends BaseOperation {
|
|
84
|
+
/** Discriminator for the Operation type */
|
|
85
|
+
kind: "ket";
|
|
86
|
+
/** Target registers the gate acts on. */
|
|
87
|
+
targets: Register[];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Union type for operations.
|
|
91
|
+
*/
|
|
92
|
+
export type Operation = Unitary | Measurement | Ket;
|
|
93
|
+
/**
|
|
94
|
+
* A parameter for an operation.
|
|
95
|
+
*/
|
|
96
|
+
export interface Parameter {
|
|
97
|
+
/** Parameter name. */
|
|
98
|
+
name: string;
|
|
99
|
+
/** Parameter's Q# type. */
|
|
100
|
+
type: string;
|
|
18
101
|
}
|
|
19
102
|
/**
|
|
20
103
|
* Conditions on when to render the given operation.
|
|
@@ -35,30 +118,3 @@ export declare enum ConditionalRender {
|
|
|
35
118
|
export interface DataAttributes {
|
|
36
119
|
[attr: string]: string;
|
|
37
120
|
}
|
|
38
|
-
/**
|
|
39
|
-
* Represents an operation and the registers it acts on.
|
|
40
|
-
*/
|
|
41
|
-
export interface Operation {
|
|
42
|
-
/** Gate label. */
|
|
43
|
-
gate: string;
|
|
44
|
-
/** Formatted gate arguments to be displayed. */
|
|
45
|
-
displayArgs?: string;
|
|
46
|
-
/** Nested operations within this operation. */
|
|
47
|
-
children?: Operation[];
|
|
48
|
-
/** Whether gate is a measurement operation. */
|
|
49
|
-
isMeasurement: boolean;
|
|
50
|
-
/** Whether gate is a conditional operation. */
|
|
51
|
-
isConditional: boolean;
|
|
52
|
-
/** Whether gate is a controlled operation. */
|
|
53
|
-
isControlled: boolean;
|
|
54
|
-
/** Whether gate is an adjoint operation. */
|
|
55
|
-
isAdjoint: boolean;
|
|
56
|
-
/** Control registers the gate acts on. */
|
|
57
|
-
controls?: Register[];
|
|
58
|
-
/** Target registers the gate acts on. */
|
|
59
|
-
targets: Register[];
|
|
60
|
-
/** Specify conditions on when to render operation. */
|
|
61
|
-
conditionalRender?: ConditionalRender;
|
|
62
|
-
/** Custom data attributes to attach to gate element. */
|
|
63
|
-
dataAttributes?: DataAttributes;
|
|
64
|
-
}
|
package/dist/shared/circuit.js
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CircuitGroup } from "./circuit.js";
|
|
2
|
+
/**
|
|
3
|
+
* Ensures that the given circuit object is a CircuitGroup, doing any
|
|
4
|
+
* necessary conversions from Circuit or legacy formats.
|
|
5
|
+
*
|
|
6
|
+
* @param circuit The circuit to convert.
|
|
7
|
+
* @returns The converted CircuitGroup.
|
|
8
|
+
*/
|
|
9
|
+
export declare function toCircuitGroup(circuit: any): CircuitGroup;
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
import { getMinMaxRegIdx } from "../utils.js";
|
|
4
|
+
import { CURRENT_VERSION, } from "./circuit.js";
|
|
5
|
+
/**
|
|
6
|
+
* Ensures that the given circuit object is a CircuitGroup, doing any
|
|
7
|
+
* necessary conversions from Circuit or legacy formats.
|
|
8
|
+
*
|
|
9
|
+
* @param circuit The circuit to convert.
|
|
10
|
+
* @returns The converted CircuitGroup.
|
|
11
|
+
*/
|
|
12
|
+
export function toCircuitGroup(circuit) {
|
|
13
|
+
const emptyCircuit = {
|
|
14
|
+
qubits: [],
|
|
15
|
+
componentGrid: [],
|
|
16
|
+
};
|
|
17
|
+
const emptyCircuitGroup = {
|
|
18
|
+
version: CURRENT_VERSION,
|
|
19
|
+
circuits: [emptyCircuit],
|
|
20
|
+
};
|
|
21
|
+
if (circuit && Object.keys(circuit).length === 0) {
|
|
22
|
+
return emptyCircuitGroup;
|
|
23
|
+
}
|
|
24
|
+
if (circuit?.version) {
|
|
25
|
+
const version = circuit.version;
|
|
26
|
+
// If it has a "version" field, it is up-to-date
|
|
27
|
+
if (isCircuitGroup(circuit)) {
|
|
28
|
+
// If it's already a CircuitGroup, return it as is
|
|
29
|
+
return circuit;
|
|
30
|
+
}
|
|
31
|
+
else if (isCircuit(circuit)) {
|
|
32
|
+
// If it's a Circuit, wrap it in a CircuitGroup
|
|
33
|
+
return {
|
|
34
|
+
version,
|
|
35
|
+
circuits: [circuit],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
console.error("Unknown schema: circuit is neither a CircuitGroup nor a Circuit.");
|
|
40
|
+
return emptyCircuitGroup;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else if (isCircuit(circuit)) {
|
|
44
|
+
// If it's a Circuit without a version, wrap it in a CircuitGroup
|
|
45
|
+
return {
|
|
46
|
+
version: CURRENT_VERSION,
|
|
47
|
+
circuits: [circuit],
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
else if (circuit?.operations) {
|
|
51
|
+
// Legacy schema: convert to CircuitGroup
|
|
52
|
+
if (circuit.qubits === undefined || !Array.isArray(circuit.qubits)) {
|
|
53
|
+
console.error("Unknown schema: circuit is missing qubit information.");
|
|
54
|
+
return emptyCircuitGroup;
|
|
55
|
+
}
|
|
56
|
+
const qubits = circuit.qubits.map((qubit) => {
|
|
57
|
+
return {
|
|
58
|
+
id: qubit.id,
|
|
59
|
+
numResults: qubit.numChildren || 0, // Rename "numChildren" to "numResults"
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
const componentGrid = operationListToGrid(circuit.operations.map(toOperation), qubits.length);
|
|
63
|
+
return {
|
|
64
|
+
version: CURRENT_VERSION,
|
|
65
|
+
circuits: [
|
|
66
|
+
{
|
|
67
|
+
qubits,
|
|
68
|
+
componentGrid,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
console.error("Unknown schema: circuit does not match any known format.");
|
|
75
|
+
return emptyCircuitGroup;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Converts a legacy operation object to the new Operation format.
|
|
80
|
+
*
|
|
81
|
+
* @param op The operation to convert.
|
|
82
|
+
* @returns The converted Operation.
|
|
83
|
+
*/
|
|
84
|
+
function toOperation(op) {
|
|
85
|
+
let targets = [];
|
|
86
|
+
if (op.targets) {
|
|
87
|
+
targets = op.targets.map((t) => {
|
|
88
|
+
return {
|
|
89
|
+
qubit: t.qId,
|
|
90
|
+
result: t.cId,
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
let controls = undefined;
|
|
95
|
+
if (op.controls) {
|
|
96
|
+
controls = op.controls.map((c) => {
|
|
97
|
+
return {
|
|
98
|
+
qubit: c.qId,
|
|
99
|
+
result: c.cId,
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (op.isMeasurement) {
|
|
104
|
+
return {
|
|
105
|
+
...op,
|
|
106
|
+
kind: "measurement",
|
|
107
|
+
qubits: controls || [],
|
|
108
|
+
results: targets,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const ket = getKetLabel(op.gate);
|
|
113
|
+
if (ket.length > 0) {
|
|
114
|
+
return {
|
|
115
|
+
...op,
|
|
116
|
+
kind: "ket",
|
|
117
|
+
gate: ket,
|
|
118
|
+
targets,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
const convertedOp = {
|
|
123
|
+
...op,
|
|
124
|
+
kind: "unitary",
|
|
125
|
+
targets,
|
|
126
|
+
controls,
|
|
127
|
+
};
|
|
128
|
+
if (op.displayArgs) {
|
|
129
|
+
convertedOp.args = [op.displayArgs];
|
|
130
|
+
// Assume the parameter is always "theta" for now
|
|
131
|
+
convertedOp.params = [{ name: "theta", type: "Double" }];
|
|
132
|
+
}
|
|
133
|
+
if (op.children) {
|
|
134
|
+
convertedOp.children = [
|
|
135
|
+
{
|
|
136
|
+
components: op.children.map((child) => toOperation(child)),
|
|
137
|
+
},
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
return convertedOp;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Checks if the given object is a CircuitGroup.
|
|
146
|
+
*
|
|
147
|
+
* @param circuit The object to check.
|
|
148
|
+
* @returns True if the object is a CircuitGroup, false otherwise.
|
|
149
|
+
*/
|
|
150
|
+
function isCircuitGroup(circuit) {
|
|
151
|
+
return circuit && Array.isArray(circuit.circuits);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Checks if the given object is a Circuit.
|
|
155
|
+
*
|
|
156
|
+
* @param circuit The object to check.
|
|
157
|
+
* @returns True if the object is a Circuit, false otherwise.
|
|
158
|
+
*/
|
|
159
|
+
function isCircuit(circuit) {
|
|
160
|
+
return (circuit &&
|
|
161
|
+
Array.isArray(circuit.qubits) &&
|
|
162
|
+
Array.isArray(circuit.componentGrid));
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Get the label from a ket string.
|
|
166
|
+
*
|
|
167
|
+
* @param ket The ket string to extract the label from.
|
|
168
|
+
* @returns The label extracted from the ket string.
|
|
169
|
+
*/
|
|
170
|
+
function getKetLabel(ket) {
|
|
171
|
+
// Check that the ket conforms to the format |{label}> or |{label}⟩
|
|
172
|
+
const ketRegex = /^\|([^\s〉⟩〉>]+)(?:[〉⟩〉>])$/;
|
|
173
|
+
// Match the ket string against the regex
|
|
174
|
+
const match = ket.match(ketRegex);
|
|
175
|
+
// If valid, return the inner label (captured group 1), otherwise return an empty string
|
|
176
|
+
return match ? match[1] : "";
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Converts a list of operations into a 2D grid of operations in col-row format.
|
|
180
|
+
* Operations will be left-justified as much as possible in the resulting grid.
|
|
181
|
+
* Children operations are recursively converted into a grid.
|
|
182
|
+
*
|
|
183
|
+
* @param operations Array of operations.
|
|
184
|
+
* @param numQubits Number of qubits in the circuit.
|
|
185
|
+
*
|
|
186
|
+
* @returns A 2D array of operations.
|
|
187
|
+
*/
|
|
188
|
+
function operationListToGrid(operations, numQubits) {
|
|
189
|
+
operations.forEach((op) => {
|
|
190
|
+
// The children data structure is a grid, so checking if it is
|
|
191
|
+
// length 1 is actually checking if it has a single column,
|
|
192
|
+
// or in other words, we are checking if its children are in a single list.
|
|
193
|
+
// If the operation has children in a single list, it needs to be converted to a grid.
|
|
194
|
+
// If it was already converted to a grid, but the grid was still a single list,
|
|
195
|
+
// then doing it again won't effect anything.
|
|
196
|
+
if (op.children && op.children.length == 1) {
|
|
197
|
+
op.children = operationListToGrid(op.children[0].components, numQubits);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
return removePadding(operationListToPaddedArray(operations, numQubits)).map((col) => ({
|
|
201
|
+
components: col,
|
|
202
|
+
}));
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Converts a list of operations into a padded 2D array of operations.
|
|
206
|
+
*
|
|
207
|
+
* @param operations Array of operations.
|
|
208
|
+
* @param numQubits Number of qubits in the circuit.
|
|
209
|
+
*
|
|
210
|
+
* @returns A 2D array of operations padded with `null`s.
|
|
211
|
+
*/
|
|
212
|
+
function operationListToPaddedArray(operations, numQubits) {
|
|
213
|
+
if (operations.length === 0)
|
|
214
|
+
return [];
|
|
215
|
+
// Group operations based on registers
|
|
216
|
+
const groupedOps = groupOperations(operations, numQubits);
|
|
217
|
+
// Align operations on multiple registers
|
|
218
|
+
const alignedOps = transformToColRow(alignOps(groupedOps));
|
|
219
|
+
const operationArray = alignedOps.map((col) => col.map((opIdx) => {
|
|
220
|
+
if (opIdx == null)
|
|
221
|
+
return null;
|
|
222
|
+
return operations[opIdx];
|
|
223
|
+
}));
|
|
224
|
+
return operationArray;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Removes padding (`null` values) from a 2D array of operations.
|
|
228
|
+
*
|
|
229
|
+
* @param operations 2D array of operations padded with `null`s.
|
|
230
|
+
*
|
|
231
|
+
* @returns A 2D array of operations without `null` values.
|
|
232
|
+
*/
|
|
233
|
+
function removePadding(operations) {
|
|
234
|
+
return operations.map((col) => col.filter((op) => op != null));
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Transforms a row-col 2D array into an equivalent col-row 2D array.
|
|
238
|
+
*
|
|
239
|
+
* @param alignedOps 2D array of operations in row-col format.
|
|
240
|
+
*
|
|
241
|
+
* @returns 2D array of operations in col-row format.
|
|
242
|
+
*/
|
|
243
|
+
function transformToColRow(alignedOps) {
|
|
244
|
+
if (alignedOps.length === 0)
|
|
245
|
+
return [];
|
|
246
|
+
const numRows = alignedOps.length;
|
|
247
|
+
const numCols = Math.max(...alignedOps.map((row) => row.length));
|
|
248
|
+
const colRowArray = Array.from({ length: numCols }, () => Array(numRows).fill(null));
|
|
249
|
+
for (let row = 0; row < numRows; row++) {
|
|
250
|
+
for (let col = 0; col < alignedOps[row].length; col++) {
|
|
251
|
+
colRowArray[col][row] = alignedOps[row][col];
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return colRowArray;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Group gates provided by operations into their respective registers.
|
|
258
|
+
*
|
|
259
|
+
* @param operations Array of operations.
|
|
260
|
+
* @param numQubits Number of qubits in the circuit.
|
|
261
|
+
*
|
|
262
|
+
* @returns 2D array of indices where `groupedOps[i][j]` is the index of the operations
|
|
263
|
+
* at register `i` and column `j` (not yet aligned/padded).
|
|
264
|
+
*/
|
|
265
|
+
function groupOperations(operations, numQubits) {
|
|
266
|
+
const groupedOps = Array.from(Array(numQubits), () => new Array(0));
|
|
267
|
+
operations.forEach((operation, instrIdx) => {
|
|
268
|
+
const [minRegIdx, maxRegIdx] = getMinMaxRegIdx(operation, numQubits);
|
|
269
|
+
// Add operation also to registers that are in-between target registers
|
|
270
|
+
// so that other gates won't render in the middle.
|
|
271
|
+
for (let i = minRegIdx; i <= maxRegIdx; i++) {
|
|
272
|
+
groupedOps[i].push(instrIdx);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
return groupedOps;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Aligns operations by padding registers with `null`s to make sure that multiqubit
|
|
279
|
+
* gates are in the same column.
|
|
280
|
+
* e.g. ---[x]---[x]--
|
|
281
|
+
* ----------|---
|
|
282
|
+
*
|
|
283
|
+
* @param ops 2D array of operations. Each row represents a register
|
|
284
|
+
* and the operations acting on it (in-order).
|
|
285
|
+
*
|
|
286
|
+
* @returns 2D array of aligned operations padded with `null`s.
|
|
287
|
+
*/
|
|
288
|
+
function alignOps(ops) {
|
|
289
|
+
let maxNumOps = Math.max(0, ...ops.map((regOps) => regOps.length));
|
|
290
|
+
let col = 0;
|
|
291
|
+
// Deep copy ops to be returned as paddedOps
|
|
292
|
+
const paddedOps = ops.map((regOps) => [...regOps]);
|
|
293
|
+
while (col < maxNumOps) {
|
|
294
|
+
for (let regIdx = 0; regIdx < paddedOps.length; regIdx++) {
|
|
295
|
+
const reg = paddedOps[regIdx];
|
|
296
|
+
if (reg.length <= col)
|
|
297
|
+
continue;
|
|
298
|
+
// Should never be null (nulls are only padded to previous columns)
|
|
299
|
+
const opIdx = reg[col];
|
|
300
|
+
// Get position of gate
|
|
301
|
+
const targetsPos = paddedOps.map((regOps) => regOps.indexOf(opIdx));
|
|
302
|
+
const gatePos = Math.max(-1, ...targetsPos);
|
|
303
|
+
// If current column is not desired gate position, pad with null
|
|
304
|
+
if (col < gatePos) {
|
|
305
|
+
paddedOps[regIdx].splice(col, 0, null);
|
|
306
|
+
maxNumOps = Math.max(maxNumOps, paddedOps[regIdx].length);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
col++;
|
|
310
|
+
}
|
|
311
|
+
return paddedOps;
|
|
312
|
+
}
|
|
@@ -9,12 +9,10 @@ export declare enum RegisterType {
|
|
|
9
9
|
* Represents a register resource.
|
|
10
10
|
*/
|
|
11
11
|
export interface Register {
|
|
12
|
-
/** Type of register. If missing defaults to Qubit. */
|
|
13
|
-
type?: RegisterType;
|
|
14
12
|
/** Qubit register ID. */
|
|
15
|
-
|
|
16
|
-
/** Classical register ID
|
|
17
|
-
|
|
13
|
+
qubit: number;
|
|
14
|
+
/** Classical register ID. If present, register is classical register. */
|
|
15
|
+
result?: number;
|
|
18
16
|
}
|
|
19
17
|
/**
|
|
20
18
|
* Metadata for qubit register.
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Operation } from "./shared/circuit.js";
|
|
1
2
|
export type Tick = {
|
|
2
3
|
value: number;
|
|
3
4
|
label: string;
|
|
@@ -21,4 +22,12 @@ export declare function getRanges(data: SeriesOfPoints, rangeCoefficient: number
|
|
|
21
22
|
max: number;
|
|
22
23
|
};
|
|
23
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Get the minimum and maximum register indices for a given operation.
|
|
27
|
+
*
|
|
28
|
+
* @param operation The operation for which to get the register indices.
|
|
29
|
+
* @param numQubits The number of qubits in the circuit.
|
|
30
|
+
* @returns A tuple containing the minimum and maximum register indices.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getMinMaxRegIdx(operation: Operation, numQubits: number): [number, number];
|
|
24
33
|
export {};
|
package/dist/utils.js
CHANGED
|
@@ -146,3 +146,44 @@ export function getRanges(data, rangeCoefficient) {
|
|
|
146
146
|
};
|
|
147
147
|
return { rangeX, rangeY };
|
|
148
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Get the minimum and maximum register indices for a given operation.
|
|
151
|
+
*
|
|
152
|
+
* @param operation The operation for which to get the register indices.
|
|
153
|
+
* @param numQubits The number of qubits in the circuit.
|
|
154
|
+
* @returns A tuple containing the minimum and maximum register indices.
|
|
155
|
+
*/
|
|
156
|
+
export function getMinMaxRegIdx(operation, numQubits) {
|
|
157
|
+
let targets;
|
|
158
|
+
let controls;
|
|
159
|
+
switch (operation.kind) {
|
|
160
|
+
case "measurement":
|
|
161
|
+
targets = operation.results;
|
|
162
|
+
controls = operation.qubits;
|
|
163
|
+
break;
|
|
164
|
+
case "unitary":
|
|
165
|
+
targets = operation.targets;
|
|
166
|
+
controls = operation.controls || [];
|
|
167
|
+
break;
|
|
168
|
+
case "ket":
|
|
169
|
+
targets = operation.targets;
|
|
170
|
+
controls = [];
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
const ctrls = controls || [];
|
|
174
|
+
const qRegs = [...ctrls, ...targets].filter(({ result }) => result === undefined);
|
|
175
|
+
const qRegIdxList = qRegs.map(({ qubit }) => qubit);
|
|
176
|
+
const clsControls = ctrls.filter(({ result }) => result !== undefined);
|
|
177
|
+
const isClassicallyControlled = clsControls.length > 0;
|
|
178
|
+
if (!isClassicallyControlled && qRegs.length === 0)
|
|
179
|
+
return [-1, -1];
|
|
180
|
+
// If operation is classically-controlled, pad all qubit registers. Otherwise, only pad
|
|
181
|
+
// the contiguous range of registers that it covers.
|
|
182
|
+
const minRegIdx = isClassicallyControlled
|
|
183
|
+
? 0
|
|
184
|
+
: Math.min(...qRegIdxList);
|
|
185
|
+
const maxRegIdx = isClassicallyControlled
|
|
186
|
+
? numQubits - 1
|
|
187
|
+
: Math.max(...qRegIdxList);
|
|
188
|
+
return [minRegIdx, maxRegIdx];
|
|
189
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
uid: Qdk.Microsoft.Quantum.Core.Length
|
|
3
3
|
title: Length exported item
|
|
4
4
|
description: "Q# Length exported item: This is an exported item. The actual definition is found here: [Std.Core.Length](xref:Qdk.Std.Core.Length)"
|
|
5
|
-
ms.date:
|
|
5
|
+
ms.date: 04/17/2025
|
|
6
6
|
ms.topic: managed-reference
|
|
7
7
|
qsharp.kind: export
|
|
8
8
|
qsharp.package: __Std__
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
uid: Qdk.Microsoft.Quantum.Core.Repeated
|
|
3
3
|
title: Repeated exported item
|
|
4
4
|
description: "Q# Repeated exported item: This is an exported item. The actual definition is found here: [Std.Core.Repeated](xref:Qdk.Std.Core.Repeated)"
|
|
5
|
-
ms.date:
|
|
5
|
+
ms.date: 04/17/2025
|
|
6
6
|
ms.topic: managed-reference
|
|
7
7
|
qsharp.kind: export
|
|
8
8
|
qsharp.package: __Std__
|