Skip to content

Commit 1f9b5ca

Browse files
authored
chore!: remove "rapids" flavor for louvain, umap, and neighbors (#4052)
1 parent 3fb43a0 commit 1f9b5ca

6 files changed

Lines changed: 10 additions & 113 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove `'rapids'` flavor for {func}`scanpy.pp.neighbors`, {func}`scanpy.tl.louvain`, {func}`scanpy.tl.umap` {smaller}`P Angerer`

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ louvain = [ "igraph", "louvain>=0.8.2", "setuptools" ]
9393
magic = [ "magic-impute>=2.0.4" ]
9494
paga = [ "igraph" ]
9595
plotting = [ "colour-science" ]
96-
# Neighbors acceleration
97-
rapids = [ "cudf>=0.9", "cugraph>=0.9", "cuml>=0.9" ]
9896
scanorama = [ "scanorama" ]
9997
scrublet = [ "scikit-image>=0.23.1" ]
10098
# highly_variable_genes method 'seurat_v3'

src/scanpy/neighbors/__init__.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,6 @@ def neighbors( # noqa: PLR0913
149149
:class:`~pynndescent.pynndescent_.PyNNDescentTransformer`
150150
`'pynndescent'`
151151
:class:`~pynndescent.pynndescent_.PyNNDescentTransformer`
152-
`'rapids'`
153-
A transformer based on :class:`cuml.neighbors.NearestNeighbors`.
154-
155-
.. deprecated:: 1.10.0
156-
Use :func:`rapids_singlecell.pp.neighbors` instead.
157152
metric
158153
A known metric’s name or a callable that returns a distance.
159154
If `distances` is given, this parameter is simply stored in `.uns` (see below),
@@ -749,15 +744,7 @@ def _handle_transformer(
749744
)
750745

751746
# Coerce `method` to 'gauss', 'umap', or 'jaccard'
752-
if method == "rapids":
753-
if transformer is not None:
754-
msg = "Can’t specify both `method = 'rapids'` and `transformer`."
755-
raise ValueError(msg)
756-
method = "umap"
757-
transformer = "rapids"
758-
elif (
759-
method not in (methods := get_literal_vals(_Method)) and method is not None
760-
):
747+
if method not in (methods := get_literal_vals(_Method)) and method is not None:
761748
msg = f"`method` needs to be one of {methods}."
762749
raise ValueError(msg)
763750

@@ -797,15 +784,6 @@ def _handle_transformer(
797784
n_iters=max(5, round(np.log2(self._adata.n_obs))),
798785
)
799786
transformer = PyNNDescentTransformer(**kwds)
800-
elif transformer == "rapids":
801-
msg = (
802-
"`transformer='rapids'` is deprecated. "
803-
"Use `rapids_singlecell.tl.neighbors` instead."
804-
)
805-
warn(msg, FutureWarning)
806-
from scanpy.neighbors._backends.rapids import RapidsKNNTransformer
807-
808-
transformer = RapidsKNNTransformer(**kwds)
809787
elif isinstance(transformer, str):
810788
msg = (
811789
f"Unknown transformer: {transformer}. "

src/scanpy/neighbors/_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
]
2222

2323
type _Method = Literal["umap", "gauss", "jaccard"]
24-
type _KnownTransformer = Literal["pynndescent", "sklearn", "rapids"]
24+
type _KnownTransformer = Literal["pynndescent", "sklearn"]
2525

2626
type _MetricFn = Callable[[np.ndarray, np.ndarray], float]
2727
# from sklearn.metrics.pairwise_distances.__doc__:

src/scanpy/tools/_louvain.py

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
from .. import _utils
1212
from .. import logging as logg
13-
from .._compat import deprecated, pkg_version, warn
14-
from .._utils import _choose_graph, _doc_params, dematrix
13+
from .._compat import deprecated, pkg_version
14+
from .._utils import _choose_graph, _doc_params
1515
from ._docs import (
1616
doc_adata,
1717
doc_adjacency,
@@ -54,7 +54,7 @@ def louvain( # noqa: PLR0912, PLR0913, PLR0915
5454
restrict_to: tuple[str, Sequence[str]] | None = None,
5555
key_added: str = "louvain",
5656
adjacency: CSBase | None = None,
57-
flavor: Literal["vtraag", "igraph", "rapids"] = "vtraag",
57+
flavor: Literal["vtraag", "igraph"] = "vtraag",
5858
directed: bool = True,
5959
use_weights: bool = False,
6060
partition_type: type[MutableVertexPartition] | None = None,
@@ -99,11 +99,6 @@ def louvain( # noqa: PLR0912, PLR0913, PLR0915
9999
Much more powerful than ``'igraph'``, and the default.
100100
``'igraph'``
101101
Built in ``igraph`` method.
102-
``'rapids'``
103-
GPU accelerated implementation.
104-
105-
.. deprecated:: 1.10.0
106-
Use :func:`rapids_singlecell.tl.louvain` instead.
107102
directed
108103
Interpret the ``adjacency`` matrix as directed graph?
109104
use_weights
@@ -180,44 +175,6 @@ def louvain( # noqa: PLR0912, PLR0913, PLR0915
180175
else:
181176
part = g.community_multilevel(weights=weights)
182177
groups = np.array(part.membership)
183-
elif flavor == "rapids":
184-
msg = (
185-
"`flavor='rapids'` is deprecated. "
186-
"Use `rapids_singlecell.tl.louvain` instead."
187-
)
188-
warn(msg, FutureWarning)
189-
# nvLouvain only works with undirected graphs,
190-
# and `adjacency` must have a directed edge in both directions
191-
import cudf
192-
import cugraph
193-
194-
offsets = cudf.Series(adjacency.indptr)
195-
indices = cudf.Series(adjacency.indices)
196-
if use_weights:
197-
sources, targets = adjacency.nonzero()
198-
weights = dematrix(adjacency[sources, targets]).ravel()
199-
weights = cudf.Series(weights)
200-
else:
201-
weights = None
202-
g = cugraph.Graph()
203-
204-
if hasattr(g, "add_adj_list"):
205-
g.add_adj_list(offsets, indices, weights)
206-
else:
207-
g.from_cudf_adjlist(offsets, indices, weights)
208-
209-
logg.info(' using the "louvain" package of rapids')
210-
if resolution is not None:
211-
louvain_parts, _ = cugraph.louvain(g, resolution=resolution)
212-
else:
213-
louvain_parts, _ = cugraph.louvain(g)
214-
groups = (
215-
louvain_parts
216-
.to_pandas()
217-
.sort_values("vertex")[["partition"]]
218-
.to_numpy()
219-
.ravel()
220-
)
221178
elif flavor == "taynaud":
222179
# this is deprecated
223180
import community

src/scanpy/tools/_umap.py

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from sklearn.utils import check_array
77

88
from .. import logging as logg
9-
from .._compat import warn
109
from .._docs import doc_rng
1110
from .._settings import settings
1211
from .._utils import NeighborsView, _doc_params
@@ -44,7 +43,7 @@ def umap( # noqa: PLR0913
4443
rng: SeedLike | RNGLike | None = None,
4544
a: float | None = None,
4645
b: float | None = None,
47-
method: Literal["umap", "rapids"] = "umap",
46+
method: Literal["umap"] = "umap",
4847
key_added: str | None = None,
4948
neighbors_key: str = "neighbors",
5049
copy: bool = False,
@@ -117,11 +116,6 @@ def umap( # noqa: PLR0913
117116
118117
``'umap'``
119118
Umap’s simplical set embedding.
120-
``'rapids'``
121-
GPU accelerated implementation.
122-
123-
.. deprecated:: 1.10.0
124-
Use :func:`rapids_singlecell.tl.umap` instead.
125119
key_added
126120
If not specified, the embedding is stored as
127121
:attr:`~anndata.AnnData.obsm`\ `['X_umap']` and the the parameters in
@@ -218,40 +212,9 @@ def umap( # noqa: PLR0913
218212
output_dens=False,
219213
verbose=settings.verbosity > 3,
220214
)
221-
elif method == "rapids":
222-
msg = (
223-
"`method='rapids'` is deprecated. Use `rapids_singlecell.tl.umap` instead."
224-
)
225-
warn(msg, FutureWarning)
226-
metric = neigh_params.get("metric", "euclidean")
227-
if metric != "euclidean":
228-
msg = (
229-
f"`sc.pp.neighbors` was called with `metric` {metric!r}, "
230-
"but umap `method` 'rapids' only supports the 'euclidean' metric."
231-
)
232-
raise ValueError(msg)
233-
from cuml import UMAP
234-
235-
n_neighbors = neighbors["params"]["n_neighbors"]
236-
n_epochs = (
237-
500 if maxiter is None else maxiter
238-
) # 0 is not a valid value for rapids, unlike original umap
239-
x_contiguous = np.ascontiguousarray(x, dtype=np.float32)
240-
umap = UMAP(
241-
n_neighbors=n_neighbors,
242-
n_components=n_components,
243-
n_epochs=n_epochs,
244-
learning_rate=alpha,
245-
init=init_pos,
246-
min_dist=min_dist,
247-
spread=spread,
248-
negative_sample_rate=negative_sample_rate,
249-
a=a,
250-
b=b,
251-
verbose=settings.verbosity > 3,
252-
random_state=_legacy_random_state(rng),
253-
)
254-
x_umap = umap.fit_transform(x_contiguous)
215+
else:
216+
msg = f"Unknown method {method}"
217+
raise ValueError(msg)
255218
adata.obsm[key_obsm] = x_umap # annotate samples with UMAP coordinates
256219
logg.info(
257220
" finished",

0 commit comments

Comments
 (0)