From 7fc5da1671515ecc259c685e05117430de9cba1b Mon Sep 17 00:00:00 2001 From: Adam Tyson Date: Tue, 30 Apr 2024 16:13:34 +0100 Subject: [PATCH 1/2] expose n_free_cpus parameter to in GUI --- brainreg/core/cli.py | 2 +- brainreg/napari/register.py | 13 ++++++++++++- brainreg/napari/util.py | 5 +++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/brainreg/core/cli.py b/brainreg/core/cli.py index cf4738d..6214da9 100644 --- a/brainreg/core/cli.py +++ b/brainreg/core/cli.py @@ -98,7 +98,7 @@ def misc_parse(parser): "--n-free-cpus", dest="n_free_cpus", type=check_positive_int, - default=4, + default=2, help="The number of CPU cores on the machine to leave " "unused by the program to spare resources.", ) diff --git a/brainreg/napari/register.py b/brainreg/napari/register.py index 448a440..38d2927 100644 --- a/brainreg/napari/register.py +++ b/brainreg/napari/register.py @@ -132,6 +132,7 @@ def brainreg_register(): smoothing_sigma_floating=1, histogram_n_bins_floating=128, histogram_n_bins_reference=128, + n_free_cpus=2, debug=False, ) @@ -212,6 +213,10 @@ def brainreg_register(): value=DEFAULT_PARAMETERS["histogram_n_bins_reference"], label="histogram_n_bins_reference", ), + n_free_cpus=dict( + value=DEFAULT_PARAMETERS["n_free_cpus"], + label="Free CPU cores", + ), debug=dict( value=DEFAULT_PARAMETERS["debug"], label="Debug mode", @@ -243,6 +248,7 @@ def widget( smoothing_sigma_floating: float, histogram_n_bins_floating: float, histogram_n_bins_reference: float, + n_free_cpus: int, debug: bool, reset_button, check_orientation_button, @@ -333,6 +339,8 @@ def widget( Number of bins used for the generation of the histograms used for the calculation of Normalized Mutual Information on the reference image + n_free_cpus : int + How many CPU cores to leave free debug: bool Activate debug mode (save intermediate steps). check_orientation_button: @@ -432,7 +440,10 @@ def run(): scaling, load_parallel, ) = initialise_brainreg( - atlas_key.value, data_orientation, voxel_sizes + atlas_key.value, + data_orientation, + voxel_sizes, + n_free_cpus=n_free_cpus, ) additional_images_downsample = get_additional_images_downsample( diff --git a/brainreg/napari/util.py b/brainreg/napari/util.py index af19a0d..82779f5 100644 --- a/brainreg/napari/util.py +++ b/brainreg/napari/util.py @@ -9,9 +9,10 @@ from tqdm import tqdm -def initialise_brainreg(atlas_key, data_orientation_key, voxel_sizes): +def initialise_brainreg( + atlas_key, data_orientation_key, voxel_sizes, n_free_cpus=2 +): scaling_rounding_decimals = 5 - n_free_cpus = 2 atlas = BrainGlobeAtlas(atlas_key) source_space = bg.AnatomicalSpace(data_orientation_key) From f23fc837fe45975217f5b15fccb753560e795eb6 Mon Sep 17 00:00:00 2001 From: Adam Tyson Date: Tue, 30 Apr 2024 16:38:12 +0100 Subject: [PATCH 2/2] Pass n_free_cpus to worker --- brainreg/napari/register.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brainreg/napari/register.py b/brainreg/napari/register.py index 38d2927..9a37e6b 100644 --- a/brainreg/napari/register.py +++ b/brainreg/napari/register.py @@ -403,7 +403,7 @@ def get_gui_logging_args(): ) @thread_worker - def run(): + def run(n_free_cpus): paths = Paths(pathlib.Path(registration_output_folder)) niftyreg_args = NiftyregArgs( @@ -495,7 +495,7 @@ def run(): f"{paths.registration_output_folder}" ) - worker = run() + worker = run(n_free_cpus) if not block: worker.returned.connect(load_registration_as_layers)