Skip to content

Commit fb55f8f

Browse files
committed
config and result info automatically get stored
1 parent 3da8584 commit fb55f8f

File tree

6 files changed

+123
-17
lines changed

6 files changed

+123
-17
lines changed

deepcave/runs/converters/raytune.py

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
import os
1414
from pathlib import Path
1515

16-
from ConfigSpace import ConfigurationSpace
16+
from ConfigSpace import Configuration, ConfigurationSpace
1717
from ray.tune import ExperimentAnalysis
1818

19+
from deepcave.runs import Status
1920
from deepcave.runs.objective import Objective
2021
from deepcave.runs.run import Run
2122
from deepcave.utils.hash import file_to_hash
@@ -88,6 +89,10 @@ def from_path(cls, path: Path) -> "RayTuneRun":
8889
The run.
8990
"""
9091
configspace = None
92+
hp_names = {}
93+
analysis = None
94+
analysis = ExperimentAnalysis(str(path)).results
95+
9196
# Get the information of the configspace
9297
if not os.path.isfile(str(path) + "/configspace.json"):
9398
configspace = { # type: ignore
@@ -99,14 +104,6 @@ def from_path(cls, path: Path) -> "RayTuneRun":
99104
"format_version": 0.4,
100105
}
101106
# Get hyperparameters as well as upper and lower bounds, types etc
102-
hp_names = {}
103-
analysis = None
104-
analysis = ExperimentAnalysis(str(path)).results
105-
print(analysis)
106-
dic = ExperimentAnalysis(str(path)).get_all_configs()
107-
print(dic)
108-
dii = ExperimentAnalysis(str(path)).dataframe()
109-
print(dii)
110107

111108
for key in analysis.keys():
112109
for hp, value in analysis[key]["config"].items():
@@ -146,19 +143,56 @@ def from_path(cls, path: Path) -> "RayTuneRun":
146143

147144
objective = Objective(obj)
148145
run = RayTuneRun(path.stem, configspace=configspace, objectives=objective) # type: ignore
146+
147+
config = None
148+
# Get all information of the run
149+
for result in analysis:
150+
config = Configuration(
151+
configuration_space=configspace,
152+
values=analysis[result]["config"],
153+
config_id=analysis[result]["trial_id"],
154+
)
155+
if analysis[result]["done"]:
156+
status = Status.SUCCESS
157+
else:
158+
status = Status.CRASHED
159+
start_time = analysis[result]["timestamp"]
160+
end_time = start_time + analysis[result]["time_this_iter_s"]
161+
cost = analysis[result]["time_this_iter_s"]
162+
163+
run.add(
164+
costs=cost,
165+
config=config,
166+
seed=42,
167+
status=status,
168+
start_time=start_time,
169+
end_time=end_time,
170+
)
171+
172+
# The configs are stored, without results
173+
if not os.path.isfile(str(path) + "/configs.json"):
174+
config_dict = {id: config["config"] for id, config in analysis.items()}
175+
with open(str(path) + "/configs.json", "w") as f:
176+
json.dump(config_dict, f, indent=4)
177+
178+
# The results with
179+
if not os.path.isfile(str(path) + "/results.json"):
180+
# The first value of the results should be the result itself
181+
results_dict = {id: list(config.items())[0] for id, config in analysis.items()}
182+
with open(str(path) + "/results.json", "w") as f:
183+
json.dump(results_dict, f, indent=4)
149184
# TODO: Warning also in configspace.json -> Wie?
150185
# TODO: Warning that all get treated as uniform
151-
# TODO: Create RayTune Run
152-
# TODO: What else needs to be in the configspace
186+
# TODO: Warning objective bounds & optimize goal
153187
# TODO: Store results? Where?
154-
# TODO: Get Status
155-
# TODO: Add cost, configs (get all configs), budget, seed, starttime,
156-
# endtime, status, additional?, origin?,
157188
# TODO: Test other functions of
158189
# TODO: Test for mutliple search variants
159190
# TODO: put raytune in doc install
160191
# TODO: Did pyarrow update break anything?
161192
# TODO: ignores rausnehmen
193+
# TODO: adjust git ignore
194+
os.remove(path / "configspace.json")
195+
162196
return run
163197

164198
@classmethod

logs/RayTune/run_1/configspace.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

logs/RayTune/run_2/configs.json

Whitespace-only changes.

logs/RayTune/run_2/configspace.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

logs/RayTune/run_2/results.json

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"fef07_00016": [
3+
"score",
4+
14.59
5+
],
6+
"fef07_00006": [
7+
"score",
8+
9.55
9+
],
10+
"fef07_00003": [
11+
"score",
12+
6.45
13+
],
14+
"fef07_00010": [
15+
"score",
16+
20.69
17+
],
18+
"fef07_00014": [
19+
"score",
20+
14.440000000000001
21+
],
22+
"fef07_00004": [
23+
"score",
24+
11.490000000000002
25+
],
26+
"fef07_00001": [
27+
"score",
28+
20.69
29+
],
30+
"fef07_00011": [
31+
"score",
32+
23.64
33+
],
34+
"fef07_00007": [
35+
"score",
36+
14.59
37+
],
38+
"fef07_00009": [
39+
"score",
40+
15.65
41+
],
42+
"fef07_00008": [
43+
"score",
44+
17.540000000000003
45+
],
46+
"fef07_00012": [
47+
"score",
48+
6.45
49+
],
50+
"fef07_00015": [
51+
"score",
52+
9.55
53+
],
54+
"fef07_00017": [
55+
"score",
56+
17.540000000000003
57+
],
58+
"fef07_00002": [
59+
"score",
60+
23.64
61+
],
62+
"fef07_00000": [
63+
"score",
64+
15.65
65+
],
66+
"fef07_00005": [
67+
"score",
68+
14.440000000000001
69+
],
70+
"fef07_00013": [
71+
"score",
72+
11.490000000000002
73+
]
74+
}

tests/test_runs/test_converter/test_raytune.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class TestRayTune(unittest.TestCase):
88
def test_test(self):
9-
RayTuneRun.from_path(Path("/Users/krissi/Documents/DeepCAVE/logs/RayTune/run_1"))
9+
RayTuneRun.from_path(Path("/Users/krissi/Documents/DeepCAVE/logs/RayTune/run_2"))
1010

1111

1212
if __name__ == "__main__":

0 commit comments

Comments
 (0)