Skip to content

Commit 1a0281f

Browse files
Docs preview for PR #2443.
1 parent 06a9c41 commit 1a0281f

File tree

196 files changed

+7172
-1225
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

196 files changed

+7172
-1225
lines changed

pr-2443/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ============================================================================ #
2-
# Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. #
2+
# Copyright (c) 2022 - 2025 NVIDIA Corporation & Affiliates. #
33
# All rights reserved. #
44
# #
55
# This source code and the accompanying materials are made available under #

pr-2443/_sources/api/default_ops.rst.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ defined by the qudit level that represents the qumode. If it is applied to a qum
650650
where the number of photons is already at the maximum value, the operation has no
651651
effect.
652652

653-
:math:`U|0\rangle → |1\rangle, U|1\rangle → |2\rangle, U|2\rangle → |3\rangle, \cdots, U|d\rangle → |d\rangle`
653+
:math:`C|0\rangle → |1\rangle, C|1\rangle → |2\rangle, C|2\rangle → |3\rangle, \cdots, C|d\rangle → |d\rangle`
654654
where :math:`d` is the qudit level.
655655

656656
.. tab:: Python
@@ -674,7 +674,7 @@ This operation reduces the number of photons in a qumode up to a minimum value o
674674
0 representing the vacuum state. If it is applied to a qumode where the number of
675675
photons is already at the minimum value 0, the operation has no effect.
676676

677-
:math:`U|0\rangle → |0\rangle, U|1\rangle → |0\rangle, U|2\rangle → |1\rangle, \cdots, U|d\rangle → |d-1\rangle`
677+
:math:`A|0\rangle → |0\rangle, A|1\rangle → |0\rangle, A|2\rangle → |1\rangle, \cdots, A|d\rangle → |d-1\rangle`
678678
where :math:`d` is the qudit level.
679679

680680
.. tab:: Python

pr-2443/_sources/api/languages/cpp_api.rst.txt

+17
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ Common
3535
.. doxygenclass:: cudaq::observe_result
3636
:members:
3737

38+
.. doxygenstruct:: cudaq::observe_options
39+
:members:
40+
41+
.. doxygenfunction:: cudaq::observe(const observe_options &options, QuantumKernel &&kernel, spin_op H, Args &&...args)
42+
.. doxygenfunction:: cudaq::observe(std::size_t shots, QuantumKernel &&kernel, spin_op H, Args &&...args)
43+
.. doxygenfunction:: cudaq::observe(QuantumKernel &&kernel, spin_op H, Args &&...args)
44+
.. doxygenfunction:: cudaq::observe(QuantumKernel &&kernel, const SpinOpContainer &termList, Args &&...args)
45+
3846
.. doxygenclass:: cudaq::ExecutionContext
3947
:members:
4048

@@ -53,6 +61,13 @@ Common
5361
.. doxygenclass:: cudaq::sample_result
5462
:members:
5563

64+
.. doxygenstruct:: cudaq::sample_options
65+
:members:
66+
67+
.. doxygenfunction:: cudaq::sample(const sample_options &options, QuantumKernel &&kernel, Args &&...args)
68+
.. doxygenfunction:: cudaq::sample(std::size_t shots, QuantumKernel &&kernel, Args &&...args)
69+
.. doxygenfunction:: cudaq::sample(QuantumKernel &&kernel, Args&&... args)
70+
5671
.. doxygenclass:: cudaq::SimulationState
5772

5873
.. doxygenstruct:: cudaq::SimulationState::Tensor
@@ -89,6 +104,8 @@ Common
89104

90105
.. doxygenfunction:: cudaq::draw(QuantumKernel &&kernel, Args&&... args)
91106

107+
.. doxygenfunction:: cudaq::get_state(QuantumKernel &&kernel, Args&&... args)
108+
92109
.. doxygenclass:: cudaq::Resources
93110

94111
.. doxygentypedef:: cudaq::complex_matrix::value_type

pr-2443/_sources/api/languages/python_api.rst.txt

+2
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ Data Types
157157
.. autoclass:: cudaq.operator.cudm_state.CuDensityMatState
158158
:members:
159159

160+
.. autoclass:: cudaq.operator.helpers.InitialState
161+
160162
.. autofunction:: cudaq.operator.cudm_state.to_cupy_array
161163

162164
.. autoclass:: cudaq::SampleResult

pr-2443/_sources/applications/python/deutschs_algorithm.ipynb.txt

+24-25
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,14 @@
1313
"cell_type": "markdown",
1414
"metadata": {},
1515
"source": [
16-
"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",
16+
"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",
17+
"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",
1718
"\n",
18-
"The function $f$ has a property; either it is constant or balanced. \n",
19+
"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",
1920
"\n",
20-
"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",
21-
"\n",
22-
"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",
23-
"\n",
24-
"The question we would like to answer is if the function is constant or balanced. \n",
21+
"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",
2522
" \n",
26-
"Classically, if we are given a function $f$, we can solve to find its property via the code below: \n"
23+
"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"
2724
]
2825
},
2926
{
@@ -96,11 +93,11 @@
9693
"cell_type": "markdown",
9794
"metadata": {},
9895
"source": [
99-
"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",
96+
"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",
10097
"\n",
101-
"The claim is that Deutsch's algorithm can solve for this property with 1 function evalulation, demonstrating quantum advantage. \n",
98+
"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",
10299
"\n",
103-
"Below we first go through the math and then the implementation in CUDA Quantum. \n",
100+
"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",
104101
"\n"
105102
]
106103
},
@@ -130,7 +127,7 @@
130127
"\n",
131128
"<img src=\"images/oracle.png\" width=\"300\" height=\"150\">\n",
132129
"\n",
133-
"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",
130+
"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",
134131
"\n",
135132
"Above you see an oracle represented as $U_f$ which allows us to transform the state $\\ket{x}\\ket{y}$ into: \n",
136133
"\n",
@@ -140,7 +137,7 @@
140137
"\\end{aligned}\n",
141138
"$$\n",
142139
"\n",
143-
"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",
140+
"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",
144141
"\n",
145142
"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",
146143
" \n",
@@ -213,7 +210,7 @@
213210
"cell_type": "markdown",
214211
"metadata": {},
215212
"source": [
216-
"## Deutschs' Algorithm: \n",
213+
"## Deutsch's Algorithm: \n",
217214
"\n",
218215
"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",
219216
"\n",
@@ -296,18 +293,9 @@
296293
},
297294
{
298295
"cell_type": "code",
299-
"execution_count": 3,
296+
"execution_count": null,
300297
"metadata": {},
301-
"outputs": [
302-
{
303-
"name": "stderr",
304-
"output_type": "stream",
305-
"text": [
306-
"/usr/local/lib/python3.10/dist-packages/qutip/__init__.py:66: UserWarning: The new version of Cython, (>= 3.0.0) is not supported.\n",
307-
" warnings.warn(\n"
308-
]
309-
}
310-
],
298+
"outputs": [],
311299
"source": [
312300
"# Import the CUDA-Q package and set the target to run on NVIDIA GPUs.\n",
313301
"\n",
@@ -391,6 +379,17 @@
391379
"elif np.array(result)[0] == '1':\n",
392380
" print('f(x) is a balanced function')"
393381
]
382+
},
383+
{
384+
"cell_type": "markdown",
385+
"metadata": {},
386+
"source": [
387+
"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",
388+
"\n",
389+
"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",
390+
"\n",
391+
"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$."
392+
]
394393
}
395394
],
396395
"metadata": {

pr-2443/_sources/applications/python/digitized_counterdiabatic_qaoa.ipynb.txt

+11-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"\n",
99
"Drugs often work by binding to an active site of a protein, inhibiting or activating its function for some therapeutic purpose. Finding new candidate drugs is extremely difficult. The study of molecular docking helps guide this search and involves the prediction of how strongly a certain ligand (drug) will bind to its target (usually a protein). \n",
1010
"\n",
11-
"One of the primary challenges to molecular docking arises from the many geometric degrees of freedom present in proteins and ligands, making it difficult to predict the optimal orientation and assess if the drug is a good candidate or not. One solution is to formulate the problem as a mathematical optimization problem where the optimal solution corresponds to the most likely ligand-protein configuration. This optimization problem can be solved on a quantum computer using methods like the Quantum Approximate Optimization Algorithm (QAOA). This tutorial demonstrates how this [paper](https://arxiv.org/pdf/2308.04098) used digitized-counteradiabatic (DC) QAOA to study molecular docking. This tutorial assumes you have an understanding of QAOA, if not, please see the CUDA-Q MaxCut tutorial found [here](https://nvidia.github.io/cuda-quantum/latest/examples/python/tutorials/qaoa.html)\n",
11+
"One of the primary challenges to molecular docking arises from the many geometric degrees of freedom present in proteins and ligands, making it difficult to predict the optimal orientation and assess if the drug is a good candidate or not. One solution is to formulate the problem as a mathematical optimization problem where the optimal solution corresponds to the most likely ligand-protein configuration. This optimization problem can be solved on a quantum computer using methods like the Quantum Approximate Optimization Algorithm (QAOA). This tutorial demonstrates how this [paper](https://arxiv.org/pdf/2308.04098) used digitized-counteradiabatic (DC) QAOA to study molecular docking. This tutorial assumes you have an understanding of QAOA, if not, please see the CUDA-Q MaxCut tutorial found [here](https://nvidia.github.io/cuda-quantum/latest/applications/python/qaoa.html).\n",
1212
"\n",
1313
"The next section provides more detail on the problem setup followed by CUDA-Q implementations below."
1414
]
@@ -25,10 +25,10 @@
2525
"\n",
2626
"\n",
2727
"There are 6 key steps:\n",
28-
"1. The experimental protein and ligand structures are determined and used to select pharmacores, or an important chemical group that will govern the chemical interactions,\n",
29-
"2. T wo labeled distance graphs (LAGs) of size $N$ and $M$ represent the protein and the ligand, respectively. Each node corresponds to a pharmacore and each edge weight corresponds to the distance between pharmacores.\n",
28+
"1. The experimental protein and ligand structures are determined and used to select pharmacores, or an important chemical group that will govern the chemical interactions.\n",
29+
"2. Two labeled distance graphs (LAGs) of size $N$ and $M$ represent the protein and the ligand, respectively. Each node corresponds to a pharmacore and each edge weight corresponds to the distance between pharmacores.\n",
3030
"3. A $M*N$ node binding interaction graph (BIG) is created from the LAGs. Each node in the BIG graph corresponds to a pair of pharmacores, one from the ligand and the other from the protein. The existence of edges between nodes in the BIG graph are determined from the LAGs and correspond to interactions that can feesibly coexist. Therefore, cliques in the graph correspond to mutually possible interactions. \n",
31-
"4. The problem is mapped to a QAOA circuit and corresponding Hamiltonian, and the ground state solution is determined.\n",
31+
"4. The problem is mapped to a QAOA circuit and corresponding Hamiltonian. From there, the ground state solution is determined.\n",
3232
"5. The ground state will produce the maximum weighted clique which corresponds to the best (most strongly bound) orientation of the ligand and protein.\n",
3333
"6. The predicted docking structure is interpreted from the QAOA result and is used for further analysis.\n"
3434
]
@@ -50,16 +50,14 @@
5050
"source": [
5151
"import cudaq\n",
5252
"from cudaq import spin\n",
53-
"import numpy as np\n",
54-
"\n",
55-
"# cudaq.set_target('nvidia')"
53+
"import numpy as np\n"
5654
]
5755
},
5856
{
5957
"cell_type": "markdown",
6058
"metadata": {},
6159
"source": [
62-
"The block below defines two of the BIG data sets from the paper. The first is a smaller example, but it can be swapped with the commented out example below at your discretion. The weights are specified for each node based on the nature of the ligand and protein pharmacores represented by the node"
60+
"The block below defines two of the BIG data sets from the paper. The first is a smaller example, but it can be swapped with the commented out example below at your discretion. The weights are specified for each node based on the nature of the ligand and protein pharmacores represented by the node."
6361
]
6462
},
6563
{
@@ -77,7 +75,7 @@
7775
}
7876
],
7977
"source": [
80-
"# The two graphs input from the paper\n",
78+
"# The two graph inputs from the paper\n",
8179
"\n",
8280
"# BIG 1\n",
8381
"\n",
@@ -113,12 +111,12 @@
113111
"cell_type": "markdown",
114112
"metadata": {},
115113
"source": [
116-
"Next, the Hamiltonian is constructed. \n",
114+
"Next, the Hamiltonian is constructed: \n",
117115
"\n",
118116
"$$H = \\frac{1}{2}\\sum_{i \\in V}w_i(\\sigma^z_i - 1) + \\frac{P}{4} \\sum_{(i,j) \\notin E, i \\neq j} (\\sigma^z_i -1)(\\sigma^z_j - 1) $$\n",
119117
"\n",
120118
"\n",
121-
"The first term concerns the vertices and the weights of the given pharmacores. The second term is a penalty term that penalizes edges of the graph with no interactions. The penalty $P$ is set by the user and is defined as 6 in the cell above. The function below returns the Hamiltonina as a CUDA-Q `spin_op` object.\n",
119+
"The first term concerns the vertices and the weights of the given pharmacores. The second term is a penalty term that penalizes edges of the graph with no interactions. The penalty $P$ is set by the user and is defined as 6 in the cell above. The function below returns the Hamiltonian as a CUDA-Q `spin_op` object.\n",
122120
"\n"
123121
]
124122
},
@@ -208,7 +206,7 @@
208206
"cell_type": "markdown",
209207
"metadata": {},
210208
"source": [
211-
"The kernel below defines a DC-QAOA circuit. What makes the approach \"DC\" is the inclusion of additional counteradiabatic terms to better drive the optimization to the ground state. These terms are digitized and applied as additional operations following each QAOA layer. The increase in parameters is hopefully offset by requiring fewer layers. In this example, the DC terms are additional parameterized $Y$ operations applied to each qubit. These can be commented out to run conventional QAOA."
209+
"The kernel below defines a DC-QAOA circuit. What makes the approach \"DC\" is the inclusion of additional counteradiabatic terms to better drive the optimization to the ground state. These terms are digitized and applied as additional operations following each QAOA layer. The increase in parameters is hopefully offset by requiring fewer layers. In this example, the DC terms are the additional parameterized $Y$ operations applied to each qubit. These can be commented out to run conventional QAOA."
212210
]
213211
},
214212
{
@@ -246,7 +244,7 @@
246244
"cell_type": "markdown",
247245
"metadata": {},
248246
"source": [
249-
"The classical optimizer for the QAOA procedure can be specified as one of the build in CUDA-Q optimizers, in this case Nelder Mead. The parameter count is defined for DC-QAOA, but can be swapped with the commented line below for conventional QAOA."
247+
"The classical optimizer for the QAOA procedure can be specified as one of the built-in CUDA-Q optimizers, in this case Nelder Mead. The parameter count is defined for DC-QAOA, but can be swapped with the commented line below for conventional QAOA."
250248
]
251249
},
252250
{

0 commit comments

Comments
 (0)