Skip to content

Commit

Permalink
fix: fix calypso-op to compatible with dpv3
Browse files Browse the repository at this point in the history
  • Loading branch information
wangzyphysics committed Mar 25, 2024
1 parent 201812d commit c70edf4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion dpgen2/exploration/task/calypso/caly_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
calypso_run_opt_str = """#!/usr/bin/env python3
import os
import sys
import time
import glob
import numpy as np
Expand Down Expand Up @@ -100,7 +101,7 @@ def Write_Outcar(outcar, element, ele, volume, lat, pos, ene, force, stress, pst
def run_opt(fmax, stress):
# Using the ASE&DP to Optimize Configures
calc = DP(model='frozen_model.pb') # init the model before iteration
calc = DP(model=sys.argv[1]) # init the model before iteration
Opt_Step = 1000
start = time.time()
Expand Down
3 changes: 2 additions & 1 deletion dpgen2/op/prep_caly_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
calypso_run_opt_str = """#!/usr/bin/env python3
import os
import sys
import time
import glob
import numpy as np
Expand Down Expand Up @@ -126,7 +127,7 @@ def Write_Outcar(outcar, element, ele, volume, lat, pos, ene, force, stress, pst
def run_opt(fmax, stress):
'''Using the ASE&DP to Optimize Configures'''
calc = DP(model='frozen_model.pb') # init the model before iteration
calc = DP(model=sys.argv[1]) # init the model before iteration
Opt_Step = 1000
start = time.time()
Expand Down
12 changes: 9 additions & 3 deletions dpgen2/op/prep_run_dp_optim.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,23 @@ def execute(
caly_run_opt_file = _caly_run_opt_file.resolve()
caly_check_opt_file = _caly_check_opt_file.resolve()
poscar_list = [poscar.resolve() for poscar in poscar_dir.rglob("POSCAR_*")]
model_list = [model.resolve() for model in models_dir.rglob("*model*pb")]
model_name = "frozen_model.pb"
model_list = [model.resolve() for model in models_dir.rglob(model_name)]
if len(model_list) == 0:
model_name = "model.ckpt.pt"
model_list = [model.resolve() for model in models_dir.rglob(model_name)]
model_list = sorted(model_list, key=lambda x: str(x).split(".")[1])
model_file = model_list[0]

config = ip["config"] if ip["config"] is not None else {}
command = config.get("run_opt_command", "python -u calypso_run_opt.py")
command = config.get(
f"run_opt_command", "python -u calypso_run_opt.py {model_name}"
)

with set_directory(work_dir):
for idx, poscar in enumerate(poscar_list):
Path(poscar.name).symlink_to(poscar)
Path("frozen_model.pb").symlink_to(model_file)
Path(model_name).symlink_to(model_file)
Path(caly_run_opt_file.name).symlink_to(caly_run_opt_file)
Path(caly_check_opt_file.name).symlink_to(caly_check_opt_file)

Expand Down
3 changes: 2 additions & 1 deletion dpgen2/op/run_caly_model_devi.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,15 @@ def parse_traj(traj_file):


def write_model_devi_out(devi: np.ndarray, fname: Union[str, Path], header: str = ""):
assert devi.shape[1] == 7
assert devi.shape[1] == 8
header = "%s\n%10s" % (header, "step")
for item in "vf":
header += "%19s%19s%19s" % (
f"max_devi_{item}",
f"min_devi_{item}",
f"avg_devi_{item}",
)
header += "%19s" % "devi_e"
with open(fname, "ab") as fp:
np.savetxt(
fp,
Expand Down

0 comments on commit c70edf4

Please sign in to comment.