Skip to content

Commit

Permalink
Don't throw fatal exception during 'import cudaq' (#1152)
Browse files Browse the repository at this point in the history
If the user has GPUs but doesn't have all the right dependencies for a
GPU-based simulator, we should not throw fatal exceptions in that case.
  • Loading branch information
bmhowe23 authored Jan 31, 2024
1 parent 714498f commit 9fff5cf
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions python/utils/LinkedLibraryHolder.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. *
* Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. *
* All rights reserved. *
* *
* This source code and the accompanying materials are made available under *
Expand Down Expand Up @@ -255,10 +255,27 @@ LinkedLibraryHolder::LinkedLibraryHolder() {

// Set the default target
// If environment variable set with a valid value, use it
// Otherwise, if GPU(s) available, set default to 'nvidia', else to 'qpp-cpu'
// Otherwise, if GPU(s) available and other dependencies are satisfied, set
// default to 'nvidia', else to 'qpp-cpu'
defaultTarget = "qpp-cpu";
if (countGPUs() > 0) {
defaultTarget = "nvidia";
// Before setting the defaultTarget to nvidia, make sure the simulator is
// available.
const std::string nvidiaTarget = "nvidia";
auto iter = targets.find(nvidiaTarget);
if (iter != targets.end()) {
auto target = iter->second;
if (std::find(availableSimulators.begin(), availableSimulators.end(),
target.simulatorName) != availableSimulators.end())
defaultTarget = nvidiaTarget;
else
cudaq::info(
"GPU(s) found but cannot select nvidia target because simulator "
"is not available. Are all dependencies installed?");
} else {
cudaq::info("GPU(s) found but cannot select nvidia target because nvidia "
"target not found.");
}
}
auto env = std::getenv("CUDAQ_DEFAULT_SIMULATOR");
if (env) {
Expand Down

0 comments on commit 9fff5cf

Please sign in to comment.