Skip to content

Commit

Permalink
update "all" default value
Browse files Browse the repository at this point in the history
  • Loading branch information
waltsims committed Dec 15, 2024
1 parent 8020329 commit 493021c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions kwave/options/simulation_execution_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(
kwave_function_name: Optional[str] = "kspaceFirstOrder3D",
delete_data: bool = True,
device_num: Optional[int] = None,
num_threads: Union[int, str] = "all",
num_threads: Optional[int] = None,
thread_binding: Optional[bool] = None,
system_call: Optional[str] = None,
verbose_level: int = 0,
Expand All @@ -34,8 +34,8 @@ def __init__(
self._binary_dir = binary_dir
self.kwave_function_name = kwave_function_name
self.delete_data = delete_data
self._device_num = device_num
self._num_threads = num_threads
self.device_num = device_num
self.num_threads = num_threads
self.thread_binding = thread_binding
self.system_call = system_call
self.verbose_level = verbose_level
Expand All @@ -53,7 +53,11 @@ def num_threads(self, value: Union[int, str]):
raise RuntimeError("Unable to determine the number of CPUs on this system. Please specify the number of threads explicitly.")

if value == "all":
value = cpu_count
warnings.warn("The 'all' option is deprecated. The value of None sets the maximal number of threads (excluding Windows).", DeprecationWarning)
value = cpu_count

if value is None:
value = cpu_count

if not isinstance(value, int):
raise ValueError("Got {value}. Number of threads must be 'all' or a positive integer")
Expand Down Expand Up @@ -87,10 +91,8 @@ def is_gpu_simulation(self, value: Optional[bool]):

@property
def binary_name(self) -> str:
valid_binary_names = ["kspaceFirstOrder-CUDA", "kspaceFirstOrder-OMP"]
if PLATFORM == "windows":
valid_binary_names = [name + ".exe" for name in valid_binary_names]


valid_binary_names = ["kspaceFirstOrder-OMP", "kspaceFirstOrder-CUDA"]
if self._binary_name is None:
# set default binary name based on GPU simulation value
if self.is_gpu_simulation is None:
Expand All @@ -103,9 +105,9 @@ def binary_name(self) -> str:

if PLATFORM == "windows":
self._binary_name += ".exe"
valid_binary_names = [name + ".exe" for name in valid_binary_names]

elif self._binary_name not in valid_binary_names:
import warnings

warnings.warn("Custom binary name set. Ignoring `is_gpu_simulation` state.")
return self._binary_name

Expand Down
2 changes: 1 addition & 1 deletion tests/test_simulation_execution_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_default_initialization(self):
self.assertEqual(options.kwave_function_name, "kspaceFirstOrder3D")
self.assertTrue(options.delete_data)
self.assertIsNone(options.device_num)
self.assertEqual(options.num_threads, "all") # "all" should default to CPU count
self.assertEqual(options._num_threads, os.cpu_count())
self.assertIsNone(options.thread_binding)
self.assertEqual(options.verbose_level, 0)
self.assertTrue(options.auto_chunking)
Expand Down

0 comments on commit 493021c

Please sign in to comment.