From d40cb5b2b40d9a99cb6fc12c15459392b653f55a Mon Sep 17 00:00:00 2001 From: Monica VanDieren <150082832+mmvandieren@users.noreply.github.com> Date: Tue, 17 Dec 2024 07:30:13 -0800 Subject: [PATCH] copy edits and removal of error message in Deutsch's algorithm (#2445) * copy edits and removal of error message in Deutsch's algorithm * Update docs/sphinx/applications/python/deutschs_algorithm.ipynb Co-authored-by: Eric Schweitz Signed-off-by: Monica VanDieren <150082832+mmvandieren@users.noreply.github.com> * caught a spelling error * copy edit to deutschs_algorithm.ipynb and sign-off added DCO Remediation Commit for Monica VanDieren <150082832+mmvandieren@users.noreply.github.com> I, Monica VanDieren <150082832+mmvandieren@users.noreply.github.com>, hereby add my Signed-off-by to this commit: ab2cb59ee0daee5c17aea6a80df3b8b5d468a14c I, Monica VanDieren <150082832+mmvandieren@users.noreply.github.com>, hereby add my Signed-off-by to this commit: c2d03110bed58bc711bde948731340d9bfa25f74 Signed-off-by: Monica VanDieren <150082832+mmvandieren@users.noreply.github.com> --------- Signed-off-by: Monica VanDieren <150082832+mmvandieren@users.noreply.github.com> Co-authored-by: Eric Schweitz Co-authored-by: Bettina Heim --- .../python/deutschs_algorithm.ipynb | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/docs/sphinx/applications/python/deutschs_algorithm.ipynb b/docs/sphinx/applications/python/deutschs_algorithm.ipynb index feaacacd9d..b1e281a0af 100644 --- a/docs/sphinx/applications/python/deutschs_algorithm.ipynb +++ b/docs/sphinx/applications/python/deutschs_algorithm.ipynb @@ -13,17 +13,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We have a function which takes in a bit and outputs a bit. This can be represented as $f: \\{0,1\\} \\longrightarrow \\{0,1\\}$. \n", + "Deutsch's Algorithm is a concise demonstration of the differences in computational complexity between classical and quantum algorithms for certain problems. For Desutch's algorithm, we begin with a function which takes in a bit and outputs a bit. This can be represented as $f: \\{0,1\\} \\longrightarrow \\{0,1\\}$. \n", + "The function $f$ has the property that it either constant or balanced. The goal of Deutsch's Algorithm is to determine whether our given function is constant or whether it is balanced. \n", "\n", - "The function $f$ has a property; either it is constant or balanced. \n", + "A constant function is \"A balanced function is a function such that the outputs are the same regardless of the inputs, i.e., if $f(0) = 0$ then $f(1) = 1$ or if $f(0) = 1$ then $f(1) = 0$.\n\", the outputs are the same regardless of the inputs, i.e., in the case of $f: \\{0,1\\} \\longrightarrow \\{0,1\\}$, there are are two ways in which this can occur: $f(0) = f(1) = 0$ or $f(0) = f(1) = 1$.\n", "\n", - "If constant, the outputs are the same regardless of the inputs, i.e., $f(0) = f(1) = 0$ or $f(0) = f(1) = 1$.\n", - "\n", - "If balanced, the ouputs are balanced across their possibilities, i.e, if $f(0) = 0$ then $f(1) = 1$ or if $f(0) = 1$ then $f(1) = 0$.\n", - "\n", - "The question we would like to answer is if the function is constant or balanced. \n", + "A balanced function is defined such that the ouputs are balanced across their possibilities, i.e., if $f(0) = 0$ then $f(1) = 1$ or if $f(0) = 1$ then $f(1) = 0$.\n", " \n", - "Classically, if we are given a function $f$, we can solve to find its property via the code below: \n" + "Classically, if we are given a function $f: \\{0,1\\} \\longrightarrow \\{0,1\\}$, we can determine if it is constant or balanced by evaluating the function at $0$ and at $1$. This is carried out in the code below: \n" ] }, { @@ -96,11 +93,11 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "If you step through the `if` statements above, one can see that we require 2 calls to the function to determine its property. That is, we have to query $f$ twice.\n", + "If you step through the `if` statements above, you may notice that we require 2 calls to the function to determine its property. That is, we have to query $f$ twice.\n", "\n", - "The claim is that Deutsch's algorithm can solve for this property with 1 function evalulation, demonstrating quantum advantage. \n", + "The claim is that Deutsch's Algorithm can determine if a given function is constant or balanced with just 1 function evalulation, demonstrating quantum advantage. \n", "\n", - "Below we first go through the math and then the implementation in CUDA Quantum. \n", + "Below we first outline Deutsch's Algorithm and work through the math to verify that it does as promised. Then, we provide the implementation in CUDA-Q. \n", "\n" ] }, @@ -130,7 +127,7 @@ "\n", "\n", "\n", - "Suppose we have $f(x): \\{0,1\\} \\longrightarrow \\{0,1\\}$. We can compute this function on a quantum computer using oracles which we treat as black box functions that yield the output with an appropriate sequence of logic gates. \n", + "Suppose we have $f(x): \\{0,1\\} \\longrightarrow \\{0,1\\}$. We can compute this function on a quantum computer using oracles which we treat as black box functions that yield the output with an appropriate sequence of logical gates. \n", "\n", "Above you see an oracle represented as $U_f$ which allows us to transform the state $\\ket{x}\\ket{y}$ into: \n", "\n", @@ -140,7 +137,7 @@ "\\end{aligned}\n", "$$\n", "\n", - "If $y = 0$, then $U_f\\ket{x}\\ket{y} = U_f\\ket{x}\\ket{0} = \\ket{x}\\ket{0 \\oplus f(x)} = \\ket{x}\\ket{f(x)}$ since $f(x)$ can either be $0/1$ and $0 \\oplus 0 = 0$ and $0 \\oplus 1 = 1$.\n", + "If $y = 0$, then $U_f\\ket{x}\\ket{y} = U_f\\ket{x}\\ket{0} = \\ket{x}\\ket{0 \\oplus f(x)} = \\ket{x}\\ket{f(x)}$, since $f(x)$ can either be $0$ or $1$ and $0 \\oplus 0 = 0$ and $0 \\oplus 1 = 1$.\n", "\n", "This is remarkable because by setting $\\ket{y} = \\ket{0}$, we can extract the value of $f(x)$ by measuring the value of the second qubit. \n", " \n", @@ -213,7 +210,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Deutschs' Algorithm: \n", + "## Deutsch's Algorithm: \n", "\n", "Our aim is to find out if $f: \\{0,1\\} \\longrightarrow \\{0,1\\}$ is a constant or a balanced function? If constant, $f(0) = f(1)$, and if balanced, $f(0) \\neq f(1)$.\n", "\n", @@ -296,18 +293,9 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/usr/local/lib/python3.10/dist-packages/qutip/__init__.py:66: UserWarning: The new version of Cython, (>= 3.0.0) is not supported.\n", - " warnings.warn(\n" - ] - } - ], + "outputs": [], "source": [ "# Import the CUDA-Q package and set the target to run on NVIDIA GPUs.\n", "\n", @@ -391,6 +379,17 @@ "elif np.array(result)[0] == '1':\n", " print('f(x) is a balanced function')" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This algorithm can be generalized to determine if a $n$-bit function $f:{0,1}^n\\longrightarrow {0,1}$ is constant or a balanced with only $\\frac{n}{2}$ function evaluations, for $n$ even. A function if balanced if half of the inputs map to $0$ and half map to $1$. \n", + "\n", + "Here we must assume that the function that we are given is either constant or balanced since there are $n$-bit functions that are neither constant, nor balanced. For instance the $2$-bit function $f(b_0,b_1) = \\max(b_0,b_1)$ is neither balanced, nor constant.\n", + "\n", + "A hint on how you might approach this problem is to first solve the problem for $n=2$ and see if you can then use that approach to handle $n$-bit functions for larger values of $n$." + ] } ], "metadata": {