[Superposition] Add workbook solution for task 2.3 (#409)

This commit is contained in:
Vincent van Wingerden 2020-07-19 07:02:53 +02:00 коммит произвёл GitHub
Родитель f41640064c
Коммит 2ef65e367e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 31 добавлений и 5 удалений

Просмотреть файл

@ -710,7 +710,7 @@
"Looking at the other two gates, $R_x$ gate rotates the qubit state around the X axis and thus takes the qubit state out of the X-Z plane, introducing complex coefficients. $R_z$ gate rotates the qubit state around the Z axis, so it doesn't modify the $|0\\rangle$ state which lies on the Z axis.\n",
"<br/><br/> \n",
"In case you are surprised to see the $|0\\rangle$ and $|1\\rangle$ vectors 180 degrees apart from each other, the Bloch sphere represents orthogonal vectors as opposite points on the sphere. \n",
"You can learn more about the bloch sphere from <a href=\"http://www.vcpc.univie.ac.at/~ian/hotlist/qc/talks/bloch-sphere.pdf\">this presentation</a></td>\n",
"You can learn more about the Bloch sphere from <a href=\"http://www.vcpc.univie.ac.at/~ian/hotlist/qc/talks/bloch-sphere.pdf\">this presentation</a>.</td>\n",
" <td style=\"text-align:center; font-size: 14px; background-color:white; border:0\"><img src=\"./img/blochsphere.png\"/></td> \n",
" </tr> \n",
"</table>"
@ -841,7 +841,7 @@
"\n",
"> Q# has a built-in [repeat-until-success (RUS) loop](https://docs.microsoft.com/en-us/quantum/user-guide/using-qsharp/control-flow#repeat-until-success-loop), which comes in handy in this case. \n",
"> * We will describe the main operations (applying **H** and **CCNOT** gates and the measurement) in the `repeat` part of the loop, which specifies its body. \n",
"> * `until` section specifies the condition which will break the loop. In this case the result of the measurement needs to be `Zero` to indicate our succes. \n",
"> * `until` section specifies the condition which will break the loop. In this case the result of the measurement needs to be `Zero` to indicate our success. \n",
"> * Finally, the `fixup` section allows us to clean up the results of the loop body execution before trying again if the success criteria is not met. In this case we reset the first two qubits back to the $|00\\rangle$ state.\n",
"\n",
"This technique is sometimes called post-selection."
@ -881,7 +881,33 @@
"source": [
"Alternatively, this state can be prepared using arbitrary rotations (the **Ry** gate). \n",
"\n",
"*The detailed explanation of this approach is coming soon, meanwhile you can follow [Niel's answer at QuantumComputing Stack Exchange](https://quantumcomputing.stackexchange.com/a/2313/).*"
"To start, we will try to find a decomposition of the target state that makes it easier to see how to prepare the state. \n",
"Knowing that $|+\\rangle = \\frac{1}{\\sqrt{2}}\\big(|0\\rangle+|1\\rangle\\big)$, we can represent the state as follows:\n",
"\n",
"$$ \\frac{1}{\\sqrt{3}} \\big(|00\\rangle + |01\\rangle + |10\\rangle\\big) = \\frac{\\sqrt{2}}{\\sqrt{3}}|0\\rangle \\otimes |+\\rangle + \\frac{1}{\\sqrt{3}}|1\\rangle \\otimes |0\\rangle $$ \n",
"\n",
"To prepare this state, we first want to prepare the first qubit in the state $ \\frac{\\sqrt{2}}{\\sqrt{3}}|0\\rangle + \\frac{1}{\\sqrt{3}}|1\\rangle $, while leaving the second qubit unchanged. \n",
"To do this we can use the [$Ry$](../tutorials/SingleQubitGates/SingleQubitGates.ipynb#Rotation-Gates) gate which will perform the following transformation:\n",
"$$ Ry|0\\rangle = \\cos\\frac{\\theta}{2}|0\\rangle + \\sin\\frac{\\theta}{2}|1\\rangle $$\n",
"We need to find a value of $\\theta$ which satisfies both: \n",
"$$\\cos\\frac{\\theta}{2} = \\frac{\\sqrt{2}}{\\sqrt{3}} \\text{ and } \\sin\\frac{\\theta}{2} = \\frac{1}{\\sqrt{3}}$$\n",
"\n",
"Solving the last equation for $\\theta$ gives us $\\frac{\\theta}{2} = \\arcsin\\frac{1}{\\sqrt{3}}$, or $\\theta = 2 \\arcsin\\frac{1}{\\sqrt{3}}$.\n",
"\n",
"When we apply this to our first qubit, we will get our desired intermediary state:\n",
"$$ \\big(Ry(2 \\arcsin\\frac{1}{\\sqrt{3}})|0\\rangle \\big) \\otimes |0\\rangle = \n",
"\\big(\\frac{\\sqrt{2}}{\\sqrt{3}}|0\\rangle + \\frac{1}{\\sqrt{3}}|1\\rangle \\big) \\otimes |0\\rangle = \n",
"\\frac{\\sqrt{2}}{\\sqrt{3}}|0\\rangle \\otimes |0\\rangle + \\frac{1}{\\sqrt{3}}|1\\rangle \\otimes |0\\rangle$$\n",
"\n",
"Now, the second term of this state already matches our final goal, so we need to adjust the first term: \n",
"prepare the $|+\\rangle$ state on the second qubit only if the first qubit is in the $|0\\rangle$ state. \n",
"To do this, we apply a conditional $H$ gate to the second qubit, if the first qubit is in the $|0\\rangle$ state, this will give our desired state:\n",
"$$ \\frac{\\sqrt{2}}{\\sqrt{3}}|0\\rangle \\otimes |+\\rangle + \\frac{1}{\\sqrt{3}}|1\\rangle \\otimes |0\\rangle$$\n",
"\n",
"> In Q# we can apply a conditional gate with arbitrary controls using the [`ControlledOnInt` function](https://docs.microsoft.com/qsharp/api/qsharp/microsoft.quantum.canon.controlledonint). \n",
"> In this case we want the **H** gate to be applied if the control qubit is in the $|0\\rangle$ state, so we will use `ControlledOnInt(0, H)` gate.\n",
"\n",
"*This solution is based on [Niel's answer at QuantumComputing Stack Exchange](https://quantumcomputing.stackexchange.com/a/2313/).*"
]
},
{
@ -1168,7 +1194,7 @@
" Ry(2.0 * ArcCos(Sqrt(10.0 / 12.0)), qs[0]);\n",
" (ControlledOnInt(0, Ry))([qs[0]], (2.0 * ArcCos(Sqrt(9.0 / 10.0)), qs[1]));\n",
" (ControlledOnInt(1, Ry))([qs[0]], (2.0 * PI()/4.0, qs[1]));\n",
" // In this special case the second Controlled Ry is eqivalent to a Controlled H:\n",
" // In this special case the second Controlled Ry is equivalent to a Controlled H:\n",
" // Controlled H([qs[0]], qs[1]);\n",
"}"
]
@ -1532,7 +1558,7 @@
"file_extension": ".qs",
"mimetype": "text/x-qsharp",
"name": "qsharp",
"version": "0.10"
"version": "0.12"
}
},
"nbformat": 4,