Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scvelo.tl.velocity_graph throws ValueError #1044

Closed
alexblaessle opened this issue May 2, 2023 · 8 comments
Closed

scvelo.tl.velocity_graph throws ValueError #1044

alexblaessle opened this issue May 2, 2023 · 8 comments
Labels
bug Something isn't working duplicate Duplicated issue

Comments

@alexblaessle
Copy link

Hi

I was trying to reproduce the intro tutorial, however, I am getting a ValueError when running scv.tl.velocity_graph(adata).

import scvelo as scv

adata=scv.datasets.pancreas()

scv.pp.filter_genes(adata, min_shared_counts=20)
scv.pp.normalize_per_cell(adata)
scv.pp.filter_genes_dispersion(adata, n_top_genes=2000)
scv.pp.log1p(adata)

scv.pp.filter_and_normalize(adata, min_shared_counts=20, n_top_genes=2000)
scv.pp.moments(adata, n_pcs=30, n_neighbors=30)

scv.tl.velocity(adata)

scv.tl.velocity_graph(adata)
Error output
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[10], line 1
----> 1 scv.tl.velocity_graph(adata)

File ~/venvs/scvelo/lib/python3.11/site-packages/scvelo/tools/velocity_graph.py:363, in velocity_graph(data, vkey, xkey, tkey, basis, n_neighbors, n_recurse_neighbors, random_neighbors_at_max, sqrt_transform, variance_stabilization, gene_subset, compute_uncertainties, approx, mode_neighbors, copy, n_jobs, backend)
    359 n_jobs = get_n_jobs(n_jobs=n_jobs)
    360 logg.info(
    361     f"computing velocity graph (using {n_jobs}/{os.cpu_count()} cores)", r=True
    362 )
--> 363 vgraph.compute_cosines(n_jobs=n_jobs, backend=backend)
    365 adata.uns[f"{vkey}_graph"] = vgraph.graph
    366 adata.uns[f"{vkey}_graph_neg"] = vgraph.graph_neg

File ~/venvs/scvelo/lib/python3.11/site-packages/scvelo/tools/velocity_graph.py:175, in VelocityGraph.compute_cosines(self, n_jobs, backend)
    172 n_obs = self.X.shape[0]
    174 # TODO: Use batches and vectorize calculation of dX in self._calculate_cosines
--> 175 res = parallelize(
    176     self._compute_cosines,
    177     range(self.X.shape[0]),
    178     n_jobs=n_jobs,
    179     unit="cells",
    180     backend=backend,
    181 )()
    182 uncertainties, vals, rows, cols = map(_flatten, zip(*res))
    184 vals = np.hstack(vals)

File ~/venvs/scvelo/lib/python3.11/site-packages/scvelo/core/_parallelize.py:138, in parallelize.<locals>.wrapper(*args, **kwargs)
    126     pbar, queue, thread = None, None, None
    128 res = Parallel(n_jobs=n_jobs, backend=backend)(
    129     delayed(callback)(
    130         *((i, cs) if use_ixs else (cs,)),
   (...)
    135     for i, cs in enumerate(collections)
    136 )
--> 138 res = np.array(res) if as_array else res
    139 if thread is not None:
    140     thread.join()

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (1, 4) + inhomogeneous part.
Versions
python 3.11.1

scvelo==0.2.5  scanpy==1.9.3  anndata==0.9.1  loompy==3.0.7  numpy==1.24.3  scipy==1.10.1  matplotlib==3.7.1  sklearn==1.2.2  pandas==2.0.1  
@alexblaessle alexblaessle added the bug Something isn't working label May 2, 2023
@alexblaessle
Copy link
Author

Ok, I did some more digging. Downgrading from numpy-1.24.3 to numpy-1.23.5 fixes the problem. However, not working with the latest numpy version.

@WeilerP
Copy link
Member

WeilerP commented May 16, 2023

Closing as duplicate of #1058.

@tobylanser
Copy link

@WeilerP I wrestled with this too. Tried downgrading to numpy==1.21.1 which didn't work, but 1.23.5 makes it run smoothly. Thanks!

@lzygenomics
Copy link

@alexblaessle I occur this bug too. Downgrading from numpy-1.24.3 to numpy-1.23.5 is working! Thank you! @WeilerP And I think maybe it is not totally duplicate of #1058, following your solution for #1058, the bug on scv.tl.recover_dynamics is fixed perfectly~ but the bug on scv.tl.velocity_graph still remain until downgrading numpy. Thanks!

@Tomzhangmx
Copy link

I occur this bug too. Manipulating numpy versions didn't work.

@Zodiac111111
Copy link

I changed numpy to 1.23.5, but it still not work. then I updated the TensorFlow 2, it suddenly worked. I don't know if this can fix the problem, just for your reference.

@liyiyuian
Copy link

I'm not reporting new errors; I just want to let people know changing to 1.23.5 makes it work for me.

@pyhell
Copy link

pyhell commented Mar 15, 2024

Hello,
For those that might have the same problem. I tried downgrading to numpy 1.23.5 and it did not work. I had Python 3.11 and had to go down to 3.8 for it to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate Duplicated issue
Projects
None yet
Development

No branches or pull requests

8 participants