Skip to content

Commit

Permalink
split arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
waltsims committed Dec 14, 2024
1 parent 275b4de commit 1faee26
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 20 deletions.
13 changes: 9 additions & 4 deletions kwave/options/simulation_execution_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,17 @@ def as_list(self, sensor: kSensor) -> list[str]:
if self.device_num is not None:
if self.device_num < 0:
raise ValueError("Device number must be non-negative")
options_list.append(f"-g {self.device_num}")
options_list.append("-g")
options_list.append(str(self.device_num))

if self.num_threads is not None and PLATFORM != "windows":
options_list.append(f"-t {self.num_threads}")
options_list.append("-t")
options_list.append(str(self.num_threads))

if self.verbose_level > 0:
options_list.append(f"--verbose {self.verbose_level}")
options_list.append("--verbose")
options_list.append(str(self.verbose_level))


record_options_map = {
"p": "p_raw", "p_max": "p_max", "p_min": "p_min", "p_rms": "p_rms",
Expand All @@ -184,7 +188,8 @@ def as_list(self, sensor: kSensor) -> list[str]:
options_list.append("--p_raw")

if sensor.record_start_index is not None:
options_list.append(f"-s {sensor.record_start_index}")
options_list.append("-s")
options_list.append(f"{sensor.record_start_index}")

return options_list

Expand Down
48 changes: 32 additions & 16 deletions tests/test_simulation_execution_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,16 @@ def test_get_options_string_darwin(self):

options_list = options.as_list(self.mock_sensor)
expected_elements = [
f"-g {options.device_num}",
f"-t {os.cpu_count()}",
"--verbose 2",
"-g",
f"{options.device_num}",
"-t",
f"{os.cpu_count()}",
"--verbose",
"2",
"--p_raw",
"--u_max",
f"-s {self.mock_sensor.record_start_index}" # Updated to use self.mock_sensor
"-s",
f"{self.mock_sensor.record_start_index}" # Updated to use self.mock_sensor
]
for element in expected_elements:
self.assertIn(element, options_list)
Expand All @@ -116,11 +120,14 @@ def test_as_list_windows(self):

options_list = options.as_list(self.mock_sensor)
expected_elements = [
f"-g {options.device_num}",
"--verbose 2",
"-g",
f"{options.device_num}",
"--verbose",
"2",
"--p_raw",
"--u_max",
f"-s {self.mock_sensor.record_start_index}" # Updated to use self.mock_sensor
"-s",
f"{self.mock_sensor.record_start_index}"
]
for element in expected_elements:
self.assertIn(element, options_list)
Expand All @@ -136,12 +143,16 @@ def test_as_list_darwin(self):

options_list = options.as_list(self.mock_sensor)
expected_elements = [
f"-g {options.device_num}",
f"-t {os.cpu_count()}",
"--verbose 2",
"-g",
f"{options.device_num}",
"-t",
f"{os.cpu_count()}",
"--verbose",
"2",
"--p_raw",
"--u_max",
f"-s {self.mock_sensor.record_start_index}" # Updated to use self.mock_sensor
"-s",
f"{self.mock_sensor.record_start_index}" # Updated to use self.mock_sensor
]
for element in expected_elements:
self.assertIn(element, options_list)
Expand All @@ -156,9 +167,12 @@ def test_as_list_custom_record(self):

options_list = options.as_list(self.mock_sensor)
expected_elements = [
f"-g {options.device_num}",
"-t 8",
"--verbose 1",
"-g",
f"{options.device_num}",
"-t",
"8",
"--verbose",
"1",
"--p_max",
"--u_min",
"--p_raw" # Default if no specific 'p' or 'u' options are given
Expand All @@ -183,8 +197,10 @@ def test_as_list_no_record(self):

options_list = options.as_list(self.mock_sensor)
expected_elements = [
f"-g {options.device_num}",
"-t 4",
"-g",
f"{options.device_num}",
"-t",
"4",
"--p_raw", # Default value
]
for element in expected_elements:
Expand Down

0 comments on commit 1faee26

Please sign in to comment.