Skip to content

Commit 9e862e0

Browse files
author
Sarah Krebs
committed
Get hovertext per budget
1 parent ec2c03a commit 9e862e0

File tree

7 files changed

+49
-17
lines changed

7 files changed

+49
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- Add exit button which first deletes running jobs and then terminates DeepCave.
1818
- Nicer handling of Keyboard Interrupt.
1919
- Disable debug mode.
20+
- Get hovertext per budget in Footprint, Config Cube, Cost over Time, and Pareto Front.
2021

2122
## Bug-Fixes
2223
- Fix missing objective specification in LPI evaluator (#71).

deepcave/plugins/objective/configuration_cube.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ def load_outputs(run, inputs, outputs) -> go.Figure: # type: ignore
326326
n_configs = inputs["n_configs"]
327327
objective_id = inputs["objective_id"]
328328
objective = run.get_objective(objective_id)
329+
budget = run.get_budget(inputs["budget_id"])
329330
df = df.groupby(df.columns.drop(objective.name).to_list(), as_index=False).mean()
330331
df.index = df.index.astype("str")
331332

@@ -393,7 +394,9 @@ def load_outputs(run, inputs, outputs) -> go.Figure: # type: ignore
393394
"color": costs,
394395
"colorbar": {"thickness": 30, "title": objective.name},
395396
},
396-
"hovertext": [get_hovertext_from_config(run, config_id) for config_id in config_ids],
397+
"hovertext": [
398+
get_hovertext_from_config(run, config_id, budget) for config_id in config_ids
399+
],
397400
"meta": {"colorbar": costs},
398401
"hoverinfo": "text",
399402
}

deepcave/plugins/objective/cost_over_time.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ def load_outputs(runs, inputs, outputs) -> go.Figure: # type: ignore
341341
continue
342342

343343
objective = run.get_objective(inputs["objective_id"])
344+
budget = run.get_budget(inputs["budget_id"])
344345
config_ids = outputs[run.id]["config_ids"]
345346
x = outputs[run.id]["times"]
346347
if inputs["xaxis"] == "trials":
@@ -357,7 +358,9 @@ def load_outputs(runs, inputs, outputs) -> go.Figure: # type: ignore
357358
symbol = None
358359
mode = "lines"
359360
if len(config_ids) > 0:
360-
hovertext = [get_hovertext_from_config(run, config_id) for config_id in config_ids]
361+
hovertext = [
362+
get_hovertext_from_config(run, config_id, budget) for config_id in config_ids
363+
]
361364
hoverinfo = "text"
362365
symbol = "circle"
363366
mode = "lines+markers"

deepcave/plugins/objective/pareto_front.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ def load_outputs(runs, inputs, outputs) -> go.Figure: # type: ignore
423423
points_avg = np.array(outputs[run.id]["points_avg"])
424424
points_std = np.array(outputs[run.id]["points_std"])
425425
config_ids = outputs[run.id]["config_ids"]
426+
budget = run.get_budget(inputs["budget_id"])
426427
pareto_config_ids = []
427428

428429
x, y, x_std, y_std = [], [], [], []
@@ -486,7 +487,7 @@ def load_outputs(runs, inputs, outputs) -> go.Figure: # type: ignore
486487
line_shape = "hv"
487488

488489
hovertext = [
489-
get_hovertext_from_config(run, config_id) for config_id in pareto_config_ids
490+
get_hovertext_from_config(run, config_id, budget) for config_id in pareto_config_ids
490491
]
491492

492493
error_pareto_x = (

deepcave/plugins/summary/footprint.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ def load_outputs(run, inputs, outputs) -> List[Any]: # type: ignore
335335
The plotly figure of the footprint performance and area.
336336
"""
337337
objective = run.get_objective(inputs["objective_id"])
338+
budget = run.get_budget(inputs["budget_id"])
338339
show_borders = inputs["show_borders"]
339340
show_supports = inputs["show_supports"]
340341

@@ -401,7 +402,8 @@ def load_outputs(run, inputs, outputs) -> List[Any]: # type: ignore
401402
marker_symbol=marker_symbol,
402403
marker={"size": size, "color": get_color(color_id)},
403404
hovertext=[
404-
get_hovertext_from_config(run, config_id) for config_id in config_ids
405+
get_hovertext_from_config(run, config_id, budget)
406+
for config_id in config_ids
405407
],
406408
hoverinfo="text",
407409
)

deepcave/runs/__init__.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,11 @@ def get_avg_costs(
722722
objectives = self.get_objectives()
723723

724724
# Budget might not be evaluated
725-
config_costs = self.get_all_costs(budget=budget, statuses=statuses)[config_id]
725+
all_costs = self.get_all_costs(budget=budget, statuses=statuses)
726+
if config_id in all_costs:
727+
config_costs = all_costs[config_id]
728+
else:
729+
raise ValueError(f"No costs available for config_id {config_id}.")
726730

727731
avg_costs, std_costs = [], []
728732
for idx in range(len(objectives)):
@@ -912,6 +916,9 @@ def get_incumbent(
912916
budget=budget, statuses=statuses, seed=seed, selected_ids=selected_ids
913917
)
914918

919+
if len(results) == 0:
920+
raise RuntimeError("No data available, thus no incumbent found.")
921+
915922
seed_count = {}
916923
for config_id, seed_costs_dict in results.items():
917924
seed_count[config_id] = len(seed_costs_dict)
@@ -1128,13 +1135,14 @@ def get_trajectory(
11281135
trial = self.history[id]
11291136

11301137
# Get the incumbent over all trials up to this point
1131-
_, cost = self.get_incumbent(
1132-
objectives=objective,
1133-
budget=budget,
1134-
seed=seed,
1135-
selected_ids=[selected_id for selected_id, _ in order[: i + 1]],
1136-
)
1137-
if cost is None:
1138+
try:
1139+
_, cost = self.get_incumbent(
1140+
objectives=objective,
1141+
budget=budget,
1142+
seed=seed,
1143+
selected_ids=[selected_id for selected_id, _ in order[: i + 1]],
1144+
)
1145+
except RuntimeError:
11381146
continue
11391147

11401148
# Now it's important to check whether the cost was minimized or maximized

deepcave/utils/styled_plotty.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,9 @@ def get_hyperparameter_ticks_from_values(
440440
return tickvals, ticktext
441441

442442

443-
def get_hovertext_from_config(run: AbstractRun, config_id: int) -> str:
443+
def get_hovertext_from_config(
444+
run: AbstractRun, config_id: int, budget: Optional[Union[int, float]] = None
445+
) -> str:
444446
"""
445447
Generate hover text with metrics for a configuration.
446448
@@ -453,6 +455,9 @@ def get_hovertext_from_config(run: AbstractRun, config_id: int) -> str:
453455
The run instance
454456
config_id : int
455457
The id of the configuration
458+
budget : Optional[Union[int, float]]
459+
Budget to get the hovertext for. If no budget is given, the highest budget is chosen.
460+
By default None.
456461
457462
Returns
458463
-------
@@ -472,12 +477,21 @@ def get_hovertext_from_config(run: AbstractRun, config_id: int) -> str:
472477

473478
# It's also nice to see the metrics
474479
objectives = run.get_objectives()
475-
budget = run.get_highest_budget(config_id)
480+
if budget is None or budget == -1:
481+
highest_budget = run.get_highest_budget(config_id)
482+
assert highest_budget is not None
483+
string += f"<b>Objectives</b> (on highest found budget {round(highest_budget, 2)})<br>"
484+
else:
485+
string += f"<b>Objectives</b> (on budget {round(budget, 2)})<br>"
476486

477-
avg_costs, std_costs = run.get_avg_costs(config_id, budget=budget)
487+
try:
488+
avg_c, std_c = run.get_avg_costs(config_id, budget=budget)
489+
avg_costs: List[Optional[float]] = list(avg_c)
490+
std_costs: List[Optional[float]] = list(std_c)
491+
except ValueError:
492+
avg_costs = [None for _ in range(len(objectives))]
493+
std_costs = [None for _ in range(len(objectives))]
478494

479-
assert budget is not None
480-
string += f"<b>Objectives</b> (on highest found budget {round(budget, 2)})<br>"
481495
for objective, cost, std_cost in zip(objectives, avg_costs, std_costs):
482496
if std_cost == 0.0:
483497
string += f"{objective.name}: {cost}<br>"

0 commit comments

Comments
 (0)