예제 #1
0
 def delete_machine(self):
     request = DeleteInstancesRequest()
     request.set_accept_format('json')
     if len(self.instance_list) <= 100:
         request.set_InstanceIds(self.instance_list)
         request.set_Force(True)
         response = self.client.do_action_with_exception(request)
     else:
         iteration = len(self.instance_list) // 100
         for i in range(iteration):
             request.set_InstanceIds(self.instance_list[i * 100:(i + 1) *
                                                        100])
             request.set_Force(True)
             response = self.client.do_action_with_exception(request)
         if len(self.instance_list) - iteration * 100 != 0:
             request.set_InstanceIds(self.instance_list[iteration * 100:])
             request.set_Force(True)
             response = self.client.do_action_with_exception(request)
     self.instance_list = []
     self.ip_list = []
     os.remove('machine_record.json')
     dlog.debug("Successfully free the machine!")
예제 #2
0
파일: AWS.py 프로젝트: scut-ccmp/dpgen
    def AWS_check_status(cls, job_id=""):
        """
        to aviod query jobStatus too often, set a time interval
        query_dict example:
        {job_id: JobStatus}

        {'40fb24b2-d0ca-4443-8e3a-c0906ea03622': <JobStatus.running: 3>,
         '41bda50c-0a23-4372-806c-87d16a680d85': <JobStatus.waiting: 2>}
           
        """
        query_dict = {}
        if datetime.now().timestamp() > cls._query_next_allow_time:
            cls.batch_client = boto3.client('batch')
            cls._query_next_allow_time = datetime.now().timestamp(
            ) + cls._query_time_interval
            for status in [
                    'SUBMITTED', 'PENDING', 'RUNNABLE', 'STARTING', 'RUNNING',
                    'SUCCEEDED', 'FAILED'
            ]:
                status_response = cls.batch_client.list_jobs(
                    jobQueue=cls._jobQueue,
                    jobStatus=status,
                    maxResults=cls._query_max_results)
                status_list = status_response.get('jobSummaryList', [])
                for job_dict in status_list:
                    cls._job_id_map_status.update({
                        job_dict['jobId']:
                        cls.map_aws_status_to_dpgen_status(job_dict['status'])
                    })
            # for job in cls._job_id_map_status:
            #     cls._job_id_map_status[job]=query_dict.get(job, JobStatus.unknown)
            dlog.debug('20000:_map: %s' % (cls._job_id_map_status))
        dlog.debug('62000:job_id:%s, _query: %s, _map: %s' %
                   (job_id, query_dict, cls._job_id_map_status))
        if job_id:
            return cls._job_id_map_status.get(job_id, JobStatus.unknown)

        return cls._job_id_map_status
예제 #3
0
파일: AWS.py 프로젝트: scut-ccmp/dpgen
    def do_submit(self,
                  job_dirs,
                  cmd,
                  args=None,
                  res=None,
                  outlog='log',
                  errlog='err'):

        res = self.default_resources(res)
        dlog.debug("2000, params=(%s, %s, %s, %s, %s, %s, )" %
                   (job_dirs, cmd, args, res, outlog, errlog))
        dlog.debug(
            '2200, self.context.remote_root: %s , self.context.local_root: %s'
            % (self.context.remote_root, self.context.local_root))
        # concreate_command =
        script_str = self.sub_script(job_dirs,
                                     cmd,
                                     args=args,
                                     res=res,
                                     outlog=outlog,
                                     errlog=errlog)
        dlog.debug('2300, script_str: %s, self.sub_script_name: %s' %
                   (script_str, self.sub_script_name))
        """
        jobName example:
        home-ec2-user-Ag_init-run_gen-iter_000000-01_model_devi-task_000_000048
        """
        jobName = os.path.join(self.context.remote_root,
                               job_dirs.pop())[1:].replace('/', '-').replace(
                                   '.', '_')
        jobName += ("_" + str(self.context.job_uuid))
        response = self.__class__.batch_client.submit_job(
            jobName=jobName,
            jobQueue=res['jobQueue'],
            jobDefinition=res['jobDefinition'],
            parameters={'task_command': script_str},
            containerOverrides={
                'vcpus': res['cpu_num'],
                'memory': res['memory_size']
            })
        dlog.debug('4000, response:%s' % response)
        self.job_id = (response, res['jobQueue'])
예제 #4
0
파일: Dispatcher.py 프로젝트: y1xiaoc/dpgen
 def all_finished(self, job_handler):
     task_chunks = job_handler['task_chunks']
     task_chunks_str = ['+'.join(ii) for ii in task_chunks]
     task_hashes = [
         sha1(ii.encode('utf-8')).hexdigest() for ii in task_chunks_str
     ]
     job_list = job_handler['job_list']
     job_record = job_handler['job_record']
     command = job_handler['command']
     resources = job_handler['resources']
     outlog = job_handler['outlog']
     errlog = job_handler['errlog']
     backward_task_files = job_handler['backward_task_files']
     dlog.debug('checking jobs')
     nchunks = len(task_chunks)
     for idx in range(nchunks):
         cur_hash = task_hashes[idx]
         rjob = job_list[idx]
         if not job_record.check_finished(cur_hash):
             # chunk not finished according to record
             status = rjob['batch'].check_status()
             job_uuid = rjob['context'].job_uuid
             dlog.debug('checked job %s' % job_uuid)
             if status == JobStatus.terminated:
                 job_record.increase_nfail(cur_hash)
                 if job_record.check_nfail(cur_hash) > 3:
                     raise RuntimeError(
                         'Job %s failed for more than 3 times' % job_uuid)
                 dlog.info('job %s terminated, submit again' % job_uuid)
                 dlog.debug('try %s times for %s' %
                            (job_record.check_nfail(cur_hash), job_uuid))
                 rjob['batch'].submit(task_chunks[idx],
                                      command,
                                      res=resources,
                                      outlog=outlog,
                                      errlog=errlog,
                                      restart=True)
             elif status == JobStatus.finished:
                 dlog.info('job %s finished' % job_uuid)
                 rjob['context'].download(task_chunks[idx],
                                          backward_task_files)
                 rjob['context'].clean()
                 job_record.record_finish(cur_hash)
                 job_record.dump()
     job_record.dump()
     return job_record.check_all_finished()
예제 #5
0
def make_equi(confs, inter_param, relax_param):
    # find all POSCARs and their name like mp-xxx
    # ...
    dlog.debug('debug info make equi')
    if 'type_map' in inter_param:
        ele_list = [key for key in inter_param['type_map'].keys()]
    else:
        ele_list = [key for key in inter_param['potcars'].keys()]
    # ele_list = inter_param['type_map']
    dlog.debug("ele_list %s" % ':'.join(ele_list))
    conf_dirs = []
    for conf in confs:
        conf_dirs.extend(glob.glob(conf))
    conf_dirs.sort()

    # generate a list of task names like mp-xxx/relaxation/relax_task
    # ...
    cwd = os.getcwd()
    # generate poscar for single element crystal
    if len(ele_list) == 1:
        for ii in conf_dirs:
            os.chdir(ii)
            crys_type = ii.split('/')[-1]
            dlog.debug('crys_type: %s' % crys_type)
            dlog.debug('pwd: %s' % os.getcwd())
            if crys_type == 'std-fcc':
                if not os.path.exists('POSCAR'):
                    crys.fcc1(ele_list[0]).to('POSCAR', 'POSCAR')
            elif crys_type == 'std-hcp':
                if not os.path.exists('POSCAR'):
                    crys.hcp(ele_list[0]).to('POSCAR', 'POSCAR')
            elif crys_type == 'std-dhcp':
                if not os.path.exists('POSCAR'):
                    crys.dhcp(ele_list[0]).to('POSCAR', 'POSCAR')
            elif crys_type == 'std-bcc':
                if not os.path.exists('POSCAR'):
                    crys.bcc(ele_list[0]).to('POSCAR', 'POSCAR')
            elif crys_type == 'std-diamond':
                if not os.path.exists('POSCAR'):
                    crys.diamond(ele_list[0]).to('POSCAR', 'POSCAR')
            elif crys_type == 'std-sc':
                if not os.path.exists('POSCAR'):
                    crys.sc(ele_list[0]).to('POSCAR', 'POSCAR')

            os.chdir(cwd)
    task_dirs = []
    # make task directories like mp-xxx/relaxation/relax_task
    # if mp-xxx/exists then print a warning and exit.
    # ...
    for ii in conf_dirs:
        crys_type = ii.split('/')[-1]
        dlog.debug('crys_type: %s' % crys_type)

        if 'mp-' in crys_type and not os.path.exists(os.path.join(
                ii, 'POSCAR')):
            get_structure(crys_type).to('POSCAR', os.path.join(ii, 'POSCAR'))

        poscar = os.path.abspath(os.path.join(ii, 'POSCAR'))
        if not os.path.exists(poscar):
            raise FileNotFoundError('no configuration for autotest')
        relax_dirs = os.path.abspath(
            os.path.join(ii, 'relaxation', 'relax_task')
        )  # to be consistent with property in make dispatcher
        if os.path.exists(relax_dirs):
            dlog.warning('%s already exists' % relax_dirs)
        else:
            os.makedirs(relax_dirs)
        task_dirs.append(relax_dirs)
        os.chdir(relax_dirs)
        # copy POSCARs to mp-xxx/relaxation/relax_task
        # ...
        if os.path.isfile('POSCAR'):
            os.remove('POSCAR')
        os.symlink(os.path.relpath(poscar), 'POSCAR')
        os.chdir(cwd)
    task_dirs.sort()
    # generate task files
    relax_param['cal_type'] = 'relaxation'
    if 'cal_setting' not in relax_param:
        relax_param['cal_setting'] = {
            "relax_pos": True,
            "relax_shape": True,
            "relax_vol": True
        }
    elif "relax_pos" not in relax_param['cal_setting']:
        relax_param['cal_setting']['relax_pos'] = True
    elif "relax_shape" not in relax_param['cal_setting']:
        relax_param['cal_setting']['relax_shape'] = True
    elif "relax_vol" not in relax_param['cal_setting']:
        relax_param['cal_setting']['relax_vol'] = True

    for ii in task_dirs:
        poscar = os.path.join(ii, 'POSCAR')
        dlog.debug('task_dir %s' % ii)
        inter = make_calculator(inter_param, poscar)
        inter.make_potential_files(ii)
        inter.make_input_file(ii, 'relaxation', relax_param)
예제 #6
0
    def submit(self, job_dirs, cmd, args=None, resources=None, restart=False):
        dlog.debug(restart)
        if restart:
            status = self.check_status()
            if status in [
                    JobStatus.unsubmitted, JobStatus.unknown,
                    JobStatus.terminated
            ]:
                dlog.debug('task restart point !!!')
                self._submit(job_dirs, cmd, args, resources)
            elif status == JobStatus.waiting:
                dlog.debug('task is waiting')
            elif status == JobStatus.running:
                dlog.debug('task is running')
            else:
                dlog.debug('task is finished')

        #except:
        #dlog.debug('no job_id file')
        #dlog.debug('task restart point !!!')
        #self._submit(job_dirs, cmd, args, resources)
        else:
            dlog.debug('new task!!!')
            self._submit(job_dirs, cmd, args, resources)
예제 #7
0
    def submit(self, job_dirs, cmd, args=None, resources=None, restart=False):
        def _submit():
            script_name = self._make_script(job_dirs, cmd, args, res=resources)
            stdin, stdout, stderr = self.block_checkcall(
                ('cd %s; sbatch %s' % (self.remote_root, script_name)))
            subret = (stdout.readlines())
            job_id = subret[0].split()[-1]
            sftp = self.ssh.open_sftp()

            with sftp.open(os.path.join(self.remote_root, 'job_id'),
                           'w') as fp:
                fp.write(job_id)
            sftp.close()

        dlog.debug(restart)
        if restart:
            try:
                status = self.check_status()
                dlog.debug(status)
                if status in [
                        JobStatus.unsubmitted, JobStatus.unknown,
                        JobStatus.terminated
                ]:
                    dlog.debug('task restart point !!!')
                    _submit()
                elif status == JobStatus.waiting:
                    dlog.debug('task is waiting')
                elif status == JobStatus.running:
                    dlog.debug('task is running')
                else:
                    dlog.debug('task is finished')

            except:
                dlog.debug('no job_id file')
                dlog.debug('task restart point !!!')
                _submit()
        else:
            dlog.debug('new task!!!')
            _submit()
예제 #8
0
파일: Batch.py 프로젝트: xcxxcx1996/dpgen
 def submit(self,
            job_dirs,
            cmd,
            args=None,
            res=None,
            restart=False,
            outlog='log',
            errlog='err'):
     if restart:
         dlog.debug('restart task')
         status = self.check_status()
         if status in [
                 JobStatus.unsubmitted, JobStatus.unknown,
                 JobStatus.terminated
         ]:
             dlog.debug('task restart point !!!')
             self.do_submit(job_dirs,
                            cmd,
                            args,
                            res,
                            outlog=outlog,
                            errlog=errlog)
         elif status == JobStatus.waiting:
             dlog.debug('task is waiting')
         elif status == JobStatus.running:
             dlog.debug('task is running')
         elif status == JobStatus.finished:
             dlog.debug('task is finished')
         else:
             raise RuntimeError('unknow job status, must be wrong')
     else:
         dlog.debug('new task')
         self.do_submit(job_dirs,
                        cmd,
                        args,
                        res,
                        outlog=outlog,
                        errlog=errlog)
     if res is None:
         sleep = 0
     else:
         sleep = res.get('submit_wait_time', 0)
     time.sleep(
         sleep)  # For preventing the crash of the tasks while submitting
예제 #9
0
    def run_jobs(self,
                 resources,
                 command,
                 work_path,
                 tasks,
                 group_size,
                 forward_common_files,
                 forward_task_files,
                 backward_task_files,
                 forward_task_deference=True,
                 outlog='log',
                 errlog='err'):
        # task_chunks = [
        #     [os.path.basename(j) for j in tasks[i:i + group_size]] \
        #     for i in range(0, len(tasks), group_size)
        # ]
        task_chunks = _split_tasks(tasks, group_size)
        _pmap = PMap(work_path)
        path_map = _pmap.load()
        _fr = FinRecord(work_path, len(task_chunks))

        job_list = []
        task_chunks_ = ['+'.join(ii) for ii in task_chunks]
        job_fin = _fr.get_record()
        assert (len(job_fin) == len(task_chunks))
        for ii, chunk in enumerate(task_chunks):
            if not job_fin[ii]:
                # map chunk info. to uniq id
                chunk_sha1 = sha1(task_chunks_[ii].encode('utf-8')).hexdigest()
                # if hash in map, recover job, else start a new job
                if chunk_sha1 in path_map:
                    # job_uuid = path_map[chunk_sha1][1].split('/')[-1]
                    job_uuid = path_map[chunk_sha1][2]
                    dlog.debug("load uuid %s for chunk %s" %
                               (job_uuid, task_chunks_[ii]))
                else:
                    job_uuid = None
                # communication context, bach system
                context = self.context(work_path, self.session, job_uuid)
                batch = self.batch(context, uuid_names=self.uuid_names)
                rjob = {'context': context, 'batch': batch}
                # upload files
                if not rjob['context'].check_file_exists('tag_upload'):
                    rjob['context'].upload('.', forward_common_files)
                    rjob['context'].upload(chunk,
                                           forward_task_files,
                                           dereference=forward_task_deference)
                    rjob['context'].write_file('tag_upload', '')
                    dlog.debug('uploaded files for %s' % task_chunks_[ii])
                # submit new or recover old submission
                if job_uuid is None:
                    rjob['batch'].submit(chunk,
                                         command,
                                         res=resources,
                                         outlog=outlog,
                                         errlog=errlog)
                    job_uuid = rjob['context'].job_uuid
                    dlog.debug('assigned uudi %s for %s ' %
                               (job_uuid, task_chunks_[ii]))
                    dlog.info('new submission of %s' % job_uuid)
                else:
                    rjob['batch'].submit(chunk,
                                         command,
                                         res=resources,
                                         outlog=outlog,
                                         errlog=errlog,
                                         restart=True)
                    dlog.info('restart from old submission %s ' % job_uuid)
                # record job and its hash
                job_list.append(rjob)
                path_map[chunk_sha1] = [
                    context.local_root, context.remote_root, job_uuid
                ]
            else:
                # finished job, append a None to list
                job_list.append(None)
        _pmap.dump(path_map)

        assert (len(job_list) == len(task_chunks))
        fcount = [0] * len(job_list)
        while not all(job_fin):
            dlog.debug('checking jobs')
            for idx, rjob in enumerate(job_list):
                if not job_fin[idx]:
                    status = rjob['batch'].check_status()
                    job_uuid = rjob['context'].job_uuid
                    if status == JobStatus.terminated:
                        fcount[idx] += 1
                        if fcount[idx] > 3:
                            raise RuntimeError(
                                'Job %s failed for more than 3 times' %
                                job_uuid)
                        dlog.info('job %s terminated, submit again' % job_uuid)
                        dlog.debug('try %s times for %s' %
                                   (fcount[idx], job_uuid))
                        rjob['batch'].submit(task_chunks[idx],
                                             command,
                                             res=resources,
                                             outlog=outlog,
                                             errlog=errlog,
                                             restart=True)
                    elif status == JobStatus.finished:
                        dlog.info('job %s finished' % job_uuid)
                        rjob['context'].download(task_chunks[idx],
                                                 backward_task_files)
                        rjob['context'].clean()
                        job_fin[idx] = True
                        _fr.write_record(job_fin)
            time.sleep(10)
        # delete path map file when job finish
        _pmap.delete()
예제 #10
0
def group_slurm_jobs(ssh_sess,
                     resources,
                     command,
                     work_path,
                     tasks,
                     group_size,
                     forward_common_files,
                     forward_task_files,
                     backward_task_files,
                     remote_job=SlurmJob,
                     forward_task_deference=True):

    task_chunks = [
        [os.path.basename(j) for j in tasks[i:i + group_size]] \
        for i in range(0, len(tasks), group_size)
    ]
    cwd = os.getcwd()
    _pmap = PMap(cwd)
    path_map = _pmap.load()
    dlog.debug("work_path: %s" % work_path)
    dlog.debug("curr_path: %s" % cwd)

    job_list = []
    task_chunks_ = ['+'.join(ii) for ii in task_chunks]
    for ii in task_chunks_:
        dlog.debug("task_chunk %s" % ii)

    #dlog.debug(path_map)
    for ii, chunk in enumerate(task_chunks):

        # map chunk info. to uniq id
        chunk_uni = task_chunks_[ii].encode('utf-8')
        chunk_sha1 = sha1(chunk_uni).hexdigest()

        if chunk_sha1 in path_map:
            job_uuid = path_map[chunk_sha1][1].split('/')[-1]
            dlog.debug("load uuid %s" % job_uuid)
        else:
            job_uuid = None

        rjob = remote_job(ssh_sess, work_path, job_uuid)
        dlog.debug('uuid %s' % job_uuid)
        rjob.upload('.', forward_common_files)
        rjob.upload(chunk,
                    forward_task_files,
                    dereference=forward_task_deference)
        if job_uuid:
            rjob.submit(chunk, command, resources=resources, restart=True)
        else:
            rjob.submit(chunk, command, resources=resources)
        job_list.append(rjob)
        path_map[chunk_sha1] = [rjob.local_root, rjob.remote_root]
    _pmap.dump(path_map)

    job_fin = [False for ii in job_list]
    lcount = [0] * len(job_list)
    count_fail = 0
    while not all(job_fin):
        for idx, rjob in enumerate(job_list):
            if not job_fin[idx]:
                try:
                    status = rjob.check_status()
                except:
                    ssh_sess = SSHSession(ssh_sess.remote_profile)
                    for _idx, _rjob in enumerate(job_list):
                        job_list[_idx] = SlurmJob(ssh_sess, work_path,
                                                  _rjob.job_uuid)
                    count_fail = count_fail + 1
                    dlog.info("ssh_sess failed for %d times" % count_fail)
                    break
                if status == JobStatus.terminated:
                    lcount[idx] += 1
                    _job_uuid = rjob.remote_root.split('/')[-1]
                    dlog.info('Job at %s  terminated, submit again' %
                              _job_uuid)
                    dlog.debug('try %s times for %s' %
                               (lcount[idx], _job_uuid))
                    rjob.submit(task_chunks[idx],
                                command,
                                resources=resources,
                                restart=True)
                    if lcount[idx] > 3:
                        dlog.info('Too many errors for ! %s ' % _job_uuid)
                        rjob.download(task_chunks[idx],
                                      backward_task_files,
                                      back_error=True)
                        rjob.clean()
                        job_fin[idx] = True
                elif status == JobStatus.finished:
                    rjob.download(task_chunks[idx], backward_task_files)
                    rjob.clean()
                    job_fin[idx] = True
        time.sleep(10)
    dlog.debug('error count')
    dlog.debug(lcount)
    # delete path map file when job finish
    _pmap.delete()
예제 #11
0
 def submit(self, job_dirs, cmd, args=None, resources=None, restart=False):
     dlog.debug(restart)
     if restart:
         status = self.check_status()
         if status in [
                 JobStatus.unsubmitted, JobStatus.unknown,
                 JobStatus.terminated
         ]:
             dlog.debug('task restart point !!!')
             if 'task_max' in resources and resources['task_max'] > 0:
                 while self.check_limit(task_max=resources['task_max']):
                     time.sleep(60)
             self._submit(job_dirs, cmd, args, resources)
         elif status == JobStatus.waiting:
             dlog.debug('task is waiting')
         elif status == JobStatus.running:
             dlog.debug('task is running')
         else:
             dlog.debug('task is finished')
         #except:
         #dlog.debug('no job_id file')
         #dlog.debug('task restart point !!!')
         #self._submit(job_dirs, cmd, args, resources)
     else:
         dlog.debug('new task!!!')
         if 'task_max' in resources and resources['task_max'] > 0:
             while self.check_limit(task_max=resources['task_max']):
                 time.sleep(60)
         self._submit(job_dirs, cmd, args, resources)
     time.sleep(
         20)  # For preventing the crash of the tasks while submitting.
예제 #12
0
    def submit_jobs(self,
                    resources,
                    command,
                    work_path,
                    tasks,
                    group_size,
                    forward_common_files,
                    forward_task_files,
                    backward_task_files,
                    forward_task_deference=True,
                    outlog='log',
                    errlog='err'):
        self.backward_task_files = backward_task_files
        # task_chunks = [
        #     [os.path.basename(j) for j in tasks[i:i + group_size]] \
        #     for i in range(0, len(tasks), group_size)
        # ]
        task_chunks = _split_tasks(tasks, group_size)
        task_chunks_str = ['+'.join(ii) for ii in task_chunks]
        task_hashes = [
            sha1(ii.encode('utf-8')).hexdigest() for ii in task_chunks_str
        ]
        job_record = JobRecord(work_path, task_chunks, fname=self.jrname)
        job_record.dump()
        nchunks = len(task_chunks)

        job_list = []
        for ii in range(nchunks):
            cur_chunk = task_chunks[ii]
            cur_hash = task_hashes[ii]
            if not job_record.check_finished(cur_hash):
                # chunk is not finished
                # check if chunk is submitted
                submitted = job_record.check_submitted(cur_hash)
                if not submitted:
                    job_uuid = None
                else:
                    job_uuid = job_record.get_uuid(cur_hash)
                    dlog.debug("load uuid %s for chunk %s" %
                               (job_uuid, cur_hash))
                # communication context, bach system
                context = self.context(work_path, self.session, job_uuid)
                batch = self.batch(context, uuid_names=self.uuid_names)
                rjob = {'context': context, 'batch': batch}
                # upload files
                if not rjob['context'].check_file_exists(
                        rjob['batch'].upload_tag_name):
                    rjob['context'].upload('.', forward_common_files)
                    rjob['context'].upload(cur_chunk,
                                           forward_task_files,
                                           dereference=forward_task_deference)

                    rjob['context'].write_file(rjob['batch'].upload_tag_name,
                                               '')
                    dlog.debug('uploaded files for %s' % task_chunks_str[ii])
                # submit new or recover old submission
                if not submitted:
                    rjob['batch'].submit(cur_chunk,
                                         command,
                                         res=resources,
                                         outlog=outlog,
                                         errlog=errlog)
                    job_uuid = rjob['context'].job_uuid
                    dlog.debug('assigned uuid %s for %s ' %
                               (job_uuid, task_chunks_str[ii]))
                    dlog.info('new submission of %s for chunk %s' %
                              (job_uuid, cur_hash))
                else:
                    rjob['batch'].submit(cur_chunk,
                                         command,
                                         res=resources,
                                         outlog=outlog,
                                         errlog=errlog,
                                         restart=True)
                    dlog.info('restart from old submission %s for chunk %s' %
                              (job_uuid, cur_hash))
                # record job and its remote context
                job_list.append(rjob)
                ip = None
                instance_id = None
                if 'cloud_resources' in self.remote_profile:
                    ip = self.remote_profile['hostname']
                    instance_id = self.remote_profile['instance_id']
                job_record.record_remote_context(cur_hash, context.local_root,
                                                 context.remote_root, job_uuid,
                                                 ip, instance_id)
                job_record.dump()
            else:
                # finished job, append a None to list
                job_list.append(None)
        assert (len(job_list) == nchunks)
        job_handler = {
            'task_chunks': task_chunks,
            'job_list': job_list,
            'job_record': job_record,
            'command': command,
            'resources': resources,
            'outlog': outlog,
            'errlog': errlog,
            'backward_task_files': backward_task_files
        }
        return job_handler
예제 #13
0
    def compute(self,
                output_dir):
        log_lammps = os.path.join(output_dir, 'log.lammps')
        dump_lammps = os.path.join(output_dir, 'dump.relax')
        if not os.path.isfile(log_lammps):
            warnings.warn("cannot find log.lammps in " + output_dir + " skip")
            return None
        if not os.path.isfile(dump_lammps):
            warnings.warn("cannot find dump.relax in " + output_dir + " skip")
            return None
        else:
            box = []
            coord = []
            vol = []
            energy = []
            force = []
            virial = []
            stress = []
            with open(dump_lammps, 'r') as fin:
                dump = fin.read().split('\n')
            dumptime = []
            for idx, ii in enumerate(dump):
                if ii == 'ITEM: TIMESTEP':
                    box.append([])
                    coord.append([])
                    force.append([])
                    dumptime.append(int(dump[idx + 1]))
                    natom = int(dump[idx + 3])
                    xlo_bound = float(dump[idx + 5].split()[0])
                    xhi_bound = float(dump[idx + 5].split()[1])
                    xy = float(dump[idx + 5].split()[2])
                    ylo_bound = float(dump[idx + 6].split()[0])
                    yhi_bound = float(dump[idx + 6].split()[1])
                    xz = float(dump[idx + 6].split()[2])
                    zlo = float(dump[idx + 7].split()[0])
                    zhi = float(dump[idx + 7].split()[1])
                    yz = float(dump[idx + 7].split()[2])
                    xx = xhi_bound - max([0, xy, xz, xy + xz]) - (xlo_bound - min([0, xy, xz, xy + xz]))
                    yy = yhi_bound - max([0, yz]) - (ylo_bound - min([0, yz]))
                    zz = zhi - zlo
                    box[-1].append([xx, 0.0, 0.0])
                    box[-1].append([xy, yy, 0.0])
                    box[-1].append([xz, yz, zz])
                    vol.append(xx * yy * zz)
                    type_list = []
                    for jj in range(natom):
                        type_list.append(int(dump[idx + 9 + jj].split()[1]) - 1)
                        if 'xs ys zs' in dump[idx + 8]:
                            a_x = float(dump[idx + 9 + jj].split()[2]) * xx + float(
                                dump[idx + 9 + jj].split()[3]) * xy \
                                  + float(dump[idx + 9 + jj].split()[4]) * xz
                            a_y = float(dump[idx + 9 + jj].split()[3]) * yy + float(
                                dump[idx + 9 + jj].split()[4]) * yz
                            a_z = float(dump[idx + 9 + jj].split()[4]) * zz
                        else:
                            a_x = float(dump[idx + 9 + jj].split()[2])
                            a_y = float(dump[idx + 9 + jj].split()[3])
                            a_z = float(dump[idx + 9 + jj].split()[4])
                        coord[-1].append([a_x, a_y, a_z])
                        fx = float(dump[idx + 9 + jj].split()[5])
                        fy = float(dump[idx + 9 + jj].split()[6])
                        fz = float(dump[idx + 9 + jj].split()[7])
                        force[-1].append([fx, fy, fz])

            with open(log_lammps, 'r') as fp:
                if 'Total wall time:' not in fp.read():
                    warnings.warn("lammps not finished " + log_lammps + " skip")
                    return None
                else:
                    fp.seek(0)
                    lines = fp.read().split('\n')
                    idid = -1
                    for ii in dumptime:
                        idid += 1
                        for jj in lines:
                            line = jj.split()
                            if len(line) and str(ii) == line[0]:
                                try:
                                    [float(kk) for kk in line]
                                except:
                                    continue
                                stress.append([])
                                virial.append([])
                                energy.append(float(line[1]))
                                # virials = stress * vol * 1e5 *1e-30 * 1e19/1.6021766208
                                stress[-1].append([float(line[2]) / 1000.0, float(line[5]) / 1000.0, float(line[6]) / 1000.0])
                                stress[-1].append([float(line[5]) / 1000.0, float(line[3]) / 1000.0, float(line[7]) / 1000.0])
                                stress[-1].append([float(line[6]) / 1000.0, float(line[7]) / 1000.0, float(line[4]) / 1000.0])
                                stress_to_virial = vol[idid] * 1e5 * 1e-30 * 1e19 / 1.6021766208
                                virial[-1].append([float(line[2]) * stress_to_virial, float(line[5]) * stress_to_virial,
                                                   float(line[6]) * stress_to_virial])
                                virial[-1].append([float(line[5]) * stress_to_virial, float(line[3]) * stress_to_virial,
                                                   float(line[7]) * stress_to_virial])
                                virial[-1].append([float(line[6]) * stress_to_virial, float(line[7]) * stress_to_virial,
                                                   float(line[4]) * stress_to_virial])
                                break

            _tmp = self.type_map
            dlog.debug(_tmp)
            type_map_list = lammps.element_list(self.type_map)

            type_map_idx = list(range(len(type_map_list)))
            atom_numbs = []
            for ii in type_map_idx:
                count = 0
                for jj in type_list:
                    if jj == ii:
                        count += 1
                atom_numbs.append(count)

            # d_dump = dpdata.System(dump_lammps, fmt='lammps/dump', type_map=type_map_list)
            # d_dump.to('vasp/poscar', contcar, frame_idx=-1)

            result_dict = {"@module": "dpdata.system", "@class": "LabeledSystem", "data": {"atom_numbs": atom_numbs,
                                                                                           "atom_names": type_map_list,
                                                                                           "atom_types": {
                                                                                               "@module": "numpy",
                                                                                               "@class": "array",
                                                                                               "dtype": "int64",
                                                                                               "data": type_list},
                                                                                           "orig": {"@module": "numpy",
                                                                                                    "@class": "array",
                                                                                                    "dtype": "int64",
                                                                                                    "data": [0, 0, 0]},
                                                                                           "cells": {"@module": "numpy",
                                                                                                     "@class": "array",
                                                                                                     "dtype": "float64",
                                                                                                     "data": box},
                                                                                           "coords": {
                                                                                               "@module": "numpy",
                                                                                               "@class": "array",
                                                                                               "dtype": "float64",
                                                                                               "data": coord},
                                                                                           "energies": {
                                                                                               "@module": "numpy",
                                                                                               "@class": "array",
                                                                                               "dtype": "float64",
                                                                                               "data": energy},
                                                                                           "forces": {
                                                                                               "@module": "numpy",
                                                                                               "@class": "array",
                                                                                               "dtype": "float64",
                                                                                               "data": force},
                                                                                           "virials": {
                                                                                               "@module": "numpy",
                                                                                               "@class": "array",
                                                                                               "dtype": "float64",
                                                                                               "data": virial},
                                                                                           "stress": {
                                                                                               "@module": "numpy",
                                                                                               "@class": "array",
                                                                                               "dtype": "float64",
                                                                                               "data": stress}}}

            contcar = os.path.join(output_dir, 'CONTCAR')
            dumpfn(result_dict, contcar, indent=4)
            d_dump = loadfn(contcar)
            d_dump.to('vasp/poscar', contcar, frame_idx=-1)

            return result_dict