-
Notifications
You must be signed in to change notification settings - Fork 95
spatial_autocorr limit the numba threads as n_jobs temporarily #984
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
base: main
Are you sure you want to change the base?
spatial_autocorr limit the numba threads as n_jobs temporarily #984
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #984 +/- ##
==========================================
- Coverage 69.99% 66.60% -3.39%
==========================================
Files 39 40 +1
Lines 5532 6061 +529
Branches 1037 1014 -23
==========================================
+ Hits 3872 4037 +165
- Misses 1367 1663 +296
- Partials 293 361 +68
🚀 New features to boost your workflow:
|
@selmanozleyen I think this issue is conflating two things. The function you're wrapping doesn't appear to have anything to do with |
I assumed it is numba related it uses score_helper which uses moran's I which is implemented with numba in scanpy. squidpy/src/squidpy/gr/_ppatterns.py Line 254 in afcb8d0
moran helper in scanpy: https://github.com/scverse/scanpy/blob/15c5434ad0382614a16df612745c183807675d04/src/scanpy/metrics/_morans_i.py#L131 I checked locally with htop and this runs on all the cores without the changes I made import numpy as np
import pandas as pd
import anndata as ad
import scanpy as sc
import squidpy as sq
# load the pre-processed dataset
adata = sq.datasets.visium_hne_adata()
sq.gr.spatial_neighbors(adata)
sq.gr.spatial_autocorr(adata, n_jobs=1, n_perms=10000000, mode="moran") |
Awesome thanks! And with the change, it works? I would wonder if this problem applies everywhere this |
Yes it works when I set it to 1 but it doesn't work for 2 because there is no guarantee that numba and joblib will use the same cores. So there would be 2*n_jobs cores utilized. I couldn't observe this very clearly because I have 8 cores locally already atm. But do you think this is a bug? I think |
Right @selmanozleyen yes I got lost in the sauce. I understand now better, I think. So:
If so, then I think this issue is one of documentation, you're right. |
Description
I am not sure if this is a bug. But it makes sense for the user to expect numba to be using at most
n_jobs
on their cores. I made one solution like this one but I think any code that uses numba will have to be modified this way if we see this as a bug right @ilan-gold ? or am I missing something?Closes
#957 (comment)