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

Error checking for #1461 #1462

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 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
6 changes: 4 additions & 2 deletions nevergrad/benchmark/test_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
@testing.parametrized(**{name: (name, maker) for name, maker in experiments.registry.items()})
def test_experiments_registry(name: str, maker: tp.Callable[[], tp.Iterator[experiments.Experiment]]) -> None:
# "mav" is not availablefor now.
if name == "conformant_planning" or name == "neuro_planning":
if name == "conformant_planning" or name == "neuro_planning" or "compiler" in name:
raise SkipTest("This is user parametric and can not be tested.")

if "emulator" in name:
raise SkipTest("Emulators not included in CI.")

# Our PGAN is not well accepted by circleci.
if "_pgan" in name and os.environ.get("CIRCLECI", False):
raise SkipTest("Too slow in CircleCI")
Expand Down
9 changes: 6 additions & 3 deletions nevergrad/optimization/differentialevolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def __init__(
if isinstance(self._config.popsize, int):
self.llambda = self._config.popsize
else:
self.llambda = max(30, self.num_workers, pop_choice[self._config.popsize])
self.llambda = max(30, pop_choice[self._config.popsize])
self.llambda = max(self.llambda, self.num_workers)
# internals
if budget is not None and budget < 60:
warnings.warn(
Expand Down Expand Up @@ -158,6 +159,8 @@ def _internal_ask_candidate(self) -> p.Parameter:
self.population[candidate.uid] = candidate
self._uid_queue.asked.add(candidate.uid)
return candidate
# stop queue wrapping around to lineage waiting for a tell
assert self._uid_queue.told, "More untold asks than population size (exceeds num_workers)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrapin you are the expert for self._uid_queue.told (among so many things...), do you validate this assert ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I guess the error is in class Portfolio. Let me propose a fix (fingers crossed :-) ).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrapin you are the expert for self._uid_queue.told (among so many things...), do you validate this assert ?

If it helps, my thinking was that there should be a tell preceding every ask after the initalization phase keeping the told queue non-empty. Even in the worst case where popsize ==num_workers and all workers are evaluating untold points, the worker that beats the others to the tell can use the same point again on the next ask.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just sent a message to Jeremy, who knows that code better than anyone else and who might not have been close to github recently. Sorry for the delay; your PR is interesting.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used to be strict with the fact that we should not go beyond num_workers, but I changed my mind a couple of years ago because there are many cases you don't master all the details of what is happening (eg: a process dies and you'll never get the result), most times the user won't deal with it and we should be robust to it to simplify use. The code was then supposed to be robust but visibly there are corner cases :s
I would be therefore rather make it robust to this case (would that just take removing duplicates in UuidQueue.told ? it should be light speed so not a problem)

cc @bottler you seemed to disagree and want the user to strictly conform to the "contract", maybe we can discuss and adapt depending if I change your mind or not ;)

@Game4Move78 as a power user, would you rather it bugged explicitely, or be robust to those corner cases? (why did you happen to ask for more points?)

Copy link
Contributor Author

@Game4Move78 Game4Move78 Aug 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed the hyper-parameter settings of papers that used DE for HPO and set popsize to 20 explicitly without providing num_workers, and thought it would be robust. I then asked for more points and handed them to my own adaptive resource allocation + early stopping implementation that evaluated HPO choices with multiple budgets and only provided a tell to the NG optimiser when points were either stopped early or allocated maximum budget.

This would work fine for hundreds of points until it hit that corner case with a point in the told queue that has been deleted from population. My current workaround is to provide feedback immediately on the minimum budget and then treat all evaluations on higher budgets as unasked points, which works fine for DE.

If you want less strict (I do too), how about we allow duplicates in told but at L162 we add

while lineage not in self.population:
      lineage = self._uid_queue.ask()

Which I believe would toss away those points that were deleted from a better tell not asked. Future asks will be biased to duplicate points. Added a commit that checks for duplicate tell using absence from asked queue, although there may be a more intuitive way.

Copy link
Contributor Author

@Game4Move78 Game4Move78 Aug 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My personal preference to help users master those details where they can is to copy Ax's client interface with an abandon_tell. For most optimisers this would just tell a large value, and the BO optimisers might do something different to avoid damaging the model.

# init is done
lineage = self._uid_queue.ask()
parent = self.population[lineage]
Expand Down Expand Up @@ -275,8 +278,8 @@ class DifferentialEvolution(base.ConfiguredOptimizer):
F2: float
differential weight #2
popsize: int, "standard", "dimension", "large"
size of the population to use. "standard" is max(num_workers, 30), "dimension" max(num_workers, 30, dimension +1)
and "large" max(num_workers, 30, 7 * dimension).
size of the population to use. "standard" is 30, "dimension" max(30, dimension +1) and "large"
max(30, 7 * dimension). Set to be at least num_workers so that base vectors are distinct.
multiobjective_adaptation: bool
Automatically adapts to handle multiobjective case. This is a very basic **experimental** version,
activated by default because the non-multiobjective implementation is performing very badly.
Expand Down
1 change: 1 addition & 0 deletions nevergrad/optimization/experimentalvariants.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@
MixDeterministicRL = ConfPortfolio(optimizers=[DiagonalCMA, PSO, GeneticDE]).set_name(
"MixDeterministicRL", register=True
)

SpecialRL = Chaining([MixDeterministicRL, TBPSA], ["half"]).set_name("SpecialRL", register=True)
NoisyRL1 = Chaining([MixDeterministicRL, NoisyOnePlusOne], ["half"]).set_name("NoisyRL1", register=True)
NoisyRL2 = Chaining(
Expand Down
4 changes: 2 additions & 2 deletions nevergrad/optimization/optimizerlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,7 @@ def __init__(
num = len(optimizers)
self.optims: tp.List[base.Optimizer] = []
sub_budget = None if budget is None else budget // num + (budget % num > 0)
sub_workers = 1
sub_workers = num_workers
if distribute_workers:
sub_workers = num_workers // num + (num_workers % num > 0)
for opt in optimizers:
Expand Down Expand Up @@ -1673,7 +1673,7 @@ def enable_pickling(self) -> None:
opt.enable_pickling()


ParaPortfolio = ConfPortfolio(optimizers=[CMA, TwoPointsDE, PSO, SQP, ScrHammersleySearch]).set_name(
ParaPortfolio = ConfPortfolio(optimizers=[CMA, TwoPointsDE, PSO, ScrHammersleySearch]).set_name(
"ParaPortfolio", register=True
)
ASCMADEthird = ConfPortfolio(optimizers=[CMA, LhsDE], warmup_ratio=0.33).set_name(
Expand Down