|
32 | 32 | CONSTANT_VALUE, |
33 | 33 | NAN_VALUE, |
34 | 34 | ) |
35 | | -from deepcave.runs.exceptions import NotMergeableError |
| 35 | +from deepcave.runs.exceptions import NotMergeableError, RunInequality |
36 | 36 | from deepcave.runs.objective import Objective |
37 | 37 | from deepcave.runs.status import Status |
38 | 38 | from deepcave.runs.trial import Trial |
@@ -1236,68 +1236,79 @@ def check_equality( |
1236 | 1236 | if len(runs) == 0: |
1237 | 1237 | return result |
1238 | 1238 |
|
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 |
1244 | 1242 | for run in runs: |
1245 | | - m2 = run.get_meta() |
1246 | | - |
1247 | | - for k, v in m1.items(): |
1248 | | - # Don't check on objectives or budgets |
1249 | | - if k in ignore: |
1250 | | - continue |
| 1243 | + o2 = run.get_objectives() |
1251 | 1244 |
|
1252 | | - if k not in m2 or m2[k] != v: |
1253 | | - raise NotMergeableError("Meta data of runs are not equal.") |
| 1245 | + if o1 is None: |
| 1246 | + o1 = o2 |
| 1247 | + continue |
1254 | 1248 |
|
1255 | | - result["meta"] = m1 |
| 1249 | + if len(o1) != len(o2): |
| 1250 | + raise NotMergeableError( |
| 1251 | + "Objectives of runs are not equal.", RunInequality.INEQ_OBJECTIVE |
| 1252 | + ) |
1256 | 1253 |
|
1257 | | - # Make sure the same configspace is used |
1258 | | - # Otherwise it does not make sense to merge |
1259 | | - # the histories |
1260 | | - if configspace: |
1261 | | - cs1 = runs[0].configspace |
1262 | | - for run in runs: |
1263 | | - cs2 = run.configspace |
1264 | | - if cs1 != cs2: |
1265 | | - raise NotMergeableError("Configspace of runs are not equal.") |
| 1254 | + for o1_, o2_ in zip(o1, o2): |
| 1255 | + try: |
| 1256 | + o1_.merge(o2_) |
| 1257 | + except NotMergeableError: |
| 1258 | + raise NotMergeableError( |
| 1259 | + "Objectives of runs are not equal.", RunInequality.INEQ_OBJECTIVE |
| 1260 | + ) |
1266 | 1261 |
|
1267 | | - result["configspace"] = cs1 |
| 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 |
1268 | 1267 |
|
1269 | 1268 | # Also check if budgets are the same |
1270 | 1269 | if budgets: |
1271 | 1270 | b1 = runs[0].get_budgets(include_combined=False) |
1272 | 1271 | for run in runs: |
1273 | 1272 | b2 = run.get_budgets(include_combined=False) |
1274 | 1273 | if b1 != b2: |
1275 | | - raise NotMergeableError("Budgets of runs are not equal.") |
| 1274 | + raise NotMergeableError("Budgets of runs are not equal.", RunInequality.INEQ_BUDGET) |
1276 | 1275 |
|
1277 | 1276 | result["budgets"] = b1 |
1278 | 1277 | if meta: |
1279 | 1278 | result["meta"]["budgets"] = b1 |
1280 | 1279 |
|
1281 | | - # And if objectives are the same |
1282 | | - if objectives: |
1283 | | - o1 = None |
| 1280 | + # Make sure the same configspace is used |
| 1281 | + # Otherwise it does not make sense to merge |
| 1282 | + # the histories |
| 1283 | + if configspace: |
| 1284 | + cs1 = runs[0].configspace |
1284 | 1285 | for run in runs: |
1285 | | - o2 = run.get_objectives() |
| 1286 | + cs2 = run.configspace |
| 1287 | + if cs1 != cs2: |
| 1288 | + raise NotMergeableError( |
| 1289 | + "Configspace of runs are not equal.", RunInequality.INEQ_CONFIGSPACE |
| 1290 | + ) |
1286 | 1291 |
|
1287 | | - if o1 is None: |
1288 | | - o1 = o2 |
1289 | | - continue |
| 1292 | + result["configspace"] = cs1 |
1290 | 1293 |
|
1291 | | - if len(o1) != len(o2): |
1292 | | - raise NotMergeableError("Objectives of runs are not equal.") |
| 1294 | + # Check meta |
| 1295 | + if meta: |
| 1296 | + ignore = ["objectives", "budgets", "wallclock_limit"] |
1293 | 1297 |
|
1294 | | - for o1_, o2_ in zip(o1, o2): |
1295 | | - o1_.merge(o2_) |
| 1298 | + m1 = runs[0].get_meta() |
| 1299 | + for run in runs: |
| 1300 | + m2 = run.get_meta() |
1296 | 1301 |
|
1297 | | - assert o1 is not None |
1298 | | - serialized_objectives = [o.to_json() for o in o1] |
1299 | | - result["objectives"] = serialized_objectives |
1300 | | - if meta: |
1301 | | - result["meta"]["objectives"] = serialized_objectives |
| 1302 | + for k, v in m1.items(): |
| 1303 | + # Don't check on objectives or budgets |
| 1304 | + if k in ignore: |
| 1305 | + continue |
| 1306 | + |
| 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 | + ) |
| 1311 | + |
| 1312 | + result["meta"] = m1 |
1302 | 1313 |
|
1303 | 1314 | return result |
0 commit comments