Skip to content

Commit

Permalink
fixing repo checks
Browse files Browse the repository at this point in the history
  • Loading branch information
bettinaheim committed Jul 27, 2023
1 parent 28eb45f commit def87cb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 49 deletions.
10 changes: 6 additions & 4 deletions docs/sphinx/examples/python/bernstein_vazirani.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,18 @@ def bernstein_vazirani(qubit_count: int):
# larger number of qubits compared the CPU-only backend.

# Depending on the available memory on your GPU, you can
# set the number of qubits to around 30 qubits, and uncomment
# set the number of qubits to around 30 qubits, and un-comment
# the `cudaq.set_target(nvidia)` line.

# Note: Without setting the target to the nvidia backend,
# Note: Without setting the target to the `nvidia` backend,
# a 30 qubit simulation simply seems to hang; that is
# because it takes a long time for the CPU-only backend
# to handle this number of qubits!

qubit_count = 5 # set to around 30 qubits for nvidia target
#cudaq.set_target("nvidia")
qubit_count = 5 # set to around 30 qubits for `nvidia` target
# ```
# cudaq.set_target("nvidia")
# ```

kernel, hidden_bitstring = bernstein_vazirani(qubit_count)
result = cudaq.sample(kernel)
Expand Down
6 changes: 3 additions & 3 deletions python/cudaq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

if not "CUDAQ_DYNLIBS" in os.environ:
try:
cublas_libs=get_link_path("cublas", 11)
cublas_libs=get_library_path("nvidia-cublas-cu11")
cublas_path=os.path.join(cublas_libs, "libcublas.so.11")
cublasLt_path=os.path.join(cublas_libs, "libcublasLt.so.11")

custatevec_libs=get_link_path("custatevec", 11)
custatevec_libs=get_library_path("custatevec-cu11")
custatevec_path=os.path.join(custatevec_libs, "libcustatevec.so.1")

os.environ["CUDAQ_DYNLIBS"] = f"{cublasLt_path}:{cublas_path}:{custatevec_path}"
except:
except RuntimeError:
pass

from ._pycudaq import *
Expand Down
53 changes: 14 additions & 39 deletions python/cudaq/_packages.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES
#
# SPDX-License-Identifier: BSD-3-Clause

# ============================================================================ #
# Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. #
# All rights reserved. #
# #
# This source code and the accompanying materials are made available under #
# the terms of the Apache License 2.0 which accompanies this distribution. #
# ============================================================================ #

from importlib.metadata import distribution
import os.path


def find_package_location(package_name):
path = None
try:
path = _find_package_location_by_license(package_name)
except:
pass
if path is None:
path = _find_package_location_by_root(package_name)
return path


def _find_package_location_by_root(package_name):
"""This should not fail, unless the package is not installed."""
dist = distribution(package_name)
roots = set()
for f in dist.files:
Expand All @@ -31,7 +21,6 @@ def _find_package_location_by_root(package_name):


def _find_package_location_by_license(package_name):
"""This function assumes a file named LICENSE is placed at the package root."""
dist = distribution(package_name)
for f in dist.files:
if str(f).endswith("LICENSE"):
Expand All @@ -43,28 +32,14 @@ def _find_package_location_by_license(package_name):
return path


def get_library_path(library, cuda_major=11):
if library in ("cuda-runtime", "cublas", "cusolver", "cusparse"):
package_name = f"nvidia-{library}-cu{cuda_major}"
subdir = library.replace("-", "_")
elif library in ("cutensor", "custatevec", "cutensornet"):
package_name = f"{library}-cu{cuda_major}"
subdir = ""
else:
raise NotImplementedError(f"library {library} is not recognized")

dirname = os.path.join(find_package_location(package_name), subdir)
assert os.path.isdir(dirname)
return dirname


def get_include_path(library, cuda_major=11):
dirname = os.path.join(get_library_path(library, cuda_major), "include")
assert os.path.isdir(dirname)
return dirname
def get_library_path(package_name):
subdir = ""
if package_name.startswith("nvidia-"):
subdir = "-".join(package_name.split("-")[1:-1])

try: package_location = _find_package_location_by_license(package_name)
except: package_location = _find_package_location_by_root(package_name)

def get_link_path(library, cuda_major=11):
dirname = os.path.join(get_library_path(library, cuda_major), "lib")
dirname = os.path.join(package_location, subdir, "lib")
assert os.path.isdir(dirname)
return dirname
7 changes: 4 additions & 3 deletions python/utils/LinkedLibraryHolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ LinkedLibraryHolder::LinkedLibraryHolder() {

const char *statevec_dynlibs_var = std::getenv("CUDAQ_DYNLIBS");
if (statevec_dynlibs_var != nullptr) {
std::string statevec_dynlib;
std::string statevec_dynlib;
std::stringstream ss((std::string(statevec_dynlibs_var)));
while(std::getline(ss, statevec_dynlib, ':')){
cudaq::info("Init: add custatevec dynamic library path {}.", statevec_dynlib);
while(std::getline(ss, statevec_dynlib, ':')) {
cudaq::info("Init: add custatevec dynamic library path {}.",
statevec_dynlib);
libPaths.push_back(statevec_dynlib);
}
}
Expand Down

0 comments on commit def87cb

Please sign in to comment.