Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copy edits and removal of error message in Deutsch's algorithm #2445

Merged
merged 15 commits into from
Dec 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 24 additions & 25 deletions docs/sphinx/applications/python/deutschs_algorithm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
mmvandieren marked this conversation as resolved.
Show resolved Hide resolved
" \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"
]
},
{
Expand Down Expand Up @@ -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"
]
},
Expand Down Expand Up @@ -130,7 +127,7 @@
"\n",
"<img src=\"images/oracle.png\" width=\"300\" height=\"150\">\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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down