Example #1
0
    def _update_generation_strategy_in_db_if_possible(
        self,
        generation_strategy: GenerationStrategy,
        new_generator_runs: List[GeneratorRun],
        suppress_all_errors: bool = False,
    ) -> bool:
        """Updates the given generation strategy with new generator runs (and with
        new current generation step if applicable) if DB settings are set
        on this `WithDBSettingsBase` instance.

        Args:
            generation_strategy: Generation strategy to update in DB.
            new_generator_runs: New generator runs of this generation strategy
                since its last 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 experiment was saved.
        """
        if self.db_settings_set:
            start_time = time.time()
            _update_generation_strategy(
                generation_strategy=generation_strategy,
                generator_runs=new_generator_runs,
                encoder=self.db_settings.encoder,
            )
            logger.debug(
                f"Updated generation strategy {generation_strategy.name} in "
                f"{_round_floats_for_logging(time.time() - start_time)} seconds."
            )
            return True
        return False
Example #2
0
def _update_generation_strategy_in_db_if_possible(
    generation_strategy: GenerationStrategy,
    new_generator_runs: List[GeneratorRun],
    encoder: Encoder,
    decoder: Decoder,
    suppress_all_errors: bool,
) -> None:
    start_time = time.time()
    _update_generation_strategy(
        generation_strategy=generation_strategy,
        generator_runs=new_generator_runs,
        encoder=encoder,
        decoder=decoder,
        batch_size=STORAGE_MINI_BATCH_SIZE,
    )
    logger.debug(
        f"Updated generation strategy {generation_strategy.name} in "
        f"{_round_floats_for_logging(time.time() - start_time)} seconds in "
        f"mini-batches of {STORAGE_MINI_BATCH_SIZE} generator runs.")
Example #3
0
def update_generation_strategy(
    generation_strategy: GenerationStrategy,
    generator_runs: List[GeneratorRun],
    db_settings: DBSettings,
) -> None:
    """Update generation strategy in DB with new generator runs.

    Args:
        generation_strategy: Corresponding generation strategy.
        generator_runs: New generator runs produced from the generation strategy
            since its last save.
        db_settings: Defines behavior for loading/saving experiment to/from db.
    """
    init_engine_and_session_factory(creator=db_settings.creator,
                                    url=db_settings.url)
    start_time = time.time()
    _update_generation_strategy(
        generation_strategy=generation_strategy,
        generator_runs=generator_runs,
        encoder=db_settings.encoder,
    )
    logger.debug(
        f"Updated generation strategy {generation_strategy.name} in "
        f"{_round_floats_for_logging(time.time() - start_time)} seconds.")