Skip to content

Commit b60e78f

Browse files
committed
Add IDLE message to optimizer to allow idle executors (#49)
(cherry picked from commit 17d6816)
1 parent 5614372 commit b60e78f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

maggy/core/experimentdriver.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,17 @@ def _target_function(self):
455455
msg["partition_id"], None
456456
)
457457
self.experiment_done = True
458+
elif trial == "IDLE":
459+
self.add_message(
460+
{
461+
"type": "IDLE",
462+
"partition_id": msg["partition_id"],
463+
"idle_start": time.time(),
464+
}
465+
)
466+
self.server.reservations.assign_trial(
467+
msg["partition_id"], None
468+
)
458469
else:
459470
with trial.lock:
460471
trial.start = time.time()
@@ -464,6 +475,34 @@ def _target_function(self):
464475
)
465476
self.add_trial(trial)
466477

478+
# 4. Let executor be idle
479+
elif msg["type"] == "IDLE":
480+
# execute only every 0.1 seconds but do not block thread
481+
if (
482+
self.experiment_type == "optimization"
483+
and time.time() - msg["idle_start"] > 0.1
484+
):
485+
trial = self.optimizer.get_suggestion()
486+
if trial is None:
487+
self.server.reservations.assign_trial(
488+
msg["partition_id"], None
489+
)
490+
self.experiment_done = True
491+
elif trial == "IDLE":
492+
# reset timeout
493+
msg["idle_start"] = time.time()
494+
self.add_message(msg)
495+
else:
496+
with trial.lock:
497+
trial.start = time.time()
498+
trial.status = Trial.SCHEDULED
499+
self.server.reservations.assign_trial(
500+
msg["partition_id"], trial.trial_id
501+
)
502+
self.add_trial(trial)
503+
elif self.experiment_type == "optimization":
504+
self.add_message(msg)
505+
467506
# 4. REG
468507
elif msg["type"] == "REG":
469508
if self.experiment_type == "optimization":

0 commit comments

Comments
 (0)