optimagic: Add wrappers for Nevergrad

Wrap the gradient free optimizers from nevergrad in optimagic.

Nevergrad implements the following algorithms:

  • NgIohTuned is “meta”-optimizer which adapts to the provided settings (budget, number of workers, parametrization) and should therefore be a good default.
  • TwoPointsDE is excellent in many cases, including very high num_workers.
  • PortfolioDiscreteOnePlusOne is excellent in discrete settings of mixed settings when high precision on parameters is not relevant; it’s possibly a good choice for hyperparameter choice.
  • OnePlusOne is a simple robust method for continuous parameters with num_workers < 8.
  • CMA is excellent for control (e.g. neurocontrol) when the environment is not very noisy (num_workers ~50 ok) and when the budget is large (e.g. 1000 x the dimension).
  • TBPSA is excellent for problems corrupted by noise, in particular overparameterized (neural) ones; very high num_workers ok).
  • PSO is excellent in terms of robustness, high num_workers ok.
  • ScrHammersleySearchPlusMiddlePoint is excellent for super parallel cases (fully one-shot, i.e. num_workers = budget included) or for very multimodal cases (such as some of our MLDA problems); don’t use softmax with this optimizer.
  • RandomSearch is the classical random search baseline; don’t use softmax with this optimizer.

In the long run we want to wrap all of them, but if you are tackling this as your first issue you should focus on one. In that case please coment below which optimizer you are going to work on so we don’t duplicate efforts.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 17 (12 by maintainers)

Most upvoted comments

@r3kste, @gulshan-123 unless you have already worked on this we can postpone the implementation of nonlinear constraints until all active nevergrad PRs are merged and we did some refactoring to avoid duplicated code.

@r3kste thanks for the clarification.

Sure, if we cannot make it work with minimize we can use the ask-and-tell interface. Long run that is probably also the better choice if we want to have a more sophisticated outer loop.

range(optimizer.num_workers)

I think here we should have range(min(optimizer.budget-optimizer.num_ask, optimizer.num_workers)), for strict budget constraint.

We actually want to collect histories for all optimizers. The main benefit of history collection is to compare how efficient different optimizers are, i.e. how fast (in terms of function evaluations) they make progress.

There are a few optimizers where we have not found ways to do it yet, but in nevergrad it seems to be quite easy, so we definitely want to do it.

This would for example allow users to compare the efficiency of PSO with a random search algorithm.

@gulshan-123 and @r3kste, thanks for your PRs. In both PRs we currently have the problem that they way you implement parallelism is not compatible with our history collection. I first thought that the only way around this is to use the lower level ask-and-tell inferface, but I think there is a better solution you can try.

Background

Optimagic’s InternalOptimizationProblem automatically adds history collection to the objective function. The collected history forms the basis of om.criterion_plot and other important visualizations. For history collection to work in a parallel case, it is important to use problem.batch_fun (which automatically parallelizes) instead of just using multiprocessing on problem.fun.

Implementation Idea

Nevergrad has the batch_mode and executor arguments for parallelization. An example is here. The executor needs to be compatible with the Executor interface from concurrent.futures.

I think the simplest way to make history collection work with nevergrad is to implement a custom Executor that calls problem.batch_fun internally.