Skip to content

Commit

Permalink
Docs preview for PR #1797.
Browse files Browse the repository at this point in the history
  • Loading branch information
cuda-quantum-bot committed Jul 24, 2024
1 parent a597dcb commit e6e5fc6
Show file tree
Hide file tree
Showing 185 changed files with 17,481 additions and 8,626 deletions.
23 changes: 18 additions & 5 deletions pr-1797/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
# SOURCE_LOCATION: location of the source file (relative to 'sphinx/examples/cpp' directory by default)
# Optional keyword args:
# TARGET <TARGET_NAME>: name of the target to use
# TARGET_OPTION <Option>: extra option for the target
# SOURCE_DIR <DIR>: the directory that SOURCE_LOCATION is relative to (if not the default)
# LAUNCH_COMMAND <COMMAND>: the command to launch the test (e.g., mpirun)
function(add_nvqpp_test TEST_NAME SOURCE_LOCATION)
cmake_parse_arguments(PARSED_ARGS "" "TARGET;LABELS;SOURCE_DIR;LAUNCH_COMMAND;APPLICATION_ARGS" "" ${ARGN})
cmake_parse_arguments(PARSED_ARGS "" "TARGET;LABELS;SOURCE_DIR;LAUNCH_COMMAND;APPLICATION_ARGS;TARGET_OPTION" "" ${ARGN})
set(NVQPP_COMPILE_ARGS "")
if(PARSED_ARGS_TARGET)
set(NVQPP_COMPILE_ARGS "${NVQPP_COMPILE_ARGS} --target ${PARSED_ARGS_TARGET}")
if (PARSED_ARGS_TARGET_OPTION)
set(NVQPP_COMPILE_ARGS "${NVQPP_COMPILE_ARGS} --${PARSED_ARGS_TARGET}-option ${PARSED_ARGS_TARGET_OPTION}")
endif()
endif()
if (NOT PARSED_ARGS_SOURCE_DIR)
set(PARSED_ARGS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/sphinx/examples/cpp")
Expand Down Expand Up @@ -59,7 +63,6 @@ endif()

# code snippets in docs
add_nvqpp_test(QuickStart_default quick_start.cpp SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp)
add_nvqpp_test(FirstKernel using/first_kernel.cpp SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp)
add_nvqpp_test(FirstObserve using/first_observe.cpp SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp)
add_nvqpp_test(FirstSample using/first_sample.cpp SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp)
add_nvqpp_test(Timing using/time.cpp SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp APPLICATION_ARGS "10")
Expand All @@ -69,9 +72,14 @@ if (CUSTATEVEC_ROOT AND CUDA_FOUND)
add_nvqpp_test(QuickStart_nvidia quick_start.cpp TARGET nvidia LABELS gpu_required SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp)

# mqpu snippets need custatevec backend and optionally MPI
add_nvqpp_test(SampleAsync using/cudaq/platform/sample_async.cpp TARGET nvidia-mqpu LABELS gpu_required SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp)
add_nvqpp_test(ObserveMQPU using/cudaq/platform/observe_mqpu.cpp TARGET nvidia-mqpu LABELS gpu_required SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp)
add_nvqpp_test(StateAsyncMQPU using/cudaq/platform/get_state_async.cpp TARGET nvidia-mqpu LABELS gpu_required SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp)
add_nvqpp_test(SampleAsync using/cudaq/platform/sample_async.cpp TARGET nvidia TARGET_OPTION mqpu LABELS gpu_required SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp)
add_nvqpp_test(ObserveMQPU using/cudaq/platform/observe_mqpu.cpp TARGET nvidia TARGET_OPTION mqpu LABELS gpu_required SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp)
add_nvqpp_test(StateAsyncMQPU using/cudaq/platform/get_state_async.cpp TARGET nvidia TARGET_OPTION mqpu LABELS gpu_required SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp)

# Legacy check for the `nvidia-mqpu` target
add_nvqpp_test(LegacySampleAsync using/cudaq/platform/sample_async.cpp TARGET nvidia-mqpu LABELS gpu_required SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp)
add_nvqpp_test(LegacyObserveMQPU using/cudaq/platform/observe_mqpu.cpp TARGET nvidia-mqpu LABELS gpu_required SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp)
add_nvqpp_test(LegacyStateAsyncMQPU using/cudaq/platform/get_state_async.cpp TARGET nvidia-mqpu LABELS gpu_required SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp)

# Add the MPI test if MPI was found and there are more than 2 GPUs
if (MPI_CXX_FOUND)
Expand All @@ -82,6 +90,11 @@ if (CUSTATEVEC_ROOT AND CUDA_FOUND)
# Only build this test if we have more than 1 GPU
if (${NGPUS} GREATER_EQUAL 2)
add_nvqpp_test(ObserveMQPU_MPI using/cudaq/platform/observe_mqpu_mpi.cpp
TARGET nvidia
TARGET_OPTION mqpu
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp
LAUNCH_COMMAND "${MPIEXEC} --allow-run-as-root -np 2")
add_nvqpp_test(LegacyObserveMQPU_MPI using/cudaq/platform/observe_mqpu_mpi.cpp
TARGET nvidia-mqpu
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp
LAUNCH_COMMAND "${MPIEXEC} --allow-run-as-root -np 2")
Expand Down
Binary file removed pr-1797/_images/Bloch_sphere.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pr-1797/_images/orca_tbi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions pr-1797/_sources/api/languages/cpp_api.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ Platform
.. doxygenclass:: cudaq::quantum_platform
:members:

.. doxygenstruct:: cudaq::RemoteCapabilities
:members:

.. doxygenclass:: cudaq::SerializedCodeExecutionContext

.. doxygentypedef:: cudaq::QuantumTask

.. doxygentypedef:: cudaq::QubitConnectivity
Expand Down
3 changes: 2 additions & 1 deletion pr-1797/_sources/api/languages/python_api.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ Kernel Execution
.. autofunction:: cudaq::get_state
.. autofunction:: cudaq::get_state_async
.. autofunction:: cudaq::vqe
.. autofunction:: cudaq::draw
.. autofunction:: cudaq::draw
.. autofunction:: cudaq::translate

Backend Configuration
=============================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@
"# Initialize a kernel/ ansatz and variational parameters.\n",
"@cudaq.kernel\n",
"def kernel(angles: List[float]):\n",
" # Allocate a qubit that is initialised to the |0> state.\n",
" # Allocate a qubit that is initialized to the |0> state.\n",
" qubit = cudaq.qubit()\n",
" # Define gates and the qubits they act upon.\n",
" rx(angles[0], qubit)\n",
" ry(angles[1], qubit)\n",
"\n",
"\n",
"# Our hamiltonian will be the Z expectation value of our qubit.\n",
"# Our Hamiltonian will be the Z expectation value of our qubit.\n",
"hamiltonian = cudaq.spin.z(0)\n",
"\n",
"# Initial gate parameters which intialize the qubit in the zero state\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Deutschs' Algorithm "
"# Deutsch's Algorithm "
]
},
{
Expand All @@ -17,7 +17,7 @@
"\n",
"The function $f$ has a property; either it is constant or balanced. \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",
"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",
Expand All @@ -32,14 +32,14 @@
"metadata": {},
"outputs": [],
"source": [
"# Treat the code snippet below like a black box, i.e you dont have access to the value of the property argument and can just query f with different inputs.\n",
"# Treat the code snippet below like a black box, i.e., you don't have access to the value of the property argument and can just query f with different inputs.\n",
"\n",
"\n",
"def f(x, property='constant'):\n",
"\n",
" if property == 'constant':\n",
"\n",
" # The output is a 1 regardless of the input, we can also make the output to be 0.\n",
" # The output is a 1 regardless of the input; we can also make the output to be 0.\n",
"\n",
" if x == 0:\n",
" return 1\n",
Expand Down Expand Up @@ -96,9 +96,9 @@
"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, one can see 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 Deutschs' algorithm can solve for this property with 1 function evalulation demonstrating quantum advantage. \n",
"The claim is that Deutsch's algorithm can solve for this property with 1 function evalulation, demonstrating quantum advantage. \n",
"\n",
"Below we first go through the math and then the implementation in CUDA Quantum. \n",
"\n"
Expand Down Expand Up @@ -142,7 +142,7 @@
"\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",
"\n",
"This is remarkable as by setting $\\ket{y} = \\ket{0}$, we can extract the value of $f(x)$ by measuring the value of the second qubit. \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",
"\n"
]
Expand All @@ -155,9 +155,9 @@
"## Phase oracle\n",
"\n",
"\n",
"Since $f(x)$ can be either $0/1$, $0 \\oplus f(x) = 0 \\oplus 0/1 = 0/1 = f(x)$. \n",
"Since $f(x)$ can be either $0$ or $1$, we have that $0 \\oplus f(x) = 0 \\oplus 0 = 0 = f(x)$ or $0 \\oplus f(x) = 0 \\oplus 1 = 1 = f(x)$. \n",
"\n",
"Similarly, $1 \\oplus f(x) = 1 \\oplus 0/1 = 1/0 = \\overline{f(x)}$ where the bar on top of $f(x)$ denotes 'not $f(x)$'. \n",
"Similarly, $1 \\oplus f(x) = 1 \\oplus 0 = 1 = \\overline{f(x)}$ or $1 \\oplus f(x) = 1 \\oplus 1 = 0 = \\overline{f(x)}$ where the bar on top of $f(x)$ denotes 'not $f(x)$'. \n",
"\n",
"\n",
"Let us now prove a result which we shall use later: \n",
Expand All @@ -178,7 +178,7 @@
"$$\n",
"\n",
"\n",
"In summary, $U_f\\ket{x}\\ket{-} = (-1)^{f(x)}\\ket{x}\\ket{-}$ where the $\\ket{-}$ qubit was left unchanged and a phase was applied to $\\ket{x}$ \n",
"In summary, $U_f\\ket{x}\\ket{-} = (-1)^{f(x)}\\ket{x}\\ket{-}$ where the $\\ket{-}$ qubit was left unchanged and a phase was applied to $\\ket{x}$. \n",
"\n",
"\n",
"\n"
Expand Down Expand Up @@ -287,9 +287,9 @@
"\\end{aligned}\n",
"$$\n",
"\n",
"We can now measure the first qubit to yield either a $0/1$ to determine if $f(x)$ is constant or balanced. \n",
"We can now measure the first qubit to yield either a $0$ or a $1$ to determine if $f(x)$ is constant or balanced. \n",
"\n",
"Deutschs' algorithm may not be practically useful but does demonstrate quantum advantage since it uses one function call to determine the property of $f$ in comparison to two for classical methods. \n",
"Deutsch's algorithm may not be practically useful but does demonstrate quantum advantage since it uses one function call to determine the property of $f$ in comparison to two for classical methods. \n",
"\n",
"\n"
]
Expand Down
Loading

0 comments on commit e6e5fc6

Please sign in to comment.