Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions .github/workflows/pr_workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
name: Check changes
runs-on: ubuntu-latest
outputs:
check-cudaq-patch: ${{ steps.filter.outputs.check-cudaq-patch }}
build-cudaq: ${{ steps.filter.outputs.build-cudaq }}
build-docs: ${{ steps.filter.outputs.build-docs }}
build-all: ${{ steps.filter.outputs.build-all }}
Expand All @@ -39,11 +40,18 @@ jobs:
with:
base: ${{ fromJSON(steps.get-pr-info.outputs.pr-info).base.sha }}
filters: |
check-cudaq-patch:
- '.cudaq_version'
- '.github/actions/get-cudaq-version/**'
- '.github/workflows/pr_workflow.yaml'
- '.github/workflows/scripts/build_cudaq.sh'
- '.github/workflows/scripts/check_cudaq_patch.sh'
- 'scripts/ci/build_cudaq_wheel.sh'
build-cudaq:
- '.cudaq_version'
- '.github/actions/get-cudaq-build/**'
- '.github/actions/get-cudaq-version/**'
- '.github/workflows/scripts/build_cudaq.sh'
- '.cudaq_version'
build-docs:
- '.github/workflows/docs.yaml'
- 'docs/**'
Expand Down Expand Up @@ -91,6 +99,25 @@ jobs:
build-examples-solvers:
- 'docs/sphinx/examples/solvers/**'

check-cudaq-patch:
name: Check CUDAQ patch
needs: [check-changes]
if: needs.check-changes.outputs.check-cudaq-patch == 'true'
runs-on: linux-amd64-cpu4
steps:
- name: Get code
uses: actions/checkout@v4
with:
set-safe-directory: true

- name: Install jq
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends jq

- name: Verify CUDAQ patch applies
run: bash .github/workflows/scripts/check_cudaq_patch.sh

build-cudaq:
name: Build CUDAQ
needs: [check-changes]
Expand Down Expand Up @@ -184,6 +211,7 @@ jobs:
name: Verify PR
if: ${{ always() }}
needs:
- check-cudaq-patch
- build-cudaq
- build-all
- build-qec
Expand All @@ -206,10 +234,11 @@ jobs:
fi
}

check_result "build-cudaq" "${{needs.build-cudaq.result}}"
check_result "build-all" "${{needs.build-all.result}}"
check_result "build-qec" "${{needs.build-qec.result}}"
check_result "build-solvers" "${{needs.build-solvers.result}}"
check_result "check-cudaq-patch" "${{ needs.check-cudaq-patch.result }}"
check_result "build-cudaq" "${{ needs.build-cudaq.result }}"
check_result "build-all" "${{ needs.build-all.result }}"
check_result "build-qec" "${{ needs.build-qec.result }}"
check_result "build-solvers" "${{ needs.build-solvers.result }}"

if [[ "$status" != "success" ]]; then
exit 1
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/scripts/build_cudaq.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@ diff --git a/python/runtime/cudaq/domains/plugins/CMakeLists.txt b/python/runtim
+ nanobind-static Python3::Module
cudaq-chemistry cudaq-operator cudaq cudaq-py-utils cudaq-platform-default)
endif()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We won't need this patch once NVIDIA/cuda-quantum#4643 lands.

diff --git a/runtime/common/CMakeLists.txt b/runtime/common/CMakeLists.txt
--- a/runtime/common/CMakeLists.txt
+++ b/runtime/common/CMakeLists.txt
@@ -80,7 +80,7 @@ if(OPENSSL_FOUND)
if(APPLE)
target_link_libraries(${LIBRARY_NAME} PRIVATE cpr::cpr ZLIB::ZLIB)
else()
- target_link_libraries(${LIBRARY_NAME} PRIVATE cpr::cpr -Wl,--start-group ZLIB::ZLIB)
+ target_link_libraries(${LIBRARY_NAME} PRIVATE cpr::cpr -Wl,--start-group ZLIB::ZLIB ${CMAKE_DL_LIBS})
endif()
target_compile_definitions(${LIBRARY_NAME} PRIVATE -DCUDAQ_RESTCLIENT_AVAILABLE)
# Override the global flat_namespace for this library. cudaq-common doesn'\''t need
'

echo "$CUDAQ_PATCH" | git apply --verbose
Expand Down
96 changes: 96 additions & 0 deletions .github/workflows/scripts/check_cudaq_patch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/bash

# ============================================================================ #
# Copyright (c) 2022 - 2026 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. #
# ============================================================================ #

# Verify that the embedded CUDAQ_PATCH in the CUDA-Q build scripts still
# applies cleanly against the CUDA-Q commit pinned in .cudaq_version.
#
# The patches are sourced and piped to `git apply` exactly the way the build
# scripts apply them (assign the CUDAQ_PATCH heredoc, then
# `echo "$CUDAQ_PATCH" | git apply`). This is important because the trailing
# newline added by `echo` is part of the patch payload (it supplies the final
# blank context line in the second hunk). Anything that extracts the patch
# via a different mechanism may produce a payload that git apply rejects even
# though the build scripts apply the same bytes successfully.

set -eo pipefail

REPO_ROOT="$(cd "$(dirname "$0")/../../.." && pwd)"
WORKFLOW_SCRIPT="$REPO_ROOT/.github/workflows/scripts/build_cudaq.sh"
WHEEL_SCRIPT="$REPO_ROOT/scripts/ci/build_cudaq_wheel.sh"
CUDAQ_VERSION_FILE="$REPO_ROOT/.cudaq_version"

# Source the CUDAQ_PATCH='...' heredoc out of a build script and echo it back
# the same way the build script does, so the trailing newline matches.
emit_patch_from_script() {
local script=$1
local shell=$2
"${shell}" -c "$(sed -n "/^CUDAQ_PATCH='/,/^'\$/p" "${script}")"$'\n''echo "$CUDAQ_PATCH"'
}

# Apply (or check) the patch via the same code path the build script uses.
apply_patch_like_build_script() {
local script=$1
local shell=$2
local mode=$3 # "--check" or empty
emit_patch_from_script "${script}" "${shell}" \
| git apply ${mode} --verbose
}

if [ ! -f "${CUDAQ_VERSION_FILE}" ]; then
echo "Missing ${CUDAQ_VERSION_FILE}" >&2
exit 1
fi

if ! command -v jq >/dev/null 2>&1; then
echo "jq is required" >&2
exit 1
fi

CUDAQ_REPO=$(jq -r '.cudaq.repository' "${CUDAQ_VERSION_FILE}")
CUDAQ_REF=$(jq -r '.cudaq.ref' "${CUDAQ_VERSION_FILE}")

echo "Checking CUDAQ_PATCH against ${CUDAQ_REPO}@${CUDAQ_REF}"

WORKDIR=$(mktemp -d)
trap 'rm -rf "${WORKDIR}"' EXIT

# Compare the two embedded patches byte-for-byte, using the same emission
# path each build script uses.
WORKFLOW_PATCH_BYTES="${WORKDIR}/workflow.patch"
WHEEL_PATCH_BYTES="${WORKDIR}/wheel.patch"
emit_patch_from_script "${WORKFLOW_SCRIPT}" bash > "${WORKFLOW_PATCH_BYTES}"
emit_patch_from_script "${WHEEL_SCRIPT}" sh > "${WHEEL_PATCH_BYTES}"

if ! cmp -s "${WORKFLOW_PATCH_BYTES}" "${WHEEL_PATCH_BYTES}"; then
echo "CUDAQ_PATCH differs between:" >&2
echo " ${WORKFLOW_SCRIPT}" >&2
echo " ${WHEEL_SCRIPT}" >&2
diff -u "${WORKFLOW_PATCH_BYTES}" "${WHEEL_PATCH_BYTES}" >&2 || true
exit 1
fi
echo "CUDAQ_PATCH matches in both build scripts."

git clone --filter=blob:none --no-checkout \
"https://github.com/${CUDAQ_REPO}.git" "${WORKDIR}/cudaq"
git -C "${WORKDIR}/cudaq" checkout "${CUDAQ_REF}"

echo "Checking patch from .github/workflows/scripts/build_cudaq.sh (bash) ..."
(
cd "${WORKDIR}/cudaq"
apply_patch_like_build_script "${WORKFLOW_SCRIPT}" bash --check
)

echo "Checking patch from scripts/ci/build_cudaq_wheel.sh (sh) ..."
(
cd "${WORKDIR}/cudaq"
apply_patch_like_build_script "${WHEEL_SCRIPT}" sh --check
)

echo "CUDAQ_PATCH applies cleanly to ${CUDAQ_REPO}@${CUDAQ_REF}."
13 changes: 13 additions & 0 deletions scripts/ci/build_cudaq_wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ diff --git a/python/runtime/cudaq/domains/plugins/CMakeLists.txt b/python/runtim
+ nanobind-static Python3::Module
cudaq-chemistry cudaq-operator cudaq cudaq-py-utils cudaq-platform-default)
endif()

diff --git a/runtime/common/CMakeLists.txt b/runtime/common/CMakeLists.txt
--- a/runtime/common/CMakeLists.txt
+++ b/runtime/common/CMakeLists.txt
@@ -80,7 +80,7 @@ if(OPENSSL_FOUND)
if(APPLE)
target_link_libraries(${LIBRARY_NAME} PRIVATE cpr::cpr ZLIB::ZLIB)
else()
- target_link_libraries(${LIBRARY_NAME} PRIVATE cpr::cpr -Wl,--start-group ZLIB::ZLIB)
+ target_link_libraries(${LIBRARY_NAME} PRIVATE cpr::cpr -Wl,--start-group ZLIB::ZLIB ${CMAKE_DL_LIBS})
endif()
target_compile_definitions(${LIBRARY_NAME} PRIVATE -DCUDAQ_RESTCLIENT_AVAILABLE)
# Override the global flat_namespace for this library. cudaq-common doesn'\''t need
'

echo "$CUDAQ_PATCH" | git apply --verbose
Expand Down
Loading