1313import os
1414from pathlib import Path
1515
16- from ConfigSpace import ConfigurationSpace
16+ from ConfigSpace import Configuration , ConfigurationSpace
1717from ray .tune import ExperimentAnalysis
1818
19+ from deepcave .runs import Status
1920from deepcave .runs .objective import Objective
2021from deepcave .runs .run import Run
2122from 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
0 commit comments