From a7bd9ccb45efdbbdb737f1d5935efba86d25eb9d Mon Sep 17 00:00:00 2001 From: Zhuxuegang2022 Date: Sun, 22 Oct 2023 23:17:29 +0800 Subject: [PATCH 1/6] In integrate test add force threshold of 0.0001 and stress threhold of 0.001 to made less warning output --- tests/integrate/Autotest.sh | 50 +++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/tests/integrate/Autotest.sh b/tests/integrate/Autotest.sh index edb99a316c..268cd1e5de 100755 --- a/tests/integrate/Autotest.sh +++ b/tests/integrate/Autotest.sh @@ -6,6 +6,8 @@ abacus=abacus np=4 # threshold with unit: eV threshold=0.0000001 +force_threshold=0.0001 +stress_threshold=0.001 # check accuracy ca=8 # regex of case name @@ -15,29 +17,31 @@ sanitize=false while getopts a:n:t:c:s:r:g flag do - case "${flag}" in - a) abacus=${OPTARG};; - n) np=${OPTARG};; + case "${flag}" in + a) abacus=${OPTARG};; + n) np=${OPTARG};; t) threshold=${OPTARG};; c) ca=${OPTARG};; s) sanitize=${OPTARG};; r) case=${OPTARG};; g) g=true;; #generate test reference - esac + esac done # number of OpenMP threads nt=$OMP_NUM_THREADS if [[ -z "$nt" ]]; then - nt=$(expr `nproc` / ${np}) - export OMP_NUM_THREADS=${nt} + nt=$(expr `nproc` / ${np}) + export OMP_NUM_THREADS=${nt} fi echo "-----AUTO TESTS OF ABACUS ------" echo "ABACUS path: $abacus" echo "Number of processes: $np" echo "Number of threads: $nt" -echo "Test accuracy: $threshold eV" +echo "Test accuracy totenergy: $threshold eV" +echo "Test accuracy force: $force_threshold" +echo "Test accuracy stress: $stress_threshold" echo "Check accuaracy: $ca" echo "Test cases: $case" echo "Generate reference: $g" @@ -63,7 +67,7 @@ check_out(){ #------------------------------------------------------ if test -e "jd"; then jd=`cat jd` - echo "[----------] $jd" + echo "[----------] $jd" fi #------------------------------------------------------ @@ -100,16 +104,30 @@ check_out(){ # deviation should be positively defined #-------------------------------------------------- if [ ! -n "$deviation" ]; then - echo -e "\e[0;31m[ERROR ] Fatal Error: key $key not found in output.\e[0m" + echo -e "\e[0;31m[ERROR ] Fatal Error: key $key not found in output.\e[0m" let fatal++ fatal_case_list+=$dir'\n' break - else + else if [ $(echo "sqrt($deviation*$deviation) < $threshold"|bc) = 0 ]; then + if [ $key == "totalforceref" -o $key == "totalstressref"]; then + if [ $key == "totalforceref" && $(echo "sqrt($deviation*$deviation) < $force_threshold"|bc) = 0 ];then + echo -e "[WARNING ] "\ + "$key cal=$cal ref=$ref deviation=$deviation" + let failed++ + failed_case_list+=$dir'\n' + elif [ $key == "totalstressref" && $(echo "sqrt($deviation*$deviation) < $stress_threshold"|bc) = 0 ];then + echo -e "[WARNING ] "\ + "$key cal=$cal ref=$ref deviation=$deviation" + let failed++ + failed_case_list+=$dir'\n' + fi + else echo -e "[WARNING ] "\ "$key cal=$cal ref=$ref deviation=$deviation" let failed++ failed_case_list+=$dir'\n' + fi if [ $(echo "sqrt($deviation*$deviation) < $fatal_threshold"|bc) = 0 ]; then let fatal++ fatal_case_list+=$dir @@ -152,7 +170,7 @@ if [ "$sanitize" == true ]; then mkdir ../html echo -e "# Address Sanitizer Diagnostics\n" > ../html/README.md report=$(realpath ../html/README.md) - export ASAN_OPTIONS="log_path=asan" + export ASAN_OPTIONS="log_path=asan" fi for dir in $testdir; do @@ -161,11 +179,11 @@ for dir in $testdir; do TIMEFORMAT='[----------] Time elapsed: %R seconds' #parallel test time { - if [ "$case" = "282_NO_RPA" -o "$dir" = "102_PW_BPCG" ]; then - mpirun -np 1 $abacus > log.txt - else - mpirun -np $np $abacus > log.txt - fi + if [ "$case" = "282_NO_RPA" -o "$dir" = "102_PW_BPCG" ]; then + mpirun -np 1 $abacus > log.txt + else + mpirun -np $np $abacus > log.txt + fi if [ "$sanitize" == true ]; then echo -e "## Test case ${dir}\n" >> ${report} From 3536e466f0ae6d6edf556a68a1ee51255720f5bd Mon Sep 17 00:00:00 2001 From: Zhuxuegang2022 Date: Mon, 23 Oct 2023 10:39:27 +0800 Subject: [PATCH 2/6] just add space before ' ]' --- tests/integrate/Autotest.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integrate/Autotest.sh b/tests/integrate/Autotest.sh index 268cd1e5de..cb48e6d632 100755 --- a/tests/integrate/Autotest.sh +++ b/tests/integrate/Autotest.sh @@ -110,7 +110,7 @@ check_out(){ break else if [ $(echo "sqrt($deviation*$deviation) < $threshold"|bc) = 0 ]; then - if [ $key == "totalforceref" -o $key == "totalstressref"]; then + if [ $key == "totalforceref" -o $key == "totalstressref" ]; then if [ $key == "totalforceref" && $(echo "sqrt($deviation*$deviation) < $force_threshold"|bc) = 0 ];then echo -e "[WARNING ] "\ "$key cal=$cal ref=$ref deviation=$deviation" From 6ab6b99ac5a597bd44d77a75eb6cb901024ddfe0 Mon Sep 17 00:00:00 2001 From: Zhuxuegang2022 Date: Mon, 23 Oct 2023 10:45:24 +0800 Subject: [PATCH 3/6] add some tab to make the bash script align --- tests/integrate/Autotest.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/integrate/Autotest.sh b/tests/integrate/Autotest.sh index cb48e6d632..33e05102f8 100755 --- a/tests/integrate/Autotest.sh +++ b/tests/integrate/Autotest.sh @@ -123,10 +123,10 @@ check_out(){ failed_case_list+=$dir'\n' fi else - echo -e "[WARNING ] "\ - "$key cal=$cal ref=$ref deviation=$deviation" - let failed++ - failed_case_list+=$dir'\n' + echo -e "[WARNING ] "\ + "$key cal=$cal ref=$ref deviation=$deviation" + let failed++ + failed_case_list+=$dir'\n' fi if [ $(echo "sqrt($deviation*$deviation) < $fatal_threshold"|bc) = 0 ]; then let fatal++ From f939e52d7af87b138d1b3e0a29be3eec6544d938 Mon Sep 17 00:00:00 2001 From: Zhuxuegang2022 Date: Mon, 23 Oct 2023 10:57:28 +0800 Subject: [PATCH 4/6] delet unnecessary 'if ' with 'if...elif...else' is already work --- tests/integrate/Autotest.sh | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/tests/integrate/Autotest.sh b/tests/integrate/Autotest.sh index 33e05102f8..8916852849 100755 --- a/tests/integrate/Autotest.sh +++ b/tests/integrate/Autotest.sh @@ -110,18 +110,16 @@ check_out(){ break else if [ $(echo "sqrt($deviation*$deviation) < $threshold"|bc) = 0 ]; then - if [ $key == "totalforceref" -o $key == "totalstressref" ]; then - if [ $key == "totalforceref" && $(echo "sqrt($deviation*$deviation) < $force_threshold"|bc) = 0 ];then - echo -e "[WARNING ] "\ - "$key cal=$cal ref=$ref deviation=$deviation" - let failed++ - failed_case_list+=$dir'\n' - elif [ $key == "totalstressref" && $(echo "sqrt($deviation*$deviation) < $stress_threshold"|bc) = 0 ];then - echo -e "[WARNING ] "\ - "$key cal=$cal ref=$ref deviation=$deviation" - let failed++ - failed_case_list+=$dir'\n' - fi + if [ $key == "totalforceref" && $(echo "sqrt($deviation*$deviation) < $force_threshold"|bc) = 0 ];then + echo -e "[WARNING ] "\ + "$key cal=$cal ref=$ref deviation=$deviation" + let failed++ + failed_case_list+=$dir'\n' + elif [ $key == "totalstressref" && $(echo "sqrt($deviation*$deviation) < $stress_threshold"|bc) = 0 ];then + echo -e "[WARNING ] "\ + "$key cal=$cal ref=$ref deviation=$deviation" + let failed++ + failed_case_list+=$dir'\n' else echo -e "[WARNING ] "\ "$key cal=$cal ref=$ref deviation=$deviation" From cfd208252511e1d7f5bdf1503753fec2978600f6 Mon Sep 17 00:00:00 2001 From: Zhuxuegang2022 Date: Mon, 23 Oct 2023 19:11:28 +0800 Subject: [PATCH 5/6] Change tab to space in the 'Autotest.sh' --- tests/integrate/Autotest.sh | 322 ++++++++++++++++++------------------ 1 file changed, 161 insertions(+), 161 deletions(-) diff --git a/tests/integrate/Autotest.sh b/tests/integrate/Autotest.sh index 8916852849..07d8180fb6 100755 --- a/tests/integrate/Autotest.sh +++ b/tests/integrate/Autotest.sh @@ -17,22 +17,22 @@ sanitize=false while getopts a:n:t:c:s:r:g flag do - case "${flag}" in - a) abacus=${OPTARG};; - n) np=${OPTARG};; - t) threshold=${OPTARG};; - c) ca=${OPTARG};; - s) sanitize=${OPTARG};; - r) case=${OPTARG};; - g) g=true;; #generate test reference - esac + case "${flag}" in + a) abacus=${OPTARG};; + n) np=${OPTARG};; + t) threshold=${OPTARG};; + c) ca=${OPTARG};; + s) sanitize=${OPTARG};; + r) case=${OPTARG};; + g) g=true;; #generate test reference + esac done # number of OpenMP threads nt=$OMP_NUM_THREADS if [[ -z "$nt" ]]; then - nt=$(expr `nproc` / ${np}) - export OMP_NUM_THREADS=${nt} + nt=$(expr `nproc` / ${np}) + export OMP_NUM_THREADS=${nt} fi echo "-----AUTO TESTS OF ABACUS ------" @@ -52,98 +52,98 @@ echo "" # define a function named 'check_out' #---------------------------------------------------------- check_out(){ - #------------------------------------------------------ - # input file $1 is 'result.out' in each test directory - #------------------------------------------------------ - outfile=$1 - - #------------------------------------------------------ - # outfile = result.out - #------------------------------------------------------ - properties=`awk '{print $1}' $outfile` - - #------------------------------------------------------ - # jd = job description - #------------------------------------------------------ - if test -e "jd"; then - jd=`cat jd` - echo "[----------] $jd" - fi - - #------------------------------------------------------ - # check every 'key' word - #------------------------------------------------------ - for key in $properties; do - - #-------------------------------------------------- - # calculated value - #-------------------------------------------------- - cal=`grep "$key" result.out | awk '{printf "%.'$ca'f\n",$2}'` - - #-------------------------------------------------- - # reference value - #-------------------------------------------------- - ref=`grep "$key" result.ref | awk '{printf "%.'$ca'f\n",$2}'` - - #-------------------------------------------------- - # computed the deviation between the calculated - # and reference value - #-------------------------------------------------- - deviation=`awk 'BEGIN {x='$ref';y='$cal';printf "%.'$ca'f\n",x-y}'` - - if [ $key == "totaltimeref" ]; then - # echo "time=$cal ref=$ref" - break - fi - - - #-------------------------------------------------- - # If deviation < threshold, then the test passes, - # otherwise, the test prints out warning - # Daye Zheng found bug on 2021-06-20, - # deviation should be positively defined - #-------------------------------------------------- - if [ ! -n "$deviation" ]; then - echo -e "\e[0;31m[ERROR ] Fatal Error: key $key not found in output.\e[0m" - let fatal++ - fatal_case_list+=$dir'\n' - break - else - if [ $(echo "sqrt($deviation*$deviation) < $threshold"|bc) = 0 ]; then - if [ $key == "totalforceref" && $(echo "sqrt($deviation*$deviation) < $force_threshold"|bc) = 0 ];then - echo -e "[WARNING ] "\ - "$key cal=$cal ref=$ref deviation=$deviation" - let failed++ - failed_case_list+=$dir'\n' - elif [ $key == "totalstressref" && $(echo "sqrt($deviation*$deviation) < $stress_threshold"|bc) = 0 ];then - echo -e "[WARNING ] "\ - "$key cal=$cal ref=$ref deviation=$deviation" - let failed++ - failed_case_list+=$dir'\n' - else - echo -e "[WARNING ] "\ - "$key cal=$cal ref=$ref deviation=$deviation" - let failed++ - failed_case_list+=$dir'\n' - fi - if [ $(echo "sqrt($deviation*$deviation) < $fatal_threshold"|bc) = 0 ]; then - let fatal++ - fatal_case_list+=$dir - echo -e "\e[0;31m[ERROR ] \e[0m"\ - "An unacceptable deviation occurs." - calculation=`grep calculation INPUT | awk '{print $2}' | sed s/[[:space:]]//g` - running_path=`echo "OUT.autotest/running_$calculation"".log"` - cat $running_path - fi - break - else - #echo "$key cal=$cal ref=$ref deviation=$deviation" - #echo "[ PASS ] $key" - echo -e "\e[0;32m[ OK ] \e[0m $key" - fi - fi - let ok++ - done + #------------------------------------------------------ + # input file $1 is 'result.out' in each test directory + #------------------------------------------------------ + outfile=$1 + + #------------------------------------------------------ + # outfile = result.out + #------------------------------------------------------ + properties=`awk '{print $1}' $outfile` + + #------------------------------------------------------ + # jd = job description + #------------------------------------------------------ + if test -e "jd"; then + jd=`cat jd` + echo "[----------] $jd" + fi + + #------------------------------------------------------ + # check every 'key' word + #------------------------------------------------------ + for key in $properties; do + + #-------------------------------------------------- + # calculated value + #-------------------------------------------------- + cal=`grep "$key" result.out | awk '{printf "%.'$ca'f\n",$2}'` + + #-------------------------------------------------- + # reference value + #-------------------------------------------------- + ref=`grep "$key" result.ref | awk '{printf "%.'$ca'f\n",$2}'` + + #-------------------------------------------------- + # computed the deviation between the calculated + # and reference value + #-------------------------------------------------- + deviation=`awk 'BEGIN {x='$ref';y='$cal';printf "%.'$ca'f\n",x-y}'` + + if [ $key == "totaltimeref" ]; then + # echo "time=$cal ref=$ref" + break + fi + + + #-------------------------------------------------- + # If deviation < threshold, then the test passes, + # otherwise, the test prints out warning + # Daye Zheng found bug on 2021-06-20, + # deviation should be positively defined + #-------------------------------------------------- + if [ ! -n "$deviation" ]; then + echo -e "\e[0;31m[ERROR ] Fatal Error: key $key not found in output.\e[0m" + let fatal++ + fatal_case_list+=$dir'\n' + break + else + if [ $(echo "sqrt($deviation*$deviation) < $threshold"|bc) = 0 ]; then + if [ $key == "totalforceref" && $(echo "sqrt($deviation*$deviation) < $force_threshold"|bc) = 0 ]; then + echo -e "[WARNING ] "\ + "$key cal=$cal ref=$ref deviation=$deviation" + let failed++ + failed_case_list+=$dir'\n' + elif [ $key == "totalstressref" && $(echo "sqrt($deviation*$deviation) < $stress_threshold"|bc) = 0 ]; then + echo -e "[WARNING ] "\ + "$key cal=$cal ref=$ref deviation=$deviation" + let failed++ + failed_case_list+=$dir'\n' + else + echo -e "[WARNING ] "\ + "$key cal=$cal ref=$ref deviation=$deviation" + let failed++ + failed_case_list+=$dir'\n' + fi + if [ $(echo "sqrt($deviation*$deviation) < $fatal_threshold"|bc) = 0 ]; then + let fatal++ + fatal_case_list+=$dir + echo -e "\e[0;31m[ERROR ] \e[0m"\ + "An unacceptable deviation occurs." + calculation=`grep calculation INPUT | awk '{print $2}' | sed s/[[:space:]]//g` + running_path=`echo "OUT.autotest/running_$calculation"".log"` + cat $running_path + fi + break + else + #echo "$key cal=$cal ref=$ref deviation=$deviation" + #echo "[ PASS ] $key" + echo -e "\e[0;32m[ OK ] \e[0m $key" + fi + fi + let ok++ + done } #--------------------------------------------- @@ -164,77 +164,77 @@ report="" repo="$(realpath ..)/" if [ "$sanitize" == true ]; then - echo "Testing with Address Sanitizer..." - mkdir ../html - echo -e "# Address Sanitizer Diagnostics\n" > ../html/README.md - report=$(realpath ../html/README.md) - export ASAN_OPTIONS="log_path=asan" + echo "Testing with Address Sanitizer..." + mkdir ../html + echo -e "# Address Sanitizer Diagnostics\n" > ../html/README.md + report=$(realpath ../html/README.md) + export ASAN_OPTIONS="log_path=asan" fi for dir in $testdir; do - cd $dir - echo -e "\e[0;32m[ RUN ]\e[0m $dir" - TIMEFORMAT='[----------] Time elapsed: %R seconds' - #parallel test - time { - if [ "$case" = "282_NO_RPA" -o "$dir" = "102_PW_BPCG" ]; then - mpirun -np 1 $abacus > log.txt - else - mpirun -np $np $abacus > log.txt - fi - - if [ "$sanitize" == true ]; then - echo -e "## Test case ${dir}\n" >> ${report} - for diagnostic in asan.*; do - echo -e "### On process id ${diagnostic}\n" >> ${report} - echo -e "\`\`\`bash" >> ${report} - cat ${diagnostic} >> ${report} - echo -e "\`\`\`\n" >> ${report} - done - fi - #$abacus > log.txt - test -d OUT.autotest || (echo "No 'OUT.autotest' dir presented. Some errors may happened in ABACUS." && exit 1) - if test -z $g - then - ../tools/catch_properties.sh result.out - if [ $? == 1 ]; then - echo -e "\e[0;31m [ERROR ] Fatal Error in catch_properties.sh \e[0m" - let fatal++ - fatal_case_list+=$dir'\n' - break - else - check_out result.out - fi - else - ../tools/catch_properties.sh result.ref - fi - } - echo "" - cd ../ + cd $dir + echo -e "\e[0;32m[ RUN ]\e[0m $dir" + TIMEFORMAT='[----------] Time elapsed: %R seconds' + #parallel test + time { + if [ "$case" = "282_NO_RPA" -o "$dir" = "102_PW_BPCG" ]; then + mpirun -np 1 $abacus > log.txt + else + mpirun -np $np $abacus > log.txt + fi + + if [ "$sanitize" == true ]; then + echo -e "## Test case ${dir}\n" >> ${report} + for diagnostic in asan.*; do + echo -e "### On process id ${diagnostic}\n" >> ${report} + echo -e "\`\`\`bash" >> ${report} + cat ${diagnostic} >> ${report} + echo -e "\`\`\`\n" >> ${report} + done + fi + #$abacus > log.txt + test -d OUT.autotest || (echo "No 'OUT.autotest' dir presented. Some errors may happened in ABACUS." && exit 1) + if test -z $g + then + ../tools/catch_properties.sh result.out + if [ $? == 1 ]; then + echo -e "\e[0;31m [ERROR ] Fatal Error in catch_properties.sh \e[0m" + let fatal++ + fatal_case_list+=$dir'\n' + break + else + check_out result.out + fi + else + ../tools/catch_properties.sh result.ref + fi + } + echo "" + cd ../ done if [ "$sanitize" == true ]; then - if [[ `uname` == "Darwin" ]]; then - sed -i '' "s,${repo},,g" ${report} - else - sed -i "s,${repo},,g" ${report} - fi + if [[ `uname` == "Darwin" ]]; then + sed -i '' "s,${repo},,g" ${report} + else + sed -i "s,${repo},,g" ${report} + fi fi if [ -z $g ] then if [ $failed -eq 0 ] then - echo -e "\e[0;32m[ PASSED ] \e[0m $ok test cases passed." + echo -e "\e[0;32m[ PASSED ] \e[0m $ok test cases passed." else - echo -e "[WARNING]\e[0m $failed test cases out of $[ $failed + $ok ] failed." - echo -e $failed_case_list - if [ $fatal -gt 0 ] - then - echo -e "\e[0;31m[ERROR ]\e[0m $fatal test cases out of $[ $failed + $ok ] produced fatal error." - echo -e $fatal_case_list - exit 1 - fi + echo -e "[WARNING]\e[0m $failed test cases out of $[ $failed + $ok ] failed." + echo -e $failed_case_list + if [ $fatal -gt 0 ] + then + echo -e "\e[0;31m[ERROR ]\e[0m $fatal test cases out of $[ $failed + $ok ] produced fatal error." + echo -e $fatal_case_list + exit 1 + fi fi else echo "Generate test cases complete." From ac16c4bff04f24e85f70c111c8431c0543b7ff59 Mon Sep 17 00:00:00 2001 From: Zhuxuegang2022 Date: Tue, 24 Oct 2023 12:39:27 +0800 Subject: [PATCH 6/6] using correct formation of ash --- tests/integrate/Autotest.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integrate/Autotest.sh b/tests/integrate/Autotest.sh index 07d8180fb6..314c6a7e8c 100755 --- a/tests/integrate/Autotest.sh +++ b/tests/integrate/Autotest.sh @@ -110,12 +110,12 @@ check_out(){ break else if [ $(echo "sqrt($deviation*$deviation) < $threshold"|bc) = 0 ]; then - if [ $key == "totalforceref" && $(echo "sqrt($deviation*$deviation) < $force_threshold"|bc) = 0 ]; then + if [[ $key == "totalforceref" && $(echo "sqrt($deviation*$deviation) < $force_threshold"|bc) = 0 ]]; then echo -e "[WARNING ] "\ "$key cal=$cal ref=$ref deviation=$deviation" let failed++ failed_case_list+=$dir'\n' - elif [ $key == "totalstressref" && $(echo "sqrt($deviation*$deviation) < $stress_threshold"|bc) = 0 ]; then + elif [[ $key == "totalstressref" && $(echo "sqrt($deviation*$deviation) < $stress_threshold"|bc) = 0 ]]; then echo -e "[WARNING ] "\ "$key cal=$cal ref=$ref deviation=$deviation" let failed++