Skip to content

Commit

Permalink
added enum & warning notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
KrissiHub committed Feb 9, 2024
1 parent daf6c2f commit 80a21a2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 11 deletions.
18 changes: 15 additions & 3 deletions deepcave/plugins/objective/cost_over_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
from dash import dcc, html
from dash.exceptions import PreventUpdate

from deepcave import config
from deepcave import config, notification
from deepcave.plugins.dynamic import DynamicPlugin
from deepcave.runs import AbstractRun, check_equality
from deepcave.runs.exceptions import NotMergeableError, RunInequality
from deepcave.utils.layout import get_select_options, help_button
from deepcave.utils.styled_plotty import (
get_color,
Expand All @@ -24,8 +25,19 @@ class CostOverTime(DynamicPlugin):
help = "docs/plugins/cost_over_time.rst"

def check_runs_compatibility(self, runs: List[AbstractRun]) -> None:
check_equality(runs, objectives=True, budgets=True)

try:
check_equality(runs, objectives=True, budgets=True)
except NotMergeableError as e:
run_inequality = e.args[1]
if run_inequality == RunInequality.INEQ_BUDGET:
notification.update("The budgets of the runs are not equal.", color="warning")
elif run_inequality == RunInequality.INEQ_CONFIGSPACE:
notification.update("The configuration spaces of the runs are not equal.", color="warning")
elif run_inequality == RunInequality.INEQ_META:
notification.update("The meta data of the runs is not equal.", color="warning")
elif run_inequality == RunInequality.INEQ_OBJECTIVE:
notification.update("The objectives of the runs are not equal.", color="warning")

# Set some attributes here
run = runs[0]

Expand Down
16 changes: 14 additions & 2 deletions deepcave/plugins/objective/pareto_front.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import plotly.graph_objs as go
from dash import dcc, html

from deepcave import config
from deepcave import config, notification
from deepcave.plugins.dynamic import DynamicPlugin
from deepcave.runs import Status, check_equality
from deepcave.runs.exceptions import NotMergeableError, RunInequality
from deepcave.utils.layout import get_select_options, help_button
from deepcave.utils.styled_plot import plt
from deepcave.utils.styled_plotty import (
Expand All @@ -24,7 +25,18 @@ class ParetoFront(DynamicPlugin):
help = "docs/plugins/pareto_front.rst"

def check_runs_compatibility(self, runs):
check_equality(runs, objectives=True, budgets=True)
try:
check_equality(runs, objectives=True, budgets=True)
except NotMergeableError as e:
run_inequality = e.args[1]
if run_inequality == RunInequality.INEQ_BUDGET:
notification.update("The budgets of the runs are not equal.", color="warning")
elif run_inequality == RunInequality.INEQ_CONFIGSPACE:
notification.update("The configuration spaces of the runs are not equal.", color="warning")
elif run_inequality == RunInequality.INEQ_META:
notification.update("The meta data of the runs is not equal.", color="warning")
elif run_inequality == RunInequality.INEQ_OBJECTIVE:
notification.update("The objectives of the runs are not equal.", color="warning")

# Set some attributes here
run = runs[0]
Expand Down
13 changes: 7 additions & 6 deletions deepcave/runs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
CONSTANT_VALUE,
NAN_VALUE,
)
from deepcave.runs.exceptions import NotMergeableError
from deepcave.runs.exceptions import NotMergeableError, RunInequality
from deepcave.runs.objective import Objective
from deepcave.runs.status import Status
from deepcave.runs.trial import Trial
Expand Down Expand Up @@ -919,6 +919,7 @@ def check_equality(
Dict[str, Any]
Dictionary containing the checked attributes.
"""

result = {}

if len(runs) == 0:
Expand All @@ -938,7 +939,7 @@ def check_equality(
continue

if k not in m2 or m2[k] != v:
raise NotMergeableError("Meta data of runs are not equal.")
raise NotMergeableError("Meta data of runs are not equal.", RunInequality.INEQ_META)

result["meta"] = m1

Expand All @@ -950,7 +951,7 @@ def check_equality(
for run in runs:
cs2 = run.configspace
if cs1 != cs2:
raise NotMergeableError("Configspace of runs are not equal.")
raise NotMergeableError("Configspace of runs are not equal.", RunInequality.INEQ_CONFIGSPACE)

result["configspace"] = cs1

Expand All @@ -960,7 +961,7 @@ def check_equality(
for run in runs:
b2 = run.get_budgets(include_combined=False)
if b1 != b2:
raise NotMergeableError("Budgets of runs are not equal.")
raise NotMergeableError("Budgets of runs are not equal.", RunInequality.INEQ_BUDGET)

result["budgets"] = b1
if meta:
Expand All @@ -977,7 +978,7 @@ def check_equality(
continue

if len(o1) != len(o2):
raise NotMergeableError("Objectives of runs are not equal.")
raise NotMergeableError("Objectives of runs are not equal.", RunInequality.INEQ_OBJECTIVE)

for o1_, o2_ in zip(o1, o2):
o1_.merge(o2_)
Expand All @@ -987,4 +988,4 @@ def check_equality(
if meta:
result["meta"]["objectives"] = serialized_objectives

return result
return result
11 changes: 11 additions & 0 deletions deepcave/runs/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from enum import Enum
class NotValidRunError(Exception):
"""Raised if directory is not a valid run."""

Expand All @@ -8,3 +9,13 @@ class NotMergeableError(Exception):
"""Raised if two or more runs are not mergeable"""

pass

class RunInequality(Enum):
"""Check why runs were not compatible."""
INEQ_META = 1
INEQ_OBJECTIVE = 2
INEQ_BUDGET = 3
INEQ_CONFIGSPACE = 4



0 comments on commit 80a21a2

Please sign in to comment.