Coverage for mlos_bench/mlos_bench/schedulers/sync_scheduler.py: 100%
21 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"""A simple single-threaded synchronous optimization loop implementation."""
7import logging
9from mlos_bench.schedulers.base_scheduler import Scheduler
10from mlos_bench.storage.base_storage import Storage
12_LOG = logging.getLogger(__name__)
15class SyncScheduler(Scheduler):
16 """A simple single-threaded synchronous optimization loop implementation."""
18 def start(self) -> None:
19 """Start the optimization loop."""
20 super().start()
22 is_warm_up = self.optimizer.supports_preload
23 if not is_warm_up:
24 _LOG.warning("Skip pending trials and warm-up: %s", self.optimizer)
26 not_done = True
27 while not_done:
28 _LOG.info("Optimization loop: Last trial ID: %d", self._last_trial_id)
29 self._run_schedule(is_warm_up)
30 not_done = self._schedule_new_optimizer_suggestions()
31 is_warm_up = False
33 def run_trial(self, trial: Storage.Trial) -> None:
34 """
35 Set up and run a single trial.
37 Save the results in the storage.
38 """
39 super().run_trial(trial)
40 # In the sync scheduler we run each trial on its own TrialRunner in sequence.
41 trial_runner = self.get_trial_runner(trial)
42 trial_runner.run_trial(trial, self.global_config)
43 _LOG.info("QUEUE: Finished trial: %s on %s", trial, trial_runner)