Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert - dashes to _ underscores when parsing CLI arg extra globals #849

Merged
merged 3 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading