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

ValueError in tabula_sapiens_tutorial.ipynb #61

Open
juanduphd opened this issue Jan 3, 2025 · 4 comments
Open

ValueError in tabula_sapiens_tutorial.ipynb #61

juanduphd opened this issue Jan 3, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@juanduphd
Copy link

Report

Hi,
I was trying out this notebook: https://github.com/YosefLab/popV/blob/main/docs/notebooks/tabula_sapiens_tutorial.ipynb, but I got stuck at this code block:

from popv.annotation import annotate_data
annotate_data(adata, save_path=f"{output_folder}/popv_output")

With this error:
ValueError: The number of threads must be between 1 and 2

I am using the example data: tmp_testing/LCA.h5ad

Any suggestions on how to overcome this issue?

Thanks,
Juan

Version information

No response

@juanduphd juanduphd added the bug Something isn't working label Jan 3, 2025
@canergen
Copy link
Member

canergen commented Jan 3, 2025

Hi, can you paste the full error message? Thanks. Can you also give it a try on Colab? It should be fine there.

@juanduphd
Copy link
Author

Thanks for your quick reply. I am running it on the colab (https://colab.research.google.com/github/YosefLab/PopV/blob/main/docs/notebooks/tabula_sapiens_tutorial.ipynb) and I didn't change any of the code:

Here is the full error message:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
[<ipython-input-19-4ee413451442>](https://localhost:8080/#) in <cell line: 3>()
      1 from popv.annotation import annotate_data
      2 
----> 3 annotate_data(adata, save_path=f"{output_folder}/popv_output")

11 frames
[/usr/local/lib/python3.10/dist-packages/popv/annotation.py](https://localhost:8080/#) in annotate_data(adata, methods, save_path, methods_kwargs)
     61         current_method = getattr(algorithms, method)(**methods_kwargs.pop(method, {}))
     62         current_method.compute_integration(adata)
---> 63         current_method.predict(adata)
     64         current_method.compute_embedding(adata)
     65         all_prediction_keys += [current_method.result_key]

[/usr/local/lib/python3.10/dist-packages/popv/algorithms/_celltypist.py](https://localhost:8080/#) in predict(self, adata)
     58         if adata.uns["_prediction_mode"] == "fast":
     59             self.classifier_dict["majority_voting"] = False
---> 60         predictions = celltypist.annotate(
     61             adata,
     62             model=adata.uns["_save_path_trained_models"] + "celltypist.pkl",

[/usr/local/lib/python3.10/dist-packages/celltypist/annotate.py](https://localhost:8080/#) in annotate(filename, model, transpose_input, gene_file, cell_file, mode, p_thres, majority_voting, over_clustering, use_GPU, min_prop)
     91     #over clustering
     92     if over_clustering is None:
---> 93         over_clustering = clf.over_cluster(use_GPU = use_GPU)
     94         predictions.adata = clf.adata
     95     elif isinstance(over_clustering, str):

[/usr/local/lib/python3.10/dist-packages/celltypist/classifier.py](https://localhost:8080/#) in over_cluster(self, resolution, use_GPU)
    435             logger.info("👀 Can not detect a neighborhood graph, will construct one before the over-clustering")
    436             adata = self.adata.copy()
--> 437             self.adata.obsm['X_pca'], self.adata.obsp['connectivities'], self.adata.obsp['distances'], self.adata.uns['neighbors'] = Classifier._construct_neighbor_graph(adata, use_GPU)
    438         else:
    439             logger.info("👀 Detected a neighborhood graph in the input object, will run over-clustering on the basis of it")

[/usr/local/lib/python3.10/dist-packages/celltypist/classifier.py](https://localhost:8080/#) in _construct_neighbor_graph(adata, use_GPU)
    408             fsc.pp.scale(adata, max_value=10)
    409             fsc.pp.pca(adata, n_comps=50)
--> 410         fsc.pp.neighbors(adata, n_neighbors=10, n_pcs=50)
    411         return adata.obsm['X_pca'], adata.obsp['connectivities'], adata.obsp['distances'], adata.uns['neighbors']
    412 

[/usr/local/lib/python3.10/dist-packages/scanpy/neighbors/__init__.py](https://localhost:8080/#) in neighbors(adata, n_neighbors, n_pcs, use_rep, knn, method, transformer, metric, metric_kwds, random_state, key_added, copy)
    189         adata._init_as_actual(adata.copy())
    190     neighbors = Neighbors(adata)
--> 191     neighbors.compute_neighbors(
    192         n_neighbors,
    193         n_pcs=n_pcs,

[/usr/local/lib/python3.10/dist-packages/scanpy/neighbors/__init__.py](https://localhost:8080/#) in compute_neighbors(self, n_neighbors, n_pcs, use_rep, knn, method, transformer, metric, metric_kwds, random_state)
    571         self.knn = knn
    572         X = _choose_representation(self._adata, use_rep=use_rep, n_pcs=n_pcs)
--> 573         self._distances = transformer.fit_transform(X)
    574         knn_indices, knn_distances = _get_indices_distances_from_sparse_matrix(
    575             self._distances, n_neighbors

[/usr/local/lib/python3.10/dist-packages/pynndescent/pynndescent_.py](https://localhost:8080/#) in fit_transform(self, X, y, **fit_params)
   2254             The diagonal is always explicit.
   2255         """
-> 2256         self.fit(X, compress_index=False)
   2257         result = self.transform(X=None)
   2258 

[/usr/local/lib/python3.10/dist-packages/pynndescent/pynndescent_.py](https://localhost:8080/#) in fit(self, X, compress_index)
   2172         effective_n_neighbors = self.n_neighbors + 1
   2173 
-> 2174         self.index_ = NNDescent(
   2175             X,
   2176             metric=self.metric,

[/usr/local/lib/python3.10/dist-packages/pynndescent/pynndescent_.py](https://localhost:8080/#) in __init__(self, data, metric, metric_kwds, n_neighbors, n_trees, leaf_size, pruning_degree_multiplier, diversify_prob, n_search_trees, tree_init, init_graph, init_dist, random_state, low_memory, max_candidates, max_rptree_depth, n_iters, delta, n_jobs, compressed, parallel_batch_queries, verbose)
    817         self._original_num_threads = numba.get_num_threads()
    818         if self.n_jobs != -1 and self.n_jobs is not None:
--> 819             numba.set_num_threads(self.n_jobs)
    820 
    821         if isspmatrix_csr(self._raw_data):

[/usr/local/lib/python3.10/dist-packages/numba/np/ufunc/parallel.py](https://localhost:8080/#) in set_num_threads(n)
    608     if not isinstance(n, (int, np.integer)):
    609         raise TypeError("The number of threads specified must be an integer")
--> 610     snt_check(n)
    611     _set_num_threads(n)
    612 

[/usr/local/lib/python3.10/dist-packages/numba/np/ufunc/parallel.py](https://localhost:8080/#) in snt_check(n)
    570     def snt_check(n):
    571         if n > NUMBA_NUM_THREADS or n < 1:
--> 572             raise ValueError(msg)
    573     return snt_check
    574 

ValueError: The number of threads must be between 1 and 2

@canergen
Copy link
Member

canergen commented Jan 3, 2025

Hi. The tutorial runs on my end without any issues. This is a call within Celltypist. The Celltypist function call actually is correct. I assume it's one instance on Colab that has issues with running it. Can you check the n_jobs argument in scanpy and otherwise check with scanpy what's going wrong here (create an issue there): https://scanpy.readthedocs.io/en/stable/generated/scanpy._settings.ScanpyConfig.n_jobs.html#scanpy._settings.ScanpyConfig.n_jobs. You can also change prediction_mode to fast, which will disable overclustering and therefore by-pass the issue.

@juanduphd
Copy link
Author

Which hardware accelerator are you using? I am using T4 GPU (without Colab Pro). Perhaps that is the issue?

I tried prediction_mode="fast", unfortunately, it didn't resolve the issue on my side.

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

No branches or pull requests

2 participants