Esempio n. 1
0
 def __init__(self, prefix, resume=resume_default, force=False, infix=None,
              output_prefix=None):
     self.name = "output"
     self.set_logger(self.name)
     # MARKED FOR DEPRECATION IN v3.0
     # -- also remove output_prefix kwarg above
     if output_prefix is not None:
         self.log.warning("*DEPRECATION*: `output_prefix` will be deprecated in the "
                          "next version. Please use `prefix` instead.")
         # BEHAVIOUR TO BE REPLACED BY ERROR:
         prefix = output_prefix
     # END OF DEPRECATION BLOCK
     self.lock = FileLock()
     self.folder, self.prefix = split_prefix(prefix)
     self.prefix_regexp_str = re.escape(self.prefix) + (
         r"[\._]" if self.prefix else "")
     self.force = force
     if resume and force and prefix:
         # No resume and force at the same time (if output)
         raise LoggedError(
             self.log,
             "Make 'resume: True' or 'force: True', not both at the same time: "
             "can't simultaneously overwrite a chain and resume from it.")
     if not os.path.exists(self.folder):
         self.log.debug("Creating output folder '%s'", self.folder)
         try:
             os.makedirs(self.folder)
         except OSError:
             self.log.error(get_traceback_text(sys.exc_info()))
             raise LoggedError(
                 self.log, "Could not create folder '%s'. "
                           "See traceback on top of this message.", self.folder)
     self.log.info("Output to be read-from/written-into folder '%s', with prefix '%s'",
                   self.folder, self.prefix)
     # Prepare file names, and check if chain exists
     self.file_input = get_info_path(
         self.folder, self.prefix, infix=infix, kind="input")
     self.file_updated = get_info_path(self.folder, self.prefix, infix=infix)
     self.dump_file_updated = get_info_path(
         self.folder, self.prefix, infix=infix, ext=Extension.dill)
     self._resuming = False
     # Output kind and collection extension
     self.kind = _kind
     self.ext = _ext
     if os.path.isfile(self.file_updated):
         self.log.info(
             "Found existing info files with the requested output prefix: '%s'",
             prefix)
         if self.force:
             self.log.info("Will delete previous products ('force' was requested).")
             self.delete_infos()
             # Sampler products will be deleted at sampler initialisation
         elif resume:
             # Only in this case we can be sure that we are actually resuming
             self._resuming = True
             self.log.info("Let's try to resume/load.")
Esempio n. 2
0
 def __exit__(self, exc_type, exc_val, exc_tb):
     if log:
         log.info('END %s %s', self.name, self.tag)
     if exc_type:
         self.set(State.ERROR)
         if not self.wait_all_ended(
                 timeout=not issubclass(exc_type, OtherProcessError)):
             from cobaya.log import get_traceback_text, LoggedError, get_logger
             get_logger(self.name).critical(
                 "Aborting MPI due to error" if issubclass(exc_type, LoggedError) else
                 get_traceback_text(sys.exc_info()))
             self.timeout_abort_proc()
             self.wait_all_ended()  # if didn't actually MPI abort
     else:
         self.set(State.END)
         self.wait_all_ended()
     set_current_process_state(self.last_process_state)
     if not exc_type and any(self.states == State.ERROR):
         self.fire_error()