Skip to content

Commit 8dfe38e

Browse files
authored
Fix #517 (#518)
* Fix #517 * Update CHANGELOG
1 parent f8143aa commit 8dfe38e

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@ and this project adheres to [Semantic Versioning][].
88
[keep a changelog]: https://keepachangelog.com/en/1.0.0/
99
[semantic versioning]: https://semver.org/spec/v2.0.0.html
1010

11-
## Unreleased
11+
## v0.17.0
12+
13+
### Additions
1214

1315
- Add "TCRdist" as new metric ([#502](https://github.com/scverse/scirpy/pull/502))
1416

17+
### Fixes
18+
19+
- Fix issue with detecting the number of available CPUs on MacOD ([#518](https://github.com/scverse/scirpy/pull/502))
20+
1521
## v0.16.1
1622

1723
### Fixes

src/scirpy/ir_dist/_clonotype_neighbors.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import itertools
2-
import os
32
from collections.abc import Mapping, Sequence
43
from typing import Literal, Optional, Union
54

@@ -11,7 +10,7 @@
1110

1211
from scirpy.get import _has_ir
1312
from scirpy.get import airr as get_airr
14-
from scirpy.util import DataHandler, tqdm
13+
from scirpy.util import DataHandler, _get_usable_cpus, tqdm
1514

1615
from ._util import DoubleLookupNeighborFinder, merge_coo_matrices, reduce_and, reduce_or
1716

@@ -225,7 +224,7 @@ def compute_distances(self) -> sp.csr_matrix:
225224
dist_rows = process_map(
226225
self._dist_for_clonotype,
227226
range(n_clonotypes),
228-
max_workers=self.n_jobs if self.n_jobs > 0 else len(os.sched_getaffinity(0)),
227+
max_workers=_get_usable_cpus(self.n_jobs),
229228
chunksize=2000,
230229
tqdm_class=tqdm,
231230
)

src/scirpy/util/__init__.py

+19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import contextlib
2+
import os
23
import warnings
34
from collections.abc import Mapping, Sequence
45
from textwrap import dedent
@@ -582,3 +583,21 @@ def _parallelize_with_joblib(delayed_objects, *, total=None, **kwargs):
582583
"Consider setting verbosity in joblib.parallel_config"
583584
)
584585
return Parallel(return_as="list", **kwargs)(delayed_objects)
586+
587+
588+
def _get_usable_cpus(n_jobs: int = 0):
589+
"""Get the number of CPUs available to the process
590+
591+
If `n_jobs` is specified and > 0 that value will be returned unaltered.
592+
Otherwise will try to determine the number of CPUs available to the process which
593+
is not necessarily the number of CPUs available on the system.
594+
595+
On MacOS, `os.sched_getaffinity` is not implemented, therefore we just return the cpu count there.
596+
"""
597+
if n_jobs > 0:
598+
return n_jobs
599+
600+
try:
601+
return os.sched_getaffinity(0)
602+
except AttributeError:
603+
return os.cpu_count()

0 commit comments

Comments
 (0)