Beispiel #1
0
    def __init__(self, out_path, exe_path, params, time=10080, 
                priority=1, connection=None, verbose=False, 
                test=False, env='BaseTrial.yml'):
 
        self._connection = None
        if connection:
            self.connection = connection
        self.test = test
        self.verbose = verbose
        self.out_path = out_path
        self.exe_path = exe_path
        self.id_ = None
        self.priority = priority
        self.time = time

        if isinstance(params, dict):
            params = sorted(list(params.iteritems()))
        self.params = sorted(params)
        if verbose:
            print self.params
        sha1 = hashlib.sha1(str((self.exe_path, self.params)))
        self.hash_path = path(sha1.hexdigest())
        env_file = path('./environments') / path(env)
        self.wrap_path = path('./')
       
        if env_file.isfile():
            env = yaml.load(open(env_file))
            self.env = env
            resolve_env_vars(env)
            if self.verbose:
                print 'outpath before sub ', self.out_path
            self.out_path = resolve(env, self.out_path)
            self.wrap_path = resolve(env, Trial.MANAGER)
            self.python_path = resolve(env, Trial.WORK) / 'local/bin/python'
        elif verbose:
            print 'No Enviroment path found'
        if self.verbose:
            print  'exe path, out path, ', self.exe_path, self.out_path
Beispiel #2
-1
    def submit(self):
        # set the PATH environment
        dir_ = self.out_path / self.hash_path
        if self.test:
            test = '--test '
        else:
            test = ''
        if test:
            print 'setting time to 60 mins for test'
            self.time = 60
        work_path = resolve(self.env, Trial.WORK)
        if self.verbose: 
            print 'work path = ', work_path 
        command = "LD_LIBRARY_PATH=%s/local/lib PATH=%s\n sqsub %s -r  %d -o %s %s %s %s" % (
                   work_path,
                   SharcNetTrial.PATH + ":/home/%s/bin" %self.connection.get_username(),
                   test, self.time, str(dir_/path(Trial.LOG)), 
                   self.python_path,
                   str(self.wrap_path / path(Trial.WRAPPER)), str(dir_))
        if self.verbose:
            print 'Command = ', command
        stdin, stdout, stderr = self.connection.exec_command(command)

        output = [line for line in stdout]
        errors = [line for line in stderr]

        for line in output:
            match = re.search(pattern='jobid\s+(?P<job>\d+)', string=line)
            if match:
                self.id_ = int(match.groupdict()['job'])
                if self.verbose: 
                    print 'self.id = ', self.id_
        
        return output, errors