Skip to content
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

ENH: Remove unused default process count parameter #530

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions scilpy/io/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,22 +206,23 @@ def add_sh_basis_args(parser, mandatory=False):
help=help_msg)


def validate_nbr_processes(parser, args, default_nbr_cpu=None):
def validate_nbr_processes(parser, args):
jhlegarreta marked this conversation as resolved.
Show resolved Hide resolved
""" Check if the passed number of processes arg is valid.
If not valid (0 < nbr_cpu_to_use <= cpu_count), raise parser.error.
Valid values are considered to be in the [0, CPU count] range:
- Raises a parser.error if an invalid value is provided.
- Returns the maximum number of cores retrieved if no value (or a value
of 0) is provided.

Parameters
----------
parser: argparse.ArgumentParser object
Parser as created by argparse.
args: argparse namespace
Args as created by argparse.
default_nbr_cpu: int (or None)
Number of cpu to use, default is cpu_count (all).

Results
------
nbr_cpu
Returns
-------
nbr_cpu: int
The number of CPU to be used.
"""

Expand All @@ -230,7 +231,7 @@ def validate_nbr_processes(parser, args, default_nbr_cpu=None):
else:
nbr_cpu = multiprocessing.cpu_count()

if nbr_cpu <= 0:
if nbr_cpu < 0:
parser.error('Number of processes must be > 0.')
elif nbr_cpu > multiprocessing.cpu_count():
parser.error('Max number of processes is {}. Got {}.'.format(
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_compute_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def main():
if not args.no_self_connection:
comb_list.extend(zip(labels_list, labels_list))

nbr_cpu = validate_nbr_processes(parser, args, args.nbr_processes)
nbr_cpu = validate_nbr_processes(parser, args)
measures_dict_list = []
if nbr_cpu == 1:
for comb in comb_list:
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_compute_hdf5_average_density_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def main():
keys.extend(curr_file.keys())

keys = set(keys)
nbr_cpu = validate_nbr_processes(parser, args, args.nbr_processes)
nbr_cpu = validate_nbr_processes(parser, args)
if nbr_cpu == 1:
for key in keys:
_average_wrapper([args.in_hdf5, key, args.binary, args.out_dir])
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_compute_mean_fixel_afd_from_hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def main():
assert_inputs_exist(parser, [args.in_hdf5, args.in_fodf])
assert_outputs_exist(parser, args, [args.out_hdf5])

nbr_cpu = validate_nbr_processes(parser, args, args.nbr_processes)
nbr_cpu = validate_nbr_processes(parser, args)

# HDF5 will not overwrite the file
if os.path.isfile(args.out_hdf5):
Expand Down
4 changes: 2 additions & 2 deletions scripts/scil_remove_similar_streamlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ def main():
original_length = len(streamlines)
logging.debug('Loaded {} streamlines...'.format(original_length))

nbr_cpu = validate_nbr_processes(parser, args, args.nbr_processes)
nbr_cpu = validate_nbr_processes(parser, args)
pool = multiprocessing.Pool(nbr_cpu)
timer = time()

logging.debug(
'Lauching subsampling on {} processes.'.format(args.nbr_processes))
'Lauching subsampling on {} processes.'.format(nbr_cpu))
last_iteration = False
iter_count = 0
while True:
Expand Down