Skip to content

Commit a410f5b

Browse files
committed
get error message if objectives are unequal
1 parent 5dfc980 commit a410f5b

File tree

4 files changed

+51
-45
lines changed

4 files changed

+51
-45
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Plugins
44
- Add symbolic explanations plugin (#46).
55
- It is now possible to view multiple unequal runs at once in Cost over Time and Pareto (#93).
6+
- Runs with unequal objectives cannot be displayed together.
67
- Added an enum for displaying according warning messages.
78

89
## Enhancements

deepcave/plugins/objective/cost_over_time.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def check_runs_compatibility(self, runs: List[AbstractRun]) -> None:
8787
elif run_inequality == RunInequality.INEQ_META:
8888
notification.update("The meta data of the runs is not equal.", color="warning")
8989
elif run_inequality == RunInequality.INEQ_OBJECTIVE:
90-
notification.update("The objectives of the runs are not equal.", color="warning")
90+
raise NotMergeableError("The objectives of the selected runs cannot be merged.")
9191

9292
# Set some attributes here
9393
# It is necessary to get the run with the smallest budget and objective options

deepcave/plugins/objective/pareto_front.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def check_runs_compatibility(self, runs: List[AbstractRun]) -> None:
8686
elif run_inequality == RunInequality.INEQ_META:
8787
notification.update("The meta data of the runs is not equal.", color="warning")
8888
elif run_inequality == RunInequality.INEQ_OBJECTIVE:
89-
notification.update("The objectives of the runs are not equal.", color="warning")
89+
raise NotMergeableError("The objectives of the selected runs cannot be merged.")
9090

9191
# Set some attributes here
9292
# It is necessary to get the run with the smallest budget and objective options

deepcave/runs/__init__.py

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,25 +1236,46 @@ def check_equality(
12361236
if len(runs) == 0:
12371237
return result
12381238

1239-
# Check meta
1240-
if meta:
1241-
ignore = ["objectives", "budgets", "wallclock_limit"]
1242-
1243-
m1 = runs[0].get_meta()
1239+
# Check if objectives are mergeable
1240+
if objectives:
1241+
o1 = None
12441242
for run in runs:
1245-
m2 = run.get_meta()
1243+
o2 = run.get_objectives()
12461244

1247-
for k, v in m1.items():
1248-
# Don't check on objectives or budgets
1249-
if k in ignore:
1250-
continue
1245+
if o1 is None:
1246+
o1 = o2
1247+
continue
12511248

1252-
if k not in m2 or m2[k] != v:
1249+
if len(o1) != len(o2):
1250+
raise NotMergeableError(
1251+
"Objectives of runs are not equal.", RunInequality.INEQ_OBJECTIVE
1252+
)
1253+
1254+
for o1_, o2_ in zip(o1, o2):
1255+
try:
1256+
o1_.merge(o2_)
1257+
except NotMergeableError:
12531258
raise NotMergeableError(
1254-
"Meta data of runs are not equal.", RunInequality.INEQ_META
1259+
"Objectives of runs are not equal.", RunInequality.INEQ_OBJECTIVE
12551260
)
12561261

1257-
result["meta"] = m1
1262+
assert o1 is not None
1263+
serialized_objectives = [o.to_json() for o in o1]
1264+
result["objectives"] = serialized_objectives
1265+
if meta:
1266+
result["meta"]["objectives"] = serialized_objectives
1267+
1268+
# Also check if budgets are the same
1269+
if budgets:
1270+
b1 = runs[0].get_budgets(include_combined=False)
1271+
for run in runs:
1272+
b2 = run.get_budgets(include_combined=False)
1273+
if b1 != b2:
1274+
raise NotMergeableError("Budgets of runs are not equal.", RunInequality.INEQ_BUDGET)
1275+
1276+
result["budgets"] = b1
1277+
if meta:
1278+
result["meta"]["budgets"] = b1
12581279

12591280
# Make sure the same configspace is used
12601281
# Otherwise it does not make sense to merge
@@ -1270,40 +1291,24 @@ def check_equality(
12701291

12711292
result["configspace"] = cs1
12721293

1273-
# Also check if budgets are the same
1274-
if budgets:
1275-
b1 = runs[0].get_budgets(include_combined=False)
1276-
for run in runs:
1277-
b2 = run.get_budgets(include_combined=False)
1278-
if b1 != b2:
1279-
raise NotMergeableError("Budgets of runs are not equal.", RunInequality.INEQ_BUDGET)
1280-
1281-
result["budgets"] = b1
1282-
if meta:
1283-
result["meta"]["budgets"] = b1
1294+
# Check meta
1295+
if meta:
1296+
ignore = ["objectives", "budgets", "wallclock_limit"]
12841297

1285-
# And if objectives are the same
1286-
if objectives:
1287-
o1 = None
1298+
m1 = runs[0].get_meta()
12881299
for run in runs:
1289-
o2 = run.get_objectives()
1290-
1291-
if o1 is None:
1292-
o1 = o2
1293-
continue
1300+
m2 = run.get_meta()
12941301

1295-
if len(o1) != len(o2):
1296-
raise NotMergeableError(
1297-
"Objectives of runs are not equal.", RunInequality.INEQ_OBJECTIVE
1298-
)
1302+
for k, v in m1.items():
1303+
# Don't check on objectives or budgets
1304+
if k in ignore:
1305+
continue
12991306

1300-
for o1_, o2_ in zip(o1, o2):
1301-
o1_.merge(o2_)
1307+
if k not in m2 or m2[k] != v:
1308+
raise NotMergeableError(
1309+
"Meta data of runs are not equal.", RunInequality.INEQ_META
1310+
)
13021311

1303-
assert o1 is not None
1304-
serialized_objectives = [o.to_json() for o in o1]
1305-
result["objectives"] = serialized_objectives
1306-
if meta:
1307-
result["meta"]["objectives"] = serialized_objectives
1312+
result["meta"] = m1
13081313

13091314
return result

0 commit comments

Comments
 (0)