Skip to content

Commit a1f0471

Browse files
authored
Expose ANTs thread count to CLI (#283)
1 parent eccd701 commit a1f0471

16 files changed

Lines changed: 36 additions & 1 deletion

src/rbc/cli/all.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def main(args: AllArgs) -> int:
103103
runner=args.runner,
104104
verbose=bool(args.verbose),
105105
tmp_dir=args.tmp_dir,
106+
ants_threads=args.ants_threads,
106107
),
107108
)
108109
return 0

src/rbc/cli/anatomical.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def main(args: AnatomicalArgs) -> int:
5757
runner=args.runner,
5858
verbose=bool(args.verbose),
5959
tmp_dir=args.tmp_dir,
60+
ants_threads=args.ants_threads,
6061
),
6162
)
6263
return 0

src/rbc/cli/base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class BaseArgs:
2929
session_label: list[str]
3030
verbose: int
3131
tmp_dir: Path | None
32+
ants_threads: int
3233

3334
@classmethod
3435
def validate_namespace(cls, ns: argparse.Namespace) -> BaseArgs:
@@ -56,6 +57,12 @@ def validate_namespace(cls, ns: argparse.Namespace) -> BaseArgs:
5657
f"Temporary path exists, but is not a directory: {tmp_dir}"
5758
)
5859

60+
ants_threads: int = ns.ants_threads
61+
if ants_threads < 1:
62+
raise ValueError(
63+
f"ANTs thread count must be at least 1, got: {ants_threads}"
64+
)
65+
5966
return cls(
6067
input_dirs=tuple(ns.input_dirs),
6168
output_dir=ns.output_dir,
@@ -64,6 +71,7 @@ def validate_namespace(cls, ns: argparse.Namespace) -> BaseArgs:
6471
session_label=ns.session_label,
6572
verbose=ns.verbose,
6673
tmp_dir=tmp_dir,
74+
ants_threads=ants_threads,
6775
)
6876

6977

src/rbc/cli/functional.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def main(args: FunctionalArgs) -> int:
8181
runner=args.runner,
8282
verbose=bool(args.verbose),
8383
tmp_dir=args.tmp_dir,
84+
ants_threads=args.ants_threads,
8485
),
8586
)
8687
return 0

src/rbc/cli/longitudinal.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def main(args: LongitudinalArgs) -> int:
5757
runner=args.runner,
5858
verbose=bool(args.verbose),
5959
tmp_dir=args.tmp_dir,
60+
ants_threads=args.ants_threads,
6061
),
6162
)
6263
return 0

src/rbc/cli/main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ def _global_opts() -> argparse.ArgumentParser:
7979
default=None,
8080
help="Directory for intermediate files (default: system temp)",
8181
)
82+
global_opts.add_argument(
83+
"--ants-threads",
84+
type=int,
85+
default=1,
86+
metavar="N",
87+
help="Number of threads for ANTs (ITK) operations (default: 1). "
88+
"Values above 1 speed up registration but increase memory usage "
89+
"and may produce non-deterministic results",
90+
)
8291
return global_opts
8392

8493

src/rbc/cli/metrics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def main(args: MetricsArgs) -> int:
8989
runner=args.runner,
9090
verbose=bool(args.verbose),
9191
tmp_dir=args.tmp_dir,
92+
ants_threads=args.ants_threads,
9293
),
9394
)
9495
return 0

src/rbc/cli/qc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def main(args: QCArgs) -> int:
5555
runner=args.runner,
5656
verbose=bool(args.verbose),
5757
tmp_dir=args.tmp_dir,
58+
ants_threads=args.ants_threads,
5859
),
5960
)
6061
return 0

src/rbc/orchestration/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ class RunnerConfig:
7272
runner: Execution backend (local, docker, podman, singularity).
7373
verbose: Enable verbose output (progress bars, info logging).
7474
tmp_dir: Temporary directory for intermediate files.
75+
ants_threads: Number of threads for ANTs (ITK) operations.
7576
"""
7677

7778
runner: Literal["auto", "local", "docker", "podman", "singularity"] = "local"
7879
verbose: bool = False
7980
tmp_dir: Path | None = None
81+
ants_threads: int = 1
8082

8183

8284
def init_runner(config: RunnerConfig) -> None:
@@ -88,4 +90,7 @@ def init_runner(config: RunnerConfig) -> None:
8890
ctx = setup_runner(
8991
runner=config.runner, verbose=config.verbose, tmp_dir=config.tmp_dir
9092
)
91-
ctx.runner.environ = _DEFAULT_ENV_VARS
93+
ctx.runner.environ = {
94+
**_DEFAULT_ENV_VARS,
95+
"ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS": str(config.ants_threads),
96+
}

tests/unit/cli/test_all.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def base_args(tmp_path: Path) -> argparse.Namespace:
4141
func_template=None,
4242
func_template_mask=None,
4343
func_template_ref=None,
44+
ants_threads=1,
4445
)
4546

4647

0 commit comments

Comments
 (0)