Beispiel #1
0
 def _validate_environment(self):
     """Ensure there is a currently active Environment instance that is not already occupied"""
     if G.Env is None:
         raise EnvironmentInactiveError("")
     if G.Env.current_task is None:
         G.Env.current_task = self
         G.log(f"Validated Environment:  '{self.cross_experiment_key}'")
     else:
         raise EnvironmentInvalidError(
             "Current experiment must finish before starting another")
Beispiel #2
0
 def _validate_environment():
     """Check that there is a currently active and unoccupied Environment instance"""
     if G.Env is None:
         raise EnvironmentInactiveError()
     if G.Env.current_task is None:
         G.log_(
             f'Validated Environment with key: "{G.Env.cross_experiment_key}"'
         )
     else:
         raise EnvironmentInvalidError(
             "Must finish current task before starting a new one")
Beispiel #3
0
    def _create_script_backup(self):
        """Create and save a copy of the script that initialized the Experiment if allowed to, and
        if :attr:`source_script` ends with a ".py" extension"""
        #################### Attempt to Copy Source Script if Allowed ####################
        try:
            if not self.source_script.endswith(".py"):
                G.Env.result_paths["script_backup"] = None

            if G.Env.result_paths["script_backup"] is not None:
                try:
                    self._source_copy_helper()
                except FileNotFoundError:
                    make_dirs(self.result_paths["script_backup"],
                              exist_ok=False)
                    self._source_copy_helper()
                G.log(
                    "Created source backup:  '{}'".format(self.source_script),
                    4)
            else:
                G.log(
                    "Skipped source backup:  '{}'".format(self.source_script),
                    4)
        #################### Exception Handling ####################
        except AttributeError as _ex:
            if G.Env is None:
                raise EnvironmentInactiveError(extra="\n{!s}".format(_ex))
            if not hasattr(G.Env, "result_paths"):
                raise EnvironmentInvalidError(
                    extra=f"G.Env lacks 'result_paths' attr\n{_ex!s}")
            raise
        except KeyError as _ex:
            if "script_backup" not in G.Env.result_paths:
                raise EnvironmentInvalidError(
                    extra=
                    f"G.Env.result_paths lacks 'script_backup' key\n{_ex!s}")
            raise
Beispiel #4
0
 def validate_environment(self):
     """Check that the currently active Environment is suitable"""
     if G.Env is None:
         raise EnvironmentInactiveError("")
     if not all([hasattr(G.Env, _) for _ in ["result_paths", "cross_experiment_key"]]):
         raise EnvironmentInvalidError("")
     try:
         # Ensure :attr:`tested_keys_dir` exists before calling :meth:`does_key_exist`, so "None" paths won't be checked
         if os.path.exists(self.tested_keys_dir) is False:
             # TypeError may also be raised if :func:`os.path.exists` receives invalid input
             raise TypeError
     except TypeError:  # Key-making blacklisted
         if self.tested_keys_dir is None:
             return
         make_dirs(self.tested_keys_dir)