Skip to content

Commit

Permalink
Merge branch 'main' into plugin_example
Browse files Browse the repository at this point in the history
  • Loading branch information
melody-ren committed Dec 18, 2024
2 parents ad25870 + bd893b8 commit 7fcbe6a
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .cudaq_version
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"cudaq": {
"repository": "NVIDIA/cuda-quantum",
"ref": "c9d0e4c020ca83b119a0df8a5fdf41911078e12a"
"ref": "5785e44256b757263879580c82cb84adc85bcf5a"
}
}

68 changes: 68 additions & 0 deletions .github/workflows/update-cudaq-dep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
on:
workflow_dispatch:
schedule:
- cron: 0 1 * * 6

name: "Bump CUDA-Q Commit"

jobs:
update-cudaq-commit:
name: Bump CUDA-Q Commit
runs-on: ubuntu-latest
if: ${{ github.repository == 'NVIDIA/cudaqx' }}
permissions:
contents: write # Required to push changes
pull-requests: write # Required to open PRs

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: main

- name: Fetch the latest commit
run: |
SHA=$(curl -s "https://api.github.com/repos/NVIDIA/cuda-quantum/commits/main" | jq -r '.sha')
echo "Latest SHA: $SHA"
echo "sha=$SHA" >> $GITHUB_ENV
- name: Check if SHA has changed
id: check_change
run: |
CURRENT_SHA=$(jq -r '.cudaq.ref' .cudaq_version)
if [[ "${{ env.LATEST_SHA }}" == "$CURRENT_SHA" ]]; then
echo "No changes in SHA. Skipping PR creation."
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "SHA has changed. Proceeding to create PR."
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Update .cudaq_version file
if: ${{ steps.check_change.outputs.changed == 'true' }}
run: |
jq '.cudaq.ref = "${{ env.sha }}"' .cudaq_version > .cudaq_version.tmp
mv .cudaq_version.tmp .cudaq_version
echo "Updated SHA in .cudaq_version"
- name: Commit and push changes
if: ${{ steps.check_change.outputs.changed == 'true' }}
run: |
git config --global user.email "action@github.com"
git config --global user.name "GitHub Action"
BRANCH_NAME="update-cudaq-sha-$(date +%s)"
git checkout -b $BRANCH_NAME
git add .cudaq_version
git commit -m "Update dependency SHA to ${{ env.sha }}"
git push origin $BRANCH_NAME
- name: Create Pull Request
if: ${{ steps.check_change.outputs.changed == 'true' }}
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
gh pr create \
--title "Bump CUDA-Q commit" \
--body "Auto update to the latest CUDA-Q commit" \
--head "${BRANCH_NAME}" \
--base "main"
62 changes: 62 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,68 @@ if (CUDAQX_INCLUDE_TESTS)
endif()
endif()

# Hooks setup. If the repo contains a custom pre-push hook, attempt to install
# it. If the user has a different one installed, then warn them but do not fail
# configuration.
# ==============================================================================

# Define the directory where your hooks are stored
set(SRC_HOOK_PRE_PUSH "${CMAKE_SOURCE_DIR}/.githooks/pre-push")

if(EXISTS "${SRC_HOOK_PRE_PUSH}")
# Get the Git hooks directory from the Git configuration
execute_process(
COMMAND git config --get core.hooksPath
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_HOOKS_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Determine the target hooks directory
if(GIT_HOOKS_DIR)
set(TARGET_HOOKS_DIR "${GIT_HOOKS_DIR}")
else()
set(TARGET_HOOKS_DIR "${CMAKE_SOURCE_DIR}/.git/hooks")
endif()
set(DST_HOOK_PRE_PUSH "${TARGET_HOOKS_DIR}/pre-push")

if(EXISTS "${DST_HOOK_PRE_PUSH}")
# Compare the contents of the src and dst hook.
execute_process(
COMMAND git hash-object "${DST_HOOK_PRE_PUSH}"
OUTPUT_VARIABLE SHA_DST
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git hash-object "${SRC_HOOK_PRE_PUSH}"
OUTPUT_VARIABLE SHA_SRC
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT SHA_SRC STREQUAL SHA_DST)
message(WARNING
"You already have a ${DST_HOOK_PRE_PUSH} script installed. "
"This configuration script will not overwrite it despite the fact that "
"it is strongly recommended to use ${SRC_HOOK_PRE_PUSH} in your environment."
"\nProceed with caution!")
endif()
else()
if(EXISTS "${TARGET_HOOKS_DIR}")
file(COPY "${SRC_HOOK_PRE_PUSH}"
DESTINATION "${TARGET_HOOKS_DIR}"
FILE_PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)
message(STATUS "Git pre-push hook installed to ${TARGET_HOOKS_DIR}")
else()
message(WARNING
"The Git hooks directory does not exist: ${TARGET_HOOKS_DIR}\n"
"Are you sure this is a Git repository? Hook cannot be installed."
)
endif()
endif()
endif()

# Directory setup
# ==============================================================================

Expand Down
4 changes: 2 additions & 2 deletions docs/sphinx/components/qec/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,8 @@ Here's a complete example of running a memory experiment:
# Create code and decoder
code = qec.get_code('steane')
decoder = qec.get_decoder('steane_lut',
code.get_parity())
decoder = qec.get_decoder('single_error_lut',
code.get_parity())
# Configure noise
noise = cudaq.noise_model()
Expand Down
8 changes: 8 additions & 0 deletions docs/sphinx/quickstart/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ The simplest way to install CUDA-QX is via pip. You can install individual compo
# Install both libraries
pip install cudaq-qec cudaq-solvers
.. note::

CUDA-Q Solvers will require the presence of :code:`libgfortran`, which is
not distributed with the Python wheel, for provided classical optimizers. If
:code:`libgfortran` is not installed, you will need to install it via your
distribution's package manager. On Debian based systems, you can install
this with :code:`apt-get install gfortran`.

Docker Container
^^^^^^^^^^^^^^^^

Expand Down
40 changes: 39 additions & 1 deletion libs/qec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# the terms of the Apache License 2.0 which accompanies this distribution. #
# ============================================================================ #

# Requering the same version as the others.
# Requiring the same version as the others.
cmake_minimum_required(VERSION 3.28 FATAL_ERROR)

# Project setup
Expand Down Expand Up @@ -52,6 +52,44 @@ option(CUDAQX_QEC_INSTALL_PYTHON
"Install python files alongside the library."
${CUDAQX_INSTALL_PYTHON})

# Check for CUDA Support (ref: cuda-quantum/CMakeLists.txt)
# ==============================================================================
include(CheckLanguage)
check_language(CUDA)
set(CUDA_FOUND FALSE)
# Generate -gencode arch=compute_XX,code=sm_XX for list of supported
# arch values.
# List should be sorted in increasing order.
function(CUDA_get_gencode_args out_args_string arch_values)
# allow the user to pass the list like a normal variable
set(arch_list ${arch_values} ${ARGN})
set(out "")
foreach(arch IN LISTS arch_list)
set(out "${out} -gencode arch=compute_${arch},code=sm_${arch}")
endforeach(arch)

# Repeat the last one as to ensure the generation of PTX for most
# recent virtual architecture for forward compatibility
list(GET arch_list -1 last_arch)
set(out "${out} -gencode arch=compute_${last_arch},code=compute_${last_arch}")
set(${out_args_string} ${out} PARENT_SCOPE)
endfunction()

if(CMAKE_CUDA_COMPILER)
if (NOT CUDA_TARGET_ARCHS)
# Volta, Ampere, Hopper
set(CUDA_TARGET_ARCHS "70;80;90")
endif()
CUDA_get_gencode_args(CUDA_gencode_flags ${CUDA_TARGET_ARCHS})
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -shared -std=c++17 ${CUDA_gencode_flags} --compiler-options -fPIC")

enable_language(CUDA)
set(CUDA_FOUND TRUE)
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CUDA_STANDARD_REQUIRED TRUE)
message(STATUS "Cuda language found.")
endif()

# External Dependencies
# ==============================================================================

Expand Down
15 changes: 13 additions & 2 deletions libs/qec/include/cudaq/qec/decoder.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************-*- C++ -*-****
* Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. *
* Copyright (c) 2024 NVIDIA Corporation & Affiliates. *
* All rights reserved. *
* *
* This source code and the accompanying materials are made available under *
Expand All @@ -19,7 +19,7 @@ namespace cudaq::qec {
#if defined(CUDAQX_QEC_FLOAT_TYPE)
using float_t = CUDAQX_QEC_FLOAT_TYPE;
#else
using float_t = float;
using float_t = double;
#endif

/// @brief Decoder results
Expand All @@ -30,6 +30,17 @@ struct decoder_result {
/// @brief Vector of length `block_size` with soft probabilities of errors in
/// each index.
std::vector<float_t> result;

// Manually define the equality operator
bool operator==(const decoder_result &other) const {
return std::tie(converged, result) ==
std::tie(other.converged, other.result);
}

// Manually define the inequality operator
bool operator!=(const decoder_result &other) const {
return !(*this == other);
}
};

/// @brief The `decoder` base class should be subclassed by specific decoder
Expand Down
24 changes: 13 additions & 11 deletions libs/qec/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
# the terms of the Apache License 2.0 which accompanies this distribution. #
# ============================================================================ #

set(LIBRARY_NAME cudaq-qec)

add_compile_options(-Wno-attributes)

# FIXME?: This must be a shared library. Trying to build a static one will fail.
add_library(cudaq-qec SHARED
add_library(${LIBRARY_NAME} SHARED
code.cpp
stabilizer_utils.cpp
decoder.cpp
Expand All @@ -22,22 +24,22 @@ add_subdirectory(decoders/plugins/example)
add_subdirectory(codes)
add_subdirectory(device)

if (CUDAQX_QEC_USE_DOUBLE)
target_compile_definitions(cudaq-qec PUBLIC -DCUDAQX_QEC_FLOAT_TYPE=double)
if (CUDAQX_QEC_USE_FLOAT)
target_compile_definitions(${LIBRARY_NAME} PUBLIC -DCUDAQX_QEC_FLOAT_TYPE=float)
endif()

target_include_directories(cudaq-qec
target_include_directories(${LIBRARY_NAME}
PUBLIC
$<BUILD_INTERFACE:${CUDAQX_QEC_INCLUDE_DIR}>
$<INSTALL_INTERFACE:${CUDAQ_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>
)

target_link_options(cudaq-qec PUBLIC
target_link_options(${LIBRARY_NAME} PUBLIC
$<$<CXX_COMPILER_ID:GNU>:-Wl,--no-as-needed>
)

target_link_libraries(cudaq-qec
target_link_libraries(${LIBRARY_NAME}
PUBLIC
cudaqx-core
cudaq::cudaq
Expand All @@ -46,33 +48,33 @@ target_link_libraries(cudaq-qec
cudaq::cudaq-common
)

set_target_properties(cudaq-qec PROPERTIES
set_target_properties(${LIBRARY_NAME} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

# RPATH configuration
# ==============================================================================

if (NOT SKBUILD)
set_target_properties(cudaq-qec PROPERTIES
set_target_properties(${LIBRARY_NAME} PROPERTIES
BUILD_RPATH "$ORIGIN"
INSTALL_RPATH "$ORIGIN:$ORIGIN/../lib"
)

# Let CMake automatically add paths of linked libraries to the RPATH:
set_target_properties(cudaq-qec PROPERTIES
set_target_properties(${LIBRARY_NAME} PROPERTIES
INSTALL_RPATH_USE_LINK_PATH TRUE)
else()
# CUDA-Q install its libraries in site-packages/lib (or dist-packages/lib)
# Thus, we need the $ORIGIN/../lib
set_target_properties(cudaq-qec PROPERTIES
set_target_properties(${LIBRARY_NAME} PROPERTIES
INSTALL_RPATH "$ORIGIN/../../lib"
)
endif()

# Install
# ==============================================================================

install(TARGETS cudaq-qec
install(TARGETS ${LIBRARY_NAME}
COMPONENT qec-lib
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
Expand Down
38 changes: 38 additions & 0 deletions libs/solvers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,44 @@ option(CUDAQX_SOLVERS_INSTALL_PYTHON
"Install python files alongside the library."
${CUDAQX_INSTALL_PYTHON})

# Check for CUDA Support (ref: cuda-quantum/CMakeLists.txt)
# ==============================================================================
include(CheckLanguage)
check_language(CUDA)
set(CUDA_FOUND FALSE)
# Generate -gencode arch=compute_XX,code=sm_XX for list of supported
# arch values.
# List should be sorted in increasing order.
function(CUDA_get_gencode_args out_args_string arch_values)
# allow the user to pass the list like a normal variable
set(arch_list ${arch_values} ${ARGN})
set(out "")
foreach(arch IN LISTS arch_list)
set(out "${out} -gencode arch=compute_${arch},code=sm_${arch}")
endforeach(arch)

# Repeat the last one as to ensure the generation of PTX for most
# recent virtual architecture for forward compatibility
list(GET arch_list -1 last_arch)
set(out "${out} -gencode arch=compute_${last_arch},code=compute_${last_arch}")
set(${out_args_string} ${out} PARENT_SCOPE)
endfunction()

if(CMAKE_CUDA_COMPILER)
if (NOT CUDA_TARGET_ARCHS)
# Volta, Ampere, Hopper
set(CUDA_TARGET_ARCHS "70;80;90")
endif()
CUDA_get_gencode_args(CUDA_gencode_flags ${CUDA_TARGET_ARCHS})
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -shared -std=c++17 ${CUDA_gencode_flags} --compiler-options -fPIC")

enable_language(CUDA)
set(CUDA_FOUND TRUE)
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CUDA_STANDARD_REQUIRED TRUE)
message(STATUS "Cuda language found.")
endif()

# External Dependencies
# ==============================================================================

Expand Down

0 comments on commit 7fcbe6a

Please sign in to comment.