theislab / scvelo

RNA Velocity generalized through dynamical modeling
https://scvelo.org
BSD 3-Clause "New" or "Revised" License
412 stars 102 forks source link

A task has failed to un-serialize. Please ensure that the arguments of the function are all picklable. #1257

Closed christophechu closed 3 months ago

christophechu commented 3 months ago

scv.tl.velocity_graph(adata,n_jobs=25) it works when n_jobs=1 BrokenProcessPool Traceback (most recent call last) Cell In[23], line 1 ----> 1 scv.tl.velocity_graph(adata,n_jobs=5)

File ~/miniforge3/envs/sc-python/lib/python3.9/site-packages/scvelo/tools/velocity_graph.py:373, 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) 369 n_jobs = get_n_jobs(n_jobs=n_jobs) 370 logg.info( 371 f"computing velocity graph (using {n_jobs}/{os.cpu_count()} cores)", r=True 372 ) --> 373 vgraph.compute_cosines(n_jobs=n_jobs, backend=backend) 375 adata.uns[f"{vkey}_graph"] = vgraph.graph 376 adata.uns[f"{vkey}_graph_neg"] = vgraph.graph_neg

File ~/miniforge3/envs/sc-python/lib/python3.9/site-packages/scvelo/tools/velocity_graph.py:185, in VelocityGraph.compute_cosines(self, n_jobs, backend) 182 n_obs = self.X.shape[0] 184 # TODO: Use batches and vectorize calculation of dX in self._calculate_cosines --> 185 res = parallelize( 186 self._compute_cosines, 187 range(self.X.shape[0]), 188 n_jobs=n_jobs, 189 unit="cells", 190 backend=backend, 191 as_array=False, 192 )() 193 uncertainties, vals, rows, cols = map(_flatten, zip(*res)) 195 vals = np.hstack(vals)

File ~/miniforge3/envs/sc-python/lib/python3.9/site-packages/scvelo/core/_parallelize.py:127, in parallelize..wrapper(*args, kwargs) 124 else: 125 pbar, queue, thread = None, None, None --> 127 res = Parallel(n_jobs=n_jobs, backend=backend)( 128 delayed(callback)( 129 ((i, cs) if use_ixs else (cs,)), 130 args, 131 kwargs, 132 queue=queue, 133 ) 134 for i, cs in enumerate(collections) 135 ) 137 res = np.array(res) if as_array else res 138 if thread is not None:

File ~/miniforge3/envs/sc-python/lib/python3.9/site-packages/joblib/parallel.py:2007, in Parallel.call(self, iterable) 2001 # The first item from the output is blank, but it makes the interpreter 2002 # progress until it enters the Try/Except block of the generator and 2003 # reaches the first yield statement. This starts the asynchronous 2004 # dispatch of the tasks to the workers. 2005 next(output) -> 2007 return output if self.return_generator else list(output)

File ~/miniforge3/envs/sc-python/lib/python3.9/site-packages/joblib/parallel.py:1650, in Parallel._get_outputs(self, iterator, pre_dispatch) 1647 yield 1649 with self._backend.retrieval_context(): -> 1650 yield from self._retrieve() 1652 except GeneratorExit: 1653 # The generator has been garbage collected before being fully 1654 # consumed. This aborts the remaining tasks if possible and warn 1655 # the user if necessary. 1656 self._exception = True

File ~/miniforge3/envs/sc-python/lib/python3.9/site-packages/joblib/parallel.py:1754, in Parallel._retrieve(self) 1747 while self._wait_retrieval(): 1748 1749 # If the callback thread of a worker has signaled that its task 1750 # triggered an exception, or if the retrieval loop has raised an 1751 # exception (e.g. GeneratorExit), exit the loop and surface the 1752 # worker traceback. 1753 if self._aborting: -> 1754 self._raise_error_fast() 1755 break 1757 # If the next job is not ready for retrieval yet, we just wait for 1758 # async callbacks to progress.

File ~/miniforge3/envs/sc-python/lib/python3.9/site-packages/joblib/parallel.py:1789, in Parallel._raise_error_fast(self) 1785 # If this error job exists, immediately raise the error by 1786 # calling get_result. This job might not exists if abort has been 1787 # called directly or if the generator is gc'ed. 1788 if error_job is not None: -> 1789 error_job.get_result(self.timeout)

File ~/miniforge3/envs/sc-python/lib/python3.9/site-packages/joblib/parallel.py:745, in BatchCompletionCallBack.get_result(self, timeout) 739 backend = self.parallel._backend 741 if backend.supports_retrieve_callback: 742 # We assume that the result has already been retrieved by the 743 # callback thread, and is stored internally. It's just waiting to 744 # be returned. --> 745 return self._return_or_raise() 747 # For other backends, the main thread needs to run the retrieval step. 748 try:

File ~/miniforge3/envs/sc-python/lib/python3.9/site-packages/joblib/parallel.py:763, in BatchCompletionCallBack._return_or_raise(self) 761 try: 762 if self.status == TASK_ERROR: --> 763 raise self._result 764 return self._result 765 finally:

BrokenProcessPool: A task has failed to un-serialize. Please ensure that the arguments of the function are all picklable.

WeilerP commented 3 months ago

I cannot reproduce the error. Please use the provided issue template as provided and include all information.