Skip to content

Commit

Permalink
Merge pull request #105 from automl/feature/smac-multi-objective
Browse files Browse the repository at this point in the history
Feature/smac-multi-objective
  • Loading branch information
sarah-segel authored Jan 25, 2024
2 parents 019855e + 95b4eac commit d73688e
Show file tree
Hide file tree
Showing 7 changed files with 11,537 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Enhancements
- Fix lower bounds of dependency versions.
- Allow to load multi-objective SMAC3v2 and add example (#69)
- Do not disable existing loggers.

## Bug-Fixes
Expand Down
21 changes: 14 additions & 7 deletions deepcave/runs/converters/smac3v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@ def from_path(cls, path):
configspace = cs_json.read(f.read())

# Read objectives
# We have to define it ourselves, because we don't know the type of the objective
# Only lock lower
objective1 = Objective("Cost", lower=0)
objective2 = Objective("Time", lower=0)
with (path / "scenario.json").open() as json_file:
all_data = json.load(json_file)
objectives = all_data["objectives"]

obj_list = list()
if not isinstance(objectives, list):
objectives = [objectives]
for obj in objectives:
obj_list.append(Objective(obj))
# Only lock lower for time
obj_list.append(Objective("Time"))

# Read meta
with (path / "scenario.json").open() as json_file:
Expand All @@ -54,7 +61,7 @@ def from_path(cls, path):

# Let's create a new run object
run = SMAC3v2Run(
name=path.stem, configspace=configspace, objectives=[objective1, objective2], meta=meta
name=path.stem, configspace=configspace, objectives=obj_list, meta=meta
)

# We have to set the path manually
Expand Down Expand Up @@ -118,7 +125,7 @@ def from_path(cls, path):

if status != Status.SUCCESS:
# We don't want cost included which are failed
cost = None
cost = [None] * len(cost) if isinstance(cost, list) else None
time = None
else:
time = endtime - starttime
Expand All @@ -134,7 +141,7 @@ def from_path(cls, path):
origin = config_origins[config_id]

run.add(
costs=[cost, time],
costs=cost + [time] if isinstance(cost, list) else [cost, time],
config=config,
budget=budget,
start_time=starttime,
Expand Down
17 changes: 17 additions & 0 deletions logs/SMAC3v2/multi-objective/run_1/configspace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"hyperparameters": [
{
"name": "x",
"type": "uniform_float",
"log": false,
"lower": -2.0,
"upper": 2.0,
"default": 0.0,
"q": null
}
],
"conditions": [],
"forbiddens": [],
"python_module_version": "0.6.1",
"json_format_version": 0.4
}
Loading

0 comments on commit d73688e

Please sign in to comment.