Coverage for mlos_bench/mlos_bench/optimizers/one_shot_optimizer.py: 100%
18 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-10-07 01:52 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-10-07 01:52 +0000
1#
2# Copyright (c) Microsoft Corporation.
3# Licensed under the MIT License.
4#
5"""No-op optimizer for mlos_bench that proposes a single configuration."""
7import logging
8from typing import Optional
10from mlos_bench.optimizers.mock_optimizer import MockOptimizer
11from mlos_bench.services.base_service import Service
12from mlos_bench.tunables.tunable_groups import TunableGroups
14_LOG = logging.getLogger(__name__)
17class OneShotOptimizer(MockOptimizer):
18 """
19 No-op optimizer that proposes a single configuration and returns.
21 Explicit configs (partial or full) are possible using configuration files.
22 """
24 # TODO: Add support for multiple explicit configs (i.e., FewShot or Manual Optimizer) - #344
26 def __init__(
27 self,
28 tunables: TunableGroups,
29 config: dict,
30 global_config: Optional[dict] = None,
31 service: Optional[Service] = None,
32 ):
33 super().__init__(tunables, config, global_config, service)
34 _LOG.info("Run a single iteration for: %s", self._tunables)
35 self._max_suggestions = 1 # Always run for just one iteration.
37 def suggest(self) -> TunableGroups:
38 """Always produce the same (initial) suggestion."""
39 tunables = super().suggest()
40 self._start_with_defaults = True
41 return tunables
43 @property
44 def supports_preload(self) -> bool:
45 return False