From b4668ab74f3805a1f9df45d1f8f6fba242504d44 Mon Sep 17 00:00:00 2001 From: Mitchell Date: Wed, 27 Aug 2025 14:53:38 -0700 Subject: [PATCH 01/11] init add patch-pypi.sh Signed-off-by: Mitchell --- scripts/patch-pypi.sh | 79 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 scripts/patch-pypi.sh diff --git a/scripts/patch-pypi.sh b/scripts/patch-pypi.sh new file mode 100644 index 00000000000..aeeeef05789 --- /dev/null +++ b/scripts/patch-pypi.sh @@ -0,0 +1,79 @@ +# copyright (c) 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. # +# ============================================================================ # + +# This script is used to patch the wheel metadata for a PyPI package. For now, +# it is anticipated that one would use this script as a reference and update the +# MODIFY_ME1 and MODIFY_ME2 sections before using it. + +# Note: you may need to run "python3 -m pip install -U wheel" first. + +# MODIFY_ME1 - review and modify the following variables +PACKAGE_NAME=cudaq +ORIG_VER=0.12.0 +NEW_VER=0.12.0.post0 + +# Make sure that curl, jq, python3, and wget are installed. +if ! command -v curl &> /dev/null; then + echo "curl could not be found" + exit 1 +fi +if ! command -v jq &> /dev/null; then + echo "jq could not be found" + exit 1 +fi +if ! command -v python3 &> /dev/null; then + echo "python3 could not be found" + exit 1 +fi +if ! command -v wget &> /dev/null; then + echo "wget could not be found" + exit 1 +fi + +# Make a temporary directory to work in +TMP_DIR=$(mktemp -d) +echo "Building TMP_DIR in $TMP_DIR" +echo "Using temporary directory: $TMP_DIR" + +# # Be sure to clean up the temporary directory on exit +# trap "rm -rf $TMP_DIR" EXIT + +echo "Downloading the original wheels into wheels_orig..." +mkdir -p wheels_orig && \ +curl -fsSL "https://pypi.org/pypi/${PACKAGE_NAME}/${ORIG_VER}/json" \ +| jq -r '.urls[] | select(.packagetype=="sdist") | .url' \ +| xargs -n1 -P4 -I{} wget -c -P wheels_orig {} + +mkdir -p wheels_new + +echo "Placing the patched source into wheels_new..." +tar -xvzf wheels_orig/*.tar.gz -C wheels_new + +# at this point, we need to update the version in the setup.py or pyproject.toml +echo ${NEW_VER} > + + +# python3 -m wheel unpack $f -d $TMP_DIR + +# # --- Begin modifications +# # Update the version +# sed -i "s/^Version: ${ORIG_VER}/Version: ${NEW_VER}/" $TMP_DIR/${PACKAGE_NAME}-${ORIG_VER}/${PACKAGE_NAME}-${ORIG_VER}.dist-info/METADATA +# # MODIFY_ME2 - review and modify the METADATA file here +# # ... +# # --- End modifications + +# # Re-package into a new whl file now +# cd $TMP_DIR +# mv cudaq_qec-${ORIG_VER}/${PACKAGE_NAME}-${ORIG_VER}.dist-info ${PACKAGE_NAME}-${ORIG_VER}/${PACKAGE_NAME}-${NEW_VER}.dist-info +# python3 -m wheel pack cudaq_qec-${ORIG_VER} -d . +# cd - +# mv $TMP_DIR/cudaq_qec-${NEW_VER}*.whl wheels_new +# rm -rf $TMP_DIR + +# echo "Done!" +# echo "Your original wheels are in wheels_orig, and your patched wheels are in wheels_new." +# echo "You can now upload the patched wheels to PyPI." From 06886108cb4a1033595f9c377d890d737a8ebb51 Mon Sep 17 00:00:00 2001 From: Mitchell Date: Tue, 2 Sep 2025 09:17:44 -0700 Subject: [PATCH 02/11] handle cuda-quantum-cu* Signed-off-by: Mitchell --- scripts/patch-pypi.sh | 111 +++++++++++++++++++++++++----------------- 1 file changed, 67 insertions(+), 44 deletions(-) diff --git a/scripts/patch-pypi.sh b/scripts/patch-pypi.sh index aeeeef05789..4ab4522c94f 100644 --- a/scripts/patch-pypi.sh +++ b/scripts/patch-pypi.sh @@ -14,66 +14,89 @@ # MODIFY_ME1 - review and modify the following variables PACKAGE_NAME=cudaq ORIG_VER=0.12.0 -NEW_VER=0.12.0.post0 +NEW_VER=0.12.0.post4 -# Make sure that curl, jq, python3, and wget are installed. -if ! command -v curl &> /dev/null; then - echo "curl could not be found" - exit 1 -fi -if ! command -v jq &> /dev/null; then - echo "jq could not be found" - exit 1 -fi -if ! command -v python3 &> /dev/null; then - echo "python3 could not be found" - exit 1 -fi -if ! command -v wget &> /dev/null; then - echo "wget could not be found" +# Ensure required commands are available +missing=() + +for cmd in curl jq python3 wget; do + if ! command -v "$cmd" >/dev/null 2>&1; then + missing+=("$cmd") + fi +done + +if [ ${#missing[@]} -ne 0 ]; then + echo "[ERROR] the following required commands are missing:" + echo " - ${missing[*]}" exit 1 fi # Make a temporary directory to work in -TMP_DIR=$(mktemp -d) +TMP_DIR="$(mktemp -d)" echo "Building TMP_DIR in $TMP_DIR" echo "Using temporary directory: $TMP_DIR" +mkdir -p wheels_new -# # Be sure to clean up the temporary directory on exit -# trap "rm -rf $TMP_DIR" EXIT +# Be sure to clean up the temporary directory on exit +trap "rm -rf $TMP_DIR" EXIT -echo "Downloading the original wheels into wheels_orig..." -mkdir -p wheels_orig && \ +### ------------------------------------------------- ### +# Update cudaq metapackage +CUDAQ_METAPACKAGE_ORIG="wheels_orig_${PACKAGE_NAME}" +echo "Downloading the original cudaq wheels into ${CUDAQ_METAPACKAGE_ORIG}..." +mkdir -p ${CUDAQ_METAPACKAGE_ORIG} && \ curl -fsSL "https://pypi.org/pypi/${PACKAGE_NAME}/${ORIG_VER}/json" \ | jq -r '.urls[] | select(.packagetype=="sdist") | .url' \ -| xargs -n1 -P4 -I{} wget -c -P wheels_orig {} +| xargs -n1 -P4 -I{} wget -c -P ${CUDAQ_METAPACKAGE_ORIG} {} -mkdir -p wheels_new +tar -xvzf ${CUDAQ_METAPACKAGE_ORIG}/*.tar.gz -C ${TMP_DIR} +cd ${TMP_DIR} +ls -l ${TMP_DIR} +echo ${NEW_VER} > ${TMP_DIR}/*/_version.txt +cd ${TMP_DIR}/*/ + +# MODIFY_ME2 - review and modify the source code here +sed -i '' 's/elif cuda_version < 13000:/elif cuda_version <= 13000:/' setup.py + +CUDAQ_META_WHEEL_BUILD=1 python3 -m build . --sdist +mv ${TMP_DIR}/*/dist/cudaq-*.tar.gz wheels_new -echo "Placing the patched source into wheels_new..." -tar -xvzf wheels_orig/*.tar.gz -C wheels_new +# upload cudaq metapackage with: +# python3 -m twine upload --repository testpypi wheels_new/*/dist/cudaq-0.12.0.post2.tar.gz --verbose + + +### ------------------------------------------------- ### +# modify cuda-quantum-cu* packages +mkdir -p wheels_new -# at this point, we need to update the version in the setup.py or pyproject.toml -echo ${NEW_VER} > +# cuda-quantum-cu* ships actual wheels, so we need to modify them +for package in cuda-quantum-cu12 cuda-quantum-cu11; do + PACKAGE_NAME_UNDER="${package//-/_}" + orig_dir=wheels_orig_${PACKAGE_NAME_UNDER} + # download wheels for this dist/version + curl -fsSL "https://pypi.org/pypi/${package}/${ORIG_VER}/json" \ + | jq -r '.urls[] | select(.packagetype=="bdist_wheel") | .url' \ + | xargs -n1 -P4 -I{} wget -c -P "$orig_dir" {} -# python3 -m wheel unpack $f -d $TMP_DIR + for f in ${orig_dir}/*.whl; do + python3 -m wheel unpack $f -d $TMP_DIR -# # --- Begin modifications -# # Update the version -# sed -i "s/^Version: ${ORIG_VER}/Version: ${NEW_VER}/" $TMP_DIR/${PACKAGE_NAME}-${ORIG_VER}/${PACKAGE_NAME}-${ORIG_VER}.dist-info/METADATA -# # MODIFY_ME2 - review and modify the METADATA file here -# # ... -# # --- End modifications + # --- Begin modifications + # Update the version + sed -i '' "s/^Version: ${ORIG_VER}/Version: ${NEW_VER}/" $TMP_DIR/${PACKAGE_NAME_UNDER}-${ORIG_VER}/${PACKAGE_NAME_UNDER}-${ORIG_VER}.dist-info/METADATA + # MODIFY_ME2 - review and modify the METADATA file here + # ... + # --- End modifications -# # Re-package into a new whl file now -# cd $TMP_DIR -# mv cudaq_qec-${ORIG_VER}/${PACKAGE_NAME}-${ORIG_VER}.dist-info ${PACKAGE_NAME}-${ORIG_VER}/${PACKAGE_NAME}-${NEW_VER}.dist-info -# python3 -m wheel pack cudaq_qec-${ORIG_VER} -d . -# cd - -# mv $TMP_DIR/cudaq_qec-${NEW_VER}*.whl wheels_new -# rm -rf $TMP_DIR + # Re-package into a new whl file now + cd $TMP_DIR + mv ${PACKAGE_NAME_UNDER}-${ORIG_VER}/${PACKAGE_NAME_UNDER}-${ORIG_VER}.dist-info ${PACKAGE_NAME_UNDER}-${ORIG_VER}/${PACKAGE_NAME_UNDER}-${NEW_VER}.dist-info + python3 -m wheel pack ${PACKAGE_NAME_UNDER}-${ORIG_VER} -d . + cd - + mv $TMP_DIR/${PACKAGE_NAME_UNDER}-${NEW_VER}*.whl wheels_new + rm -rf $TMP_DIR + done +done -# echo "Done!" -# echo "Your original wheels are in wheels_orig, and your patched wheels are in wheels_new." -# echo "You can now upload the patched wheels to PyPI." +# python3 -m twine upload --repository testpypi wheels_new/* --verbose From 0def3b1f766fac47b40edaddf3b2f50b55fba290 Mon Sep 17 00:00:00 2001 From: Mitchell Date: Tue, 2 Sep 2025 09:24:42 -0700 Subject: [PATCH 03/11] properly cd back so can transfer to wheels_new Signed-off-by: Mitchell --- scripts/patch-pypi.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/patch-pypi.sh b/scripts/patch-pypi.sh index 4ab4522c94f..747aecffe6c 100644 --- a/scripts/patch-pypi.sh +++ b/scripts/patch-pypi.sh @@ -50,8 +50,6 @@ curl -fsSL "https://pypi.org/pypi/${PACKAGE_NAME}/${ORIG_VER}/json" \ | xargs -n1 -P4 -I{} wget -c -P ${CUDAQ_METAPACKAGE_ORIG} {} tar -xvzf ${CUDAQ_METAPACKAGE_ORIG}/*.tar.gz -C ${TMP_DIR} -cd ${TMP_DIR} -ls -l ${TMP_DIR} echo ${NEW_VER} > ${TMP_DIR}/*/_version.txt cd ${TMP_DIR}/*/ @@ -59,7 +57,10 @@ cd ${TMP_DIR}/*/ sed -i '' 's/elif cuda_version < 13000:/elif cuda_version <= 13000:/' setup.py CUDAQ_META_WHEEL_BUILD=1 python3 -m build . --sdist -mv ${TMP_DIR}/*/dist/cudaq-*.tar.gz wheels_new +cd - + +file ${TMP_DIR}/*/dist/cudaq-*.tar.gz +mv -v ${TMP_DIR}/*/dist/cudaq-*.tar.gz wheels_new # upload cudaq metapackage with: # python3 -m twine upload --repository testpypi wheels_new/*/dist/cudaq-0.12.0.post2.tar.gz --verbose From 505cd0ed167266cb7f2466731f820e52b764cd63 Mon Sep 17 00:00:00 2001 From: Mitchell Date: Tue, 2 Sep 2025 10:50:46 -0700 Subject: [PATCH 04/11] use /tmp/ instead of mktemp This allows docker container to use the script. Signed-off-by: Mitchell --- scripts/patch-pypi.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/patch-pypi.sh b/scripts/patch-pypi.sh index 747aecffe6c..cc8edb5b765 100644 --- a/scripts/patch-pypi.sh +++ b/scripts/patch-pypi.sh @@ -32,7 +32,8 @@ if [ ${#missing[@]} -ne 0 ]; then fi # Make a temporary directory to work in -TMP_DIR="$(mktemp -d)" +TMP_DIR="$(/tmp/cudaq-scratch)" +mkdir -p ${TMP_DIR} echo "Building TMP_DIR in $TMP_DIR" echo "Using temporary directory: $TMP_DIR" mkdir -p wheels_new From ebee9f83796228dad5ce732377bfde504addbc55 Mon Sep 17 00:00:00 2001 From: Mitchell Date: Tue, 2 Sep 2025 10:53:32 -0700 Subject: [PATCH 05/11] fix script Signed-off-by: Mitchell --- scripts/patch-pypi.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/patch-pypi.sh b/scripts/patch-pypi.sh index cc8edb5b765..aea0688a350 100644 --- a/scripts/patch-pypi.sh +++ b/scripts/patch-pypi.sh @@ -32,7 +32,7 @@ if [ ${#missing[@]} -ne 0 ]; then fi # Make a temporary directory to work in -TMP_DIR="$(/tmp/cudaq-scratch)" +TMP_DIR="/tmp/cudaq-scratch" mkdir -p ${TMP_DIR} echo "Building TMP_DIR in $TMP_DIR" echo "Using temporary directory: $TMP_DIR" From 376683c210e8cdef10d3d44f8a5fcd8186c71380 Mon Sep 17 00:00:00 2001 From: Mitchell Date: Tue, 2 Sep 2025 11:28:18 -0700 Subject: [PATCH 06/11] make it work on non-mac Signed-off-by: Mitchell --- scripts/patch-pypi.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/patch-pypi.sh b/scripts/patch-pypi.sh index aea0688a350..1d4ea3aaf13 100644 --- a/scripts/patch-pypi.sh +++ b/scripts/patch-pypi.sh @@ -55,12 +55,11 @@ echo ${NEW_VER} > ${TMP_DIR}/*/_version.txt cd ${TMP_DIR}/*/ # MODIFY_ME2 - review and modify the source code here -sed -i '' 's/elif cuda_version < 13000:/elif cuda_version <= 13000:/' setup.py +sed -i 's/elif cuda_version < 13000:/elif cuda_version <= 13000:/' setup.py CUDAQ_META_WHEEL_BUILD=1 python3 -m build . --sdist cd - -file ${TMP_DIR}/*/dist/cudaq-*.tar.gz mv -v ${TMP_DIR}/*/dist/cudaq-*.tar.gz wheels_new # upload cudaq metapackage with: @@ -86,7 +85,7 @@ for package in cuda-quantum-cu12 cuda-quantum-cu11; do # --- Begin modifications # Update the version - sed -i '' "s/^Version: ${ORIG_VER}/Version: ${NEW_VER}/" $TMP_DIR/${PACKAGE_NAME_UNDER}-${ORIG_VER}/${PACKAGE_NAME_UNDER}-${ORIG_VER}.dist-info/METADATA + sed -i "s/^Version: ${ORIG_VER}/Version: ${NEW_VER}/" $TMP_DIR/${PACKAGE_NAME_UNDER}-${ORIG_VER}/${PACKAGE_NAME_UNDER}-${ORIG_VER}.dist-info/METADATA # MODIFY_ME2 - review and modify the METADATA file here # ... # --- End modifications From 7f466c85899aed832e647bfbf4fa8104d16b7bb8 Mon Sep 17 00:00:00 2001 From: Mitchell Date: Tue, 2 Sep 2025 11:29:38 -0700 Subject: [PATCH 07/11] add set -eu Signed-off-by: Mitchell --- scripts/patch-pypi.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/patch-pypi.sh b/scripts/patch-pypi.sh index 1d4ea3aaf13..7c69ff67dae 100644 --- a/scripts/patch-pypi.sh +++ b/scripts/patch-pypi.sh @@ -5,6 +5,8 @@ # the terms of the Apache License 2.0 which accompanies this distribution. # # ============================================================================ # +set -eu + # This script is used to patch the wheel metadata for a PyPI package. For now, # it is anticipated that one would use this script as a reference and update the # MODIFY_ME1 and MODIFY_ME2 sections before using it. From 48da1691825144fd6b5861a0de9a200a0241e30a Mon Sep 17 00:00:00 2001 From: Mitchell Date: Tue, 2 Sep 2025 12:03:51 -0700 Subject: [PATCH 08/11] set pipefail Signed-off-by: Mitchell --- scripts/patch-pypi.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/patch-pypi.sh b/scripts/patch-pypi.sh index 7c69ff67dae..9ef4c3bb7ef 100644 --- a/scripts/patch-pypi.sh +++ b/scripts/patch-pypi.sh @@ -5,7 +5,7 @@ # the terms of the Apache License 2.0 which accompanies this distribution. # # ============================================================================ # -set -eu +set -euo pipefail # This script is used to patch the wheel metadata for a PyPI package. For now, # it is anticipated that one would use this script as a reference and update the From f3fefbcc4c9294a7d2805f80983c83f96acc52e9 Mon Sep 17 00:00:00 2001 From: Mitchell Date: Tue, 2 Sep 2025 13:53:23 -0700 Subject: [PATCH 09/11] update logs Signed-off-by: Mitchell --- scripts/patch-pypi.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/patch-pypi.sh b/scripts/patch-pypi.sh index 9ef4c3bb7ef..d80b3f4f0ca 100644 --- a/scripts/patch-pypi.sh +++ b/scripts/patch-pypi.sh @@ -7,9 +7,9 @@ set -euo pipefail -# This script is used to patch the wheel metadata for a PyPI package. For now, +# This script is used to patch the cudaq pypi published packages. For now, # it is anticipated that one would use this script as a reference and update the -# MODIFY_ME1 and MODIFY_ME2 sections before using it. +# MODIFY_ME{1,2,3} sections before using it. # Note: you may need to run "python3 -m pip install -U wheel" first. @@ -70,7 +70,6 @@ mv -v ${TMP_DIR}/*/dist/cudaq-*.tar.gz wheels_new ### ------------------------------------------------- ### # modify cuda-quantum-cu* packages -mkdir -p wheels_new # cuda-quantum-cu* ships actual wheels, so we need to modify them for package in cuda-quantum-cu12 cuda-quantum-cu11; do @@ -88,7 +87,7 @@ for package in cuda-quantum-cu12 cuda-quantum-cu11; do # --- Begin modifications # Update the version sed -i "s/^Version: ${ORIG_VER}/Version: ${NEW_VER}/" $TMP_DIR/${PACKAGE_NAME_UNDER}-${ORIG_VER}/${PACKAGE_NAME_UNDER}-${ORIG_VER}.dist-info/METADATA - # MODIFY_ME2 - review and modify the METADATA file here + # MODIFY_ME3 - review and modify the METADATA file here # ... # --- End modifications From 62f0e2bbe1a3212fa70dae4d0cb2020ecb79a40c Mon Sep 17 00:00:00 2001 From: Mitchell Date: Tue, 2 Sep 2025 13:55:25 -0700 Subject: [PATCH 10/11] set to post0 Signed-off-by: Mitchell --- scripts/patch-pypi.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/patch-pypi.sh b/scripts/patch-pypi.sh index d80b3f4f0ca..b94b762c9d2 100644 --- a/scripts/patch-pypi.sh +++ b/scripts/patch-pypi.sh @@ -16,7 +16,7 @@ set -euo pipefail # MODIFY_ME1 - review and modify the following variables PACKAGE_NAME=cudaq ORIG_VER=0.12.0 -NEW_VER=0.12.0.post4 +NEW_VER=0.12.0.post0 # Ensure required commands are available missing=() From 34892162981cf2785992b84a142bd5136cba0917 Mon Sep 17 00:00:00 2001 From: Mitchell Date: Tue, 2 Sep 2025 14:48:57 -0700 Subject: [PATCH 11/11] use post1 Signed-off-by: Mitchell --- scripts/patch-pypi.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/patch-pypi.sh b/scripts/patch-pypi.sh index b94b762c9d2..661e9e5265f 100644 --- a/scripts/patch-pypi.sh +++ b/scripts/patch-pypi.sh @@ -16,7 +16,7 @@ set -euo pipefail # MODIFY_ME1 - review and modify the following variables PACKAGE_NAME=cudaq ORIG_VER=0.12.0 -NEW_VER=0.12.0.post0 +NEW_VER=0.12.0.post1 # Ensure required commands are available missing=()