Skip to content

Commit 1921a2f

Browse files
authored
Merge pull request #33 from automl/final_config_fix
Fixing and simplifying final config creation
2 parents 5b53d9d + 25f544f commit 1921a2f

3 files changed

Lines changed: 11 additions & 22 deletions

File tree

.github/workflows/pytest.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
echo "::set-output name=BEFORE::$(git status --porcelain -b)"
5757
5858
- name: Tests
59-
run: pytest tests -v --disable-pytest-warnings
59+
run: python -m pytest tests -v --disable-pytest-warnings
6060

6161
- name: Check for files left behind by test
6262
run: |
@@ -67,4 +67,4 @@ jobs:
6767
echo "git status from after: $after"
6868
echo "Not all generated files have been deleted!"
6969
exit 1
70-
fi
70+
fi

hydra_plugins/hypersweeper/hypersweeper_backend.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
from __future__ import annotations
44

55
import logging
6-
import operator
76
from collections.abc import Callable
8-
from functools import reduce
97
from pathlib import Path
108
from typing import TYPE_CHECKING
119

10+
import numpy as np
1211
from hydra.core.plugins import Plugins
1312
from hydra.plugins.sweeper import Sweeper
1413
from hydra.utils import get_class, get_method
@@ -163,23 +162,13 @@ def sweep(self, arguments: list[str]) -> list | None:
163162
final_config = self.config
164163
with open_dict(final_config):
165164
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+
182171
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)
184173

185174
return incumbent

hydra_plugins/hypersweeper/hypersweeper_sweeper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,4 +523,4 @@ def run(self, verbose=False):
523523
incumbent had a performance of {np.round(inc_performance, decimals=2)}"
524524
)
525525
log.info(f"The incumbent configuration is {inc_config}")
526-
return self.incumbents[-1]
526+
return self.incumbents["config"][-1]

0 commit comments

Comments
 (0)