BasicGates: Add new task for adding global phase -1 (#177)
This commit is contained in:
Родитель
47dfa99dc7
Коммит
8621795b0d
|
@ -107,7 +107,7 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%kata T11_StateFlip_Test \n",
|
||||
"%kata T101_StateFlip_Test \n",
|
||||
"\n",
|
||||
"operation StateFlip (q : Qubit) : Unit is Adj+Ctl {\n",
|
||||
" // The Pauli X gate will change the |0⟩ state to the |1⟩ state and vice versa.\n",
|
||||
|
@ -142,7 +142,7 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%kata T12_BasisChange_Test \n",
|
||||
"%kata T102_BasisChange_Test \n",
|
||||
"\n",
|
||||
"operation BasisChange (q : Qubit) : Unit is Adj+Ctl {\n",
|
||||
" // ...\n",
|
||||
|
@ -166,7 +166,7 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%kata T13_SignFlip_Test \n",
|
||||
"%kata T103_SignFlip_Test \n",
|
||||
"\n",
|
||||
"operation SignFlip (q : Qubit) : Unit is Adj+Ctl {\n",
|
||||
" // ...\n",
|
||||
|
@ -199,7 +199,7 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%kata T14_AmplitudeChange_Test\n",
|
||||
"%kata T104_AmplitudeChange_Test\n",
|
||||
"\n",
|
||||
"operation AmplitudeChange (alpha : Double, q : Qubit) : Unit is Adj+Ctl {\n",
|
||||
" // ...\n",
|
||||
|
@ -223,7 +223,7 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%kata T15_PhaseFlip_Test\n",
|
||||
"%kata T105_PhaseFlip_Test\n",
|
||||
"\n",
|
||||
"operation PhaseFlip (q : Qubit) : Unit is Adj+Ctl {\n",
|
||||
" // ...\n",
|
||||
|
@ -253,7 +253,7 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%kata T16_PhaseChange_Test\n",
|
||||
"%kata T106_PhaseChange_Test\n",
|
||||
"\n",
|
||||
"operation PhaseChange (alpha : Double, q : Qubit) : Unit is Adj+Ctl {\n",
|
||||
" // ...\n",
|
||||
|
@ -264,7 +264,34 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Task 1.7. Bell state change - 1\n",
|
||||
"### Task 1.7. Global phase change\n",
|
||||
"**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",
|
||||
"> Note: 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."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%kata T107_GlobalPhaseChange_Test\n",
|
||||
"\n",
|
||||
"operation GlobalPhaseChange (q : Qubit) : Unit is Adj+Ctl {\n",
|
||||
" // ...\n",
|
||||
"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Task 1.8. Bell state change - 1\n",
|
||||
"\n",
|
||||
"**Input:** Two entangled qubits in Bell state $|\\Phi^{+}\\rangle = \\frac{1}{\\sqrt{2}} \\big(|00\\rangle + |11\\rangle\\big)$.\n",
|
||||
"\n",
|
||||
|
@ -277,7 +304,7 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%kata T17_BellStateChange1_Test\n",
|
||||
"%kata T108_BellStateChange1_Test\n",
|
||||
"\n",
|
||||
"operation BellStateChange1 (qs : Qubit[]) : Unit is Adj+Ctl {\n",
|
||||
" // ...\n",
|
||||
|
@ -288,7 +315,7 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Task 1.8. Bell state change - 2\n",
|
||||
"### Task 1.9. Bell state change - 2\n",
|
||||
"\n",
|
||||
"**Input:** Two entangled qubits in Bell state $|\\Phi^{+}\\rangle = \\frac{1}{\\sqrt{2}} \\big(|00\\rangle + |11\\rangle\\big)$.\n",
|
||||
"\n",
|
||||
|
@ -301,7 +328,7 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%kata T18_BellStateChange2_Test\n",
|
||||
"%kata T109_BellStateChange2_Test\n",
|
||||
"\n",
|
||||
"operation BellStateChange2 (qs : Qubit[]) : Unit is Adj+Ctl {\n",
|
||||
" // ...\n",
|
||||
|
@ -312,7 +339,7 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Task 1.9. Bell state change - 3\n",
|
||||
"### Task 1.10. Bell state change - 3\n",
|
||||
"\n",
|
||||
"**Input:** Two entangled qubits in Bell state $|\\Phi^{+}\\rangle = \\frac{1}{\\sqrt{2}} \\big(|00\\rangle + |11\\rangle\\big)$.\n",
|
||||
"\n",
|
||||
|
@ -325,7 +352,7 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%kata T19_BellStateChange3_Test\n",
|
||||
"%kata T110_BellStateChange3_Test\n",
|
||||
"\n",
|
||||
"operation BellStateChange3 (qs : Qubit[]) : Unit is Adj+Ctl {\n",
|
||||
" // ...\n",
|
||||
|
@ -367,7 +394,7 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%kata T21_TwoQubitGate1_Test\n",
|
||||
"%kata T201_TwoQubitGate1_Test\n",
|
||||
"\n",
|
||||
"operation TwoQubitGate1 (qs : Qubit[]) : Unit is Adj {\n",
|
||||
" // ...\n",
|
||||
|
@ -395,7 +422,7 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%kata T22_TwoQubitGate2_Test\n",
|
||||
"%kata T202_TwoQubitGate2_Test\n",
|
||||
"\n",
|
||||
"operation TwoQubitGate2 (qs : Qubit[]) : Unit is Adj {\n",
|
||||
" // ...\n",
|
||||
|
@ -422,7 +449,7 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%kata T23_TwoQubitGate3_Test\n",
|
||||
"%kata T203_TwoQubitGate3_Test\n",
|
||||
"\n",
|
||||
"operation TwoQubitGate3 (qs : Qubit[]) : Unit is Adj {\n",
|
||||
" // ...\n",
|
||||
|
@ -447,7 +474,7 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%kata T24_ToffoliGate_Test\n",
|
||||
"%kata T204_ToffoliGate_Test\n",
|
||||
"\n",
|
||||
"operation ToffoliGate (qs : Qubit[]) : Unit is Adj {\n",
|
||||
" // ...\n",
|
||||
|
@ -472,7 +499,7 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%kata T25_FredkinGate_Test\n",
|
||||
"%kata T205_FredkinGate_Test\n",
|
||||
"\n",
|
||||
"operation FredkinGate (qs : Qubit[]) : Unit is Adj {\n",
|
||||
" // ...\n",
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
namespace Quantum.Kata.BasicGates {
|
||||
open Microsoft.Quantum.Intrinsic;
|
||||
open Microsoft.Quantum.Math;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
@ -81,8 +82,14 @@ namespace Quantum.Kata.BasicGates {
|
|||
R1(alpha, q);
|
||||
}
|
||||
|
||||
// Task 1.7. Global Phase Change
|
||||
// Input: A qubit in state β|0⟩ + γ|1⟩.
|
||||
// Goal: Change the state of the qubit to - β|0⟩ - γ|1⟩.
|
||||
operation GlobalPhaseChange_Reference (q: Qubit) : Unit is Adj+Ctl {
|
||||
R(PauliI, 2.0 * PI(), q);
|
||||
}
|
||||
|
||||
// Task 1.7. Bell state change - 1
|
||||
// Task 1.8. Bell state change - 1
|
||||
// Input: Two entangled qubits in Bell state |Φ⁺⟩ = (|00⟩ + |11⟩) / sqrt(2).
|
||||
// Goal: Change the two-qubit state to |Φ⁻⟩ = (|00⟩ - |11⟩) / sqrt(2).
|
||||
operation BellStateChange1_Reference (qs : Qubit[]) : Unit is Adj+Ctl {
|
||||
|
@ -91,7 +98,7 @@ namespace Quantum.Kata.BasicGates {
|
|||
}
|
||||
|
||||
|
||||
// Task 1.8. Bell state change - 2
|
||||
// Task 1.9. Bell state change - 2
|
||||
// Input: Two entangled qubits in Bell state |Φ⁺⟩ = (|00⟩ + |11⟩) / sqrt(2).
|
||||
// Goal: Change the two-qubit state to |Ψ⁺⟩ = (|01⟩ + |10⟩) / sqrt(2).
|
||||
operation BellStateChange2_Reference (qs : Qubit[]) : Unit is Adj+Ctl {
|
||||
|
@ -100,7 +107,7 @@ namespace Quantum.Kata.BasicGates {
|
|||
}
|
||||
|
||||
|
||||
// Task 1.9. Bell state change - 3
|
||||
// Task 1.10. Bell state change - 3
|
||||
// Input: Two entangled qubits in Bell state |Φ⁺⟩ = (|00⟩ + |11⟩) / sqrt(2).
|
||||
// Goal: Change the two-qubit state to |Ψ⁻⟩ = (|01⟩ - |10⟩) / sqrt(2).
|
||||
operation BellStateChange3_Reference (qs : Qubit[]) : Unit is Adj+Ctl {
|
||||
|
|
|
@ -111,8 +111,22 @@ namespace Quantum.Kata.BasicGates {
|
|||
// ...
|
||||
}
|
||||
|
||||
// Task 1.7. Global phase change
|
||||
// Input: A qubit in state β|0⟩ + γ|1⟩.
|
||||
// Goal: Change the state of the qubit to - β|0⟩ - γ|1⟩.
|
||||
//
|
||||
// Note: 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.
|
||||
// However, you can use a controlled version of this operation
|
||||
// to observe the global phase it introduces. This is used
|
||||
// in later katas as part of more complicated tasks.
|
||||
operation GlobalPhaseChange (q: Qubit) : Unit is Adj+Ctl {
|
||||
// ...
|
||||
}
|
||||
|
||||
// Task 1.7. Bell state change - 1
|
||||
|
||||
// Task 1.8. Bell state change - 1
|
||||
// Input: Two entangled qubits in Bell state |Φ⁺⟩ = (|00⟩ + |11⟩) / sqrt(2).
|
||||
// Goal: Change the two-qubit state to |Φ⁻⟩ = (|00⟩ - |11⟩) / sqrt(2).
|
||||
operation BellStateChange1 (qs : Qubit[]) : Unit is Adj+Ctl {
|
||||
|
@ -120,7 +134,7 @@ namespace Quantum.Kata.BasicGates {
|
|||
}
|
||||
|
||||
|
||||
// Task 1.8. Bell state change - 2
|
||||
// Task 1.9. Bell state change - 2
|
||||
// Input: Two entangled qubits in Bell state |Φ⁺⟩ = (|00⟩ + |11⟩) / sqrt(2).
|
||||
// Goal: Change the two-qubit state to |Ψ⁺⟩ = (|01⟩ + |10⟩) / sqrt(2).
|
||||
operation BellStateChange2 (qs : Qubit[]) : Unit is Adj+Ctl {
|
||||
|
@ -128,7 +142,7 @@ namespace Quantum.Kata.BasicGates {
|
|||
}
|
||||
|
||||
|
||||
// Task 1.9. Bell state change - 3
|
||||
// Task 1.10. Bell state change - 3
|
||||
// Input: Two entangled qubits in Bell state |Φ⁺⟩ = (|00⟩ + |11⟩) / sqrt(2).
|
||||
// Goal: Change the two-qubit state to |Ψ⁻⟩ = (|01⟩ - |10⟩) / sqrt(2).
|
||||
operation BellStateChange3 (qs : Qubit[]) : Unit is Adj+Ctl {
|
||||
|
|
|
@ -35,25 +35,25 @@ namespace Quantum.Kata.BasicGates {
|
|||
|
||||
|
||||
// ------------------------------------------------------
|
||||
operation T11_StateFlip_Test () : Unit {
|
||||
operation T101_StateFlip_Test () : Unit {
|
||||
AssertOperationsEqualReferenced(2, ArrayWrapperOperation(StateFlip, _), ArrayWrapperOperation(StateFlip_Reference, _));
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
operation T12_BasisChange_Test () : Unit {
|
||||
operation T102_BasisChange_Test () : Unit {
|
||||
AssertOperationsEqualReferenced(2, ArrayWrapperOperation(BasisChange, _), ArrayWrapperOperation(BasisChange_Reference, _));
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
operation T13_SignFlip_Test () : Unit {
|
||||
operation T103_SignFlip_Test () : Unit {
|
||||
AssertOperationsEqualReferenced(2, ArrayWrapperOperation(SignFlip, _), ArrayWrapperOperation(SignFlip_Reference, _));
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
operation T14_AmplitudeChange_Test () : Unit {
|
||||
operation T104_AmplitudeChange_Test () : Unit {
|
||||
for (i in 0 .. 36) {
|
||||
let alpha = ((2.0 * PI()) * IntAsDouble(i)) / 36.0;
|
||||
AssertOperationsEqualReferenced(2, ArrayWrapperOperation(AmplitudeChange(alpha, _), _), ArrayWrapperOperation(AmplitudeChange_Reference(alpha, _), _));
|
||||
|
@ -62,13 +62,13 @@ namespace Quantum.Kata.BasicGates {
|
|||
|
||||
|
||||
// ------------------------------------------------------
|
||||
operation T15_PhaseFlip_Test () : Unit {
|
||||
operation T105_PhaseFlip_Test () : Unit {
|
||||
AssertOperationsEqualReferenced(2, ArrayWrapperOperation(PhaseFlip, _), ArrayWrapperOperation(PhaseFlip_Reference, _));
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
operation T16_PhaseChange_Test () : Unit {
|
||||
operation T106_PhaseChange_Test () : Unit {
|
||||
for (i in 0 .. 36) {
|
||||
let alpha = ((2.0 * PI()) * IntAsDouble(i)) / 36.0;
|
||||
AssertOperationsEqualReferenced(2, ArrayWrapperOperation(PhaseChange(alpha, _), _), ArrayWrapperOperation(PhaseChange_Reference(alpha, _), _));
|
||||
|
@ -76,6 +76,12 @@ namespace Quantum.Kata.BasicGates {
|
|||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
operation T107_GlobalPhaseChange_Test () : Unit {
|
||||
AssertOperationsEqualReferenced(2, ArrayWrapperOperation(GlobalPhaseChange, _), ArrayWrapperOperation(GlobalPhaseChange_Reference, _));
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
// 0 - |Φ⁺⟩ = (|00⟩ + |11⟩) / sqrt(2)
|
||||
// 1 - |Φ⁻⟩ = (|00⟩ - |11⟩) / sqrt(2)
|
||||
|
@ -119,22 +125,23 @@ namespace Quantum.Kata.BasicGates {
|
|||
AssertAllZero(qs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
operation T17_BellStateChange1_Test () : Unit {
|
||||
operation T108_BellStateChange1_Test () : Unit {
|
||||
VerifyBellStateConversion(BellStateChange1, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
operation T18_BellStateChange2_Test () : Unit {
|
||||
operation T109_BellStateChange2_Test () : Unit {
|
||||
VerifyBellStateConversion(BellStateChange2, 0, 2);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
operation T19_BellStateChange3_Test () : Unit {
|
||||
operation T110_BellStateChange3_Test () : Unit {
|
||||
VerifyBellStateConversion(BellStateChange3, 0, 3);
|
||||
}
|
||||
|
||||
|
@ -147,7 +154,7 @@ namespace Quantum.Kata.BasicGates {
|
|||
|
||||
|
||||
// ------------------------------------------------------
|
||||
operation T21_TwoQubitGate1_Test () : Unit {
|
||||
operation T201_TwoQubitGate1_Test () : Unit {
|
||||
|
||||
// Note that the way the problem is formulated, we can't just compare two unitaries,
|
||||
// we need to create an input state |A⟩ and check that the output state is correct
|
||||
|
@ -180,7 +187,7 @@ namespace Quantum.Kata.BasicGates {
|
|||
|
||||
|
||||
// ------------------------------------------------------
|
||||
operation T22_TwoQubitGate2_Test () : Unit {
|
||||
operation T202_TwoQubitGate2_Test () : Unit {
|
||||
using (qs = Qubit[2]) {
|
||||
// prepare |+⟩ ⊗ |+⟩ state
|
||||
StatePrep_PlusPlus(qs);
|
||||
|
@ -204,20 +211,20 @@ namespace Quantum.Kata.BasicGates {
|
|||
}
|
||||
|
||||
|
||||
operation T23_TwoQubitGate3_Test () : Unit {
|
||||
operation T203_TwoQubitGate3_Test () : Unit {
|
||||
AssertOperationsEqualReferenced(2, SwapWrapper, TwoQubitGate3_Reference);
|
||||
AssertOperationsEqualReferenced(2, TwoQubitGate3, TwoQubitGate3_Reference);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
operation T24_ToffoliGate_Test () : Unit {
|
||||
operation T204_ToffoliGate_Test () : Unit {
|
||||
AssertOperationsEqualReferenced(3, ToffoliGate, ToffoliGate_Reference);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
operation T25_FredkinGate_Test () : Unit {
|
||||
operation T205_FredkinGate_Test () : Unit {
|
||||
AssertOperationsEqualReferenced(3, FredkinGate, FredkinGate_Reference);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче