Skip to content

Commit

Permalink
Merge pull request #613 from amcadmus/master
Browse files Browse the repository at this point in the history
Merge recent devel into master
  • Loading branch information
amcadmus authored Dec 10, 2021
2 parents 02037ad + eb6449c commit 93b833a
Show file tree
Hide file tree
Showing 39 changed files with 669 additions and 238 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

[![GitHub release](https://img.shields.io/github/release/deepmodeling/dpgen.svg?maxAge=86400)](https://github.com/deepmodeling/dpgen/releases/)
[![doi:10.1016/j.cpc.2020.107206](https://img.shields.io/badge/DOI-10.1016%2Fj.cpc.2020.107206-blue)](https://doi.org/10.1016/j.cpc.2020.107206)
![Citations](https://citations.njzjz.win/10.1016/j.cpc.2020.107206)
[![conda install](https://img.shields.io/conda/dn/conda-forge/dpgen?label=conda%20install)](https://anaconda.org/conda-forge/dpgen)
[![pip install](https://img.shields.io/pypi/dm/dpgen?label=pip%20install)](https://pypi.org/project/dpgen)

Expand Down Expand Up @@ -544,20 +545,21 @@ The bold notation of key (such aas **type_map**) means that it's a necessary key
| training_iter0_model_path | list of string | ["/path/to/model0_ckpt/", ...] | The model used to init the first iter training. Number of element should be equal to `numb_models` |
| training_init_model | bool | False | Iteration > 0, the model parameters will be initilized from the model trained at the previous iteration. Iteration == 0, the model parameters will be initialized from `training_iter0_model_path`. |
| **default_training_param** | Dict | | Training parameters for `deepmd-kit` in `00.train`. <br /> You can find instructions from here: (https://github.com/deepmodeling/deepmd-kit)..<br /> |
| dp_compress | bool | false | Use `dp compress` to compress the model. Default is false. |
| *#Exploration*
| **model_devi_dt** | Float | 0.002 (recommend) | Timestep for MD |
| **model_devi_skip** | Integer | 0 | Number of structures skipped for fp in each MD
| **model_devi_f_trust_lo** | Float | 0.05 | Lower bound of forces for the selection.
| **model_devi_f_trust_hi** | Float | 0.15 | Upper bound of forces for the selection
| **model_devi_v_trust_lo** | Float | 1e10 | Lower bound of virial for the selection. Should be used with DeePMD-kit v2.x |
| **model_devi_v_trust_hi** | Float | 1e10 | Upper bound of virial for the selection. Should be used with DeePMD-kit v2.x |
| **model_devi_f_trust_lo** | Float or List of float | 0.05 | Lower bound of forces for the selection. If List, should be set for each index in `sys_configs`, respectively. |
| **model_devi_f_trust_hi** | Float or List of float | 0.15 | Upper bound of forces for the selection. If List, should be set for each index in `sys_configs`, respectively. |
| **model_devi_v_trust_lo** | Float or List of float | 1e10 | Lower bound of virial for the selection. If List, should be set for each index in `sys_configs`, respectively. Should be used with DeePMD-kit v2.x. |
| **model_devi_v_trust_hi** | Float or List of float | 1e10 | Upper bound of virial for the selection. If List, should be set for each index in `sys_configs`, respectively. Should be used with DeePMD-kit v2.x. |
| model_devi_adapt_trust_lo | Boolean | False | Adaptively determines the lower trust levels of force and virial. This option should be used together with `model_devi_numb_candi_f`, `model_devi_numb_candi_v` and optionally with `model_devi_perc_candi_f` and `model_devi_perc_candi_v`. `dpgen` will make two sets: 1. From the frames with force model deviation lower than `model_devi_f_trust_hi`, select `max(model_devi_numb_candi_f, model_devi_perc_candi_f*n_frames)` frames with largest force model deviation. 2. From the frames with virial model deviation lower than `model_devi_v_trust_hi`, select `max(model_devi_numb_candi_v, model_devi_perc_candi_v*n_frames)` frames with largest virial model deviation. The union of the two sets is made as candidate dataset|
| model_devi_numb_candi_f | Int | 10 | See `model_devi_adapt_trust_lo`.|
| model_devi_numb_candi_v | Int | 0 | See `model_devi_adapt_trust_lo`.|
| model_devi_perc_candi_f | Float | 0.0 | See `model_devi_adapt_trust_lo`.|
| model_devi_perc_candi_v | Float | 0.0 | See `model_devi_adapt_trust_lo`.|
| model_devi_f_avg_relative | Boolean | False | Normalized the force model deviations by the RMS force magnitude along the trajectory. This key should not be used with `use_relative`. |
| **model_devi_clean_traj** | Boolean | true | Deciding whether to clean traj folders in MD since they are too large. |
| **model_devi_clean_traj** | Boolean or Int | true | If type of model_devi_clean_traj is boolean type then it denote whether to clean traj folders in MD since they are too large. If it is Int type, then the most recent n iterations of traj folders will be retained, others will be removed. |
| **model_devi_nopbc** | Boolean | False | Assume open boundary condition in MD simulations. |
| model_devi_activation_func | List of list of string | [["tanh","tanh"],["tanh","gelu"],["gelu","tanh"],["gelu","gelu"]] | Set activation functions for models, length of the List should be the same as `numb_models`, and two elements in the list of string respectively assign activation functions to the embedding and fitting nets within each model. *Backward compatibility*: the orginal "List of String" format is still supported, where embedding and fitting nets of one model use the same activation function, and the length of the List should be the same as `numb_models`|
| **model_devi_jobs** | [<br/>{<br/>"sys_idx": [0], <br/>"temps": <br/>[100],<br/>"press":<br/>[1],<br/>"trj_freq":<br/>10,<br/>"nsteps":<br/> 1000,<br/> "ensembles": <br/> "nvt" <br />},<br />...<br />] | List of dict | Settings for exploration in `01.model_devi`. Each dict in the list corresponds to one iteration. The index of `model_devi_jobs` exactly accord with index of iterations |
Expand Down
6 changes: 6 additions & 0 deletions conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ requirements:
- requests
- dpdata
- dpdispatcher
- ase
- GromacsWrapper
- custodian

run:
- python >=3.6
Expand All @@ -34,6 +37,9 @@ requirements:
- dpdata
- dpdispatcher
- pymatgen
- ase
- GromacsWrapper
- custodian

test:
imports:
Expand Down
4 changes: 2 additions & 2 deletions dpgen/auto_test/EOS.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ def _compute_lower(self,
# vol = self.vol_start + ii * self.vol_step
vol = loadfn(os.path.join(all_tasks[ii], 'eos.json'))['volume']
task_result = loadfn(all_res[ii])
res_data[vol] = task_result['energies'][-1] / task_result['atom_numbs'][0]
ptr_data += '%7.3f %8.4f \n' % (vol, task_result['energies'][-1] / task_result['atom_numbs'][0])
res_data[vol] = task_result['energies'][-1] / task_result['atom_numbs'].sum()
ptr_data += '%7.3f %8.4f \n' % (vol, task_result['energies'][-1] / task_result['atom_numbs'].sum())
# res_data[vol] = all_res[ii]['energy'] / len(all_res[ii]['force'])
# ptr_data += '%7.3f %8.4f \n' % (vol, all_res[ii]['energy'] / len(all_res[ii]['force']))

Expand Down
4 changes: 2 additions & 2 deletions dpgen/auto_test/VASP.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ def make_input_file(self,
incar['ENCUT'] = cal_setting['encut']

if 'kspacing' in cal_setting:
dlog.info("%s setting KSAPCING to %s" % (self.make_input_file.__name__, cal_setting['kspacing']))
incar['KSAPCING'] = cal_setting['kspacing']
dlog.info("%s setting KSPACING to %s" % (self.make_input_file.__name__, cal_setting['kspacing']))
incar['KSPACING'] = cal_setting['kspacing']

if 'kgamma' in cal_setting:
dlog.info("%s setting KGAMMA to %s" % (self.make_input_file.__name__, cal_setting['kgamma']))
Expand Down
106 changes: 69 additions & 37 deletions dpgen/auto_test/common_equi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import warnings
from monty.serialization import dumpfn
from multiprocessing import Pool

import dpgen.auto_test.lib.crys as crys
import dpgen.auto_test.lib.util as util
Expand All @@ -12,6 +13,8 @@
from distutils.version import LooseVersion
from dpgen.dispatcher.Dispatcher import make_submission
from dpgen.remote.decide_machine import convert_mdata
from dpgen.auto_test.lib.utils import create_path

lammps_task_type = ['deepmd', 'meam', 'eam_fs', 'eam_alloy']


Expand Down Expand Up @@ -76,11 +79,11 @@ def make_equi(confs,
poscar = os.path.abspath(os.path.join(ii, 'POSCAR'))
if not os.path.exists(poscar):
raise FileNotFoundError('no configuration for autotest')
if os.path.exists(os.path.join(ii, 'relaxation', 'jr.json')):
os.remove(os.path.join(ii, 'relaxation', 'jr.json'))

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)
create_path(relax_dirs)
task_dirs.append(relax_dirs)
os.chdir(relax_dirs)
# copy POSCARs to mp-xxx/relaxation/relax_task
Expand Down Expand Up @@ -111,6 +114,47 @@ def make_equi(confs,
inter.make_input_file(ii, 'relaxation', relax_param)


def worker(work_path,
run_task,
forward_common_files,
forward_files,
backward_files,
mdata,
inter_type):
machine, resources, command, group_size = util.get_machine_info(mdata, inter_type)
disp = make_dispatcher(machine, resources, work_path, [run_task], group_size)
print("%s --> Runing... " % (work_path))

api_version = mdata.get('api_version', '0.9')
if LooseVersion(api_version) < LooseVersion('1.0'):
warnings.warn(f"the dpdispatcher will be updated to new version."
f"And the interface may be changed. Please check the documents for more details")
disp.run_jobs(resources,
command,
work_path,
[run_task],
group_size,
forward_common_files,
forward_files,
backward_files,
outlog='outlog',
errlog='errlog')
elif LooseVersion(api_version) >= LooseVersion('1.0'):
submission = make_submission(
mdata_machine=machine,
mdata_resources=resources,
commands=[command],
work_path=work_path,
run_tasks=run_task,
group_size=group_size,
forward_common_files=forward_common_files,
forward_files=forward_files,
backward_files=backward_files,
outlog='outlog',
errlog='errlog'
)
submission.run_submission()

def run_equi(confs,
inter_param,
mdata):
Expand All @@ -120,6 +164,11 @@ def run_equi(confs,
for conf in confs:
conf_dirs.extend(glob.glob(conf))
conf_dirs.sort()

processes = len(conf_dirs)
pool = Pool(processes=processes)
print("Submit job via %d processes" % processes)

# generate a list of task names like mp-xxx/relaxation/relax_task
# ...
work_path_list = []
Expand Down Expand Up @@ -150,45 +199,28 @@ def run_equi(confs,
if len(run_tasks) == 0:
return
else:
# if LooseVersion()
run_tasks = [os.path.basename(ii) for ii in all_task]
machine, resources, command, group_size = util.get_machine_info(mdata, inter_type)
print('%d tasks will be submited '%len(run_tasks))
multiple_ret = []
for ii in range(len(work_path_list)):
work_path = work_path_list[ii]
disp = make_dispatcher(machine, resources, work_path, [run_tasks[ii]], group_size)
print("%s --> Runing... "%(work_path))

api_version = mdata.get('api_version', '0.9')
if LooseVersion(api_version) < LooseVersion('1.0'):
warnings.warn(f"the dpdispatcher will be updated to new version."
f"And the interface may be changed. Please check the documents for more details")
disp.run_jobs(resources,
command,
work_path,
[run_tasks[ii]],
group_size,
forward_common_files,
forward_files,
backward_files,
outlog='outlog',
errlog='errlog')
elif LooseVersion(api_version) >= LooseVersion('1.0'):
submission = make_submission(
mdata_machine=machine,
mdata_resource=resources,
commands=[command],
work_path=work_path,
run_tasks=run_tasks,
group_size=group_size,
forward_common_files=forward_common_files,
forward_files=forward_files,
backward_files=backward_files,
outlog = 'outlog',
errlog = 'errlog'
)
submission.run_submission()

ret = pool.apply_async(worker, (work_path,
run_tasks[ii],
forward_common_files,
forward_files,
backward_files,
mdata,
inter_type,
))
multiple_ret.append(ret)
pool.close()
pool.join()
for ii in range(len(multiple_ret)):
if not multiple_ret[ii].successful():
raise RuntimeError("Task %d is not successful! work_path: %s " % (ii, work_path_list[ii]))
print('finished')

def post_equi(confs, inter_param):
# find all POSCARs and their name like mp-xxx
Expand Down
31 changes: 10 additions & 21 deletions dpgen/auto_test/common_prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from dpgen.dispatcher.Dispatcher import make_dispatcher
from dpgen.dispatcher.Dispatcher import make_submission
from dpgen.remote.decide_machine import convert_mdata
from dpgen.auto_test.lib.utils import create_path
lammps_task_type = ['deepmd', 'meam', 'eam_fs', 'eam_alloy']


Expand Down Expand Up @@ -73,10 +74,7 @@ def make_property(confs,
path_to_equi = os.path.join(ii, 'relaxation', 'relax_task')
path_to_work = os.path.join(ii, property_type + '_' + suffix)

if os.path.exists(path_to_work):
dlog.warning('%s already exists' % path_to_work)
else:
os.makedirs(path_to_work)
create_path(path_to_work)

prop = make_property_instance(jj)
task_list = prop.make_confs(path_to_work, path_to_equi, do_refine)
Expand Down Expand Up @@ -112,6 +110,7 @@ def run_property(confs,
conf_dirs.sort()
task_list = []
work_path_list = []
multiple_ret = []
for ii in conf_dirs:
sepline(ch=ii, screen=True)
for jj in property_list:
Expand Down Expand Up @@ -159,7 +158,7 @@ def run_property(confs,
all_task = tmp_task_list
run_tasks = util.collect_task(all_task, inter_type)
if len(run_tasks) == 0:
return
continue
else:
ret = pool.apply_async(worker, (work_path,
all_task,
Expand All @@ -169,23 +168,13 @@ def run_property(confs,
mdata,
inter_type,
))
# run_tasks = [os.path.basename(ii) for ii in all_task]
# machine, resources, command, group_size = util.get_machine_info(mdata, inter_type)
# disp = make_dispatcher(machine, resources, work_path, run_tasks, group_size)
# disp.run_jobs(resources,
# command,
# work_path,
# run_tasks,
# group_size,
# forward_common_files,
# forward_files,
# backward_files,
# outlog='outlog',
# errlog='errlog')
multiple_ret.append(ret)
pool.close()
pool.join()
if ret.successful():
print('finished')
for ii in range(len(multiple_ret)):
if not multiple_ret[ii].successful():
raise RuntimeError("Job %d is not successful!" % ii)
print('%d jobs are finished' % len(multiple_ret))


def worker(work_path,
Expand Down Expand Up @@ -215,7 +204,7 @@ def worker(work_path,
elif LooseVersion(api_version) >= LooseVersion('1.0'):
submission = make_submission(
mdata_machine=machine,
mdata_resource=resources,
mdata_resources=resources,
commands=[command],
work_path=work_path,
run_tasks=run_tasks,
Expand Down
7 changes: 5 additions & 2 deletions dpgen/data/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def make_vasp_md(jdata, mdata) :

for ii in sys_ps :
for jj in scale :
for kk in range(pert_numb) :
for kk in range(pert_numb+1) :
path_work = path_md
path_work = os.path.join(path_work, ii)
path_work = os.path.join(path_work, "scale-%.3f" % jj)
Expand Down Expand Up @@ -534,6 +534,8 @@ def coll_vasp_md(jdata) :
#dlog.info("md_nstep", md_nstep)
if nforce == md_nstep :
valid_outcars.append(outcar)
elif md_nstep == 0 and nforce == 1 :
valid_outcars.append(outcar)
else:
dlog.info("WARNING : in directory %s nforce in OUTCAR is not equal to settings in INCAR"%(os.getcwd()))
arg_cvt = " "
Expand Down Expand Up @@ -767,13 +769,14 @@ def gen_init_bulk(args) :
dlog.info("Current stage is 1, relax")
create_path(out_dir)
shutil.copy2(args.PARAM, os.path.join(out_dir, 'param.json'))
skip_relax = jdata['skip_relax']
if from_poscar :
make_super_cell_poscar(jdata)
else :
make_unit_cell(jdata)
make_super_cell(jdata)
place_element(jdata)
if args.MACHINE is not None:
if args.MACHINE is not None and not skip_relax:
make_vasp_relax(jdata, mdata)
run_vasp_relax(jdata, mdata)
else:
Expand Down
12 changes: 9 additions & 3 deletions dpgen/dispatcher/Dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,17 @@ def make_dispatcher(mdata, mdata_resource=None, work_path=None, run_tasks=None,
def make_submission(mdata_machine, mdata_resources, commands, work_path, run_tasks, group_size,
forward_common_files, forward_files, backward_files, outlog, errlog):

machine = Machine.load_from_dict(mdata_machine)
resources = Resources.load_from_dict(mdata_resources)

if mdata_machine['local_root'] != './':
raise RuntimeError(f"local_root must be './' in dpgen's machine.json.")

abs_local_root = os.path.abspath('./')

abs_mdata_machine = mdata_machine.copy()
abs_mdata_machine['local_root'] = abs_local_root

machine = Machine.load_from_dict(abs_mdata_machine)
resources = Resources.load_from_dict(mdata_resources)


command = "&&".join(commands)

Expand Down
8 changes: 7 additions & 1 deletion dpgen/dispatcher/LocalContext.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,13 @@ def download(self,
pass
elif (os.path.exists(rfile)) and (not os.path.exists(lfile)) :
# trivial case, download happily
shutil.move(rfile, lfile)
# If the file to be downloaded is a softlink, `cp` should be performed instead of `mv`.
# Otherwise, `lfile` is still a file linked to some original file,
# and when this file's removed, `lfile` will be invalid.
if os.path.islink(rfile):
shutil.copyfile(rfile,lfile)
else:
shutil.move(rfile, lfile)
elif (os.path.exists(rfile)) and (os.path.exists(lfile)) :
# both exists, replace!
dlog.info('find existing %s, replacing by %s' % (lfile, rfile))
Expand Down
Loading

0 comments on commit 93b833a

Please sign in to comment.