Coverage for mlos_bench/mlos_bench/tests/launcher_in_process_test.py: 100%
8 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-21 01:50 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-21 01:50 +0000
1#
2# Copyright (c) Microsoft Corporation.
3# Licensed under the MIT License.
4#
5"""Unit tests to check the launcher and the main optimization loop in-process."""
8import pytest
10from mlos_bench.run import _main
13@pytest.mark.parametrize(
14 ("argv", "expected_score"),
15 [
16 (
17 [
18 "--config",
19 "mlos_bench/mlos_bench/tests/config/cli/mock-bench.jsonc",
20 "--trial_config_repeat_count",
21 "5",
22 "--mock_env_seed",
23 "-1", # Deterministic Mock Environment.
24 ],
25 67.40329,
26 ),
27 (
28 [
29 "--config",
30 "mlos_bench/mlos_bench/tests/config/cli/mock-opt.jsonc",
31 "--trial_config_repeat_count",
32 "3",
33 "--max-suggestions",
34 "3",
35 "--mock_env_seed",
36 "42", # Noisy Mock Environment.
37 ],
38 64.53897,
39 ),
40 (
41 [
42 "--config",
43 "mlos_bench/mlos_bench/tests/config/cli/test-cli-local-env-bench.jsonc",
44 "--globals",
45 "experiment_test_local.jsonc",
46 "--tunable_values",
47 "tunable-values/tunable-values-local.jsonc",
48 ],
49 123.4,
50 ),
51 (
52 [
53 "--config",
54 "mlos_bench/mlos_bench/tests/config/cli/test-cli-local-env-opt.jsonc",
55 "--globals",
56 "experiment_test_local.jsonc",
57 "--max-suggestions",
58 "3",
59 ],
60 123.4,
61 ),
62 ],
63)
64@pytest.mark.filterwarnings(
65 "ignore:.*(Configuration.*was already registered).*:UserWarning:.*flaml_optimizer.*:0"
66)
67def test_main_bench(argv: list[str], expected_score: float) -> None:
68 """Run mlos_bench optimization loop with given config and check the results."""
69 (score, _config) = _main(argv)
70 assert score is not None
71 assert pytest.approx(score["score"], 1e-5) == expected_score