Skip to content

Commit bc1c833

Browse files
Docs preview for PR #4211.
1 parent aa8ab9c commit bc1c833

File tree

1,058 files changed

+682619
-0
lines changed

Some content is hidden

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

1,058 files changed

+682619
-0
lines changed

pr-4211/CMakeLists.txt

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# ============================================================================ #
2+
# Copyright (c) 2022 - 2026 NVIDIA Corporation & Affiliates. #
3+
# All rights reserved. #
4+
# #
5+
# This source code and the accompanying materials are made available under #
6+
# the terms of the Apache License 2.0 which accompanies this distribution. #
7+
# ============================================================================ #
8+
9+
# Add nvq++ compile + execution test of code examples
10+
# Args:
11+
# TEST_NAME: name of the test executable. Test name is prefixed with "nvqpp"
12+
# SOURCE_LOCATION: location of the source file (relative to 'sphinx' directory by default)
13+
# Optional keyword args:
14+
# TARGET <TARGET_NAME>: name of the target to use
15+
# TARGET_OPTION <Option>: extra option for the target
16+
# SOURCE_DIR <DIR>: the directory that SOURCE_LOCATION is relative to (if not the default)
17+
# LAUNCH_COMMAND <COMMAND>: the command to launch the test (e.g., mpirun)
18+
function(add_nvqpp_test TEST_NAME SOURCE_LOCATION)
19+
cmake_parse_arguments(PARSED_ARGS "" "TARGET;LABELS;SOURCE_DIR;LAUNCH_COMMAND;APPLICATION_ARGS;TARGET_OPTION" "" ${ARGN})
20+
set(NVQPP_COMPILE_ARGS "--library-mode -I${CMAKE_SOURCE_DIR}/runtime/include")
21+
if(PARSED_ARGS_TARGET)
22+
set(NVQPP_COMPILE_ARGS "${NVQPP_COMPILE_ARGS} --target ${PARSED_ARGS_TARGET}")
23+
if (PARSED_ARGS_TARGET_OPTION)
24+
set(NVQPP_COMPILE_ARGS "${NVQPP_COMPILE_ARGS} --${PARSED_ARGS_TARGET}-option ${PARSED_ARGS_TARGET_OPTION}")
25+
endif()
26+
endif()
27+
if (NOT PARSED_ARGS_SOURCE_DIR)
28+
set(PARSED_ARGS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/sphinx")
29+
endif()
30+
add_test(
31+
NAME
32+
nvqpp_${TEST_NAME}
33+
COMMAND
34+
bash -c "rm -f ${TEST_NAME}; ${CMAKE_BINARY_DIR}/bin/nvq++ ${NVQPP_COMPILE_ARGS} ${PARSED_ARGS_SOURCE_DIR}/${SOURCE_LOCATION} -o ${TEST_NAME} && \
35+
${PARSED_ARGS_LAUNCH_COMMAND} ${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME} ${PARSED_ARGS_APPLICATION_ARGS}"
36+
)
37+
if(PARSED_ARGS_LABELS)
38+
set_tests_properties(nvqpp_${TEST_NAME} PROPERTIES LABELS "${PARSED_ARGS_LABELS}")
39+
endif()
40+
endfunction()
41+
42+
add_nvqpp_test(GHZ examples/cpp/basics/static_kernel.cpp)
43+
add_nvqpp_test(ExpVals examples/cpp/basics/expectation_values.cpp)
44+
add_nvqpp_test(MidCircuitMeasurements examples/cpp/basics/mid_circuit_measurement.cpp)
45+
add_nvqpp_test(PhaseEstimation applications/cpp/phase_estimation.cpp)
46+
add_nvqpp_test(Grover applications/cpp/grover.cpp)
47+
add_nvqpp_test(QAOA applications/cpp/qaoa_maxcut.cpp)
48+
add_nvqpp_test(VQEH2 applications/cpp/vqe_h2.cpp)
49+
add_nvqpp_test(AmplitudeEstimation applications/cpp/amplitude_estimation.cpp)
50+
add_nvqpp_test(Builder examples/cpp/other/builder/builder.cpp)
51+
add_nvqpp_test(QAOABuilder examples/cpp/other/builder/qaoa_maxcut_builder.cpp)
52+
add_nvqpp_test(VQEH2Builder examples/cpp/other/builder/vqe_h2_builder.cpp)
53+
add_nvqpp_test(ComputeAction examples/cpp/other/compute_actions.cpp)
54+
add_nvqpp_test(Gradients examples/cpp/other/gradients.cpp)
55+
add_nvqpp_test(IterativePhaseEstimation applications/cpp/iterative_qpe.cpp)
56+
add_nvqpp_test(RandomWalkPhaseEstimation applications/cpp/random_walk_qpe.cpp)
57+
58+
if (CUSTATEVEC_ROOT AND CUDA_FOUND)
59+
add_nvqpp_test(CuQuantumGHZ examples/cpp/basics/cuquantum_backends.cpp TARGET nvidia LABELS gpu_required)
60+
add_nvqpp_test(CuQuantumBernsteinVazirani applications/cpp/bernstein_vazirani.cpp TARGET nvidia LABELS gpu_required)
61+
endif()
62+
63+
# code snippets in docs
64+
add_nvqpp_test(QuickStart_default quick_start.cpp SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp)
65+
add_nvqpp_test(FirstObserve using/first_observe.cpp SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp)
66+
add_nvqpp_test(FirstSample using/first_sample.cpp SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp)
67+
add_nvqpp_test(Timing using/time.cpp SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp APPLICATION_ARGS "10")
68+
69+
set(PTSBE_CPP_SNIPPET_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp/using/examples/ptsbe)
70+
add_nvqpp_test(PTSBE_BellDepol bell_circuit_under_depol_noise.cpp SOURCE_DIR ${PTSBE_CPP_SNIPPET_DIR})
71+
add_nvqpp_test(PTSBE_InspectData inspect_execution_data.cpp SOURCE_DIR ${PTSBE_CPP_SNIPPET_DIR})
72+
add_nvqpp_test(PTSBE_SamplingStrategies sampling_strategies.cpp SOURCE_DIR ${PTSBE_CPP_SNIPPET_DIR})
73+
add_nvqpp_test(PTSBE_ShotAllocation shot_allocation.cpp SOURCE_DIR ${PTSBE_CPP_SNIPPET_DIR})
74+
75+
if (CUDENSITYMAT_ROOT AND CUDA_FOUND)
76+
add_nvqpp_test(Dynamics_Snippets using/backends/dynamics.cpp SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp/ TARGET dynamics LABELS gpu_required)
77+
add_nvqpp_test(Dynamics_State_Batching_Snippets using/backends/dynamics_state_batching.cpp SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp/ TARGET dynamics LABELS gpu_required)
78+
add_nvqpp_test(Dynamics_Operator_Batching_Snippets using/backends/dynamics_operator_batching.cpp SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp/ TARGET dynamics LABELS gpu_required)
79+
endif()
80+
81+
set(NGPUS 0)
82+
if (CUSTATEVEC_ROOT AND CUDA_FOUND)
83+
add_nvqpp_test(QuickStart_nvidia quick_start.cpp TARGET nvidia LABELS gpu_required SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp)
84+
85+
# mqpu snippets need custatevec backend and optionally MPI
86+
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)
87+
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)
88+
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)
89+
90+
# Legacy check for the `nvidia-mqpu` target
91+
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)
92+
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)
93+
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)
94+
95+
# Add the MPI test if MPI was found and there are more than 2 GPUs
96+
if (MPI_CXX_FOUND)
97+
# Count the number of GPUs
98+
find_program(NVIDIA_SMI "nvidia-smi")
99+
if(NVIDIA_SMI)
100+
execute_process(COMMAND bash -c "nvidia-smi --list-gpus | wc -l" OUTPUT_VARIABLE NGPUS)
101+
# Only build this test if we have more than 1 GPU
102+
if (${NGPUS} GREATER_EQUAL 2)
103+
add_nvqpp_test(ObserveMQPU_MPI using/cudaq/platform/observe_mqpu_mpi.cpp
104+
TARGET nvidia
105+
TARGET_OPTION mqpu
106+
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp
107+
LAUNCH_COMMAND "${MPIEXEC} --allow-run-as-root -np 2")
108+
add_nvqpp_test(LegacyObserveMQPU_MPI using/cudaq/platform/observe_mqpu_mpi.cpp
109+
TARGET nvidia-mqpu
110+
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp
111+
LAUNCH_COMMAND "${MPIEXEC} --allow-run-as-root -np 2")
112+
endif()
113+
endif(NVIDIA_SMI)
114+
endif()
115+
endif()
116+
117+
add_nvqpp_test(photonics_sim targets/cpp/photonics.cpp TARGET orca-photonics)
118+
add_nvqpp_test(SampleAsyncRemote using/cudaq/platform/sample_async_remote.cpp TARGET remote-mqpu SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp)
119+
set_tests_properties(
120+
nvqpp_SampleAsyncRemote
121+
PROPERTIES
122+
ENVIRONMENT_MODIFICATION PATH=path_list_append:${CMAKE_BINARY_DIR}/bin
123+
)
124+
125+
# Only add the python tests if we built the python API
126+
if (CUDAQ_ENABLE_PYTHON)
127+
function(add_pycudaq_test TEST_NAME SOURCE_LOCATION)
128+
cmake_parse_arguments(PARSED_ARGS "" "LABELS;SOURCE_DIR;LAUNCH_COMMAND" "" ${ARGN})
129+
if (NOT PARSED_ARGS_SOURCE_DIR)
130+
set(PARSED_ARGS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/sphinx/examples/python")
131+
endif()
132+
add_test(
133+
NAME
134+
pycudaq_${TEST_NAME}
135+
COMMAND
136+
bash -c "${PARSED_ARGS_LAUNCH_COMMAND} ${Python_EXECUTABLE} ${PARSED_ARGS_SOURCE_DIR}/${SOURCE_LOCATION}"
137+
)
138+
set_tests_properties(pycudaq_${TEST_NAME} PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/python")
139+
if(PARSED_ARGS_LABELS)
140+
set_tests_properties(pycudaq_${TEST_NAME} PROPERTIES LABELS "${PARSED_ARGS_LABELS}")
141+
endif()
142+
endfunction()
143+
144+
add_pycudaq_test(Intro intro.py)
145+
146+
set(PTSBE_PY_SNIPPET_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/python/using/examples/ptsbe)
147+
add_pycudaq_test(PTSBE_BellDepol bell_circuit_under_depol_noise.py SOURCE_DIR ${PTSBE_PY_SNIPPET_DIR})
148+
add_pycudaq_test(PTSBE_InspectData inspect_execution_data.py SOURCE_DIR ${PTSBE_PY_SNIPPET_DIR})
149+
add_pycudaq_test(PTSBE_SamplingStrategies sampling_strategies.py SOURCE_DIR ${PTSBE_PY_SNIPPET_DIR})
150+
add_pycudaq_test(PTSBE_ShotAllocation shot_allocation.py SOURCE_DIR ${PTSBE_PY_SNIPPET_DIR})
151+
152+
if (CUDA_FOUND)
153+
add_pycudaq_test(EvolveDynamics using/backends/dynamics.py LABELS gpu_required SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/python)
154+
add_pycudaq_test(EvolveDynamicsStateBatching using/backends/dynamics_state_batching.py LABELS gpu_required SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/python)
155+
add_pycudaq_test(EvolveDynamicsOperatorBatching using/backends/dynamics_operator_batching.py LABELS gpu_required SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/python)
156+
endif()
157+
158+
if (CUTENSORNET_ROOT AND CUDA_FOUND)
159+
# This example uses tensornet backend.
160+
add_pycudaq_test(SampleAsyncRemote using/cudaq/platform/sample_async_remote.py SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/python)
161+
endif()
162+
163+
if (CUSTATEVEC_ROOT AND CUDA_FOUND)
164+
add_pycudaq_test(SampleAsync using/cudaq/platform/sample_async.py LABELS gpu_required SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/python)
165+
add_pycudaq_test(ObserveMQPU using/cudaq/platform/observe_mqpu.py LABELS gpu_required SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/python)
166+
if (MPI_CXX_FOUND AND ${NGPUS} GREATER_EQUAL 2)
167+
add_pycudaq_test(ObserveMQPU_MPI using/cudaq/platform/observe_mqpu_mpi.py
168+
LABELS "gpu_required;mgpus_required"
169+
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/python
170+
LAUNCH_COMMAND "${MPIEXEC} --allow-run-as-root -np 2")
171+
endif()
172+
endif()
173+
endif()

0 commit comments

Comments
 (0)