diff --git a/mlos_bench/mlos_bench/launcher.py b/mlos_bench/mlos_bench/launcher.py index 9024b15adfd..339a11963de 100644 --- a/mlos_bench/mlos_bench/launcher.py +++ b/mlos_bench/mlos_bench/launcher.py @@ -399,6 +399,10 @@ def _try_parse_extra_args(cmdline: Iterable[str]) -> Dict[str, TunableValue]: # Handles missing trailing elem from last --key arg. raise ValueError("Command line argument has no value: " + key) + # Convert "max-suggestions" to "max_suggestions" for compatibility with + # other CLI options to use as common python/json variable replacements. + config = {k.replace("-", "_"): v for k, v in config.items()} + _LOG.debug("Parsed config: %s", config) return config diff --git a/mlos_bench/mlos_bench/tests/launcher_in_process_test.py b/mlos_bench/mlos_bench/tests/launcher_in_process_test.py index 6fe340c9eb5..eb20b1ababd 100644 --- a/mlos_bench/mlos_bench/tests/launcher_in_process_test.py +++ b/mlos_bench/mlos_bench/tests/launcher_in_process_test.py @@ -31,7 +31,7 @@ "mlos_bench/mlos_bench/tests/config/cli/mock-opt.jsonc", "--trial_config_repeat_count", "3", - "--max_suggestions", + "--max-suggestions", "3", "--mock_env_seed", "42", # Noisy Mock Environment. diff --git a/mlos_bench/mlos_bench/tests/launcher_parse_args_test.py b/mlos_bench/mlos_bench/tests/launcher_parse_args_test.py index ce56ae17a27..118fa13ba97 100644 --- a/mlos_bench/mlos_bench/tests/launcher_parse_args_test.py +++ b/mlos_bench/mlos_bench/tests/launcher_parse_args_test.py @@ -260,9 +260,12 @@ def test_launcher_args_parse_3(config_paths: List[str]) -> None: " ".join([f"--config-path {config_path}" for config_path in config_paths]) + f" --config {config_file}" + f" --globals {globals_file}" + + " --max-suggestions 10" # check for - to _ conversion too ) launcher = _get_launcher(__name__, cli_args) + assert launcher.optimizer.max_suggestions == 10 # from CLI args + # Check that CLI file parameter overrides JSON config: assert isinstance(launcher.scheduler, SyncScheduler) # from test-cli-config.jsonc (should override scheduler config file)