diff --git a/maggy/core/experimentdriver.py b/maggy/core/experimentdriver.py index 5a7e0ca1..3cd14e8a 100644 --- a/maggy/core/experimentdriver.py +++ b/maggy/core/experimentdriver.py @@ -455,6 +455,17 @@ def _target_function(self): msg["partition_id"], None ) self.experiment_done = True + elif trial == "IDLE": + self.add_message( + { + "type": "IDLE", + "partition_id": msg["partition_id"], + "idle_start": time.time(), + } + ) + self.server.reservations.assign_trial( + msg["partition_id"], None + ) else: with trial.lock: trial.start = time.time() @@ -464,6 +475,34 @@ def _target_function(self): ) self.add_trial(trial) + # 4. Let executor be idle + elif msg["type"] == "IDLE": + # execute only every 0.1 seconds but do not block thread + if ( + self.experiment_type == "optimization" + and time.time() - msg["idle_start"] > 0.1 + ): + trial = self.optimizer.get_suggestion() + if trial is None: + self.server.reservations.assign_trial( + msg["partition_id"], None + ) + self.experiment_done = True + elif trial == "IDLE": + # reset timeout + msg["idle_start"] = time.time() + self.add_message(msg) + else: + with trial.lock: + trial.start = time.time() + trial.status = Trial.SCHEDULED + self.server.reservations.assign_trial( + msg["partition_id"], trial.trial_id + ) + self.add_trial(trial) + elif self.experiment_type == "optimization": + self.add_message(msg) + # 4. REG elif msg["type"] == "REG": if self.experiment_type == "optimization":