Skip to content

Commit 1b7f673

Browse files
committed
Misc fixes for various build/test environments
Signed-off-by: Ben Howe <[email protected]>
1 parent f0e4d55 commit 1b7f673

File tree

6 files changed

+35
-6
lines changed

6 files changed

+35
-6
lines changed

Building.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ git clone https://github.com/NVIDIA/cudaqx.git
4040
cd cudaqx
4141
mkdir build && cd build
4242

43-
# Configure your build (adjust as necessary)
43+
# Configure your build (adjust as necessary). Note TRT requires extra
44+
# dependencies, so the command below disables it from the build.
4445
cmake -G Ninja -S .. \
4546
-DCUDAQ_INSTALL_DIR=$CUDAQ_INSTALL_PREFIX \
4647
-DCMAKE_INSTALL_PREFIX=${CUDAQX_INSTALL_PREFIX} \
4748
-DCUDAQ_DIR=${CUDAQ_INSTALL_PREFIX}/lib/cmake/cudaq \
4849
-DCMAKE_BUILD_TYPE=Release
50+
-DCUDAQ_QEC_BUILD_TRT_DECODER=OFF
4951

5052
# Install your build
5153
ninja install
@@ -55,7 +57,7 @@ export PYTHONPATH=${CUDAQ_INSTALL_PREFIX}:${CUDAQX_INSTALL_PREFIX}
5557
export PATH="${CUDAQ_INSTALL_PREFIX}/bin:${CUDAQX_INSTALL_PREFIX}/bin:${PATH}"
5658
ctest
5759
# Run the python tests
58-
# The --ignore option is to bypass tests that require additional packages not contained in
60+
# The --ignore option is to bypass tests that require additional packages not contained in
5961
# the standard docker container
6062
cd ..
6163
python3 -m pytest -v libs/qec/python/tests --ignore libs/qec/python/tests/test_tensor_network_decoder.py

libs/qec/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ option(CUDAQX_QEC_INSTALL_PYTHON
6161
"Install python files alongside the library."
6262
${CUDAQX_INSTALL_PYTHON})
6363

64+
# Option to control TRT decoder build (default: ON)
65+
option(CUDAQ_QEC_BUILD_TRT_DECODER "Build the TensorRT decoder plugin" ON)
66+
6467
# Check for CUDA Support (ref: cuda-quantum/CMakeLists.txt)
6568
# ==============================================================================
6669
include(CheckLanguage)

libs/qec/lib/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ add_library(${LIBRARY_NAME} SHARED
2525
)
2626

2727
add_subdirectory(decoders/plugins/example)
28-
add_subdirectory(decoders/plugins/trt_decoder)
28+
29+
if(CUDAQ_QEC_BUILD_TRT_DECODER)
30+
add_subdirectory(decoders/plugins/trt_decoder)
31+
endif()
32+
2933
add_subdirectory(codes)
3034
add_subdirectory(device)
3135

libs/qec/unittests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ add_dependencies(CUDAQXQECUnitTests test_qec)
4444
gtest_discover_tests(test_qec)
4545

4646
# TensorRT decoder test is only built for x86 architectures
47-
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(AMD64|amd64)|(^i.86$)")
47+
if(CUDAQ_QEC_BUILD_TRT_DECODER AND CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(AMD64|amd64)|(^i.86$)")
4848
add_executable(test_trt_decoder ./decoders/trt_decoder/test_trt_decoder.cpp)
4949

5050
# Find TensorRT for the test

libs/solvers/python/tests/test_uccgsd.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@
66
import cudaq
77
import cudaq_solvers as solvers
88
from scipy.optimize import minimize
9+
import subprocess
10+
11+
12+
def is_nvidia_gpu_available():
13+
"""Check if NVIDIA GPU is available using nvidia-smi command."""
14+
try:
15+
result = subprocess.run(["nvidia-smi"],
16+
stdout=subprocess.PIPE,
17+
stderr=subprocess.PIPE,
18+
text=True)
19+
if result.returncode == 0 and "GPU" in result.stdout:
20+
return True
21+
except FileNotFoundError:
22+
# The nvidia-smi command is not found, indicating no NVIDIA GPU drivers
23+
return False
24+
return False
925

1026

1127
def test_solvers_adapt_uccgsd_h2():
@@ -138,6 +154,9 @@ def cost(theta):
138154
assert np.isclose(energy, -1.1371, atol=1e-4)
139155

140156

157+
# Since this test is so slow on the CPU, only run this test if a GPU was found.
158+
@pytest.mark.skipif(not is_nvidia_gpu_available(),
159+
reason="NVIDIA GPU not found")
141160
def test_solvers_vqe_uccgsd_lih():
142161

143162
geometry = [('Li', (0.3925, 0., 0.)), ('H', (-1.1774, 0., .0))]

libs/solvers/unittests/test_uccgsd_operator_pool.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,9 @@ TEST(UCCGSDOperatorPoolTest, AllOperatorsNonEmpty) {
187187
for (size_t i = 0; i < ops.size(); ++i) {
188188
EXPECT_GT(ops[i].num_terms(), 0)
189189
<< "Operator " << i << " is empty (has 0 terms)";
190-
EXPECT_FALSE(ops[i].is_identity())
191-
<< "Operator " << i << " should not be identity";
190+
for (const auto &term : ops[i])
191+
EXPECT_FALSE(term.is_identity())
192+
<< "Term " << term.to_string() << " is identity";
192193
}
193194
}
194195

0 commit comments

Comments
 (0)