Example #1
0
def _copy_db_ids_if_possible(new_obj: Any, obj: Any) -> None:
    """Wraps _copy_db_ids in a try/except, and logs warnings on error."""
    try:
        copy_db_ids(new_obj, obj, [])
    except SQADecodeError as e:
        # Raise these warnings in unittests only
        if os.environ.get("TESTENV"):
            raise e
        logger.warning(
            "Error encountered when copying db_ids back to user-facing object. "
            "This might cause issues if you re-save this experiment. "
            f"Exception: {e}")
Example #2
0
    def testCopyDBIDsBatchTrialExp(self):
        exp1 = get_experiment_with_batch_trial()
        save_experiment(exp1)
        exp2 = load_experiment(exp1.name)
        self.assertEqual(exp1, exp2)

        # empty some of exp2 db_ids
        exp2.trials[0].db_id = None
        exp2.trials[0].generator_runs[0].arms[0].db_id = None

        # copy db_ids from exp1 to exp2
        copy_db_ids(exp1, exp2)
        self.assertEqual(exp1, exp2)
Example #3
0
    def testCopyDBIDsDataExp(self):
        exp1 = get_experiment_with_data()
        save_experiment(exp1)
        exp2 = load_experiment(exp1.name)
        self.assertEqual(exp1, exp2)

        # empty some of exp2 db_ids
        data, _ = exp2.lookup_data_for_trial(0)
        data.db_id = None

        # copy db_ids from exp1 to exp2
        copy_db_ids(exp1, exp2)
        self.assertEqual(exp1, exp2)
Example #4
0
    def test_copy_db_ids_none_search_space(self):
        exp1 = get_experiment_with_batch_trial()
        save_experiment(exp1)
        exp2 = load_experiment(exp1.name)
        self.assertEqual(exp1, exp2)

        # empty search_space of exp1
        exp1._search_space = None

        # empty some of exp2 db_ids
        exp2.trials[0].db_id = None
        exp2.trials[0].generator_runs[0].arms[0].db_id = None

        with self.assertWarnsRegex(
            Warning,
            "Encountered two objects of different types",
        ):
            # copy db_ids from exp1 to exp2
            copy_db_ids(exp1, exp2)

        # empty search space of exp2 for comparison
        exp2._search_space = None
        self.assertEqual(exp1, exp2)