Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/Fix api examples #103

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

## Bug-Fixes
- Don't convert BOHB runs with status 'running' (consistent with SMAC).
- Reset inputs to fix error when subsequently selecting runs with different configspaces, objectives or budgets (#106)
- Fix api examples (#68).
- Reset inputs to fix error when subsequently selecting runs with different configspaces, objectives or budgets (#106).

# Version 1.1.3

Expand Down
4 changes: 2 additions & 2 deletions deepcave/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ def get_base_url(cls) -> str:
str
Url for the plugin as string.
"""
from deepcave import config
from deepcave.config import Config

return f"http://{config.DASH_ADDRESS}:{config.DASH_PORT}/plugins/{cls.id}"
return f"http://{Config.DASH_ADDRESS}:{Config.DASH_PORT}/plugins/{cls.id}"

@staticmethod
def check_run_compatibility(run: AbstractRun) -> bool:
Expand Down
7 changes: 4 additions & 3 deletions deepcave/plugins/budget/budget_correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from dash import dcc, html
from scipy import stats

from deepcave import config, notification
from deepcave import notification
from deepcave.config import Config
from deepcave.plugins.dynamic import DynamicPlugin
from deepcave.runs import Status
from deepcave.utils.layout import create_table, get_select_options
Expand Down Expand Up @@ -114,7 +115,7 @@ def get_output_layout(register):
[
dbc.Tab(
dcc.Graph(
id=register("graph", "figure"), style={"height": config.FIGURE_HEIGHT}
id=register("graph", "figure"), style={"height": Config.FIGURE_HEIGHT}
),
label="Graph",
),
Expand Down Expand Up @@ -171,7 +172,7 @@ def load_outputs(run, _, outputs):
layout = go.Layout(
xaxis=dict(title="Budget"),
yaxis=dict(title="Correlation"),
margin=config.FIGURE_MARGIN,
margin=Config.FIGURE_MARGIN,
legend=dict(title="Budgets"),
)

Expand Down
6 changes: 3 additions & 3 deletions deepcave/plugins/hyperparameter/importances.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from dash import dcc, html
from dash.exceptions import PreventUpdate

from deepcave import config
from deepcave.config import Config
from deepcave.evaluators.fanova import fANOVA as GlobalEvaluator
from deepcave.evaluators.lpi import LPI as LocalEvaluator
from deepcave.plugins.static import StaticPlugin
Expand Down Expand Up @@ -201,7 +201,7 @@ def process(run, inputs):

@staticmethod
def get_output_layout(register):
return dcc.Graph(register("graph", "figure"), style={"height": config.FIGURE_HEIGHT})
return dcc.Graph(register("graph", "figure"), style={"height": Config.FIGURE_HEIGHT})

@staticmethod
def load_outputs(run, inputs, outputs):
Expand Down Expand Up @@ -273,7 +273,7 @@ def load_outputs(run, inputs, outputs):
barmode="group",
yaxis_title="Importance",
legend={"title": "Budget"},
margin=config.FIGURE_MARGIN,
margin=Config.FIGURE_MARGIN,
xaxis=dict(tickangle=-45),
)
save_image(figure, "importances.pdf")
Expand Down
6 changes: 3 additions & 3 deletions deepcave/plugins/hyperparameter/pdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from dash import dcc, html
from pyPDP.algorithms.pdp import PDP

from deepcave import config
from deepcave.config import Config
from deepcave.evaluators.epm.random_forest_surrogate import RandomForestSurrogate
from deepcave.plugins.static import StaticPlugin
from deepcave.runs import Status
Expand Down Expand Up @@ -234,7 +234,7 @@ def process(run, inputs):

@staticmethod
def get_output_layout(register):
return dcc.Graph(register("graph", "figure"), style={"height": config.FIGURE_HEIGHT})
return dcc.Graph(register("graph", "figure"), style={"height": Config.FIGURE_HEIGHT})

@staticmethod
def load_outputs(run, inputs, outputs):
Expand Down Expand Up @@ -348,7 +348,7 @@ def load_outputs(run, inputs, outputs):
dict(
xaxis=dict(tickvals=x_tickvals, ticktext=x_ticktext, title=hp1_name),
yaxis=dict(tickvals=y_tickvals, ticktext=y_ticktext, title=hp2_name),
margin=config.FIGURE_MARGIN,
margin=Config.FIGURE_MARGIN,
)
)

Expand Down
6 changes: 3 additions & 3 deletions deepcave/plugins/objective/configuration_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from dash import dcc, html
from dash.exceptions import PreventUpdate

from deepcave import config
from deepcave.config import Config
from deepcave.plugins.dynamic import DynamicPlugin
from deepcave.runs import Status
from deepcave.utils.compression import deserialize, serialize
Expand Down Expand Up @@ -178,7 +178,7 @@ def process(run, inputs):

@staticmethod
def get_output_layout(register):
return (dcc.Graph(register("graph", "figure"), style={"height": config.FIGURE_HEIGHT}),)
return (dcc.Graph(register("graph", "figure"), style={"height": Config.FIGURE_HEIGHT}),)

@staticmethod
def load_outputs(run, inputs, outputs):
Expand Down Expand Up @@ -278,7 +278,7 @@ def load_outputs(run, inputs, outputs):
layout = go.Layout(**layout_kwargs)

figure = go.Figure(data=trace, layout=layout)
figure.update_layout(dict(margin=config.FIGURE_MARGIN))
figure.update_layout(dict(margin=Config.FIGURE_MARGIN))
save_image(figure, "configuration_cube.pdf")

return figure
6 changes: 3 additions & 3 deletions deepcave/plugins/objective/cost_over_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dash import dcc, html
from dash.exceptions import PreventUpdate

from deepcave import config
from deepcave.config import Config
from deepcave.plugins.dynamic import DynamicPlugin
from deepcave.runs import AbstractRun, check_equality
from deepcave.utils.layout import get_select_options, help_button
Expand Down Expand Up @@ -150,7 +150,7 @@ def process(run, inputs):

@staticmethod
def get_output_layout(register):
return dcc.Graph(register("graph", "figure"), style={"height": config.FIGURE_HEIGHT})
return dcc.Graph(register("graph", "figure"), style={"height": Config.FIGURE_HEIGHT})

@staticmethod
def load_outputs(runs, inputs, outputs):
Expand Down Expand Up @@ -245,7 +245,7 @@ def load_outputs(runs, inputs, outputs):
layout = go.Layout(
xaxis=dict(title=xaxis_label, type=type),
yaxis=dict(title=objective.name),
margin=config.FIGURE_MARGIN,
margin=Config.FIGURE_MARGIN,
)

figure = go.Figure(data=traces, layout=layout)
Expand Down
6 changes: 3 additions & 3 deletions deepcave/plugins/objective/parallel_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from dash import dcc, html
from dash.exceptions import PreventUpdate

from deepcave import config
from deepcave.config import Config
from deepcave.constants import VALUE_RANGE
from deepcave.evaluators.fanova import fANOVA
from deepcave.plugins.static import StaticPlugin
Expand Down Expand Up @@ -88,7 +88,7 @@ def get_filter_layout(register):
dbc.Label("Limit Hyperparameters"),
help_button(
"Shows either the n most important hyperparameters (if show "
"importance hyperparameters is true) or the first n selected "
"important hyperparameters is true) or the first n selected "
"hyperparameters."
),
dbc.Input(id=register("n_hps", "value"), type="number"),
Expand Down Expand Up @@ -206,7 +206,7 @@ def process(run, inputs):

@staticmethod
def get_output_layout(register):
return dcc.Graph(register("graph", "figure"), style={"height": config.FIGURE_HEIGHT})
return dcc.Graph(register("graph", "figure"), style={"height": Config.FIGURE_HEIGHT})

@staticmethod
def load_outputs(run, inputs, outputs):
Expand Down
6 changes: 3 additions & 3 deletions deepcave/plugins/objective/pareto_front.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import plotly.graph_objs as go
from dash import dcc, html

from deepcave import config
from deepcave.config import Config
from deepcave.plugins.dynamic import DynamicPlugin
from deepcave.runs import Status, check_equality
from deepcave.utils.layout import get_select_options, help_button
Expand Down Expand Up @@ -206,7 +206,7 @@ def process(run, inputs):

@staticmethod
def get_output_layout(register):
return dcc.Graph(register("graph", "figure"), style={"height": config.FIGURE_HEIGHT})
return dcc.Graph(register("graph", "figure"), style={"height": Config.FIGURE_HEIGHT})

@staticmethod
def load_outputs(runs, inputs, outputs):
Expand Down Expand Up @@ -291,7 +291,7 @@ def load_outputs(runs, inputs, outputs):
layout = go.Layout(
xaxis=dict(title=objective_1.name),
yaxis=dict(title=objective_2.name),
margin=config.FIGURE_MARGIN,
margin=Config.FIGURE_MARGIN,
)
else:
layout = None
Expand Down
4 changes: 2 additions & 2 deletions deepcave/plugins/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,12 @@ def _get_job_id(self, run_name: str, inputs_key: str) -> str:

@interactive
def __call__(self) -> List[Component]: # type: ignore
from deepcave import config
from deepcave.config import Config

self._setup()

components = [
dcc.Interval(id=self.get_internal_id("update-interval"), interval=config.REFRESH_RATE),
dcc.Interval(id=self.get_internal_id("update-interval"), interval=Config.REFRESH_RATE),
dcc.Store(id=self.get_internal_id("update-interval-output"), data=0),
]
components += super().__call__(True)
Expand Down
8 changes: 4 additions & 4 deletions deepcave/plugins/summary/configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import plotly.graph_objs as go
from dash import dcc, html

from deepcave import config
from deepcave.config import Config
from deepcave.constants import VALUE_RANGE
from deepcave.plugins.dynamic import DynamicPlugin
from deepcave.runs import AbstractRun, Status
Expand Down Expand Up @@ -178,7 +178,7 @@ def get_output_layout(register):
dbc.Tab(
dcc.Graph(
id=register("performance_graph", "figure"),
style={"height": config.FIGURE_HEIGHT},
style={"height": Config.FIGURE_HEIGHT},
),
label="Graph",
),
Expand All @@ -192,7 +192,7 @@ def get_output_layout(register):
dbc.Tab(
dcc.Graph(
id=register("configspace_graph", "figure"),
style={"height": config.FIGURE_HEIGHT},
style={"height": Config.FIGURE_HEIGHT},
),
label="Graph",
),
Expand Down Expand Up @@ -231,7 +231,7 @@ def _get_objective_figure(_, outputs, run):
objective_data.append(trace)

layout_kwargs = {
"margin": config.FIGURE_MARGIN,
"margin": Config.FIGURE_MARGIN,
"xaxis": {"title": "Budget", "domain": [0.05 * len(run.get_objectives()), 1]},
}

Expand Down
8 changes: 4 additions & 4 deletions deepcave/plugins/summary/footprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import plotly.graph_objs as go
from dash import dcc, html

from deepcave import config
from deepcave.config import Config
from deepcave.evaluators.footprint import Footprint as Evaluator
from deepcave.plugins.static import StaticPlugin
from deepcave.utils.layout import get_select_options, help_button
Expand Down Expand Up @@ -173,13 +173,13 @@ def get_output_layout(register):
[
dbc.Tab(
dcc.Graph(
id=register("performance", "figure"), style={"height": config.FIGURE_HEIGHT}
id=register("performance", "figure"), style={"height": Config.FIGURE_HEIGHT}
),
label="Performance",
),
dbc.Tab(
dcc.Graph(
id=register("area", "figure"), style={"height": config.FIGURE_HEIGHT}
id=register("area", "figure"), style={"height": Config.FIGURE_HEIGHT}
),
label="Coverage",
),
Expand Down Expand Up @@ -264,7 +264,7 @@ def load_outputs(run, inputs, outputs):
layout = go.Layout(
xaxis=dict(title=None, tickvals=[]),
yaxis=dict(title=None, tickvals=[]),
margin=config.FIGURE_MARGIN,
margin=Config.FIGURE_MARGIN,
)

performance = go.Figure(data=[performance_data] + traces, layout=layout)
Expand Down
10 changes: 5 additions & 5 deletions deepcave/plugins/summary/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
from dash import dcc, html

from deepcave import config
from deepcave.config import Config
from deepcave.plugins.dynamic import DynamicPlugin
from deepcave.plugins.summary.configurations import Configurations
from deepcave.runs.group import Group
Expand Down Expand Up @@ -51,14 +51,14 @@ def get_output_layout(register):
dbc.Tab(
dcc.Graph(
id=register("status_statistics", "figure"),
style={"height": config.FIGURE_HEIGHT},
style={"height": Config.FIGURE_HEIGHT},
),
label="Barplot",
),
dbc.Tab(
dcc.Graph(
id=register("config_statistics", "figure"),
style={"height": config.FIGURE_HEIGHT},
style={"height": Config.FIGURE_HEIGHT},
),
label="Heatmap",
),
Expand Down Expand Up @@ -328,7 +328,7 @@ def load_outputs(run, *_):
barmode="group",
xaxis=dict(title="Status"),
yaxis=dict(title="Number of configurations"),
margin=config.FIGURE_MARGIN,
margin=Config.FIGURE_MARGIN,
)
stats_figure = go.Figure(data=stats_data, layout=stats_layout)
save_image(stats_figure, "status_bar.pdf")
Expand All @@ -337,7 +337,7 @@ def load_outputs(run, *_):
legend={"title": "Status"},
xaxis=dict(title="Budget"),
yaxis=dict(title="Configuration ID"),
margin=config.FIGURE_MARGIN,
margin=Config.FIGURE_MARGIN,
)
config_figure = go.Figure(
data=get_discrete_heatmap(
Expand Down
6 changes: 3 additions & 3 deletions deepcave/utils/styled_plotty.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def save_image(figure: go.Figure, name: str) -> None:
name : str
Name of the image with extension. Will be automatically saved to the cache.
"""
from deepcave import config
from deepcave.config import Config

if not config.SAVE_IMAGES:
if not Config.SAVE_IMAGES:
return

ratio = 16 / 9
width = 500
height = int(width / ratio)
path = config.CACHE_DIR / "figures" / name
path = Config.CACHE_DIR / "figures" / name

figure.write_image(path, width=width, height=height)
logger.info(f"Saved figure {name} to {path}.")
Expand Down
38 changes: 38 additions & 0 deletions examples/api/importances.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
Importances
^^^^^^^^^^^^^^^^^^^^

This example shows how to use the plugin Importances.
Note that other plugins use the same interfaces and can be used in the same fashion.
"""

from deepcave.plugins.hyperparameter.importances import Importances
from deepcave.runs.converters.deepcave import DeepCAVERun
from pathlib import Path


if __name__ == "__main__":
# Instantiate the run
run = DeepCAVERun.from_path(Path("logs/DeepCAVE/minimal/run_2"))

objective_id = run.get_objective_ids()[0]
budget_ids = run.get_budget_ids()

# Instantiate the plugin
plugin = Importances()
inputs = plugin.generate_inputs(
hyperparameter_names=run.configspace.get_hyperparameter_names(),
objective_id=objective_id,
budget_ids=budget_ids,
method="global",
n_hps=3,
n_trees=10
)
# Note: Filter variables are not considered.
outputs = plugin.generate_outputs(run, inputs)

# Finally, you can load the figure. Here, the filter variables play a role.
# Alternatively: Use the matplotlib output (`load_mpl_outputs`) if available.
figure = plugin.load_outputs(run, inputs, outputs) # plotly.go figure
figure.write_image("examples/api/importances.png", scale=2.)
# figure.show()
Loading
Loading