From aef4036a729c066ab06b18369dcc573ac7f5a1cb Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Fri, 8 Nov 2024 19:14:37 +0100 Subject: [PATCH] Metapackage issues and torch install issues (#2368) Signed-off-by: Bettina Heim --- .github/workflows/python_metapackages.yml | 14 ++++++-------- .../applications/python/hybrid_qnns.ipynb | 4 ++-- python/cudaq/__init__.py | 2 +- python/metapackages/setup.py | 18 ++++++++++++++---- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/.github/workflows/python_metapackages.yml b/.github/workflows/python_metapackages.yml index 0521e80a31a..9817896badd 100644 --- a/.github/workflows/python_metapackages.yml +++ b/.github/workflows/python_metapackages.yml @@ -154,7 +154,7 @@ jobs: # autoremove is in an odd location that isn't found unless we search for it... autoremove="$python $($python -m pip show pip3-autoremove | grep -e 'Location: .*$' | cut -d ' ' -f2)/pip_autoremove.py" $python -m pip install pypiserver - server="$python $($python -m pip show pypiserver | grep -e 'Location: .*$' | cut -d ' ' -f2)/pypiserver_main__.py" + server="$python $($python -m pip show pypiserver | grep -e 'Location: .*$' | cut -d ' ' -f2)/pypiserver/__main__.py" $server run -p 8080 /tmp/packages & package_dep=`echo cuda-quantum${cuda_version_suffix:+-cu$cuda_version_suffix} | cut -d '-' -f1-2` @@ -195,14 +195,12 @@ jobs: fi - name: Test installation error + # FIXME: We actually don't give a proper install error if there are conflicting packages on the system... + if: matrix.cuda_version == '' run: | - #dnf install -y --nobest --setopt=install_weak_deps=False curl jq - #PACKAGE_JSON_URL="https://pypi.org/pypi/cuda-quantum/json" - #curl -L -s "$PACKAGE_JSON_URL" | jq -r '.releases | keys | .[]' - python=python${{ matrix.python_version }} $python -m pip install pypiserver - server="$python $($python -m pip show pypiserver | grep -e 'Location: .*$' | cut -d ' ' -f2)/pypiserver_main__.py" + server="$python $($python -m pip show pypiserver | grep -e 'Location: .*$' | cut -d ' ' -f2)/pypiserver/__main__.py" $server run -p 8080 /tmp/packages & case "${{ matrix.cuda_version }}" in @@ -216,7 +214,7 @@ jobs: $python -m pip install cuda-quantum-cu11==${{ inputs.cudaq_version }} \ --extra-index-url http://localhost:8080 set +e # continue on error - $python -m pip install cudaq==${{ inputs.cudaq_version }} \ + $python -m pip install cudaq==${{ inputs.cudaq_version }} -v \ --extra-index-url http://localhost:8080 set -e && check_package=cudaq ;; @@ -231,7 +229,7 @@ jobs: --extra-index-url http://localhost:8080 fi set +e # continue on error - $python -m pip install cudaq==${{ inputs.cudaq_version }} \ + $python -m pip install cudaq==${{ inputs.cudaq_version }} -v \ --extra-index-url http://localhost:8080 set -e && check_package=cudaq ;; diff --git a/docs/sphinx/applications/python/hybrid_qnns.ipynb b/docs/sphinx/applications/python/hybrid_qnns.ipynb index e3e68279a37..cc3f054e614 100644 --- a/docs/sphinx/applications/python/hybrid_qnns.ipynb +++ b/docs/sphinx/applications/python/hybrid_qnns.ipynb @@ -28,13 +28,13 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Install the relevant packages.\n", "\n", - "!pip install matplotlib==3.8.4 torch==2.2.0 torchvision==0.17.0 scikit-learn==1.4.2 -q" + "!pip install matplotlib==3.8.4 torch==2.0.1+cu118 torchvision==0.15.2+cu118 scikit-learn==1.4.2 -q --extra-index-url https://download.pytorch.org/whl/cu118" ] }, { diff --git a/python/cudaq/__init__.py b/python/cudaq/__init__.py index bfefe6bea04..81e63969c31 100644 --- a/python/cudaq/__init__.py +++ b/python/cudaq/__init__.py @@ -40,7 +40,7 @@ os.environ["CUDAQ_DYNLIBS"] += f":{cudart_path}" except: import importlib.util - package_spec = importlib.util.find_spec("cuda-quantum") + package_spec = importlib.util.find_spec(f"cuda-quantum-cu{cuda_major}") if not package_spec is None and not package_spec.loader is None: print("Could not find a suitable cuQuantum Python package.") pass diff --git a/python/metapackages/setup.py b/python/metapackages/setup.py index 46706207538..5d02ccfa3b1 100644 --- a/python/metapackages/setup.py +++ b/python/metapackages/setup.py @@ -6,7 +6,8 @@ # the terms of the Apache License 2.0 which accompanies this distribution. # # ============================================================================ # -import ctypes, pkg_resources, os, sys +import ctypes, os, sys +import importlib.util from setuptools import setup from typing import Optional @@ -105,10 +106,16 @@ def _infer_best_package() -> str: # Find the existing wheel installation installed = [] for pkg_suffix in ['', '-cu11', '-cu12']: + _log(f"Looking for existing installation of cuda-quantum{pkg_suffix}.") try: - pkg_resources.get_distribution(f"cuda-quantum{pkg_suffix}") - installed.append(f"cuda-quantum{pkg_suffix}") - except pkg_resources.DistributionNotFound: + package_spec = importlib.util.find_spec(f"cuda-quantum{pkg_suffix}") + if package_spec is None: + _log("No installation found.") + else: + installed.append(f"cuda-quantum{pkg_suffix}") + _log("Installation found.") + except: + _log("No installation found.") pass cuda_version = _get_cuda_version() @@ -122,10 +129,13 @@ def _infer_best_package() -> str: cudaq_bdist = 'cuda-quantum-cu12' else: raise Exception(f'Your CUDA version ({cuda_version}) is too new.') + _log(f"Identified {cudaq_bdist} as the best package.") # Disallow -cu11 & -cu12 wheels from coexisting conflicting = ", ".join((pkg for pkg in installed if pkg != cudaq_bdist)) + _log(f"Conflicting packages: {conflicting}") if conflicting != '': + _log("Abort.") raise Exception( f'You have a conflicting CUDA-Q version installed.' f'Please remove the following package(s): {conflicting}')