Skip to content

Commit 048942b

Browse files
authored
Misc fixes for various build/test environments (#331)
* Allow the build to skip the TensorRT-based decoder if the user explicitly disables it. (Useful for developer testing.) * Fix a build warning from the UCCGSD test * Also, skip the `libs/solvers/python/tests/test_uccgsd.py::test_solvers_vqe_uccgsd_lih` test in CPU-only environments (like some of our CI) because it was taking ~30 minutes just for that one test.
1 parent f0e4d55 commit 048942b

File tree

6 files changed

+43
-4
lines changed

6 files changed

+43
-4
lines changed

docker/build_env/cudaqx.dev.Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,21 @@ LABEL org.opencontainers.image.url="https://github.com/NVIDIA/cudaqx"
1919
# FIXME: Remove the cmake install once private repos are updated.
2020
RUN apt-get update && CUDA_DASH=$(echo $cuda_version | tr '.' '-') \
2121
&& apt-get install -y gfortran libblas-dev jq cuda-nvtx-${CUDA_DASH} \
22+
&& apt-get install -y git-lfs \
2223
&& python3 -m pip install "cmake<4" --user \
2324
&& apt-get autoremove -y --purge && apt-get clean && rm -rf /var/lib/apt/lists/*
2425

26+
# Install tensorrt-dev, unless this is CUDA 12 w/ arm64
27+
RUN CUDA_MAJOR_VERSION=$(echo $cuda_version | cut -d . -f1); \
28+
ARCH="${ARCH:-$(dpkg --print-architecture)}"; \
29+
if [ "$CUDA_MAJOR_VERSION" != "12" ] || [ "$ARCH" = "amd64" ]; then \
30+
apt-get update \
31+
&& apt-cache search tensorrt | awk '{print "Package: "$1"\nPin: version *+cuda'${cuda_version}'\nPin-Priority: 1001\n"}' | tee /etc/apt/preferences.d/tensorrt-cuda${cuda_version}.pref > /dev/null \
32+
&& apt update \
33+
&& apt-get install -y tensorrt-dev \
34+
&& apt-get autoremove -y --purge && apt-get clean && rm -rf /var/lib/apt/lists/*; \
35+
fi
36+
2537
COPY .cudaq_version /cudaq_version
2638

2739
ENV CUDAQ_INSTALL_PREFIX=/usr/local/cudaq

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)