Skip to content

Commit

Permalink
Allow number of free CPU cores to be set in the GUI (#195)
Browse files Browse the repository at this point in the history
* expose n_free_cpus parameter to in GUI

* Pass n_free_cpus to worker
  • Loading branch information
adamltyson committed Apr 30, 2024
1 parent 8012442 commit c66a315
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion brainreg/core/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
)
Expand Down
21 changes: 16 additions & 5 deletions brainreg/napari/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def brainreg_register():
smoothing_sigma_floating=-1.0,
histogram_n_bins_floating=128,
histogram_n_bins_reference=128,
n_free_cpus=2,
debug=False,
)

Expand Down Expand Up @@ -216,6 +217,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",
Expand Down Expand Up @@ -245,8 +250,9 @@ def widget(
grid_spacing: int,
smoothing_sigma_reference: float,
smoothing_sigma_floating: float,
histogram_n_bins_floating: int,
histogram_n_bins_reference: int,
histogram_n_bins_floating: float,
histogram_n_bins_reference: float,
n_free_cpus: int,
debug: bool,
reset_button,
check_orientation_button,
Expand Down Expand Up @@ -339,6 +345,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:
Expand Down Expand Up @@ -401,7 +409,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(
Expand Down Expand Up @@ -438,7 +446,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(
Expand Down Expand Up @@ -491,7 +502,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)

Expand Down
5 changes: 3 additions & 2 deletions brainreg/napari/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit c66a315

Please sign in to comment.