Skip to content

Commit

Permalink
Convert - dashes to _ underscores when parsing CLI arg extra globals (#…
Browse files Browse the repository at this point in the history
…849)

See Also: #847

---------

Co-authored-by: Sergiy Matusevych <[email protected]>
  • Loading branch information
bpkroth and motus authored Aug 19, 2024
1 parent 439df99 commit 85fdec3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions mlos_bench/mlos_bench/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion mlos_bench/mlos_bench/tests/launcher_in_process_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions mlos_bench/mlos_bench/tests/launcher_parse_args_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 85fdec3

Please sign in to comment.