From ab2cb59ee0daee5c17aea6a80df3b8b5d468a14c Mon Sep 17 00:00:00 2001 From: Monica VanDieren <150082832+mmvandieren@users.noreply.github.com> Date: Tue, 3 Dec 2024 12:36:50 -0800 Subject: [PATCH 1/5] copy edits and removal of error message in Deutsch's algorithm --- .../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..fefa78bfda 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 consise 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 one in which 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 one in which 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": { From 493e2bb79774abad6f3cbbf3b282d8a5f0d912b3 Mon Sep 17 00:00:00 2001 From: Monica VanDieren <150082832+mmvandieren@users.noreply.github.com> Date: Mon, 9 Dec 2024 12:07:59 -0500 Subject: [PATCH 2/5] Update docs/sphinx/applications/python/deutschs_algorithm.ipynb Co-authored-by: Eric Schweitz Signed-off-by: Monica VanDieren <150082832+mmvandieren@users.noreply.github.com> --- docs/sphinx/applications/python/deutschs_algorithm.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sphinx/applications/python/deutschs_algorithm.ipynb b/docs/sphinx/applications/python/deutschs_algorithm.ipynb index fefa78bfda..d3463b5ce0 100644 --- a/docs/sphinx/applications/python/deutschs_algorithm.ipynb +++ b/docs/sphinx/applications/python/deutschs_algorithm.ipynb @@ -18,7 +18,7 @@ "\n", "A constant function is one in which 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", - "A balanced function is one in which 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", + "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: \\{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" ] From c2d03110bed58bc711bde948731340d9bfa25f74 Mon Sep 17 00:00:00 2001 From: Monica VanDieren <150082832+mmvandieren@users.noreply.github.com> Date: Mon, 9 Dec 2024 16:47:25 -0500 Subject: [PATCH 3/5] caught a spelling error --- docs/sphinx/applications/python/deutschs_algorithm.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sphinx/applications/python/deutschs_algorithm.ipynb b/docs/sphinx/applications/python/deutschs_algorithm.ipynb index d3463b5ce0..2dfe8936e9 100644 --- a/docs/sphinx/applications/python/deutschs_algorithm.ipynb +++ b/docs/sphinx/applications/python/deutschs_algorithm.ipynb @@ -13,7 +13,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Deutsch's Algorithm is a consise 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", + "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", "A constant function is one in which 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", From 0404dc423ba6c82c52ffab0fbc908b229ed666bb Mon Sep 17 00:00:00 2001 From: Monica VanDieren <150082832+mmvandieren@users.noreply.github.com> Date: Wed, 11 Dec 2024 09:37:42 -0500 Subject: [PATCH 4/5] 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> --- docs/sphinx/applications/python/deutschs_algorithm.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/sphinx/applications/python/deutschs_algorithm.ipynb b/docs/sphinx/applications/python/deutschs_algorithm.ipynb index 2dfe8936e9..8428a9d5e9 100644 --- a/docs/sphinx/applications/python/deutschs_algorithm.ipynb +++ b/docs/sphinx/applications/python/deutschs_algorithm.ipynb @@ -16,9 +16,9 @@ "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", - "A constant function is one in which 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", + "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", - "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", + "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: \\{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" ] From 0dd444d1451af32e0dcc27ba72ad9bfd6b07f618 Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Tue, 17 Dec 2024 13:23:07 +0100 Subject: [PATCH 5/5] fixing quotes Signed-off-by: Bettina Heim --- docs/sphinx/applications/python/deutschs_algorithm.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sphinx/applications/python/deutschs_algorithm.ipynb b/docs/sphinx/applications/python/deutschs_algorithm.ipynb index 8428a9d5e9..b1e281a0af 100644 --- a/docs/sphinx/applications/python/deutschs_algorithm.ipynb +++ b/docs/sphinx/applications/python/deutschs_algorithm.ipynb @@ -16,7 +16,7 @@ "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", - "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", + "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", "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",