qsharp-lang 1.1.4-dev → 1.1.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/browser.d.ts +3 -3
- package/dist/browser.js +12 -58
- package/dist/compiler/compiler.d.ts +4 -2
- package/dist/compiler/compiler.js +14 -1
- package/dist/compiler/events.d.ts +1 -1
- package/dist/compiler/worker-browser.d.ts +1 -1
- package/dist/compiler/worker-browser.js +3 -40
- package/dist/compiler/worker-node.js +3 -39
- package/dist/debug-service/debug-service.d.ts +5 -3
- package/dist/debug-service/debug-service.js +18 -1
- package/dist/debug-service/worker-browser.d.ts +1 -1
- package/dist/debug-service/worker-browser.js +3 -29
- package/dist/debug-service/worker-node.js +3 -28
- package/dist/katas-content.generated.js +308 -308
- package/dist/language-service/language-service.d.ts +7 -1
- package/dist/language-service/language-service.js +27 -0
- package/dist/language-service/worker-browser.d.ts +1 -1
- package/dist/language-service/worker-browser.js +3 -29
- package/dist/language-service/worker-node.js +3 -28
- package/dist/main.d.ts +2 -2
- package/dist/main.js +7 -42
- package/dist/samples.generated.js +1 -1
- package/dist/workers/browser.d.ts +21 -0
- package/dist/workers/browser.js +67 -0
- package/dist/{worker-proxy.d.ts → workers/common.d.ts} +26 -9
- package/dist/{worker-proxy.js → workers/common.js} +33 -4
- package/dist/workers/node.d.ts +20 -0
- package/dist/workers/node.js +55 -0
- package/docs/Microsoft.Quantum.Arrays/All.md +4 -6
- package/docs/Microsoft.Quantum.Arrays/Any.md +4 -6
- package/docs/Microsoft.Quantum.Arrays/Chunks.md +3 -3
- package/docs/Microsoft.Quantum.Arrays/CircularlyShifted.md +3 -3
- package/docs/Microsoft.Quantum.Arrays/ColumnAt.md +3 -3
- package/docs/Microsoft.Quantum.Arrays/Count.md +4 -6
- package/docs/Microsoft.Quantum.Arrays/Diagonal.md +3 -3
- package/docs/Microsoft.Quantum.Arrays/DrawMany.md +5 -6
- package/docs/Microsoft.Quantum.Arrays/Enumerated.md +4 -5
- package/docs/Microsoft.Quantum.Arrays/Excluding.md +4 -5
- package/docs/Microsoft.Quantum.Arrays/Filtered.md +4 -6
- package/docs/Microsoft.Quantum.Arrays/FlatMapped.md +4 -5
- package/docs/Microsoft.Quantum.Arrays/Flattened.md +3 -3
- package/docs/Microsoft.Quantum.Arrays/Fold.md +4 -5
- package/docs/Microsoft.Quantum.Arrays/ForEach.md +5 -7
- package/docs/Microsoft.Quantum.Arrays/Head.md +3 -3
- package/docs/Microsoft.Quantum.Arrays/HeadAndRest.md +3 -3
- package/docs/Microsoft.Quantum.Arrays/IndexOf.md +4 -5
- package/docs/Microsoft.Quantum.Arrays/IndexRange.md +4 -5
- package/docs/Microsoft.Quantum.Arrays/Interleaved.md +3 -3
- package/docs/Microsoft.Quantum.Arrays/IsEmpty.md +3 -3
- package/docs/Microsoft.Quantum.Arrays/IsRectangularArray.md +3 -3
- package/docs/Microsoft.Quantum.Arrays/IsSorted.md +4 -5
- package/docs/Microsoft.Quantum.Arrays/IsSquareArray.md +3 -3
- package/docs/Microsoft.Quantum.Arrays/Mapped.md +4 -6
- package/docs/Microsoft.Quantum.Arrays/MappedByIndex.md +4 -6
- package/docs/Microsoft.Quantum.Arrays/MappedOverRange.md +4 -6
- package/docs/Microsoft.Quantum.Arrays/Most.md +4 -5
- package/docs/Microsoft.Quantum.Arrays/MostAndTail.md +3 -3
- package/docs/Microsoft.Quantum.Arrays/Padded.md +4 -5
- package/docs/Microsoft.Quantum.Arrays/Partitioned.md +3 -3
- package/docs/Microsoft.Quantum.Arrays/Rest.md +4 -5
- package/docs/Microsoft.Quantum.Arrays/Reversed.md +4 -5
- package/docs/Microsoft.Quantum.Arrays/SequenceI.md +3 -3
- package/docs/Microsoft.Quantum.Arrays/SequenceL.md +3 -3
- package/docs/Microsoft.Quantum.Arrays/Sorted.md +4 -5
- package/docs/Microsoft.Quantum.Arrays/Subarray.md +4 -6
- package/docs/Microsoft.Quantum.Arrays/Swapped.md +3 -3
- package/docs/Microsoft.Quantum.Arrays/Tail.md +3 -3
- package/docs/Microsoft.Quantum.Arrays/Transposed.md +4 -5
- package/docs/Microsoft.Quantum.Arrays/Unzipped.md +4 -5
- package/docs/Microsoft.Quantum.Arrays/Where.md +4 -5
- package/docs/Microsoft.Quantum.Arrays/Windows.md +3 -3
- package/docs/Microsoft.Quantum.Arrays/Zipped.md +4 -5
- package/docs/Microsoft.Quantum.Canon/ApplyCNOTChain.md +4 -4
- package/docs/Microsoft.Quantum.Canon/ApplyControlledOnBitString.md +5 -6
- package/docs/Microsoft.Quantum.Canon/ApplyControlledOnInt.md +5 -6
- package/docs/Microsoft.Quantum.Canon/ApplyP.md +5 -6
- package/docs/Microsoft.Quantum.Canon/ApplyPauli.md +5 -6
- package/docs/Microsoft.Quantum.Canon/ApplyPauliFromBitString.md +5 -6
- package/docs/Microsoft.Quantum.Canon/ApplyPauliFromInt.md +5 -6
- package/docs/Microsoft.Quantum.Canon/ApplyQFT.md +4 -4
- package/docs/Microsoft.Quantum.Canon/ApplyToEach.md +4 -4
- package/docs/Microsoft.Quantum.Canon/ApplyToEachA.md +5 -6
- package/docs/Microsoft.Quantum.Canon/ApplyToEachC.md +5 -6
- package/docs/Microsoft.Quantum.Canon/ApplyToEachCA.md +5 -6
- package/docs/Microsoft.Quantum.Canon/ApplyXorInPlace.md +5 -6
- package/docs/Microsoft.Quantum.Canon/ApplyXorInPlaceL.md +5 -6
- package/docs/Microsoft.Quantum.Canon/CX.md +4 -4
- package/docs/Microsoft.Quantum.Canon/CY.md +4 -4
- package/docs/Microsoft.Quantum.Canon/CZ.md +4 -4
- package/docs/Microsoft.Quantum.Canon/Fst.md +3 -3
- package/docs/Microsoft.Quantum.Canon/Snd.md +3 -3
- package/docs/Microsoft.Quantum.Canon/SwapReverseRegister.md +4 -4
- package/docs/Microsoft.Quantum.Convert/BigIntAsBoolArray.md +4 -5
- package/docs/Microsoft.Quantum.Convert/BoolArrayAsBigInt.md +4 -5
- package/docs/Microsoft.Quantum.Convert/BoolArrayAsInt.md +3 -3
- package/docs/Microsoft.Quantum.Convert/BoolArrayAsResultArray.md +4 -5
- package/docs/Microsoft.Quantum.Convert/BoolAsResult.md +4 -5
- package/docs/Microsoft.Quantum.Convert/ComplexAsComplexPolar.md +4 -5
- package/docs/Microsoft.Quantum.Convert/ComplexPolarAsComplex.md +4 -5
- package/docs/Microsoft.Quantum.Convert/IntAsBigInt.md +3 -3
- package/docs/Microsoft.Quantum.Convert/IntAsBoolArray.md +4 -5
- package/docs/Microsoft.Quantum.Convert/IntAsDouble.md +3 -3
- package/docs/Microsoft.Quantum.Convert/ResultArrayAsBoolArray.md +4 -5
- package/docs/Microsoft.Quantum.Convert/ResultArrayAsInt.md +3 -3
- package/docs/Microsoft.Quantum.Convert/ResultAsBool.md +4 -5
- package/docs/Microsoft.Quantum.Core/IsRangeEmpty.md +3 -3
- package/docs/Microsoft.Quantum.Core/Length.md +3 -3
- package/docs/Microsoft.Quantum.Core/RangeEnd.md +4 -5
- package/docs/Microsoft.Quantum.Core/RangeReverse.md +3 -3
- package/docs/Microsoft.Quantum.Core/RangeStart.md +3 -3
- package/docs/Microsoft.Quantum.Core/RangeStep.md +3 -3
- package/docs/Microsoft.Quantum.Core/Repeated.md +3 -3
- package/docs/Microsoft.Quantum.Diagnostics/CheckAllZero.md +4 -4
- package/docs/Microsoft.Quantum.Diagnostics/CheckOperationsAreEqual.md +4 -4
- package/docs/Microsoft.Quantum.Diagnostics/CheckZero.md +4 -4
- package/docs/Microsoft.Quantum.Diagnostics/DumpMachine.md +3 -3
- package/docs/Microsoft.Quantum.Diagnostics/Fact.md +3 -3
- package/docs/Microsoft.Quantum.Intrinsic/CCNOT.md +4 -4
- package/docs/Microsoft.Quantum.Intrinsic/CNOT.md +4 -4
- package/docs/Microsoft.Quantum.Intrinsic/Exp.md +4 -4
- package/docs/Microsoft.Quantum.Intrinsic/H.md +4 -4
- package/docs/Microsoft.Quantum.Intrinsic/I.md +4 -4
- package/docs/Microsoft.Quantum.Intrinsic/M.md +5 -6
- package/docs/Microsoft.Quantum.Intrinsic/Measure.md +5 -6
- package/docs/Microsoft.Quantum.Intrinsic/Message.md +3 -3
- package/docs/Microsoft.Quantum.Intrinsic/R.md +4 -4
- package/docs/Microsoft.Quantum.Intrinsic/R1.md +4 -4
- package/docs/Microsoft.Quantum.Intrinsic/R1Frac.md +5 -11
- package/docs/Microsoft.Quantum.Intrinsic/RFrac.md +5 -10
- package/docs/Microsoft.Quantum.Intrinsic/Reset.md +5 -6
- package/docs/Microsoft.Quantum.Intrinsic/ResetAll.md +5 -6
- package/docs/Microsoft.Quantum.Intrinsic/Rx.md +4 -4
- package/docs/Microsoft.Quantum.Intrinsic/Rxx.md +4 -4
- package/docs/Microsoft.Quantum.Intrinsic/Ry.md +4 -4
- package/docs/Microsoft.Quantum.Intrinsic/Ryy.md +4 -4
- package/docs/Microsoft.Quantum.Intrinsic/Rz.md +4 -4
- package/docs/Microsoft.Quantum.Intrinsic/Rzz.md +4 -4
- package/docs/Microsoft.Quantum.Intrinsic/S.md +4 -4
- package/docs/Microsoft.Quantum.Intrinsic/SWAP.md +4 -4
- package/docs/Microsoft.Quantum.Intrinsic/T.md +4 -4
- package/docs/Microsoft.Quantum.Intrinsic/X.md +4 -4
- package/docs/Microsoft.Quantum.Intrinsic/Y.md +4 -4
- package/docs/Microsoft.Quantum.Intrinsic/Z.md +4 -4
- package/docs/Microsoft.Quantum.Logical/Xor.md +3 -3
- package/docs/Microsoft.Quantum.Math/AbsComplex.md +4 -5
- package/docs/Microsoft.Quantum.Math/AbsComplexPolar.md +4 -5
- package/docs/Microsoft.Quantum.Math/AbsD.md +3 -3
- package/docs/Microsoft.Quantum.Math/AbsI.md +3 -3
- package/docs/Microsoft.Quantum.Math/AbsL.md +3 -3
- package/docs/Microsoft.Quantum.Math/AbsSquaredComplex.md +4 -5
- package/docs/Microsoft.Quantum.Math/AbsSquaredComplexPolar.md +4 -5
- package/docs/Microsoft.Quantum.Math/ApproximateFactorial.md +3 -3
- package/docs/Microsoft.Quantum.Math/ArcCos.md +3 -3
- package/docs/Microsoft.Quantum.Math/ArcCosh.md +3 -3
- package/docs/Microsoft.Quantum.Math/ArcSin.md +3 -3
- package/docs/Microsoft.Quantum.Math/ArcSinh.md +3 -3
- package/docs/Microsoft.Quantum.Math/ArcTan.md +3 -3
- package/docs/Microsoft.Quantum.Math/ArcTan2.md +3 -3
- package/docs/Microsoft.Quantum.Math/ArcTanh.md +3 -3
- package/docs/Microsoft.Quantum.Math/ArgComplex.md +4 -5
- package/docs/Microsoft.Quantum.Math/ArgComplexPolar.md +3 -3
- package/docs/Microsoft.Quantum.Math/Binom.md +3 -3
- package/docs/Microsoft.Quantum.Math/BitSizeI.md +4 -5
- package/docs/Microsoft.Quantum.Math/BitSizeL.md +4 -5
- package/docs/Microsoft.Quantum.Math/Ceiling.md +4 -5
- package/docs/Microsoft.Quantum.Math/Complex.md +4 -6
- package/docs/Microsoft.Quantum.Math/ComplexPolar.md +4 -5
- package/docs/Microsoft.Quantum.Math/ContinuedFractionConvergentI.md +4 -6
- package/docs/Microsoft.Quantum.Math/ContinuedFractionConvergentL.md +4 -6
- package/docs/Microsoft.Quantum.Math/Cos.md +3 -3
- package/docs/Microsoft.Quantum.Math/Cosh.md +3 -3
- package/docs/Microsoft.Quantum.Math/DivRemI.md +3 -3
- package/docs/Microsoft.Quantum.Math/DivRemL.md +3 -3
- package/docs/Microsoft.Quantum.Math/DividedByC.md +3 -3
- package/docs/Microsoft.Quantum.Math/DividedByCP.md +3 -3
- package/docs/Microsoft.Quantum.Math/E.md +3 -3
- package/docs/Microsoft.Quantum.Math/ExpModI.md +4 -5
- package/docs/Microsoft.Quantum.Math/ExpModL.md +4 -5
- package/docs/Microsoft.Quantum.Math/ExtendedGreatestCommonDivisorI.md +4 -5
- package/docs/Microsoft.Quantum.Math/ExtendedGreatestCommonDivisorL.md +4 -5
- package/docs/Microsoft.Quantum.Math/FactorialI.md +3 -3
- package/docs/Microsoft.Quantum.Math/FactorialL.md +3 -3
- package/docs/Microsoft.Quantum.Math/Floor.md +4 -5
- package/docs/Microsoft.Quantum.Math/GreatestCommonDivisorI.md +4 -5
- package/docs/Microsoft.Quantum.Math/GreatestCommonDivisorL.md +4 -5
- package/docs/Microsoft.Quantum.Math/HammingWeightI.md +3 -3
- package/docs/Microsoft.Quantum.Math/InverseModI.md +3 -3
- package/docs/Microsoft.Quantum.Math/InverseModL.md +3 -3
- package/docs/Microsoft.Quantum.Math/IsCoprimeI.md +3 -3
- package/docs/Microsoft.Quantum.Math/IsCoprimeL.md +3 -3
- package/docs/Microsoft.Quantum.Math/IsInfinite.md +4 -5
- package/docs/Microsoft.Quantum.Math/IsNaN.md +4 -5
- package/docs/Microsoft.Quantum.Math/LargestFixedPoint.md +3 -3
- package/docs/Microsoft.Quantum.Math/Lg.md +3 -3
- package/docs/Microsoft.Quantum.Math/Log.md +3 -3
- package/docs/Microsoft.Quantum.Math/Log10.md +3 -3
- package/docs/Microsoft.Quantum.Math/LogFactorialD.md +4 -5
- package/docs/Microsoft.Quantum.Math/LogGammaD.md +4 -5
- package/docs/Microsoft.Quantum.Math/LogOf2.md +3 -3
- package/docs/Microsoft.Quantum.Math/Max.md +3 -3
- package/docs/Microsoft.Quantum.Math/MaxD.md +3 -3
- package/docs/Microsoft.Quantum.Math/MaxI.md +3 -3
- package/docs/Microsoft.Quantum.Math/MaxL.md +3 -3
- package/docs/Microsoft.Quantum.Math/Min.md +3 -3
- package/docs/Microsoft.Quantum.Math/MinD.md +3 -3
- package/docs/Microsoft.Quantum.Math/MinI.md +3 -3
- package/docs/Microsoft.Quantum.Math/MinL.md +3 -3
- package/docs/Microsoft.Quantum.Math/MinusC.md +3 -3
- package/docs/Microsoft.Quantum.Math/MinusCP.md +3 -3
- package/docs/Microsoft.Quantum.Math/ModulusI.md +4 -5
- package/docs/Microsoft.Quantum.Math/ModulusL.md +4 -5
- package/docs/Microsoft.Quantum.Math/NegationC.md +3 -3
- package/docs/Microsoft.Quantum.Math/NegationCP.md +3 -3
- package/docs/Microsoft.Quantum.Math/PI.md +3 -3
- package/docs/Microsoft.Quantum.Math/PNorm.md +4 -7
- package/docs/Microsoft.Quantum.Math/PNormalized.md +4 -8
- package/docs/Microsoft.Quantum.Math/PlusC.md +3 -3
- package/docs/Microsoft.Quantum.Math/PlusCP.md +3 -3
- package/docs/Microsoft.Quantum.Math/PowC.md +4 -5
- package/docs/Microsoft.Quantum.Math/PowCP.md +4 -5
- package/docs/Microsoft.Quantum.Math/RealMod.md +3 -3
- package/docs/Microsoft.Quantum.Math/Round.md +4 -5
- package/docs/Microsoft.Quantum.Math/SignD.md +3 -3
- package/docs/Microsoft.Quantum.Math/SignI.md +3 -3
- package/docs/Microsoft.Quantum.Math/SignL.md +3 -3
- package/docs/Microsoft.Quantum.Math/Sin.md +3 -3
- package/docs/Microsoft.Quantum.Math/Sinh.md +3 -3
- package/docs/Microsoft.Quantum.Math/SmallestFixedPoint.md +3 -3
- package/docs/Microsoft.Quantum.Math/Sqrt.md +3 -3
- package/docs/Microsoft.Quantum.Math/SquaredNorm.md +3 -3
- package/docs/Microsoft.Quantum.Math/Tan.md +3 -3
- package/docs/Microsoft.Quantum.Math/Tanh.md +3 -3
- package/docs/Microsoft.Quantum.Math/TimesC.md +3 -3
- package/docs/Microsoft.Quantum.Math/TimesCP.md +3 -3
- package/docs/Microsoft.Quantum.Math/TrailingZeroCountI.md +4 -5
- package/docs/Microsoft.Quantum.Math/TrailingZeroCountL.md +4 -5
- package/docs/Microsoft.Quantum.Math/Truncate.md +4 -5
- package/docs/Microsoft.Quantum.Measurement/MResetEachZ.md +5 -6
- package/docs/Microsoft.Quantum.Measurement/MResetX.md +5 -7
- package/docs/Microsoft.Quantum.Measurement/MResetY.md +5 -7
- package/docs/Microsoft.Quantum.Measurement/MResetZ.md +5 -7
- package/docs/Microsoft.Quantum.Measurement/MeasureAllZ.md +4 -4
- package/docs/Microsoft.Quantum.Measurement/MeasureEachZ.md +4 -4
- package/docs/Microsoft.Quantum.Measurement/MeasureInteger.md +5 -7
- package/docs/Microsoft.Quantum.Random/DrawRandomDouble.md +4 -4
- package/docs/Microsoft.Quantum.Random/DrawRandomInt.md +4 -4
- package/docs/Microsoft.Quantum.ResourceEstimation/AccountForEstimates.md +5 -7
- package/docs/Microsoft.Quantum.ResourceEstimation/AuxQubitCount.md +4 -5
- package/docs/Microsoft.Quantum.ResourceEstimation/BeginEstimateCaching.md +4 -6
- package/docs/Microsoft.Quantum.ResourceEstimation/BeginRepeatEstimates.md +5 -10
- package/docs/Microsoft.Quantum.ResourceEstimation/CczCount.md +4 -5
- package/docs/Microsoft.Quantum.ResourceEstimation/EndEstimateCaching.md +4 -6
- package/docs/Microsoft.Quantum.ResourceEstimation/EndRepeatEstimates.md +4 -4
- package/docs/Microsoft.Quantum.ResourceEstimation/MeasurementCount.md +4 -5
- package/docs/Microsoft.Quantum.ResourceEstimation/PSSPCLayout.md +4 -6
- package/docs/Microsoft.Quantum.ResourceEstimation/RepeatEstimates.md +5 -8
- package/docs/Microsoft.Quantum.ResourceEstimation/RotationCount.md +4 -5
- package/docs/Microsoft.Quantum.ResourceEstimation/RotationDepth.md +4 -5
- package/docs/Microsoft.Quantum.ResourceEstimation/SingleVariant.md +4 -5
- package/docs/Microsoft.Quantum.ResourceEstimation/TCount.md +4 -5
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/AddLE.md +5 -6
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfEqualL.md +5 -6
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfEqualLE.md +5 -7
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterL.md +5 -6
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterLE.md +5 -7
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterOrEqualL.md +5 -6
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterOrEqualLE.md +5 -7
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessL.md +5 -6
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessLE.md +5 -7
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessOrEqualL.md +5 -6
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessOrEqualLE.md +5 -7
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/FourierTDIncByLE.md +5 -6
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByI.md +4 -4
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByIUsingIncByLE.md +5 -6
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByL.md +4 -4
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLE.md +4 -4
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLEUsingAddLE.md +4 -4
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLUsingIncByLE.md +5 -6
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/LookAheadDKRSAddLE.md +5 -6
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/MAJ.md +4 -4
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/ReflectAboutInteger.md +4 -4
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryCGAddLE.md +5 -6
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryCGIncByLE.md +5 -6
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryTTKIncByLE.md +4 -4
- package/docs/Microsoft.Quantum.Unstable.StatePreparation/ApproximatelyPreparePureStateCP.md +5 -7
- package/docs/Microsoft.Quantum.Unstable.StatePreparation/PreparePureStateD.md +5 -6
- package/docs/Microsoft.Quantum.Unstable.TableLookup/Select.md +4 -4
- package/docs/toc.yml +286 -284
- package/lib/node/qsc_wasm_bg.wasm +0 -0
- package/lib/web/qsc_wasm_bg.wasm +0 -0
- package/package.json +1 -1
- package/dist/compiler/worker-proxy.d.ts +0 -7
- package/dist/compiler/worker-proxy.js +0 -18
- package/dist/debug-service/worker-proxy.d.ts +0 -7
- package/dist/debug-service/worker-proxy.js +0 -22
- package/dist/language-service/worker-proxy.d.ts +0 -6
- package/dist/language-service/worker-proxy.js +0 -28
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ICodeLens, ICompletionList, IHover, ILocation, INotebookMetadata, IPosition, ISignatureHelp, ITextEdit, IWorkspaceConfiguration, IWorkspaceEdit, VSDiagnostic } from "../../lib/node/qsc_wasm.cjs";
|
|
2
|
-
import { IServiceProxy } from "../
|
|
2
|
+
import { IServiceProxy, ServiceProtocol } from "../workers/common.js";
|
|
3
3
|
type QscWasm = typeof import("../../lib/node/qsc_wasm.cjs");
|
|
4
4
|
export type LanguageServiceEvent = {
|
|
5
5
|
type: "diagnostics";
|
|
@@ -71,4 +71,10 @@ export declare class QSharpLanguageService implements ILanguageService {
|
|
|
71
71
|
}>) => void): void;
|
|
72
72
|
onDiagnostics(uri: string, version: number | undefined, diagnostics: VSDiagnostic[]): Promise<void>;
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* The protocol definition to allow running the language service in a worker.
|
|
76
|
+
*
|
|
77
|
+
* Not to be confused with "the" LSP (Language Server Protocol).
|
|
78
|
+
*/
|
|
79
|
+
export declare const languageServiceProtocol: ServiceProtocol<ILanguageService, LanguageServiceEvent>;
|
|
74
80
|
export {};
|
|
@@ -75,3 +75,30 @@ export class QSharpLanguageService {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* The protocol definition to allow running the language service in a worker.
|
|
80
|
+
*
|
|
81
|
+
* Not to be confused with "the" LSP (Language Server Protocol).
|
|
82
|
+
*/
|
|
83
|
+
export const languageServiceProtocol = {
|
|
84
|
+
class: QSharpLanguageService,
|
|
85
|
+
methods: {
|
|
86
|
+
updateConfiguration: "request",
|
|
87
|
+
updateDocument: "request",
|
|
88
|
+
updateNotebookDocument: "request",
|
|
89
|
+
closeDocument: "request",
|
|
90
|
+
closeNotebookDocument: "request",
|
|
91
|
+
getCompletions: "request",
|
|
92
|
+
getHover: "request",
|
|
93
|
+
getDefinition: "request",
|
|
94
|
+
getReferences: "request",
|
|
95
|
+
getSignatureHelp: "request",
|
|
96
|
+
getRename: "request",
|
|
97
|
+
prepareRename: "request",
|
|
98
|
+
getCodeLenses: "request",
|
|
99
|
+
dispose: "request",
|
|
100
|
+
addEventListener: "addEventListener",
|
|
101
|
+
removeEventListener: "removeEventListener",
|
|
102
|
+
},
|
|
103
|
+
eventNames: ["diagnostics"],
|
|
104
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare
|
|
1
|
+
export declare const messageHandler: (e: MessageEvent<any>) => void;
|
|
@@ -1,32 +1,6 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { QSharpLanguageService } from "./language-service.js";
|
|
6
|
-
import { createLanguageServiceDispatcher } from "./worker-proxy.js";
|
|
7
|
-
let invokeCompiler = null;
|
|
3
|
+
import { createWorker } from "../workers/browser.js";
|
|
4
|
+
import { languageServiceProtocol } from "./language-service.js";
|
|
8
5
|
// This export should be assigned to 'self.onmessage' in a WebWorker
|
|
9
|
-
export
|
|
10
|
-
const data = e.data;
|
|
11
|
-
if (!data.type || typeof data.type !== "string") {
|
|
12
|
-
log.error(`Unrecognized msg: ${data}`);
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
switch (data.type) {
|
|
16
|
-
case "init":
|
|
17
|
-
{
|
|
18
|
-
log.setLogLevel(data.qscLogLevel);
|
|
19
|
-
wasm.initSync(data.wasmModule);
|
|
20
|
-
const languageService = new QSharpLanguageService(wasm);
|
|
21
|
-
invokeCompiler = createLanguageServiceDispatcher(self.postMessage.bind(self), languageService);
|
|
22
|
-
}
|
|
23
|
-
break;
|
|
24
|
-
default:
|
|
25
|
-
if (!invokeCompiler) {
|
|
26
|
-
log.error(`Received message before the compiler was initialized: %o`, data);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
invokeCompiler(data);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
6
|
+
export const messageHandler = createWorker(languageServiceProtocol);
|
|
@@ -1,30 +1,5 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// const worker = new Worker(join(thisDir,"worker-node.js"), {
|
|
7
|
-
// workerData: {qscLogLevel: log.getLogLevel() }
|
|
8
|
-
// });
|
|
9
|
-
import { isMainThread, parentPort, workerData } from "node:worker_threads";
|
|
10
|
-
import * as wasm from "../../lib/node/qsc_wasm.cjs";
|
|
11
|
-
import { log } from "../log.js";
|
|
12
|
-
import { QSharpLanguageService } from "./language-service.js";
|
|
13
|
-
import { createLanguageServiceDispatcher } from "./worker-proxy.js";
|
|
14
|
-
if (isMainThread)
|
|
15
|
-
throw "Worker script should be loaded in a Worker thread only";
|
|
16
|
-
if (workerData && typeof workerData.qscLogLevel === "number") {
|
|
17
|
-
log.setLogLevel(workerData.qscLogLevel);
|
|
18
|
-
}
|
|
19
|
-
const port = parentPort; // eslint-disable-line @typescript-eslint/no-non-null-assertion
|
|
20
|
-
const postMessage = port.postMessage.bind(port);
|
|
21
|
-
const compiler = new QSharpLanguageService(wasm);
|
|
22
|
-
const invokeCompiler = createLanguageServiceDispatcher(postMessage, compiler);
|
|
23
|
-
function messageHandler(data) {
|
|
24
|
-
if (!data.type || typeof data.type !== "string") {
|
|
25
|
-
log.error(`Unrecognized msg: %O"`, data);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
invokeCompiler(data);
|
|
29
|
-
}
|
|
30
|
-
port.addListener("message", messageHandler);
|
|
3
|
+
import { createWorker } from "../workers/node.js";
|
|
4
|
+
import { languageServiceProtocol } from "./language-service.js";
|
|
5
|
+
createWorker(languageServiceProtocol);
|
package/dist/main.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { ProjectLoader } from "../lib/node/qsc_wasm.cjs";
|
|
1
2
|
import { ICompiler, ICompilerWorker } from "./compiler/compiler.js";
|
|
2
|
-
import { ILanguageService, ILanguageServiceWorker, qsharpLibraryUriScheme } from "./language-service/language-service.js";
|
|
3
3
|
import { IDebugService, IDebugServiceWorker } from "./debug-service/debug-service.js";
|
|
4
|
-
import {
|
|
4
|
+
import { ILanguageService, ILanguageServiceWorker, qsharpLibraryUriScheme } from "./language-service/language-service.js";
|
|
5
5
|
export { qsharpLibraryUriScheme };
|
|
6
6
|
export declare function getLibrarySourceContent(path: string): Promise<string | undefined>;
|
|
7
7
|
export declare function getCompiler(): ICompiler;
|
package/dist/main.js
CHANGED
|
@@ -3,16 +3,11 @@
|
|
|
3
3
|
// This module is the main entry point for use in Node.js environments. For browser environments,
|
|
4
4
|
// the "./browser.js" file is the entry point module.
|
|
5
5
|
import { createRequire } from "node:module";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
6
|
+
import { Compiler, compilerProtocol, } from "./compiler/compiler.js";
|
|
7
|
+
import { QSharpDebugService, debugServiceProtocol, } from "./debug-service/debug-service.js";
|
|
8
|
+
import { QSharpLanguageService, languageServiceProtocol, qsharpLibraryUriScheme, } from "./language-service/language-service.js";
|
|
9
9
|
import { log } from "./log.js";
|
|
10
|
-
import {
|
|
11
|
-
import { createCompilerProxy } from "./compiler/worker-proxy.js";
|
|
12
|
-
import { QSharpLanguageService, qsharpLibraryUriScheme, } from "./language-service/language-service.js";
|
|
13
|
-
import { createLanguageServiceProxy } from "./language-service/worker-proxy.js";
|
|
14
|
-
import { QSharpDebugService, } from "./debug-service/debug-service.js";
|
|
15
|
-
import { createDebugServiceProxy } from "./debug-service/worker-proxy.js";
|
|
10
|
+
import { createProxy } from "./workers/node.js";
|
|
16
11
|
export { qsharpLibraryUriScheme };
|
|
17
12
|
let wasm = null;
|
|
18
13
|
const require = createRequire(import.meta.url);
|
|
@@ -41,17 +36,7 @@ export function getProjectLoader(readFile, loadDirectory, getManifest) {
|
|
|
41
36
|
return new wasm.ProjectLoader(readFile, loadDirectory, getManifest);
|
|
42
37
|
}
|
|
43
38
|
export function getCompilerWorker() {
|
|
44
|
-
|
|
45
|
-
const worker = new Worker(join(thisDir, "./compiler/worker-node.js"), {
|
|
46
|
-
workerData: { qscLogLevel: log.getLogLevel() },
|
|
47
|
-
});
|
|
48
|
-
// Create the proxy which will forward method calls to the worker
|
|
49
|
-
const proxy = createCompilerProxy(
|
|
50
|
-
// If you lose the 'this' binding, some environments have issues.
|
|
51
|
-
worker.postMessage.bind(worker), () => worker.terminate());
|
|
52
|
-
// Let proxy handle response and event messages from the worker
|
|
53
|
-
worker.addListener("message", proxy.onMsgFromWorker);
|
|
54
|
-
return proxy;
|
|
39
|
+
return createProxy("../compiler/worker-node.js", compilerProtocol);
|
|
55
40
|
}
|
|
56
41
|
export function getDebugService() {
|
|
57
42
|
if (!wasm)
|
|
@@ -59,17 +44,7 @@ export function getDebugService() {
|
|
|
59
44
|
return new QSharpDebugService(wasm);
|
|
60
45
|
}
|
|
61
46
|
export function getDebugServiceWorker() {
|
|
62
|
-
|
|
63
|
-
const worker = new Worker(join(thisDir, "./debug-service/worker-node.js"), {
|
|
64
|
-
workerData: { qscLogLevel: log.getLogLevel() },
|
|
65
|
-
});
|
|
66
|
-
// Create the proxy which will forward method calls to the worker
|
|
67
|
-
const proxy = createDebugServiceProxy(
|
|
68
|
-
// If you lose the 'this' binding, some environments have issues.
|
|
69
|
-
worker.postMessage.bind(worker), () => worker.terminate());
|
|
70
|
-
// Let proxy handle response and event messages from the worker
|
|
71
|
-
worker.addListener("message", proxy.onMsgFromWorker);
|
|
72
|
-
return proxy;
|
|
47
|
+
return createProxy("../debug-service/worker-node.js", debugServiceProtocol);
|
|
73
48
|
}
|
|
74
49
|
export function getLanguageService(readFile, listDir, getManifest) {
|
|
75
50
|
if (!wasm)
|
|
@@ -77,16 +52,6 @@ export function getLanguageService(readFile, listDir, getManifest) {
|
|
|
77
52
|
return new QSharpLanguageService(wasm, readFile, listDir, getManifest);
|
|
78
53
|
}
|
|
79
54
|
export function getLanguageServiceWorker() {
|
|
80
|
-
|
|
81
|
-
const worker = new Worker(join(thisDir, "./language-service/worker-node.js"), {
|
|
82
|
-
workerData: { qscLogLevel: log.getLogLevel() },
|
|
83
|
-
});
|
|
84
|
-
// Create the proxy which will forward method calls to the worker
|
|
85
|
-
const proxy = createLanguageServiceProxy(
|
|
86
|
-
// If you lose the 'this' binding, some environments have issues.
|
|
87
|
-
worker.postMessage.bind(worker), () => worker.terminate());
|
|
88
|
-
// Let proxy handle response and event messages from the worker
|
|
89
|
-
worker.addListener("message", proxy.onMsgFromWorker);
|
|
90
|
-
return proxy;
|
|
55
|
+
return createProxy("../language-service/worker-node.js", languageServiceProtocol);
|
|
91
56
|
}
|
|
92
57
|
export * as utils from "./utils.js";
|
|
@@ -82,7 +82,7 @@ export default [
|
|
|
82
82
|
{
|
|
83
83
|
"title": "Dynamics (Resource Estimation)",
|
|
84
84
|
"shots": 1,
|
|
85
|
-
"code": "/// # Sample\n/// Quantum Dynamics\n///\n/// # Description\n/// This example demonstrates quantum dynamics in a style tailored for\n/// resource estimation. The sample is specifically the simulation\n/// of an Ising model Hamiltonian on an N1xN2 2D lattice using a\n/// fourth-order Trotter Suzuki product formula, assuming\n/// a 2D qubit architecture with nearest-neighbor connectivity.\n/// The is an example of a program that is not amenable to simulating\n/// classically, but can be run through resource estimation to determine\n/// what size of quantum system would be needed to solve the problem.\nnamespace QuantumDynamics {\n\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Arrays;\n\n\n @EntryPoint()\n operation Main() : Unit {\n // n : Int, m : Int, t: Double, u : Double, tstep : Double\n
|
|
85
|
+
"code": "/// # Sample\n/// Quantum Dynamics\n///\n/// # Description\n/// This example demonstrates quantum dynamics in a style tailored for\n/// resource estimation. The sample is specifically the simulation\n/// of an Ising model Hamiltonian on an N1xN2 2D lattice using a\n/// fourth-order Trotter Suzuki product formula, assuming\n/// a 2D qubit architecture with nearest-neighbor connectivity.\n/// The is an example of a program that is not amenable to simulating\n/// classically, but can be run through resource estimation to determine\n/// what size of quantum system would be needed to solve the problem.\nnamespace QuantumDynamics {\n\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Arrays;\n\n\n @EntryPoint()\n operation Main() : Unit {\n // n : Int, m : Int, t: Double, u : Double, tstep : Double\n\n let n = 10;\n let m = 10;\n\n let J = 1.0;\n let g = 1.0;\n\n let totTime = 30.0;\n let dt = 0.9;\n\n IsingModel2DSim(n, m, J, g, totTime, dt);\n }\n\n /// # Summary\n /// The function below creates a sequence containing the rotation angles that will be applied with the two operators used in the expansion of the Trotter-Suzuki formula.\n /// # Input\n /// ## p (Double) : Constant used for fourth-order formulas\n ///\n /// ## dt (Double) : Time-step used to compute rotation angles\n ///\n /// ## J (Double) : coefficient for 2-qubit interactions\n ///\n /// ## g (Double) : coefficient for transverse field\n ///\n /// # Output\n /// ## values (Double[]) : The list of rotation angles to be applies in sequence with the corresponding operators\n ///\n function SetAngleSequence(p : Double, dt : Double, J : Double, g : Double) : Double[] {\n\n let len1 = 3;\n let len2 = 3;\n let valLength = 2*len1+len2+1;\n mutable values = [0.0, size=valLength];\n\n let val1 = J*p*dt;\n let val2 = -g*p*dt;\n let val3 = J*(1.0 - 3.0*p)*dt/2.0;\n let val4 = g*(1.0 - 4.0*p)*dt/2.0;\n\n for i in 0..len1 {\n\n if (i % 2 == 0) {\n set values w/= i <- val1;\n }\n else {\n set values w/= i <- val2;\n }\n\n }\n\n for i in len1+1..len1+len2 {\n if (i % 2 == 0) {\n set values w/= i <- val3;\n }\n else {\n set values w/= i <- val4;\n }\n }\n\n for i in len1+len2+1..valLength-1 {\n if (i % 2 == 0) {\n set values w/= i <- val1;\n }\n else {\n set values w/= i <- val2;\n }\n }\n return values;\n }\n\n /// # Summary\n /// Applies e^-iX(theta) on all qubits in the 2D lattice as part of simulating the transverse field in the Ising model\n /// # Input\n /// ## n (Int) : Lattice size for an n x n lattice\n ///\n /// ## qArr (Qubit[][]) : Array of qubits representing the lattice\n ///\n /// ## theta (Double) : The angle/time-step for which the unitary simulation is done.\n ///\n operation ApplyAllX(n : Int, qArr : Qubit[][], theta : Double) : Unit {\n // This applies `Rx` with an angle of `2.0 * theta` to all qubits in `qs`\n // using partial application\n for row in 0..n-1 {\n ApplyToEach(Rx(2.0 * theta, _), qArr[row]);\n }\n }\n\n /// # Summary\n /// Applies e^-iP(theta) where P = Z o Z as part of the repulsion terms.\n /// # Input\n /// ## n, m (Int, Int) : Lattice sizes for an n x m lattice\n ///\n /// ## qArr (Qubit[]) : Array of qubits representing the lattice\n ///\n /// ## theta (Double) : The angle/time-step for which unitary simulation is done.\n ///\n /// ## dir (Bool) : Direction is true for vertical direction.\n ///\n /// ## grp (Bool) : Group is true for odd starting indices\n ///\n operation ApplyDoubleZ(n : Int, m : Int, qArr : Qubit[][], theta : Double, dir : Bool, grp : Bool) : Unit {\n let start = grp ? 1 | 0; // Choose either odd or even indices based on group number\n let P_op = [PauliZ, PauliZ];\n let c_end = dir ? m-1 | m-2;\n let r_end = dir ? m-2 | m-1;\n\n for row in 0..r_end {\n for col in start..2..c_end { // Iterate through even or odd columns based on `grp`\n\n let row2 = dir ? row+1 | row;\n let col2 = dir ? col | col+1;\n\n Exp(P_op, theta, [qArr[row][col], qArr[row2][col2]]);\n }\n }\n }\n\n /// # Summary\n /// The main function that takes in various parameters and calls the operations needed to simulate fourth order Trotterizatiuon of the Ising Hamiltonian for a given time-step\n /// # Input\n /// ## N1, N2 (Int, Int) : Lattice sizes for an N1 x N2 lattice\n ///\n /// ## J (Double) : coefficient for 2-qubit interactions\n ///\n /// ## g (Double) : coefficient for transverse field\n ///\n /// ## totTime (Double) : The total time-step for which unitary simulation is done.\n ///\n /// ## dt (Double) : The time the simulation is done for each timestep\n ///\n operation IsingModel2DSim(N1 : Int, N2 : Int, J : Double, g : Double, totTime : Double, dt : Double) : Unit {\n\n use qs = Qubit[N1*N2];\n let qubitArray = Chunks(N2, qs); // qubits are re-arranged to be in an N1 x N2 array\n\n let p = 1.0 / (4.0 - 4.0^(1.0 / 3.0));\n let t = Ceiling(totTime / dt);\n\n let seqLen = 10 * t + 1;\n\n let angSeq = SetAngleSequence(p, dt, J, g);\n\n for i in 0..seqLen - 1 {\n let theta = (i==0 or i==seqLen-1) ? J*p*dt/2.0 | angSeq[i%10];\n\n // for even indexes\n if i % 2 == 0 {\n ApplyAllX(N1, qubitArray, theta);\n } else {\n // iterate through all possible combinations for `dir` and `grp`.\n for (dir, grp) in [(true, true), (true, false), (false, true), (false, false)] {\n ApplyDoubleZ(N1, N2, qubitArray, theta, dir, grp);\n }\n }\n }\n }\n\n}\n",
|
|
86
86
|
"omitFromTests": true
|
|
87
87
|
},
|
|
88
88
|
{
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { IServiceEventMessage, IServiceProxy, ServiceMethods, ServiceProtocol } from "./common.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates an initializes a service, setting it up to receive requests.
|
|
4
|
+
* This function to be is used in the worker.
|
|
5
|
+
*
|
|
6
|
+
* @param serviceProtocol An object that describes the service: its constructor, methods and events
|
|
7
|
+
* @returns A message handler to be assigned to the `self.onmessage` handler in a web worker
|
|
8
|
+
*/
|
|
9
|
+
export declare function createWorker<TService extends ServiceMethods<TService>, TServiceEventMsg extends IServiceEventMessage>(serviceProtocol: ServiceProtocol<TService, TServiceEventMsg>): (e: MessageEvent) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Creates and initializes a service in a web worker, and returns a proxy for the service
|
|
12
|
+
* to be used from the main thread.
|
|
13
|
+
*
|
|
14
|
+
* @param workerArg The service web worker or the URL of the web worker script.
|
|
15
|
+
* @param wasmModule The wasm module to initialize the service with
|
|
16
|
+
* @param serviceProtocol An object that describes the service: its constructor, methods and events
|
|
17
|
+
* @returns A proxy object that implements the service interface.
|
|
18
|
+
* This interface can now be used as if calling into the real service,
|
|
19
|
+
* and the calls will be proxied to the web worker.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createProxy<TService extends ServiceMethods<TService>, TServiceEventMsg extends IServiceEventMessage>(workerArg: string | Worker, wasmModule: WebAssembly.Module, serviceProtocol: ServiceProtocol<TService, TServiceEventMsg>): TService & IServiceProxy;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import * as wasm from "../../lib/web/qsc_wasm.js";
|
|
4
|
+
import { log } from "../log.js";
|
|
5
|
+
import { createProxyInternal, initService, } from "./common.js";
|
|
6
|
+
/**
|
|
7
|
+
* Creates an initializes a service, setting it up to receive requests.
|
|
8
|
+
* This function to be is used in the worker.
|
|
9
|
+
*
|
|
10
|
+
* @param serviceProtocol An object that describes the service: its constructor, methods and events
|
|
11
|
+
* @returns A message handler to be assigned to the `self.onmessage` handler in a web worker
|
|
12
|
+
*/
|
|
13
|
+
export function createWorker(serviceProtocol) {
|
|
14
|
+
let invokeService = null;
|
|
15
|
+
// This export should be assigned to 'self.onmessage' in a WebWorker
|
|
16
|
+
return function messageHandler(e) {
|
|
17
|
+
const data = e.data;
|
|
18
|
+
if (!data.type || typeof data.type !== "string") {
|
|
19
|
+
log.error(`Unrecognized msg: ${data}`);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
switch (data.type) {
|
|
23
|
+
case "init":
|
|
24
|
+
{
|
|
25
|
+
wasm.initSync(data.wasmModule);
|
|
26
|
+
invokeService = initService(self.postMessage.bind(self), serviceProtocol, wasm, data.qscLogLevel);
|
|
27
|
+
}
|
|
28
|
+
break;
|
|
29
|
+
default:
|
|
30
|
+
if (!invokeService) {
|
|
31
|
+
log.error(`Received message before the service was initialized: %o`, data);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
invokeService(data);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates and initializes a service in a web worker, and returns a proxy for the service
|
|
41
|
+
* to be used from the main thread.
|
|
42
|
+
*
|
|
43
|
+
* @param workerArg The service web worker or the URL of the web worker script.
|
|
44
|
+
* @param wasmModule The wasm module to initialize the service with
|
|
45
|
+
* @param serviceProtocol An object that describes the service: its constructor, methods and events
|
|
46
|
+
* @returns A proxy object that implements the service interface.
|
|
47
|
+
* This interface can now be used as if calling into the real service,
|
|
48
|
+
* and the calls will be proxied to the web worker.
|
|
49
|
+
*/
|
|
50
|
+
export function createProxy(workerArg, wasmModule, serviceProtocol) {
|
|
51
|
+
// Create or use the WebWorker
|
|
52
|
+
const worker = typeof workerArg === "string" ? new Worker(workerArg) : workerArg;
|
|
53
|
+
// Send it the Wasm module to instantiate
|
|
54
|
+
worker.postMessage({
|
|
55
|
+
type: "init",
|
|
56
|
+
wasmModule,
|
|
57
|
+
qscLogLevel: log.getLogLevel(),
|
|
58
|
+
});
|
|
59
|
+
// If you lose the 'this' binding, some environments have issues
|
|
60
|
+
const postMessage = worker.postMessage.bind(worker);
|
|
61
|
+
const onTerminate = () => worker.terminate();
|
|
62
|
+
// Create the proxy which will forward method calls to the worker
|
|
63
|
+
const proxy = createProxyInternal(postMessage, onTerminate, serviceProtocol.methods);
|
|
64
|
+
// Let proxy handle response and event messages from the worker
|
|
65
|
+
worker.onmessage = (ev) => proxy.onMsgFromWorker(ev.data);
|
|
66
|
+
return proxy;
|
|
67
|
+
}
|
|
@@ -1,17 +1,34 @@
|
|
|
1
|
+
type Wasm = typeof import("../../lib/node/qsc_wasm.cjs");
|
|
2
|
+
/**
|
|
3
|
+
* Describes a service that can be run in a worker.
|
|
4
|
+
*/
|
|
5
|
+
export interface ServiceProtocol<TService extends ServiceMethods<TService>, TServiceEventMsg extends IServiceEventMessage> {
|
|
6
|
+
/** The concrete class that implements the service. */
|
|
7
|
+
class: {
|
|
8
|
+
new (wasmModule: Wasm): TService;
|
|
9
|
+
};
|
|
10
|
+
/** Methods that can be proxied from the main thread to the worker. @see MethodMap*/
|
|
11
|
+
methods: MethodMap<TService>;
|
|
12
|
+
/** Events that can be received by the main thread from the worker. */
|
|
13
|
+
eventNames: TServiceEventMsg["type"][];
|
|
14
|
+
}
|
|
1
15
|
/**
|
|
2
16
|
* Used as a type constraint for a "service", i.e. an object
|
|
3
17
|
* we can create proxy methods for. The type shouldn't define
|
|
4
18
|
* any non-method properties.
|
|
5
19
|
*/
|
|
6
|
-
type ServiceMethods<T> = {
|
|
20
|
+
export type ServiceMethods<T> = {
|
|
7
21
|
[x in keyof T]: (...args: any[]) => any;
|
|
8
22
|
};
|
|
9
23
|
/**
|
|
10
24
|
* Defines the service methods that the proxy will handle and their types.
|
|
25
|
+
*
|
|
11
26
|
* "request" is a normal async method.
|
|
12
|
-
*
|
|
27
|
+
*
|
|
28
|
+
* "requestWithProgress" methods take an `IServiceEventTarget` to
|
|
13
29
|
* communicate events back to the main thread as they run. They also set
|
|
14
30
|
* the service state to "busy" while they run.
|
|
31
|
+
*
|
|
15
32
|
* "addEventListener" and "removeEventListener" methods are used to
|
|
16
33
|
* subscribe to events from the service.
|
|
17
34
|
*/
|
|
@@ -52,7 +69,7 @@ export type EventMessage<TEventMsg extends IServiceEventMessage> = {
|
|
|
52
69
|
messageType: "event";
|
|
53
70
|
} & TEventMsg;
|
|
54
71
|
/** Used as a constraint for events defined by the service */
|
|
55
|
-
interface IServiceEventMessage {
|
|
72
|
+
export interface IServiceEventMessage {
|
|
56
73
|
type: string;
|
|
57
74
|
detail: unknown;
|
|
58
75
|
}
|
|
@@ -78,18 +95,18 @@ export interface IServiceEventTarget<TEvents extends IServiceEventMessage> {
|
|
|
78
95
|
* @returns The proxy object. The caller should then set the onMsgFromWorker
|
|
79
96
|
* property to a callback that will receive messages from the worker.
|
|
80
97
|
*/
|
|
81
|
-
export declare function
|
|
98
|
+
export declare function createProxyInternal<TService extends ServiceMethods<TService>, TServiceEventMsg extends IServiceEventMessage>(postMessage: (msg: RequestMessage<TService>) => void, terminator: () => void, methods: MethodMap<TService>): TService & IServiceProxy & {
|
|
82
99
|
onMsgFromWorker: (msg: ResponseMessage<TService> | EventMessage<TServiceEventMsg>) => void;
|
|
83
100
|
};
|
|
84
101
|
/**
|
|
85
|
-
*
|
|
102
|
+
* Creates and initializes the actual service. To be used in the worker thread.
|
|
86
103
|
*
|
|
87
|
-
* @param service The service to be wrapped
|
|
88
|
-
* @param methods A map of method names. Should match the list passed into @see createProxy.
|
|
89
|
-
* @param eventNames The list of event names that the service can emit
|
|
90
104
|
* @param postMessage A function to post messages back to the main thread
|
|
105
|
+
* @param serviceProtocol An object that describes the service: its constructor, methods and events
|
|
106
|
+
* @param wasm The wasm module to initialize the service with
|
|
107
|
+
* @param qscLogLevel The log level to initialize the service with
|
|
91
108
|
* @returns A function that takes a message and invokes the corresponding
|
|
92
109
|
* method on the service. The caller should then set this method as a message handler.
|
|
93
110
|
*/
|
|
94
|
-
export declare function
|
|
111
|
+
export declare function initService<TService extends ServiceMethods<TService>, TServiceEventMsg extends IServiceEventMessage>(postMessage: (msg: ResponseMessage<TService> | EventMessage<TServiceEventMsg>) => void, serviceProtocol: ServiceProtocol<TService, TServiceEventMsg>, wasm: Wasm, qscLogLevel?: number): (req: RequestMessage<TService>) => Promise<void>;
|
|
95
112
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
|
-
import { log } from "
|
|
3
|
+
import { log } from "../log.js";
|
|
4
4
|
/*
|
|
5
5
|
The WorkerProxy works by queuing up requests to send over to the Worker, only
|
|
6
6
|
ever having one in flight at a time. By queuing on the caller side, this allows
|
|
@@ -23,7 +23,7 @@ complete the request.
|
|
|
23
23
|
* @returns The proxy object. The caller should then set the onMsgFromWorker
|
|
24
24
|
* property to a callback that will receive messages from the worker.
|
|
25
25
|
*/
|
|
26
|
-
export function
|
|
26
|
+
export function createProxyInternal(postMessage, terminator, methods) {
|
|
27
27
|
const queue = [];
|
|
28
28
|
const eventTarget = new EventTarget();
|
|
29
29
|
let curr;
|
|
@@ -172,13 +172,13 @@ export function createProxy(postMessage, terminator, methods) {
|
|
|
172
172
|
* Function to wrap a service in a dispatcher. To be used in the worker thread.
|
|
173
173
|
*
|
|
174
174
|
* @param service The service to be wrapped
|
|
175
|
-
* @param methods A map of method names. Should match the list passed into @see
|
|
175
|
+
* @param methods A map of method names. Should match the list passed into @see createProxyInternal.
|
|
176
176
|
* @param eventNames The list of event names that the service can emit
|
|
177
177
|
* @param postMessage A function to post messages back to the main thread
|
|
178
178
|
* @returns A function that takes a message and invokes the corresponding
|
|
179
179
|
* method on the service. The caller should then set this method as a message handler.
|
|
180
180
|
*/
|
|
181
|
-
|
|
181
|
+
function createDispatcher(postMessage, service, methods, eventNames) {
|
|
182
182
|
log.debug("Worker: Constructing WorkerEventHandler");
|
|
183
183
|
function logAndPost(msg) {
|
|
184
184
|
log.debug("Worker: Sending %s message from worker: %o", msg.messageType, msg);
|
|
@@ -224,3 +224,32 @@ export function createDispatcher(postMessage, service, methods, eventNames) {
|
|
|
224
224
|
}));
|
|
225
225
|
};
|
|
226
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Creates and initializes the actual service. To be used in the worker thread.
|
|
229
|
+
*
|
|
230
|
+
* @param postMessage A function to post messages back to the main thread
|
|
231
|
+
* @param serviceProtocol An object that describes the service: its constructor, methods and events
|
|
232
|
+
* @param wasm The wasm module to initialize the service with
|
|
233
|
+
* @param qscLogLevel The log level to initialize the service with
|
|
234
|
+
* @returns A function that takes a message and invokes the corresponding
|
|
235
|
+
* method on the service. The caller should then set this method as a message handler.
|
|
236
|
+
*/
|
|
237
|
+
export function initService(postMessage, serviceProtocol, wasm, qscLogLevel) {
|
|
238
|
+
function telemetryHandler(telemetry) {
|
|
239
|
+
postMessage({
|
|
240
|
+
messageType: "event",
|
|
241
|
+
type: "telemetry-event",
|
|
242
|
+
detail: telemetry,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
if (qscLogLevel !== undefined) {
|
|
246
|
+
log.setLogLevel(qscLogLevel);
|
|
247
|
+
}
|
|
248
|
+
// Set up logging and telemetry as soon as possible after instantiating
|
|
249
|
+
log.onLevelChanged = (level) => wasm.setLogLevel(level);
|
|
250
|
+
log.setTelemetryCollector(telemetryHandler);
|
|
251
|
+
wasm.initLogging(log.logWithLevel, log.getLogLevel());
|
|
252
|
+
// Create the actual service and return the dispatcher method
|
|
253
|
+
const service = new serviceProtocol.class(wasm);
|
|
254
|
+
return createDispatcher(postMessage, service, serviceProtocol.methods, serviceProtocol.eventNames);
|
|
255
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IServiceEventMessage, IServiceProxy, ServiceMethods, ServiceProtocol } from "./common.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates an initializes a service, setting it up to receive requests.
|
|
4
|
+
* This function to be is used in the worker.
|
|
5
|
+
*
|
|
6
|
+
* @param serviceProtocol An object that describes the service: its constructor, methods and events
|
|
7
|
+
*/
|
|
8
|
+
export declare function createWorker<TService extends ServiceMethods<TService>, TServiceEventMsg extends IServiceEventMessage>(protocol: ServiceProtocol<TService, TServiceEventMsg>): void;
|
|
9
|
+
/**
|
|
10
|
+
* Creates and initializes a service in a worker thread, and returns a proxy for the service
|
|
11
|
+
* to be used from the main thread.
|
|
12
|
+
*
|
|
13
|
+
* @param workerArg The the URL of the service web worker script.
|
|
14
|
+
* @param wasmModule The wasm module to initialize the service with
|
|
15
|
+
* @param serviceProtocol An object that describes the service: its constructor, methods and events
|
|
16
|
+
* @returns A proxy object that implements the service interface.
|
|
17
|
+
* This interface can now be used as if calling into the real service,
|
|
18
|
+
* and the calls will be proxied to the web worker.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createProxy<TService extends ServiceMethods<TService>, TServiceEventMsg extends IServiceEventMessage>(workerArg: string, serviceProtocol: ServiceProtocol<TService, TServiceEventMsg>): TService & IServiceProxy;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { Worker, isMainThread, parentPort, workerData, } from "node:worker_threads";
|
|
6
|
+
import * as wasm from "../../lib/node/qsc_wasm.cjs";
|
|
7
|
+
import { log } from "../log.js";
|
|
8
|
+
import { createProxyInternal, initService, } from "./common.js";
|
|
9
|
+
/**
|
|
10
|
+
* Creates an initializes a service, setting it up to receive requests.
|
|
11
|
+
* This function to be is used in the worker.
|
|
12
|
+
*
|
|
13
|
+
* @param serviceProtocol An object that describes the service: its constructor, methods and events
|
|
14
|
+
*/
|
|
15
|
+
export function createWorker(protocol) {
|
|
16
|
+
if (isMainThread)
|
|
17
|
+
throw "Worker script should be loaded in a Worker thread only";
|
|
18
|
+
const port = parentPort; // eslint-disable-line @typescript-eslint/no-non-null-assertion
|
|
19
|
+
const postMessage = port.postMessage.bind(port);
|
|
20
|
+
const invokeService = initService(postMessage, protocol, wasm, workerData && typeof workerData.qscLogLevel === "number"
|
|
21
|
+
? workerData.qscLogLevel
|
|
22
|
+
: undefined);
|
|
23
|
+
function messageHandler(data) {
|
|
24
|
+
if (!data.type || typeof data.type !== "string") {
|
|
25
|
+
log.error(`Unrecognized msg: %O"`, data);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
invokeService(data);
|
|
29
|
+
}
|
|
30
|
+
port.addListener("message", messageHandler);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Creates and initializes a service in a worker thread, and returns a proxy for the service
|
|
34
|
+
* to be used from the main thread.
|
|
35
|
+
*
|
|
36
|
+
* @param workerArg The the URL of the service web worker script.
|
|
37
|
+
* @param wasmModule The wasm module to initialize the service with
|
|
38
|
+
* @param serviceProtocol An object that describes the service: its constructor, methods and events
|
|
39
|
+
* @returns A proxy object that implements the service interface.
|
|
40
|
+
* This interface can now be used as if calling into the real service,
|
|
41
|
+
* and the calls will be proxied to the web worker.
|
|
42
|
+
*/
|
|
43
|
+
export function createProxy(workerArg, serviceProtocol) {
|
|
44
|
+
const thisDir = dirname(fileURLToPath(import.meta.url));
|
|
45
|
+
const worker = new Worker(join(thisDir, workerArg), {
|
|
46
|
+
workerData: { qscLogLevel: log.getLogLevel() },
|
|
47
|
+
});
|
|
48
|
+
// Create the proxy which will forward method calls to the worker
|
|
49
|
+
const proxy = createProxyInternal(
|
|
50
|
+
// If you lose the 'this' binding, some environments have issues.
|
|
51
|
+
worker.postMessage.bind(worker), () => worker.terminate(), serviceProtocol.methods);
|
|
52
|
+
// Let proxy handle response and event messages from the worker
|
|
53
|
+
worker.addListener("message", proxy.onMsgFromWorker);
|
|
54
|
+
return proxy;
|
|
55
|
+
}
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
---
|
|
2
|
-
uid: Microsoft.Quantum.Arrays.All
|
|
2
|
+
uid: Qdk.Microsoft.Quantum.Arrays.All
|
|
3
3
|
title: All function
|
|
4
|
-
ms.date: 02/
|
|
4
|
+
ms.date: 02/23/2024 12:00:00 AM
|
|
5
5
|
ms.topic: managed-reference
|
|
6
6
|
qsharp.kind: function
|
|
7
7
|
qsharp.namespace: Microsoft.Quantum.Arrays
|
|
8
8
|
qsharp.name: All
|
|
9
|
-
qsharp.summary: Given an array and a predicate that is defined
|
|
10
|
-
for the elements of the array, and checks if all elements of the
|
|
11
|
-
array satisfy the predicate.
|
|
9
|
+
qsharp.summary: Given an array and a predicate that is defined for the elements of the array, and checks if all elements of the array satisfy the predicate.
|
|
12
10
|
---
|
|
13
11
|
|
|
14
12
|
# All function
|
|
15
13
|
|
|
16
|
-
Namespace:
|
|
14
|
+
Namespace: Microsoft.Quantum.Arrays
|
|
17
15
|
|
|
18
16
|
```qsharp
|
|
19
17
|
function All<'T>(predicate : ('T -> Bool), array : 'T[]) : Bool
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
---
|
|
2
|
-
uid: Microsoft.Quantum.Arrays.Any
|
|
2
|
+
uid: Qdk.Microsoft.Quantum.Arrays.Any
|
|
3
3
|
title: Any function
|
|
4
|
-
ms.date: 02/
|
|
4
|
+
ms.date: 02/23/2024 12:00:00 AM
|
|
5
5
|
ms.topic: managed-reference
|
|
6
6
|
qsharp.kind: function
|
|
7
7
|
qsharp.namespace: Microsoft.Quantum.Arrays
|
|
8
8
|
qsharp.name: Any
|
|
9
|
-
qsharp.summary: Given an array and a predicate that is defined
|
|
10
|
-
for the elements of the array, checks if at least one element of
|
|
11
|
-
the array satisfies the predicate.
|
|
9
|
+
qsharp.summary: Given an array and a predicate that is defined for the elements of the array, checks if at least one element of the array satisfies the predicate.
|
|
12
10
|
---
|
|
13
11
|
|
|
14
12
|
# Any function
|
|
15
13
|
|
|
16
|
-
Namespace:
|
|
14
|
+
Namespace: Microsoft.Quantum.Arrays
|
|
17
15
|
|
|
18
16
|
```qsharp
|
|
19
17
|
function Any<'T>(predicate : ('T -> Bool), array : 'T[]) : Bool
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
uid: Microsoft.Quantum.Arrays.Chunks
|
|
2
|
+
uid: Qdk.Microsoft.Quantum.Arrays.Chunks
|
|
3
3
|
title: Chunks function
|
|
4
|
-
ms.date: 02/
|
|
4
|
+
ms.date: 02/23/2024 12:00:00 AM
|
|
5
5
|
ms.topic: managed-reference
|
|
6
6
|
qsharp.kind: function
|
|
7
7
|
qsharp.namespace: Microsoft.Quantum.Arrays
|
|
@@ -11,7 +11,7 @@ qsharp.summary: Splits an array into multiple parts of equal length.
|
|
|
11
11
|
|
|
12
12
|
# Chunks function
|
|
13
13
|
|
|
14
|
-
Namespace:
|
|
14
|
+
Namespace: Microsoft.Quantum.Arrays
|
|
15
15
|
|
|
16
16
|
```qsharp
|
|
17
17
|
function Chunks<'T>(chunkSize : Int, array : 'T[]) : 'T[][]
|