Repository: facebookresearch/hydra

Issue:
[nevergrad] Port Nevergrad sweeper to use Structured configs
cc @jrapin 


Discussion:

Resolving patch:
diff --git a/plugins/hydra_nevergrad_sweeper/hydra_plugins/hydra_nevergrad_sweeper/conf/__init__.py b/plugins/hydra_nevergrad_sweeper/hydra_plugins/hydra_nevergrad_sweeper/conf/__init__.py
deleted file mode 100644
--- a/plugins/hydra_nevergrad_sweeper/hydra_plugins/hydra_nevergrad_sweeper/conf/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
diff --git a/plugins/hydra_nevergrad_sweeper/hydra_plugins/hydra_nevergrad_sweeper/config.py b/plugins/hydra_nevergrad_sweeper/hydra_plugins/hydra_nevergrad_sweeper/config.py
new file mode 100644
--- /dev/null
+++ b/plugins/hydra_nevergrad_sweeper/hydra_plugins/hydra_nevergrad_sweeper/config.py
@@ -0,0 +1,68 @@
+# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
+from dataclasses import dataclass, field
+from typing import Any, Dict, Optional
+
+from hydra.core.config_store import ConfigStore
+from hydra.types import ObjectConf
+
+
+@dataclass
+class OptimConf:
+
+    # name of the Nevergrad optimizer to use. Here is a sample:
+    #   - "OnePlusOne" extremely simple and robust, especially at low budget, but
+    #     tends to converge early.
+    #   - "CMA" very good algorithm, but may require a significant budget (> 120)
+    #   - "TwoPointsDE": an algorithm good in a wide range of settings, for significant
+    #     budgets (> 120).
+    #   - "Shiva" an algorithm aiming at identifying the best optimizer given your input
+    #     definition (work in progress, it may still be ill-suited for low budget)
+    # find out more within nevergrad's documentation:
+    # https://github.com/facebookresearch/nevergrad/
+    optimizer: str = "OnePlusOne"
+
+    # total number of function evaluations to perform
+    budget: int = 80
+
+    # number of parallel workers for performing function evaluations
+    num_workers: int = 10
+
+    # set to true if the function evaluations are noisy
+    noisy: bool = False
+
+    # set to true for performing maximization instead of minimization
+    maximize: bool = False
+
+    # optimization seed, for reproducibility
+    seed: Optional[int] = None
+
+
+@dataclass
+class NevergradConf:
+
+    # configuration of the optimizer
+    optim: OptimConf = OptimConf()
+
+    # default parametrization of the search space
+    # can be specified:
+    # - as a string, like commandline arguments
+    # - as a list, for categorical variables
+    # - as a full scalar specification
+    parametrization: Dict[str, Any] = field(default_factory=dict)
+
+    # version of the commandline API
+    version: int = 1
+
+
+@dataclass
+class NevergradSweeperConf(ObjectConf):
+    cls: str = "hydra_plugins.hydra_nevergrad_sweeper.core.NevergradSweeper"
+    params: NevergradConf = NevergradConf()
+
+
+ConfigStore.instance().store(
+    group="hydra/sweeper",
+    name="nevergrad",
+    path="hydra.sweeper",
+    node=NevergradSweeperConf,
+)
diff --git a/plugins/hydra_nevergrad_sweeper/hydra_plugins/hydra_nevergrad_sweeper/core.py b/plugins/hydra_nevergrad_sweeper/hydra_plugins/hydra_nevergrad_sweeper/core.py
--- a/plugins/hydra_nevergrad_sweeper/hydra_plugins/hydra_nevergrad_sweeper/core.py
+++ b/plugins/hydra_nevergrad_sweeper/hydra_plugins/hydra_nevergrad_sweeper/core.py
@@ -12,6 +12,8 @@
 from hydra.plugins.sweeper import Sweeper
 from hydra.types import TaskFunction
 
+from .config import OptimConf
+
 # pylint: disable=logging-fstring-interpolation,no-self-used
 
 log = logging.getLogger(__name__)
@@ -20,7 +22,7 @@
 class NevergradSearchPathPlugin(SearchPathPlugin):
     def manipulate_search_path(self, search_path: ConfigSearchPath) -> None:
         search_path.append(
-            "nevergrad", "pkg://hydra_plugins.hydra_nevergrad_sweeper.conf"
+            "nevergrad", "pkg://hydra_plugins.hydra_nevergrad_sweeper.config"
         )
 
 
@@ -152,7 +154,7 @@ class NevergradSweeper(Sweeper):
     """
 
     def __init__(
-        self, optim: DictConfig, version: int, parametrization: Optional[DictConfig],
+        self, optim: OptimConf, version: int, parametrization: Optional[DictConfig],
     ):
         assert (
             version == 1


Test patch: