-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
45 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,6 +185,8 @@ lint.ignore = [ | |
"N812", | ||
"N817", | ||
"S307", | ||
"S603", | ||
"S607" | ||
] | ||
|
||
exclude = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,41 @@ | ||
#!/usr/bin/env python | ||
"""Tests for `hypersweeper` package.""" | ||
from __future__ import annotations | ||
|
||
import json | ||
import shutil | ||
import subprocess | ||
import pandas as pd | ||
import numpy as np | ||
from pathlib import Path | ||
|
||
import numpy as np | ||
import pandas as pd | ||
|
||
|
||
def test_non_max_incumbent(): | ||
subprocess.call(["python", "examples/branin.py", "--config-name=branin_rs", "-m"]) | ||
assert Path("./tmp/branin_rs").exists(), "Run directory not created" | ||
runhistory = pd.read_csv("./tmp/branin_rs/runhistory.csv") | ||
with open(Path("./tmp/branin_rs/incumbent.json")) as f: | ||
last_line = f.readlines()[-1] | ||
incumbent = json.loads(last_line) | ||
assert np.round(incumbent["score"], decimals=3) == np.round(runhistory["performance"].min(), decimals=3), "Incumbent is not the minimum score in the runhistory" | ||
assert np.round(incumbent["score"], decimals=3) == np.round( | ||
runhistory["performance"].min(), decimals=3 | ||
), "Incumbent is not the minimum score in the runhistory" | ||
shutil.rmtree("./tmp") | ||
|
||
|
||
def test_max_incumbent(): | ||
subprocess.call(["python", "examples/branin.py", "--config-name=branin_rs", "-m", "+hydra.sweeper.sweeper_kwargs.maximize=True"]) | ||
subprocess.call( | ||
["python", "examples/branin.py", "--config-name=branin_rs", "-m", "+hydra.sweeper.sweeper_kwargs.maximize=True"] | ||
) | ||
assert Path("./tmp/branin_rs").exists(), "Run directory not created" | ||
runhistory = pd.read_csv("./tmp/branin_rs/runhistory.csv") | ||
with open(Path("./tmp/branin_rs/incumbent.json")) as f: | ||
last_line = f.readlines()[-1] | ||
incumbent = json.loads(last_line) | ||
print(incumbent["score"], runhistory["performance"].max(), runhistory.performance.min()) | ||
print(runhistory.values) | ||
assert np.round(incumbent["score"], decimals=3) == np.round(runhistory["performance"].max(), decimals=3), "Incumbent is not the maximum score in the runhistory even though maximize is enabled" | ||
shutil.rmtree("./tmp") | ||
assert np.round(incumbent["score"], decimals=3) == np.round( | ||
runhistory["performance"].max(), decimals=3 | ||
), "Incumbent is not the maximum score in the runhistory even though maximize is enabled" | ||
shutil.rmtree("./tmp") |