From c70edf42f4b1978612620fa12f64e2de2e52d1ce Mon Sep 17 00:00:00 2001 From: Zhenyu Wang Date: Mon, 25 Mar 2024 08:49:13 +0800 Subject: [PATCH] fix: fix calypso-op to compatible with dpv3 --- dpgen2/exploration/task/calypso/caly_input.py | 3 ++- dpgen2/op/prep_caly_input.py | 3 ++- dpgen2/op/prep_run_dp_optim.py | 12 +++++++++--- dpgen2/op/run_caly_model_devi.py | 3 ++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/dpgen2/exploration/task/calypso/caly_input.py b/dpgen2/exploration/task/calypso/caly_input.py index 686ec17a..28b668a6 100644 --- a/dpgen2/exploration/task/calypso/caly_input.py +++ b/dpgen2/exploration/task/calypso/caly_input.py @@ -18,6 +18,7 @@ calypso_run_opt_str = """#!/usr/bin/env python3 import os +import sys import time import glob import numpy as np @@ -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() diff --git a/dpgen2/op/prep_caly_input.py b/dpgen2/op/prep_caly_input.py index 7c2ed6df..b0b2a919 100644 --- a/dpgen2/op/prep_caly_input.py +++ b/dpgen2/op/prep_caly_input.py @@ -43,6 +43,7 @@ calypso_run_opt_str = """#!/usr/bin/env python3 import os +import sys import time import glob import numpy as np @@ -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() diff --git a/dpgen2/op/prep_run_dp_optim.py b/dpgen2/op/prep_run_dp_optim.py index c8aa53cd..36f38c0e 100644 --- a/dpgen2/op/prep_run_dp_optim.py +++ b/dpgen2/op/prep_run_dp_optim.py @@ -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) diff --git a/dpgen2/op/run_caly_model_devi.py b/dpgen2/op/run_caly_model_devi.py index 48e5a106..e6163b0e 100644 --- a/dpgen2/op/run_caly_model_devi.py +++ b/dpgen2/op/run_caly_model_devi.py @@ -273,7 +273,7 @@ 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" % ( @@ -281,6 +281,7 @@ def write_model_devi_out(devi: np.ndarray, fname: Union[str, Path], header: str f"min_devi_{item}", f"avg_devi_{item}", ) + header += "%19s" % "devi_e" with open(fname, "ab") as fp: np.savetxt( fp,