Skip to content

Commit

Permalink
add UT for abacus/fix getattr value/add restart subcommand (#177)
Browse files Browse the repository at this point in the history
add UT for abacus
fix outputs.parameters[exploration_scheduler] has no attribute value
add restart subcommand for debug mode

---------

Signed-off-by: zjgemi <liuxin_zijian@163.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
zjgemi and pre-commit-ci[bot] committed Oct 17, 2023
1 parent 0c45f50 commit 16f24d6
Show file tree
Hide file tree
Showing 16 changed files with 10,991 additions and 0 deletions.
18 changes: 18 additions & 0 deletions dpgen2/entrypoint/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Optional,
)

import dflow
from dflow import (
Step,
Steps,
Expand Down Expand Up @@ -277,6 +278,14 @@ def main_parser() -> argparse.ArgumentParser:
for cmd in workflow_subcommands:
add_subparser_workflow_subcommand(subparsers, cmd)

parser_restart = subparsers.add_parser(
"restart",
help="restart a DPGEN2 workflow (for debug mode only).",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser_restart.add_argument("CONFIG", help="the config file in json format.")
parser_restart.add_argument("ID", help="the ID of the workflow.")

# --version
parser.add_argument(
"-v",
Expand Down Expand Up @@ -390,6 +399,15 @@ def main():
port=args.port,
bind_all=args.bind_all,
)
elif args.command == "restart":
with open(args.CONFIG) as fp:
config = json.load(fp)
wf = submit_concurrent_learning(
config,
no_submission=True,
)
wf.id = args.ID
wf.submit()
elif args.command in workflow_subcommands:
with open(args.CONFIG) as fp:
config = json.load(fp)
Expand Down
1 change: 1 addition & 0 deletions dpgen2/utils/dflow_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def get_last_scheduler(
outputs is not None
and hasattr(outputs, "parameters")
and "exploration_scheduler" in outputs.parameters
and hasattr(outputs.parameters["exploration_scheduler"], "value")
):
return outputs.parameters["exploration_scheduler"].value

Expand Down
17 changes: 17 additions & 0 deletions tests/fp/data.abacus/INPUT
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
INPUT_PARAMETERS
calculation scf
suffix ABACUS
ntype 1
symmetry 0
ecutwfc 50.000000
scf_thr 1.000000e-08
scf_nmax 100
cal_force 1
cal_stress 1
basis_type pw
smearing_method mp
smearing_sigma 0.014600
mixing_type pulay
mixing_beta 0.700000
ks_solver dav
kspacing 0.20000
1,228 changes: 1,228 additions & 0 deletions tests/fp/data.abacus/Na_ONCV_PBE-1.0.upf

Large diffs are not rendered by default.

348 changes: 348 additions & 0 deletions tests/fp/data.abacus/OUT.ABACUS/INPUT

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions tests/fp/data.abacus/OUT.ABACUS/STRU_READIN_ADJUST.cif
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
data_none

_audit_creation_method generated by ABACUS

_cell_length_a 2.72368
_cell_length_b 2.72368
_cell_length_c 2.72368
_cell_angle_alpha 90
_cell_angle_beta 90
_cell_angle_gamma 90

loop_
_atom_site_label
_atom_site_fract_x
_atom_site_fract_y
_atom_site_fract_z
Na 0 0 0
Na 0.5 0.5 0.5
3,784 changes: 3,784 additions & 0 deletions tests/fp/data.abacus/OUT.ABACUS/istate.info

Large diffs are not rendered by default.

519 changes: 519 additions & 0 deletions tests/fp/data.abacus/OUT.ABACUS/kpoints

Large diffs are not rendered by default.

4,812 changes: 4,812 additions & 0 deletions tests/fp/data.abacus/OUT.ABACUS/running_scf.log

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions tests/fp/data.abacus/OUT.ABACUS/warning.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
In SCAN_BEGIN, can't find: LATTICE_PARAMETERS block.
Generate k-points file according to KSPACING: KPT
AUTO_SET NBANDS to 19
startmag_type = 2
charge from rho_at = 8.86329
charge should be = 9

SETUP ATOMIC RHO FOR SPIN 1
Electron number from rho = 18
total electron number from rho = 18
should be = 18
charge before normalized = 18
charge after normalized = 18
scf warning : Threshold on eigenvalues was too large.
148 changes: 148 additions & 0 deletions tests/fp/data.abacus/log
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@

ABACUS v3.4.0

Atomic-orbital Based Ab-initio Computation at UStc

Website: http://abacus.ustc.edu.cn/
Documentation: https://abacus.deepmodeling.com/
Repository: https://github.com/abacusmodeling/abacus-develop
https://github.com/deepmodeling/abacus-develop
Commit: 923b69739 (Wed Oct 4 08:03:06 2023 +0800)

Wed Oct 11 18:19:35 2023
MAKE THE DIR : OUT.ABACUS/

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Warning: the number of valence electrons in pseudopotential > 1 for Na: [Ne] 3s1
Pseudopotentials with additional electrons can yield (more) accurate outcomes, but may be less efficient.
If you're confident that your chosen pseudopotential is appropriate, you can safely ignore this warning.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

UNIFORM GRID DIM : 24 * 24 * 24
UNIFORM GRID DIM(BIG) : 24 * 24 * 24
DONE(0.0548091 SEC) : SETUP UNITCELL
DONE(0.0725173 SEC) : INIT K-POINTS
---------------------------------------------------------
Self-consistent calculations for electrons
---------------------------------------------------------
SPIN KPOINTS PROCESSORS
1 172 8
---------------------------------------------------------
Use plane wave basis
---------------------------------------------------------
ELEMENT NATOM XC
Na 2
---------------------------------------------------------
Initial plane wave basis and FFT box
---------------------------------------------------------
DONE(0.0800991 SEC) : INIT PLANEWAVE
MEMORY FOR PSI (MB) : 5.63483
DONE(0.0827224 SEC) : LOCAL POTENTIAL
DONE(0.110291 SEC) : NON-LOCAL POTENTIAL
DONE(0.110479 SEC) : INIT BASIS
-------------------------------------------
SELF-CONSISTENT :
-------------------------------------------
START CHARGE : atomic
DONE(0.120689 SEC) : INIT SCF
ITER ETOT(eV) EDIFF(eV) DRHO TIME(s)
DA1 -2.311285e+03 0.000000e+00 5.600e-02 9.706e+00
DA2 -2.311426e+03 -1.417236e-01 2.051e-03 2.038e+00
DA3 -2.311428e+03 -1.722780e-03 2.507e-04 2.323e+00
DA4 -2.311428e+03 -1.182258e-04 5.989e-07 2.253e+00
DA5 -2.311428e+03 -3.124808e-06 8.708e-08 4.012e+00
DA6 -2.311428e+03 5.838250e-07 8.032e-09 2.094e+00
><><><><><><><><><><><><><><><><><><><><><><
TOTAL-STRESS (KBAR):
><><><><><><><><><><><><><><><><><><><><><><
1.216e+03 -1.242e-04 -1.421e-05
-1.242e-04 1.216e+03 5.712e-05
-1.421e-05 5.712e-05 1.216e+03
TOTAL-PRESSURE: 1.216e+03 KBAR
TIME STATISTICS
------------------------------------------------------------------------------
CLASS_NAME NAME TIME(Sec) CALLS AVG(Sec) PER(%)
------------------------------------------------------------------------------
total 22.98 15 1.53 100.00
Driver reading 0.03 1 0.03 0.13
Input Init 0.02 1 0.02 0.08
Input_Conv Convert 0.00 1 0.00 0.00
Driver driver_line 22.95 1 22.95 99.87
UnitCell check_tau 0.00 1 0.00 0.00
PW_Basis setuptransform 0.01 1 0.01 0.03
PW_Basis distributeg 0.00 1 0.00 0.00
mymath heapsort 0.00 3 0.00 0.00
PW_Basis_K setuptransform 0.00 1 0.00 0.01
PW_Basis_K distributeg 0.00 1 0.00 0.00
PW_Basis setup_struc_factor 0.00 1 0.00 0.00
ppcell_vnl init 0.00 1 0.00 0.00
ppcell_vl init_vloc 0.00 1 0.00 0.01
ppcell_vnl init_vnl 0.03 1 0.03 0.12
Sphbes Spherical_Bessel 0.02 3412 0.00 0.10
WF_atomic init_at_1 0.00 1 0.00 0.00
wavefunc wfcinit 0.00 1 0.00 0.00
Ions opt_ions 22.85 1 22.85 99.43
ESolver_KS_PW Run 22.45 1 22.45 97.71
H_Ewald_pw compute_ewald 0.00 1 0.00 0.00
Charge set_rho_core 0.00 1 0.00 0.00
Charge atomic_rho 0.01 1 0.01 0.03
PW_Basis recip2real 0.01 40 0.00 0.04
PW_Basis gathers_scatterp 0.00 40 0.00 0.01
Potential init_pot 0.00 1 0.00 0.01
Potential update_from_charge 0.01 7 0.00 0.06
Potential cal_fixed_v 0.00 1 0.00 0.00
PotLocal cal_fixed_v 0.00 1 0.00 0.00
Potential cal_v_eff 0.01 7 0.00 0.06
H_Hartree_pw v_hartree 0.00 7 0.00 0.01
PW_Basis real2recip 0.01 62 0.00 0.02
PW_Basis gatherp_scatters 0.00 62 0.00 0.02
PotXC cal_v_eff 0.01 7 0.00 0.05
XC_Functional v_xc 0.01 7 0.00 0.05
HSolverPW solve 22.41 7 3.20 97.53
Nonlocal getvnl 0.12 1204 0.00 0.51
pp_cell_vnl getvnl 0.14 1548 0.00 0.60
Structure_Factor get_sk 0.03 2924 0.00 0.13
DiagoDavid diag_mock 20.75 1204 0.02 90.32
DiagoDavid first 4.77 1204 0.00 20.77
DiagoDavid SchmitOrth 1.38 68810 0.00 5.99
Operator hPsi 10.17 5602 0.00 44.26
Operator EkineticPW 0.16 5602 0.00 0.71
Operator VeffPW 9.58 5602 0.00 41.68
PW_Basis_K recip2real 5.16 79723 0.00 22.45
PW_Basis_K gathers_scatterp 4.35 79723 0.00 18.93
PW_Basis_K real2recip 4.86 68810 0.00 21.13
PW_Basis_K gatherp_scatters 4.18 68810 0.00 18.19
Operator NonlocalPW 0.39 5602 0.00 1.69
Nonlocal add_nonlocal_pp 0.18 5602 0.00 0.78
DiagoDavid cal_elem 4.08 5602 0.00 17.77
DiagoDavid diag_zhegvx 4.26 5602 0.00 18.53
DiagoDavid cal_grad 8.52 4398 0.00 37.07
DiagoDavid check_update 0.01 4398 0.00 0.04
DiagoDavid last 0.12 1378 0.00 0.51
DiagoDavid refresh 0.03 174 0.00 0.13
ElecStatePW psiToRho 0.79 7 0.11 3.44
Charge_Mixing rhog_dot_product 0.00 7 0.00 0.00
Charge mix_rho 0.00 5 0.00 0.01
Charge Pulay_mixing 0.00 5 0.00 0.01
Charge plain_mixing 0.00 1 0.00 0.00
Inverse using_zheev 0.00 4 0.00 0.00
Forces cal_force_loc 0.00 1 0.00 0.00
Forces cal_force_ew 0.00 1 0.00 0.00
Forces cal_force_nl 0.05 1 0.05 0.20
Forces cal_force_cc 0.00 1 0.00 0.00
Forces cal_force_scc 0.00 1 0.00 0.01
Stress_PW cal_stress 0.35 1 0.35 1.51
Stress_Func stress_kin 0.01 1 0.01 0.05
Stress_Func stress_har 0.00 1 0.00 0.00
Stress_Func stress_ewa 0.00 1 0.00 0.00
Stress_Func stress_gga 0.00 1 0.00 0.00
Stress_Func stress_loc 0.00 1 0.00 0.02
Stress_Func stress_cc 0.00 1 0.00 0.00
Stress_Func stress_nl 0.33 1 0.33 1.43
ModuleIO write_istate_info 0.02 1 0.02 0.09
------------------------------------------------------------------------------

START Time : Wed Oct 11 18:19:35 2023
FINISH Time : Wed Oct 11 18:19:58 2023
TOTAL Time : 23
SEE INFORMATION IN : OUT.ABACUS/
Binary file added tests/fp/data.abacus/sys-2/set.000/box.npy
Binary file not shown.
Binary file added tests/fp/data.abacus/sys-2/set.000/coord.npy
Binary file not shown.
2 changes: 2 additions & 0 deletions tests/fp/data.abacus/sys-2/type.raw
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0
0
1 change: 1 addition & 0 deletions tests/fp/data.abacus/sys-2/type_map.raw
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Na
81 changes: 81 additions & 0 deletions tests/fp/test_abacus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import os
import shutil
import unittest
from pathlib import (
Path,
)

import dflow
import dpdata
from dflow import (
Step,
Workflow,
download_artifact,
upload_artifact,
)

from dpgen2.fp import (
FpOpAbacusInputs,
PrepFpOpAbacus,
RunFpOpAbacus,
)
from dpgen2.superop import (
PrepRunFp,
)


class TestFpOpAbacus(unittest.TestCase):
def tearDown(self):
if Path("upload").is_dir():
shutil.rmtree("upload")
if Path("output").is_dir():
shutil.rmtree("output")
for p in Path(".").glob("abacus-dpgen-*"):
shutil.rmtree(p)

def test_abacus(self):
data_path = Path(__file__).parent / "data.abacus"
fp_config = {
"inputs": FpOpAbacusInputs(
data_path / "INPUT", {"Na": data_path / "Na_ONCV_PBE-1.0.upf"}
),
"run": {
"command": "cp -r %s OUT.ABACUS && cat %s"
% (data_path / "OUT.ABACUS", data_path / "log"),
},
}
confs = [data_path / "sys-2"]
type_map = ["Na"]

dflow.config["mode"] = "debug"
prep_run_fp_op = PrepRunFp(
"prep-run-fp",
PrepFpOpAbacus,
RunFpOpAbacus,
)
prep_run_fp = Step(
name="prep-run-fp",
template=prep_run_fp_op,
parameters={
"block_id": "iter-000000",
"fp_config": fp_config,
"type_map": type_map,
},
artifacts={
"confs": upload_artifact(confs),
},
key="iter-000000--prep-run-fp",
)
wf = Workflow(name="abacus-dpgen")
wf.add(prep_run_fp)
wf.submit()
self.assertEqual(wf.query_status(), "Succeeded")

step = wf.query_step(key="iter-000000--run-fp-000000")[0]
log = download_artifact(step.outputs.artifacts["log"], path="output")[0]
self.assertTrue(os.path.isfile(log))
labeled_data = download_artifact(
step.outputs.artifacts["labeled_data"], path="output"
)[0]
s = dpdata.LabeledSystem(labeled_data, fmt="deepmd/npy")
self.assertEqual(len(s), 1)

0 comments on commit 16f24d6

Please sign in to comment.