Skip to content

Commit 4bee6e2

Browse files
committed
Test: Add an integrate test 01_PW/103_PW_Gene_Descriptors for of_ml_gene_data
1 parent bb6a29b commit 4bee6e2

9 files changed

Lines changed: 171 additions & 5 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
INPUT_PARAMETERS
2+
#Parameters (1.General)
3+
suffix autotest
4+
calculation scf
5+
nbands 3
6+
symmetry 1
7+
pseudo_dir ../../PP_ORB
8+
pseudo_rcut 16
9+
10+
#Parameters (2.Iteration)
11+
ecutwfc 10
12+
scf_nmax 100
13+
dft_functional XC_GGA_X_PBE+XC_GGA_C_PBE
14+
15+
16+
#Parameters (3.Basis)
17+
basis_type pw
18+
19+
#Parameters (4.Smearing)
20+
smearing_method gauss
21+
smearing_sigma 0.0002
22+
23+
#Parameters (5.Mixing)
24+
mixing_type broyden
25+
device cpu
26+
27+
#Parameters (6.Gene Data)
28+
of_full_pw 1
29+
of_full_pw_dim 1
30+
31+
of_ml_gene_data 1
32+
33+
of_ml_nkernel 2
34+
of_ml_kernel 1 1
35+
of_ml_kernel_scaling 1.5 1
36+
of_ml_chi_p 0.2
37+
of_ml_chi_q 0.1
38+
of_ml_chi_pnl 0.2 0.2
39+
of_ml_chi_qnl 0.1 0.1
40+
of_ml_chi_xi 0.8 1
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
K_POINTS
2+
0
3+
Gamma
4+
20 20 20 0 0 0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Tests the correctness of ML functional descriptors generated by PW KSDFT; this case supports single-rank only.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
ATOMIC_SPECIES
2+
Al 13 al.gga.psp blps
3+
4+
LATTICE_CONSTANT
5+
7.6513590200098225 // add lattice constant
6+
7+
LATTICE_VECTORS
8+
0.000000000000 0.500000000000 0.500000000000
9+
0.500000000000 0.000000000000 0.500000000000
10+
0.500000000000 0.500000000000 0.000000000000
11+
12+
ATOMIC_POSITIONS
13+
Direct
14+
15+
Al
16+
0.0
17+
1
18+
0.000000000000 0.000000000000 0.000000000000 1 1 1
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
etotref -57.04829815855825
2+
etotperatomref -57.0482981586
3+
ml_desc_mean_enhancement_npy 1.111419127928
4+
ml_desc_mean_gamma_npy 0.995847307666
5+
ml_desc_mean_gammanl_1_1_5_npy 0.077138936619
6+
ml_desc_mean_gammanl_1_1_npy 0.083331919287
7+
ml_desc_mean_nablaRhox_npy 0.003714583460
8+
ml_desc_mean_nablaRhoy_npy 0.003714583460
9+
ml_desc_mean_nablaRhoz_npy 0.003714583460
10+
ml_desc_mean_p_npy 0.095710030124
11+
ml_desc_mean_pauli_npy 0.875124481343
12+
ml_desc_mean_pnl_1_1_5_npy 0.230824971750
13+
ml_desc_mean_pnl_1_1_npy 0.224100011030
14+
ml_desc_mean_q_npy 0.310335060112
15+
ml_desc_mean_qnl_1_1_5_npy 0.598582089727
16+
ml_desc_mean_qnl_1_1_npy 0.660815190079
17+
ml_desc_mean_rho_npy 0.026789555290
18+
ml_desc_mean_tanh_pnl_1_1_5_npy 0.044695787317
19+
ml_desc_mean_tanh_pnl_1_1_npy 0.043383873620
20+
ml_desc_mean_tanh_qnl_1_1_5_npy 0.053898994944
21+
ml_desc_mean_tanh_qnl_1_1_npy 0.059951993401
22+
ml_desc_mean_tanhp_npy 0.018740571716
23+
ml_desc_mean_tanhp_nl_1_1_5_npy 0.044938608030
24+
ml_desc_mean_tanhp_nl_1_1_npy 0.043643966443
25+
ml_desc_mean_tanhq_npy 0.028985866312
26+
ml_desc_mean_tanhq_nl_1_1_5_npy 0.054446092813
27+
ml_desc_mean_tanhq_nl_1_1_npy 0.060077197039
28+
ml_desc_mean_tanhxi_1_1_5_npy 0.065230231297
29+
ml_desc_mean_tanhxi_1_1_npy 0.086762840891
30+
ml_desc_mean_tanhxi_nl_1_1_5_npy 0.113754807936
31+
ml_desc_mean_tanhxi_nl_1_1_npy 0.163063987051
32+
ml_desc_mean_veff_npy 0.431187756019
33+
ml_desc_mean_xi_1_1_5_npy 0.083625451851
34+
ml_desc_mean_xi_1_1_npy 0.090202449809
35+
pointgroupref O_h
36+
spacegroupref O_h
37+
nksibzref 256
38+
totaltimeref 1.46

tests/01_PW/CASES_CPU.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ scf_out_chg_tau
103103
100_PW_W90
104104
101_PW_MD_1O
105105
102_PW_MD_2O
106+
103_PW_Gene_Descriptors
106107
201_PW_UPF201_Ce_f
107108
202_PW_ONCV_Libxc
108109
204_PW_SY

tests/integrate/Autotest.sh

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ nt=$OMP_NUM_THREADS # number of OpenMP threads, default is $OMP_NUM_THREADS
99
threshold=0.0000001
1010
force_threshold=0.0001
1111
stress_threshold=0.001
12+
# descriptor mean threshold
13+
descriptor_threshold=0.00001
1214
# check accuracy
1315
ca=8
1416
# specify the test cases file
@@ -55,6 +57,7 @@ echo "Number of threads: $nt"
5557
echo "Test accuracy totenergy: $threshold eV"
5658
echo "Test accuracy force: $force_threshold"
5759
echo "Test accuracy stress: $stress_threshold"
60+
echo "Test accuracy descriptor mean: $descriptor_threshold"
5861
echo "Check accuaracy: $ca"
5962
echo "Test cases file: $cases_file"
6063
echo "Test cases regex: $case"
@@ -84,6 +87,7 @@ check_out(){
8487
force_thr=$3
8588
stress_thr=$4
8689
fatal_thr=$5
90+
descriptor_thr=$6
8791

8892
#------------------------------------------------------
8993
# outfile = result.out
@@ -139,7 +143,11 @@ check_out(){
139143
fatal_case_list+=$dir'\n'
140144
break
141145
else
142-
if [ $(check_deviation_pass $deviation $thr) = 0 ]; then
146+
compare_thr=$thr
147+
if [[ $key == ml_desc_mean_* ]]; then
148+
compare_thr=$descriptor_thr
149+
fi
150+
if [ $(check_deviation_pass $deviation $compare_thr) = 0 ]; then
143151
if [ $key == "totalforceref" ]; then
144152
if [ $(check_deviation_pass $deviation $force_thr) = 0 ]; then
145153
echo -e "[WARNING ] "\
@@ -251,11 +259,15 @@ for dir in $testdir; do
251259
TIMEFORMAT='[----------] Time elapsed: %R seconds'
252260
#parallel test
253261
time {
262+
run_np=$np
254263
if [ "$case" = "282_NO_RPA" ]; then
255-
mpirun -np 1 $abacus > log.txt
256-
else
257-
mpirun -np $np $abacus > log.txt
264+
run_np=1
265+
fi
266+
if grep -qE '^[[:space:]]*of_ml_gene_data[[:space:]]+1([[:space:]]|$)' INPUT; then
267+
# of_ml_gene_data supports single-rank only.
268+
run_np=1
258269
fi
270+
mpirun -np $run_np $abacus > log.txt
259271

260272
# if ABACUS failed, print out the error message
261273
if [ $? -ne 0 ]; then
@@ -279,7 +291,7 @@ for dir in $testdir; do
279291
my_force_threshold=$(get_threshold $threshold_file "force_threshold" $force_threshold)
280292
my_stress_threshold=$(get_threshold $threshold_file "stress_threshold" $stress_threshold)
281293
my_fatal_threshold=$(get_threshold $threshold_file "fatal_threshold" $fatal_threshold)
282-
check_out result.out $my_threshold $my_force_threshold $my_stress_threshold $my_fatal_threshold
294+
check_out result.out $my_threshold $my_force_threshold $my_stress_threshold $my_fatal_threshold $descriptor_threshold
283295
fi
284296
else
285297
bash -e ../../integrate/tools/catch_properties.sh result.ref

tests/integrate/tools/catch_properties.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
COMPARE_SCRIPT="../../integrate/tools/CompareFile.py"
66
#COMPARE_SCRIPT="../../integrate/tools/compare_file.py"
77
SUM_CUBE_EXE="python3 ../../integrate/tools/sum_cube.py"
8+
COLLECT_NPY_MEANS="../../integrate/tools/collect_npy_means.py"
89

910

1011
sum_file(){
@@ -646,6 +647,14 @@ if [ "$need_process_cube" = true ]; then
646647
fi
647648
fi
648649

650+
#--------------------------------------------
651+
# ML gene data descriptors (.npy)
652+
#--------------------------------------------
653+
descriptor_dir="OUT.autotest/MLKEDF_Descriptors"
654+
if [ -d "$descriptor_dir" ]; then
655+
python3 $COLLECT_NPY_MEANS "$descriptor_dir" >> "$1"
656+
fi
657+
649658
#--------------------------------------------
650659
# implicit solvation model
651660
#--------------------------------------------
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python3
2+
import argparse
3+
import os
4+
import re
5+
import sys
6+
7+
import numpy as np
8+
9+
10+
def sanitize_name(name):
11+
return re.sub(r"[^A-Za-z0-9_]", "_", name)
12+
13+
14+
def main():
15+
parser = argparse.ArgumentParser()
16+
parser.add_argument("descriptor_dir")
17+
args = parser.parse_args()
18+
19+
descriptor_dir = args.descriptor_dir
20+
if not os.path.isdir(descriptor_dir):
21+
print(f"Descriptor dir not found: {descriptor_dir}", file=sys.stderr)
22+
return 1
23+
24+
files = sorted(f for f in os.listdir(descriptor_dir) if f.endswith(".npy"))
25+
if not files:
26+
print(f"No .npy files in: {descriptor_dir}", file=sys.stderr)
27+
return 1
28+
29+
for filename in files:
30+
path = os.path.join(descriptor_dir, filename)
31+
data = np.load(path, allow_pickle=False)
32+
if data.size == 0:
33+
mean_value = 0.0
34+
else:
35+
mean_value = float(np.mean(np.abs(data)))
36+
key = f"ml_desc_mean_{sanitize_name(filename)}"
37+
print(f"{key} {mean_value:.12f}")
38+
39+
return 0
40+
41+
42+
if __name__ == "__main__":
43+
raise SystemExit(main())

0 commit comments

Comments
 (0)