qsharp-lang 1.3.4-dev → 1.3.6-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 +2 -2
- package/dist/compiler/compiler.d.ts +11 -5
- package/dist/compiler/compiler.js +15 -6
- package/dist/debug-service/debug-service.d.ts +2 -2
- package/dist/katas-content.generated.js +306 -76
- package/dist/language-service/language-service.d.ts +2 -2
- package/dist/main.d.ts +1 -1
- package/dist/main.js +12 -18
- package/dist/workers/common.d.ts +1 -1
- package/dist/workers/node.js +2 -1
- package/docs/Microsoft.Quantum.Arrays/All.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Any.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Chunks.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/CircularlyShifted.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/ColumnAt.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Count.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Diagonal.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/DrawMany.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Enumerated.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Excluding.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Filtered.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/FlatMapped.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Flattened.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Fold.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/ForEach.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Head.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/HeadAndRest.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/IndexOf.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/IndexRange.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Interleaved.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/IsEmpty.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/IsRectangularArray.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/IsSorted.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/IsSquareArray.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Mapped.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/MappedByIndex.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/MappedOverRange.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Most.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/MostAndTail.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Padded.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Partitioned.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Rest.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Reversed.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/SequenceI.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/SequenceL.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Sorted.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Subarray.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Swapped.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Tail.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Transposed.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Unzipped.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Where.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Windows.md +1 -1
- package/docs/Microsoft.Quantum.Arrays/Zipped.md +1 -1
- package/docs/Microsoft.Quantum.Canon/ApplyCNOTChain.md +1 -1
- package/docs/Microsoft.Quantum.Canon/ApplyControlledOnBitString.md +1 -1
- package/docs/Microsoft.Quantum.Canon/ApplyControlledOnInt.md +1 -1
- package/docs/Microsoft.Quantum.Canon/ApplyP.md +1 -1
- package/docs/Microsoft.Quantum.Canon/ApplyPauli.md +1 -1
- package/docs/Microsoft.Quantum.Canon/ApplyPauliFromBitString.md +1 -1
- package/docs/Microsoft.Quantum.Canon/ApplyPauliFromInt.md +1 -1
- package/docs/Microsoft.Quantum.Canon/ApplyQFT.md +1 -1
- package/docs/Microsoft.Quantum.Canon/ApplyToEach.md +1 -1
- package/docs/Microsoft.Quantum.Canon/ApplyToEachA.md +1 -1
- package/docs/Microsoft.Quantum.Canon/ApplyToEachC.md +1 -1
- package/docs/Microsoft.Quantum.Canon/ApplyToEachCA.md +1 -1
- package/docs/Microsoft.Quantum.Canon/ApplyXorInPlace.md +1 -1
- package/docs/Microsoft.Quantum.Canon/ApplyXorInPlaceL.md +1 -1
- package/docs/Microsoft.Quantum.Canon/CX.md +1 -1
- package/docs/Microsoft.Quantum.Canon/CY.md +1 -1
- package/docs/Microsoft.Quantum.Canon/CZ.md +1 -1
- package/docs/Microsoft.Quantum.Canon/Fst.md +1 -1
- package/docs/Microsoft.Quantum.Canon/Snd.md +1 -1
- package/docs/Microsoft.Quantum.Canon/SwapReverseRegister.md +1 -1
- package/docs/Microsoft.Quantum.Convert/BigIntAsBoolArray.md +1 -1
- package/docs/Microsoft.Quantum.Convert/BoolArrayAsBigInt.md +1 -1
- package/docs/Microsoft.Quantum.Convert/BoolArrayAsInt.md +1 -1
- package/docs/Microsoft.Quantum.Convert/BoolArrayAsResultArray.md +1 -1
- package/docs/Microsoft.Quantum.Convert/BoolAsResult.md +1 -1
- package/docs/Microsoft.Quantum.Convert/ComplexAsComplexPolar.md +1 -1
- package/docs/Microsoft.Quantum.Convert/ComplexPolarAsComplex.md +1 -1
- package/docs/Microsoft.Quantum.Convert/IntAsBigInt.md +1 -1
- package/docs/Microsoft.Quantum.Convert/IntAsBoolArray.md +1 -1
- package/docs/Microsoft.Quantum.Convert/IntAsDouble.md +1 -1
- package/docs/Microsoft.Quantum.Convert/ResultArrayAsBoolArray.md +1 -1
- package/docs/Microsoft.Quantum.Convert/ResultArrayAsInt.md +1 -1
- package/docs/Microsoft.Quantum.Convert/ResultAsBool.md +1 -1
- package/docs/Microsoft.Quantum.Core/IsRangeEmpty.md +1 -1
- package/docs/Microsoft.Quantum.Core/Length.md +1 -1
- package/docs/Microsoft.Quantum.Core/RangeEnd.md +1 -1
- package/docs/Microsoft.Quantum.Core/RangeReverse.md +1 -1
- package/docs/Microsoft.Quantum.Core/RangeStart.md +1 -1
- package/docs/Microsoft.Quantum.Core/RangeStep.md +1 -1
- package/docs/Microsoft.Quantum.Core/Repeated.md +1 -1
- package/docs/Microsoft.Quantum.Diagnostics/CheckAllZero.md +1 -1
- package/docs/Microsoft.Quantum.Diagnostics/CheckOperationsAreEqual.md +1 -1
- package/docs/Microsoft.Quantum.Diagnostics/CheckZero.md +1 -1
- package/docs/Microsoft.Quantum.Diagnostics/DumpMachine.md +1 -1
- package/docs/Microsoft.Quantum.Diagnostics/DumpRegister.md +1 -1
- package/docs/Microsoft.Quantum.Diagnostics/Fact.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/CCNOT.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/CNOT.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/Exp.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/H.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/I.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/M.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/Measure.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/Message.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/R.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/R1.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/R1Frac.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/RFrac.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/Reset.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/ResetAll.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/Rx.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/Rxx.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/Ry.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/Ryy.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/Rz.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/Rzz.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/S.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/SWAP.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/T.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/X.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/Y.md +1 -1
- package/docs/Microsoft.Quantum.Intrinsic/Z.md +1 -1
- package/docs/Microsoft.Quantum.Logical/Xor.md +1 -1
- package/docs/Microsoft.Quantum.Math/AbsComplex.md +1 -1
- package/docs/Microsoft.Quantum.Math/AbsComplexPolar.md +1 -1
- package/docs/Microsoft.Quantum.Math/AbsD.md +1 -1
- package/docs/Microsoft.Quantum.Math/AbsI.md +1 -1
- package/docs/Microsoft.Quantum.Math/AbsL.md +1 -1
- package/docs/Microsoft.Quantum.Math/AbsSquaredComplex.md +1 -1
- package/docs/Microsoft.Quantum.Math/AbsSquaredComplexPolar.md +1 -1
- package/docs/Microsoft.Quantum.Math/ApproximateFactorial.md +1 -1
- package/docs/Microsoft.Quantum.Math/ArcCos.md +1 -1
- package/docs/Microsoft.Quantum.Math/ArcCosh.md +1 -1
- package/docs/Microsoft.Quantum.Math/ArcSin.md +1 -1
- package/docs/Microsoft.Quantum.Math/ArcSinh.md +1 -1
- package/docs/Microsoft.Quantum.Math/ArcTan.md +1 -1
- package/docs/Microsoft.Quantum.Math/ArcTan2.md +1 -1
- package/docs/Microsoft.Quantum.Math/ArcTanh.md +1 -1
- package/docs/Microsoft.Quantum.Math/ArgComplex.md +1 -1
- package/docs/Microsoft.Quantum.Math/ArgComplexPolar.md +1 -1
- package/docs/Microsoft.Quantum.Math/Binom.md +1 -1
- package/docs/Microsoft.Quantum.Math/BitSizeI.md +1 -1
- package/docs/Microsoft.Quantum.Math/BitSizeL.md +1 -1
- package/docs/Microsoft.Quantum.Math/Ceiling.md +1 -1
- package/docs/Microsoft.Quantum.Math/Complex.md +1 -1
- package/docs/Microsoft.Quantum.Math/ComplexPolar.md +1 -1
- package/docs/Microsoft.Quantum.Math/ContinuedFractionConvergentI.md +1 -1
- package/docs/Microsoft.Quantum.Math/ContinuedFractionConvergentL.md +1 -1
- package/docs/Microsoft.Quantum.Math/Cos.md +1 -1
- package/docs/Microsoft.Quantum.Math/Cosh.md +1 -1
- package/docs/Microsoft.Quantum.Math/DivRemI.md +1 -1
- package/docs/Microsoft.Quantum.Math/DivRemL.md +1 -1
- package/docs/Microsoft.Quantum.Math/DividedByC.md +1 -1
- package/docs/Microsoft.Quantum.Math/DividedByCP.md +1 -1
- package/docs/Microsoft.Quantum.Math/E.md +1 -1
- package/docs/Microsoft.Quantum.Math/ExpModI.md +1 -1
- package/docs/Microsoft.Quantum.Math/ExpModL.md +1 -1
- package/docs/Microsoft.Quantum.Math/ExtendedGreatestCommonDivisorI.md +1 -1
- package/docs/Microsoft.Quantum.Math/ExtendedGreatestCommonDivisorL.md +1 -1
- package/docs/Microsoft.Quantum.Math/FactorialI.md +1 -1
- package/docs/Microsoft.Quantum.Math/FactorialL.md +1 -1
- package/docs/Microsoft.Quantum.Math/Floor.md +1 -1
- package/docs/Microsoft.Quantum.Math/GreatestCommonDivisorI.md +1 -1
- package/docs/Microsoft.Quantum.Math/GreatestCommonDivisorL.md +1 -1
- package/docs/Microsoft.Quantum.Math/HammingWeightI.md +1 -1
- package/docs/Microsoft.Quantum.Math/InverseModI.md +1 -1
- package/docs/Microsoft.Quantum.Math/InverseModL.md +1 -1
- package/docs/Microsoft.Quantum.Math/IsCoprimeI.md +1 -1
- package/docs/Microsoft.Quantum.Math/IsCoprimeL.md +1 -1
- package/docs/Microsoft.Quantum.Math/IsInfinite.md +1 -1
- package/docs/Microsoft.Quantum.Math/IsNaN.md +1 -1
- package/docs/Microsoft.Quantum.Math/LargestFixedPoint.md +1 -1
- package/docs/Microsoft.Quantum.Math/Lg.md +1 -1
- package/docs/Microsoft.Quantum.Math/Log.md +1 -1
- package/docs/Microsoft.Quantum.Math/Log10.md +1 -1
- package/docs/Microsoft.Quantum.Math/LogFactorialD.md +1 -1
- package/docs/Microsoft.Quantum.Math/LogGammaD.md +1 -1
- package/docs/Microsoft.Quantum.Math/LogOf2.md +1 -1
- package/docs/Microsoft.Quantum.Math/Max.md +1 -1
- package/docs/Microsoft.Quantum.Math/MaxD.md +1 -1
- package/docs/Microsoft.Quantum.Math/MaxI.md +1 -1
- package/docs/Microsoft.Quantum.Math/MaxL.md +1 -1
- package/docs/Microsoft.Quantum.Math/Min.md +1 -1
- package/docs/Microsoft.Quantum.Math/MinD.md +1 -1
- package/docs/Microsoft.Quantum.Math/MinI.md +1 -1
- package/docs/Microsoft.Quantum.Math/MinL.md +1 -1
- package/docs/Microsoft.Quantum.Math/MinusC.md +1 -1
- package/docs/Microsoft.Quantum.Math/MinusCP.md +1 -1
- package/docs/Microsoft.Quantum.Math/ModulusI.md +1 -1
- package/docs/Microsoft.Quantum.Math/ModulusL.md +1 -1
- package/docs/Microsoft.Quantum.Math/NegationC.md +1 -1
- package/docs/Microsoft.Quantum.Math/NegationCP.md +1 -1
- package/docs/Microsoft.Quantum.Math/PI.md +1 -1
- package/docs/Microsoft.Quantum.Math/PNorm.md +1 -1
- package/docs/Microsoft.Quantum.Math/PNormalized.md +1 -1
- package/docs/Microsoft.Quantum.Math/PlusC.md +1 -1
- package/docs/Microsoft.Quantum.Math/PlusCP.md +1 -1
- package/docs/Microsoft.Quantum.Math/PowC.md +1 -1
- package/docs/Microsoft.Quantum.Math/PowCP.md +1 -1
- package/docs/Microsoft.Quantum.Math/RealMod.md +1 -1
- package/docs/Microsoft.Quantum.Math/Round.md +1 -1
- package/docs/Microsoft.Quantum.Math/SignD.md +1 -1
- package/docs/Microsoft.Quantum.Math/SignI.md +1 -1
- package/docs/Microsoft.Quantum.Math/SignL.md +1 -1
- package/docs/Microsoft.Quantum.Math/Sin.md +1 -1
- package/docs/Microsoft.Quantum.Math/Sinh.md +1 -1
- package/docs/Microsoft.Quantum.Math/SmallestFixedPoint.md +1 -1
- package/docs/Microsoft.Quantum.Math/Sqrt.md +1 -1
- package/docs/Microsoft.Quantum.Math/SquaredNorm.md +1 -1
- package/docs/Microsoft.Quantum.Math/Tan.md +1 -1
- package/docs/Microsoft.Quantum.Math/Tanh.md +1 -1
- package/docs/Microsoft.Quantum.Math/TimesC.md +1 -1
- package/docs/Microsoft.Quantum.Math/TimesCP.md +1 -1
- package/docs/Microsoft.Quantum.Math/TrailingZeroCountI.md +1 -1
- package/docs/Microsoft.Quantum.Math/TrailingZeroCountL.md +1 -1
- package/docs/Microsoft.Quantum.Math/Truncate.md +1 -1
- package/docs/Microsoft.Quantum.Measurement/MResetEachZ.md +1 -1
- package/docs/Microsoft.Quantum.Measurement/MResetX.md +1 -1
- package/docs/Microsoft.Quantum.Measurement/MResetY.md +1 -1
- package/docs/Microsoft.Quantum.Measurement/MResetZ.md +1 -1
- package/docs/Microsoft.Quantum.Measurement/MeasureAllZ.md +1 -1
- package/docs/Microsoft.Quantum.Measurement/MeasureEachZ.md +1 -1
- package/docs/Microsoft.Quantum.Measurement/MeasureInteger.md +1 -1
- package/docs/Microsoft.Quantum.Random/DrawRandomDouble.md +1 -1
- package/docs/Microsoft.Quantum.Random/DrawRandomInt.md +1 -1
- package/docs/Microsoft.Quantum.ResourceEstimation/AccountForEstimates.md +1 -1
- package/docs/Microsoft.Quantum.ResourceEstimation/AuxQubitCount.md +1 -1
- package/docs/Microsoft.Quantum.ResourceEstimation/BeginEstimateCaching.md +1 -1
- package/docs/Microsoft.Quantum.ResourceEstimation/BeginRepeatEstimates.md +1 -1
- package/docs/Microsoft.Quantum.ResourceEstimation/CczCount.md +1 -1
- package/docs/Microsoft.Quantum.ResourceEstimation/EndEstimateCaching.md +1 -1
- package/docs/Microsoft.Quantum.ResourceEstimation/EndRepeatEstimates.md +1 -1
- package/docs/Microsoft.Quantum.ResourceEstimation/MeasurementCount.md +1 -1
- package/docs/Microsoft.Quantum.ResourceEstimation/PSSPCLayout.md +1 -1
- package/docs/Microsoft.Quantum.ResourceEstimation/RepeatEstimates.md +1 -1
- package/docs/Microsoft.Quantum.ResourceEstimation/RotationCount.md +1 -1
- package/docs/Microsoft.Quantum.ResourceEstimation/RotationDepth.md +1 -1
- package/docs/Microsoft.Quantum.ResourceEstimation/SingleVariant.md +1 -1
- package/docs/Microsoft.Quantum.ResourceEstimation/TCount.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/AddLE.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfEqualL.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfEqualLE.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterL.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterLE.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterOrEqualL.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterOrEqualLE.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessL.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessLE.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessOrEqualL.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessOrEqualLE.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/FourierTDIncByLE.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByI.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByIUsingIncByLE.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByL.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLE.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLEUsingAddLE.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLUsingIncByLE.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/LookAheadDKRSAddLE.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/MAJ.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/ReflectAboutInteger.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryCGAddLE.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryCGIncByLE.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryTTKIncByLE.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.StatePreparation/ApproximatelyPreparePureStateCP.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.StatePreparation/PreparePureStateD.md +1 -1
- package/docs/Microsoft.Quantum.Unstable.TableLookup/Select.md +1 -1
- package/lib/node/qsc_wasm.cjs +60 -21
- package/lib/node/qsc_wasm.d.cts +21 -7
- package/lib/node/qsc_wasm_bg.wasm +0 -0
- package/lib/web/qsc_wasm.d.ts +25 -10
- package/lib/web/qsc_wasm.js +60 -21
- package/lib/web/qsc_wasm_bg.wasm +0 -0
- package/package.json +3 -3
- package/ux/circuit.tsx +157 -59
- package/ux/data.ts +4 -1
- package/ux/estimatesPanel.tsx +2 -10
- package/ux/qsharp-ux.css +8 -0
- package/ux/spinner.tsx +17 -0
- package/ux/tsconfig.json +2 -1
|
@@ -1196,60 +1196,90 @@ export default {
|
|
|
1196
1196
|
},
|
|
1197
1197
|
{
|
|
1198
1198
|
"type": "exercise",
|
|
1199
|
-
"id": "
|
|
1200
|
-
"title": "
|
|
1199
|
+
"id": "single_qubit_gates__state_flip",
|
|
1200
|
+
"title": "State Flip",
|
|
1201
1201
|
"description": {
|
|
1202
1202
|
"type": "text-content",
|
|
1203
|
-
"asHtml": "<p><strong>Input:</strong> A qubit in
|
|
1204
|
-
"asMarkdown": "**Input:** A qubit in
|
|
1203
|
+
"asHtml": "<p><strong>Input:</strong> A qubit in state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.</p>\n<p><strong>Goal:</strong> Change the state of the qubit to $\\alpha |1\\rangle + \\beta |0\\rangle$.</p>\n<p><strong>Example:</strong></p>\n<p>If the qubit is in state $|0\\rangle$, change its state to $|1\\rangle$.</p>\n<p>If the qubit is in state $|1\\rangle$, change its state to $|0\\rangle$.</p>\n<blockquote>\n<p>Note that this operation is self-adjoint: applying it for a second time\nreturns the qubit to the original state.</p>\n</blockquote>\n",
|
|
1204
|
+
"asMarkdown": "**Input:** A qubit in state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.\n\n**Goal:** Change the state of the qubit to $\\alpha |1\\rangle + \\beta |0\\rangle$.\n\n**Example:**\n\nIf the qubit is in state $|0\\rangle$, change its state to $|1\\rangle$.\n\nIf the qubit is in state $|1\\rangle$, change its state to $|0\\rangle$.\n\n> Note that this operation is self-adjoint: applying it for a second time\n> returns the qubit to the original state.\n"
|
|
1205
1205
|
},
|
|
1206
1206
|
"sourceIds": [
|
|
1207
|
-
"
|
|
1207
|
+
"single_qubit_gates__state_flip__Verification.qs",
|
|
1208
1208
|
"KatasLibrary.qs"
|
|
1209
1209
|
],
|
|
1210
|
-
"placeholderCode": "namespace Kata {\n operation
|
|
1210
|
+
"placeholderCode": "namespace Kata {\n operation StateFlip (q : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n \n }\n}\n\n",
|
|
1211
1211
|
"explainedSolution": {
|
|
1212
1212
|
"type": "explained-solution",
|
|
1213
1213
|
"items": [
|
|
1214
1214
|
{
|
|
1215
1215
|
"type": "text-content",
|
|
1216
|
-
"asHtml": "<p>We
|
|
1217
|
-
"asMarkdown": "\nWe
|
|
1216
|
+
"asHtml": "<p>We can recognize that the Pauli $X$ gate will change the state $|0\\rangle$ to $|1\\rangle$ and vice versa, and $\\alpha|0\\rangle + \\beta|1\\rangle$ to $\\alpha|1\\rangle + \\beta|0\\rangle$.</p>\n<p>As a reminder, the Pauli $X$ gate is defined by the following matrix:</p>\n<p>$$\nX =\n\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}\n$$</p>\n<p>We can see how it affects, for example, the basis state $|0\\rangle$:</p>\n<p>$$\nX|0\\rangle =\n\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}\n\\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} =\n\\begin{bmatrix} 0 \\cdot 1 + 1 \\cdot 0 \\\\ 1 \\cdot 1 + 0 \\cdot 0 \\end{bmatrix}=\n\\begin{bmatrix} 0 \\\\1 \\end{bmatrix}=\n|1\\rangle\n$$</p>\n<p>Similarly, we can consider the effect of the $X$ gate on the superposition state $|\\psi\\rangle = 0.6|0\\rangle + 0.8|1\\rangle$:</p>\n<p>$$\nX|\\psi\\rangle =\n\\begin{bmatrix} 0 & 1 \\\\1 & 0\\end{bmatrix}\n\\begin{bmatrix}0.6 \\\\0.8 \\end{bmatrix}=\n\\begin{bmatrix} 0 \\cdot 0.6 + 1 \\cdot 0.8 \\\\1 \\cdot 0.6 + 0 \\cdot 0.8\\end{bmatrix}=\n\\begin{bmatrix}0.8 \\\\0.6\\end{bmatrix}=\n0.8|0\\rangle + 0.6|1\\rangle\n$$</p>\n",
|
|
1217
|
+
"asMarkdown": "\nWe can recognize that the Pauli $X$ gate will change the state $|0\\rangle$ to $|1\\rangle$ and vice versa, and $\\alpha|0\\rangle + \\beta|1\\rangle$ to $\\alpha|1\\rangle + \\beta|0\\rangle$.\n\nAs a reminder, the Pauli $X$ gate is defined by the following matrix:\n\n$$\nX =\n\\begin{bmatrix} 0 & 1 \\\\\\ 1 & 0 \\end{bmatrix}\n$$\n\nWe can see how it affects, for example, the basis state $|0\\rangle$:\n\n$$\nX|0\\rangle =\n\\begin{bmatrix} 0 & 1 \\\\\\ 1 & 0 \\end{bmatrix}\n\\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix} =\n\\begin{bmatrix} 0 \\cdot 1 + 1 \\cdot 0 \\\\\\ 1 \\cdot 1 + 0 \\cdot 0 \\end{bmatrix}=\n\\begin{bmatrix} 0 \\\\\\1 \\end{bmatrix}=\n|1\\rangle\n$$\n\nSimilarly, we can consider the effect of the $X$ gate on the superposition state $|\\psi\\rangle = 0.6|0\\rangle + 0.8|1\\rangle$:\n\n$$\nX|\\psi\\rangle =\n\\begin{bmatrix} 0 & 1 \\\\\\1 & 0\\end{bmatrix}\n\\begin{bmatrix}0.6 \\\\\\0.8 \\end{bmatrix}=\n\\begin{bmatrix} 0 \\cdot 0.6 + 1 \\cdot 0.8 \\\\\\1 \\cdot 0.6 + 0 \\cdot 0.8\\end{bmatrix}=\n\\begin{bmatrix}0.8 \\\\\\0.6\\end{bmatrix}=\n0.8|0\\rangle + 0.6|1\\rangle\n$$"
|
|
1218
1218
|
},
|
|
1219
1219
|
{
|
|
1220
1220
|
"type": "solution",
|
|
1221
|
-
"id": "
|
|
1222
|
-
"code": "namespace Kata {\n operation
|
|
1221
|
+
"id": "single_qubit_gates__state_flip_solution",
|
|
1222
|
+
"code": "namespace Kata {\n operation StateFlip (q : Qubit) : Unit is Adj + Ctl {\n X(q);\n }\n}"
|
|
1223
1223
|
}
|
|
1224
1224
|
]
|
|
1225
1225
|
}
|
|
1226
1226
|
},
|
|
1227
1227
|
{
|
|
1228
1228
|
"type": "exercise",
|
|
1229
|
-
"id": "
|
|
1230
|
-
"title": "
|
|
1229
|
+
"id": "single_qubit_gates__sign_flip",
|
|
1230
|
+
"title": "Sign Flip",
|
|
1231
1231
|
"description": {
|
|
1232
1232
|
"type": "text-content",
|
|
1233
|
-
"asHtml": "<p><strong>Input
|
|
1234
|
-
"asMarkdown": "**Input
|
|
1233
|
+
"asHtml": "<p><strong>Input</strong>: A qubit in state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.</p>\n<p><strong>Goal</strong> : Change the qubit state to $\\alpha |0\\rangle - \\beta |1\\rangle$ (i.e., flip the sign of the $|1\\rangle$ component of the superposition).</p>\n",
|
|
1234
|
+
"asMarkdown": "**Input**: A qubit in state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.\n\n**Goal** : Change the qubit state to $\\alpha |0\\rangle - \\beta |1\\rangle$ (i.e., flip the sign of the $|1\\rangle$ component of the superposition).\n"
|
|
1235
1235
|
},
|
|
1236
1236
|
"sourceIds": [
|
|
1237
|
-
"
|
|
1237
|
+
"single_qubit_gates__sign_flip__Verification.qs",
|
|
1238
1238
|
"KatasLibrary.qs"
|
|
1239
1239
|
],
|
|
1240
|
-
"placeholderCode": "namespace Kata {\n operation
|
|
1240
|
+
"placeholderCode": "namespace Kata {\n operation SignFlip (q : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n}\n\n",
|
|
1241
1241
|
"explainedSolution": {
|
|
1242
1242
|
"type": "explained-solution",
|
|
1243
1243
|
"items": [
|
|
1244
1244
|
{
|
|
1245
1245
|
"type": "text-content",
|
|
1246
|
-
"asHtml": "<p>
|
|
1247
|
-
"asMarkdown": "\
|
|
1246
|
+
"asHtml": "<p>The action of the Pauli Z gate is exactly what is required by this question.\nThis gate leaves the sign of the $|0\\rangle$ component of the superposition unchanged but flips the sign of the $|1\\rangle$ component of the superposition.</p>\n<p>As a reminder, the Pauli Z gate is defined by the following matrix:</p>\n<p>$$\nZ =\n \\begin{bmatrix}1 & 0\\\\0 & -1 \\end{bmatrix}\n$$</p>\n<p>Let's see its effect on the only computational basis state that it changes, $|1\\rangle$:</p>\n<p>$$\nZ|1\\rangle =\n \\begin{bmatrix} 1 & 0\\\\0 & -1 \\end{bmatrix}\n \\begin{bmatrix}0\\\\ 1\\\\ \\end{bmatrix}=\n\\begin{bmatrix}1 \\cdot 0 + 0 \\cdot1\\\\0 \\cdot 1 + (-1) \\cdot 1\\\\ \\end{bmatrix}=\n\\begin{bmatrix}0\\\\ -1\\\\ \\end{bmatrix}=\n -\\begin{bmatrix}0\\\\ 1\\\\ \\end{bmatrix}=\n-|1\\rangle\n$$</p>\n<p>In general applying the Z gate to a single qubit superposition state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$ gives</p>\n<p>$$\nZ|\\psi\\rangle =\n \\begin{bmatrix}1 & 0 \\\\0 & -1\\end{bmatrix}\n \\begin{bmatrix}\\alpha\\\\ \\beta\\\\ \\end{bmatrix}=\n\\begin{bmatrix}1\\cdot\\alpha + 0\\cdot\\beta\\\\0\\cdot\\alpha + (-1)\\cdot\\beta\\\\ \\end{bmatrix}=\n \\begin{bmatrix}\\alpha\\\\ -\\beta\\\\ \\end{bmatrix}=\n \\alpha |0\\rangle -\\beta |1\\rangle\n$$</p>\n",
|
|
1247
|
+
"asMarkdown": "\nThe action of the Pauli Z gate is exactly what is required by this question.\nThis gate leaves the sign of the $|0\\rangle$ component of the superposition unchanged but flips the sign of the $|1\\rangle$ component of the superposition.\n\nAs a reminder, the Pauli Z gate is defined by the following matrix:\n\n$$\nZ =\n \\begin{bmatrix}1 & 0\\\\\\0 & -1 \\end{bmatrix}\n$$\n\nLet's see its effect on the only computational basis state that it changes, $|1\\rangle$:\n\n$$\nZ|1\\rangle =\n \\begin{bmatrix} 1 & 0\\\\\\0 & -1 \\end{bmatrix}\n \\begin{bmatrix}0\\\\\\ 1\\\\\\ \\end{bmatrix}=\n\\begin{bmatrix}1 \\cdot 0 + 0 \\cdot1\\\\\\0 \\cdot 1 + (-1) \\cdot 1\\\\\\ \\end{bmatrix}=\n\\begin{bmatrix}0\\\\\\ -1\\\\\\ \\end{bmatrix}=\n -\\begin{bmatrix}0\\\\\\ 1\\\\\\ \\end{bmatrix}=\n-|1\\rangle\n$$\n\nIn general applying the Z gate to a single qubit superposition state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$ gives\n\n$$\nZ|\\psi\\rangle =\n \\begin{bmatrix}1 & 0 \\\\\\0 & -1\\end{bmatrix}\n \\begin{bmatrix}\\alpha\\\\\\ \\beta\\\\\\ \\end{bmatrix}=\n\\begin{bmatrix}1\\cdot\\alpha + 0\\cdot\\beta\\\\\\0\\cdot\\alpha + (-1)\\cdot\\beta\\\\\\ \\end{bmatrix}=\n \\begin{bmatrix}\\alpha\\\\\\ -\\beta\\\\\\ \\end{bmatrix}=\n \\alpha |0\\rangle -\\beta |1\\rangle\n$$"
|
|
1248
1248
|
},
|
|
1249
1249
|
{
|
|
1250
1250
|
"type": "solution",
|
|
1251
|
-
"id": "
|
|
1252
|
-
"code": "namespace Kata {\n operation
|
|
1251
|
+
"id": "single_qubit_gates__sign_flip_solution",
|
|
1252
|
+
"code": "namespace Kata {\n operation SignFlip (q : Qubit) : Unit is Adj + Ctl {\n Z(q);\n }\n}"
|
|
1253
|
+
}
|
|
1254
|
+
]
|
|
1255
|
+
}
|
|
1256
|
+
},
|
|
1257
|
+
{
|
|
1258
|
+
"type": "exercise",
|
|
1259
|
+
"id": "single_qubit_gates__y_gate",
|
|
1260
|
+
"title": "The Y Gate",
|
|
1261
|
+
"description": {
|
|
1262
|
+
"type": "text-content",
|
|
1263
|
+
"asHtml": "<p><strong>Input:</strong> A qubit in an arbitrary state $|\\psi\\rangle = \\alpha|0\\rangle + \\beta|1\\rangle$.</p>\n<p><strong>Goal:</strong> Apply the Y gate to the qubit, i.e., transform the given state into $i\\alpha|1\\rangle - i\\beta|0\\rangle$.</p>\n",
|
|
1264
|
+
"asMarkdown": "**Input:** A qubit in an arbitrary state $|\\\\psi\\\\rangle = \\\\alpha|0\\\\rangle + \\\\beta|1\\\\rangle$.\n\n**Goal:** Apply the Y gate to the qubit, i.e., transform the given state into $i\\\\alpha|1\\\\rangle - i\\\\beta|0\\\\rangle$."
|
|
1265
|
+
},
|
|
1266
|
+
"sourceIds": [
|
|
1267
|
+
"single_qubit_gates__y_gate__Verification.qs",
|
|
1268
|
+
"KatasLibrary.qs"
|
|
1269
|
+
],
|
|
1270
|
+
"placeholderCode": "namespace Kata {\n operation ApplyY(q : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n}",
|
|
1271
|
+
"explainedSolution": {
|
|
1272
|
+
"type": "explained-solution",
|
|
1273
|
+
"items": [
|
|
1274
|
+
{
|
|
1275
|
+
"type": "text-content",
|
|
1276
|
+
"asHtml": "<p>We have to do exactly what the task asks us to do: apply the Pauli gate $Y=\\begin{bmatrix} 0 & -i \\\\ i & 0 \\end{bmatrix}$.</p>\n<p>This has the effect of turning $|\\psi\\rangle = \\alpha|0\\rangle + \\beta|1\\rangle$ into $Y|\\psi\\rangle = i\\alpha|1\\rangle - i\\beta|0\\rangle$, which in matrix form looks as follows:\n$$\n\\begin{bmatrix} 0 & -i \\\\ i & 0 \\end{bmatrix} \\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix} = \n\\begin{bmatrix} -i\\beta \\\\ i\\alpha \\end{bmatrix}\n$$</p>\n",
|
|
1277
|
+
"asMarkdown": "\nWe have to do exactly what the task asks us to do: apply the Pauli gate $Y=\\\\begin{bmatrix} 0 & -i \\\\\\\\ i & 0 \\\\end{bmatrix}$.\n\nThis has the effect of turning $|\\psi\\rangle = \\alpha|0\\rangle + \\beta|1\\rangle$ into $Y|\\psi\\rangle = i\\alpha|1\\rangle - i\\beta|0\\rangle$, which in matrix form looks as follows:\n$$\n\\begin{bmatrix} 0 & -i \\\\\\ i & 0 \\end{bmatrix} \\begin{bmatrix} \\alpha \\\\\\ \\beta \\end{bmatrix} = \n\\begin{bmatrix} -i\\beta \\\\\\ i\\alpha \\end{bmatrix}\n$$"
|
|
1278
|
+
},
|
|
1279
|
+
{
|
|
1280
|
+
"type": "solution",
|
|
1281
|
+
"id": "single_qubit_gates__y_gate_solution",
|
|
1282
|
+
"code": "namespace Kata {\n operation ApplyY(q : Qubit) : Unit is Adj + Ctl {\n Y(q); // As simple as this.\n }\n}"
|
|
1253
1283
|
}
|
|
1254
1284
|
]
|
|
1255
1285
|
}
|
|
@@ -1284,6 +1314,66 @@ export default {
|
|
|
1284
1314
|
]
|
|
1285
1315
|
}
|
|
1286
1316
|
},
|
|
1317
|
+
{
|
|
1318
|
+
"type": "exercise",
|
|
1319
|
+
"id": "single_qubit_gates__global_phase_minusone",
|
|
1320
|
+
"title": "Global Phase -1",
|
|
1321
|
+
"description": {
|
|
1322
|
+
"type": "text-content",
|
|
1323
|
+
"asHtml": "<p><strong>Input:</strong> A qubit in state $|\\psi\\rangle = \\beta |0\\rangle + \\gamma |1\\rangle$.</p>\n<p><strong>Goal</strong>: Change the state of the qubit to $- \\beta |0\\rangle - \\gamma |1\\rangle$.</p>\n<blockquote>\n<p>This change on its own is not observable - there is no experiment you can do on a standalone qubit to figure out whether it acquired the global phase or not.\nHowever, you can use a controlled version of this operation to observe the global phase it introduces.\nThis is used in later katas as part of more complicated tasks.</p>\n</blockquote>\n",
|
|
1324
|
+
"asMarkdown": "**Input:** A qubit in state $|\\psi\\rangle = \\beta |0\\rangle + \\gamma |1\\rangle$.\n\n**Goal**: Change the state of the qubit to $- \\beta |0\\rangle - \\gamma |1\\rangle$.\n\n> This change on its own is not observable - there is no experiment you can do on a standalone qubit to figure out whether it acquired the global phase or not.\n> However, you can use a controlled version of this operation to observe the global phase it introduces.\n> This is used in later katas as part of more complicated tasks.\n"
|
|
1325
|
+
},
|
|
1326
|
+
"sourceIds": [
|
|
1327
|
+
"single_qubit_gates__global_phase_minusone__Verification.qs",
|
|
1328
|
+
"KatasLibrary.qs"
|
|
1329
|
+
],
|
|
1330
|
+
"placeholderCode": "namespace Kata {\n operation GlobalPhaseChange (q : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n \n }\n}\n\n",
|
|
1331
|
+
"explainedSolution": {
|
|
1332
|
+
"type": "explained-solution",
|
|
1333
|
+
"items": [
|
|
1334
|
+
{
|
|
1335
|
+
"type": "text-content",
|
|
1336
|
+
"asHtml": "<p>A global phase is a phase factor that multiplies the entire quantum state. It is not observable when measuring the qubit's state, as the probabilities remain unchanged. However, it is significant when considering quantum state transformations.</p>\n<p>Our task is to implement an operation that transforms the given qubit state from $|\\psi\\rangle = \\beta |0\\rangle + \\gamma |1\\rangle$ to $- \\beta |0\\rangle - \\gamma |1\\rangle$.</p>\n<p>To do that, we utilize a sequence of gates. The Pauli Z gate followed by the Pauli X gate can be used to achieve this effect when applied in succession twice.</p>\n<ol>\n<li><p><strong>Apply the Pauli Z gate</strong>: The Z gate multiplies the $|1\\rangle$ state by $-1$ but does not change the $|0\\rangle$ state, converting our state $\\beta |0\\rangle + \\gamma |1\\rangle$ to $\\beta |0\\rangle - \\gamma |1\\rangle$.</p>\n<p>The matrix representation of the Z gate is:</p>\n<p>$$\nZ =\n\\begin{bmatrix}1 & 0 \\\\ 0 & -1 \\end{bmatrix}\n$$</p>\n</li>\n<li><p><strong>Apply the Pauli X gate</strong>: The X gate flips the $|0\\rangle$ and $|1\\rangle$ basis states, converting our $\\beta |0\\rangle - \\gamma |1\\rangle$ state to $\\beta |1\\rangle - \\gamma |0\\rangle$.</p>\n<p>The matrix representation of the X gate is:</p>\n<p>$$\nX =\n\\begin{bmatrix}0 & 1 \\\\1 & 0\\end{bmatrix}\n$$</p>\n</li>\n<li><p><strong>Repeat the Z and X gates</strong>: Applying the Z gate again will multiply the $|1\\rangle$ state (that used to be $|0\\rangle$), converting our state $\\beta |1\\rangle - \\gamma |0\\rangle$ to $- \\beta |1\\rangle - \\gamma |0\\rangle$. Finally, the second X gate will restore the original basis states, but now with both amplitudes having acquired an additional phase of $-1$. This means our state has been multiplied by $-1$, achieving the required global phase change.</p>\n</li>\n</ol>\n",
|
|
1337
|
+
"asMarkdown": "\nA global phase is a phase factor that multiplies the entire quantum state. It is not observable when measuring the qubit's state, as the probabilities remain unchanged. However, it is significant when considering quantum state transformations.\n\nOur task is to implement an operation that transforms the given qubit state from $|\\psi\\rangle = \\beta |0\\rangle + \\gamma |1\\rangle$ to $- \\beta |0\\rangle - \\gamma |1\\rangle$.\n\nTo do that, we utilize a sequence of gates. The Pauli Z gate followed by the Pauli X gate can be used to achieve this effect when applied in succession twice.\n\n1. **Apply the Pauli Z gate**: The Z gate multiplies the $|1\\rangle$ state by $-1$ but does not change the $|0\\rangle$ state, converting our state $\\beta |0\\rangle + \\gamma |1\\rangle$ to $\\beta |0\\rangle - \\gamma |1\\rangle$.\n\n The matrix representation of the Z gate is:\n\n $$\n Z =\n \\begin{bmatrix}1 & 0 \\\\\\ 0 & -1 \\end{bmatrix}\n $$\n\n2. **Apply the Pauli X gate**: The X gate flips the $|0\\rangle$ and $|1\\rangle$ basis states, converting our $\\beta |0\\rangle - \\gamma |1\\rangle$ state to $\\beta |1\\rangle - \\gamma |0\\rangle$.\n\n The matrix representation of the X gate is:\n\n $$\n X =\n \\begin{bmatrix}0 & 1 \\\\\\1 & 0\\end{bmatrix}\n $$\n\n3. **Repeat the Z and X gates**: Applying the Z gate again will multiply the $|1\\rangle$ state (that used to be $|0\\rangle$), converting our state $\\beta |1\\rangle - \\gamma |0\\rangle$ to $- \\beta |1\\rangle - \\gamma |0\\rangle$. Finally, the second X gate will restore the original basis states, but now with both amplitudes having acquired an additional phase of $-1$. This means our state has been multiplied by $-1$, achieving the required global phase change."
|
|
1338
|
+
},
|
|
1339
|
+
{
|
|
1340
|
+
"type": "solution",
|
|
1341
|
+
"id": "single_qubit_gates__global_phase_minusone_solution",
|
|
1342
|
+
"code": "namespace Kata {\n operation GlobalPhaseChange (q : Qubit) : Unit is Adj + Ctl {\n Z(q);\n X(q);\n Z(q);\n X(q);\n }\n}\n"
|
|
1343
|
+
}
|
|
1344
|
+
]
|
|
1345
|
+
}
|
|
1346
|
+
},
|
|
1347
|
+
{
|
|
1348
|
+
"type": "exercise",
|
|
1349
|
+
"id": "single_qubit_gates__global_phase_i",
|
|
1350
|
+
"title": "Global Phase i",
|
|
1351
|
+
"description": {
|
|
1352
|
+
"type": "text-content",
|
|
1353
|
+
"asHtml": "<p><strong>Input:</strong> A qubit in an arbitrary state $|\\psi\\rangle = \\alpha|0\\rangle + \\beta|1\\rangle$.</p>\n<p><strong>Goal:</strong> Use several Pauli gates to change the qubit state to $i|\\psi\\rangle = i\\alpha|0\\rangle + i\\beta|1\\rangle$.</p>\n",
|
|
1354
|
+
"asMarkdown": "**Input:** A qubit in an arbitrary state $|\\\\psi\\\\rangle = \\\\alpha|0\\\\rangle + \\\\beta|1\\\\rangle$.\n\n**Goal:** Use several Pauli gates to change the qubit state to $i|\\\\psi\\\\rangle = i\\\\alpha|0\\\\rangle + i\\\\beta|1\\\\rangle$."
|
|
1355
|
+
},
|
|
1356
|
+
"sourceIds": [
|
|
1357
|
+
"single_qubit_gates__global_phase_i__Verification.qs",
|
|
1358
|
+
"KatasLibrary.qs"
|
|
1359
|
+
],
|
|
1360
|
+
"placeholderCode": "namespace Kata {\n operation GlobalPhaseI(q : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n}",
|
|
1361
|
+
"explainedSolution": {
|
|
1362
|
+
"type": "explained-solution",
|
|
1363
|
+
"items": [
|
|
1364
|
+
{
|
|
1365
|
+
"type": "text-content",
|
|
1366
|
+
"asHtml": "<p>We need to apply a gate which applies a global phase of $i$, i.e. $|\\psi\\rangle \\rightarrow i|\\psi\\rangle$.\nThe matrix representation of such a gate is $\\begin{bmatrix} i & 0 \\\\ 0 & i \\end{bmatrix} = i\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix} = iI$.\nSince we are restricted to the Pauli gates, we use the property that a product of any two distinct Pauli gates equals the third gate with a $+i$ or a $-i$ global phase, therefore the product of all three Pauli gates is $XYZ = iI$.\n$$\n\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}\\begin{bmatrix} 0 & -i \\\\ i & 0 \\end{bmatrix}\\begin{bmatrix} 1 & 0 \\\\ 0 & -1 \\end{bmatrix} = \n\\begin{bmatrix} i & 0 \\\\ 0 & i \\end{bmatrix}\n$$</p>\n<blockquote>\n<p>Remember the rightmost gates in mathematical notation are applied first in Q# code. Hence we first apply the $Z$ gate, followed by the $Y$ gate, and finally the $X$ gate.</p>\n</blockquote>\n",
|
|
1367
|
+
"asMarkdown": "\nWe need to apply a gate which applies a global phase of $i$, i.e. $|\\psi\\rangle \\rightarrow i|\\psi\\rangle$.\nThe matrix representation of such a gate is $\\begin{bmatrix} i & 0 \\\\\\ 0 & i \\end{bmatrix} = i\\begin{bmatrix} 1 & 0 \\\\\\ 0 & 1 \\end{bmatrix} = iI$.\nSince we are restricted to the Pauli gates, we use the property that a product of any two distinct Pauli gates equals the third gate with a $+i$ or a $-i$ global phase, therefore the product of all three Pauli gates is $XYZ = iI$.\n$$\n\\begin{bmatrix} 0 & 1 \\\\\\ 1 & 0 \\end{bmatrix}\\begin{bmatrix} 0 & -i \\\\\\ i & 0 \\end{bmatrix}\\begin{bmatrix} 1 & 0 \\\\\\ 0 & -1 \\end{bmatrix} = \n\\begin{bmatrix} i & 0 \\\\\\ 0 & i \\end{bmatrix}\n$$\n\n> Remember the rightmost gates in mathematical notation are applied first in Q# code. Hence we first apply the $Z$ gate, followed by the $Y$ gate, and finally the $X$ gate."
|
|
1368
|
+
},
|
|
1369
|
+
{
|
|
1370
|
+
"type": "solution",
|
|
1371
|
+
"id": "single_qubit_gates__global_phase_i_solution",
|
|
1372
|
+
"code": "namespace Kata {\n operation GlobalPhaseI(q : Qubit) : Unit is Adj + Ctl {\n Z(q);\n Y(q);\n X(q);\n }\n}"
|
|
1373
|
+
}
|
|
1374
|
+
]
|
|
1375
|
+
}
|
|
1376
|
+
},
|
|
1287
1377
|
{
|
|
1288
1378
|
"type": "lesson",
|
|
1289
1379
|
"id": "identity_gate",
|
|
@@ -1292,7 +1382,7 @@ export default {
|
|
|
1292
1382
|
{
|
|
1293
1383
|
"type": "text-content",
|
|
1294
1384
|
"asHtml": "<p>The identity gate is mostly here for completeness, at least for now. It will come in handy when dealing with multi-qubit systems and multi-qubit gates. It is represented by the identity matrix, and does not affect the state of the qubit.</p>\n<table>\n<tr>\n<th>Gate</th>\n<th>Matrix</th>\n<th>Ket-Bra</th>\n<th>Applying to $|\\psi\\rangle = \\alpha|0\\rangle + \\beta|1\\rangle$</th>\n</tr>\n<tr>\n<td>$I$</td>\n<td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}$</td>\n<td>$|0\\rangle\\langle0| + |1\\rangle\\langle1|$</td>\n<td>$I|\\psi\\rangle = |\\psi\\rangle$</td>\n</tr>\n</table>",
|
|
1295
|
-
"asMarkdown": "\nThe identity gate is mostly here for completeness, at least for now. It will come in handy when dealing with multi-qubit systems and multi-qubit gates. It is represented by the identity matrix, and does not affect the state of the qubit.\n
|
|
1385
|
+
"asMarkdown": "\nThe identity gate is mostly here for completeness, at least for now. It will come in handy when dealing with multi-qubit systems and multi-qubit gates. It is represented by the identity matrix, and does not affect the state of the qubit.\n\n<table>\n<tr>\n<th>Gate</th>\n<th>Matrix</th>\n<th>Ket-Bra</th>\n<th>Applying to $|\\psi\\rangle = \\alpha|0\\rangle + \\beta|1\\rangle$</th>\n</tr>\n<tr>\n<td>$I$</td>\n<td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}$</td>\n<td>$|0\\rangle\\langle0| + |1\\rangle\\langle1|$</td>\n<td>$I|\\psi\\rangle = |\\psi\\rangle$</td>\n</tr>\n</table>"
|
|
1296
1386
|
}
|
|
1297
1387
|
]
|
|
1298
1388
|
},
|
|
@@ -1308,6 +1398,36 @@ export default {
|
|
|
1308
1398
|
}
|
|
1309
1399
|
]
|
|
1310
1400
|
},
|
|
1401
|
+
{
|
|
1402
|
+
"type": "exercise",
|
|
1403
|
+
"id": "single_qubit_gates__basis_change",
|
|
1404
|
+
"title": "Basis Change",
|
|
1405
|
+
"description": {
|
|
1406
|
+
"type": "text-content",
|
|
1407
|
+
"asHtml": "<p><strong>Input</strong>: A qubit in state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.</p>\n<p><strong>Goal</strong>: Change the state of the qubit as follows:</p>\n<ul>\n<li>If the qubit is in state $|0\\rangle$, change its state to $|+\\rangle = \\frac{1}{\\sqrt{2}} \\big(|0\\rangle + |1\\rangle\\big)$.</li>\n<li>If the qubit is in state $|1\\rangle$, change its state to $|-\\rangle = \\frac{1}{\\sqrt{2}} \\big(|0\\rangle - |1\\rangle\\big)$.</li>\n<li>If the qubit is in superposition, change its state according to the effect on basis vectors.</li>\n</ul>\n",
|
|
1408
|
+
"asMarkdown": "**Input**: A qubit in state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.\n\n**Goal**: Change the state of the qubit as follows:\n\n- If the qubit is in state $|0\\rangle$, change its state to $|+\\rangle = \\frac{1}{\\sqrt{2}} \\big(|0\\rangle + |1\\rangle\\big)$.\n- If the qubit is in state $|1\\rangle$, change its state to $|-\\rangle = \\frac{1}{\\sqrt{2}} \\big(|0\\rangle - |1\\rangle\\big)$.\n- If the qubit is in superposition, change its state according to the effect on basis vectors.\n"
|
|
1409
|
+
},
|
|
1410
|
+
"sourceIds": [
|
|
1411
|
+
"single_qubit_gates__basis_change__Verification.qs",
|
|
1412
|
+
"KatasLibrary.qs"
|
|
1413
|
+
],
|
|
1414
|
+
"placeholderCode": "namespace Kata {\n operation BasisChange (q : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n \n }\n}\n\n",
|
|
1415
|
+
"explainedSolution": {
|
|
1416
|
+
"type": "explained-solution",
|
|
1417
|
+
"items": [
|
|
1418
|
+
{
|
|
1419
|
+
"type": "text-content",
|
|
1420
|
+
"asHtml": "<p>We can recognize that the Hadamard gate changes states $|0\\rangle$ and $|1\\rangle$ to $|+\\rangle$ and $|-\\rangle$, respectively, and vice versa.</p>\n<p>As a reminder, the Hadamard gate is defined by the following matrix:</p>\n<p>$$\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix}1 & 1 \\\\1 & -1\\end{bmatrix}\n$$</p>\n<p>For example, we can work out $H|1\\rangle$ as follows:</p>\n<p>$$\nH|1\\rangle=\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 & 1 \\\\1 & -1\\end{bmatrix}\n\\begin{bmatrix} 0\\\\ 1\\end{bmatrix}=\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix}1 \\cdot 0 + 1 \\cdot 1 \\\\1 \\cdot 0 + (-1) \\cdot 1\\end{bmatrix}=\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix}1\\\\ -1\\\\ \\end{bmatrix}=\n\\frac{1}{\\sqrt{2}} \\big(|0\\rangle - |1\\rangle\\big) = |-\\rangle\n$$</p>\n<p>Similarly, we can consider the effect of the Hadamard gate on the superposition state $|\\psi\\rangle = 0.6|0\\rangle + 0.8|1\\rangle$ (rounding the numbers to 4 decimal places):</p>\n<p>$$\nH|\\psi⟩ =\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 & 1 \\\\ 1 & -1 \\end{bmatrix}\n \\begin{bmatrix} \\alpha\\\\ \\beta\\\\ \\end{bmatrix} =\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix} \\alpha + \\beta\\\\ \\alpha - \\beta\\\\ \\end{bmatrix}=\n0.7071\\begin{bmatrix} 1.4\\\\ -0.2\\\\ \\end{bmatrix} =\n\\begin{bmatrix}\n 0.98994\\\\ -0.14142\\\\ \\end{bmatrix} =\n 0.9899|0\\rangle - 0.1414|1\\rangle\n$$</p>\n",
|
|
1421
|
+
"asMarkdown": "\nWe can recognize that the Hadamard gate changes states $|0\\rangle$ and $|1\\rangle$ to $|+\\rangle$ and $|-\\rangle$, respectively, and vice versa.\n\nAs a reminder, the Hadamard gate is defined by the following matrix:\n\n$$\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix}1 & 1 \\\\\\1 & -1\\end{bmatrix}\n$$\n\nFor example, we can work out $H|1\\rangle$ as follows:\n\n$$\nH|1\\rangle=\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 & 1 \\\\\\1 & -1\\end{bmatrix}\n\\begin{bmatrix} 0\\\\\\ 1\\end{bmatrix}=\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix}1 \\cdot 0 + 1 \\cdot 1 \\\\\\1 \\cdot 0 + (-1) \\cdot 1\\end{bmatrix}=\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix}1\\\\\\ -1\\\\\\ \\end{bmatrix}=\n\\frac{1}{\\sqrt{2}} \\big(|0\\rangle - |1\\rangle\\big) = |-\\rangle\n$$\n\nSimilarly, we can consider the effect of the Hadamard gate on the superposition state $|\\psi\\rangle = 0.6|0\\rangle + 0.8|1\\rangle$ (rounding the numbers to 4 decimal places):\n\n$$\nH|\\psi⟩ =\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 & 1 \\\\\\ 1 & -1 \\end{bmatrix}\n \\begin{bmatrix} \\alpha\\\\\\ \\beta\\\\\\ \\end{bmatrix} =\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix} \\alpha + \\beta\\\\\\ \\alpha - \\beta\\\\\\ \\end{bmatrix}=\n0.7071\\begin{bmatrix} 1.4\\\\\\ -0.2\\\\\\ \\end{bmatrix} =\n\\begin{bmatrix}\n 0.98994\\\\\\ -0.14142\\\\\\ \\end{bmatrix} =\n 0.9899|0\\rangle - 0.1414|1\\rangle\n$$"
|
|
1422
|
+
},
|
|
1423
|
+
{
|
|
1424
|
+
"type": "solution",
|
|
1425
|
+
"id": "single_qubit_gates__basis_change_solution",
|
|
1426
|
+
"code": "namespace Kata {\n operation BasisChange (q : Qubit) : Unit is Adj + Ctl {\n H(q);\n }\n}"
|
|
1427
|
+
}
|
|
1428
|
+
]
|
|
1429
|
+
}
|
|
1430
|
+
},
|
|
1311
1431
|
{
|
|
1312
1432
|
"type": "exercise",
|
|
1313
1433
|
"id": "single_qubit_gates__prepare_minus",
|
|
@@ -1350,6 +1470,46 @@ export default {
|
|
|
1350
1470
|
}
|
|
1351
1471
|
]
|
|
1352
1472
|
},
|
|
1473
|
+
{
|
|
1474
|
+
"type": "exercise",
|
|
1475
|
+
"id": "single_qubit_gates__phase_i",
|
|
1476
|
+
"title": "Relative Phase i",
|
|
1477
|
+
"description": {
|
|
1478
|
+
"type": "text-content",
|
|
1479
|
+
"asHtml": "<p><strong>Input:</strong> A qubit in state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.</p>\n<p><strong>Goal:</strong> Change the qubit state to $\\alpha |0\\rangle + {\\color{red}i}\\beta |1\\rangle$ (add a relative phase $i$ to $|1\\rangle$ component of the superposition).</p>\n",
|
|
1480
|
+
"asMarkdown": "**Input:** A qubit in state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.\n\n**Goal:** Change the qubit state to $\\alpha |0\\rangle + {\\color{red}i}\\beta |1\\rangle$ (add a relative phase $i$ to $|1\\rangle$ component of the superposition).\n"
|
|
1481
|
+
},
|
|
1482
|
+
"sourceIds": [
|
|
1483
|
+
"single_qubit_gates__phase_i__Verification.qs",
|
|
1484
|
+
"KatasLibrary.qs"
|
|
1485
|
+
],
|
|
1486
|
+
"placeholderCode": "namespace Kata {\n operation PhaseFlip (q : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n \n }\n}\n\n",
|
|
1487
|
+
"explainedSolution": {
|
|
1488
|
+
"type": "explained-solution",
|
|
1489
|
+
"items": [
|
|
1490
|
+
{
|
|
1491
|
+
"type": "text-content",
|
|
1492
|
+
"asHtml": "<h4>Solution 1</h4>\n<p>We can recognize that the $S$ gate performs this particular relative phase addition to the $|1\\rangle$ basis state. As a reminder,</p>\n<p>$$\nS =\n\\begin{bmatrix}1 & 0\\\\ 0 & i\\end{bmatrix}\n$$</p>\n<p>Let's see the effect of this gate on the general superposition $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.</p>\n<p>$$\n \\begin{bmatrix}1 & 0 \\\\ 0 & i \\end{bmatrix}\n \\begin{bmatrix}\\alpha\\\\ \\beta\\\\ \\end{bmatrix}=\n\\begin{bmatrix}1\\cdot\\alpha + 0\\cdot\\beta\\\\ 0\\cdot\\alpha + i\\cdot\\beta \\end{bmatrix}=\n \\begin{bmatrix}\\alpha\\\\ i\\beta\\\\ \\end{bmatrix}\n$$</p>\n<p>It is therefore easy to see that when $|\\psi\\rangle = 0.6|0\\rangle + 0.8|1\\rangle, S|\\psi\\rangle = 0.6|0\\rangle + 0.8i|1\\rangle$.</p>\n",
|
|
1493
|
+
"asMarkdown": "\n#### Solution 1\n\nWe can recognize that the $S$ gate performs this particular relative phase addition to the $|1\\rangle$ basis state. As a reminder,\n\n$$\nS =\n\\begin{bmatrix}1 & 0\\\\\\ 0 & i\\end{bmatrix}\n$$\n\nLet's see the effect of this gate on the general superposition $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.\n\n$$\n \\begin{bmatrix}1 & 0 \\\\\\ 0 & i \\end{bmatrix}\n \\begin{bmatrix}\\alpha\\\\\\ \\beta\\\\\\ \\end{bmatrix}=\n\\begin{bmatrix}1\\cdot\\alpha + 0\\cdot\\beta\\\\\\ 0\\cdot\\alpha + i\\cdot\\beta \\end{bmatrix}=\n \\begin{bmatrix}\\alpha\\\\\\ i\\beta\\\\\\ \\end{bmatrix}\n$$\n\nIt is therefore easy to see that when $|\\psi\\rangle = 0.6|0\\rangle + 0.8|1\\rangle, S|\\psi\\rangle = 0.6|0\\rangle + 0.8i|1\\rangle$."
|
|
1494
|
+
},
|
|
1495
|
+
{
|
|
1496
|
+
"type": "solution",
|
|
1497
|
+
"id": "single_qubit_gates__phase_i_solution_a",
|
|
1498
|
+
"code": "namespace Kata {\n operation PhaseFlip (q : Qubit) : Unit is Adj + Ctl {\n S(q);\n }\n}"
|
|
1499
|
+
},
|
|
1500
|
+
{
|
|
1501
|
+
"type": "text-content",
|
|
1502
|
+
"asHtml": "<h4>Solution 2</h4>\n<p>Alternatively, see the Complex Relative Phase task later in the kata for an explanation of using $R1$ gate to implement the same transformation.</p>\n",
|
|
1503
|
+
"asMarkdown": "\n#### Solution 2\n\nAlternatively, see the Complex Relative Phase task later in the kata for an explanation of using $R1$ gate to implement the same transformation."
|
|
1504
|
+
},
|
|
1505
|
+
{
|
|
1506
|
+
"type": "solution",
|
|
1507
|
+
"id": "single_qubit_gates_phase_i_solution_b",
|
|
1508
|
+
"code": "namespace Kata {\n operation PhaseFlip (q : Qubit) : Unit is Adj + Ctl {\n open Microsoft.Quantum.Math;\n R1(0.5 * PI(), q);\n }\n}"
|
|
1509
|
+
}
|
|
1510
|
+
]
|
|
1511
|
+
}
|
|
1512
|
+
},
|
|
1353
1513
|
{
|
|
1354
1514
|
"type": "exercise",
|
|
1355
1515
|
"id": "single_qubit_gates__three_quarters_pi_phase",
|
|
@@ -1392,6 +1552,66 @@ export default {
|
|
|
1392
1552
|
}
|
|
1393
1553
|
]
|
|
1394
1554
|
},
|
|
1555
|
+
{
|
|
1556
|
+
"type": "exercise",
|
|
1557
|
+
"id": "single_qubit_gates__complex_phase",
|
|
1558
|
+
"title": "Complex Relative Phase",
|
|
1559
|
+
"description": {
|
|
1560
|
+
"type": "text-content",
|
|
1561
|
+
"asHtml": "<p><strong>Inputs:</strong></p>\n<ol>\n<li>Angle $\\alpha$, in radians, represented as Double.</li>\n<li>A qubit in state $|\\psi\\rangle = \\beta |0\\rangle + \\gamma |1\\rangle$.</li>\n</ol>\n<p><strong>Goal:</strong> Change the state of the qubit as follows:</p>\n<ul>\n<li>If the qubit is in state $|0\\rangle$, don't change its state.</li>\n<li>If the qubit is in state $|1\\rangle$, change its state to $e^{i\\alpha} |1\\rangle$.</li>\n<li>If the qubit is in superposition, change its state according to the effect on basis vectors: $\\beta |0\\rangle + {\\color{red}{e^{i\\alpha}}} \\gamma |1\\rangle$.</li>\n</ul>\n",
|
|
1562
|
+
"asMarkdown": "**Inputs:**\n\n1. Angle $\\alpha$, in radians, represented as Double.\n2. A qubit in state $|\\psi\\rangle = \\beta |0\\rangle + \\gamma |1\\rangle$.\n\n**Goal:** Change the state of the qubit as follows:\n\n- If the qubit is in state $|0\\rangle$, don't change its state.\n- If the qubit is in state $|1\\rangle$, change its state to $e^{i\\alpha} |1\\rangle$.\n- If the qubit is in superposition, change its state according to the effect on basis vectors: $\\beta |0\\rangle + {\\color{red}{e^{i\\alpha}}} \\gamma |1\\rangle$.\n"
|
|
1563
|
+
},
|
|
1564
|
+
"sourceIds": [
|
|
1565
|
+
"single_qubit_gates__complex_phase__Verification.qs",
|
|
1566
|
+
"KatasLibrary.qs"
|
|
1567
|
+
],
|
|
1568
|
+
"placeholderCode": "namespace Kata {\n operation PhaseChange (alpha : Double, q : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n \n }\n}\n\n",
|
|
1569
|
+
"explainedSolution": {
|
|
1570
|
+
"type": "explained-solution",
|
|
1571
|
+
"items": [
|
|
1572
|
+
{
|
|
1573
|
+
"type": "text-content",
|
|
1574
|
+
"asHtml": "<p>We know that:</p>\n<p>$$\nR1(\\alpha)=\n \\begin{bmatrix}1 & 0\\\\0 & \\color{red}{e^{i\\alpha}}\\end{bmatrix}\n$$</p>\n<p>So we have:</p>\n<p>$$\nR1(\\beta |0\\rangle + \\gamma |1\\rangle) =\n \\begin{bmatrix}1 & 0 \\\\0 & \\color{red}{e^{i\\alpha}} \\end{bmatrix}\n \\begin{bmatrix}\\beta\\\\ \\gamma\\\\ \\end{bmatrix}=\n\\begin{bmatrix}1 \\cdot \\beta + 0 \\cdot \\gamma\\\\ 0 \\cdot \\beta + {\\color{red}{e^{i\\alpha}}} \\cdot \\gamma\\end{bmatrix}=\n \\begin{bmatrix}\\beta\\\\ {\\color{red}{e^{i\\alpha}}}\\gamma\\end{bmatrix}=\n \\beta |0\\rangle + {\\color{red}{e^{i\\alpha}}} \\gamma |1\\rangle\n$$</p>\n<blockquote>\n<p>Suppose now that $\\alpha = \\frac{\\pi}{2}$.\nThen $e^{i\\alpha}= \\cos\\frac{\\pi}{2} + i\\sin\\frac{\\pi}{2}$.\nAnd, since $\\cos\\frac{\\pi}{2}= 0$ and $\\sin\\frac{\\pi}{2} = 1$, then we have that $\\cos\\frac{\\pi}{2} + i \\sin\\frac{\\pi}{2} = i$, and<br>$R1(\\frac{\\pi}{2}) = S$, which we used in the second solution to the task "Relative Phase i".</p>\n</blockquote>\n",
|
|
1575
|
+
"asMarkdown": "\nWe know that:\n\n$$\nR1(\\alpha)=\n \\begin{bmatrix}1 & 0\\\\\\0 & \\color{red}{e^{i\\alpha}}\\end{bmatrix}\n$$\n\nSo we have:\n\n$$\nR1(\\beta |0\\rangle + \\gamma |1\\rangle) =\n \\begin{bmatrix}1 & 0 \\\\\\0 & \\color{red}{e^{i\\alpha}} \\end{bmatrix}\n \\begin{bmatrix}\\beta\\\\\\ \\gamma\\\\\\ \\end{bmatrix}=\n\\begin{bmatrix}1 \\cdot \\beta + 0 \\cdot \\gamma\\\\\\ 0 \\cdot \\beta + {\\color{red}{e^{i\\alpha}}} \\cdot \\gamma\\end{bmatrix}=\n \\begin{bmatrix}\\beta\\\\\\ {\\color{red}{e^{i\\alpha}}}\\gamma\\end{bmatrix}=\n \\beta |0\\rangle + {\\color{red}{e^{i\\alpha}}} \\gamma |1\\rangle\n$$\n\n> Suppose now that $\\alpha = \\frac{\\pi}{2}$.\n> Then $e^{i\\alpha}= \\cos\\frac{\\pi}{2} + i\\sin\\frac{\\pi}{2}$.\n> And, since $\\cos\\frac{\\pi}{2}= 0$ and $\\sin\\frac{\\pi}{2} = 1$, then we have that $\\cos\\frac{\\pi}{2} + i \\sin\\frac{\\pi}{2} = i$, and \n> $R1(\\frac{\\pi}{2}) = S$, which we used in the second solution to the task \"Relative Phase i\"."
|
|
1576
|
+
},
|
|
1577
|
+
{
|
|
1578
|
+
"type": "solution",
|
|
1579
|
+
"id": "single_qubit_gates__complex_phase_solution",
|
|
1580
|
+
"code": "namespace Kata {\n operation PhaseChange (alpha : Double, q : Qubit) : Unit is Adj + Ctl {\n R1(alpha, q); \n }\n}\n\n"
|
|
1581
|
+
}
|
|
1582
|
+
]
|
|
1583
|
+
}
|
|
1584
|
+
},
|
|
1585
|
+
{
|
|
1586
|
+
"type": "exercise",
|
|
1587
|
+
"id": "single_qubit_gates__amplitude_change",
|
|
1588
|
+
"title": "Amplitude Change",
|
|
1589
|
+
"description": {
|
|
1590
|
+
"type": "text-content",
|
|
1591
|
+
"asHtml": "<p><strong>Inputs:</strong></p>\n<ol>\n<li>Angle $\\alpha$, in radians, represented as Double.</li>\n<li>A qubit in state $|\\psi\\rangle = \\beta |0\\rangle + \\gamma |1\\rangle$.</li>\n</ol>\n<p><strong>Goal:</strong> Change the state of the qubit as follows:</p>\n<ul>\n<li>If the qubit is in state $|0\\rangle$, change its state to $\\cos \\alpha |0\\rangle + \\sin \\alpha |1\\rangle$.</li>\n<li>If the qubit is in state $|1\\rangle$, change its state to $-\\sin \\alpha |0\\rangle + \\cos \\alpha |1\\rangle$.</li>\n<li>If the qubit is in superposition, change its state according to the effect on basis vectors.</li>\n</ul>\n",
|
|
1592
|
+
"asMarkdown": "**Inputs:**\n\n1. Angle $\\alpha$, in radians, represented as Double.\n2. A qubit in state $|\\psi\\rangle = \\beta |0\\rangle + \\gamma |1\\rangle$.\n\n**Goal:** Change the state of the qubit as follows:\n\n- If the qubit is in state $|0\\rangle$, change its state to $\\cos \\alpha |0\\rangle + \\sin \\alpha |1\\rangle$.\n- If the qubit is in state $|1\\rangle$, change its state to $-\\sin \\alpha |0\\rangle + \\cos \\alpha |1\\rangle$.\n- If the qubit is in superposition, change its state according to the effect on basis vectors.\n"
|
|
1593
|
+
},
|
|
1594
|
+
"sourceIds": [
|
|
1595
|
+
"single_qubit_gates__amplitude_change__Verification.qs",
|
|
1596
|
+
"KatasLibrary.qs"
|
|
1597
|
+
],
|
|
1598
|
+
"placeholderCode": "namespace Kata {\n operation AmplitudeChange (alpha : Double, q : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n \n }\n}\n\n",
|
|
1599
|
+
"explainedSolution": {
|
|
1600
|
+
"type": "explained-solution",
|
|
1601
|
+
"items": [
|
|
1602
|
+
{
|
|
1603
|
+
"type": "text-content",
|
|
1604
|
+
"asHtml": "<p>We can recognize that we need to use one of the rotation gates Rx, Ry, and Rz (named because they "rotate" the qubit state in the three dimensional space visualized as the Bloch sphere about the x, y, and z axes, respectively), since they involve angle parameters. Of these three gates, only Ry rotates the basis states $|0\\rangle$ and $|1\\rangle$ to have real amplitudes (the other two gates introduce complex coefficients).</p>\n<p>As a reminder,</p>\n<p>$$\nR_{y}(\\theta) =\n\\begin{bmatrix}\\cos \\frac{\\theta}{2} & -\\sin \\frac{\\theta}{2}\\\\ \\sin \\frac{\\theta}{2} & \\cos \\frac{\\theta}{2}\\end{bmatrix}\n$$</p>\n<p>Let's see its effect on the $|0\\rangle$ state:</p>\n<p>$$\nR_y(\\theta)|0\\rangle =\n\\begin{bmatrix}\\cos \\frac{\\theta}{2} & -\\sin \\frac{\\theta}{2}\\\\ \\sin \\frac{\\theta}{2} & \\cos \\frac{\\theta}{2} \\end{bmatrix}\n\\begin{bmatrix}1\\\\ 0\\\\ \\end{bmatrix}=\n\\begin{bmatrix}\\cos \\frac{\\theta}{2}\\cdot1 - \\sin \\frac{\\theta}{2}\\cdot0\\\\ \\sin \\frac{\\theta}{2}\\cdot1 + \\cos \\frac{\\theta}{2}\\cdot0\n\\end{bmatrix}=\n\\begin{bmatrix}\\cos \\frac{\\theta}{2}\\\\ \\sin \\frac{\\theta}{2}\\end{bmatrix}=\n\\cos\\frac{\\theta}{2} |0\\rangle + \\sin\\frac{\\theta}{2} |1\\rangle\n$$</p>\n<p>Recall that when applying a gate, you can tell what its matrix does to the basis states by looking at its columns: the first column of the matrix is the state into which it will transform the $|0\\rangle$ state, and the second column is the state into which it will transform the $|1\\rangle$ state.\nOne of the examples used by the testing harness has $\\beta = 0.6, \\gamma = 0.8$ and $\\alpha = 1.0471975511965976 = \\frac{\\pi}{3}$.\nSince $\\cos \\frac{\\pi}{3} = 0.5$ and $\\sin \\frac{\\pi}{3} = 0.8660$, working to 4 decimal places, we can use $\\frac{\\theta}{2} = \\alpha$ to compute:</p>\n<p>$$\nR_{y}(\\theta) |\\psi\\rangle=\n \\begin{bmatrix}\\cos \\frac{\\theta}{2} & -\\sin \\frac{\\theta}{2}\\\\ \\sin \\frac{\\theta}{2} & \\cos \\frac{\\theta}{2} \\end{bmatrix}\n \\begin{bmatrix}\\beta\\\\ \\gamma\\\\ \\end{bmatrix}=\n \\begin{bmatrix}\\cos \\frac{\\theta}{2}\\cdot\\beta - \\sin \\frac{\\theta}{2}\\cdot\\gamma\\\\ \\sin \\frac{\\theta}{2}\\cdot\\beta +\\cos \\frac{\\theta}{2}\\cdot\\gamma \\end{bmatrix}=\n \\begin{bmatrix} 0.6\\cdot\\cos \\frac{\\pi}{3} -0.8\\cdot\\sin \\frac{\\pi}{3}\\\\0.6\\cdot\\sin \\frac{\\pi}{3} +0.8\\cdot\\cos \\frac{\\pi}{3}\\end{bmatrix}=\n \\begin{bmatrix}0.3 - 0.6928\\\\ 0.5196 + 0.4\\end{bmatrix}=\n\\begin{bmatrix}-0.3928\\\\ 0.9196\\\\ \\end{bmatrix}\n$$</p>\n<p>Notice that we used $\\frac{\\theta}{2} = \\alpha$; this means that in the Q# code we need to pass the angle $\\theta = 2\\alpha$.</p>\n",
|
|
1605
|
+
"asMarkdown": "\nWe can recognize that we need to use one of the rotation gates Rx, Ry, and Rz (named because they \"rotate\" the qubit state in the three dimensional space visualized as the Bloch sphere about the x, y, and z axes, respectively), since they involve angle parameters. Of these three gates, only Ry rotates the basis states $|0\\rangle$ and $|1\\rangle$ to have real amplitudes (the other two gates introduce complex coefficients).\n\nAs a reminder,\n\n$$\nR_{y}(\\theta) =\n\\begin{bmatrix}\\cos \\frac{\\theta}{2} & -\\sin \\frac{\\theta}{2}\\\\\\ \\sin \\frac{\\theta}{2} & \\cos \\frac{\\theta}{2}\\end{bmatrix}\n$$\n\nLet's see its effect on the $|0\\rangle$ state:\n\n$$\nR_y(\\theta)|0\\rangle =\n\\begin{bmatrix}\\cos \\frac{\\theta}{2} & -\\sin \\frac{\\theta}{2}\\\\\\ \\sin \\frac{\\theta}{2} & \\cos \\frac{\\theta}{2} \\end{bmatrix}\n\\begin{bmatrix}1\\\\\\ 0\\\\\\ \\end{bmatrix}=\n\\begin{bmatrix}\\cos \\frac{\\theta}{2}\\cdot1 - \\sin \\frac{\\theta}{2}\\cdot0\\\\\\ \\sin \\frac{\\theta}{2}\\cdot1 + \\cos \\frac{\\theta}{2}\\cdot0\n\\end{bmatrix}=\n\\begin{bmatrix}\\cos \\frac{\\theta}{2}\\\\\\ \\sin \\frac{\\theta}{2}\\end{bmatrix}=\n\\cos\\frac{\\theta}{2} |0\\rangle + \\sin\\frac{\\theta}{2} |1\\rangle\n$$\n\nRecall that when applying a gate, you can tell what its matrix does to the basis states by looking at its columns: the first column of the matrix is the state into which it will transform the $|0\\rangle$ state, and the second column is the state into which it will transform the $|1\\rangle$ state.\nOne of the examples used by the testing harness has $\\beta = 0.6, \\gamma = 0.8$ and $\\alpha = 1.0471975511965976 = \\frac{\\pi}{3}$.\nSince $\\cos \\frac{\\pi}{3} = 0.5$ and $\\sin \\frac{\\pi}{3} = 0.8660$, working to 4 decimal places, we can use $\\frac{\\theta}{2} = \\alpha$ to compute:\n\n$$\nR_{y}(\\theta) |\\psi\\rangle=\n \\begin{bmatrix}\\cos \\frac{\\theta}{2} & -\\sin \\frac{\\theta}{2}\\\\\\ \\sin \\frac{\\theta}{2} & \\cos \\frac{\\theta}{2} \\end{bmatrix}\n \\begin{bmatrix}\\beta\\\\\\ \\gamma\\\\\\ \\end{bmatrix}=\n \\begin{bmatrix}\\cos \\frac{\\theta}{2}\\cdot\\beta - \\sin \\frac{\\theta}{2}\\cdot\\gamma\\\\\\ \\sin \\frac{\\theta}{2}\\cdot\\beta +\\cos \\frac{\\theta}{2}\\cdot\\gamma \\end{bmatrix}=\n \\begin{bmatrix} 0.6\\cdot\\cos \\frac{\\pi}{3} -0.8\\cdot\\sin \\frac{\\pi}{3}\\\\\\0.6\\cdot\\sin \\frac{\\pi}{3} +0.8\\cdot\\cos \\frac{\\pi}{3}\\end{bmatrix}=\n \\begin{bmatrix}0.3 - 0.6928\\\\\\ 0.5196 + 0.4\\end{bmatrix}=\n\\begin{bmatrix}-0.3928\\\\\\ 0.9196\\\\\\ \\end{bmatrix}\n$$\n\nNotice that we used $\\frac{\\theta}{2} = \\alpha$; this means that in the Q# code we need to pass the angle $\\theta = 2\\alpha$."
|
|
1606
|
+
},
|
|
1607
|
+
{
|
|
1608
|
+
"type": "solution",
|
|
1609
|
+
"id": "single_qubit_gates__amplitude_change_solution",
|
|
1610
|
+
"code": "namespace Kata {\n operation AmplitudeChange (alpha : Double, q : Qubit) : Unit is Adj + Ctl {\n Ry(2.0 * alpha, q);\n }\n}"
|
|
1611
|
+
}
|
|
1612
|
+
]
|
|
1613
|
+
}
|
|
1614
|
+
},
|
|
1395
1615
|
{
|
|
1396
1616
|
"type": "exercise",
|
|
1397
1617
|
"id": "single_qubit_gates__prepare_rotated_state",
|
|
@@ -2114,8 +2334,7 @@ export default {
|
|
|
2114
2334
|
},
|
|
2115
2335
|
"sourceIds": [
|
|
2116
2336
|
"single_qubit_measurements__distinguish_0_and_1__Verification.qs",
|
|
2117
|
-
"KatasLibrary.qs"
|
|
2118
|
-
"single_qubit_measurements__Common.qs"
|
|
2337
|
+
"KatasLibrary.qs"
|
|
2119
2338
|
],
|
|
2120
2339
|
"placeholderCode": "namespace Kata {\n operation IsQubitZero(q : Qubit) : Bool {\n // Implement your solution here...\n\n return false;\n }\n}\n",
|
|
2121
2340
|
"explainedSolution": {
|
|
@@ -2157,8 +2376,7 @@ export default {
|
|
|
2157
2376
|
},
|
|
2158
2377
|
"sourceIds": [
|
|
2159
2378
|
"single_qubit_measurements__distinguish_plus_and_minus__Verification.qs",
|
|
2160
|
-
"KatasLibrary.qs"
|
|
2161
|
-
"single_qubit_measurements__Common.qs"
|
|
2379
|
+
"KatasLibrary.qs"
|
|
2162
2380
|
],
|
|
2163
2381
|
"placeholderCode": "namespace Kata {\n operation IsQubitMinus(q : Qubit) : Bool {\n // Implement your solution here...\n\n return false;\n }\n}\n",
|
|
2164
2382
|
"explainedSolution": {
|
|
@@ -2200,8 +2418,7 @@ export default {
|
|
|
2200
2418
|
},
|
|
2201
2419
|
"sourceIds": [
|
|
2202
2420
|
"single_qubit_measurements__distinguish_orthogonal_states_1__Verification.qs",
|
|
2203
|
-
"KatasLibrary.qs"
|
|
2204
|
-
"single_qubit_measurements__Common.qs"
|
|
2421
|
+
"KatasLibrary.qs"
|
|
2205
2422
|
],
|
|
2206
2423
|
"placeholderCode": "namespace Kata {\n open Microsoft.Quantum.Math;\n\n operation IsQubitPsiPlus(q : Qubit) : Bool {\n // Implement your solution here...\n\n return false;\n }\n}\n",
|
|
2207
2424
|
"explainedSolution": {
|
|
@@ -2231,8 +2448,7 @@ export default {
|
|
|
2231
2448
|
},
|
|
2232
2449
|
"sourceIds": [
|
|
2233
2450
|
"single_qubit_measurements__distinguish_orthogonal_states_2__Verification.qs",
|
|
2234
|
-
"KatasLibrary.qs"
|
|
2235
|
-
"single_qubit_measurements__Common.qs"
|
|
2451
|
+
"KatasLibrary.qs"
|
|
2236
2452
|
],
|
|
2237
2453
|
"placeholderCode": "namespace Kata {\n operation IsQubitA(alpha : Double, q : Qubit) : Bool {\n // Implement your solution here...\n\n return false;\n }\n}\n",
|
|
2238
2454
|
"explainedSolution": {
|
|
@@ -2262,8 +2478,7 @@ export default {
|
|
|
2262
2478
|
},
|
|
2263
2479
|
"sourceIds": [
|
|
2264
2480
|
"single_qubit_measurements__a_b_basis_measurements__Verification.qs",
|
|
2265
|
-
"KatasLibrary.qs"
|
|
2266
|
-
"single_qubit_measurements__Common.qs"
|
|
2481
|
+
"KatasLibrary.qs"
|
|
2267
2482
|
],
|
|
2268
2483
|
"placeholderCode": "namespace Kata {\n operation MeasureInABBasis(alpha : Double, q : Qubit) : Result {\n // Implement your solution here...\n\n return Zero;\n }\n}\n",
|
|
2269
2484
|
"explainedSolution": {
|
|
@@ -2367,7 +2582,6 @@ export default {
|
|
|
2367
2582
|
},
|
|
2368
2583
|
"sourceIds": [
|
|
2369
2584
|
"multi_qubit_measurements__full_measurements__Verification.qs",
|
|
2370
|
-
"multi_qubit_measurements__Common.qs",
|
|
2371
2585
|
"KatasLibrary.qs"
|
|
2372
2586
|
],
|
|
2373
2587
|
"placeholderCode": "namespace Kata {\n operation BasisStateMeasurement(qs : Qubit[]) : Int {\n // Implement your solution here...\n\n return -1;\n }\n}\n",
|
|
@@ -2442,7 +2656,6 @@ export default {
|
|
|
2442
2656
|
},
|
|
2443
2657
|
"sourceIds": [
|
|
2444
2658
|
"multi_qubit_measurements__partial_measurements_for_system__Verification.qs",
|
|
2445
|
-
"multi_qubit_measurements__Common.qs",
|
|
2446
2659
|
"KatasLibrary.qs"
|
|
2447
2660
|
],
|
|
2448
2661
|
"placeholderCode": "namespace Kata {\n operation IsPlusPlusMinus(qs : Qubit[]) : Int {\n // Implement your solution here...\n\n return -1;\n }\n}\n",
|
|
@@ -2485,7 +2698,6 @@ export default {
|
|
|
2485
2698
|
},
|
|
2486
2699
|
"sourceIds": [
|
|
2487
2700
|
"multi_qubit_measurements__state_modification__Verification.qs",
|
|
2488
|
-
"multi_qubit_measurements__Common.qs",
|
|
2489
2701
|
"KatasLibrary.qs"
|
|
2490
2702
|
],
|
|
2491
2703
|
"placeholderCode": "namespace Kata {\n operation StateSelection(qs : Qubit[], ind : Int) : Unit {\n // Implement your solution here...\n\n }\n}\n",
|
|
@@ -2528,7 +2740,6 @@ export default {
|
|
|
2528
2740
|
},
|
|
2529
2741
|
"sourceIds": [
|
|
2530
2742
|
"multi_qubit_measurements__state_preparation__Verification.qs",
|
|
2531
|
-
"multi_qubit_measurements__Common.qs",
|
|
2532
2743
|
"KatasLibrary.qs"
|
|
2533
2744
|
],
|
|
2534
2745
|
"placeholderCode": "namespace Kata {\n operation PostSelection(qs : Qubit[]) : Unit {\n // Implement your solution here...\n\n }\n}\n",
|
|
@@ -2571,7 +2782,6 @@ export default {
|
|
|
2571
2782
|
},
|
|
2572
2783
|
"sourceIds": [
|
|
2573
2784
|
"multi_qubit_measurements__joint_measurements__Verification.qs",
|
|
2574
|
-
"multi_qubit_measurements__Common.qs",
|
|
2575
2785
|
"KatasLibrary.qs"
|
|
2576
2786
|
],
|
|
2577
2787
|
"placeholderCode": "namespace Kata {\n operation ParityMeasurement(qs : Qubit[]) : Int {\n // Implement your solution here...\n\n return -1;\n }\n}\n",
|
|
@@ -3691,11 +3901,11 @@ export default {
|
|
|
3691
3901
|
"globalCodeSources": [
|
|
3692
3902
|
{
|
|
3693
3903
|
"id": "getting_started__flip_qubit__Verification.qs",
|
|
3694
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Katas;\n\n operation FlipQubit(q : Qubit) : Unit is Adj + Ctl {\n X(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.FlipQubit(register[0]);\n let reference = register => FlipQubit(register[0]);\n let isCorrect = CheckOperationsEquivalence(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n Message(\"Congratulations! You have solved your first exercise.\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Look out for hints when your solution is incorrect.\");\n Message(\"Hint: examine the effect your solution has on the |0〉 state and compare it with the effect it \" +\n \"is expected to have.\");\n
|
|
3904
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Katas;\n\n operation FlipQubit(q : Qubit) : Unit is Adj + Ctl {\n X(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.FlipQubit(register[0]);\n let reference = register => FlipQubit(register[0]);\n let isCorrect = CheckOperationsEquivalence(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n Message(\"Congratulations! You have solved your first exercise.\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Look out for hints when your solution is incorrect.\");\n Message(\"Hint: examine the effect your solution has on the |0〉 state and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, (qs => ()), solution, reference);\n }\n isCorrect\n }\n}\n"
|
|
3695
3905
|
},
|
|
3696
3906
|
{
|
|
3697
3907
|
"id": "KatasLibrary.qs",
|
|
3698
|
-
"code": "// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nnamespace Microsoft.Quantum.Katas {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Random;\n\n /// # Summary\n /// Given two operations, checks whether they act identically for all input states.\n /// This operation is implemented by using the Choi–Jamiołkowski isomorphism.\n operation CheckOperationsEquivalence(\n op : (Qubit[] => Unit is Adj + Ctl),\n reference : (Qubit[] => Unit is Adj + Ctl),\n inputSize : Int)\n : Bool {\n Fact(inputSize > 0, \"`inputSize` must be positive\");\n use (control, target) = (Qubit[inputSize], Qubit[inputSize]);\n within {\n EntangleRegisters(control, target);\n }\n apply {\n op(target);\n Adjoint reference(target);\n }\n\n let areEquivalent = CheckAllZero(control + target);\n ResetAll(control + target);\n areEquivalent\n }\n\n /// # Summary\n /// Given two operations, checks whether they act identically (including global phase) for all input states.\n /// This is done through controlled versions of the operations instead of plain ones which convert the global phase\n /// into a relative phase that can be detected.\n operation CheckOperationsEquivalenceStrict(\n op : (Qubit[] => Unit is Adj + Ctl),\n reference : (Qubit[] => Unit is Adj + Ctl),\n inputSize : Int)\n : Bool {\n Fact(inputSize > 0, \"`inputSize` must be positive\");\n let controlledOp = register => Controlled op(register[...0], register[1...]);\n let controlledReference = register => Controlled reference(register[...0], register[1...]);\n let areEquivalent = CheckOperationsEquivalence(controlledOp, controlledReference, inputSize + 1);\n areEquivalent\n }\n\n /// # Summary\n /// Given two operations, checks whether they act identically on the zero state |0〉 ⊗ |0〉 ⊗ ... ⊗ |0〉 composed of\n /// `inputSize` qubits.\n operation CheckOperationsEquivalenceOnZeroState(\n op : (Qubit[] => Unit),\n reference : (Qubit[] => Unit is Adj),\n inputSize : Int)\n : Bool {\n Fact(inputSize > 0, \"`inputSize` must be positive\");\n use target = Qubit[inputSize];\n op(target);\n Adjoint reference(target);\n let isCorrect = CheckAllZero(target);\n ResetAll(target);\n isCorrect\n }\n\n /// # Summary\n /// Given two operations, checks whether they act identically on the zero state |0〉 ⊗ |0〉 ⊗ ... ⊗ |0〉 composed of\n /// `inputSize` qubits.\n /// This operation introduces a control qubit to convert a global phase into a relative phase to be able to detect\n /// it.\n operation CheckOperationsEquivalenceOnZeroStateStrict(\n op : (Qubit[] => Unit is Adj + Ctl),\n reference : (Qubit[] => Unit is Adj + Ctl),\n inputSize : Int)\n : Bool {\n Fact(inputSize > 0, \"`inputSize` must be positive\");\n use control = Qubit();\n use target = Qubit[inputSize];\n within {\n H(control);\n }\n apply {\n Controlled op([control], target);\n Adjoint Controlled reference([control], target);\n }\n\n let isCorrect = CheckAllZero([control] + target);\n ResetAll([control] + target);\n isCorrect\n }\n\n /// # Summary\n /// Shows the effect a quantum operation has on the quantum state.\n operation ShowEffectOnQuantumState(targetRegister : Qubit[], op : (Qubit[] => Unit is Adj + Ctl)) : Unit {\n Message(\"Quantum state before applying the operation:\");\n DumpMachine();\n\n // Apply the operation, dump the simulator state and \"undo\" the operation by applying the adjoint.\n Message(\"Quantum state after applying the operation:\");\n op(targetRegister);\n DumpMachine();\n Adjoint op(targetRegister);\n }\n\n /// # Summary\n /// Shows the comparison of the quantum state between a specific operation and a reference operation.\n operation ShowQuantumStateComparison(\n targetRegister : Qubit[],\n op : (Qubit[] => Unit is Adj + Ctl),\n reference : (Qubit[] => Unit is Adj + Ctl))\n : Unit {\n Message(\"Initial quantum state:\");\n DumpMachine();\n\n // Apply the reference operation, dump the simulator state and \"undo\" the operation by applying the adjoint.\n reference(targetRegister);\n Message(\"Expected quantum state after applying the operation:\");\n DumpMachine();\n Adjoint reference(targetRegister);\n\n // Apply the specific operation, dump the simulator state and \"undo\" the operation by applying the adjoint.\n op(targetRegister);\n Message(\"Actual quantum state after applying the operation:\");\n DumpMachine();\n Adjoint op(targetRegister);\n }\n\n /// # Summary\n /// Given two operations, checks whether they act identically on the zero state |0〉 ⊗ |0〉 ⊗ ... ⊗ |0〉 composed of\n /// `inputSize` qubits. If they don't, prints user feedback.\n operation CheckOperationsEquivalenceOnZeroStateWithFeedback(\n testImpl : (Qubit[] => Unit is Adj + Ctl),\n refImpl : (Qubit[] => Unit is Adj + Ctl),\n inputSize : Int\n ) : Bool {\n\n let isCorrect = CheckOperationsEquivalenceOnZeroState(testImpl, refImpl, inputSize);\n\n // Output different feedback to the user depending on whether the exercise was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n use target = Qubit[inputSize];\n ShowQuantumStateComparison(target, testImpl, refImpl);\n ResetAll(target);\n }\n isCorrect\n }\n\n\n internal operation EntangleRegisters(\n control : Qubit[],\n target : Qubit[]) : Unit is Adj + Ctl {\n Fact(\n Length(control) == Length(target),\n $\"The length of qubit registers must be the same.\");\n\n for index in IndexRange(control) {\n H(control[index]);\n CNOT(control[index], target[index]);\n }\n }\n\n\n /// # Summary\n /// Prepare a random uneven superposition state on the given qubit array.\n operation PrepRandomState(qs : Qubit[]) : Unit {\n for q in qs {\n Ry(DrawRandomDouble(0.01, 0.99) * 2.0, q);\n }\n }\n}\n"
|
|
3908
|
+
"code": "// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nnamespace Microsoft.Quantum.Katas {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Random;\n\n /// # Summary\n /// Given two operations, checks whether they act identically for all input states.\n /// This operation is implemented by using the Choi–Jamiołkowski isomorphism.\n operation CheckOperationsEquivalence(\n op : (Qubit[] => Unit is Adj + Ctl),\n reference : (Qubit[] => Unit is Adj + Ctl),\n inputSize : Int)\n : Bool {\n Fact(inputSize > 0, \"`inputSize` must be positive\");\n use (control, target) = (Qubit[inputSize], Qubit[inputSize]);\n within {\n EntangleRegisters(control, target);\n }\n apply {\n op(target);\n Adjoint reference(target);\n }\n\n let areEquivalent = CheckAllZero(control + target);\n ResetAll(control + target);\n areEquivalent\n }\n\n /// # Summary\n /// Given two operations, checks whether they act identically (including global phase) for all input states.\n /// This is done through controlled versions of the operations instead of plain ones which convert the global phase\n /// into a relative phase that can be detected.\n operation CheckOperationsEquivalenceStrict(\n op : (Qubit[] => Unit is Adj + Ctl),\n reference : (Qubit[] => Unit is Adj + Ctl),\n inputSize : Int)\n : Bool {\n Fact(inputSize > 0, \"`inputSize` must be positive\");\n let controlledOp = register => Controlled op(register[...0], register[1...]);\n let controlledReference = register => Controlled reference(register[...0], register[1...]);\n let areEquivalent = CheckOperationsEquivalence(controlledOp, controlledReference, inputSize + 1);\n areEquivalent\n }\n\n /// # Summary\n /// Given two operations, checks whether they act identically on the zero state |0〉 ⊗ |0〉 ⊗ ... ⊗ |0〉 composed of\n /// `inputSize` qubits.\n operation CheckOperationsEquivalenceOnZeroState(\n op : (Qubit[] => Unit),\n reference : (Qubit[] => Unit is Adj),\n inputSize : Int)\n : Bool {\n Fact(inputSize > 0, \"`inputSize` must be positive\");\n use target = Qubit[inputSize];\n op(target);\n Adjoint reference(target);\n let isCorrect = CheckAllZero(target);\n ResetAll(target);\n isCorrect\n }\n\n /// # Summary\n /// Given two operations, checks whether they act identically on the zero state |0〉 ⊗ |0〉 ⊗ ... ⊗ |0〉 composed of\n /// `inputSize` qubits.\n /// This operation introduces a control qubit to convert a global phase into a relative phase to be able to detect\n /// it.\n operation CheckOperationsEquivalenceOnZeroStateStrict(\n op : (Qubit[] => Unit is Adj + Ctl),\n reference : (Qubit[] => Unit is Adj + Ctl),\n inputSize : Int)\n : Bool {\n Fact(inputSize > 0, \"`inputSize` must be positive\");\n use control = Qubit();\n use target = Qubit[inputSize];\n within {\n H(control);\n }\n apply {\n Controlled op([control], target);\n Adjoint Controlled reference([control], target);\n }\n\n let isCorrect = CheckAllZero([control] + target);\n ResetAll([control] + target);\n isCorrect\n }\n\n\n /// # Summary\n /// Shows the comparison of the quantum state between a specific operation and a reference operation.\n operation ShowQuantumStateComparison(\n registerSize : Int,\n initialState : Qubit[] => Unit,\n op : Qubit[] => Unit,\n reference : Qubit[] => Unit)\n : Unit {\n {\n use register = Qubit[registerSize];\n initialState(register);\n\n Message(\"Initial quantum state:\");\n DumpMachine();\n\n // Apply the reference operation and dump the simulator state\n reference(register);\n Message(\"Expected quantum state after applying the operation:\");\n DumpMachine();\n ResetAll(register);\n }\n\n {\n use register = Qubit[registerSize];\n initialState(register);\n // Apply the comparison operation and dump the simulator state\n op(register);\n Message(\"Actual quantum state after applying the operation:\");\n DumpMachine();\n ResetAll(register);\n }\n }\n\n /// # Summary\n /// Given two operations, checks whether they act identically on the zero state |0〉 ⊗ |0〉 ⊗ ... ⊗ |0〉 composed of\n /// `inputSize` qubits. If they don't, prints user feedback.\n operation CheckOperationsEquivalenceOnZeroStateWithFeedback(\n testImpl : (Qubit[] => Unit),\n refImpl : (Qubit[] => Unit is Adj),\n inputSize : Int\n ) : Bool {\n\n let isCorrect = CheckOperationsEquivalenceOnZeroState(testImpl, refImpl, inputSize);\n\n // Output different feedback to the user depending on whether the exercise was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n ShowQuantumStateComparison(inputSize, (qs => ()), testImpl, refImpl);\n }\n isCorrect\n }\n\n\n internal operation EntangleRegisters(\n control : Qubit[],\n target : Qubit[]) : Unit is Adj + Ctl {\n Fact(\n Length(control) == Length(target),\n $\"The length of qubit registers must be the same.\");\n\n for index in IndexRange(control) {\n H(control[index]);\n CNOT(control[index], target[index]);\n }\n }\n\n\n /// # Summary\n /// Prepare a random uneven superposition state on the given qubit array.\n operation PrepRandomState(qs : Qubit[]) : Unit {\n for q in qs {\n Ry(DrawRandomDouble(0.01, 0.99) * 2.0, q);\n }\n }\n\n\n // \"Framework\" operation for testing single-qubit tasks for distinguishing states of one qubit\n // with Bool return\n operation DistinguishTwoStates_SingleQubit(\n statePrep : ((Qubit, Int) => Unit is Adj),\n testImpl : (Qubit => Bool),\n stateNames : String[],\n preserveState : Bool) : Bool {\n\n let nTotal = 100;\n let nStates = 2;\n mutable misclassifications = [0, size=nStates];\n\n use q = Qubit();\n for _ in 1 .. nTotal {\n // get a random bit to define whether qubit will be in a state corresponding to true return (1) or to false one (0)\n // state = 0 false return\n // state = 1 true return\n let state = DrawRandomInt(0, 1);\n\n // do state prep: convert |0⟩ to outcome with false return or to outcome with true return depending on state\n statePrep(q, state);\n\n // get the solution's answer and verify if NOT a match, then differentiate what kind of mismatch\n let ans = testImpl(q);\n if ans != (state == 1) {\n set misclassifications w/= state <- misclassifications[state] + 1;\n }\n\n // If the final state is to be preserved, check if it was not modified\n if preserveState {\n Adjoint statePrep(q, state);\n if not CheckZero(q) {\n Message($\"Input quantum state {stateNames[state]} was not preserved during the measurement.\");\n Reset(q);\n return false;\n }\n } else {\n Reset(q);\n }\n }\n\n mutable totalMisclassifications = 0;\n for i in 0 .. nStates - 1 {\n if misclassifications[i] != 0 {\n set totalMisclassifications += misclassifications[i];\n Message($\"Misclassified {stateNames[i]} as {stateNames[1 - i]} in {misclassifications[i]} test runs.\");\n }\n }\n\n totalMisclassifications == 0\n }\n\n\n // \"Framework\" operation for testing multi-qubit tasks for distinguishing states of an array of qubits\n // with Int return\n operation DistinguishStates_MultiQubit(\n nQubits : Int,\n nStates : Int,\n statePrep : ((Qubit[], Int, Double) => Unit is Adj),\n testImpl : (Qubit[] => Int),\n preserveState : Bool,\n stateNames : String[]) : Bool {\n\n let nTotal = 100;\n // misclassifications will store the number of times state i has been classified as state j (dimension nStates^2)\n mutable misclassifications = [0, size = nStates * nStates];\n // unknownClassifications will store the number of times state i has been classified as some invalid state (index < 0 or >= nStates)\n mutable unknownClassifications = [0, size = nStates];\n\n use qs = Qubit[nQubits];\n for _ in 1 .. nTotal {\n // get a random integer to define the state of the qubits\n let state = DrawRandomInt(0, nStates - 1);\n // get a random rotation angle to define the exact state of the qubits\n // for some exercises, this value might be a dummy variable which does not matter\n let alpha = DrawRandomDouble(0.0, 1.0) * PI();\n\n // do state prep: convert |0...0⟩ to outcome with return equal to state\n statePrep(qs, state, alpha);\n\n // get the solution's answer and verify that it's a match, if not, increase the exact mismatch count\n let ans = testImpl(qs);\n if ans >= 0 and ans < nStates {\n // classification result is a valid state index - check if is it correct\n if ans != state {\n set misclassifications w/= ((state * nStates) + ans) <- (misclassifications[(state * nStates) + ans] + 1);\n }\n }\n else {\n // classification result is an invalid state index - file it separately\n set unknownClassifications w/= state <- (unknownClassifications[state] + 1);\n }\n\n if preserveState {\n // check that the state of the qubit after the operation is unchanged\n Adjoint statePrep(qs, state, alpha);\n if not CheckAllZero(qs) {\n Message($\"Input quantum state {stateNames[state]} was not preserved during the measurement.\");\n ResetAll(qs);\n return false;\n }\n } else {\n // we're not checking the state of the qubit after the operation\n ResetAll(qs);\n }\n }\n\n mutable totalMisclassifications = 0;\n for i in 0 .. nStates - 1 {\n for j in 0 .. nStates - 1 {\n if misclassifications[(i * nStates) + j] != 0 {\n set totalMisclassifications += misclassifications[i * nStates + j];\n Message($\"Misclassified {stateNames[i]} as {stateNames[j]} in {misclassifications[(i * nStates) + j]} test runs.\");\n }\n }\n if unknownClassifications[i] != 0 {\n set totalMisclassifications += unknownClassifications[i];\n Message($\"Misclassified {stateNames[i]} as Unknown State in {unknownClassifications[i]} test runs.\");\n }\n }\n totalMisclassifications == 0\n }\n\n}\n"
|
|
3699
3909
|
},
|
|
3700
3910
|
{
|
|
3701
3911
|
"id": "complex_arithmetic__powers_of_i__Verification.qs",
|
|
@@ -3797,33 +4007,61 @@ export default {
|
|
|
3797
4007
|
"id": "qubit__learn_single_qubit_state__Verification.qs",
|
|
3798
4008
|
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Math;\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n use q = Qubit();\n\n // Prepare the state that will be passed to the solution.\n let angle = 0.5;\n Ry(angle, q);\n\n // Call the solution and get the answer.\n let (a, b) = Kata.LearnSingleQubitState(q);\n\n // Calculate the expected values based on the rotation angle.\n let (a_exp, b_exp) = (Cos(0.5 * angle), Sin(0.5 * angle));\n\n Reset(q);\n\n let isCorrect =\n (AbsD(a - a_exp) <= 0.001) and\n (AbsD(b - b_exp) <= 0.001);\n\n // Output different feedback to the user depending on whether the exercise was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"At least one of the amplitudes was too far from the expected value.\");\n }\n\n isCorrect\n }\n}\n"
|
|
3799
4009
|
},
|
|
4010
|
+
{
|
|
4011
|
+
"id": "single_qubit_gates__state_flip__Verification.qs",
|
|
4012
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation StateFlip(q : Qubit) : Unit is Adj + Ctl {\n X(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.StateFlip(register[0]);\n let reference = register => StateFlip(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0]), solution, reference);\n }\n isCorrect\n }\n}"
|
|
4013
|
+
},
|
|
4014
|
+
{
|
|
4015
|
+
"id": "single_qubit_gates__sign_flip__Verification.qs",
|
|
4016
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation SignFlip(q : Qubit) : Unit is Adj + Ctl {\n Z(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.SignFlip(register[0]);\n let reference = register => SignFlip(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0]), solution, reference);\n }\n isCorrect\n }\n}\n"
|
|
4017
|
+
},
|
|
3800
4018
|
{
|
|
3801
4019
|
"id": "single_qubit_gates__y_gate__Verification.qs",
|
|
3802
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation ApplyY(q : Qubit) : Unit is Adj + Ctl {\n Y(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.ApplyY(register[0]);\n let reference = register => ApplyY(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n
|
|
4020
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation ApplyY(q : Qubit) : Unit is Adj + Ctl {\n Y(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.ApplyY(register[0]);\n let reference = register => ApplyY(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0]), solution, reference);\n }\n isCorrect\n }\n}\n"
|
|
4021
|
+
},
|
|
4022
|
+
{
|
|
4023
|
+
"id": "single_qubit_gates__sign_flip_on_zero__Verification.qs",
|
|
4024
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation SignFlipOnZero(q : Qubit) : Unit is Adj + Ctl {\n X(q);\n Z(q);\n X(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.SignFlipOnZero(register[0]);\n let reference = register => SignFlipOnZero(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the exercise was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0]), solution, reference);\n }\n isCorrect\n }\n}\n"
|
|
4025
|
+
},
|
|
4026
|
+
{
|
|
4027
|
+
"id": "single_qubit_gates__global_phase_minusone__Verification.qs",
|
|
4028
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Canon;\n open Microsoft.Quantum.Intrinsic;\n\n\n operation GlobalPhaseChange (q : Qubit) : Unit is Adj + Ctl {\n Z(q);\n X(q);\n Z(q);\n X(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.GlobalPhaseChange(register[0]);\n let reference = register => GlobalPhaseChange(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0]), solution, reference);\n }\n isCorrect\n }\n}\n"
|
|
3803
4029
|
},
|
|
3804
4030
|
{
|
|
3805
4031
|
"id": "single_qubit_gates__global_phase_i__Verification.qs",
|
|
3806
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation GlobalPhaseI(q : Qubit) : Unit is Adj + Ctl {\n X(q);\n Z(q);\n Y(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.GlobalPhaseI(register[0]);\n let reference = register => GlobalPhaseI(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n
|
|
4032
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation GlobalPhaseI(q : Qubit) : Unit is Adj + Ctl {\n X(q);\n Z(q);\n Y(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.GlobalPhaseI(register[0]);\n let reference = register => GlobalPhaseI(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0]), solution, reference);\n }\n isCorrect\n }\n}\n"
|
|
3807
4033
|
},
|
|
3808
4034
|
{
|
|
3809
|
-
"id": "
|
|
3810
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation
|
|
4035
|
+
"id": "single_qubit_gates__basis_change__Verification.qs",
|
|
4036
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation BasisChange(q : Qubit) : Unit is Adj + Ctl {\n H(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.BasisChange(register[0]);\n let reference = register => BasisChange(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0]), solution, reference);\n }\n isCorrect\n }\n}\n"
|
|
3811
4037
|
},
|
|
3812
4038
|
{
|
|
3813
4039
|
"id": "single_qubit_gates__prepare_minus__Verification.qs",
|
|
3814
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation PrepareMinus(q : Qubit) : Unit is Adj + Ctl {\n X(q);\n H(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.PrepareMinus(register[0]);\n let reference = register => PrepareMinus(register[0]);\n let isCorrect = CheckOperationsEquivalenceOnZeroStateStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the exercise was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the state prepared by your solution and compare it with the state it \" +\n \"is expected to prepare.\");\n
|
|
4040
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation PrepareMinus(q : Qubit) : Unit is Adj + Ctl {\n X(q);\n H(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.PrepareMinus(register[0]);\n let reference = register => PrepareMinus(register[0]);\n let isCorrect = CheckOperationsEquivalenceOnZeroStateStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the exercise was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the state prepared by your solution and compare it with the state it \" +\n \"is expected to prepare.\");\n ShowQuantumStateComparison(1, qs => (), solution, reference);\n }\n isCorrect\n }\n}\n"
|
|
4041
|
+
},
|
|
4042
|
+
{
|
|
4043
|
+
"id": "single_qubit_gates__phase_i__Verification.qs",
|
|
4044
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Convert;\n\n operation PhaseFlip (q : Qubit) : Unit is Adj + Ctl {\n S(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.PhaseFlip(register[0]);\n let reference = register => PhaseFlip(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0]), solution, reference);\n }\n isCorrect\n }\n}\n"
|
|
3815
4045
|
},
|
|
3816
4046
|
{
|
|
3817
4047
|
"id": "single_qubit_gates__three_quarters_pi_phase__Verification.qs",
|
|
3818
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation ThreeQuartersPiPhase(q : Qubit) : Unit is Adj + Ctl {\n S(q);\n T(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.ThreeQuartersPiPhase(register[0]);\n let reference = register => ThreeQuartersPiPhase(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the exercise was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n
|
|
4048
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation ThreeQuartersPiPhase(q : Qubit) : Unit is Adj + Ctl {\n S(q);\n T(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.ThreeQuartersPiPhase(register[0]);\n let reference = register => ThreeQuartersPiPhase(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the exercise was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0]), solution, reference);\n }\n isCorrect\n }\n}\n"
|
|
4049
|
+
},
|
|
4050
|
+
{
|
|
4051
|
+
"id": "single_qubit_gates__complex_phase__Verification.qs",
|
|
4052
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Convert;\n\n operation PhaseChange (alpha : Double, q : Qubit) : Unit is Adj+Ctl {\n R1(alpha, q); \n }\n\n operation CheckSolution() : Bool {\n for i in 0 .. 36 {\n let alpha = ((2.0 * PI()) * IntAsDouble(i)) / 36.0;\n let solution = register => Kata.PhaseChange(alpha, register[0]);\n let reference = register => PhaseChange(alpha, register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n if not isCorrect {\n Message(\"Incorrect.\");\n Message($\"The solution was incorrect for the test case alpha = {alpha}.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0]), solution, reference);\n return false;\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}"
|
|
4053
|
+
},
|
|
4054
|
+
{
|
|
4055
|
+
"id": "single_qubit_gates__amplitude_change__Verification.qs",
|
|
4056
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Convert;\n\n operation AmplitudeChange (alpha : Double, q : Qubit) : Unit is Adj+Ctl {\n Ry(2.0 * alpha, q);\n }\n\n operation CheckSolution() : Bool {\n for i in 0 .. 36 {\n let alpha = ((2.0 * PI()) * IntAsDouble(i)) / 36.0;\n let solution = register => Kata.AmplitudeChange(alpha, register[0]);\n let reference = register => AmplitudeChange(alpha, register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n if not isCorrect {\n Message(\"Incorrect.\");\n Message($\"The solution was incorrect for the test case alpha = {alpha}.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0]), solution, reference);\n return false;\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
|
|
3819
4057
|
},
|
|
3820
4058
|
{
|
|
3821
4059
|
"id": "single_qubit_gates__prepare_rotated_state__Verification.qs",
|
|
3822
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation PrepareRotatedState (alpha : Double, beta : Double, q : Qubit) : Unit is Adj+Ctl {\n let phi = ArcTan2(beta, alpha);\n Rx(2.0 * phi, q);\n }\n\n operation CheckSolution() : Bool {\n for i in 0 .. 10 {\n let i = IntAsDouble(i);\n let alpha = Cos(i);\n let beta = Sin(i);\n let solution = register => Kata.PrepareRotatedState(alpha, beta, register[0]);\n let reference = register => PrepareRotatedState(alpha, beta, register[0]);\n let isCorrect = CheckOperationsEquivalenceOnZeroStateStrict(solution, reference, 1);\n if not isCorrect {\n Message(\"Incorrect.\");\n Message($\"The solution was incorrect for the test case alpha = {alpha}, beta = {beta}.\");\n Message(\"Hint: examine the state prepared by your solution and compare it with the state it \" +\n \"is expected to prepare.\");\n
|
|
4060
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation PrepareRotatedState (alpha : Double, beta : Double, q : Qubit) : Unit is Adj+Ctl {\n let phi = ArcTan2(beta, alpha);\n Rx(2.0 * phi, q);\n }\n\n operation CheckSolution() : Bool {\n for i in 0 .. 10 {\n let i = IntAsDouble(i);\n let alpha = Cos(i);\n let beta = Sin(i);\n let solution = register => Kata.PrepareRotatedState(alpha, beta, register[0]);\n let reference = register => PrepareRotatedState(alpha, beta, register[0]);\n let isCorrect = CheckOperationsEquivalenceOnZeroStateStrict(solution, reference, 1);\n if not isCorrect {\n Message(\"Incorrect.\");\n Message($\"The solution was incorrect for the test case alpha = {alpha}, beta = {beta}.\");\n Message(\"Hint: examine the state prepared by your solution and compare it with the state it \" +\n \"is expected to prepare.\");\n ShowQuantumStateComparison(1, qs => (), solution, reference);\n return false;\n }\n }\n\n Message(\"Correct!\");\n Message(\"The solution was correct for all test cases.\");\n true\n }\n}\n"
|
|
3823
4061
|
},
|
|
3824
4062
|
{
|
|
3825
4063
|
"id": "single_qubit_gates__prepare_arbitrary_state__Verification.qs",
|
|
3826
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation PrepareArbitraryState (alpha : Double, beta : Double, theta : Double, q : Qubit) : Unit is Adj+Ctl {\n let phi = ArcTan2(beta, alpha);\n Ry(2.0 * phi, q);\n R1(theta, q);\n }\n\n operation CheckSolution() : Bool {\n for i in 0 .. 10 {\n let i = IntAsDouble(i);\n let alpha = Cos(i);\n let beta = Sin(i);\n let theta = Sin(i);\n let solution = register => Kata.PrepareArbitraryState(alpha, beta, theta, register[0]);\n let reference = register => PrepareArbitraryState(alpha, beta, theta, register[0]);\n let isCorrect = CheckOperationsEquivalenceOnZeroStateStrict(solution, reference, 1);\n if not isCorrect {\n Message(\"Incorrect.\");\n Message($\"The solution was incorrect for the test case alpha = {alpha}, beta = {beta}, theta = {theta}.\");\n Message(\"Hint: examine the state prepared by your solution and compare it with the state it \" +\n \"is expected to prepare.\");\n
|
|
4064
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation PrepareArbitraryState (alpha : Double, beta : Double, theta : Double, q : Qubit) : Unit is Adj+Ctl {\n let phi = ArcTan2(beta, alpha);\n Ry(2.0 * phi, q);\n R1(theta, q);\n }\n\n operation CheckSolution() : Bool {\n for i in 0 .. 10 {\n let i = IntAsDouble(i);\n let alpha = Cos(i);\n let beta = Sin(i);\n let theta = Sin(i);\n let solution = register => Kata.PrepareArbitraryState(alpha, beta, theta, register[0]);\n let reference = register => PrepareArbitraryState(alpha, beta, theta, register[0]);\n let isCorrect = CheckOperationsEquivalenceOnZeroStateStrict(solution, reference, 1);\n if not isCorrect {\n Message(\"Incorrect.\");\n Message($\"The solution was incorrect for the test case alpha = {alpha}, beta = {beta}, theta = {theta}.\");\n Message(\"Hint: examine the state prepared by your solution and compare it with the state it \" +\n \"is expected to prepare.\");\n ShowQuantumStateComparison(1, qs => (), solution, reference);\n return false;\n }\n }\n\n Message(\"Correct!\");\n Message(\"The solution was correct for all test cases.\");\n true\n }\n}\n"
|
|
3827
4065
|
},
|
|
3828
4066
|
{
|
|
3829
4067
|
"id": "multi_qubit_systems__learn_basis_state_amplitudes__Verification.qs",
|
|
@@ -3847,11 +4085,11 @@ export default {
|
|
|
3847
4085
|
},
|
|
3848
4086
|
{
|
|
3849
4087
|
"id": "multi_qubit_gates__compound_gate__Verification.qs",
|
|
3850
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation CompoundGate (qs : Qubit[]) : Unit is Adj + Ctl {\n S(qs[0]);\n I(qs[1]); // this line can be omitted, since it doesn't change the qubit state\n Y(qs[2]);\n }\n\n operation CheckSolution() : Bool {\n let solution = Kata.CompoundGate;\n let reference = CompoundGate;\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 3);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n \"transformation\");\n
|
|
4088
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation CompoundGate (qs : Qubit[]) : Unit is Adj + Ctl {\n S(qs[0]);\n I(qs[1]); // this line can be omitted, since it doesn't change the qubit state\n Y(qs[2]);\n }\n\n operation CheckSolution() : Bool {\n let solution = Kata.CompoundGate;\n let reference = CompoundGate;\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 3);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n \"transformation\");\n ShowQuantumStateComparison(3, PrepRandomState, solution, reference);\n }\n\n isCorrect\n }\n}"
|
|
3851
4089
|
},
|
|
3852
4090
|
{
|
|
3853
4091
|
"id": "multi_qubit_gates__preparing_bell_state__Verification.qs",
|
|
3854
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation BellState (qs : Qubit[]) : Unit is Adj + Ctl {\n H(qs[0]);\n CNOT(qs[0], qs[1]);\n }\n\n operation CheckSolution() : Bool {\n let solution = Kata.BellState;\n let reference = BellState;\n let isCorrect = CheckOperationsEquivalenceOnZeroState(solution, reference, 2);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect
|
|
4092
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation BellState (qs : Qubit[]) : Unit is Adj + Ctl {\n H(qs[0]);\n CNOT(qs[0], qs[1]);\n }\n\n operation CheckSolution() : Bool {\n let solution = Kata.BellState;\n let reference = BellState;\n let isCorrect = CheckOperationsEquivalenceOnZeroState(solution, reference, 2);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the state prepared by your solution and compare it with the state it \" +\n \"is expected to prepare.\");\n ShowQuantumStateComparison(2, (qs => ()), solution, reference);\n }\n\n isCorrect\n }\n}"
|
|
3855
4093
|
},
|
|
3856
4094
|
{
|
|
3857
4095
|
"id": "multi_qubit_gates__qubit_swap__Verification.qs",
|
|
@@ -3867,39 +4105,31 @@ export default {
|
|
|
3867
4105
|
},
|
|
3868
4106
|
{
|
|
3869
4107
|
"id": "single_qubit_measurements__distinguish_0_and_1__Verification.qs",
|
|
3870
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.
|
|
3871
|
-
},
|
|
3872
|
-
{
|
|
3873
|
-
"id": "single_qubit_measurements__Common.qs",
|
|
3874
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Random;\n\n // \"Framework\" operation for testing single-qubit tasks for distinguishing states of one qubit\n // with Bool return\n operation DistinguishTwoStates(\n statePrep : ((Qubit, Int) => Unit is Adj),\n testImpl : (Qubit => Bool),\n stateName : String[],\n checkFinalState : Bool) : Bool {\n\n let nTotal = 100;\n let nStates = 2;\n mutable misclassifications = Repeated(0, nStates);\n\n use q = Qubit();\n for i in 1 .. nTotal {\n // get a random bit to define whether qubit will be in a state corresponding to true return (1) or to false one (0)\n // state = 0 false return\n // state = 1 true return\n let state = DrawRandomInt(0, 1);\n\n // do state prep: convert |0⟩ to outcome with false return or to outcome with true return depending on state\n statePrep(q, state);\n\n // get the solution's answer and verify if NOT a match, then differentiate what kind of mismatch\n let ans = testImpl(q);\n if ans != (state == 1) {\n set misclassifications w/= state <- misclassifications[state] + 1;\n }\n\n // If the final state is to be verified, check if it matches the measurement outcome\n if checkFinalState {\n Adjoint statePrep(q, state);\n Fact(CheckZero(q), \"Returned Bool value does not match the expected qubit state.\");\n } else {\n Reset(q);\n }\n }\n\n mutable totalMisclassifications = 0;\n for i in 0 .. nStates - 1 {\n if misclassifications[i] != 0 {\n set totalMisclassifications += misclassifications[i];\n Message($\"Misclassified {stateName[i]} as {stateName[1 - i]} in {misclassifications[i]} test runs.\");\n }\n }\n\n return totalMisclassifications == 0;\n }\n\n}\n"
|
|
4108
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Katas;\n\n operation StatePrep_IsQubitZero (q : Qubit, state : Int) : Unit is Adj {\n if state == 0 {\n // convert |0⟩ to |1⟩\n X(q);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let isCorrect = DistinguishTwoStates_SingleQubit(\n StatePrep_IsQubitZero,\n Kata.IsQubitZero,\n [\"|1⟩\", \"|0⟩\"],\n false);\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n }\n isCorrect\n }\n\n}\n"
|
|
3875
4109
|
},
|
|
3876
4110
|
{
|
|
3877
4111
|
"id": "single_qubit_measurements__distinguish_plus_and_minus__Verification.qs",
|
|
3878
|
-
"code": "namespace Kata.Verification {\n\n // Distinguish |+❭ and |-❭ using Measure operation\n operation StatePrep_IsQubitMinus (q : Qubit, state : Int) : Unit is Adj {\n if state == 1 {\n // convert |0⟩ to |-⟩\n X(q);\n H(q);\n } else {\n // convert |0⟩ to |+⟩\n H(q);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let isCorrect =
|
|
4112
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n // Distinguish |+❭ and |-❭ using Measure operation\n operation StatePrep_IsQubitMinus (q : Qubit, state : Int) : Unit is Adj {\n if state == 1 {\n // convert |0⟩ to |-⟩\n X(q);\n H(q);\n } else {\n // convert |0⟩ to |+⟩\n H(q);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let isCorrect = DistinguishTwoStates_SingleQubit(\n StatePrep_IsQubitMinus,\n Kata.IsQubitMinus,\n [\"|+⟩\", \"|-⟩\"],\n false);\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n }\n isCorrect\n }\n\n}\n"
|
|
3879
4113
|
},
|
|
3880
4114
|
{
|
|
3881
4115
|
"id": "single_qubit_measurements__distinguish_orthogonal_states_1__Verification.qs",
|
|
3882
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Math;\n\n // Distinguish specific orthogonal states\n // |ψ₊⟩ = 0.6 * |0⟩ + 0.8 * |1⟩,\n // |ψ₋⟩ = -0.8 * |0⟩ + 0.6 * |1⟩.\n operation StatePrep_IsQubitPsiPlus(q : Qubit, state : Int) : Unit is Adj {\n if state == 0 {\n // convert |0⟩ to |ψ₋⟩\n X(q);\n Ry(2.0 * ArcTan2(0.8, 0.6), q);\n } else {\n // convert |0⟩ to |ψ₊⟩\n Ry(2.0 * ArcTan2(0.8, 0.6), q);\n }\n }\n\n operation CheckSolution() : Bool {\n let isCorrect =
|
|
4116
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Katas;\n\n // Distinguish specific orthogonal states\n // |ψ₊⟩ = 0.6 * |0⟩ + 0.8 * |1⟩,\n // |ψ₋⟩ = -0.8 * |0⟩ + 0.6 * |1⟩.\n operation StatePrep_IsQubitPsiPlus(q : Qubit, state : Int) : Unit is Adj {\n if state == 0 {\n // convert |0⟩ to |ψ₋⟩\n X(q);\n Ry(2.0 * ArcTan2(0.8, 0.6), q);\n } else {\n // convert |0⟩ to |ψ₊⟩\n Ry(2.0 * ArcTan2(0.8, 0.6), q);\n }\n }\n\n operation CheckSolution() : Bool {\n let isCorrect = DistinguishTwoStates_SingleQubit(\n StatePrep_IsQubitPsiPlus,\n Kata.IsQubitPsiPlus,\n [\"|ψ₋⟩\", \"|ψ₊⟩\"],\n false);\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n }\n isCorrect\n }\n\n}\n"
|
|
3883
4117
|
},
|
|
3884
4118
|
{
|
|
3885
4119
|
"id": "single_qubit_measurements__distinguish_orthogonal_states_2__Verification.qs",
|
|
3886
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Math;\n\n // Distinguish states |A❭ and |B❭\n // |A⟩ = cos(alpha) * |0⟩ - i sin(alpha) * |1⟩,\n // |B⟩ = - i sin(alpha) * |0⟩ + cos(alpha) * |1⟩.\n operation StatePrep_IsQubitA(alpha : Double, q : Qubit, state : Int) : Unit is Adj {\n if state == 0 {\n // convert |0⟩ to |B⟩\n X(q);\n Rx(2.0 * alpha, q);\n } else {\n // convert |0⟩ to |A⟩\n Rx(2.0 * alpha, q);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for i in 0 .. 10 {\n let alpha = (PI() * IntAsDouble(i)) / 10.0;\n let isCorrect =
|
|
4120
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Katas;\n\n // Distinguish states |A❭ and |B❭\n // |A⟩ = cos(alpha) * |0⟩ - i sin(alpha) * |1⟩,\n // |B⟩ = - i sin(alpha) * |0⟩ + cos(alpha) * |1⟩.\n operation StatePrep_IsQubitA(alpha : Double, q : Qubit, state : Int) : Unit is Adj {\n if state == 0 {\n // convert |0⟩ to |B⟩\n X(q);\n Rx(2.0 * alpha, q);\n } else {\n // convert |0⟩ to |A⟩\n Rx(2.0 * alpha, q);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for i in 0 .. 10 {\n let alpha = (PI() * IntAsDouble(i)) / 10.0;\n let isCorrect = DistinguishTwoStates_SingleQubit(\n StatePrep_IsQubitA(alpha, _, _),\n Kata.IsQubitA(alpha, _),\n [$\"|B⟩ = -i sin({i}π/10)|0⟩ + cos({i}π/10)|1⟩\", $\"|A⟩ = cos({i}π/10)|0⟩ + i sin({i}π/10)|1⟩\"],\n false);\n if not isCorrect {\n Message(\"Incorrect.\");\n return false;\n }\n }\n Message(\"Correct!\");\n true\n }\n\n}\n"
|
|
3887
4121
|
},
|
|
3888
4122
|
{
|
|
3889
4123
|
"id": "single_qubit_measurements__a_b_basis_measurements__Verification.qs",
|
|
3890
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Math;\n\n // Measure state in {|A❭, |B❭} basis\n // |A⟩ = cos(alpha) * |0⟩ - i sin(alpha) * |1⟩,\n // |B⟩ = - i sin(alpha) * |0⟩ + cos(alpha) * |1⟩.\n operation StatePrep_IsQubitA (alpha : Double, q : Qubit, state : Int) : Unit is Adj {\n if state == 0 {\n // convert |0⟩ to |B⟩\n X(q);\n Rx(2.0 * alpha, q);\n } else {\n // convert |0⟩ to |A⟩\n Rx(2.0 * alpha, q);\n }\n }\n\n // We can use the StatePrep_IsQubitA operation for the testing\n operation CheckSolution() : Bool {\n for i in 0 .. 10 {\n let alpha = (PI() * IntAsDouble(i)) / 10.0;\n let isCorrect =
|
|
4124
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Katas;\n\n // Measure state in {|A❭, |B❭} basis\n // |A⟩ = cos(alpha) * |0⟩ - i sin(alpha) * |1⟩,\n // |B⟩ = - i sin(alpha) * |0⟩ + cos(alpha) * |1⟩.\n operation StatePrep_IsQubitA (alpha : Double, q : Qubit, state : Int) : Unit is Adj {\n if state == 0 {\n // convert |0⟩ to |B⟩\n X(q);\n Rx(2.0 * alpha, q);\n } else {\n // convert |0⟩ to |A⟩\n Rx(2.0 * alpha, q);\n }\n }\n\n // We can use the StatePrep_IsQubitA operation for the testing\n operation CheckSolution() : Bool {\n for i in 0 .. 10 {\n let alpha = (PI() * IntAsDouble(i)) / 10.0;\n let isCorrect = DistinguishTwoStates_SingleQubit(\n StatePrep_IsQubitA(alpha, _, _),\n q => Kata.MeasureInABBasis(alpha, q) == Zero,\n [$\"|B⟩=(-i sin({i}π/10)|0⟩ + cos({i}π/10)|1⟩)\", $\"|A⟩=(cos({i}π/10)|0⟩ + i sin({i}π/10)|1⟩)\"],\n true);\n if not isCorrect {\n Message($\"Test fails for alpha={alpha}\");\n return false;\n }\n }\n Message(\"Correct!\");\n true\n }\n\n}\n"
|
|
3891
4125
|
},
|
|
3892
4126
|
{
|
|
3893
4127
|
"id": "multi_qubit_measurements__full_measurements__Verification.qs",
|
|
3894
|
-
"code": "namespace Kata.Verification {\n\n // Distinguish four basis states\n operation StatePrep_BasisStateMeasurement(qs : Qubit[], state : Int, dummyVar : Double) : Unit is Adj {\n if state / 2 == 1 {\n // |10⟩ or |11⟩\n X(qs[0]);\n }\n if state % 2 == 1 {\n // |01⟩ or |11⟩\n X(qs[1]);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let isCorrect = DistinguishStates_MultiQubit(\n 2,\n 4,\n StatePrep_BasisStateMeasurement,\n Kata.BasisStateMeasurement,\n false,\n [\"|00⟩\", \"|01⟩\", \"|10⟩\", \"|11⟩\"]);\n\n if (isCorrect) {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n }\n\n isCorrect\n }\n}\n"
|
|
3895
|
-
},
|
|
3896
|
-
{
|
|
3897
|
-
"id": "multi_qubit_measurements__Common.qs",
|
|
3898
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Canon;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Measurement;\n open Microsoft.Quantum.Random;\n\n // \"Framework\" operation for testing multi-qubit tasks for distinguishing states of an array of qubits\n // with Int return\n operation DistinguishStates_MultiQubit(\n nQubits : Int,\n nStates : Int,\n statePrep : ((Qubit[], Int, Double) => Unit is Adj),\n testImpl : (Qubit[] => Int),\n preserveState : Bool,\n stateNames : String[]) : Bool {\n\n let nTotal = 100;\n // misclassifications will store the number of times state i has been classified as state j (dimension nStates^2)\n mutable misclassifications = [0, size = nStates * nStates];\n // unknownClassifications will store the number of times state i has been classified as some invalid state (index < 0 or >= nStates)\n mutable unknownClassifications = [0, size = nStates];\n\n use qs = Qubit[nQubits];\n for i in 1 .. nTotal {\n // get a random integer to define the state of the qubits\n let state = DrawRandomInt(0, nStates - 1);\n // get a random rotation angle to define the exact state of the qubits\n // for some exercises, this value might be a dummy variable which does not matter\n let alpha = DrawRandomDouble(0.0, 1.0) * PI();\n\n // do state prep: convert |0...0⟩ to outcome with return equal to state\n statePrep(qs, state, alpha);\n\n // get the solution's answer and verify that it's a match, if not, increase the exact mismatch count\n let ans = testImpl(qs);\n if ((ans >= 0) and (ans < nStates)) {\n // classification result is a valid state index - check if is it correct\n if ans != state {\n set misclassifications w/= ((state * nStates) + ans) <- (misclassifications[(state * nStates) + ans] + 1);\n }\n }\n else {\n // classification result is an invalid state index - file it separately\n set unknownClassifications w/= state <- (unknownClassifications[state] + 1);\n }\n\n if preserveState {\n // check that the state of the qubit after the operation is unchanged\n Adjoint statePrep(qs, state, alpha);\n if not CheckAllZero(qs) {\n Message($\"Input quantum state {stateNames[state]} was not preserved during the measurement.\");\n ResetAll(qs);\n return false;\n }\n } else {\n // we're not checking the state of the qubit after the operation\n ResetAll(qs);\n }\n }\n ResetAll(qs);\n\n mutable totalMisclassifications = 0;\n for i in 0 .. nStates - 1 {\n for j in 0 .. nStates - 1 {\n if misclassifications[(i * nStates) + j] != 0 {\n set totalMisclassifications += misclassifications[i * nStates + j];\n Message($\"Misclassified {stateNames[i]} as {stateNames[j]} in {misclassifications[(i * nStates) + j]} test runs.\");\n }\n }\n if unknownClassifications[i] != 0 {\n set totalMisclassifications += unknownClassifications[i];\n Message($\"Misclassified {stateNames[i]} as Unknown State in {unknownClassifications[i]} test runs.\");\n }\n }\n totalMisclassifications == 0\n }\n}\n"
|
|
4128
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n // Distinguish four basis states\n operation StatePrep_BasisStateMeasurement(qs : Qubit[], state : Int, dummyVar : Double) : Unit is Adj {\n if state / 2 == 1 {\n // |10⟩ or |11⟩\n X(qs[0]);\n }\n if state % 2 == 1 {\n // |01⟩ or |11⟩\n X(qs[1]);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let isCorrect = DistinguishStates_MultiQubit(\n 2,\n 4,\n StatePrep_BasisStateMeasurement,\n Kata.BasisStateMeasurement,\n false,\n [\"|00⟩\", \"|01⟩\", \"|10⟩\", \"|11⟩\"]);\n\n if (isCorrect) {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n }\n\n isCorrect\n }\n}\n"
|
|
3899
4129
|
},
|
|
3900
4130
|
{
|
|
3901
4131
|
"id": "multi_qubit_measurements__partial_measurements_for_system__Verification.qs",
|
|
3902
|
-
"code": "namespace Kata.Verification {\n\n // Distinguish orthogonal states using partial measurements\n operation StatePrep_IsPlusPlusMinus(qs : Qubit[], state : Int, dummyVar : Double) : Unit is Adj {\n if state == 0 {\n // Prepare the state |++-⟩\n X(qs[2]);\n } else {\n // Prepare the state |---⟩\n ApplyToEachA(X, qs);\n }\n ApplyToEachA(H, qs);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let isCorrect = DistinguishStates_MultiQubit(\n 3,\n 2,\n StatePrep_IsPlusPlusMinus,\n Kata.IsPlusPlusMinus,\n true,\n [\"|++-⟩\", \"|---⟩\"]);\n if (isCorrect) {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n }\n\n isCorrect \n }\n}\n"
|
|
4132
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n // Distinguish orthogonal states using partial measurements\n operation StatePrep_IsPlusPlusMinus(qs : Qubit[], state : Int, dummyVar : Double) : Unit is Adj {\n if state == 0 {\n // Prepare the state |++-⟩\n X(qs[2]);\n } else {\n // Prepare the state |---⟩\n ApplyToEachA(X, qs);\n }\n ApplyToEachA(H, qs);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let isCorrect = DistinguishStates_MultiQubit(\n 3,\n 2,\n StatePrep_IsPlusPlusMinus,\n Kata.IsPlusPlusMinus,\n true,\n [\"|++-⟩\", \"|---⟩\"]);\n if (isCorrect) {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n }\n\n isCorrect \n }\n}\n"
|
|
3903
4133
|
},
|
|
3904
4134
|
{
|
|
3905
4135
|
"id": "multi_qubit_measurements__state_modification__Verification.qs",
|
|
@@ -3907,11 +4137,11 @@ export default {
|
|
|
3907
4137
|
},
|
|
3908
4138
|
{
|
|
3909
4139
|
"id": "multi_qubit_measurements__state_preparation__Verification.qs",
|
|
3910
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n //
|
|
4140
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n // Reference solution that does not use measurements (to be adjointable)\n operation StatePrep_Rotations(qs : Qubit[]) : Unit is Adj {\n // Rotate first qubit to (sqrt(2) |0⟩ + |1⟩) / sqrt(3)\n let theta = ArcSin(1.0 / Sqrt(3.0));\n Ry(2.0 * theta, qs[0]);\n\n // Split the state sqrt(2) |0⟩ ⊗ |0⟩ into |00⟩ + |01⟩\n ApplyControlledOnInt(0, H, [qs[0]], qs[1]);\n }\n\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n CheckOperationsEquivalenceOnZeroStateWithFeedback(Kata.PostSelection, StatePrep_Rotations, 2)\n }\n}\n"
|
|
3911
4141
|
},
|
|
3912
4142
|
{
|
|
3913
4143
|
"id": "multi_qubit_measurements__joint_measurements__Verification.qs",
|
|
3914
|
-
"code": "namespace Kata.Verification {\n\n // Two qubit parity Measurement\n operation StatePrep_ParityMeasurement(qs : Qubit[], state : Int, alpha : Double) : Unit is Adj {\n // prep cos(alpha) * |0..0⟩ + sin(alpha) * |1..1⟩\n Ry(2.0 * alpha, qs[0]);\n CNOT(qs[0], qs[1]);\n\n if state == 1 {\n // flip the state of the first qubit\n X(qs[0]);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let isCorrect = DistinguishStates_MultiQubit(\n 2,\n 2,\n StatePrep_ParityMeasurement,\n Kata.ParityMeasurement,\n true,\n [\"α|00⟩ + β|11⟩\", \"α|01⟩ + β|10⟩\"]);\n\n if (isCorrect) {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n }\n\n isCorrect\n }\n}\n"
|
|
4144
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n // Two qubit parity Measurement\n operation StatePrep_ParityMeasurement(qs : Qubit[], state : Int, alpha : Double) : Unit is Adj {\n // prep cos(alpha) * |0..0⟩ + sin(alpha) * |1..1⟩\n Ry(2.0 * alpha, qs[0]);\n CNOT(qs[0], qs[1]);\n\n if state == 1 {\n // flip the state of the first qubit\n X(qs[0]);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let isCorrect = DistinguishStates_MultiQubit(\n 2,\n 2,\n StatePrep_ParityMeasurement,\n Kata.ParityMeasurement,\n true,\n [\"α|00⟩ + β|11⟩\", \"α|01⟩ + β|10⟩\"]);\n\n if (isCorrect) {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n }\n\n isCorrect\n }\n}\n"
|
|
3915
4145
|
},
|
|
3916
4146
|
{
|
|
3917
4147
|
"id": "random_numbers__random_bit__Verification.qs",
|
|
@@ -3947,35 +4177,35 @@ export default {
|
|
|
3947
4177
|
},
|
|
3948
4178
|
{
|
|
3949
4179
|
"id": "oracles__phase_oracle_seven__Verification.qs",
|
|
3950
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation IsSeven_PhaseOracle_Reference(x : Qubit[]) : Unit is Adj + Ctl {\n Controlled Z(Most(x), Tail(x));\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let N = 3;\n let isCorrect = CheckOperationsEquivalenceStrict(\n Kata.IsSeven_PhaseOracle,\n IsSeven_PhaseOracle_Reference,\n 3);\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n \"transformation\");\n
|
|
4180
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation IsSeven_PhaseOracle_Reference(x : Qubit[]) : Unit is Adj + Ctl {\n Controlled Z(Most(x), Tail(x));\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let N = 3;\n let isCorrect = CheckOperationsEquivalenceStrict(\n Kata.IsSeven_PhaseOracle,\n IsSeven_PhaseOracle_Reference,\n 3);\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n \"transformation\");\n ShowQuantumStateComparison(3, PrepRandomState, Kata.IsSeven_PhaseOracle, IsSeven_PhaseOracle_Reference);\n }\n isCorrect\n }\n}\n"
|
|
3951
4181
|
},
|
|
3952
4182
|
{
|
|
3953
4183
|
"id": "oracles__marking_oracle_seven__Verification.qs",
|
|
3954
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation IsSeven_MarkingOracle_Reference(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n Controlled X(x, y);\n }\n\n // ------------------------------------------------------\n @EntryPoint()\n operation CheckSolution () : Bool {\n let N = 3;\n let sol = ApplyOracle(_, Kata.IsSeven_MarkingOracle);\n let ref = ApplyOracle(_, IsSeven_MarkingOracle_Reference);\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N + 1);\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n \"transformation\");\n
|
|
4184
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation IsSeven_MarkingOracle_Reference(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n Controlled X(x, y);\n }\n\n // ------------------------------------------------------\n @EntryPoint()\n operation CheckSolution () : Bool {\n let N = 3;\n let sol = ApplyOracle(_, Kata.IsSeven_MarkingOracle);\n let ref = ApplyOracle(_, IsSeven_MarkingOracle_Reference);\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N + 1);\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n \"transformation\");\n ShowQuantumStateComparison(4, qs => PrepRandomState(qs[...2]), sol, ref);\n }\n isCorrect\n }\n}\n"
|
|
3955
4185
|
},
|
|
3956
4186
|
{
|
|
3957
4187
|
"id": "oracles__marking_oracle_as_phase__Verification.qs",
|
|
3958
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Random;\n\n operation ApplyMarkingOracleAsPhaseOracle_Reference(\n markingOracle : ((Qubit[], Qubit) => Unit is Adj + Ctl),\n qubits : Qubit[]) : Unit is Adj + Ctl {\n\n use minus = Qubit();\n within {\n X(minus);\n H(minus);\n } apply {\n markingOracle(qubits, minus);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 1 .. 3 {\n for k in 0 .. 2^N - 1 {\n let pattern = IntAsBoolArray(k, N);\n let marking = ApplyControlledOnBitString(pattern, X, _, _);\n let sol = Kata.ApplyMarkingOracleAsPhaseOracle(marking, _);\n let ref = ApplyMarkingOracleAsPhaseOracle_Reference(marking, _);\n\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle that marks the bit string {pattern}\");\n
|
|
4188
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Random;\n\n operation ApplyMarkingOracleAsPhaseOracle_Reference(\n markingOracle : ((Qubit[], Qubit) => Unit is Adj + Ctl),\n qubits : Qubit[]) : Unit is Adj + Ctl {\n\n use minus = Qubit();\n within {\n X(minus);\n H(minus);\n } apply {\n markingOracle(qubits, minus);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 1 .. 3 {\n for k in 0 .. 2^N - 1 {\n let pattern = IntAsBoolArray(k, N);\n let marking = ApplyControlledOnBitString(pattern, X, _, _);\n let sol = Kata.ApplyMarkingOracleAsPhaseOracle(marking, _);\n let ref = ApplyMarkingOracleAsPhaseOracle_Reference(marking, _);\n\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle that marks the bit string {pattern}\");\n ShowQuantumStateComparison(N, PrepRandomState, sol, ref);\n return false;\n }\n }\n }\n Message(\"Correct!\");\n true\n }\n\n}\n"
|
|
3959
4189
|
},
|
|
3960
4190
|
{
|
|
3961
4191
|
"id": "oracles__or_oracle__Verification.qs",
|
|
3962
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Random;\n\n operation Or_Oracle_Reference(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n X(y);\n ApplyControlledOnInt(0, X, x, y);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 1 .. 3 {\n let sol = ApplyOracle(_, Kata.Or_Oracle);\n let ref = ApplyOracle(_, Or_Oracle_Reference);\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N + 1);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle\");\n
|
|
4192
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Random;\n\n operation Or_Oracle_Reference(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n X(y);\n ApplyControlledOnInt(0, X, x, y);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 1 .. 3 {\n let sol = ApplyOracle(_, Kata.Or_Oracle);\n let ref = ApplyOracle(_, Or_Oracle_Reference);\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N + 1);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle\");\n ShowQuantumStateComparison(N + 1, qs => PrepRandomState(qs[...N - 1]), sol, ref);\n return false;\n }\n }\n Message(\"Correct!\");\n true\n }\n}\n"
|
|
3963
4193
|
},
|
|
3964
4194
|
{
|
|
3965
4195
|
"id": "oracles__kth_bit_oracle__Verification.qs",
|
|
3966
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation KthBit_Oracle_Reference(x : Qubit[], k : Int) : Unit is Adj + Ctl {\n Z(x[k]);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 1 .. 3 {\n for k in 0 .. N - 1 {\n let sol = Kata.KthBit_Oracle(_, k);\n let ref = KthBit_Oracle_Reference(_, k);\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle for k = {k}\");\n
|
|
4196
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation KthBit_Oracle_Reference(x : Qubit[], k : Int) : Unit is Adj + Ctl {\n Z(x[k]);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 1 .. 3 {\n for k in 0 .. N - 1 {\n let sol = Kata.KthBit_Oracle(_, k);\n let ref = KthBit_Oracle_Reference(_, k);\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle for k = {k}\");\n ShowQuantumStateComparison(N, PrepRandomState, sol, ref);\n return false;\n }\n }\n }\n Message(\"Correct!\");\n true\n }\n}\n"
|
|
3967
4197
|
},
|
|
3968
4198
|
{
|
|
3969
4199
|
"id": "oracles__or_but_kth_oracle__Verification.qs",
|
|
3970
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation Or_Oracle_Reference(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n X(y);\n ApplyControlledOnInt(0, X, x, y);\n }\n\n operation OrOfBitsExceptKth_Oracle_Reference(x : Qubit[], k : Int) : Unit is Adj + Ctl {\n use minus = Qubit();\n within {\n X(minus);\n H(minus);\n } apply {\n Or_Oracle_Reference(x[...k-1] + x[k+1...], minus);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 2 .. 4 {\n for k in 0 .. N - 1 {\n let sol = Kata.OrOfBitsExceptKth_Oracle(_, k);\n let ref = OrOfBitsExceptKth_Oracle_Reference(_, k);\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle for k = {k}\");\n
|
|
4200
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation Or_Oracle_Reference(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n X(y);\n ApplyControlledOnInt(0, X, x, y);\n }\n\n operation OrOfBitsExceptKth_Oracle_Reference(x : Qubit[], k : Int) : Unit is Adj + Ctl {\n use minus = Qubit();\n within {\n X(minus);\n H(minus);\n } apply {\n Or_Oracle_Reference(x[...k-1] + x[k+1...], minus);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 2 .. 4 {\n for k in 0 .. N - 1 {\n let sol = Kata.OrOfBitsExceptKth_Oracle(_, k);\n let ref = OrOfBitsExceptKth_Oracle_Reference(_, k);\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle for k = {k}\");\n ShowQuantumStateComparison(N, PrepRandomState, sol, ref);\n return false;\n }\n }\n }\n Message(\"Correct!\");\n true\n }\n}\n"
|
|
3971
4201
|
},
|
|
3972
4202
|
{
|
|
3973
4203
|
"id": "oracles__bit_pattern_oracle__Verification.qs",
|
|
3974
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n\n operation ArbitraryBitPattern_Oracle_Reference(x : Qubit[], y : Qubit, pattern : Bool[]) : Unit is Adj + Ctl {\n ApplyControlledOnBitString(pattern, X, x, y);\n }\n\n // ------------------------------------------------------\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 1 .. 3 {\n for k in 0 .. 2^N - 1 {\n let pattern = IntAsBoolArray(k, N);\n\n let sol = ApplyOracle(_, Kata.ArbitraryBitPattern_Oracle(_, _, pattern));\n let ref = ApplyOracle(_, ArbitraryBitPattern_Oracle_Reference(_, _, pattern));\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N + 1);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle for the pattern {pattern}\");\n
|
|
4204
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n\n operation ArbitraryBitPattern_Oracle_Reference(x : Qubit[], y : Qubit, pattern : Bool[]) : Unit is Adj + Ctl {\n ApplyControlledOnBitString(pattern, X, x, y);\n }\n\n // ------------------------------------------------------\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 1 .. 3 {\n for k in 0 .. 2^N - 1 {\n let pattern = IntAsBoolArray(k, N);\n\n let sol = ApplyOracle(_, Kata.ArbitraryBitPattern_Oracle(_, _, pattern));\n let ref = ApplyOracle(_, ArbitraryBitPattern_Oracle_Reference(_, _, pattern));\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N + 1);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle for the pattern {pattern}\");\n ShowQuantumStateComparison(N + 1, qs => PrepRandomState(qs[...N - 1]), sol, ref);\n return false;\n }\n }\n }\n Message(\"Correct!\");\n true\n }\n\n}\n"
|
|
3975
4205
|
},
|
|
3976
4206
|
{
|
|
3977
4207
|
"id": "oracles__bit_pattern_challenge__Verification.qs",
|
|
3978
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n\n operation ArbitraryBitPattern_Oracle_Challenge_Reference(x : Qubit[], pattern : Bool[]) : Unit is Adj + Ctl {\n within {\n for i in IndexRange(x) {\n if not pattern[i] {\n X(x[i]);\n }\n }\n } apply {\n Controlled Z(Most(x), Tail(x));\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 1 .. 3 {\n for k in 0 .. 2^N -1 {\n let pattern = IntAsBoolArray(k, N);\n\n let sol = Kata.ArbitraryBitPattern_Oracle_Challenge(_, pattern);\n let ref = ArbitraryBitPattern_Oracle_Challenge_Reference(_, pattern);\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle for pattern = {pattern}\");\n
|
|
4208
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n\n operation ArbitraryBitPattern_Oracle_Challenge_Reference(x : Qubit[], pattern : Bool[]) : Unit is Adj + Ctl {\n within {\n for i in IndexRange(x) {\n if not pattern[i] {\n X(x[i]);\n }\n }\n } apply {\n Controlled Z(Most(x), Tail(x));\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 1 .. 3 {\n for k in 0 .. 2^N -1 {\n let pattern = IntAsBoolArray(k, N);\n\n let sol = Kata.ArbitraryBitPattern_Oracle_Challenge(_, pattern);\n let ref = ArbitraryBitPattern_Oracle_Challenge_Reference(_, pattern);\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle for pattern = {pattern}\");\n ShowQuantumStateComparison(N, PrepRandomState, sol, ref);\n return false;\n }\n }\n }\n Message(\"All tests passed.\");\n true\n }\n}\n"
|
|
3979
4209
|
},
|
|
3980
4210
|
{
|
|
3981
4211
|
"id": "oracles__meeting_oracle__Verification.qs",
|
|
@@ -3983,7 +4213,7 @@ export default {
|
|
|
3983
4213
|
},
|
|
3984
4214
|
{
|
|
3985
4215
|
"id": "deutsch_algo__one_minus_x_oracle__Verification.qs",
|
|
3986
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation PhaseOracle_OneMinusX_Reference(x : Qubit) : Unit is Adj + Ctl {\n Z(x);\n R(PauliI, 2.0 * PI(), x);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.PhaseOracle_OneMinusX(register[0]);\n let reference = register => PhaseOracle_OneMinusX_Reference(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have. Note that the simulator might drop the global phase -1, so if you're getting \" +\n \"verdict \\\"Incorrect\\\" but the actual state matches the expected one, check that you're handling the global phase correctly.\");\n
|
|
4216
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation PhaseOracle_OneMinusX_Reference(x : Qubit) : Unit is Adj + Ctl {\n Z(x);\n R(PauliI, 2.0 * PI(), x);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.PhaseOracle_OneMinusX(register[0]);\n let reference = register => PhaseOracle_OneMinusX_Reference(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have. Note that the simulator might drop the global phase -1, so if you're getting \" +\n \"verdict \\\"Incorrect\\\" but the actual state matches the expected one, check that you're handling the global phase correctly.\");\n ShowQuantumStateComparison(1, (qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0])), solution, reference);\n }\n isCorrect\n }\n}\n"
|
|
3987
4217
|
},
|
|
3988
4218
|
{
|
|
3989
4219
|
"id": "deutsch_algo__implement_algo__Verification.qs",
|
|
@@ -3991,11 +4221,11 @@ export default {
|
|
|
3991
4221
|
},
|
|
3992
4222
|
{
|
|
3993
4223
|
"id": "deutsch_jozsa__msb_oracle__Verification.qs",
|
|
3994
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation PhaseOracle_MostSignificantBit_Reference(x : Qubit[]) : Unit is Adj + Ctl {\n Z(x[0]);\n }\n\n operation CheckSolution() : Bool {\n let solution = Kata.PhaseOracle_MostSignificantBit;\n let reference = PhaseOracle_MostSignificantBit_Reference;\n for N in 1 .. 4 {\n if not CheckOperationsEquivalenceStrict(solution, reference, N) {\n Message(\"Incorrect.\");\n Message($\"Hint: examine the effect your solution has on the {N}-qubit and compare it with the effect it \" +\n \"is expected to have. Note that the simulator might drop the global phase -1, so if you're getting \" +\n \"verdict \\\"Incorrect\\\" but the actual state matches the expected one, check that you're handling the global phase correctly.\");\n
|
|
4224
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation PhaseOracle_MostSignificantBit_Reference(x : Qubit[]) : Unit is Adj + Ctl {\n Z(x[0]);\n }\n\n operation CheckSolution() : Bool {\n let solution = Kata.PhaseOracle_MostSignificantBit;\n let reference = PhaseOracle_MostSignificantBit_Reference;\n for N in 1 .. 4 {\n if not CheckOperationsEquivalenceStrict(solution, reference, N) {\n Message(\"Incorrect.\");\n Message($\"Hint: examine the effect your solution has on the {N}-qubit and compare it with the effect it \" +\n \"is expected to have. Note that the simulator might drop the global phase -1, so if you're getting \" +\n \"verdict \\\"Incorrect\\\" but the actual state matches the expected one, check that you're handling the global phase correctly.\");\n ShowQuantumStateComparison(N, PrepRandomState, solution, reference);\n return false;\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
|
|
3995
4225
|
},
|
|
3996
4226
|
{
|
|
3997
4227
|
"id": "deutsch_jozsa__parity_oracle__Verification.qs",
|
|
3998
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation PhaseOracle_Parity_Reference(x : Qubit[]) : Unit is Adj + Ctl {\n for xi in x {\n Z(xi);\n }\n }\n\n operation CheckSolution() : Bool {\n let solution = Kata.PhaseOracle_Parity;\n let reference = PhaseOracle_Parity_Reference;\n for N in 1 .. 4 {\n if not CheckOperationsEquivalenceStrict(solution, reference, N) {\n Message(\"Incorrect.\");\n Message($\"Hint: examine the effect your solution has on the {N}-qubit and compare it with the effect it \" +\n \"is expected to have. Note that the simulator might drop the global phase -1, so if you're getting \" +\n \"verdict \\\"Incorrect\\\" but the actual state matches the expected one, check that you're handling the global phase correctly.\");\n
|
|
4228
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation PhaseOracle_Parity_Reference(x : Qubit[]) : Unit is Adj + Ctl {\n for xi in x {\n Z(xi);\n }\n }\n\n operation CheckSolution() : Bool {\n let solution = Kata.PhaseOracle_Parity;\n let reference = PhaseOracle_Parity_Reference;\n for N in 1 .. 4 {\n if not CheckOperationsEquivalenceStrict(solution, reference, N) {\n Message(\"Incorrect.\");\n Message($\"Hint: examine the effect your solution has on the {N}-qubit and compare it with the effect it \" +\n \"is expected to have. Note that the simulator might drop the global phase -1, so if you're getting \" +\n \"verdict \\\"Incorrect\\\" but the actual state matches the expected one, check that you're handling the global phase correctly.\");\n ShowQuantumStateComparison(N, PrepRandomState, solution, reference);\n return false;\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
|
|
3999
4229
|
},
|
|
4000
4230
|
{
|
|
4001
4231
|
"id": "deutsch_jozsa__implement_dj__Verification.qs",
|