spatial_autocorr limit the numba threads as n_jobs temporarily#984
spatial_autocorr limit the numba threads as n_jobs temporarily#984selmanozleyen wants to merge 2 commits intoscverse:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #984 +/- ##
==========================================
+ Coverage 66.58% 66.60% +0.02%
==========================================
Files 40 40
Lines 6057 6061 +4
Branches 1014 1014
==========================================
+ Hits 4033 4037 +4
Misses 1663 1663
Partials 361 361
🚀 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. |
|
Based on the original comment it seems that numba just grabs cores irregardless though. I think we should limit numba here to only act "within core" since as Selman said the user expects only |
|
I will close this as we decided this is a documentation issue |
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_jobson 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)