Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

task 1.7 global phase change was added #177

Merged
merged 15 commits into from
Oct 5, 2019
Prev Previous commit
Next Next commit
Do some minor cleanup
  • Loading branch information
tcNickolas committed Oct 4, 2019
commit 8872146830eb5161bf28ceb30c6a2246e2ac2f96
40 changes: 21 additions & 19 deletions BasicGates/BasicGates.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Task 101. State flip: $|0\\rangle$ to $|1\\rangle$ and vice versa\n",
"### Task 1.1. State flip: $|0\\rangle$ to $|1\\rangle$ and vice versa\n",
"\n",
"**Input:** A qubit in state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.\n",
"\n",
Expand Down Expand Up @@ -122,7 +122,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Task 102. Basis change: $|0\\rangle$ to $|+\\rangle$ and $|1\\rangle$ to $|-\\rangle$ (and vice versa)\n",
"### Task 1.2. Basis change: $|0\\rangle$ to $|+\\rangle$ and $|1\\rangle$ to $|-\\rangle$ (and vice versa)\n",
"\n",
"**Input**: A qubit in state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.\n",
"\n",
Expand Down Expand Up @@ -153,7 +153,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Task 103. Sign flip: $|+\\rangle$ to $|-\\rangle$ and vice versa.\n",
"### Task 1.3. Sign flip: $|+\\rangle$ to $|-\\rangle$ and vice versa.\n",
"\n",
"**Input**: A qubit in state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.\n",
"\n",
Expand All @@ -177,7 +177,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Task 104. Amplitude change: $|0\\rangle$ to $\\cos{α} |0\\rangle + \\sin{α} |1\\rangle$.\n",
"### Task 1.4. Amplitude change: $|0\\rangle$ to $\\cos{α} |0\\rangle + \\sin{α} |1\\rangle$.\n",
"\n",
"**Inputs:**\n",
"\n",
Expand Down Expand Up @@ -210,7 +210,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Task 105. Phase flip\n",
"### Task 1.5. Phase flip\n",
"\n",
"**Input:** A qubit in state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.\n",
"\n",
Expand All @@ -234,7 +234,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Task 106. Phase change\n",
"### Task 1.6. Phase change\n",
"\n",
"**Inputs:**\n",
"\n",
Expand Down Expand Up @@ -264,12 +264,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Task 107. Global Phase Change",
"### Task 1.7. Global phase change\n",
"**Input:** A qubit in state $|\\psi\\rangle = \\beta |0\\rangle + \\gamma |1\\rangle$.\n",
"\n",
"**Input:** \n",
"1) A qubit in state $|\\psi\\rangle = \\beta |0\\rangle + \\gamma |1\\rangle$.\n",
"**Goal**: Change the state of the qubit to $- \\beta |0\\rangle - \\gamma |1\\rangle$.\n",
"\n",
"**Goal**: Change the state of the qubit to - $|\\psi\\rangle$.\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."
]
},
{
Expand All @@ -280,7 +282,7 @@
"source": [
"%kata T107_GlobalPhaseChange_Test\n",
"\n",
"operation GlobalPhaseChange (q : Qubit[]) : Unit is Adj+Ctl {\n",
"operation GlobalPhaseChange (q : Qubit) : Unit is Adj+Ctl {\n",
" // ...\n",
"}"
]
Expand All @@ -289,7 +291,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Task 108. Bell state change - 1\n",
"### 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",
Expand All @@ -313,7 +315,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Task 109. 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",
Expand All @@ -337,7 +339,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Task 110. 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",
Expand Down Expand Up @@ -372,7 +374,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Task 201. Two-qubit gate - 1\n",
"### Task 2.1. Two-qubit gate - 1\n",
"\n",
"**Input:** Two unentangled qubits (stored in an array of length 2).\n",
"The first qubit will be in state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$, the second - in state $|0\\rangle$\n",
Expand Down Expand Up @@ -403,7 +405,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Task 202. Two-qubit gate - 2\n",
"### Task 2.2. Two-qubit gate - 2\n",
"\n",
"**Input:** Two unentangled qubits (stored in an array of length 2) in state $|+\\rangle \\otimes |+\\rangle = \\frac{1}{2} \\big( |00\\rangle + |01\\rangle + |10\\rangle \\color{blue}+ |11\\rangle \\big)$.\n",
"\n",
Expand Down Expand Up @@ -431,7 +433,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Task 203. Two-qubit gate - 3\n",
"### Task 2.3. Two-qubit gate - 3\n",
"\n",
"**Input:** Two unentangled qubits (stored in an array of length 2) in an arbitrary two-qubit state $\\alpha |00\\rangle + \\color{blue}\\beta |01\\rangle + \\color{blue}\\gamma |10\\rangle + \\delta |11\\rangle$.\n",
"\n",
Expand All @@ -458,7 +460,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Task 204. Toffoli gate\n",
"### Task 2.4. Toffoli gate\n",
"\n",
"**Input:** Three qubits (stored in an array of length 3) in an arbitrary three-qubit state \n",
"$\\alpha |000\\rangle + \\beta |001\\rangle + \\gamma |010\\rangle + \\delta |011\\rangle + \\epsilon |100\\rangle + \\zeta|101\\rangle + \\color{blue}\\eta|110\\rangle + \\color{blue}\\theta|111\\rangle$.\n",
Expand All @@ -483,7 +485,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Task 205. Fredkin gate\n",
"### Task 2.5. Fredkin gate\n",
"\n",
"**Input:** Three qubits (stored in an array of length 3) in an arbitrary three-qubit state \n",
"$\\alpha |000\\rangle + \\beta |001\\rangle + \\gamma |010\\rangle + \\delta |011\\rangle + \\epsilon |100\\rangle + \\color{blue}\\zeta|101\\rangle + \\color{blue}\\eta|110\\rangle + \\theta|111\\rangle$.\n",
Expand Down
39 changes: 18 additions & 21 deletions BasicGates/ReferenceImplementation.qs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Quantum.Kata.BasicGates {
// Part I. Single-Qubit Gates
//////////////////////////////////////////////////////////////////

// Task 101. State flip
// Task 1.1. State flip
// Input: A qubit in state |ψ⟩ = α |0⟩ + β |1⟩.
// Goal: Change the state of the qubit to α |1⟩ + β |0⟩.
// Example:
Expand All @@ -28,7 +28,7 @@ namespace Quantum.Kata.BasicGates {
}


// Task 102. Basis change: |0⟩ to |+⟩ and |1⟩ to |-⟩ (and vice versa)
// Task 1.2. Basis change: |0⟩ to |+⟩ and |1⟩ to |-⟩ (and vice versa)
// Input: A qubit in state |ψ⟩ = α |0⟩ + β |1⟩.
// Goal: Change the state of the qubit as follows:
// If the qubit is in state |0⟩, change its state to |+⟩ = (|0⟩ + |1⟩) / sqrt(2).
Expand All @@ -40,15 +40,15 @@ namespace Quantum.Kata.BasicGates {
}


// Task 103. Sign flip: |+⟩ to |-⟩ and vice versa.
// Task 1.3. Sign flip: |+⟩ to |-⟩ and vice versa.
// Inputs: A qubit in state |ψ⟩ = α |0⟩ + β |1⟩.
// Goal: Change the qubit state to α |0⟩ - β |1⟩ (flip the sign of |1⟩ component of the superposition).
operation SignFlip_Reference (q : Qubit) : Unit is Adj+Ctl {
Z(q);
}


// Task 104*. Amplitude change (|0⟩ to cos(alpha)*|0⟩ + sin(alpha)*|1⟩).
// Task 1.4*. Amplitude change (|0⟩ to cos(alpha)*|0⟩ + sin(alpha)*|1⟩).
// Inputs:
// 1) Angle alpha, in radians, represented as Double.
// 2) A qubit in state β|0⟩ + γ|1⟩.
Expand All @@ -61,7 +61,7 @@ namespace Quantum.Kata.BasicGates {
}


// Task 105. Phase flip
// Task 1.5. Phase flip
// Input: A qubit in state |ψ⟩ = α |0⟩ + β |1⟩.
// Goal: Change the qubit state to α |0⟩ + iβ |1⟩ (flip the phase of |1⟩ component of the superposition).
operation PhaseFlip_Reference (q : Qubit) : Unit is Adj+Ctl {
Expand All @@ -70,7 +70,7 @@ namespace Quantum.Kata.BasicGates {
}


// Task 106*. Phase change
// Task 1.6*. Phase change
// Inputs:
// 1) Angle alpha, in radians, represented as Double.
// 2) A qubit in state β|0⟩ + γ|1⟩.
Expand All @@ -82,17 +82,14 @@ namespace Quantum.Kata.BasicGates {
R1(alpha, q);
}

// Task 107. Global Phase Change
// Inputs:
// 1) Pauli operator (μ) represented as Pauli.
// 2) Angle alpha, in radians, represented as Double.
// 3) A qubit in state β|0⟩ + γ|1⟩.
// 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);
operation GlobalPhaseChange_Reference (q: Qubit) : Unit is Adj+Ctl {
R(PauliI, 2.0 * PI(), q);
}

// Task 108. 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 {
Expand All @@ -101,7 +98,7 @@ namespace Quantum.Kata.BasicGates {
}


// Task 109. 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 {
Expand All @@ -110,7 +107,7 @@ namespace Quantum.Kata.BasicGates {
}


// Task 110 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 {
Expand All @@ -124,7 +121,7 @@ namespace Quantum.Kata.BasicGates {
// Part II. Multi-Qubit Gates
//////////////////////////////////////////////////////////////////

// Task 201. Two-qubit gate - 1
// Task 2.1. Two-qubit gate - 1
// Input: Two unentangled qubits (stored in an array of length 2).
// The first qubit will be in state |ψ⟩ = α |0⟩ + β |1⟩, the second - in state |0⟩
// (this can be written as two-qubit state (α|0⟩ + β|1⟩) ⊗ |0⟩).
Expand All @@ -137,7 +134,7 @@ namespace Quantum.Kata.BasicGates {
}


// Task 202. Two-qubit gate - 2
// Task 2.2. Two-qubit gate - 2
// Input: Two qubits (stored in an array of length 2)
// in state |+⟩ ⊗ |+⟩ = (|00⟩ + |01⟩ + |10⟩ + |11⟩) / 2.
// Goal: Change the two-qubit state to (|00⟩ + |01⟩ + |10⟩ - |11⟩) / 2.
Expand All @@ -148,7 +145,7 @@ namespace Quantum.Kata.BasicGates {
// alternatively: CZ(qs[0], qs[1]);
}

// Task 203. Two-qubit gate - 3
// Task 2.3. Two-qubit gate - 3
// Input: Two qubits (stored in an array of length 2) in an arbitrary
// two-qubit state α|00⟩ + β|01⟩ + γ|10⟩ + δ|11⟩.
// Goal: Change the two-qubit state to α|00⟩ + γ|01⟩ + β|10⟩ + δ|11⟩.
Expand All @@ -161,7 +158,7 @@ namespace Quantum.Kata.BasicGates {
}


// Task 204. Toffoli gate
// Task 2.4. Toffoli gate
// Input: Three qubits (stored in an array of length 3) in an arbitrary three-qubit state
// α|000⟩ + β|001⟩ + γ|010⟩ + δ|011⟩ + ε|100⟩ + ζ|101⟩ + η|110⟩ + θ|111⟩.
// Goal: Flip the state of the third qubit if the state of the first two is |11⟩:
Expand All @@ -172,7 +169,7 @@ namespace Quantum.Kata.BasicGates {
// alternatively (Controlled X)(qs[0..1], qs[2]);
}

// Task 205. Fredkin gate
// Task 2.5. Fredkin gate
// Input: Three qubits (stored in an array of length 3) in an arbitrary three-qubit state
// α|000⟩ + β|001⟩ + γ|010⟩ + δ|011⟩ + ε|100⟩ + ζ|101⟩ + η|110⟩ + θ|111⟩.
// Goal: Swap the states of second and third qubit if and only if the state of the first qubit is |1⟩:
Expand Down
Loading