Skip to content

Commit

Permalink
Sample initialization in portfolio (#1400)
Browse files Browse the repository at this point in the history
* Sample initialization in portfolio

* done

* fix

* fix

* fix

Co-authored-by: Jeremy Rapin <[email protected]>
  • Loading branch information
jrapin and jrapin authored May 1, 2022
1 parent ad4b48b commit 5540474
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions nevergrad/optimization/optimizerlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,7 @@ def _internal_ask_candidate(self) -> p.Parameter:
self._current += 1
optim_index = self._current % len(self.optims)
opt = self.optims[optim_index]

if opt.num_workers > opt.num_ask - (opt.num_tell - opt.num_tell_not_asked):
break # if there are workers left, use this optimizer
if k > num:
Expand All @@ -1455,6 +1456,10 @@ def _internal_ask_candidate(self) -> p.Parameter:
if optim_index is None:
raise RuntimeError("Something went wrong in optimizer selection")
opt = self.optims[optim_index]
if optim_index > 1 and not opt.num_ask and not opt._suggestions and not opt.num_tell:
# most algorithms start at 0, lets avoid that for all but the first if they have no information
opt._suggestions.append(self.parametrization.sample())
# (hacky suggestion to avoid calling args and kwargs)
candidate = opt.ask()
candidate._meta["optim_index"] = optim_index
return candidate
Expand Down

0 comments on commit 5540474

Please sign in to comment.