Skip to content

Commit 285d93e

Browse files
authored
Merge pull request #223 from automl/222-compatibility-with-current-smac-version
222 compatibility with current smac version
2 parents a7e6cbf + 3e4b235 commit 285d93e

File tree

12 files changed

+13297
-10
lines changed

12 files changed

+13297
-10
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Version 1.3.6
22

3+
## New SMAC version compatibility
4+
- The smac3v2 converter can now also handle the output of the new smac version
5+
6+
# Version 1.3.5
7+
38
## Converter
49
- Added a new converter to handle RayTune runs
510
- Added example RayTune runs to logs

deepcave/custom_queue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def get_workers(self) -> List[Worker]:
103103
List[Worker]
104104
A list of the queued workers.
105105
"""
106-
return Worker.all(queue=self._queue)
106+
return Worker.all(queue=self._queue) # type: ignore
107107

108108
def is_processed(self, job_id: str) -> bool:
109109
"""

deepcave/runs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,6 @@ def get_config_id(self, config: Union[Configuration, Dict]) -> Optional[int]:
505505
config = dict(config)
506506
# Use same rounding as ConfigSpace does
507507
input_config_tuple = config_to_tuple(config, ROUND_PLACES)
508-
509508
# Check if the input configuration tuple exists in the config id mapping
510509
if input_config_tuple in self.config_id_mapping:
511510
return self.config_id_mapping[input_config_tuple]
@@ -745,6 +744,7 @@ def get_avg_costs(
745744

746745
# Budget might not be evaluated
747746
all_costs = self.get_all_costs(budget=budget, statuses=statuses)
747+
748748
if config_id in all_costs:
749749
config_costs = all_costs[config_id]
750750
else:

deepcave/runs/converters/smac3v2.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,28 @@ def from_path(cls, path: Union[Path, str]) -> "SMAC3v2Run":
149149

150150
first_starttime = None
151151

152-
if isinstance(data, list):
153-
import warnings
152+
# The newer runhistory.json format needs to be transformed
153+
if isinstance(data[0], dict):
154+
data = [[d[k] for k in data[0].keys()] for d in data]
155+
156+
# There needs to be a slot for the cpu time parameter
157+
# (which is absent in the older versions)
158+
right_form = []
159+
for d_list in data:
160+
if len(d_list) == 10:
161+
d_list.insert(6, 0.0)
162+
right_form.append(d_list)
163+
data = right_form
154164

155-
warnings.warn(
156-
"The runhistory.json file is in an outdated format.",
157-
DeprecationWarning,
158-
stacklevel=2, # Adjusts the stack level to point to the caller.
159-
)
165+
if isinstance(data, list):
160166
for (
161167
config_id,
162168
instance_id,
163169
seed,
164170
budget,
165171
cost,
166172
time,
173+
cpu_time,
167174
status,
168175
starttime,
169176
endtime,
@@ -176,6 +183,7 @@ def from_path(cls, path: Union[Path, str]) -> "SMAC3v2Run":
176183
budget,
177184
cost,
178185
time,
186+
cpu_time,
179187
status,
180188
starttime,
181189
endtime,
@@ -188,12 +196,20 @@ def from_path(cls, path: Union[Path, str]) -> "SMAC3v2Run":
188196
if run_dict is not None:
189197
run.add(**run_dict)
190198
elif isinstance(data, dict):
199+
import warnings
200+
201+
warnings.warn(
202+
"The runhistory.json file is in an outdated format.",
203+
DeprecationWarning,
204+
stacklevel=2, # Adjusts the stack level to point to the caller.
205+
)
191206
for config_id, config_data in data.items():
192207
instance_id = config_data["instance"]
193208
seed = config_data["seed"]
194209
budget = config_data["budget"]
195210
cost = config_data["cost"]
196211
time = config_data["time"]
212+
cpu_time = config_data["cpu_time"]
197213
status = config_data["status"]
198214
starttime = config_data["starttime"]
199215
endtime = config_data["endtime"]
@@ -205,6 +221,7 @@ def from_path(cls, path: Union[Path, str]) -> "SMAC3v2Run":
205221
budget,
206222
cost,
207223
time,
224+
cpu_time,
208225
status,
209226
starttime,
210227
endtime,
@@ -228,6 +245,7 @@ def _process_data_entry(
228245
budget: Optional[float],
229246
cost: Optional[Union[List[Union[float, None]], float]],
230247
time: Optional[float],
248+
cpu_time: Optional[float],
231249
status: int,
232250
starttime: float,
233251
endtime: float,
@@ -276,6 +294,9 @@ def _process_data_entry(
276294
else:
277295
budget = 0.0
278296

297+
if not cpu_time:
298+
cpu_time = 0.0
299+
279300
origin = None
280301
if config_id in config_origins:
281302
origin = config_origins[config_id]
@@ -285,6 +306,7 @@ def _process_data_entry(
285306
"config": config,
286307
"budget": budget,
287308
"seed": seed,
309+
"cpu_time": cpu_time,
288310
"start_time": starttime,
289311
"end_time": endtime,
290312
"status": status,

deepcave/runs/run.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ def add(
235235
config: Union[Dict, Configuration],
236236
seed: int,
237237
budget: float = np.inf,
238+
cpu_time: float = 0.0,
238239
start_time: float = 0.0,
239240
end_time: float = 0.0,
240241
status: Status = Status.SUCCESS,
@@ -258,6 +259,8 @@ def add(
258259
Seed of the run.
259260
budget : float, optional
260261
Budget of the run. By default np.inf
262+
cpu_time : float, optional
263+
The cpu time of the run. By default 0.0.
261264
start_time : float, optional
262265
Start time. By default, 0.0
263266
end_time : float, optional
@@ -333,6 +336,7 @@ def add(
333336
budget=budget,
334337
seed=seed,
335338
costs=costs,
339+
cpu_time=cpu_time,
336340
start_time=np.round(start_time, 2),
337341
end_time=np.round(end_time, 2),
338342
status=status,
@@ -475,6 +479,10 @@ def load(self, path: Optional[Union[str, Path]] = None) -> None:
475479
with jsonlines.open(self.history_fn) as f:
476480
self.history = []
477481
for obj in f:
482+
# Check wheter cpu time is provided, if not set default
483+
if len(obj) != 11:
484+
obj.insert(6, 0.0)
485+
478486
# Create trial object here
479487
trial = Trial(*obj)
480488
self.history.append(trial)

deepcave/runs/trial.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ class Trial:
4343
The identificator of the configuration.
4444
budget : Union[int, float]
4545
The budget for the trial.
46-
seed: int
46+
seed : int
4747
The seed for the trial.
4848
costs : List[float]
4949
A list of the costs of the trial.
50+
cpu_time : float
51+
The cpu time of the trial.
5052
start_time : float
5153
The start time of the trial.
5254
end_time : float
@@ -59,6 +61,7 @@ class Trial:
5961
budget: Union[int, float]
6062
seed: int
6163
costs: List[float]
64+
cpu_time: float
6265
start_time: float
6366
end_time: float
6467
status: Status
@@ -98,6 +101,7 @@ def to_json(self) -> List[Any]:
98101
self.budget,
99102
self.seed,
100103
self.costs,
104+
self.cpu_time,
101105
self.start_time,
102106
self.end_time,
103107
self.status,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name": null, "hyperparameters": [{"type": "categorical", "name": "activation", "choices": ["logistic", "tanh", "relu"], "weights": null, "default_value": "tanh", "meta": null}, {"type": "uniform_int", "name": "n_layer", "lower": 1, "upper": 5, "default_value": 1, "log": false, "meta": null}, {"type": "uniform_int", "name": "n_neurons", "lower": 8, "upper": 256, "default_value": 10, "log": true, "meta": null}, {"type": "categorical", "name": "solver", "choices": ["lbfgs", "sgd", "adam"], "weights": null, "default_value": "adam", "meta": null}, {"type": "uniform_int", "name": "batch_size", "lower": 30, "upper": 300, "default_value": 200, "log": false, "meta": null}, {"type": "categorical", "name": "learning_rate", "choices": ["constant", "invscaling", "adaptive"], "weights": null, "default_value": "constant", "meta": null}, {"type": "uniform_float", "name": "learning_rate_init", "lower": 0.0001, "upper": 1.0, "default_value": 0.001, "log": true, "meta": null}], "conditions": [{"type": "IN", "child": "batch_size", "parent": "solver", "values": ["sgd", "adam"]}, {"type": "EQ", "child": "learning_rate", "parent": "solver", "value": "sgd"}, {"type": "IN", "child": "learning_rate_init", "parent": "solver", "values": ["sgd", "adam"]}], "forbiddens": [], "python_module_version": "1.2.0", "format_version": 0.4}

0 commit comments

Comments
 (0)