theislab / cellrank

CellRank: dynamics from multi-view single-cell data
https://cellrank.org
BSD 3-Clause "New" or "Revised" License
347 stars 46 forks source link

Identify states -> I get ValueError: Sparse implementation is only available for `method='krylov'`. #1115

Closed ryanhchung closed 1 year ago

ryanhchung commented 1 year ago

... Hi team,

I got stuck in macrostates part, which I got errors as follows:

g.fit(n_states=18, cluster_key="seurat_clusters")
g.plot_macrostates(which="all")

Computing Schur decomposition
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[37], line 1
----> 1 g.fit(n_states=18, cluster_key="seurat_clusters")
      2 g.plot_macrostates(which="all")

File ~/miniconda3/envs/r_env/lib/python3.11/site-packages/cellrank/estimators/terminal_states/_gpcca.py:563, in GPCCA.fit(self, n_states, n_cells, cluster_key, **kwargs)
    560 n = n_states if isinstance(n_states, int) else max(n_states)
    561 # call explicitly since `compute_macrostates` doesn't handle the case
    562 # when `minChi` is used for `n_states` and `self._gpcca` is uninitialized
--> 563 _ = self.compute_schur(n, **kwargs)
    564 return self.compute_macrostates(n_states=n_states, cluster_key=cluster_key, n_cells=n_cells)

File ~/miniconda3/envs/r_env/lib/python3.11/site-packages/cellrank/estimators/mixins/decomposition/_schur.py:175, in SchurMixin.compute_schur(self, n_components, initial_distribution, method, which, alpha, verbose)
    173 with (contextlib.nullcontext if verbose else contextlib.redirect_stdout)(io.StringIO()):
    174     try:
--> 175         self._gpcca._do_schur_helper(n_components)
    176     except ValueError as e:
    177         if "will split complex conjugate eigenvalues" not in str(e):

File ~/miniconda3/envs/r_env/lib/python3.11/site-packages/pygpcca/_gpcca.py:853, in GPCCA._do_schur_helper(self, m)
    851                 logging.info("Using pre-computed Schur decomposition")
    852 else:
--> 853     self._p_X, self._p_R, self._p_eigenvalues = _do_schur(
    854         self._P, eta=self._eta, m=m, z=self._z, method=self._method
    855     )

File ~/miniconda3/envs/r_env/lib/python3.11/site-packages/pygpcca/_gpcca.py:254, in _do_schur(P, eta, m, z, method, tol_krylov)
    251     P_bar = np.diag(np.sqrt(eta)).dot(P).dot(np.diag(1.0 / np.sqrt(eta)))
    253 # Make a Schur decomposition of P_bar and sort the Schur vectors (and form).
--> 254 R, Q, eigenvalues = sorted_schur(P_bar, m, z, method, tol_krylov=tol_krylov)  # Pbar!!!
    256 # Orthonormalize the sorted Schur vectors Q via modified Gram-Schmidt-orthonormalization,
    257 # if the (Schur)vectors aren't orthogonal!
    258 if not np.allclose(Q.T.dot(Q * eta[:, None]), np.eye(Q.shape[1]), rtol=1e6 * EPS, atol=1e6 * EPS):

File ~/miniconda3/envs/r_env/lib/python3.11/site-packages/pygpcca/_sorted_schur.py:373, in sorted_schur(P, m, z, method, tol_krylov)
    370         warnings.warn(NO_PETSC_SLEPC_FOUND_MSG)
    372 if method != "krylov" and issparse(P):
--> 373     raise ValueError("Sparse implementation is only available for `method='krylov'`.")
    375 # make sure we have enough eigenvalues to check for block splitting
    376 n = P.shape[0]

ValueError: Sparse implementation is only available for `method='krylov'`.

Do you know how to solve this? I really don't know what to do from this

Thanks!

Marius1311 commented 1 year ago

Hey, can you try re-installing CellRank to make sure you have version 2.0.0?

ryanhchung commented 1 year ago

Hey, can you try re-installing CellRank to make sure you have version 2.0.0?

Hi @Marius1311

I checked the version and it was 2.0.0.

Do you recommend installing development version using this command?

pip install git+https://github.com/theislab/cellrank.git@main

Thank you

ryanhchung commented 1 year ago

@Marius1311 Solved, thanks.

As you recommended, I uninstalled cellrank and reinstalled it, and it worked. Seems there was something wrong while installing.

Someone who suffers from similar problems should reinstall.