Skip to content

Commit f2246f3

Browse files
committed
converter for raytune, docs and logs
1 parent b326b44 commit f2246f3

File tree

737 files changed

+1490
-722
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

737 files changed

+1490
-722
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions

README.md

Lines changed: 2 additions & 1 deletion

deepcave/plugins/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ def plugin_input_update(pathname: str, *inputs_list: str) -> List[Optional[str]]
306306
if passed_inputs is not None:
307307
# First get normal inputs
308308
inputs = self.load_inputs()
309-
310309
# Overwrite/set the passed inputs
311310
update_dict(inputs, passed_inputs)
312311

@@ -1096,7 +1095,6 @@ def load_run_inputs(
10961095
run_path = run.path
10971096
if run_path is not None:
10981097
run_name = run_path.parent.name + "/" + run.name
1099-
11001098
values.append(run.id)
11011099
labels.append(run_name)
11021100
disabled.append(False)

deepcave/plugins/budget/budget_correlation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ def process(run: AbstractRun, inputs: Dict[str, int]) -> Dict[str, Any]:
198198
objective_id
199199
]
200200
]
201+
201202
c2 += [
202203
run.get_avg_costs(config_id, budget2, statuses=[Status.SUCCESS])[0][
203204
objective_id

deepcave/plugins/hyperparameter/symbolic_explanations.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ def load_dependency_inputs(self, run, previous_inputs, inputs) -> Dict[str, Any]
294294
budgets = run.get_budgets(human=True)
295295
budget_ids = run.get_budget_ids()
296296
budget_options = get_checklist_options(budgets, budget_ids)
297-
298297
hp_dict = run.configspace.get_hyperparameters_dict()
299298
hp_names_numerical = []
300299
for k, v in hp_dict.items():

deepcave/runs/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ def get_budget(self, id: Union[int, str], human: bool = False) -> Union[int, flo
561561
If the budget with this id is invalid.
562562
"""
563563
budgets = self.get_budgets(human=human)
564+
564565
return budgets[int(id)] # type: ignore
565566

566567
def get_budget_ids(self, include_combined: bool = True) -> List[int]:

deepcave/runs/converters/raytune.py

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,8 @@ def hash(self) -> str:
5050
if self.path is None:
5151
return ""
5252

53-
hash_file = [
54-
file
55-
for file in Path(self.path).iterdir()
56-
if file.is_file() and file.name.startswith("experiment_stat")
57-
]
5853
# Use hash of experiment_stat as id
59-
return file_to_hash(hash_file[0])
54+
return file_to_hash(self.path / "results.json")
6055

6156
@property
6257
def latest_change(self) -> float:
@@ -93,6 +88,15 @@ def from_path(cls, path: Path) -> "RayTuneRun":
9388
analysis = None
9489
analysis = ExperimentAnalysis(str(path)).results
9590

91+
# RayTune does not provide a configspace.json
92+
if not os.path.isfile(str(path) + "/configspace.json"):
93+
print(
94+
"The configspace.json file will be auto extracted. For more "
95+
"reliable results please provide your own configspace.json file or "
96+
"ajust the one provided. Numeric values will be treated as uniform values."
97+
" Please also check if the objectives bounds as well as its goal are as wanted."
98+
)
99+
96100
# Get the information of the configspace
97101
if not os.path.isfile(str(path) + "/configspace.json"):
98102
configspace_new = {
@@ -102,6 +106,10 @@ def from_path(cls, path: Path) -> "RayTuneRun":
102106
"forbiddens": [],
103107
"python_module_version": "1.2.0",
104108
"format_version": 0.4,
109+
"comment": "The configspace.json file will be auto extracted. For more"
110+
" reliable results please provide your own configspace.json file or "
111+
"ajust the one provided. Numeric values will be treated as uniform values."
112+
" Please also check if the objectives bounds as well as its goal are as wanted.",
105113
}
106114
# Get hyperparameters as well as upper and lower bounds, types etc
107115

@@ -112,14 +120,13 @@ def from_path(cls, path: Path) -> "RayTuneRun":
112120
else:
113121
hp_names[hp].append(value)
114122

115-
if isinstance(value, str):
116-
for key, values in hp_names.items():
123+
for key, values in hp_names.items():
124+
if isinstance(values[0], str):
117125
values_set = set(values)
118126
configspace_new["hyperparameters"].append(
119127
{"type": "categorical", "name": key, "choices": list(values_set)}
120128
)
121-
else:
122-
for key, values in hp_names.items():
129+
else:
123130
configspace_new["hyperparameters"].append(
124131
{
125132
"type": "uniform_" + type(values[0]).__name__,
@@ -129,9 +136,9 @@ def from_path(cls, path: Path) -> "RayTuneRun":
129136
"default_value": type(values[0])((min(values) + max(values)) / 2),
130137
}
131138
)
139+
132140
with open(str(path) + "/configspace.json", "w") as f:
133141
json.dump(configspace_new, f)
134-
135142
# Convert into a Configuration Space object
136143
configspace = ConfigurationSpace.from_json(path / "configspace.json")
137144
file_path = str(path) + "/experiment_state*"
@@ -142,11 +149,16 @@ def from_path(cls, path: Path) -> "RayTuneRun":
142149
obj = json.loads(nested_json_str)["trainable_name"]
143150

144151
objective = Objective(obj)
145-
run = RayTuneRun(path.stem, configspace=configspace, objectives=objective)
146-
152+
run = RayTuneRun(name=str(path.stem), configspace=configspace, objectives=objective)
153+
run.path = path
147154
config = None
148155
# Get all information of the run
156+
149157
for result in analysis:
158+
# ConfigSpace shortens floats to a certain length
159+
for hp in analysis[result]["config"]:
160+
if not isinstance(analysis[result]["config"][hp], str):
161+
analysis[result]["config"][hp] = round(analysis[result]["config"][hp], 13)
150162
config = Configuration(
151163
configuration_space=configspace,
152164
values=analysis[result]["config"],
@@ -158,11 +170,22 @@ def from_path(cls, path: Path) -> "RayTuneRun":
158170
status = Status.CRASHED
159171
start_time = analysis[result]["timestamp"]
160172
end_time = start_time + analysis[result]["time_this_iter_s"]
161-
cost = analysis[result]["time_this_iter_s"]
173+
cost = analysis[result]["score"]
174+
175+
budget = []
176+
if os.path.isfile(str(path) + "/budget.json"):
177+
with open(str(path) + "/budget.json", "r") as f:
178+
budget_name = json.load(f)
179+
budget = analysis[result][budget_name]
180+
181+
# If a budget is not provided, the budget default is set to the number of trials
182+
else:
183+
budget = len(run.history) # type: ignore
162184

163185
run.add(
164186
costs=cost,
165187
config=config,
188+
budget=budget, # type: ignore
166189
seed=42,
167190
status=status,
168191
start_time=start_time,
@@ -181,15 +204,6 @@ def from_path(cls, path: Path) -> "RayTuneRun":
181204
results_dict = {id: list(config.items())[0] for id, config in analysis.items()}
182205
with open(str(path) + "/results.json", "w") as f:
183206
json.dump(results_dict, f, indent=4)
184-
# TODO: Warning also in configspace.json -> Wie?
185-
# TODO: Warning that all get treated as uniform
186-
# TODO: Warning objective bounds & optimize goal
187-
# TODO: Test other functions of
188-
# TODO: Test for mutliple search variants
189-
# TODO: put raytune in doc install
190-
# TODO: Did pyarrow update break anything?
191-
# TODO: ignores rausnehmen
192-
# TODO: adjust git ignore
193207

194208
return run
195209

@@ -211,14 +225,6 @@ def is_valid_run(cls, path_name: str) -> bool:
211225
"""
212226
for file in Path(path_name).iterdir():
213227
if file.is_file() and file.name.startswith("experiment_state"):
214-
# RayTune does not provide a configspace.json
215-
if not os.path.isfile(path_name + "/configspace.json"):
216-
print(
217-
"The configspace.json file will be auto extracted. For more"
218-
"reliable results please provide your own configspace.json file or "
219-
"ajust the one provided."
220-
)
221-
return True
222228
return True
223-
return False
229+
224230
return False

deepcave/utils/cache.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def write(self) -> None:
9696
return
9797

9898
self._filename.parent.mkdir(exist_ok=True, parents=True)
99+
99100
with self._filename.open("w") as f:
100101
if self._debug:
101102
json.dump(self._data, f, cls=Encoder, indent=4)
@@ -177,6 +178,7 @@ def get(self, *keys: str) -> Optional[Any]:
177178
The value of the key.
178179
"""
179180
d = deepcopy(self._data)
181+
180182
for key in keys:
181183
if key not in d:
182184
return None

docs/converters/raytune.rst

Lines changed: 31 additions & 0 deletions

0 commit comments

Comments
 (0)