Skip to content

Commit

Permalink
fix bug in async parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
jhj0411jhj committed Feb 29, 2024
1 parent 13b6301 commit 1e14652
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions openbox/optimizer/parallel_smbo.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ def callback(self, observation: Observation):
self.iteration_id += 1 # must increment id after updating
logger.info('Update observation %d: %s.' % (self.iteration_id, str(observation)))

# TODO: Wrong logic. Need to wait before return?
def async_run(self):
with ParallelEvaluation(wrapper, n_worker=self.batch_size) as proc:
while self.iteration_id < self.max_runs:
# get suggestion and apply to worker
while True:
with self.advisor_lock:
_config = self.config_advisor.get_suggestion()
_param = [self.objective_function, _config, self.max_runtime_per_trial, self.FAILED_PERF]
Expand All @@ -187,6 +187,15 @@ def async_run(self):
# Wait for workers.
time.sleep(0.1)

with self.advisor_lock:
num_all_configs = self.iteration_id + len(self.config_advisor.running_configs)
if num_all_configs >= self.max_runs:
break

# wait for all workers to complete
while len(self.config_advisor.running_configs) > 0:
time.sleep(0.1)

# Asynchronously evaluate n configs
def async_iterate(self, n=1) -> List[Observation]:
iter_id = 0
Expand Down

0 comments on commit 1e14652

Please sign in to comment.