From d53fdbc5f7b98cf14d27861da7ee19945267cdbb Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Mon, 19 Aug 2024 19:51:55 +0000 Subject: [PATCH 1/2] Convert - to _ in parse_extras --- mlos_bench/mlos_bench/launcher.py | 4 ++++ mlos_bench/mlos_bench/tests/launcher_in_process_test.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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. From 2493fea06cd6a33c06f30dbf7bdb7bb277f2ea15 Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Mon, 19 Aug 2024 20:10:47 +0000 Subject: [PATCH 2/2] Convert - dashes to _ underscores when parsing CLI arg extra globals. --- mlos_bench/mlos_bench/tests/launcher_parse_args_test.py | 3 +++ 1 file changed, 3 insertions(+) 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 2b9c31c014b..fbd6e874a6f 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)