Skip to content

Commit

Permalink
MAINT: Work around joblib bug (#11765)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner authored Jun 30, 2023
1 parent 3c4a6f6 commit b92c88d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion mne/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@ def parallel_func(
max_nbytes = None # disable memmaping
kwargs["temp_folder"] = cache_dir
kwargs["max_nbytes"] = max_nbytes
parallel = Parallel(n_jobs, **kwargs)
n_jobs_orig = n_jobs
if n_jobs is not None: # https://github.com/joblib/joblib/issues/1473
kwargs["n_jobs"] = n_jobs
parallel = Parallel(**kwargs)
n_jobs = _check_n_jobs(parallel.n_jobs)
logger.debug(f"Got {n_jobs} parallel jobs after requesting {n_jobs_orig}")
if max_jobs is not None:
n_jobs = min(n_jobs, max(_ensure_int(max_jobs, "max_jobs"), 1))
my_func = delayed(func)
Expand Down
9 changes: 7 additions & 2 deletions mne/tests/test_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ def fun(x):
if isinstance(n_jobs, str):
backend, n_jobs = n_jobs.split()
n_jobs = want_jobs = int(n_jobs)
ctx = joblib.parallel_backend(backend, n_jobs)
try:
func = joblib.parallel_config
except AttributeError:
# joblib < 1.3
func = joblib.parallel_backend
ctx = func(backend, n_jobs=n_jobs)
n_jobs = None
else:
ctx = nullcontext()
Expand All @@ -43,5 +48,5 @@ def fun(x):
else:
want_jobs = 1
with ctx:
parallel, p_fun, got_jobs = parallel_func(fun, n_jobs)
parallel, p_fun, got_jobs = parallel_func(fun, n_jobs, verbose="debug")
assert got_jobs == want_jobs

0 comments on commit b92c88d

Please sign in to comment.