We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[Bug] The nevergrad sweeper is not properly handling quoted strings
# 🐛 Bug
## Description

The nevergrad sweeper does not properly handle quoted strings (this also manifests in other problems, e.g., with `null` values).


## Checklist
- [X] I checked on the latest version of Hydra
- [X] I created a minimal repro (See [this](https://stackoverflow.com/help/minimal-reproducible-example) for tips).

## To reproduce

** Minimal Code/Config snippet to reproduce **

```bash
python example/my_app.py -m hydra.sweeper.optim.budget=1 hydra.sweeper.optim.num_workers=1 +key="'a&b'"
```

** Stack trace/error message **
```
[2023-03-15 13:01:58,886][HYDRA] NevergradSweeper(optimizer=OnePlusOne, budget=1, num_workers=1) minimization
[2023-03-15 13:01:58,886][HYDRA] with parametrization Dict(+key=a&b,batch_size=Scalar{Cl(4,16,b),Int}[sigma=Scalar{exp=2.03}],db=Choice(choices=Tuple(mnist,cifar),indices=Array{(1,2),SoftmaxSampling}),dropout=Scalar{Cl(0,1,b)}[sigma=Scalar{exp=2.03}],lr=Log{exp=2.00}):{'db': 'mnist', 'lr': 0.020000000000000004, 'dropout': 0.5, 'batch_size': 10, '+key': 'a&b'}
[2023-03-15 13:01:58,888][HYDRA] Sweep output dir: multirun/2023-03-15/13-01-57
LexerNoViableAltException: +key=a&b
```

## Expected Behavior
It should work, passing the override `+key='a&b'` to the job being launched.

## System information
- **Hydra Version** :  latest master
- **Python version** : Python 3.9

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `plugins/hydra_nevergrad_sweeper/hydra_plugins/hydra_nevergrad_sweeper/_impl.py`
Content:
```
1 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
2 import logging
3 import math
4 from typing import (
5     Any,
6     Dict,
7     List,
8     MutableMapping,
9     MutableSequence,
10     Optional,
11     Tuple,
12     Union,
13 )
14 
15 import nevergrad as ng
16 from hydra.core import utils
17 from hydra.core.override_parser.overrides_parser import OverridesParser
18 from hydra.core.override_parser.types import (
19     ChoiceSweep,
20     IntervalSweep,
21     Override,
22     Transformer,
23 )
24 from hydra.core.plugins import Plugins
25 from hydra.plugins.launcher import Launcher
26 from hydra.plugins.sweeper import Sweeper
27 from hydra.types import HydraContext, TaskFunction
28 from omegaconf import DictConfig, ListConfig, OmegaConf
29 
30 from .config import OptimConf, ScalarConfigSpec
31 
32 log = logging.getLogger(__name__)
33 
34 
35 def create_nevergrad_param_from_config(
36     config: Union[MutableSequence[Any], MutableMapping[str, Any]]
37 ) -> Any:
38     if isinstance(config, MutableSequence):
39         if isinstance(config, ListConfig):
40             config = OmegaConf.to_container(config, resolve=True)  # type: ignore
41         return ng.p.Choice(config)
42     if isinstance(config, MutableMapping):
43         specs = ScalarConfigSpec(**config)
44         init = ["init", "lower", "upper"]
45         init_params = {x: getattr(specs, x) for x in init}
46         if not specs.log:
47             scalar = ng.p.Scalar(**init_params)
48             if specs.step is not None:
49                 scalar.set_mutation(sigma=specs.step)
50         else:
51             if specs.step is not None:
52                 init_params["exponent"] = specs.step
53             scalar = ng.p.Log(**init_params)
54         if specs.integer:
55             scalar.set_integer_casting()
56         return scalar
57     return config
58 
59 
60 def create_nevergrad_parameter_from_override(override: Override) -> Any:
61     val = override.value()
62     if not override.is_sweep_override():
63         return val
64     if override.is_choice_sweep():
65         assert isinstance(val, ChoiceSweep)
66         vals = [x for x in override.sweep_iterator(transformer=Transformer.encode)]
67         if "ordered" in val.tags:
68             return ng.p.TransitionChoice(vals)
69         else:
70             return ng.p.Choice(vals)
71     elif override.is_range_sweep():
72         vals = [x for x in override.sweep_iterator(transformer=Transformer.encode)]
73         return ng.p.Choice(vals)
74     elif override.is_interval_sweep():
75         assert isinstance(val, IntervalSweep)
76         if "log" in val.tags:
77             scalar = ng.p.Log(lower=val.start, upper=val.end)
78         else:
79             scalar = ng.p.Scalar(lower=val.start, upper=val.end)  # type: ignore
80         if isinstance(val.start, int):
81             scalar.set_integer_casting()
82         return scalar
83 
84 
85 class NevergradSweeperImpl(Sweeper):
86     def __init__(
87         self,
88         optim: OptimConf,
89         parametrization: Optional[DictConfig],
90     ):
91         self.opt_config = optim
92         self.config: Optional[DictConfig] = None
93         self.launcher: Optional[Launcher] = None
94         self.hydra_context: Optional[HydraContext] = None
95         self.job_results = None
96         self.parametrization: Dict[str, Any] = {}
97         if parametrization is not None:
98             assert isinstance(parametrization, DictConfig)
99             self.parametrization = {
100                 str(x): create_nevergrad_param_from_config(y)
101                 for x, y in parametrization.items()
102             }
103         self.job_idx: Optional[int] = None
104 
105     def setup(
106         self,
107         *,
108         hydra_context: HydraContext,
109         task_function: TaskFunction,
110         config: DictConfig,
111     ) -> None:
112         self.job_idx = 0
113         self.config = config
114         self.hydra_context = hydra_context
115         self.launcher = Plugins.instance().instantiate_launcher(
116             hydra_context=hydra_context, task_function=task_function, config=config
117         )
118 
119     def sweep(self, arguments: List[str]) -> None:
120         assert self.config is not None
121         assert self.launcher is not None
122         assert self.job_idx is not None
123         direction = -1 if self.opt_config.maximize else 1
124         name = "maximization" if self.opt_config.maximize else "minimization"
125         # Override the parametrization from commandline
126         params = dict(self.parametrization)
127 
128         parser = OverridesParser.create()
129         parsed = parser.parse_overrides(arguments)
130 
131         for override in parsed:
132             params[
133                 override.get_key_element()
134             ] = create_nevergrad_parameter_from_override(override)
135 
136         parametrization = ng.p.Dict(**params)
137         parametrization.function.deterministic = not self.opt_config.noisy
138         parametrization.random_state.seed(self.opt_config.seed)
139         # log and build the optimizer
140         opt = self.opt_config.optimizer
141         remaining_budget = self.opt_config.budget
142         nw = self.opt_config.num_workers
143         log.info(
144             f"NevergradSweeper(optimizer={opt}, budget={remaining_budget}, "
145             f"num_workers={nw}) {name}"
146         )
147         log.info(f"with parametrization {parametrization}")
148         log.info(f"Sweep output dir: {self.config.hydra.sweep.dir}")
149         optimizer = ng.optimizers.registry[opt](parametrization, remaining_budget, nw)
150         # loop!
151         all_returns: List[Any] = []
152         best: Tuple[float, ng.p.Parameter] = (float("inf"), parametrization)
153         while remaining_budget > 0:
154             batch = min(nw, remaining_budget)
155             remaining_budget -= batch
156             candidates = [optimizer.ask() for _ in range(batch)]
157             overrides = list(
158                 tuple(f"{x}={y}" for x, y in c.value.items()) for c in candidates
159             )
160             self.validate_batch_is_legal(overrides)
161             returns = self.launcher.launch(overrides, initial_job_idx=self.job_idx)
162             # would have been nice to avoid waiting for all jobs to finish
163             # aka batch size Vs steady state (launching a new job whenever one is done)
164             self.job_idx += len(returns)
165             # check job status and prepare losses
166             failures = 0
167             for cand, ret in zip(candidates, returns):
168                 if ret.status == utils.JobStatus.COMPLETED:
169                     rectified_loss = direction * ret.return_value
170                 else:
171                     rectified_loss = math.inf
172                     failures += 1
173                     try:
174                         ret.return_value
175                     except Exception as e:
176                         log.warning(f"Returning infinity for failed experiment: {e}")
177                 optimizer.tell(cand, rectified_loss)
178                 if rectified_loss < best[0]:
179                     best = (rectified_loss, cand)
180             # raise if too many failures
181             if failures / len(returns) > self.opt_config.max_failure_rate:
182                 log.error(
183                     f"Failed {failures} times out of {len(returns)} "
184                     f"with max_failure_rate={self.opt_config.max_failure_rate}"
185                 )
186                 for ret in returns:
187                     ret.return_value  # delegate raising to JobReturn, with actual traceback
188             all_returns.extend(returns)
189         recom = optimizer.provide_recommendation()
190         results_to_serialize = {
191             "name": "nevergrad",
192             "best_evaluated_params": best[1].value,
193             "best_evaluated_result": direction * best[0],
194         }
195         OmegaConf.save(
196             OmegaConf.create(results_to_serialize),
197             f"{self.config.hydra.sweep.dir}/optimization_results.yaml",
198         )
199         log.info(
200             "Best parameters: %s", " ".join(f"{x}={y}" for x, y in recom.value.items())
201         )
202
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/plugins/hydra_nevergrad_sweeper/hydra_plugins/hydra_nevergrad_sweeper/_impl.py b/plugins/hydra_nevergrad_sweeper/hydra_plugins/hydra_nevergrad_sweeper/_impl.py
--- a/plugins/hydra_nevergrad_sweeper/hydra_plugins/hydra_nevergrad_sweeper/_impl.py
+++ b/plugins/hydra_nevergrad_sweeper/hydra_plugins/hydra_nevergrad_sweeper/_impl.py
@@ -60,7 +60,7 @@
 def create_nevergrad_parameter_from_override(override: Override) -> Any:
     val = override.value()
     if not override.is_sweep_override():
-        return val
+        return override.get_value_element_as_str()
     if override.is_choice_sweep():
         assert isinstance(val, ChoiceSweep)
         vals = [x for x in override.sweep_iterator(transformer=Transformer.encode)]

{"golden_diff": "diff --git a/plugins/hydra_nevergrad_sweeper/hydra_plugins/hydra_nevergrad_sweeper/_impl.py b/plugins/hydra_nevergrad_sweeper/hydra_plugins/hydra_nevergrad_sweeper/_impl.py\n--- a/plugins/hydra_nevergrad_sweeper/hydra_plugins/hydra_nevergrad_sweeper/_impl.py\n+++ b/plugins/hydra_nevergrad_sweeper/hydra_plugins/hydra_nevergrad_sweeper/_impl.py\n@@ -60,7 +60,7 @@\n def create_nevergrad_parameter_from_override(override: Override) -> Any:\n     val = override.value()\n     if not override.is_sweep_override():\n-        return val\n+        return override.get_value_element_as_str()\n     if override.is_choice_sweep():\n         assert isinstance(val, ChoiceSweep)\n         vals = [x for x in override.sweep_iterator(transformer=Transformer.encode)]\n", "issue": "[Bug] The nevergrad sweeper is not properly handling quoted strings\n# \ud83d\udc1b Bug\r\n## Description\r\n\r\nThe nevergrad sweeper does not properly handle quoted strings (this also manifests in other problems, e.g., with `null` values).\r\n\r\n\r\n## Checklist\r\n- [X] I checked on the latest version of Hydra\r\n- [X] I created a minimal repro (See [this](https://stackoverflow.com/help/minimal-reproducible-example) for tips).\r\n\r\n## To reproduce\r\n\r\n** Minimal Code/Config snippet to reproduce **\r\n\r\n```bash\r\npython example/my_app.py -m hydra.sweeper.optim.budget=1 hydra.sweeper.optim.num_workers=1 +key=\"'a&b'\"\r\n```\r\n\r\n** Stack trace/error message **\r\n```\r\n[2023-03-15 13:01:58,886][HYDRA] NevergradSweeper(optimizer=OnePlusOne, budget=1, num_workers=1) minimization\r\n[2023-03-15 13:01:58,886][HYDRA] with parametrization Dict(+key=a&b,batch_size=Scalar{Cl(4,16,b),Int}[sigma=Scalar{exp=2.03}],db=Choice(choices=Tuple(mnist,cifar),indices=Array{(1,2),SoftmaxSampling}),dropout=Scalar{Cl(0,1,b)}[sigma=Scalar{exp=2.03}],lr=Log{exp=2.00}):{'db': 'mnist', 'lr': 0.020000000000000004, 'dropout': 0.5, 'batch_size': 10, '+key': 'a&b'}\r\n[2023-03-15 13:01:58,888][HYDRA] Sweep output dir: multirun/2023-03-15/13-01-57\r\nLexerNoViableAltException: +key=a&b\r\n```\r\n\r\n## Expected Behavior\r\nIt should work, passing the override `+key='a&b'` to the job being launched.\r\n\r\n## System information\r\n- **Hydra Version** :  latest master\r\n- **Python version** : Python 3.9\n", "before_files": [{"content": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\nimport logging\nimport math\nfrom typing import (\n    Any,\n    Dict,\n    List,\n    MutableMapping,\n    MutableSequence,\n    Optional,\n    Tuple,\n    Union,\n)\n\nimport nevergrad as ng\nfrom hydra.core import utils\nfrom hydra.core.override_parser.overrides_parser import OverridesParser\nfrom hydra.core.override_parser.types import (\n    ChoiceSweep,\n    IntervalSweep,\n    Override,\n    Transformer,\n)\nfrom hydra.core.plugins import Plugins\nfrom hydra.plugins.launcher import Launcher\nfrom hydra.plugins.sweeper import Sweeper\nfrom hydra.types import HydraContext, TaskFunction\nfrom omegaconf import DictConfig, ListConfig, OmegaConf\n\nfrom .config import OptimConf, ScalarConfigSpec\n\nlog = logging.getLogger(__name__)\n\n\ndef create_nevergrad_param_from_config(\n    config: Union[MutableSequence[Any], MutableMapping[str, Any]]\n) -> Any:\n    if isinstance(config, MutableSequence):\n        if isinstance(config, ListConfig):\n            config = OmegaConf.to_container(config, resolve=True)  # type: ignore\n        return ng.p.Choice(config)\n    if isinstance(config, MutableMapping):\n        specs = ScalarConfigSpec(**config)\n        init = [\"init\", \"lower\", \"upper\"]\n        init_params = {x: getattr(specs, x) for x in init}\n        if not specs.log:\n            scalar = ng.p.Scalar(**init_params)\n            if specs.step is not None:\n                scalar.set_mutation(sigma=specs.step)\n        else:\n            if specs.step is not None:\n                init_params[\"exponent\"] = specs.step\n            scalar = ng.p.Log(**init_params)\n        if specs.integer:\n            scalar.set_integer_casting()\n        return scalar\n    return config\n\n\ndef create_nevergrad_parameter_from_override(override: Override) -> Any:\n    val = override.value()\n    if not override.is_sweep_override():\n        return val\n    if override.is_choice_sweep():\n        assert isinstance(val, ChoiceSweep)\n        vals = [x for x in override.sweep_iterator(transformer=Transformer.encode)]\n        if \"ordered\" in val.tags:\n            return ng.p.TransitionChoice(vals)\n        else:\n            return ng.p.Choice(vals)\n    elif override.is_range_sweep():\n        vals = [x for x in override.sweep_iterator(transformer=Transformer.encode)]\n        return ng.p.Choice(vals)\n    elif override.is_interval_sweep():\n        assert isinstance(val, IntervalSweep)\n        if \"log\" in val.tags:\n            scalar = ng.p.Log(lower=val.start, upper=val.end)\n        else:\n            scalar = ng.p.Scalar(lower=val.start, upper=val.end)  # type: ignore\n        if isinstance(val.start, int):\n            scalar.set_integer_casting()\n        return scalar\n\n\nclass NevergradSweeperImpl(Sweeper):\n    def __init__(\n        self,\n        optim: OptimConf,\n        parametrization: Optional[DictConfig],\n    ):\n        self.opt_config = optim\n        self.config: Optional[DictConfig] = None\n        self.launcher: Optional[Launcher] = None\n        self.hydra_context: Optional[HydraContext] = None\n        self.job_results = None\n        self.parametrization: Dict[str, Any] = {}\n        if parametrization is not None:\n            assert isinstance(parametrization, DictConfig)\n            self.parametrization = {\n                str(x): create_nevergrad_param_from_config(y)\n                for x, y in parametrization.items()\n            }\n        self.job_idx: Optional[int] = None\n\n    def setup(\n        self,\n        *,\n        hydra_context: HydraContext,\n        task_function: TaskFunction,\n        config: DictConfig,\n    ) -> None:\n        self.job_idx = 0\n        self.config = config\n        self.hydra_context = hydra_context\n        self.launcher = Plugins.instance().instantiate_launcher(\n            hydra_context=hydra_context, task_function=task_function, config=config\n        )\n\n    def sweep(self, arguments: List[str]) -> None:\n        assert self.config is not None\n        assert self.launcher is not None\n        assert self.job_idx is not None\n        direction = -1 if self.opt_config.maximize else 1\n        name = \"maximization\" if self.opt_config.maximize else \"minimization\"\n        # Override the parametrization from commandline\n        params = dict(self.parametrization)\n\n        parser = OverridesParser.create()\n        parsed = parser.parse_overrides(arguments)\n\n        for override in parsed:\n            params[\n                override.get_key_element()\n            ] = create_nevergrad_parameter_from_override(override)\n\n        parametrization = ng.p.Dict(**params)\n        parametrization.function.deterministic = not self.opt_config.noisy\n        parametrization.random_state.seed(self.opt_config.seed)\n        # log and build the optimizer\n        opt = self.opt_config.optimizer\n        remaining_budget = self.opt_config.budget\n        nw = self.opt_config.num_workers\n        log.info(\n            f\"NevergradSweeper(optimizer={opt}, budget={remaining_budget}, \"\n            f\"num_workers={nw}) {name}\"\n        )\n        log.info(f\"with parametrization {parametrization}\")\n        log.info(f\"Sweep output dir: {self.config.hydra.sweep.dir}\")\n        optimizer = ng.optimizers.registry[opt](parametrization, remaining_budget, nw)\n        # loop!\n        all_returns: List[Any] = []\n        best: Tuple[float, ng.p.Parameter] = (float(\"inf\"), parametrization)\n        while remaining_budget > 0:\n            batch = min(nw, remaining_budget)\n            remaining_budget -= batch\n            candidates = [optimizer.ask() for _ in range(batch)]\n            overrides = list(\n                tuple(f\"{x}={y}\" for x, y in c.value.items()) for c in candidates\n            )\n            self.validate_batch_is_legal(overrides)\n            returns = self.launcher.launch(overrides, initial_job_idx=self.job_idx)\n            # would have been nice to avoid waiting for all jobs to finish\n            # aka batch size Vs steady state (launching a new job whenever one is done)\n            self.job_idx += len(returns)\n            # check job status and prepare losses\n            failures = 0\n            for cand, ret in zip(candidates, returns):\n                if ret.status == utils.JobStatus.COMPLETED:\n                    rectified_loss = direction * ret.return_value\n                else:\n                    rectified_loss = math.inf\n                    failures += 1\n                    try:\n                        ret.return_value\n                    except Exception as e:\n                        log.warning(f\"Returning infinity for failed experiment: {e}\")\n                optimizer.tell(cand, rectified_loss)\n                if rectified_loss < best[0]:\n                    best = (rectified_loss, cand)\n            # raise if too many failures\n            if failures / len(returns) > self.opt_config.max_failure_rate:\n                log.error(\n                    f\"Failed {failures} times out of {len(returns)} \"\n                    f\"with max_failure_rate={self.opt_config.max_failure_rate}\"\n                )\n                for ret in returns:\n                    ret.return_value  # delegate raising to JobReturn, with actual traceback\n            all_returns.extend(returns)\n        recom = optimizer.provide_recommendation()\n        results_to_serialize = {\n            \"name\": \"nevergrad\",\n            \"best_evaluated_params\": best[1].value,\n            \"best_evaluated_result\": direction * best[0],\n        }\n        OmegaConf.save(\n            OmegaConf.create(results_to_serialize),\n            f\"{self.config.hydra.sweep.dir}/optimization_results.yaml\",\n        )\n        log.info(\n            \"Best parameters: %s\", \" \".join(f\"{x}={y}\" for x, y in recom.value.items())\n        )\n", "path": "plugins/hydra_nevergrad_sweeper/hydra_plugins/hydra_nevergrad_sweeper/_impl.py"}], "after_files": [{"content": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\nimport logging\nimport math\nfrom typing import (\n    Any,\n    Dict,\n    List,\n    MutableMapping,\n    MutableSequence,\n    Optional,\n    Tuple,\n    Union,\n)\n\nimport nevergrad as ng\nfrom hydra.core import utils\nfrom hydra.core.override_parser.overrides_parser import OverridesParser\nfrom hydra.core.override_parser.types import (\n    ChoiceSweep,\n    IntervalSweep,\n    Override,\n    Transformer,\n)\nfrom hydra.core.plugins import Plugins\nfrom hydra.plugins.launcher import Launcher\nfrom hydra.plugins.sweeper import Sweeper\nfrom hydra.types import HydraContext, TaskFunction\nfrom omegaconf import DictConfig, ListConfig, OmegaConf\n\nfrom .config import OptimConf, ScalarConfigSpec\n\nlog = logging.getLogger(__name__)\n\n\ndef create_nevergrad_param_from_config(\n    config: Union[MutableSequence[Any], MutableMapping[str, Any]]\n) -> Any:\n    if isinstance(config, MutableSequence):\n        if isinstance(config, ListConfig):\n            config = OmegaConf.to_container(config, resolve=True)  # type: ignore\n        return ng.p.Choice(config)\n    if isinstance(config, MutableMapping):\n        specs = ScalarConfigSpec(**config)\n        init = [\"init\", \"lower\", \"upper\"]\n        init_params = {x: getattr(specs, x) for x in init}\n        if not specs.log:\n            scalar = ng.p.Scalar(**init_params)\n            if specs.step is not None:\n                scalar.set_mutation(sigma=specs.step)\n        else:\n            if specs.step is not None:\n                init_params[\"exponent\"] = specs.step\n            scalar = ng.p.Log(**init_params)\n        if specs.integer:\n            scalar.set_integer_casting()\n        return scalar\n    return config\n\n\ndef create_nevergrad_parameter_from_override(override: Override) -> Any:\n    val = override.value()\n    if not override.is_sweep_override():\n        return override.get_value_element_as_str()\n    if override.is_choice_sweep():\n        assert isinstance(val, ChoiceSweep)\n        vals = [x for x in override.sweep_iterator(transformer=Transformer.encode)]\n        if \"ordered\" in val.tags:\n            return ng.p.TransitionChoice(vals)\n        else:\n            return ng.p.Choice(vals)\n    elif override.is_range_sweep():\n        vals = [x for x in override.sweep_iterator(transformer=Transformer.encode)]\n        return ng.p.Choice(vals)\n    elif override.is_interval_sweep():\n        assert isinstance(val, IntervalSweep)\n        if \"log\" in val.tags:\n            scalar = ng.p.Log(lower=val.start, upper=val.end)\n        else:\n            scalar = ng.p.Scalar(lower=val.start, upper=val.end)  # type: ignore\n        if isinstance(val.start, int):\n            scalar.set_integer_casting()\n        return scalar\n\n\nclass NevergradSweeperImpl(Sweeper):\n    def __init__(\n        self,\n        optim: OptimConf,\n        parametrization: Optional[DictConfig],\n    ):\n        self.opt_config = optim\n        self.config: Optional[DictConfig] = None\n        self.launcher: Optional[Launcher] = None\n        self.hydra_context: Optional[HydraContext] = None\n        self.job_results = None\n        self.parametrization: Dict[str, Any] = {}\n        if parametrization is not None:\n            assert isinstance(parametrization, DictConfig)\n            self.parametrization = {\n                str(x): create_nevergrad_param_from_config(y)\n                for x, y in parametrization.items()\n            }\n        self.job_idx: Optional[int] = None\n\n    def setup(\n        self,\n        *,\n        hydra_context: HydraContext,\n        task_function: TaskFunction,\n        config: DictConfig,\n    ) -> None:\n        self.job_idx = 0\n        self.config = config\n        self.hydra_context = hydra_context\n        self.launcher = Plugins.instance().instantiate_launcher(\n            hydra_context=hydra_context, task_function=task_function, config=config\n        )\n\n    def sweep(self, arguments: List[str]) -> None:\n        assert self.config is not None\n        assert self.launcher is not None\n        assert self.job_idx is not None\n        direction = -1 if self.opt_config.maximize else 1\n        name = \"maximization\" if self.opt_config.maximize else \"minimization\"\n        # Override the parametrization from commandline\n        params = dict(self.parametrization)\n\n        parser = OverridesParser.create()\n        parsed = parser.parse_overrides(arguments)\n\n        for override in parsed:\n            params[\n                override.get_key_element()\n            ] = create_nevergrad_parameter_from_override(override)\n\n        parametrization = ng.p.Dict(**params)\n        parametrization.function.deterministic = not self.opt_config.noisy\n        parametrization.random_state.seed(self.opt_config.seed)\n        # log and build the optimizer\n        opt = self.opt_config.optimizer\n        remaining_budget = self.opt_config.budget\n        nw = self.opt_config.num_workers\n        log.info(\n            f\"NevergradSweeper(optimizer={opt}, budget={remaining_budget}, \"\n            f\"num_workers={nw}) {name}\"\n        )\n        log.info(f\"with parametrization {parametrization}\")\n        log.info(f\"Sweep output dir: {self.config.hydra.sweep.dir}\")\n        optimizer = ng.optimizers.registry[opt](parametrization, remaining_budget, nw)\n        # loop!\n        all_returns: List[Any] = []\n        best: Tuple[float, ng.p.Parameter] = (float(\"inf\"), parametrization)\n        while remaining_budget > 0:\n            batch = min(nw, remaining_budget)\n            remaining_budget -= batch\n            candidates = [optimizer.ask() for _ in range(batch)]\n            overrides = list(\n                tuple(f\"{x}={y}\" for x, y in c.value.items()) for c in candidates\n            )\n            self.validate_batch_is_legal(overrides)\n            returns = self.launcher.launch(overrides, initial_job_idx=self.job_idx)\n            # would have been nice to avoid waiting for all jobs to finish\n            # aka batch size Vs steady state (launching a new job whenever one is done)\n            self.job_idx += len(returns)\n            # check job status and prepare losses\n            failures = 0\n            for cand, ret in zip(candidates, returns):\n                if ret.status == utils.JobStatus.COMPLETED:\n                    rectified_loss = direction * ret.return_value\n                else:\n                    rectified_loss = math.inf\n                    failures += 1\n                    try:\n                        ret.return_value\n                    except Exception as e:\n                        log.warning(f\"Returning infinity for failed experiment: {e}\")\n                optimizer.tell(cand, rectified_loss)\n                if rectified_loss < best[0]:\n                    best = (rectified_loss, cand)\n            # raise if too many failures\n            if failures / len(returns) > self.opt_config.max_failure_rate:\n                log.error(\n                    f\"Failed {failures} times out of {len(returns)} \"\n                    f\"with max_failure_rate={self.opt_config.max_failure_rate}\"\n                )\n                for ret in returns:\n                    ret.return_value  # delegate raising to JobReturn, with actual traceback\n            all_returns.extend(returns)\n        recom = optimizer.provide_recommendation()\n        results_to_serialize = {\n            \"name\": \"nevergrad\",\n            \"best_evaluated_params\": best[1].value,\n            \"best_evaluated_result\": direction * best[0],\n        }\n        OmegaConf.save(\n            OmegaConf.create(results_to_serialize),\n            f\"{self.config.hydra.sweep.dir}/optimization_results.yaml\",\n        )\n        log.info(\n            \"Best parameters: %s\", \" \".join(f\"{x}={y}\" for x, y in recom.value.items())\n        )\n", "path": "plugins/hydra_nevergrad_sweeper/hydra_plugins/hydra_nevergrad_sweeper/_impl.py"}]}