Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tune integration] Don't process nan/inf results #7

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions zoopt/algos/opt_algorithms/racos/sracos.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,27 +253,41 @@ def suggest(self):
Suggest a trial for Tune, including init trials(decided by `budget`)

"""
if self.semaphore == 0:
if self.semaphore == 0 and self.live_num > 0:
# If there are no live samples and suggestion is paused, this means that
# the initial set of samples has completed, but contained some invalid
# solutions. We should suggest another trial in this case.
return

solution = None

if self.init_num < self._parameter.get_train_size(): # for init
if self.init_num == self._parameter.get_train_size(): # done initializing
# Pause suggestions until all initial trials have completed
self.semaphore = 0
self.init_num += 1
return
elif (
self.init_num < self._parameter.get_train_size()
or self.complete_num < self._parameter.get_train_size()
):
# Initialize trials
# This also handles the case where initial trial collection runs into an
# invalid result (nan/inf), and more trials need to be generated.
solution, distinct_flag = self.tune_init_attribute()
if distinct_flag is False:
return "FINISHED"
self.live_num += 1
elif self.init_num == self._parameter.get_train_size():
self.semaphore = 0
self.init_num += 1
return
elif self.live_num < self._parameter.get_server_num():
solution, distinct_flag = self.sample_solution(self.ub)
if distinct_flag is False:
return "FINISHED"
self.live_num += 1
self.init_num += 1
# Else, all initial samples have been completed, but there are already
# `server_num` live samples that need to finish before new suggesting
# new samples (concurrency limiting).

self.init_num += 1
return solution

def complete(self, solution, result):
Expand All @@ -284,8 +298,14 @@ def complete(self, solution, result):
:param result: evaluated result of solution
:return: best solution so far
"""
self.complete_num += 1
self.live_num -= 1

# Invalid results (nan/inf) should not be added as data
if np.isnan(result) or np.isinf(result):
return self._best_solution

# Only increment `complete_num` on valid solutions
self.complete_num += 1
solution.set_value(result)
if self.complete_num < self._parameter.get_train_size():
self._data.append(solution)
Expand Down