Skip to content

Commit

Permalink
Add ability to create wheels in devdeps images (NVIDIA#58)
Browse files Browse the repository at this point in the history
With this change, one can build the wheels in the cuda-quantum-devdeps
image with this command: `bash .github/workflows/scripts/build_wheels.sh
--devdeps --cudaq-prefix /usr/local/cudaq`.

The wheels are not suitable for distribution but this could be helpful
during debugging.

Signed-off-by: Ben Howe <[email protected]>
  • Loading branch information
bmhowe23 authored Jan 22, 2025
1 parent c5a92a3 commit 757268a
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions .github/workflows/scripts/build_wheels.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/bin/sh

# ============================================================================ #
# Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. #
# Copyright (c) 2024 - 2025 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. #
# ============================================================================ #

set -e # Exit immediately if a command exits with a non-zero status

# ==============================================================================
# Handling options
Expand All @@ -20,6 +21,9 @@ show_help() {
echo " --cudaq-prefix Path to CUDA-Q's install prefix"
echo " (default: \$HOME/.cudaq)"
echo " --python-version Python version to build wheel for (e.g. 3.10)"
echo " --devdeps Build wheels suitable for internal testing"
echo " (not suitable for distribution but sometimes"
echo " helpful for debugging)"
}

parse_options() {
Expand Down Expand Up @@ -52,6 +56,10 @@ parse_options() {
exit 1
fi
;;
--devdeps)
devdeps=true
shift 1
;;
-*)
echo "Error: Unknown option $1" >&2
show_help
Expand All @@ -70,6 +78,7 @@ parse_options() {
cudaq_prefix=$HOME/.cudaq
build_type=Release
python_version=3.10
devdeps=false

# Parse options
parse_options "$@"
Expand All @@ -82,9 +91,14 @@ echo "Building in $build_type mode for Python $python_version"

python=python${python_version}
ARCH=$(uname -m)
PLAT_STR=""

# We need to use a newer toolchain because CUDA-QX libraries rely on c++20
source /opt/rh/gcc-toolset-11/enable
if $devdeps; then
PLAT_STR="--plat manylinux_2_34_x86_64"
else
# We need to use a newer toolchain because CUDA-QX libraries rely on c++20
source /opt/rh/gcc-toolset-11/enable
fi

export CC=gcc
export CXX=g++
Expand All @@ -96,7 +110,9 @@ export CXX=g++
cd libs/qec

SKBUILD_CMAKE_ARGS="-DCUDAQ_DIR=$cudaq_prefix/lib/cmake/cudaq"
SKBUILD_CMAKE_ARGS+=";-DCMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN=/opt/rh/gcc-toolset-11/root/usr/lib/gcc/${ARCH}-redhat-linux/11/"
if ! $devdeps; then
SKBUILD_CMAKE_ARGS+=";-DCMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN=/opt/rh/gcc-toolset-11/root/usr/lib/gcc/${ARCH}-redhat-linux/11/"
fi
SKBUILD_CMAKE_ARGS+=";-DCMAKE_BUILD_TYPE=$build_type"
export SKBUILD_CMAKE_ARGS
$python -m build --wheel
Expand All @@ -105,7 +121,8 @@ CUDAQ_EXCLUDE_LIST=$(for f in $(find $cudaq_prefix/lib -name "*.so" -printf "%P\

LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$(pwd)/_skbuild/lib" \
$python -m auditwheel -v repair dist/*.whl $CUDAQ_EXCLUDE_LIST \
--wheel-dir /wheels
--wheel-dir /wheels \
${PLAT_STR}

# ==============================================================================
# Solvers library
Expand All @@ -114,7 +131,9 @@ $python -m auditwheel -v repair dist/*.whl $CUDAQ_EXCLUDE_LIST \
cd ../solvers

SKBUILD_CMAKE_ARGS="-DCUDAQ_DIR=$cudaq_prefix/lib/cmake/cudaq"
SKBUILD_CMAKE_ARGS+=";-DCMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN=/opt/rh/gcc-toolset-11/root/usr/lib/gcc/${ARCH}-redhat-linux/11/;"
if ! $devdeps; then
SKBUILD_CMAKE_ARGS+=";-DCMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN=/opt/rh/gcc-toolset-11/root/usr/lib/gcc/${ARCH}-redhat-linux/11/;"
fi
SKBUILD_CMAKE_ARGS+=";-DCMAKE_BUILD_TYPE=$build_type" \
export SKBUILD_CMAKE_ARGS
$python -m build --wheel
Expand All @@ -124,5 +143,9 @@ $python -m auditwheel -v repair dist/*.whl $CUDAQ_EXCLUDE_LIST \
--exclude libgfortran.so.5 \
--exclude libquadmath.so.0 \
--exclude libmvec.so.1 \
--wheel-dir /wheels
--wheel-dir /wheels \
${PLAT_STR}


echo "Wheel builds are complete: "
ls -la /wheels

0 comments on commit 757268a

Please sign in to comment.