Beispiel #1
0
    def __init__(self, hawc2_path, hawc2_cmd, htc_file, exe_dir, input_files, output_files, queue='workq', walltime='00:10:00'):
        self.hawc2_path = hawc2_path
        self.hawc2_cmd = hawc2_cmd
        self.htc_file = htc_file
        self.exe_dir = exe_dir
        self.queue = queue
        self.walltime = walltime

        if not os.path.isabs(htc_file):
            htc_file = pjoin(exe_dir, htc_file)
        else:
            htc_file = htc_file.replace("\\", "/")

        if htc_file not in input_files:
            input_files.append(htc_file)
        self.input_files = [abspath((pjoin(exe_dir, f), abspath(f))[os.path.isabs(f)])
                            for f in input_files]
        self.htc_file = relpath(htc_file, exe_dir)

        self.output_files = [abspath((pjoin(exe_dir, f), abspath(f))[os.path.isabs(f)])
                             for f in output_files]

        self.model_path = abspath(pjoin(exe_dir, relpath(os.path.commonprefix(
            self.input_files + self.output_files).rpartition("/")[0], exe_dir)))
        self.model_name = os.path.basename(abspath(self.model_path))
        self.jobname = os.path.splitext(os.path.basename(htc_file))[0]

        PBSFile.__init__(self, self.model_path, self.jobname, self.commands, queue, walltime=walltime)
Beispiel #2
0
    def copy_input(self):
        rel_input_files = [relpath(f, self.model_path) for f in self.input_files]

        copy_input = "\n".join(["mkdir -p [TARGET]/%s && cp -u -r %s [TARGET]/%s" % (os.path.dirname(f), f, os.path.dirname(f))
                                for f in rel_input_files])
        return (copy_input.replace("[TARGET]", "/scratch/$USER/$PBS_JOBID/[model_name]"),
                copy_input.replace("[TARGET]", "/scratch/$USER/$PBS_JOBID/[model_name]/run_[jobname]"))
Beispiel #3
0
 def copy_output(self):
     rel_output_files = [
         relpath(f, self.modelpath) for f in self.output_files
     ]
     return "\n".join([
         'mkdir -p "[modelpath]/%s" && cp -u -r "%s" "[modelpath]/%s"' %
         (os.path.dirname(f), f, os.path.dirname(f))
         for f in rel_output_files
     ])
Beispiel #4
0
 def copy_output(self):
     rel_output_files = [
         relpath(f, self.model_path) for f in self.output_files
     ]
     return "\n".join([
         "mkdir -p [model_path]/%s && cp -u -r %s [model_path]/%s" %
         (os.path.dirname(f), f, os.path.dirname(f))
         for f in rel_output_files
     ])
Beispiel #5
0
 def commands(self):
     rel_exe_dir = relpath(abspath(self.exe_dir), abspath(self.modelpath))
     copy_input_to_scratch, copy_input_to_exe_dir = self.copy_input()
     return template(copy_hawc2=self.copy_hawc2(),
                     exe_dir=cluster_path(self.exe_dir),
                     copy_input_to_scratch=copy_input_to_scratch,
                     copy_input_to_exe_dir=copy_input_to_exe_dir,
                     rel_exe_dir=rel_exe_dir,
                     hawc2_cmd=self.hawc2_cmd,
                     htc_file=self.htc_file,
                     jobname=self.jobname,
                     copy_output=self.copy_output(),
                     modelpath=cluster_path(self.modelpath),
                     modelname=self.modelname)