|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import logging |
6 | | -import operator |
7 | 6 | from collections.abc import Callable |
8 | | -from functools import reduce |
9 | 7 | from pathlib import Path |
10 | 8 | from typing import TYPE_CHECKING |
11 | 9 |
|
| 10 | +import numpy as np |
12 | 11 | from hydra.core.plugins import Plugins |
13 | 12 | from hydra.plugins.sweeper import Sweeper |
14 | 13 | from hydra.utils import get_class, get_method |
@@ -163,23 +162,13 @@ def sweep(self, arguments: list[str]) -> list | None: |
163 | 162 | final_config = self.config |
164 | 163 | with open_dict(final_config): |
165 | 164 | del final_config["hydra"] |
166 | | - for a in arguments: |
167 | | - try: |
168 | | - n, v = a.split("=") |
169 | | - key_parts = n.split(".") |
170 | | - reduce(operator.getitem, key_parts[:-1], final_config)[key_parts[-1]] = v |
171 | | - except: # noqa: E722 |
172 | | - print(f"Could not parse argument {a}, skipping.") |
173 | | - schedules = {} |
174 | | - for i in range(len(incumbent)): |
175 | | - for k, v in incumbent[i].items(): |
176 | | - if k not in schedules: |
177 | | - schedules[k] = [] |
178 | | - schedules[k].append(v) |
179 | | - for k in schedules: |
180 | | - key_parts = k.split(".") |
181 | | - reduce(operator.getitem, key_parts[:-1], final_config)[key_parts[-1]] = schedules[k] |
| 165 | + |
| 166 | + for k, v in incumbent.items(): |
| 167 | + if isinstance(v, np.integer | np.floating): |
| 168 | + v = v.item() # noqa: PLW2901 |
| 169 | + OmegaConf.update(final_config, k, v, force_add=True) |
| 170 | + |
182 | 171 | with open(Path(optimizer.output_dir) / "final_config.yaml", "w+") as fp: |
183 | | - OmegaConf.save(config=final_config, f=fp) |
| 172 | + OmegaConf.save(config=final_config, f=fp, resolve=True) |
184 | 173 |
|
185 | 174 | return incumbent |
0 commit comments