From 4c6912734bc5e4880641ea91109b6655e3073d65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B6lzer?= Date: Sun, 24 Nov 2024 15:15:27 +0100 Subject: [PATCH 1/7] Let user decide which cupy version to use Remove cupy from dependencies and add three extras where each requires a different cupy version: cupy (building from source), and the two prebuild cupy-cuda12x and cupy-cuda11x --- README.md | 10 ++++++++++ cupy_xarray/accessors.py | 7 ++++++- docs/index.md | 10 ++++++++++ pyproject.toml | 11 ++++++++++- 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e51cfe5..b6d56aa 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ Interface for using cupy in xarray, providing convenience accessors. ## Installation +> `cupy-xarray` will use an existing cupy installation, hence cupy needs to be installed manually! Please follow cupy's install instructions at or use the extras install + From anaconda: ```console @@ -34,6 +36,14 @@ The latest version from Github: pip install git+https://github.com/xarray-contrib/cupy-xarray.git ``` +Install cupy with extras: + +```console +pip install cupy-xarray["source"] # will install the cupy package, which will build cupy from source +pip install cupy-xarray["cuda11"] # will install the prebuild cupy-cuda11x package +pip install cupy-xarray["cuda12"] # will install the prebuild cupy-cuda12x package +``` + ## Usage ```python diff --git a/cupy_xarray/accessors.py b/cupy_xarray/accessors.py index 3f828bb..118a1ad 100644 --- a/cupy_xarray/accessors.py +++ b/cupy_xarray/accessors.py @@ -1,6 +1,11 @@ from typing import TYPE_CHECKING, Any +import warnings -import cupy as cp +try: + import cupy as cp +except ImportError as e: + warnings.warn("Cupy is not installed. cupy-xarray expects cupy to be manually installed. Please install cupy either by following the instructions at https://docs.cupy.dev/en/stable/install.html or by isntalling cupy-xaray with extras, e.g. `pip install cupy-xarray['source']`. More information can be found in the Readme or at the cupy-xarray documentation.", ImportWarning) + raise e from xarray import ( DataArray, Dataset, diff --git a/docs/index.md b/docs/index.md index fdea96c..6f61225 100644 --- a/docs/index.md +++ b/docs/index.md @@ -16,6 +16,8 @@ CuPy-Xarray is a Python library that leverages [CuPy](https://cupy.dev/), a GPU ## Installation +> `cupy-xarray` will use an existing cupy installation, hence cupy needs to be installed manually! Please follow cupy's install instructions at or use the extras install + CuPy-Xarray can be installed using `pip` or `conda`: From Conda Forge: @@ -37,6 +39,14 @@ The latest version from Github: pip install git+https://github.com/xarray-contrib/cupy-xarray.git ``` +Install cupy with extras: + +```console +pip install cupy-xarray["source"] # will install the cupy package, which will build cupy from source +pip install cupy-xarray["cuda11"] # will install the prebuild cupy-cuda11x package +pip install cupy-xarray["cuda12"] # will install the prebuild cupy-cuda12x package +``` + ## Acknowledgements Large parts of this documentations comes from [SciPy 2023 Xarray on GPUs tutorial](https://negin513.github.io/cupy-xarray-tutorials/README.html) and [this NCAR tutorial to GPUs](https://github.com/NCAR/GPU_workshop/tree/workshop/13_CuPyAndLegate). diff --git a/pyproject.toml b/pyproject.toml index be870da..96b6820 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,6 @@ classifiers = [ ] dynamic = ["version"] dependencies = [ - "cupy", "xarray>=2024.02.0", ] @@ -24,6 +23,16 @@ test = [ "dask", "pytest", ] +source = [ + "cupy" +] +cuda12 = [ + "cupy-cuda12x", +] +cuda11 = [ + "cupy-cuda11x", +] + [tool.ruff] line-length = 100 # E501 (line-too-long) From fd870ee1f5c0923278de3f029eb0474c3cf9333d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 24 Nov 2024 14:17:30 +0000 Subject: [PATCH 2/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- cupy_xarray/accessors.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cupy_xarray/accessors.py b/cupy_xarray/accessors.py index 118a1ad..956e6b4 100644 --- a/cupy_xarray/accessors.py +++ b/cupy_xarray/accessors.py @@ -1,10 +1,13 @@ -from typing import TYPE_CHECKING, Any import warnings +from typing import TYPE_CHECKING, Any try: import cupy as cp except ImportError as e: - warnings.warn("Cupy is not installed. cupy-xarray expects cupy to be manually installed. Please install cupy either by following the instructions at https://docs.cupy.dev/en/stable/install.html or by isntalling cupy-xaray with extras, e.g. `pip install cupy-xarray['source']`. More information can be found in the Readme or at the cupy-xarray documentation.", ImportWarning) + warnings.warn( + "Cupy is not installed. cupy-xarray expects cupy to be manually installed. Please install cupy either by following the instructions at https://docs.cupy.dev/en/stable/install.html or by isntalling cupy-xaray with extras, e.g. `pip install cupy-xarray['source']`. More information can be found in the Readme or at the cupy-xarray documentation.", + ImportWarning, + ) raise e from xarray import ( DataArray, From 811dd0a79946ddb2bfc9200966ee8f30a4d15704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B6lzer?= Date: Sun, 24 Nov 2024 15:59:07 +0100 Subject: [PATCH 3/7] Fix ruff B028 and E501 --- cupy_xarray/accessors.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cupy_xarray/accessors.py b/cupy_xarray/accessors.py index 956e6b4..da1f30f 100644 --- a/cupy_xarray/accessors.py +++ b/cupy_xarray/accessors.py @@ -5,8 +5,12 @@ import cupy as cp except ImportError as e: warnings.warn( - "Cupy is not installed. cupy-xarray expects cupy to be manually installed. Please install cupy either by following the instructions at https://docs.cupy.dev/en/stable/install.html or by isntalling cupy-xaray with extras, e.g. `pip install cupy-xarray['source']`. More information can be found in the Readme or at the cupy-xarray documentation.", + "Cupy is not installed. cupy-xarray expects cupy to be manually installed. Please install " + "cupy either by following the instructions at https://docs.cupy.dev/en/stable/install.html " + "or by isntalling cupy-xaray with extras, e.g. `pip install cupy-xarray['source']`. More " + "information can be found in the Readme or at the cupy-xarray documentation.", ImportWarning, + stacklevel=2, ) raise e from xarray import ( From 5b168bd098fed9faa47b5aee18f5ffe54aa33d86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B6lzer?= Date: Mon, 25 Nov 2024 13:13:33 +0100 Subject: [PATCH 4/7] Fix typo Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b6d56aa..642a5f5 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,8 @@ Install cupy with extras: ```console pip install cupy-xarray["source"] # will install the cupy package, which will build cupy from source -pip install cupy-xarray["cuda11"] # will install the prebuild cupy-cuda11x package -pip install cupy-xarray["cuda12"] # will install the prebuild cupy-cuda12x package +pip install cupy-xarray["cuda11"] # will install the prebuilt cupy-cuda11x package +pip install cupy-xarray["cuda12"] # will install the prebuilt cupy-cuda12x package ``` ## Usage From 2654ed16756595fc2d0ca16141d750617e5ba3f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B6lzer?= Date: Mon, 25 Nov 2024 13:13:40 +0100 Subject: [PATCH 5/7] Fix typo Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- cupy_xarray/accessors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cupy_xarray/accessors.py b/cupy_xarray/accessors.py index da1f30f..7baa9ce 100644 --- a/cupy_xarray/accessors.py +++ b/cupy_xarray/accessors.py @@ -7,7 +7,7 @@ warnings.warn( "Cupy is not installed. cupy-xarray expects cupy to be manually installed. Please install " "cupy either by following the instructions at https://docs.cupy.dev/en/stable/install.html " - "or by isntalling cupy-xaray with extras, e.g. `pip install cupy-xarray['source']`. More " + "or by installing cupy-xaray with extras, e.g. `pip install cupy-xarray['source']`. More " "information can be found in the Readme or at the cupy-xarray documentation.", ImportWarning, stacklevel=2, From f8185c4f791975a0dfbd4e53bd77f34918f0e070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B6lzer?= Date: Mon, 25 Nov 2024 13:13:50 +0100 Subject: [PATCH 6/7] Fix typo Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- docs/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index 6f61225..3488dfa 100644 --- a/docs/index.md +++ b/docs/index.md @@ -43,8 +43,8 @@ Install cupy with extras: ```console pip install cupy-xarray["source"] # will install the cupy package, which will build cupy from source -pip install cupy-xarray["cuda11"] # will install the prebuild cupy-cuda11x package -pip install cupy-xarray["cuda12"] # will install the prebuild cupy-cuda12x package +pip install cupy-xarray["cuda11"] # will install the prebuilt cupy-cuda11x package +pip install cupy-xarray["cuda12"] # will install the prebuilt cupy-cuda12x package ``` ## Acknowledgements From 90c962ef13b043d36927fb6dfb7fa42ac566f721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B6lzer?= Date: Mon, 25 Nov 2024 15:07:50 +0100 Subject: [PATCH 7/7] Remove cupy install option via extras --- README.md | 10 +--------- cupy_xarray/accessors.py | 4 +--- docs/index.md | 10 +--------- pyproject.toml | 10 ---------- 4 files changed, 3 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 642a5f5..d62ade6 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Interface for using cupy in xarray, providing convenience accessors. ## Installation -> `cupy-xarray` will use an existing cupy installation, hence cupy needs to be installed manually! Please follow cupy's install instructions at or use the extras install +> `cupy-xarray` will use an existing cupy installation, hence cupy needs to be installed manually! Please follow cupy's install instructions at . From anaconda: @@ -36,14 +36,6 @@ The latest version from Github: pip install git+https://github.com/xarray-contrib/cupy-xarray.git ``` -Install cupy with extras: - -```console -pip install cupy-xarray["source"] # will install the cupy package, which will build cupy from source -pip install cupy-xarray["cuda11"] # will install the prebuilt cupy-cuda11x package -pip install cupy-xarray["cuda12"] # will install the prebuilt cupy-cuda12x package -``` - ## Usage ```python diff --git a/cupy_xarray/accessors.py b/cupy_xarray/accessors.py index 7baa9ce..b26ee58 100644 --- a/cupy_xarray/accessors.py +++ b/cupy_xarray/accessors.py @@ -6,9 +6,7 @@ except ImportError as e: warnings.warn( "Cupy is not installed. cupy-xarray expects cupy to be manually installed. Please install " - "cupy either by following the instructions at https://docs.cupy.dev/en/stable/install.html " - "or by installing cupy-xaray with extras, e.g. `pip install cupy-xarray['source']`. More " - "information can be found in the Readme or at the cupy-xarray documentation.", + "cupy by following the instructions at https://docs.cupy.dev/en/stable/install.html.", ImportWarning, stacklevel=2, ) diff --git a/docs/index.md b/docs/index.md index 3488dfa..56f1995 100644 --- a/docs/index.md +++ b/docs/index.md @@ -16,7 +16,7 @@ CuPy-Xarray is a Python library that leverages [CuPy](https://cupy.dev/), a GPU ## Installation -> `cupy-xarray` will use an existing cupy installation, hence cupy needs to be installed manually! Please follow cupy's install instructions at or use the extras install +> `cupy-xarray` will use an existing cupy installation, hence cupy needs to be installed manually! Please follow cupy's install instructions at . CuPy-Xarray can be installed using `pip` or `conda`: @@ -39,14 +39,6 @@ The latest version from Github: pip install git+https://github.com/xarray-contrib/cupy-xarray.git ``` -Install cupy with extras: - -```console -pip install cupy-xarray["source"] # will install the cupy package, which will build cupy from source -pip install cupy-xarray["cuda11"] # will install the prebuilt cupy-cuda11x package -pip install cupy-xarray["cuda12"] # will install the prebuilt cupy-cuda12x package -``` - ## Acknowledgements Large parts of this documentations comes from [SciPy 2023 Xarray on GPUs tutorial](https://negin513.github.io/cupy-xarray-tutorials/README.html) and [this NCAR tutorial to GPUs](https://github.com/NCAR/GPU_workshop/tree/workshop/13_CuPyAndLegate). diff --git a/pyproject.toml b/pyproject.toml index 96b6820..d98b3fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,16 +23,6 @@ test = [ "dask", "pytest", ] -source = [ - "cupy" -] -cuda12 = [ - "cupy-cuda12x", -] -cuda11 = [ - "cupy-cuda11x", -] - [tool.ruff] line-length = 100 # E501 (line-too-long)