Source code for pycif.plugins.obsoperators.standard.transforms.utils.submit_and_kill

from logging import info
from pathlib import Path

from ......utils.yml import ordered_dump
from ......utils.check.errclass import CifRuntimeError


[docs] def submit_and_kill(self): ref_setup = self.reference_instances["reference_setup"] workdir = Path(ref_setup.workdir) config_file = Path(ref_setup.def_file) suffix = "_resubmit_" name = config_file.stem ext = config_file.suffix # Removes '_resubmit_XXX' suffix from file name if name[:-3].endswith(suffix): name = name[: -len(suffix) - 3] # Gets how many re-submissions where already done based on existing YAML files resub_config_file = None n_resubmissions = 0 for _ in range(self.max_resubmissions): n_resubmissions += 1 resub_config_file = workdir / f"{name}{suffix}{n_resubmissions:03d}{ext}" if not resub_config_file.exists(): break if n_resubmissions >= self.max_resubmissions or resub_config_file is None: raise CifRuntimeError( f"Job exceeded authorized run time of {self.autokill_time} and maximum " f"number of re-submissions of {self.max_resubmissions}. " "Please update you YAML configuration in order to resubmit the job." ) # Updating configuration dictionary config_dict = self.from_yaml(config_file) config_dict["obsoperator"]["autorestart"] = True if self.rename_resubmit_logfile: logfile = Path(config_dict["logfile"]) name = logfile.stem ext = logfile.suffix config_dict["logfile"] = f"{name}{suffix}{n_resubmissions:03}{ext}" # Dumps configuration to a new YAML file with open(resub_config_file, "w") as f: ordered_dump(f, config_dict) # Submit the job job_file = workdir / f"resubmit_{n_resubmissions:03}.sh" command = f"{self.platform.python} -m pycif {resub_config_file}" job_id = self.platform.submit_job(command, job_file) # Exiting info( f"The job was terminated and re-submitted " f"({n_resubmissions}th time of {self.max_resubmissions}). " f"Job id: '{job_id}'" ) exit()