Skip to content

Commit 10268a8

Browse files
committed
FIX: Permit overriding plugin config with CLI options
1 parent 510f28d commit 10268a8

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

fmriprep/cli/run.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def get_parser():
8181
g_perfm = parser.add_argument_group('Options to handle performance')
8282
g_perfm.add_argument('--debug', action='store_true', default=False,
8383
help='run debug version of workflow')
84-
g_perfm.add_argument('--nthreads', '--n_cpus', '-n-cpus', action='store', default=0, type=int,
84+
g_perfm.add_argument('--nthreads', '--n_cpus', '-n-cpus', action='store', type=int,
8585
help='maximum number of threads across all processes')
8686
g_perfm.add_argument('--omp-nthreads', action='store', type=int, default=0,
8787
help='maximum number of threads per-process')
@@ -416,28 +416,35 @@ def build_workflow(opts, retval):
416416
subject_list = collect_participants(
417417
bids_dir, participant_label=opts.participant_label)
418418

419-
# Setting up MultiProc
420-
nthreads = opts.nthreads
421-
if nthreads < 1:
422-
nthreads = cpu_count()
423-
424-
plugin_settings = {
425-
'plugin': 'MultiProc',
426-
'plugin_args': {
427-
'n_procs': nthreads,
428-
'raise_insufficient': False,
429-
'maxtasksperchild': 1,
430-
}
431-
}
432-
433-
if opts.mem_mb:
434-
plugin_settings['plugin_args']['memory_gb'] = opts.mem_mb / 1024
435-
436-
# Overload plugin_settings if --use-plugin
419+
# Load base plugin_settings from file if --use-plugin
437420
if opts.use_plugin is not None:
438421
from yaml import load as loadyml
439422
with open(opts.use_plugin) as f:
440423
plugin_settings = loadyml(f)
424+
plugin_settings.set_default('plugin_args', {})
425+
else:
426+
# Defaults
427+
plugin_settings = {
428+
'plugin': 'MultiProc',
429+
'plugin_args': {
430+
'raise_insufficient': False,
431+
'maxtasksperchild': 1,
432+
}
433+
}
434+
435+
# Resource management options
436+
# Note that we're making strong assumptions about valid plugin args
437+
# This may need to be revisited if people try to use batch plugins
438+
nthreads = plugin_settings['plugin_args'].get('n_procs')
439+
# Permit overriding plugin config with specific CLI options
440+
if nthreads is None or opts.nthreads is not None:
441+
nthreads = opts.nthreads
442+
if nthreads is None or nthreads < 1:
443+
nthreads = cpu_count()
444+
plugin_settings['plugin_args']['n_procs'] = nthreads
445+
446+
if opts.mem_mb:
447+
plugin_settings['plugin_args']['memory_gb'] = opts.mem_mb / 1024
441448

442449
omp_nthreads = opts.omp_nthreads
443450
if omp_nthreads == 0:

0 commit comments

Comments
 (0)