Ejemplo n.º 1
0
    def save_to_dir(self, dirpath: str, session_str: str):
        """Saves self + searcher to dir.

        Separates the "searcher" from its wrappers (concurrency, repeating).
        This allows the user to easily restore a given searcher.

        The save operation is atomic (write/swap).

        Args:
            dirpath: Filepath to experiment dir.
            session_str: Unique identifier of the current run
                session.
        """
        searcher = self.searcher
        search_alg_state = self.get_state()
        while hasattr(searcher, "searcher"):
            searcher_name = type(searcher).__name__
            if searcher_name in search_alg_state:
                logger.warning(
                    "There was a duplicate when saving {}. "
                    "Restore may not work properly.".format(searcher_name))
            else:
                search_alg_state["name:" +
                                 searcher_name] = searcher.get_state()
            searcher = searcher.searcher
        base_searcher = searcher
        # We save the base searcher separately for users to easily
        # separate the searcher.
        base_searcher.save_to_dir(dirpath, session_str)
        atomic_save(
            state=search_alg_state,
            checkpoint_dir=dirpath,
            file_name=self.CKPT_FILE_TMPL.format(session_str),
            tmp_file_name=".tmp_search_generator_ckpt",
        )
Ejemplo n.º 2
0
 def save_to_dir(self, dirpath, session_str):
     if any(iterator.lazy_eval for iterator in self._iterators):
         return False
     state_dict = self.get_state()
     atomic_save(state=state_dict,
                 checkpoint_dir=dirpath,
                 file_name=self.CKPT_FILE_TMPL.format(session_str),
                 tmp_file_name=".tmp_generator")