コード例 #1
0
    def test_save_updated_trial(self):
        experiment, _ = self.init_experiment_and_generation_strategy(
            save_generation_strategy=False
        )

        exp = _load_experiment(
            experiment.name, decoder=self.with_db_settings.db_settings.decoder
        )
        trial = exp.new_trial()
        _save_or_update_trials(
            experiment=experiment,
            trials=[trial],
            encoder=self.with_db_settings.db_settings.encoder,
            decoder=self.with_db_settings.db_settings.decoder,
        )
        self.assertEqual(trial.status, TrialStatus.CANDIDATE)

        trial.mark_running(True)
        saved = self.with_db_settings._save_or_update_trial_in_db_if_possible(
            exp, trial
        )
        self.assertTrue(saved)
        exp = _load_experiment(
            experiment.name, decoder=self.with_db_settings.db_settings.decoder
        )
        self.assertEqual(len(exp.trials), 1)
        self.assertEqual(exp.trials[0].status, TrialStatus.RUNNING)
コード例 #2
0
ファイル: with_db_settings_base.py プロジェクト: bletham/Ax
    def _save_updated_trials_to_db_if_possible(
        self,
        experiment: Experiment,
        trials: List[BaseTrial],
        suppress_all_errors: bool = False,
    ) -> bool:
        """Saves updated trials on given experiment if DB settings are set on this
        `WithDBSettingsBase` instance.

        Args:
            experiment: Experiment, on which to save updated trials in DB.
            trials: Newly updated trials to save.
            suppress_all_errors: Flag for `retry_on_exception` that makes
                the decorator suppress the thrown exception even if it
                occurred in all the retries (exception is still logged).

        Returns:
            bool: Whether the trials were saved.
        """
        if self.db_settings_set:
            start_time = time.time()
            _save_or_update_trials(experiment=experiment,
                                   trials=trials,
                                   encoder=self.db_settings.encoder)
            logger.debug(
                f"Updated trials {[trial.index for trial in trials]} in "
                f"{_round_floats_for_logging(time.time() - start_time)} seconds."
            )
            return True
        return False
コード例 #3
0
def _save_or_update_trials_in_db_if_possible(
    experiment: Experiment,
    trials: List[BaseTrial],
    encoder: Encoder,
    decoder: Decoder,
    suppress_all_errors: bool,
) -> None:
    start_time = time.time()
    _save_or_update_trials(
        experiment=experiment,
        trials=trials,
        encoder=encoder,
        decoder=decoder,
        batch_size=STORAGE_MINI_BATCH_SIZE,
    )
    logger.debug(
        f"Saved or updated trials {[trial.index for trial in trials]} in "
        f"{_round_floats_for_logging(time.time() - start_time)} seconds "
        f"in mini-batches of {STORAGE_MINI_BATCH_SIZE}.")