scverse / rapids_singlecell

Rapids_singlecell: A GPU-accelerated tool for scRNA analysis. Offers seamless scverse compatibility for efficient single-cell data processing and analysis.
https://rapids-singlecell.readthedocs.io/
MIT License
140 stars 19 forks source link

[BUG] Leiden does not work with neighborhood graph generated with algos `ivfpq` or `cagra` #142

Closed grst closed 6 months ago

grst commented 6 months ago

Describe the bug Running tl.leiden after pp.neighbors with algo="ivfpq" or algo="cagra" fails with

non-success value returned from cugraph_sg_graph_create_from_csr(): CUGRAPH_UNKNOWN_ERROR cuGraph failure at file=/opt/conda/conda-bld/work/cpp/src/structure/create_graph_from_edgelist_impl.cuh line=903: Invalid input arguments: graph_properties.is_symmetric is true but the input edge list is not symmetric.
Obtained 64 stack frames

It works with ivfflat and (presumably) brute (didn't have time to test the latter).

Stacktrace ```pytb --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) Cell In[19], line 1 ----> 1 rsc.tl.leiden(adata) File /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/lib/python3.10/site-packages/rapids_singlecell/tools/_clustering.py:109, in leiden(adata, resolution, random_state, restrict_to, key_added, adjacency, n_iterations, use_weights, neighbors_key, obsp, copy) 105 weights = None 107 g = Graph() --> 109 g.from_cudf_adjlist(offsets, indices, weights) 111 # Cluster 112 leiden_parts, _ = culeiden( 113 g, 114 resolution=resolution, 115 random_state=random_state, 116 max_iter=n_iterations, 117 ) File /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/lib/python3.10/site-packages/cugraph/structure/graph_classes.py:271, in Graph.from_cudf_adjlist(self, offset_col, index_col, value_col, renumber, store_transposed) 269 elif self._Impl.edgelist is not None or self._Impl.adjlist is not None: 270 raise RuntimeError("Graph already has values") --> 271 self._Impl._simpleGraphImpl__from_adjlist(offset_col, index_col, value_col) File /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/lib/python3.10/site-packages/cugraph/structure/graph_implementation/simpleGraph.py:547, in simpleGraphImpl.__from_adjlist(self, offset_col, index_col, value_col, renumber, store_transposed) 545 if value_col is not None: 546 self.properties.weighted = True --> 547 self._make_plc_graph( 548 value_col=value_col, store_transposed=store_transposed, renumber=renumber 549 ) 551 if self.batch_enabled: 552 self._replicate_adjlist() File /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/lib/python3.10/site-packages/cugraph/structure/graph_implementation/simpleGraph.py:1162, in simpleGraphImpl._make_plc_graph(self, value_col, store_transposed, renumber, drop_multi_edges) 1154 id_col = id_col.astype("int64") 1155 warnings.warn( 1156 f"Vertex type is int64 but edge id type is {id_col.dtype}" 1157 ", automatically casting edge id type to int64. " 1158 "This may cause extra memory usage. Consider passing" 1159 " a int64 list of edge ids instead." 1160 ) -> 1162 self._plc_graph = SGGraph( 1163 resource_handle=ResourceHandle(), 1164 graph_properties=graph_props, 1165 src_or_offset_array=src_or_offset_array, 1166 dst_or_index_array=dst_or_index_array, 1167 weight_array=weight_col, 1168 edge_id_array=id_col, 1169 edge_type_array=type_col, 1170 store_transposed=store_transposed, 1171 renumber=renumber, 1172 do_expensive_check=True, 1173 input_array_format=input_array_format, 1174 drop_multi_edges=drop_multi_edges, 1175 ) File graphs.pyx:243, in pylibcugraph.graphs.SGGraph.__cinit__() File utils.pyx:53, in pylibcugraph.utils.assert_success() RuntimeError: non-success value returned from cugraph_sg_graph_create_from_csr(): CUGRAPH_UNKNOWN_ERROR cuGraph failure at file=/opt/conda/conda-bld/work/cpp/src/structure/create_graph_from_edgelist_impl.cuh line=903: Invalid input arguments: graph_properties.is_symmetric is true but the input edge list is not symmetric. Obtained 64 stack frames #0 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/lib/python3.10/site-packages/cugraph/structure/../../../../libcugraph.so(+0x931574) [0x2b4023ee9574] #1 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/lib/python3.10/site-packages/cugraph/structure/../../../../libcugraph.so(+0x9b7fbd) [0x2b4023f6ffbd] #2 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/lib/python3.10/site-packages/cugraph/structure/../../../../libcugraph.so(_ZN7cugraph71_GLOBAL__N__9e67c577_32_create_graph_from_edgelist_sg_cu_82f3895c_1374131create_graph_from_edgelist_implIiifiiLb0ELb0EEENSt9enable_ifIXntT5_ESt5tupleIJNS_7graph_tIT_T0_XT4_EXT5_EvEESt8optionalINS_15edge_property_tINS_12graph_view_tIS5_S6_XT4_EXT5_EvEET1_EEES8_INS9_ISB_T2_EEES8_INS9_ISB_T3_EEES8_IN3rmm14device_uvectorIS5_EEEEEE4typeERKN4raft8handle_tEOSO_OSN_SX_OS8_INSM_ISC_EEEOS8_INSM_ISF_EEEOS8_INSM_ISI_EEENS_18graph_properties_tEbb+0x3c6c) [0x2b4026cdf26c] #3 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/lib/python3.10/site-packages/cugraph/structure/../../../../libcugraph.so(_ZN7cugraph26create_graph_from_edgelistIiifiiLb0ELb0EEESt5tupleIJNS_7graph_tIT_T0_XT4_EXT5_EvEESt8optionalINS_15edge_property_tINS_12graph_view_tIS3_S4_XT4_EXT5_EvEET1_EEES6_INS7_IS9_T2_EEES6_INS7_IS9_T3_EEES6_IN3rmm14device_uvectorIS3_EEEEERKN4raft8handle_tEOSM_OSL_ST_OS6_INSK_ISA_EEEOS6_INSK_ISD_EEEOS6_INSK_ISG_EEENS_18graph_properties_tEbb+0x28) [0x2b4026ce0108] #4 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/lib/python3.10/site-packages/pylibcugraph/../../../libcugraph_c.so(+0xdb12d) [0x2b3eb798612d] #5 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/lib/python3.10/site-packages/pylibcugraph/../../../libcugraph_c.so(cugraph_graph_create_sg_from_csr+0x1b5) [0x2b3eb79874e5] #6 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/lib/python3.10/site-packages/pylibcugraph/graphs.cpython-310-x86_64-linux-gnu.so(+0x10a8f) [0x2b3d7f967a8f] #7 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/lib/python3.10/site-packages/pylibcugraph/graphs.cpython-310-x86_64-linux-gnu.so(+0x12e8d) [0x2b3d7f969e8d] #8 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyObject_MakeTpCall+0x199) [0x55db79e878a9] #9 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyEval_EvalFrameDefault+0x56e0) [0x55db79e83af0] #10 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(+0x150402) [0x55db79e9a402] #11 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyEval_EvalFrameDefault+0x13cc) [0x55db79e7f7dc] #12 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyFunction_Vectorcall+0x6c) [0x55db79e8e8cc] #13 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyEval_EvalFrameDefault+0x72c) [0x55db79e7eb3c] #14 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(+0x150402) [0x55db79e9a402] #15 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyEval_EvalFrameDefault+0x4c12) [0x55db79e83022] #16 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyFunction_Vectorcall+0x6c) [0x55db79e8e8cc] #17 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyEval_EvalFrameDefault+0x4c12) [0x55db79e83022] #18 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(+0x1d7870) [0x55db79f21870] #19 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(PyEval_EvalCode+0x87) [0x55db79f217b7] #20 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(+0x1de9ba) [0x55db79f289ba] #21 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(+0x144a93) [0x55db79e8ea93] #22 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyEval_EvalFrameDefault+0x320) [0x55db79e7e730] #23 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(+0x1e0fe4) [0x55db79f2afe4] #24 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyEval_EvalFrameDefault+0x1bc0) [0x55db79e7ffd0] #25 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(+0x1e0fe4) [0x55db79f2afe4] #26 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyEval_EvalFrameDefault+0x1bc0) [0x55db79e7ffd0] #27 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(+0x1e0fe4) [0x55db79f2afe4] #28 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(+0x1f55f7) [0x55db79f3f5f7] #29 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(+0x14f3bd) [0x55db79e993bd] #30 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyEval_EvalFrameDefault+0x72c) [0x55db79e7eb3c] #31 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyFunction_Vectorcall+0x6c) [0x55db79e8e8cc] #32 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyEval_EvalFrameDefault+0x320) [0x55db79e7e730] #33 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyFunction_Vectorcall+0x6c) [0x55db79e8e8cc] #34 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyEval_EvalFrameDefault+0x72c) [0x55db79e7eb3c] #35 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(+0x150402) [0x55db79e9a402] #36 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(PyObject_Call+0xbc) [0x55db79e9ad9c] #37 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyEval_EvalFrameDefault+0x2d84) [0x55db79e81194] #38 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(+0x150402) [0x55db79e9a402] #39 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyEval_EvalFrameDefault+0x13cc) [0x55db79e7f7dc] #40 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(+0x1e0fe4) [0x55db79f2afe4] #41 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyEval_EvalFrameDefault+0x1bc0) [0x55db79e7ffd0] #42 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(+0x1e0fe4) [0x55db79f2afe4] #43 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyEval_EvalFrameDefault+0x1bc0) [0x55db79e7ffd0] #44 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(+0x1e0fe4) [0x55db79f2afe4] #45 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyEval_EvalFrameDefault+0x1bc0) [0x55db79e7ffd0] #46 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(+0x1e0fe4) [0x55db79f2afe4] #47 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyEval_EvalFrameDefault+0x1bc0) [0x55db79e7ffd0] #48 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(+0x1e0fe4) [0x55db79f2afe4] #49 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyEval_EvalFrameDefault+0x1bc0) [0x55db79e7ffd0] #50 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(+0x1e0fe4) [0x55db79f2afe4] #51 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/lib/python3.10/lib-dynload/_asyncio.cpython-310-x86_64-linux-gnu.so(+0x7bf6) [0x2b3b68f24bf6] #52 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(+0x143d2a) [0x55db79e8dd2a] #53 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(+0x25f22c) [0x55db79fa922c] #54 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(+0xfda7b) [0x55db79e47a7b] #55 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(+0x13c1b3) [0x55db79e861b3] #56 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyEval_EvalFrameDefault+0x5d5d) [0x55db79e8416d] #57 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyFunction_Vectorcall+0x6c) [0x55db79e8e8cc] #58 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyEval_EvalFrameDefault+0x72c) [0x55db79e7eb3c] #59 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyFunction_Vectorcall+0x6c) [0x55db79e8e8cc] #60 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyEval_EvalFrameDefault+0x72c) [0x55db79e7eb3c] #61 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyFunction_Vectorcall+0x6c) [0x55db79e8e8cc] #62 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyEval_EvalFrameDefault+0x72c) [0x55db79e7eb3c] #63 in /cfs/sturmgre/conda/envs/1403-0001_rapids-singlecell-2402/bin/python3.10(_PyFunction_Vectorcall+0x6c) [0x55db79e8e8cc] ```

Steps/Code to reproduce bug Wanted to make a repex, but got stuck due to #141

Expected behavior Leiden works independent on how the neighborhood graph was computed.

Environment details (please complete the following information): See #141

Intron7 commented 6 months ago

@grst this works for me.

import scanpy as sc
import rapids_singlecell as rsc

adata = sc.datasets.pbmc3k().copy()
sc.pp.filter_genes(adata, min_cells=1)
sc.pp.normalize_total(adata)
sc.pp.log1p(adata)
rsc.pp.pca(adata)
rsc.pp.neighbors(adata,algorithm="ivfpq")#carga
rsc.tl.leiden(adata)

I also used a bigger dataset (~200000 cells ). There it also worked.