From 7bf6470e8b4fcd850eb06c8dd51f11dc1f8102bf Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Mon, 6 Jul 2020 09:58:44 -0700 Subject: [PATCH 01/31] add RUS sample --- .../algorithms/repeat-until-success/RUS.png | Bin 0 -> 15058 bytes .../RepeatUntilSuccess.csproj | 8 ++ .../RepeatUntilSuccess.qs | 110 ++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 samples/algorithms/repeat-until-success/RUS.png create mode 100644 samples/algorithms/repeat-until-success/RepeatUntilSuccess.csproj create mode 100644 samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs diff --git a/samples/algorithms/repeat-until-success/RUS.png b/samples/algorithms/repeat-until-success/RUS.png new file mode 100644 index 0000000000000000000000000000000000000000..bd37801a663dba8859df3ef529309981ce6c9180 GIT binary patch literal 15058 zcmV;@IxWSCP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>DI%i2lK~#8N?VSa5 zR7V%b|0@w9Bm_(F(Bf7!1q#KAwG?-XwOFxY6+F0Wu~I1gfC2@AmOu*>cPkEs5Htx1 z354ioci%U6_AS}nY_gJFlFOc2M!$A4~f7Kj~zI0U}L0W?ZANp zJKzv72M+9rL%qS6*aAi$a<&pLpfFg+ss` z*c4?*2vmE-+v!cFE1{yZ2Vb3u}oC;@q~VvrRn0vXk;Epc)ZuS!eGKmR~+@gkBB9YXTaqvF|A zJih)Ko@2*~t(=2V0Zab-Z@d~knvKyiNIX5EymLoRf1F5vXGZA&(CF+__b>hJ8`1eO2vEeV&rPyUTozIj0#v(vt~%S zaYJl5_^%>yc81i?kLyCxym@(%6)3<3$%%xCjZF4}7Eq{@CtXjMeEasnsd8npmHja) zU}0=Hhf*oF9OM*8Ao$)=u3Uh2pNVQ#c$*4cqivG_`S_$3rW;W$@%GjTRPNm3D`yQU z*RLb0d2_L)!Kqp`6lH~C2nqzQmuWA9n-ZIPr-8li9tblIc%8N(vauppW$jCc-a-B0v6ez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(tU#=eLQ~K>%B&$>^s8wpX<}D0AudM9NAkDGdjiI8nsNh&!2jSHoJ^a*Fcsx}1g(!l zn-PuQVoY}x?gg*L72ozK74j2y-p~*0tVM`@hzlpKn$VF%lwr7b;sQcn*=2>qK_+>3 zt?82=<6*QPiu)NKA=J^KcqA=`65iRZk9mz7`}g2-OhMFa+Zbg`MWsu=hr>Z<5T2(h zx;3vLo^+61aJZ{Da9~H?!6~8x2iXUQfH`nrM;rp?z=0ic2$%y0cEllI4jkAKhk!Y7 oU`HGR=D>j+aR`_L2X+JaKT6nW!xAfCd;kCd07*qoM6N<$f-fI{qyPW_ literal 0 HcmV?d00001 diff --git a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.csproj b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.csproj new file mode 100644 index 000000000000..69ae5b1ee102 --- /dev/null +++ b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + diff --git a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs new file mode 100644 index 000000000000..49ec239cd057 --- /dev/null +++ b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs @@ -0,0 +1,110 @@ +namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Canon; + open Microsoft.Quantum.Math; + open Microsoft.Quantum.Preparation; + + /// Example of a Repeat-until-success circuit + /// The circuit is executed on a "target" qubit using an "ancilla" and + /// "resource" qubit. + /// The goal is to measure Zero for both the ancilla and resource qubit. + /// If this succeeds, the circuit will have effectively applied an + /// Rz(arctan(2)) gate (also known as V_3 gate) on the target qubit. + /// If this fails, rerun the circuit up to times. + @EntryPoint() + operation ApplyRzArcTan2( + inputValue : Bool, + inputBasis: Pauli, + limit: Int + ) : (Bool, Result, Int) { + using ((ancilla, resource, target) = (Qubit(), Qubit(), Qubit())) { + // Prepare qubits + PrepareXZero(ancilla); + PrepareXZero(resource); + PrepareValueForBasis(inputValue, inputBasis, target); + + // Initialize results to One by default. + mutable result1 = One; + mutable result2 = One; + mutable done = false; + mutable numIter = 0; + + repeat { + PrepareXZero(ancilla); + // Run Part 1 of the circuit. + set result1 = ApplyAndMeasurePart1(ancilla, resource); + // We'll only run Part 2 if Part 1 returns Zero. + // Otherwise, we'll skip and rerun Part 1 again. + if (result1 == Zero) { //|0X> + set result2 = ApplyAndMeasurePart2(resource, target); + if (result2 == One) { //|01> + H(ancilla); // Reset ancilla from |0> to |+> + PrepareXZero(resource); // Reset resource from |1> to |+> + Z(target); // Correct rotation on target + } + } else { // |1X>, skip Part 2 + // Reset ancilla from |1> to |+> + PrepareXZero(ancilla); + } + set done = (result2 == Zero or numIter >= limit); //|00> + set numIter = numIter + 1; + } + until (done) + fixup {} + + let success = (result1 == Zero and result2 == Zero); + + // Rz(2.0*ArcTan(2.0), target); + let result = Measure([inputBasis], [target]); + + Reset(target); + Reset(resource); + Reset(ancilla); + + return ( success, result, numIter ); + } + } + + // Prepare qubit in either |0> or |1> for the given basis + operation PrepareValueForBasis( + inputValue : Bool, + inputBasis : Pauli, + input: Qubit) : Unit { + if (inputValue) { + X(input); + } + PrepareQubit(inputBasis, input); + } + + // Prepare qubit in |+> state given it is in the |1> state + operation PrepareXZero(target : Qubit) : Unit { + X(target); // Flip to |0> + H(target); // Prepare |+> + } + + // Part 1 of RUS circuit + operation ApplyAndMeasurePart1( + ancilla: Qubit, + resource: Qubit + ) : Result { + within { + Adjoint T(ancilla); + } apply { + CNOT(resource, ancilla); + } + + return Measure([PauliX], [ancilla]); + } + + // Part 2 of RUS circuit + operation ApplyAndMeasurePart2( + resource: Qubit, + target: Qubit + ) : Result { + CNOT(target, resource); + T(resource); + T(target); + + return Measure([PauliX], [resource]); + } +} From 7eda2bf40a3ea8db9bbe42f4200841c722de3a8e Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Mon, 6 Jul 2020 10:20:01 -0700 Subject: [PATCH 02/31] add whitepaper reference --- .../repeat-until-success/RepeatUntilSuccess.qs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs index 49ec239cd057..e88140ec2be5 100644 --- a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs +++ b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs @@ -4,9 +4,16 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { open Microsoft.Quantum.Math; open Microsoft.Quantum.Preparation; - /// Example of a Repeat-until-success circuit + /// Example of a Repeat-until-success circuit implementing exp(i⋅ArcTan(2)⋅Z) + /// by Paetznick & Svore. Gate exp(i⋅ArcTan(2)⋅Z) is also know as V gate. + /// # References + /// - [ *Adam Paetznick, Krysta M. Svore*, + /// Quantum Information & Computation 14(15 & 16): 1277-1301 (2014) + /// ](https://arxiv.org/abs/1311.1074) + /// For circuit, see file RUS.png (to be added to README). + /// /// The circuit is executed on a "target" qubit using an "ancilla" and - /// "resource" qubit. + /// "resource" qubit. The circuit consists of two parts (red and blue in image). /// The goal is to measure Zero for both the ancilla and resource qubit. /// If this succeeds, the circuit will have effectively applied an /// Rz(arctan(2)) gate (also known as V_3 gate) on the target qubit. From 7e60588e4594f3dd9aed2d0a18724df2a3c329d0 Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Mon, 6 Jul 2020 10:30:27 -0700 Subject: [PATCH 03/31] Z rotation correction should be adjoint Z --- .../algorithms/repeat-until-success/RepeatUntilSuccess.qs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs index e88140ec2be5..ef16180307ff 100644 --- a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs +++ b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs @@ -47,7 +47,7 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { if (result2 == One) { //|01> H(ancilla); // Reset ancilla from |0> to |+> PrepareXZero(resource); // Reset resource from |1> to |+> - Z(target); // Correct rotation on target + Adjoint Z(target); // Correct effective Z rotation on target } } else { // |1X>, skip Part 2 // Reset ancilla from |1> to |+> @@ -89,7 +89,7 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { H(target); // Prepare |+> } - // Part 1 of RUS circuit + // Part 1 of RUS circuit (red) operation ApplyAndMeasurePart1( ancilla: Qubit, resource: Qubit @@ -103,7 +103,7 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { return Measure([PauliX], [ancilla]); } - // Part 2 of RUS circuit + // Part 2 of RUS circuit (blue) operation ApplyAndMeasurePart2( resource: Qubit, target: Qubit From d028bef98040dd805e00190d42dc0451965204b5 Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Mon, 6 Jul 2020 11:14:42 -0700 Subject: [PATCH 04/31] rename ancilla to auxiliary, make done and success mutable instead of results, add copyright, add third slash to comments --- .../RepeatUntilSuccess.qs | 61 ++++++++++--------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs index ef16180307ff..f47d22df2a48 100644 --- a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs +++ b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs @@ -1,9 +1,13 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Canon; open Microsoft.Quantum.Math; open Microsoft.Quantum.Preparation; + /// # Summary /// Example of a Repeat-until-success circuit implementing exp(i⋅ArcTan(2)⋅Z) /// by Paetznick & Svore. Gate exp(i⋅ArcTan(2)⋅Z) is also know as V gate. /// # References @@ -12,9 +16,9 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { /// ](https://arxiv.org/abs/1311.1074) /// For circuit, see file RUS.png (to be added to README). /// - /// The circuit is executed on a "target" qubit using an "ancilla" and + /// The circuit is executed on a "target" qubit using an "auxiliary" and /// "resource" qubit. The circuit consists of two parts (red and blue in image). - /// The goal is to measure Zero for both the ancilla and resource qubit. + /// The goal is to measure Zero for both the auxiliary and resource qubit. /// If this succeeds, the circuit will have effectively applied an /// Rz(arctan(2)) gate (also known as V_3 gate) on the target qubit. /// If this fails, rerun the circuit up to times. @@ -24,86 +28,87 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { inputBasis: Pauli, limit: Int ) : (Bool, Result, Int) { - using ((ancilla, resource, target) = (Qubit(), Qubit(), Qubit())) { - // Prepare qubits - PrepareXZero(ancilla); + using ((auxiliary, resource, target) = (Qubit(), Qubit(), Qubit())) { + /// Prepare auxiliary and resource qubits in |+> state + PrepareXZero(auxiliary); PrepareXZero(resource); + /// Prepare target qubit in |0> or |1> state, depending on input value PrepareValueForBasis(inputValue, inputBasis, target); - // Initialize results to One by default. - mutable result1 = One; - mutable result2 = One; + /// Initialize results to One by default. mutable done = false; + mutable success = false; mutable numIter = 0; repeat { - PrepareXZero(ancilla); + PrepareXZero(auxiliary); // Run Part 1 of the circuit. - set result1 = ApplyAndMeasurePart1(ancilla, resource); + let result1 = ApplyAndMeasurePart1(auxiliary, resource); // We'll only run Part 2 if Part 1 returns Zero. // Otherwise, we'll skip and rerun Part 1 again. if (result1 == Zero) { //|0X> - set result2 = ApplyAndMeasurePart2(resource, target); - if (result2 == One) { //|01> - H(ancilla); // Reset ancilla from |0> to |+> + let result2 = ApplyAndMeasurePart2(resource, target); + if (result2 == Zero) { //|00> + set success = true; + } else { //|01> + H(auxiliary); // Reset auxiliary from |0> to |+> PrepareXZero(resource); // Reset resource from |1> to |+> Adjoint Z(target); // Correct effective Z rotation on target } } else { // |1X>, skip Part 2 - // Reset ancilla from |1> to |+> - PrepareXZero(ancilla); + // Reset auxiliary from |1> to |+> + PrepareXZero(auxiliary); } - set done = (result2 == Zero or numIter >= limit); //|00> + set done = (success or numIter >= limit); set numIter = numIter + 1; } until (done) fixup {} - let success = (result1 == Zero and result2 == Zero); - // Rz(2.0*ArcTan(2.0), target); let result = Measure([inputBasis], [target]); Reset(target); Reset(resource); - Reset(ancilla); + Reset(auxiliary); return ( success, result, numIter ); } } - // Prepare qubit in either |0> or |1> for the given basis + /// Prepare qubit in either |0> or |1> for the given basis operation PrepareValueForBasis( inputValue : Bool, inputBasis : Pauli, - input: Qubit) : Unit { + input: Qubit + ) : Unit { if (inputValue) { X(input); } PrepareQubit(inputBasis, input); } - // Prepare qubit in |+> state given it is in the |1> state + /// Prepare qubit in |+> state given it is in the |1> state operation PrepareXZero(target : Qubit) : Unit { X(target); // Flip to |0> H(target); // Prepare |+> } - // Part 1 of RUS circuit (red) + /// Part 1 of RUS circuit (red) operation ApplyAndMeasurePart1( - ancilla: Qubit, + auxiliary: Qubit, resource: Qubit ) : Result { within { - Adjoint T(ancilla); + Adjoint T(auxiliary); } apply { - CNOT(resource, ancilla); + CNOT(resource, auxiliary); } - return Measure([PauliX], [ancilla]); + return Measure([PauliX], [auxiliary]); } - // Part 2 of RUS circuit (blue) + /// Part 2 of RUS circuit (blue) operation ApplyAndMeasurePart2( resource: Qubit, target: Qubit From f98f92d17dd6a9d273e9e0b18d8998eb02975771 Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Mon, 6 Jul 2020 11:18:10 -0700 Subject: [PATCH 05/31] rephrase circuit vs program --- .../repeat-until-success/RepeatUntilSuccess.qs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs index f47d22df2a48..99fd732b0bed 100644 --- a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs +++ b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs @@ -8,20 +8,21 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { open Microsoft.Quantum.Preparation; /// # Summary - /// Example of a Repeat-until-success circuit implementing exp(i⋅ArcTan(2)⋅Z) - /// by Paetznick & Svore. Gate exp(i⋅ArcTan(2)⋅Z) is also know as V gate. + /// Example of a Repeat-until-success program implementing a circuit that achieves + /// exp(i⋅ArcTan(2)⋅Z) by Paetznick & Svore. Gate exp(i⋅ArcTan(2)⋅Z) is also know as + /// V gate. /// # References /// - [ *Adam Paetznick, Krysta M. Svore*, /// Quantum Information & Computation 14(15 & 16): 1277-1301 (2014) /// ](https://arxiv.org/abs/1311.1074) - /// For circuit, see file RUS.png (to be added to README). + /// For circuit diagram, see file RUS.png (to be added to README). /// - /// The circuit is executed on a "target" qubit using an "auxiliary" and + /// The program executes a circuit on a "target" qubit using an "auxiliary" and /// "resource" qubit. The circuit consists of two parts (red and blue in image). /// The goal is to measure Zero for both the auxiliary and resource qubit. - /// If this succeeds, the circuit will have effectively applied an + /// If this succeeds, the program will have effectively applied an /// Rz(arctan(2)) gate (also known as V_3 gate) on the target qubit. - /// If this fails, rerun the circuit up to times. + /// If this fails, the program reruns the circuit up to times. @EntryPoint() operation ApplyRzArcTan2( inputValue : Bool, @@ -42,7 +43,7 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { repeat { PrepareXZero(auxiliary); - // Run Part 1 of the circuit. + // Run Part 1 of the program. let result1 = ApplyAndMeasurePart1(auxiliary, resource); // We'll only run Part 2 if Part 1 returns Zero. // Otherwise, we'll skip and rerun Part 1 again. From 9a389b72b2ad9c45f10c133049afd8f9129243a9 Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Mon, 6 Jul 2020 11:22:40 -0700 Subject: [PATCH 06/31] rename PrepareXZero to SetXZeroFromOne --- .../repeat-until-success/RepeatUntilSuccess.qs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs index 99fd732b0bed..348a1cf1f400 100644 --- a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs +++ b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs @@ -31,8 +31,8 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { ) : (Bool, Result, Int) { using ((auxiliary, resource, target) = (Qubit(), Qubit(), Qubit())) { /// Prepare auxiliary and resource qubits in |+> state - PrepareXZero(auxiliary); - PrepareXZero(resource); + SetXZeroFromOne(auxiliary); + SetXZeroFromOne(resource); /// Prepare target qubit in |0> or |1> state, depending on input value PrepareValueForBasis(inputValue, inputBasis, target); @@ -42,7 +42,7 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { mutable numIter = 0; repeat { - PrepareXZero(auxiliary); + SetXZeroFromOne(auxiliary); // Run Part 1 of the program. let result1 = ApplyAndMeasurePart1(auxiliary, resource); // We'll only run Part 2 if Part 1 returns Zero. @@ -53,12 +53,12 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { set success = true; } else { //|01> H(auxiliary); // Reset auxiliary from |0> to |+> - PrepareXZero(resource); // Reset resource from |1> to |+> + SetXZeroFromOne(resource); // Reset resource from |1> to |+> Adjoint Z(target); // Correct effective Z rotation on target } } else { // |1X>, skip Part 2 // Reset auxiliary from |1> to |+> - PrepareXZero(auxiliary); + SetXZeroFromOne(auxiliary); } set done = (success or numIter >= limit); set numIter = numIter + 1; @@ -90,7 +90,7 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { } /// Prepare qubit in |+> state given it is in the |1> state - operation PrepareXZero(target : Qubit) : Unit { + operation SetXZeroFromOne(target : Qubit) : Unit { X(target); // Flip to |0> H(target); // Prepare |+> } From 4bc552421ac12f839911a351d651ff1c70bdd2a0 Mon Sep 17 00:00:00 2001 From: Guen P Date: Mon, 6 Jul 2020 11:23:30 -0700 Subject: [PATCH 07/31] Update samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs Co-authored-by: Chris Granade --- samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs index 348a1cf1f400..82a4cf1308dd 100644 --- a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs +++ b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs @@ -64,7 +64,6 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { set numIter = numIter + 1; } until (done) - fixup {} // Rz(2.0*ArcTan(2.0), target); let result = Measure([inputBasis], [target]); From 3984b05efc7eee84dc711687a34db20ce6d7294a Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Mon, 6 Jul 2020 11:23:59 -0700 Subject: [PATCH 08/31] add missing semicolon --- samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs index 82a4cf1308dd..8b8587f138ee 100644 --- a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs +++ b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs @@ -63,7 +63,7 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { set done = (success or numIter >= limit); set numIter = numIter + 1; } - until (done) + until (done); // Rz(2.0*ArcTan(2.0), target); let result = Measure([inputBasis], [target]); From d9ad26245becd4727ff4856e7006ef56e6853a4c Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Mon, 6 Jul 2020 11:39:20 -0700 Subject: [PATCH 09/31] update QDK to version 0.12.20070124 --- .../algorithms/repeat-until-success/RepeatUntilSuccess.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.csproj b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.csproj index 69ae5b1ee102..3172cb0ebd9e 100644 --- a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.csproj +++ b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.csproj @@ -1,4 +1,4 @@ - + Exe From a57cd0e9ad1ebf4685e1b6f75b9f74dc5f6b9cfa Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Mon, 6 Jul 2020 14:23:04 -0700 Subject: [PATCH 10/31] remove qubit reset (not needed in latest release) and unused Rz --- .../algorithms/repeat-until-success/RepeatUntilSuccess.qs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs index 8b8587f138ee..a384e1e031b8 100644 --- a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs +++ b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs @@ -65,13 +65,7 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { } until (done); - // Rz(2.0*ArcTan(2.0), target); let result = Measure([inputBasis], [target]); - - Reset(target); - Reset(resource); - Reset(auxiliary); - return ( success, result, numIter ); } } From 17ff7198bc938d1a0368d806fc65171dc8f54082 Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Tue, 7 Jul 2020 10:41:13 -0700 Subject: [PATCH 11/31] add README.m, update docstring --- .../algorithms/repeat-until-success/README.md | 42 +++++++++++++++++++ .../RepeatUntilSuccess.qs | 6 +-- 2 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 samples/algorithms/repeat-until-success/README.md diff --git a/samples/algorithms/repeat-until-success/README.md b/samples/algorithms/repeat-until-success/README.md new file mode 100644 index 000000000000..1dcb4945af51 --- /dev/null +++ b/samples/algorithms/repeat-until-success/README.md @@ -0,0 +1,42 @@ +# Repeat-until-success + +This is an example of a Repeat-Until-Success (RUS) algorithm implemented in a Q# program. +The algorithm has been described in [Adam Paetznick, Krysta M. Svore, Quantum Information & Computation 14(15 & 16): 1277-1301 (2014)](https://arxiv.org/abs/1311.1074). + +The idea for the RUS algorithm originates from the goal of decomposing a single-qubit unitary operation into a sequence of gates from a given universal basis set. In general, the goal of a RUS algorithm is to reduce the number of Clifford gates needed to execute said unitary operation by using one or more auxiliary qubits that are measured during the execution of the algorithm to indicate whether the desired output state has been achieved. This specific RUS algorithm consists of a circuit that uses two auxiliary qubits, which we label `auxiliary` and `resource`, and one `target` qubit. + +In this example, the RUS algorithm aims to apply exp(i⋅ArcTan(2)⋅Z) or a $V_3$-gate on the `target` qubit. The algorithm is based on the logic mapped out in the below circuit diagram (Fig. 1(c) from [source](https://arxiv.org/abs/1311.1074)). The qubits on the left hand side are labeled from top to bottom: `auxiliary`, `resource` and `target`. As described in the whitepaper, the desired operation will have been achieved when the measurements on both `auxiliary` and `resource` qubits returns `Zero`. When that happens we can exit the program and return the result. In all other cases, we would have to re-run the circuit. Important to note is that if the auxiliary qubit returns `Zero` but the `resource` qubit returns `One`, the resulting operation will have been an effective `Z` rotation which we will then need to correct for. + +![RUS circuit diagram](RUS.png) + +Since both the `auxiliary` and `resource` qubits need to return `Zero`, we can split this circuit into two parts, in the diagram circled in red and blue. If we execute the first part and it returns `One`, we can skip running the second part and start over. Since the first part doesn't perform any operations on the `target` qubit, we don't have to make any corrections on the `target` qubit and just reinitialize the `auxiliary` and `resource` qubit. + +If we measure `Zero` on the `auxiliary` qubit, we run the second part and measure the `resource` qubit. If the measurement returns `Zero`, we measure the `target` qubit and exit the program successfully. If the measurement returns `One`, we need to apply an `Adjoint Z` operation on the `target` qubit as mentioned above. + +The program returns a tuple with three values: whether the program ran successfully, the measurement result on the `target` qubit and the number of iterations that was run to obtain the result. + +## Running the Sample + +Browse to the `samples\algorithms\repeat-until-success` folder and run `dotnet build` to build the project. Then run `dotnet run [options] --no-build`. Optionally, omit the `--no-build` option to automatically build the project before execution. + +Options are: +``` + --input-value (REQUIRED) The input value to use. + --input-basis (REQUIRED) The input basis to use. + --limit (REQUIRED) The repetition limit. + -s, --simulator The name of the simulator to use. +``` + +## Manifest + +- **OrderFinding/** + - [RepeatUntilSuccess.csproj](./RepeatUntilSuccess.csproj): Main C# project for the example. + - [Program.cs](./Program.cs): C# code to call the operations defined in Q# and perform classical post-processing. + - [RepeatUntilSuccess.qs](./RepeatUntilSuccess.qs): The Q# implementation of the RUS algorithm. + +## Example run ## + +``` +> dotnet run --no-build --input-value true --input-basis PauliZ --limit 10 +(True, One, 3) +``` diff --git a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs index a384e1e031b8..bad73a74a5d4 100644 --- a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs +++ b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs @@ -8,9 +8,9 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { open Microsoft.Quantum.Preparation; /// # Summary - /// Example of a Repeat-until-success program implementing a circuit that achieves - /// exp(i⋅ArcTan(2)⋅Z) by Paetznick & Svore. Gate exp(i⋅ArcTan(2)⋅Z) is also know as - /// V gate. + /// Example of a Repeat-until-success algorithm implementing a circuit + /// that achieves exp(i⋅ArcTan(2)⋅Z) by Paetznick & Svore. + /// Gate exp(i⋅ArcTan(2)⋅Z) is also know as V gate. /// # References /// - [ *Adam Paetznick, Krysta M. Svore*, /// Quantum Information & Computation 14(15 & 16): 1277-1301 (2014) From fa3cf021c72a230d07efa1b12334d97f6e97e09e Mon Sep 17 00:00:00 2001 From: Guen P Date: Tue, 7 Jul 2020 14:11:38 -0700 Subject: [PATCH 12/31] Apply suggestions from code review Co-authored-by: Mathias Soeken --- .../algorithms/repeat-until-success/RepeatUntilSuccess.qs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs index bad73a74a5d4..9b7aa0c0a644 100644 --- a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs +++ b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs @@ -30,7 +30,7 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { limit: Int ) : (Bool, Result, Int) { using ((auxiliary, resource, target) = (Qubit(), Qubit(), Qubit())) { - /// Prepare auxiliary and resource qubits in |+> state + // Prepare auxiliary and resource qubits in |+〉state SetXZeroFromOne(auxiliary); SetXZeroFromOne(resource); /// Prepare target qubit in |0> or |1> state, depending on input value @@ -66,7 +66,7 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { until (done); let result = Measure([inputBasis], [target]); - return ( success, result, numIter ); + return (success, result, numIter); } } @@ -84,7 +84,8 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { /// Prepare qubit in |+> state given it is in the |1> state operation SetXZeroFromOne(target : Qubit) : Unit { - X(target); // Flip to |0> + AssertQubit(One, target); + X(target); // Flip to |0〉 H(target); // Prepare |+> } From b660692e4ae4b8e98d56124d82e14e10ecf9fad8 Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Tue, 7 Jul 2020 17:14:49 -0700 Subject: [PATCH 13/31] import AssertQubit from Diagnostics --- samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs index 9b7aa0c0a644..a5a09771d030 100644 --- a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs +++ b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs @@ -6,6 +6,7 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { open Microsoft.Quantum.Canon; open Microsoft.Quantum.Math; open Microsoft.Quantum.Preparation; + open Microsoft.Quantum.Diagnostics; /// # Summary /// Example of a Repeat-until-success algorithm implementing a circuit From 9747f0ba1c0e3872b9c188f6f44e091f9aa8c859 Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Tue, 7 Jul 2020 17:33:40 -0700 Subject: [PATCH 14/31] fix typo in readme (wrong folder name) --- samples/algorithms/repeat-until-success/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/algorithms/repeat-until-success/README.md b/samples/algorithms/repeat-until-success/README.md index 1dcb4945af51..7c81ef340166 100644 --- a/samples/algorithms/repeat-until-success/README.md +++ b/samples/algorithms/repeat-until-success/README.md @@ -29,7 +29,7 @@ Options are: ## Manifest -- **OrderFinding/** +- **repeat-until-success/** - [RepeatUntilSuccess.csproj](./RepeatUntilSuccess.csproj): Main C# project for the example. - [Program.cs](./Program.cs): C# code to call the operations defined in Q# and perform classical post-processing. - [RepeatUntilSuccess.qs](./RepeatUntilSuccess.qs): The Q# implementation of the RUS algorithm. From 0ab0e062efce24c0f68bda4f2761a855e0efd87d Mon Sep 17 00:00:00 2001 From: Guen P Date: Wed, 8 Jul 2020 07:33:56 -0700 Subject: [PATCH 15/31] Update samples/algorithms/repeat-until-success/README.md Co-authored-by: Mathias Soeken --- samples/algorithms/repeat-until-success/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/algorithms/repeat-until-success/README.md b/samples/algorithms/repeat-until-success/README.md index 7c81ef340166..101a0a83f555 100644 --- a/samples/algorithms/repeat-until-success/README.md +++ b/samples/algorithms/repeat-until-success/README.md @@ -34,7 +34,7 @@ Options are: - [Program.cs](./Program.cs): C# code to call the operations defined in Q# and perform classical post-processing. - [RepeatUntilSuccess.qs](./RepeatUntilSuccess.qs): The Q# implementation of the RUS algorithm. -## Example run ## +## Example run ``` > dotnet run --no-build --input-value true --input-basis PauliZ --limit 10 From c02e197f78f6248ca7896864439712b944d186ff Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Wed, 8 Jul 2020 08:07:39 -0700 Subject: [PATCH 16/31] convert ket bracket to unicode, remove superfluous comment dashes --- .../RepeatUntilSuccess.qs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs index a5a09771d030..03bcb1120fd6 100644 --- a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs +++ b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs @@ -34,10 +34,10 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { // Prepare auxiliary and resource qubits in |+〉state SetXZeroFromOne(auxiliary); SetXZeroFromOne(resource); - /// Prepare target qubit in |0> or |1> state, depending on input value + // Prepare target qubit in |0〉or |1〉state, depending on input value PrepareValueForBasis(inputValue, inputBasis, target); - /// Initialize results to One by default. + // Initialize results to One by default. mutable done = false; mutable success = false; mutable numIter = 0; @@ -48,17 +48,18 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { let result1 = ApplyAndMeasurePart1(auxiliary, resource); // We'll only run Part 2 if Part 1 returns Zero. // Otherwise, we'll skip and rerun Part 1 again. - if (result1 == Zero) { //|0X> + if (result1 == Zero) { //|0X〉 let result2 = ApplyAndMeasurePart2(resource, target); - if (result2 == Zero) { //|00> + if (result2 == Zero) { //|00〉 set success = true; - } else { //|01> - H(auxiliary); // Reset auxiliary from |0> to |+> - SetXZeroFromOne(resource); // Reset resource from |1> to |+> + } else { //|01〉 + H(auxiliary); // Reset auxiliary from |0〉to |+〉 + SetXZeroFromOne(resource); // Reset resource from |1〉to |+〉 Adjoint Z(target); // Correct effective Z rotation on target } - } else { // |1X>, skip Part 2 - // Reset auxiliary from |1> to |+> + } else { // |1X〉, skip Part 2 + // Reset auxiliary from |1〉to |+〉 + AssertQubit(One, auxiliary); SetXZeroFromOne(auxiliary); } set done = (success or numIter >= limit); @@ -71,7 +72,7 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { } } - /// Prepare qubit in either |0> or |1> for the given basis + /// Prepare qubit in either |0〉or |1〉for the given basis operation PrepareValueForBasis( inputValue : Bool, inputBasis : Pauli, @@ -83,9 +84,8 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { PrepareQubit(inputBasis, input); } - /// Prepare qubit in |+> state given it is in the |1> state + /// Prepare qubit in |+〉state given it is in the |1〉state operation SetXZeroFromOne(target : Qubit) : Unit { - AssertQubit(One, target); X(target); // Flip to |0〉 H(target); // Prepare |+> } From 21e4cb5603b9bd05e05612771cba43462dedf877 Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Thu, 9 Jul 2020 10:41:40 -0700 Subject: [PATCH 17/31] Assertions and fixes to make sure qubits are in the correct start state, update docstrings, add InitializeQubits operation to replace PrepareValueForBasis --- .../RepeatUntilSuccess.qs | 86 ++++++++++++------- 1 file changed, 55 insertions(+), 31 deletions(-) diff --git a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs index 03bcb1120fd6..e5bec46518ec 100644 --- a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs +++ b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs @@ -1,6 +1,5 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. - namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Canon; @@ -31,11 +30,8 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { limit: Int ) : (Bool, Result, Int) { using ((auxiliary, resource, target) = (Qubit(), Qubit(), Qubit())) { - // Prepare auxiliary and resource qubits in |+〉state - SetXZeroFromOne(auxiliary); - SetXZeroFromOne(resource); - // Prepare target qubit in |0〉or |1〉state, depending on input value - PrepareValueForBasis(inputValue, inputBasis, target); + // Initialize qubits to starting values (|+⟩, |+⟩, |0⟩/|1⟩) + InitializeQubits(auxiliary, resource, target, inputBasis, inputValue); // Initialize results to One by default. mutable done = false; @@ -43,24 +39,28 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { mutable numIter = 0; repeat { - SetXZeroFromOne(auxiliary); + // Assert valid starting states for all qubits + AssertMeasurement([PauliX], [auxiliary], One, "Auxiliary qubit is not in |+⟩ state."); + AssertMeasurement([PauliX], [resource], One, "Resource qubit is not in |+⟩ state."); + AssertQubitIsInState(target, inputBasis, inputValue); + // Run Part 1 of the program. let result1 = ApplyAndMeasurePart1(auxiliary, resource); // We'll only run Part 2 if Part 1 returns Zero. // Otherwise, we'll skip and rerun Part 1 again. - if (result1 == Zero) { //|0X〉 + if (result1 == Zero) { //0X let result2 = ApplyAndMeasurePart2(resource, target); - if (result2 == Zero) { //|00〉 + if (result2 == Zero) { //00 set success = true; - } else { //|01〉 - H(auxiliary); // Reset auxiliary from |0〉to |+〉 - SetXZeroFromOne(resource); // Reset resource from |1〉to |+〉 + } else { //01 + Z(auxiliary); // Reset auxiliary from |-⟩ to |+⟩ Adjoint Z(target); // Correct effective Z rotation on target } - } else { // |1X〉, skip Part 2 - // Reset auxiliary from |1〉to |+〉 - AssertQubit(One, auxiliary); - SetXZeroFromOne(auxiliary); + } else { //1X + // Set resource qubit back to |+⟩ + Reset(resource); + X(resource); + PrepareQubit(PauliX, resource); } set done = (success or numIter >= limit); set numIter = numIter + 1; @@ -68,26 +68,37 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { until (done); let result = Measure([inputBasis], [target]); + // From version 0.12 it is no longer necessary to release qubits in zero state. + Reset(target); + Reset(resource); + Reset(auxiliary); + return (success, result, numIter); } } - /// Prepare qubit in either |0〉or |1〉for the given basis - operation PrepareValueForBasis( - inputValue : Bool, - inputBasis : Pauli, - input: Qubit - ) : Unit { - if (inputValue) { - X(input); - } - PrepareQubit(inputBasis, input); - } + /// Initialize axiliary and resource qubits in |+⟩, target in |0⟩ or |1⟩ + operation InitializeQubits( + auxiliary: Qubit, + resource: Qubit, + target: Qubit, + inputBasis: Pauli, + inputValue: Bool + ) : Unit { + // Prepare auxiliary and resource qubits in |+⟩ state + X(auxiliary); + PrepareQubit(PauliX, auxiliary); + X(resource); + PrepareQubit(PauliX, resource); + AssertMeasurement([PauliX], [auxiliary], One, "Auxiliary qubit is not in |+> state."); + AssertMeasurement([PauliX], [resource], One, "Resource qubit is not in |+> state."); - /// Prepare qubit in |+〉state given it is in the |1〉state - operation SetXZeroFromOne(target : Qubit) : Unit { - X(target); // Flip to |0〉 - H(target); // Prepare |+> + // Prepare target qubit in |0⟩ or |1⟩ state, depending on input value + if (inputValue) { + X(target); + } + PrepareQubit(inputBasis, target); + AssertQubitIsInState(target, inputBasis, inputValue); } /// Part 1 of RUS circuit (red) @@ -115,4 +126,17 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { return Measure([PauliX], [resource]); } + + /// Assert target qubit state is a given value in a given basis + operation AssertQubitIsInState( + target: Qubit, + inputBasis: Pauli, + inputValue: Bool + ) : Unit { + if (inputValue) { + AssertMeasurement([inputBasis], [target], One, "Qubit is not in 1 state for given input basis."); + } else { + AssertMeasurement([inputBasis], [target], Zero, "Qubit is not in 0 state for given input basis."); + } + } } From f80433fadaeca7b8abd25a7f3050a5fdacf33394 Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Thu, 9 Jul 2020 10:44:07 -0700 Subject: [PATCH 18/31] WIP: Add UT --- .../tests/sample-tests/RepeatUntilSuccessTests.qs | 13 +++++++++++++ samples/tests/sample-tests/SampleTests.csproj | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 samples/tests/sample-tests/RepeatUntilSuccessTests.qs diff --git a/samples/tests/sample-tests/RepeatUntilSuccessTests.qs b/samples/tests/sample-tests/RepeatUntilSuccessTests.qs new file mode 100644 index 000000000000..46cfc1d67d24 --- /dev/null +++ b/samples/tests/sample-tests/RepeatUntilSuccessTests.qs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +namespace Microsoft.Quantum.Tests { + open Microsoft.Quantum.Samples.RepeatUntilSuccess; + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Diagnostics; + + @Test("QuantumSimulator") + operation RepeatUntilSuccessTest() : Unit { + Message("hello, world"); + } + +} diff --git a/samples/tests/sample-tests/SampleTests.csproj b/samples/tests/sample-tests/SampleTests.csproj index fe4180f4bf7d..dfe76b864467 100644 --- a/samples/tests/sample-tests/SampleTests.csproj +++ b/samples/tests/sample-tests/SampleTests.csproj @@ -19,11 +19,12 @@ + - - + + From bcadcf5c5defe4747b4af8fb37dc7ed8b1b6fefc Mon Sep 17 00:00:00 2001 From: Christopher Granade Date: Thu, 9 Jul 2020 16:20:53 -0700 Subject: [PATCH 19/31] Address build warnings by updating to 0.12.20070124. --- samples/algorithms/database-search/DatabaseSearchSample.csproj | 2 +- .../reversible-logic-synthesis/ReversibleLogicSynthesis.csproj | 2 +- .../phase-estimation/PhaseEstimationSample.csproj | 2 +- samples/error-correction/bit-flip-code/BitFlipCode.csproj | 2 +- samples/getting-started/measurement/Measurement.csproj | 2 +- .../getting-started/simple-algorithms/SimpleAlgorithms.csproj | 2 +- samples/simulation/ising/adiabatic/AdiabaticIsingSample.csproj | 2 +- .../simulation/ising/generators/IsingGeneratorsSample.csproj | 2 +- .../ising/phase-estimation/IsingPhaseEstimationSample.csproj | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/samples/algorithms/database-search/DatabaseSearchSample.csproj b/samples/algorithms/database-search/DatabaseSearchSample.csproj index 69ae5b1ee102..3172cb0ebd9e 100644 --- a/samples/algorithms/database-search/DatabaseSearchSample.csproj +++ b/samples/algorithms/database-search/DatabaseSearchSample.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/samples/algorithms/reversible-logic-synthesis/ReversibleLogicSynthesis.csproj b/samples/algorithms/reversible-logic-synthesis/ReversibleLogicSynthesis.csproj index e1e065249b67..95fc64fb8b5a 100644 --- a/samples/algorithms/reversible-logic-synthesis/ReversibleLogicSynthesis.csproj +++ b/samples/algorithms/reversible-logic-synthesis/ReversibleLogicSynthesis.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/samples/characterization/phase-estimation/PhaseEstimationSample.csproj b/samples/characterization/phase-estimation/PhaseEstimationSample.csproj index 41cb4c97b6a5..879f59c1aeee 100644 --- a/samples/characterization/phase-estimation/PhaseEstimationSample.csproj +++ b/samples/characterization/phase-estimation/PhaseEstimationSample.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/samples/error-correction/bit-flip-code/BitFlipCode.csproj b/samples/error-correction/bit-flip-code/BitFlipCode.csproj index 69ae5b1ee102..3172cb0ebd9e 100644 --- a/samples/error-correction/bit-flip-code/BitFlipCode.csproj +++ b/samples/error-correction/bit-flip-code/BitFlipCode.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/samples/getting-started/measurement/Measurement.csproj b/samples/getting-started/measurement/Measurement.csproj index 69ae5b1ee102..3172cb0ebd9e 100644 --- a/samples/getting-started/measurement/Measurement.csproj +++ b/samples/getting-started/measurement/Measurement.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/samples/getting-started/simple-algorithms/SimpleAlgorithms.csproj b/samples/getting-started/simple-algorithms/SimpleAlgorithms.csproj index 69ae5b1ee102..3172cb0ebd9e 100644 --- a/samples/getting-started/simple-algorithms/SimpleAlgorithms.csproj +++ b/samples/getting-started/simple-algorithms/SimpleAlgorithms.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/samples/simulation/ising/adiabatic/AdiabaticIsingSample.csproj b/samples/simulation/ising/adiabatic/AdiabaticIsingSample.csproj index a2f770e54c82..026ace46e965 100644 --- a/samples/simulation/ising/adiabatic/AdiabaticIsingSample.csproj +++ b/samples/simulation/ising/adiabatic/AdiabaticIsingSample.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/samples/simulation/ising/generators/IsingGeneratorsSample.csproj b/samples/simulation/ising/generators/IsingGeneratorsSample.csproj index 69ae5b1ee102..3172cb0ebd9e 100644 --- a/samples/simulation/ising/generators/IsingGeneratorsSample.csproj +++ b/samples/simulation/ising/generators/IsingGeneratorsSample.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/samples/simulation/ising/phase-estimation/IsingPhaseEstimationSample.csproj b/samples/simulation/ising/phase-estimation/IsingPhaseEstimationSample.csproj index 2032efb5ef8b..ecc29e4f5a4b 100644 --- a/samples/simulation/ising/phase-estimation/IsingPhaseEstimationSample.csproj +++ b/samples/simulation/ising/phase-estimation/IsingPhaseEstimationSample.csproj @@ -1,4 +1,4 @@ - + Exe From 59d620e052866c20bc862a2c5fa773d82bba2549 Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Fri, 10 Jul 2020 08:43:12 -0700 Subject: [PATCH 20/31] Refactor to take ApplyArcTan2 into separate operation, fix issue with aux qubit initialization --- .../RepeatUntilSuccess.qs | 104 +++++++++--------- 1 file changed, 54 insertions(+), 50 deletions(-) diff --git a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs index e5bec46518ec..733cd5eafc2d 100644 --- a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs +++ b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs @@ -24,7 +24,7 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { /// Rz(arctan(2)) gate (also known as V_3 gate) on the target qubit. /// If this fails, the program reruns the circuit up to times. @EntryPoint() - operation ApplyRzArcTan2( + operation CreateQubitsAndApplyRzArcTan2( inputValue : Bool, inputBasis: Pauli, limit: Int @@ -32,51 +32,61 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { using ((auxiliary, resource, target) = (Qubit(), Qubit(), Qubit())) { // Initialize qubits to starting values (|+⟩, |+⟩, |0⟩/|1⟩) InitializeQubits(auxiliary, resource, target, inputBasis, inputValue); - - // Initialize results to One by default. - mutable done = false; - mutable success = false; - mutable numIter = 0; - - repeat { - // Assert valid starting states for all qubits - AssertMeasurement([PauliX], [auxiliary], One, "Auxiliary qubit is not in |+⟩ state."); - AssertMeasurement([PauliX], [resource], One, "Resource qubit is not in |+⟩ state."); - AssertQubitIsInState(target, inputBasis, inputValue); - - // Run Part 1 of the program. - let result1 = ApplyAndMeasurePart1(auxiliary, resource); - // We'll only run Part 2 if Part 1 returns Zero. - // Otherwise, we'll skip and rerun Part 1 again. - if (result1 == Zero) { //0X - let result2 = ApplyAndMeasurePart2(resource, target); - if (result2 == Zero) { //00 - set success = true; - } else { //01 - Z(auxiliary); // Reset auxiliary from |-⟩ to |+⟩ - Adjoint Z(target); // Correct effective Z rotation on target - } - } else { //1X - // Set resource qubit back to |+⟩ - Reset(resource); - X(resource); - PrepareQubit(PauliX, resource); - } - set done = (success or numIter >= limit); - set numIter = numIter + 1; - } - until (done); - + let (success, numIter) = ApplyRzArcTan2(auxiliary, resource, target, inputBasis, inputValue, limit); let result = Measure([inputBasis], [target]); // From version 0.12 it is no longer necessary to release qubits in zero state. Reset(target); Reset(resource); Reset(auxiliary); - return (success, result, numIter); } } + /// Apply Rz(arctan(2)) on qubits using repeat until success algorithm + operation ApplyRzArcTan2( + auxiliary: Qubit, + resource: Qubit, + target: Qubit, + inputBasis: Pauli, + inputValue: Bool, + limit: Int + ) : (Bool, Int) { + // Initialize results to One by default. + mutable done = false; + mutable success = false; + mutable numIter = 0; + + repeat { + // Assert valid starting states for all qubits + AssertMeasurement([PauliX], [auxiliary], Zero, "Auxiliary qubit is not in |+⟩ state."); + AssertMeasurement([PauliX], [resource], Zero, "Resource qubit is not in |+⟩ state."); + AssertQubitIsInState(target, inputBasis, inputValue); + + // Run Part 1 of the program. + let result1 = ApplyAndMeasurePart1(auxiliary, resource); + // We'll only run Part 2 if Part 1 returns Zero. + // Otherwise, we'll skip and rerun Part 1 again. + if (result1 == Zero) { //0X + let result2 = ApplyAndMeasurePart2(resource, target); + if (result2 == Zero) { //00 + set success = true; + } else { //01 + Z(resource); // Reset resource from |-⟩ to |+⟩ + Adjoint Z(target); // Correct effective Z rotation on target + } + } else { //1X + // Set auxiliary and resource qubit back to |+⟩ + Z(auxiliary); + Reset(resource); + H(resource); + } + set done = (success or numIter >= limit); + set numIter = numIter + 1; + } + until (done); + return (success, numIter); + } + /// Initialize axiliary and resource qubits in |+⟩, target in |0⟩ or |1⟩ operation InitializeQubits( auxiliary: Qubit, @@ -86,19 +96,14 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { inputValue: Bool ) : Unit { // Prepare auxiliary and resource qubits in |+⟩ state - X(auxiliary); - PrepareQubit(PauliX, auxiliary); - X(resource); - PrepareQubit(PauliX, resource); - AssertMeasurement([PauliX], [auxiliary], One, "Auxiliary qubit is not in |+> state."); - AssertMeasurement([PauliX], [resource], One, "Resource qubit is not in |+> state."); + H(auxiliary); + H(resource); // Prepare target qubit in |0⟩ or |1⟩ state, depending on input value if (inputValue) { X(target); } PrepareQubit(inputBasis, target); - AssertQubitIsInState(target, inputBasis, inputValue); } /// Part 1 of RUS circuit (red) @@ -106,11 +111,9 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { auxiliary: Qubit, resource: Qubit ) : Result { - within { - Adjoint T(auxiliary); - } apply { - CNOT(resource, auxiliary); - } + T(auxiliary); + CNOT(resource, auxiliary); + Adjoint T(auxiliary); return Measure([PauliX], [auxiliary]); } @@ -120,9 +123,10 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { resource: Qubit, target: Qubit ) : Result { + T(target); + Z(target); CNOT(target, resource); T(resource); - T(target); return Measure([PauliX], [resource]); } From 2cd35c7a834aa15cf5b1e6bc52a03ce34fa78db7 Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Fri, 10 Jul 2020 08:43:51 -0700 Subject: [PATCH 21/31] add unit test for ApplyRzArcTan2 --- .../sample-tests/RepeatUntilSuccessTests.qs | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/samples/tests/sample-tests/RepeatUntilSuccessTests.qs b/samples/tests/sample-tests/RepeatUntilSuccessTests.qs index 46cfc1d67d24..f595a7c2b87b 100644 --- a/samples/tests/sample-tests/RepeatUntilSuccessTests.qs +++ b/samples/tests/sample-tests/RepeatUntilSuccessTests.qs @@ -4,10 +4,51 @@ namespace Microsoft.Quantum.Tests { open Microsoft.Quantum.Samples.RepeatUntilSuccess; open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Diagnostics; + open Microsoft.Quantum.Math; @Test("QuantumSimulator") - operation RepeatUntilSuccessTest() : Unit { - Message("hello, world"); + operation RepeatUntilSuccessInitializeTest() : Unit { + let inputBasis = PauliX; + let inputValue = true; + using ((auxiliary, resource, target) = (Qubit(), Qubit(), Qubit())) { + // Initialize qubits to starting values (|+⟩, |+⟩, |0⟩/|1⟩) + InitializeQubits(auxiliary, resource, target, inputBasis, inputValue); + + // Assert valid starting states for all qubits + AssertMeasurement([PauliX], [auxiliary], Zero, "Auxiliary qubit is not in |+⟩ state."); + AssertMeasurement([PauliX], [resource], Zero, "Resource qubit is not in |+⟩ state."); + AssertQubitIsInState(target, inputBasis, inputValue); + + // Reset qubits (should no longer be necessary in v0.12) + Reset(auxiliary); + Reset(resource); + Reset(target); + } } + @Test("QuantumSimulator") + operation RepeatUntilSuccessRzArcTan2Test() : Unit { + let inputBasis = PauliX; + let inputValue = true; + let limit = 50; // typically executes succesfully in n < 10 so 50 is playing it safe + using ((auxiliary, resource, target) = (Qubit(), Qubit(), Qubit())) { + // Initialize qubits to starting values (|+⟩, |+⟩, |0⟩/|1⟩) + InitializeQubits(auxiliary, resource, target, inputBasis, inputValue); + AssertMeasurement([inputBasis], [target], One, "Target qubit is not in |1⟩ state."); + let (success, numIter) = ApplyRzArcTan2(auxiliary, resource, target, inputBasis, inputValue, limit); + Rz(2.0 * ArcTan(2.0), target); // Rotate back to initial state + + if (success == true) { + AssertMeasurement([PauliX], [auxiliary], Zero, "Auxiliary qubit is not in |-⟩ state."); + AssertMeasurement([PauliX], [resource], Zero, "Resource qubit is not in |-⟩ state."); + AssertMeasurement([inputBasis], [target], One, "Target qubit is not in 1 state for the given basis."); + } + + // Reset qubits (should no longer be necessary in v0.12) + Reset(auxiliary); + Reset(resource); + Reset(target); + + } + } } From 03c8f3662030358eeffb458e322186a84e836285 Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Fri, 10 Jul 2020 09:26:50 -0700 Subject: [PATCH 22/31] Remove Program.cs from manifest in README --- samples/algorithms/repeat-until-success/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/algorithms/repeat-until-success/README.md b/samples/algorithms/repeat-until-success/README.md index 101a0a83f555..6d0d1088f1ac 100644 --- a/samples/algorithms/repeat-until-success/README.md +++ b/samples/algorithms/repeat-until-success/README.md @@ -31,7 +31,6 @@ Options are: - **repeat-until-success/** - [RepeatUntilSuccess.csproj](./RepeatUntilSuccess.csproj): Main C# project for the example. - - [Program.cs](./Program.cs): C# code to call the operations defined in Q# and perform classical post-processing. - [RepeatUntilSuccess.qs](./RepeatUntilSuccess.qs): The Q# implementation of the RUS algorithm. ## Example run From c7751076d1ddce2c88ad8b8bf4c978a1b4d864c5 Mon Sep 17 00:00:00 2001 From: Guen P Date: Fri, 10 Jul 2020 10:18:55 -0700 Subject: [PATCH 23/31] Update samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs Change placement of parens for 'done' logic Co-authored-by: Mathias Soeken --- samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs index 733cd5eafc2d..8b207bdc9b5e 100644 --- a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs +++ b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs @@ -80,7 +80,7 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { Reset(resource); H(resource); } - set done = (success or numIter >= limit); + set done = success or (numIter >= limit); set numIter = numIter + 1; } until (done); From 8d61cf511173f03e29c656522edc0d33230ce43f Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Fri, 10 Jul 2020 10:21:04 -0700 Subject: [PATCH 24/31] fix version bug from master merge commit --- samples/tests/sample-tests/SampleTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/tests/sample-tests/SampleTests.csproj b/samples/tests/sample-tests/SampleTests.csproj index 2df6ef0e0aed..362560e440a0 100644 --- a/samples/tests/sample-tests/SampleTests.csproj +++ b/samples/tests/sample-tests/SampleTests.csproj @@ -1,4 +1,4 @@ - + netcoreapp3.1 x64 From 07d001cd80bdbd41d07b1af96d761d5fff7b1f20 Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Fri, 10 Jul 2020 17:37:34 -0700 Subject: [PATCH 25/31] address build errors by upgrading samples to version 0.12.20070124 --- samples/algorithms/chsh-game/CHSHGame.csproj | 2 +- .../integer-factorization/IntegerFactorization.csproj | 2 +- samples/algorithms/oracle-synthesis/OracleSynthesis.csproj | 2 +- samples/algorithms/order-finding/OrderFinding.csproj | 2 +- samples/algorithms/simple-grover/SimpleGroverSample.csproj | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/samples/algorithms/chsh-game/CHSHGame.csproj b/samples/algorithms/chsh-game/CHSHGame.csproj index 007bd60caaf5..e8f657199fba 100644 --- a/samples/algorithms/chsh-game/CHSHGame.csproj +++ b/samples/algorithms/chsh-game/CHSHGame.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/samples/algorithms/integer-factorization/IntegerFactorization.csproj b/samples/algorithms/integer-factorization/IntegerFactorization.csproj index 69ae5b1ee102..3172cb0ebd9e 100644 --- a/samples/algorithms/integer-factorization/IntegerFactorization.csproj +++ b/samples/algorithms/integer-factorization/IntegerFactorization.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/samples/algorithms/oracle-synthesis/OracleSynthesis.csproj b/samples/algorithms/oracle-synthesis/OracleSynthesis.csproj index 69ae5b1ee102..3172cb0ebd9e 100644 --- a/samples/algorithms/oracle-synthesis/OracleSynthesis.csproj +++ b/samples/algorithms/oracle-synthesis/OracleSynthesis.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/samples/algorithms/order-finding/OrderFinding.csproj b/samples/algorithms/order-finding/OrderFinding.csproj index 59c727c5ed0b..e1b9cd037ca0 100644 --- a/samples/algorithms/order-finding/OrderFinding.csproj +++ b/samples/algorithms/order-finding/OrderFinding.csproj @@ -1,4 +1,4 @@ - + Exe netcoreapp3.1 diff --git a/samples/algorithms/simple-grover/SimpleGroverSample.csproj b/samples/algorithms/simple-grover/SimpleGroverSample.csproj index 69ae5b1ee102..3172cb0ebd9e 100644 --- a/samples/algorithms/simple-grover/SimpleGroverSample.csproj +++ b/samples/algorithms/simple-grover/SimpleGroverSample.csproj @@ -1,4 +1,4 @@ - + Exe From a934d84583593fcad43aa89c52336581ba33fedb Mon Sep 17 00:00:00 2001 From: Guen P Date: Mon, 13 Jul 2020 09:23:44 -0700 Subject: [PATCH 26/31] Apply suggestions from code review Follow style guide, clarify docs, small refactors Co-authored-by: Chris Granade --- .../algorithms/repeat-until-success/README.md | 9 ++++-- .../RepeatUntilSuccess.qs | 29 ++++++++++--------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/samples/algorithms/repeat-until-success/README.md b/samples/algorithms/repeat-until-success/README.md index 6d0d1088f1ac..b2f19abd2db2 100644 --- a/samples/algorithms/repeat-until-success/README.md +++ b/samples/algorithms/repeat-until-success/README.md @@ -3,6 +3,11 @@ This is an example of a Repeat-Until-Success (RUS) algorithm implemented in a Q# program. The algorithm has been described in [Adam Paetznick, Krysta M. Svore, Quantum Information & Computation 14(15 & 16): 1277-1301 (2014)](https://arxiv.org/abs/1311.1074). +## Prerequisites ## + +- The Microsoft [Quantum Development Kit](https://docs.microsoft.com/quantum/install-guide/). +## Description + The idea for the RUS algorithm originates from the goal of decomposing a single-qubit unitary operation into a sequence of gates from a given universal basis set. In general, the goal of a RUS algorithm is to reduce the number of Clifford gates needed to execute said unitary operation by using one or more auxiliary qubits that are measured during the execution of the algorithm to indicate whether the desired output state has been achieved. This specific RUS algorithm consists of a circuit that uses two auxiliary qubits, which we label `auxiliary` and `resource`, and one `target` qubit. In this example, the RUS algorithm aims to apply exp(i⋅ArcTan(2)⋅Z) or a $V_3$-gate on the `target` qubit. The algorithm is based on the logic mapped out in the below circuit diagram (Fig. 1(c) from [source](https://arxiv.org/abs/1311.1074)). The qubits on the left hand side are labeled from top to bottom: `auxiliary`, `resource` and `target`. As described in the whitepaper, the desired operation will have been achieved when the measurements on both `auxiliary` and `resource` qubits returns `Zero`. When that happens we can exit the program and return the result. In all other cases, we would have to re-run the circuit. Important to note is that if the auxiliary qubit returns `Zero` but the `resource` qubit returns `One`, the resulting operation will have been an effective `Z` rotation which we will then need to correct for. @@ -17,7 +22,7 @@ The program returns a tuple with three values: whether the program ran successfu ## Running the Sample -Browse to the `samples\algorithms\repeat-until-success` folder and run `dotnet build` to build the project. Then run `dotnet run [options] --no-build`. Optionally, omit the `--no-build` option to automatically build the project before execution. +Browse to the `samples/algorithms/repeat-until-success` folder and run `dotnet build` to build the project. Then run `dotnet run [options] --no-build`. Optionally, omit the `--no-build` option to automatically build the project before execution. Options are: ``` @@ -36,6 +41,6 @@ Options are: ## Example run ``` -> dotnet run --no-build --input-value true --input-basis PauliZ --limit 10 +> dotnet run --input-value true --input-basis PauliZ --limit 10 (True, One, 3) ``` diff --git a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs index 8b207bdc9b5e..f7ac0d019a18 100644 --- a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs +++ b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { open Microsoft.Quantum.Intrinsic; @@ -17,6 +17,7 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { /// ](https://arxiv.org/abs/1311.1074) /// For circuit diagram, see file RUS.png (to be added to README). /// + /// # Remarks /// The program executes a circuit on a "target" qubit using an "auxiliary" and /// "resource" qubit. The circuit consists of two parts (red and blue in image). /// The goal is to measure Zero for both the auxiliary and resource qubit. @@ -26,18 +27,17 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { @EntryPoint() operation CreateQubitsAndApplyRzArcTan2( inputValue : Bool, - inputBasis: Pauli, + inputBasis : Pauli, limit: Int - ) : (Bool, Result, Int) { + ) + : (Bool, Result, Int) { using ((auxiliary, resource, target) = (Qubit(), Qubit(), Qubit())) { // Initialize qubits to starting values (|+⟩, |+⟩, |0⟩/|1⟩) InitializeQubits(auxiliary, resource, target, inputBasis, inputValue); let (success, numIter) = ApplyRzArcTan2(auxiliary, resource, target, inputBasis, inputValue, limit); let result = Measure([inputBasis], [target]); // From version 0.12 it is no longer necessary to release qubits in zero state. - Reset(target); - Reset(resource); - Reset(auxiliary); + ResetAll([target, resource, auxiliary]); return (success, result, numIter); } } @@ -111,9 +111,11 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { auxiliary: Qubit, resource: Qubit ) : Result { - T(auxiliary); - CNOT(resource, auxiliary); - Adjoint T(auxiliary); + within { + T(auxiliary); + } apply { + CNOT(resource, auxiliary); + } return Measure([PauliX], [auxiliary]); } @@ -137,10 +139,9 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { inputBasis: Pauli, inputValue: Bool ) : Unit { - if (inputValue) { - AssertMeasurement([inputBasis], [target], One, "Qubit is not in 1 state for given input basis."); - } else { - AssertMeasurement([inputBasis], [target], Zero, "Qubit is not in 0 state for given input basis."); - } + AssertMeasurement( + [inputBasis], [target], inputValue ? One | Zero, + $"Qubit is not in {inputValue ? One | Zero} state for given input basis." + ); } } From c6185a40259652632ab663d4765ca1bcd2e6b418 Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Mon, 13 Jul 2020 09:38:19 -0700 Subject: [PATCH 27/31] add YAML metadata for sample discoverability --- samples/algorithms/repeat-until-success/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/samples/algorithms/repeat-until-success/README.md b/samples/algorithms/repeat-until-success/README.md index b2f19abd2db2..fa89a51733ba 100644 --- a/samples/algorithms/repeat-until-success/README.md +++ b/samples/algorithms/repeat-until-success/README.md @@ -1,3 +1,12 @@ +--- +page_type: sample +languages: +- qsharp +products: +- qdk +description: "This is an example of a Repeat-Until-Success (RUS) algorithm that executes a exp(i⋅ArcTan(2)⋅Z) operation." +--- + # Repeat-until-success This is an example of a Repeat-Until-Success (RUS) algorithm implemented in a Q# program. From af7ec7eaa8f0c3aad850233e03d508705ee22cc5 Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Mon, 13 Jul 2020 10:15:33 -0700 Subject: [PATCH 28/31] improve doc(string)s, reorder input variables to have qubits last --- .../algorithms/repeat-until-success/README.md | 10 +- .../RepeatUntilSuccess.qs | 101 ++++++++++++++---- .../sample-tests/RepeatUntilSuccessTests.qs | 6 +- 3 files changed, 90 insertions(+), 27 deletions(-) diff --git a/samples/algorithms/repeat-until-success/README.md b/samples/algorithms/repeat-until-success/README.md index fa89a51733ba..e2f91c010611 100644 --- a/samples/algorithms/repeat-until-success/README.md +++ b/samples/algorithms/repeat-until-success/README.md @@ -33,12 +33,12 @@ The program returns a tuple with three values: whether the program ran successfu Browse to the `samples/algorithms/repeat-until-success` folder and run `dotnet build` to build the project. Then run `dotnet run [options] --no-build`. Optionally, omit the `--no-build` option to automatically build the project before execution. -Options are: +To see options, run `dotnet run -- -help`. ``` - --input-value (REQUIRED) The input value to use. - --input-basis (REQUIRED) The input basis to use. - --limit (REQUIRED) The repetition limit. - -s, --simulator The name of the simulator to use. +Options: + --input-value (REQUIRED) Boolean value for input qubit (true maps to One, false maps to Zero) + --input-basis (REQUIRED) Pauli basis to prepare input qubit in + --limit (REQUIRED) Integer limit to number of repeats of circuit ``` ## Manifest diff --git a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs index f7ac0d019a18..d8e407bb1ce2 100644 --- a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs +++ b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs @@ -15,7 +15,15 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { /// - [ *Adam Paetznick, Krysta M. Svore*, /// Quantum Information & Computation 14(15 & 16): 1277-1301 (2014) /// ](https://arxiv.org/abs/1311.1074) - /// For circuit diagram, see file RUS.png (to be added to README). + /// For circuit diagram, see file RUS.png. + /// + /// # Input + /// ## inputBasis + /// Pauli basis to prepare input qubit in + /// ## inputValue + /// Boolean value for input qubit (true maps to One, false maps to Zero) + /// ## limit + /// Integer limit to number of repeats of circuit /// /// # Remarks /// The program executes a circuit on a "target" qubit using an "auxiliary" and @@ -33,8 +41,8 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { : (Bool, Result, Int) { using ((auxiliary, resource, target) = (Qubit(), Qubit(), Qubit())) { // Initialize qubits to starting values (|+⟩, |+⟩, |0⟩/|1⟩) - InitializeQubits(auxiliary, resource, target, inputBasis, inputValue); - let (success, numIter) = ApplyRzArcTan2(auxiliary, resource, target, inputBasis, inputValue, limit); + InitializeQubits(inputBasis, inputValue, auxiliary, resource, target); + let (success, numIter) = ApplyRzArcTan2(inputBasis, inputValue, limit, auxiliary, resource, target); let result = Measure([inputBasis], [target]); // From version 0.12 it is no longer necessary to release qubits in zero state. ResetAll([target, resource, auxiliary]); @@ -42,14 +50,32 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { } } - /// Apply Rz(arctan(2)) on qubits using repeat until success algorithm + /// # Summary + /// Apply Rz(arctan(2)) on qubits using repeat until success algorithm. + /// + /// # Input + /// ## inputBasis + /// Pauli basis to prepare input qubit in + /// ## inputValue + /// Boolean value for input qubit (true maps to One, false maps to Zero) + /// ## limit + /// Integer limit to number of repeats of circuit + /// ## auxiliary + /// Auxiliary qubit + /// ## resource + /// Resource qubit + /// ## target + /// Target qubit + /// + /// # Output + /// Tuple of (success, numIter) where success = false if the number of iterations (numIter) exceeds the input operation ApplyRzArcTan2( - auxiliary: Qubit, - resource: Qubit, - target: Qubit, inputBasis: Pauli, inputValue: Bool, - limit: Int + limit: Int, + auxiliary: Qubit, + resource: Qubit, + target: Qubit ) : (Bool, Int) { // Initialize results to One by default. mutable done = false; @@ -66,15 +92,15 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { let result1 = ApplyAndMeasurePart1(auxiliary, resource); // We'll only run Part 2 if Part 1 returns Zero. // Otherwise, we'll skip and rerun Part 1 again. - if (result1 == Zero) { //0X + if (result1 == Zero) { //|0+⟩ let result2 = ApplyAndMeasurePart2(resource, target); - if (result2 == Zero) { //00 + if (result2 == Zero) { //|00⟩ set success = true; - } else { //01 + } else { //|01⟩ Z(resource); // Reset resource from |-⟩ to |+⟩ Adjoint Z(target); // Correct effective Z rotation on target } - } else { //1X + } else { //|1+⟩ // Set auxiliary and resource qubit back to |+⟩ Z(auxiliary); Reset(resource); @@ -87,13 +113,28 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { return (success, numIter); } - /// Initialize axiliary and resource qubits in |+⟩, target in |0⟩ or |1⟩ + /// # Summary + /// Initialize axiliary and resource qubits in |+⟩, target in |0⟩ or |1⟩. + /// + /// # Input + /// ## inputBasis + /// Pauli basis to prepare input qubit in + /// ## inputValue + /// Boolean value for input qubit (true maps to One, false maps to Zero) + /// ## limit + /// Integer limit to number of repeats of circuit + /// ## auxiliary + /// Auxiliary qubit + /// ## resource + /// Resource qubit + /// ## target + /// Target qubit operation InitializeQubits( + inputBasis: Pauli, + inputValue: Bool, auxiliary: Qubit, resource: Qubit, - target: Qubit, - inputBasis: Pauli, - inputValue: Bool + target: Qubit ) : Unit { // Prepare auxiliary and resource qubits in |+⟩ state H(auxiliary); @@ -106,7 +147,14 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { PrepareQubit(inputBasis, target); } - /// Part 1 of RUS circuit (red) + /// # Summary + /// Apply part 1 of RUS circuit (red circuit shown in README) and measure auxiliary qubit in Pauli X basis + /// + /// # Input + /// ## auxiliary + /// Auxiliary qubit + /// ## resource + /// Resource qubit operation ApplyAndMeasurePart1( auxiliary: Qubit, resource: Qubit @@ -120,7 +168,14 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { return Measure([PauliX], [auxiliary]); } - /// Part 2 of RUS circuit (blue) + /// # Summary + /// Apply part 2 of RUS circuit (blue circuit shown in README) and measure resource qubit in Pauli X basis + /// + /// # Input + /// ## resource + /// Resource qubit + /// ## target + /// Target qubit operation ApplyAndMeasurePart2( resource: Qubit, target: Qubit @@ -133,7 +188,15 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { return Measure([PauliX], [resource]); } - /// Assert target qubit state is a given value in a given basis + /// # Summary + /// Assert target qubit state is the desired input value in the desired input basis. + /// + /// ## target + /// Target qubit + /// ## inputBasis + /// Pauli basis to prepare input qubit in + /// ## inputValue + /// Boolean value for input qubit (true maps to One, false maps to Zero) operation AssertQubitIsInState( target: Qubit, inputBasis: Pauli, diff --git a/samples/tests/sample-tests/RepeatUntilSuccessTests.qs b/samples/tests/sample-tests/RepeatUntilSuccessTests.qs index f595a7c2b87b..e12b965a123c 100644 --- a/samples/tests/sample-tests/RepeatUntilSuccessTests.qs +++ b/samples/tests/sample-tests/RepeatUntilSuccessTests.qs @@ -12,7 +12,7 @@ namespace Microsoft.Quantum.Tests { let inputValue = true; using ((auxiliary, resource, target) = (Qubit(), Qubit(), Qubit())) { // Initialize qubits to starting values (|+⟩, |+⟩, |0⟩/|1⟩) - InitializeQubits(auxiliary, resource, target, inputBasis, inputValue); + InitializeQubits(inputBasis, inputValue, auxiliary, resource, target); // Assert valid starting states for all qubits AssertMeasurement([PauliX], [auxiliary], Zero, "Auxiliary qubit is not in |+⟩ state."); @@ -33,9 +33,9 @@ namespace Microsoft.Quantum.Tests { let limit = 50; // typically executes succesfully in n < 10 so 50 is playing it safe using ((auxiliary, resource, target) = (Qubit(), Qubit(), Qubit())) { // Initialize qubits to starting values (|+⟩, |+⟩, |0⟩/|1⟩) - InitializeQubits(auxiliary, resource, target, inputBasis, inputValue); + InitializeQubits(inputBasis, inputValue, auxiliary, resource, target); AssertMeasurement([inputBasis], [target], One, "Target qubit is not in |1⟩ state."); - let (success, numIter) = ApplyRzArcTan2(auxiliary, resource, target, inputBasis, inputValue, limit); + let (success, numIter) = ApplyRzArcTan2(inputBasis, inputValue, limit, auxiliary, resource, target); Rz(2.0 * ArcTan(2.0), target); // Rotate back to initial state if (success == true) { From db413c754643d33bb1722bed7efb74397da5ad0b Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Mon, 13 Jul 2020 10:34:19 -0700 Subject: [PATCH 29/31] follow style guidelines --- .../RepeatUntilSuccess.qs | 50 ++++++++++++------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs index d8e407bb1ce2..df3a46da89ba 100644 --- a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs +++ b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs @@ -26,8 +26,9 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { /// Integer limit to number of repeats of circuit /// /// # Remarks - /// The program executes a circuit on a "target" qubit using an "auxiliary" and - /// "resource" qubit. The circuit consists of two parts (red and blue in image). + /// The program executes a circuit on a "target" qubit using an "auxiliary" + /// and "resource" qubit. The circuit consists of two parts (red and blue + /// in image). /// The goal is to measure Zero for both the auxiliary and resource qubit. /// If this succeeds, the program will have effectively applied an /// Rz(arctan(2)) gate (also known as V_3 gate) on the target qubit. @@ -41,10 +42,14 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { : (Bool, Result, Int) { using ((auxiliary, resource, target) = (Qubit(), Qubit(), Qubit())) { // Initialize qubits to starting values (|+⟩, |+⟩, |0⟩/|1⟩) - InitializeQubits(inputBasis, inputValue, auxiliary, resource, target); - let (success, numIter) = ApplyRzArcTan2(inputBasis, inputValue, limit, auxiliary, resource, target); + InitializeQubits( + inputBasis, inputValue, auxiliary, resource, target + ); + let (success, numIter) = ApplyRzArcTan2( + inputBasis, inputValue, limit, auxiliary, resource, target); let result = Measure([inputBasis], [target]); - // From version 0.12 it is no longer necessary to release qubits in zero state. + // From version 0.12 it is no longer necessary to release qubits + /// in zero state. ResetAll([target, resource, auxiliary]); return (success, result, numIter); } @@ -68,7 +73,8 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { /// Target qubit /// /// # Output - /// Tuple of (success, numIter) where success = false if the number of iterations (numIter) exceeds the input + /// Tuple of (success, numIter) where success = false if the number of + /// iterations (numIter) exceeds the input operation ApplyRzArcTan2( inputBasis: Pauli, inputValue: Bool, @@ -76,7 +82,8 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { auxiliary: Qubit, resource: Qubit, target: Qubit - ) : (Bool, Int) { + ) + : (Bool, Int) { // Initialize results to One by default. mutable done = false; mutable success = false; @@ -84,8 +91,10 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { repeat { // Assert valid starting states for all qubits - AssertMeasurement([PauliX], [auxiliary], Zero, "Auxiliary qubit is not in |+⟩ state."); - AssertMeasurement([PauliX], [resource], Zero, "Resource qubit is not in |+⟩ state."); + AssertMeasurement([PauliX], [auxiliary], Zero, + "Auxiliary qubit is not in |+⟩ state."); + AssertMeasurement([PauliX], [resource], Zero, + "Resource qubit is not in |+⟩ state."); AssertQubitIsInState(target, inputBasis, inputValue); // Run Part 1 of the program. @@ -135,7 +144,8 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { auxiliary: Qubit, resource: Qubit, target: Qubit - ) : Unit { + ) + : Unit { // Prepare auxiliary and resource qubits in |+⟩ state H(auxiliary); H(resource); @@ -148,7 +158,8 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { } /// # Summary - /// Apply part 1 of RUS circuit (red circuit shown in README) and measure auxiliary qubit in Pauli X basis + /// Apply part 1 of RUS circuit (red circuit shown in README) and measure + /// auxiliary qubit in Pauli X basis /// /// # Input /// ## auxiliary @@ -158,7 +169,8 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { operation ApplyAndMeasurePart1( auxiliary: Qubit, resource: Qubit - ) : Result { + ) + : Result { within { T(auxiliary); } apply { @@ -169,17 +181,15 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { } /// # Summary - /// Apply part 2 of RUS circuit (blue circuit shown in README) and measure resource qubit in Pauli X basis + /// Apply part 2 of RUS circuit (blue circuit shown in README) and measure + /// resource qubit in Pauli X basis /// /// # Input /// ## resource /// Resource qubit /// ## target /// Target qubit - operation ApplyAndMeasurePart2( - resource: Qubit, - target: Qubit - ) : Result { + operation ApplyAndMeasurePart2(resource: Qubit, target: Qubit) : Result { T(target); Z(target); CNOT(target, resource); @@ -189,7 +199,8 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { } /// # Summary - /// Assert target qubit state is the desired input value in the desired input basis. + /// Assert target qubit state is the desired input value in the desired + /// input basis. /// /// ## target /// Target qubit @@ -201,7 +212,8 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { target: Qubit, inputBasis: Pauli, inputValue: Bool - ) : Unit { + ) + : Unit { AssertMeasurement( [inputBasis], [target], inputValue ? One | Zero, $"Qubit is not in {inputValue ? One | Zero} state for given input basis." From d1bb1a6d66ea3af1defde435a57aa9060e3f9ece Mon Sep 17 00:00:00 2001 From: Guen P Date: Mon, 13 Jul 2020 11:47:59 -0700 Subject: [PATCH 30/31] Apply suggestions from code review Improvements to docs, use unicode instead of latex Co-authored-by: Chris Granade --- samples/algorithms/repeat-until-success/README.md | 6 +++--- .../algorithms/repeat-until-success/RepeatUntilSuccess.qs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/algorithms/repeat-until-success/README.md b/samples/algorithms/repeat-until-success/README.md index e2f91c010611..b31bbe597b61 100644 --- a/samples/algorithms/repeat-until-success/README.md +++ b/samples/algorithms/repeat-until-success/README.md @@ -4,7 +4,7 @@ languages: - qsharp products: - qdk -description: "This is an example of a Repeat-Until-Success (RUS) algorithm that executes a exp(i⋅ArcTan(2)⋅Z) operation." +description: "Using repeat-until-success patterns in quantum programs" --- # Repeat-until-success @@ -19,7 +19,7 @@ The algorithm has been described in [Adam Paetznick, Krysta M. Svore, Quantum In The idea for the RUS algorithm originates from the goal of decomposing a single-qubit unitary operation into a sequence of gates from a given universal basis set. In general, the goal of a RUS algorithm is to reduce the number of Clifford gates needed to execute said unitary operation by using one or more auxiliary qubits that are measured during the execution of the algorithm to indicate whether the desired output state has been achieved. This specific RUS algorithm consists of a circuit that uses two auxiliary qubits, which we label `auxiliary` and `resource`, and one `target` qubit. -In this example, the RUS algorithm aims to apply exp(i⋅ArcTan(2)⋅Z) or a $V_3$-gate on the `target` qubit. The algorithm is based on the logic mapped out in the below circuit diagram (Fig. 1(c) from [source](https://arxiv.org/abs/1311.1074)). The qubits on the left hand side are labeled from top to bottom: `auxiliary`, `resource` and `target`. As described in the whitepaper, the desired operation will have been achieved when the measurements on both `auxiliary` and `resource` qubits returns `Zero`. When that happens we can exit the program and return the result. In all other cases, we would have to re-run the circuit. Important to note is that if the auxiliary qubit returns `Zero` but the `resource` qubit returns `One`, the resulting operation will have been an effective `Z` rotation which we will then need to correct for. +In this example, the RUS algorithm aims to apply exp(i⋅ArcTan(2)⋅Z) or a 𝑉₃-gate on the `target` qubit. The algorithm is based on the logic mapped out in the below circuit diagram (Fig. 1(c) from [source](https://arxiv.org/abs/1311.1074)). The qubits on the left hand side are labeled from top to bottom: `auxiliary`, `resource` and `target`. As described in the whitepaper, the desired operation will have been achieved when the measurements on both `auxiliary` and `resource` qubits returns `Zero`. When that happens we can exit the program and return the result. In all other cases, we would have to re-run the circuit. Important to note is that if the auxiliary qubit returns `Zero` but the `resource` qubit returns `One`, the resulting operation will have been an effective `Z` rotation which we will then need to correct for. ![RUS circuit diagram](RUS.png) @@ -33,7 +33,7 @@ The program returns a tuple with three values: whether the program ran successfu Browse to the `samples/algorithms/repeat-until-success` folder and run `dotnet build` to build the project. Then run `dotnet run [options] --no-build`. Optionally, omit the `--no-build` option to automatically build the project before execution. -To see options, run `dotnet run -- -help`. +To see options, run `dotnet run -- --help`. ``` Options: --input-value (REQUIRED) Boolean value for input qubit (true maps to One, false maps to Zero) diff --git a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs index df3a46da89ba..c071ac07d8e4 100644 --- a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs +++ b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs @@ -10,7 +10,7 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { /// # Summary /// Example of a Repeat-until-success algorithm implementing a circuit /// that achieves exp(i⋅ArcTan(2)⋅Z) by Paetznick & Svore. - /// Gate exp(i⋅ArcTan(2)⋅Z) is also know as V gate. + /// The exp(𝑖 ArcTan(2) 𝑍) operation is also known as the "𝑉 gate." /// # References /// - [ *Adam Paetznick, Krysta M. Svore*, /// Quantum Information & Computation 14(15 & 16): 1277-1301 (2014) From d21bb596dd76fb91aaa40fbd0e90c0178b9c7027 Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Mon, 13 Jul 2020 11:58:30 -0700 Subject: [PATCH 31/31] consistency in variable type annotations, fix grammar error in docstring --- .../RepeatUntilSuccess.qs | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs index c071ac07d8e4..6021662ebfc4 100644 --- a/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs +++ b/samples/algorithms/repeat-until-success/RepeatUntilSuccess.qs @@ -19,7 +19,7 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { /// /// # Input /// ## inputBasis - /// Pauli basis to prepare input qubit in + /// Pauli basis in which to prepare input qubit /// ## inputValue /// Boolean value for input qubit (true maps to One, false maps to Zero) /// ## limit @@ -37,7 +37,7 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { operation CreateQubitsAndApplyRzArcTan2( inputValue : Bool, inputBasis : Pauli, - limit: Int + limit : Int ) : (Bool, Result, Int) { using ((auxiliary, resource, target) = (Qubit(), Qubit(), Qubit())) { @@ -60,7 +60,7 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { /// /// # Input /// ## inputBasis - /// Pauli basis to prepare input qubit in + /// Pauli basis in which to prepare input qubit /// ## inputValue /// Boolean value for input qubit (true maps to One, false maps to Zero) /// ## limit @@ -76,12 +76,12 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { /// Tuple of (success, numIter) where success = false if the number of /// iterations (numIter) exceeds the input operation ApplyRzArcTan2( - inputBasis: Pauli, - inputValue: Bool, - limit: Int, - auxiliary: Qubit, - resource: Qubit, - target: Qubit + inputBasis : Pauli, + inputValue : Bool, + limit : Int, + auxiliary : Qubit, + resource : Qubit, + target : Qubit ) : (Bool, Int) { // Initialize results to One by default. @@ -127,7 +127,7 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { /// /// # Input /// ## inputBasis - /// Pauli basis to prepare input qubit in + /// Pauli basis in which to prepare input qubit /// ## inputValue /// Boolean value for input qubit (true maps to One, false maps to Zero) /// ## limit @@ -139,13 +139,13 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { /// ## target /// Target qubit operation InitializeQubits( - inputBasis: Pauli, - inputValue: Bool, - auxiliary: Qubit, - resource: Qubit, - target: Qubit + inputBasis : Pauli, + inputValue : Bool, + auxiliary : Qubit, + resource : Qubit, + target : Qubit ) - : Unit { + : Unit { // Prepare auxiliary and resource qubits in |+⟩ state H(auxiliary); H(resource); @@ -167,10 +167,10 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { /// ## resource /// Resource qubit operation ApplyAndMeasurePart1( - auxiliary: Qubit, - resource: Qubit + auxiliary : Qubit, + resource : Qubit ) - : Result { + : Result { within { T(auxiliary); } apply { @@ -189,7 +189,7 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { /// Resource qubit /// ## target /// Target qubit - operation ApplyAndMeasurePart2(resource: Qubit, target: Qubit) : Result { + operation ApplyAndMeasurePart2(resource : Qubit, target : Qubit) : Result { T(target); Z(target); CNOT(target, resource); @@ -205,15 +205,15 @@ namespace Microsoft.Quantum.Samples.RepeatUntilSuccess { /// ## target /// Target qubit /// ## inputBasis - /// Pauli basis to prepare input qubit in + /// Pauli basis in which to prepare input qubit /// ## inputValue /// Boolean value for input qubit (true maps to One, false maps to Zero) operation AssertQubitIsInState( - target: Qubit, - inputBasis: Pauli, - inputValue: Bool + target : Qubit, + inputBasis : Pauli, + inputValue : Bool ) - : Unit { + : Unit { AssertMeasurement( [inputBasis], [target], inputValue ? One | Zero, $"Qubit is not in {inputValue ? One | Zero} state for given input basis."