diff --git a/tests/09_DeePKS/clean.sh b/tests/09_DeePKS/clean.sh index 0524c2e6009..a148628da04 100755 --- a/tests/09_DeePKS/clean.sh +++ b/tests/09_DeePKS/clean.sh @@ -2,37 +2,37 @@ for module in "_PW_" "_NO_" "_NP_"; do -echo $module + echo $module -for directory in `ls | grep $module`; do + for directory in $(ls | grep $module); do - #-------------------------------------------- - # delete log.txt (if it exists) - #-------------------------------------------- - log_file="$directory/log.txt" - #test -e "$log_file" && echo $log_file - test -e "$log_file" && rm $log_file + #-------------------------------------------- + # delete log.txt (if it exists) + #-------------------------------------------- + log_file="$directory/log.txt" + #test -e "$log_file" && echo $log_file + test -e "$log_file" && rm $log_file - #-------------------------------------------- - # delete result.out (if it exists) - #-------------------------------------------- - result_file="$directory/result.out" - #test -e "$result_file" && echo $result_file - test -e "$result_file" && rm $result_file + #-------------------------------------------- + # delete result.out (if it exists) + #-------------------------------------------- + result_file="$directory/result.out" + #test -e "$result_file" && echo $result_file + test -e "$result_file" && rm $result_file - #-------------------------------------------- - # delete OUT.autotest (if it exists) - #-------------------------------------------- - OUT_directory="$directory/OUT.autotest" - test -e "$OUT_directory" && rm -rf $OUT_directory + #-------------------------------------------- + # delete OUT.autotest (if it exists) + #-------------------------------------------- + OUT_directory="$directory/OUT.autotest" + test -e "$OUT_directory" && rm -rf $OUT_directory - #-------------------------------------------- - # delete projected_DM.dat (if it exists) #-------------------------------------------- - projected_DM="$directory/projected_DM.dat" - test -e "$projected_DM" && rm -rf $projected_DM + # delete projected_DM.dat (if it exists) + #-------------------------------------------- + projected_DM="$directory/projected_DM.dat" + test -e "$projected_DM" && rm -rf $projected_DM -done + done done diff --git a/tests/17_DS_DFTU/run_scf_nscf.sh b/tests/17_DS_DFTU/run_scf_nscf.sh index 35bde1eec2a..e114b885cf4 100755 --- a/tests/17_DS_DFTU/run_scf_nscf.sh +++ b/tests/17_DS_DFTU/run_scf_nscf.sh @@ -47,20 +47,20 @@ echo "========================================" # Step 0: Check prerequisites # ------------------------------------------------------- if [ ! -f "${TEST_DIR}/INPUT" ]; then - echo "ERROR: INPUT file not found in ${TEST_DIR}" - exit 1 + echo "ERROR: INPUT file not found in ${TEST_DIR}" + exit 1 fi if [ ! -f "${TEST_DIR}/STRU" ]; then - echo "ERROR: STRU file not found in ${TEST_DIR}" - exit 1 + echo "ERROR: STRU file not found in ${TEST_DIR}" + exit 1 fi # Check if this is a DFT+U test (needs occ_mat.txt handling) IS_DFTU=false if grep -q "dft_plus_u" "${TEST_DIR}/INPUT" 2>/dev/null; then - IS_DFTU=true - echo "DFT+U test detected: will handle occ_mat.txt files" + IS_DFTU=true + echo "DFT+U test detected: will handle occ_mat.txt files" fi # ------------------------------------------------------- @@ -74,18 +74,18 @@ cp "${TEST_DIR}/STRU" "${SCF_DIR}/STRU" # Copy KPT to SCF directory (if exists) if [ -f "${TEST_DIR}/KPT" ]; then - cp "${TEST_DIR}/KPT" "${SCF_DIR}/KPT" + cp "${TEST_DIR}/KPT" "${SCF_DIR}/KPT" fi # Generate SCF INPUT from NSCF INPUT # Key changes: calculation=scf, init_chg=atomic, remove nscf-specific params SCF_INPUT="${SCF_DIR}/INPUT" cat "${TEST_DIR}/INPUT" | sed \ - -e 's/calculation\s*nscf/calculation scf/' \ - -e 's/init_chg\s*file/init_chg atomic/' \ - -e '/read_file_dir/d' \ - -e '/out_band/d' \ - > "${SCF_INPUT}" + -e 's/calculation\s*nscf/calculation scf/' \ + -e 's/init_chg\s*file/init_chg atomic/' \ + -e '/read_file_dir/d' \ + -e '/out_band/d' \ + >"${SCF_INPUT}" echo "" echo "--- SCF INPUT ---" @@ -98,11 +98,11 @@ echo "-----------------" echo "" echo "[1/4] Running SCF calculation..." cd "${SCF_DIR}" -mpirun -np ${MPI_NP} "${ABACUS}" > scf.log 2>&1 || { - echo "ERROR: SCF calculation failed!" - echo "Check ${SCF_DIR}/scf.log for details" - cd "${TEST_DIR}" - exit 1 +mpirun -np ${MPI_NP} "${ABACUS}" >scf.log 2>&1 || { + echo "ERROR: SCF calculation failed!" + echo "Check ${SCF_DIR}/scf.log for details" + cd "${TEST_DIR}" + exit 1 } cd "${TEST_DIR}" @@ -123,8 +123,8 @@ NSCF_SUFFIX=${NSCF_SUFFIX:-OUT} # Find charge density file (pattern: *-CHARGE-DENSITY.restart or *-CHARGE-DENSITY) CHG_FILE=$(find "${SCF_OUT}" -name "*CHARGE-DENSITY*" 2>/dev/null | head -1) if [ -z "${CHG_FILE}" ]; then - echo "ERROR: No charge density file found in ${SCF_OUT}" - exit 1 + echo "ERROR: No charge density file found in ${SCF_OUT}" + exit 1 fi CHG_BASENAME=$(basename "${CHG_FILE}") @@ -138,23 +138,23 @@ echo " Copied to: ${TEST_DIR}/${NSCF_CHG_FILE}" # For DFT+U tests, also copy occ_mat.txt if it exists. # occ_mat.txt is read from read_file_dir (global_readin_dir), same as charge density if [ "${IS_DFTU}" = true ]; then - ONSITE_FILE=$(find "${SCF_OUT}" -name "occ_mat.txt" 2>/dev/null | head -1) - if [ -n "${ONSITE_FILE}" ]; then - cp "${ONSITE_FILE}" "${TEST_DIR}/occ_mat.txt" - echo " Copied occ_mat.txt to: ${TEST_DIR}/occ_mat.txt" - else - echo " WARNING: occ_mat.txt not found in SCF output" - fi + ONSITE_FILE=$(find "${SCF_OUT}" -name "occ_mat.txt" 2>/dev/null | head -1) + if [ -n "${ONSITE_FILE}" ]; then + cp "${ONSITE_FILE}" "${TEST_DIR}/occ_mat.txt" + echo " Copied occ_mat.txt to: ${TEST_DIR}/occ_mat.txt" + else + echo " WARNING: occ_mat.txt not found in SCF output" + fi fi # ------------------------------------------------------- # Step 4: Run NSCF calculation # ------------------------------------------------------- echo "[3/4] Running NSCF calculation..." -mpirun -np ${MPI_NP} "${ABACUS}" > nscf.log 2>&1 || { - echo "ERROR: NSCF calculation failed!" - echo "Check ${TEST_DIR}/nscf.log for details" - exit 1 +mpirun -np ${MPI_NP} "${ABACUS}" >nscf.log 2>&1 || { + echo "ERROR: NSCF calculation failed!" + echo "Check ${TEST_DIR}/nscf.log for details" + exit 1 } # ------------------------------------------------------- @@ -166,8 +166,8 @@ NSF_OUT="${TEST_DIR}/${NSCF_SUFFIX}" # Check if output directory exists if [ ! -d "${NSF_OUT}" ]; then - echo "WARNING: Output directory ${NSF_OUT} not found" - exit 1 + echo "WARNING: Output directory ${NSF_OUT} not found" + exit 1 fi # Print summary @@ -181,25 +181,25 @@ echo "" # Print energy from SCF if [ -f "${SCF_OUT}/running_scf.log" ]; then - echo "SCF final energy:" - grep "!FINAL ENERGY" "${SCF_OUT}/running_scf.log" | tail -1 || echo " (not found)" + echo "SCF final energy:" + grep "!FINAL ENERGY" "${SCF_OUT}/running_scf.log" | tail -1 || echo " (not found)" fi # Print magnetic moments from NSCF if [ -f "${NSF_OUT}/running_scf.log" ] || [ -f "${NSF_OUT}/running_nscf.log" ]; then - echo "" - echo "NSCF magnetic moments:" - grep -A 1 "TOTAL MAGNETISM" "${NSF_OUT}/running_scf.log" 2>/dev/null | tail -3 || \ - grep -A 1 "TOTAL MAGNETISM" "${NSF_OUT}/running_nscf.log" 2>/dev/null | tail -3 || \ + echo "" + echo "NSCF magnetic moments:" + grep -A 1 "TOTAL MAGNETISM" "${NSF_OUT}/running_scf.log" 2>/dev/null | tail -3 || + grep -A 1 "TOTAL MAGNETISM" "${NSF_OUT}/running_nscf.log" 2>/dev/null | tail -3 || echo " (not found)" fi # Print lambda if DeltaSpin if grep -q "sc_mag_switch" "${TEST_DIR}/INPUT" 2>/dev/null; then - echo "" - echo "NSCF lambda values:" - grep "lambda" "${NSF_OUT}/running_scf.log" 2>/dev/null | tail -3 || \ - grep "lambda" "${NSF_OUT}/running_nscf.log" 2>/dev/null | tail -3 || \ + echo "" + echo "NSCF lambda values:" + grep "lambda" "${NSF_OUT}/running_scf.log" 2>/dev/null | tail -3 || + grep "lambda" "${NSF_OUT}/running_nscf.log" 2>/dev/null | tail -3 || echo " (not found)" fi diff --git a/tests/integrate/Autotest.sh b/tests/integrate/Autotest.sh index 950febe09ac..063f8f6ee90 100755 --- a/tests/integrate/Autotest.sh +++ b/tests/integrate/Autotest.sh @@ -13,7 +13,7 @@ abacus_exe_env=${ABACUS_EXE:-} abacus= abacus_local_info="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/general_info.local" if [ -f "$abacus_local_info" ]; then - . "$abacus_local_info" + . "$abacus_local_info" fi # ABACUS executable path; override with the ABACUS_EXE environment variable @@ -53,8 +53,8 @@ mpi_np_flag=${ABACUS_MPIEXEC_NUMPROC_FLAG:--np} # FindMPI may require launcher-specific flags (for example # Open MPI's --allow-run-as-root in a CI container). Keep these as arrays so # every invocation uses the same command assembled by the CMake test setup. -read -r -a mpi_preflags <<< "${ABACUS_MPIEXEC_PREFLAGS:-}" -read -r -a mpi_postflags <<< "${ABACUS_MPIEXEC_POSTFLAGS:-}" +read -r -a mpi_preflags <<<"${ABACUS_MPIEXEC_PREFLAGS:-}" +read -r -a mpi_postflags <<<"${ABACUS_MPIEXEC_POSTFLAGS:-}" threshold_file="threshold" # can specify the threshold for each test case @@ -64,22 +64,23 @@ threshold_file="threshold" # stress_threshold 0.001 # fatal_threshold 1 - -while getopts a:n:t:c:s:r:f:gpo:j: flag -do - case "${flag}" in - a) abacus=${OPTARG};; - n) np=${OPTARG};; - t) threshold=${OPTARG};; - c) ca=${OPTARG};; - s) sanitize=${OPTARG};; - r) case=${OPTARG};; - f) cases_file=${OPTARG};; - g) g=true;; #generate test reference - p) property_check=false;; #skip property collectors - o) nt=${OPTARG}; nt_explicit=true;; # number of OpenMP threads - j) njobs=${OPTARG};; # number of concurrent test cases, or "auto" - esac +while getopts a:n:t:c:s:r:f:gpo:j: flag; do + case "${flag}" in + a) abacus=${OPTARG} ;; + n) np=${OPTARG} ;; + t) threshold=${OPTARG} ;; + c) ca=${OPTARG} ;; + s) sanitize=${OPTARG} ;; + r) case=${OPTARG} ;; + f) cases_file=${OPTARG} ;; + g) g=true ;; #generate test reference + p) property_check=false ;; #skip property collectors + o) + nt=${OPTARG} + nt_explicit=true + ;; # number of OpenMP threads + j) njobs=${OPTARG} ;; # number of concurrent test cases, or "auto" + esac done #---------------------------------------------------------- @@ -101,21 +102,21 @@ ncores=$(OMP_NUM_THREADS= OMP_THREAD_LIMIT= nproc) # a wide OpenMP team, because these cases are only a few atoms each. #---------------------------------------------------------- if [ "$njobs" == "auto" ]; then - if [ "$np" -le 0 ] 2>/dev/null; then - njobs=$ncores - else - njobs=$(expr $ncores / $np) - fi + if [ "$np" -le 0 ] 2>/dev/null; then + njobs=$ncores + else + njobs=$(expr $ncores / $np) + fi fi if [ "$njobs" -lt 1 ] 2>/dev/null; then - njobs=1 + njobs=1 fi # Address Sanitizer appends every case to one shared report file, so those # runs stay serial. if [ "$sanitize" == true ] && [ "$njobs" -gt 1 ]; then - echo "Address Sanitizer run: forcing -j 1, the diagnostics report is shared." - njobs=1 + echo "Address Sanitizer run: forcing -j 1, the diagnostics report is shared." + njobs=1 fi #---------------------------------------------------------- @@ -126,18 +127,18 @@ fi # Recompute it from the core budget unless -o pinned it. #---------------------------------------------------------- if [ "$njobs" -gt 1 ] && [ "$nt_explicit" == false ]; then - nt="" + nt="" fi if [[ -z "$nt" ]]; then - if [ "$np" -le 0 ] 2>/dev/null; then - # serial build (no MPI launcher): use all cores for OpenMP - nt=$(expr $ncores / $njobs) - else - nt=$(expr $ncores / ${np} / $njobs) - fi + if [ "$np" -le 0 ] 2>/dev/null; then + # serial build (no MPI launcher): use all cores for OpenMP + nt=$(expr $ncores / $njobs) + else + nt=$(expr $ncores / ${np} / $njobs) + fi fi if [ "$nt" -lt 1 ] 2>/dev/null; then - nt=1 + nt=1 fi export OMP_NUM_THREADS=${nt} @@ -158,165 +159,162 @@ echo "Property collectors: $property_check" echo "--------------------------------" echo "" - #---------------------------------------------------------- # check_deviation() #---------------------------------------------------------- -check_deviation_pass(){ - deviation=$1 - thr=$2 - echo $(awk -v deviation="$deviation" -v thr="$thr" 'BEGIN{ if (sqrt(deviation*deviation) < thr) print 1; else print 0}') +check_deviation_pass() { + deviation=$1 + thr=$2 + echo $(awk -v deviation="$deviation" -v thr="$thr" 'BEGIN{ if (sqrt(deviation*deviation) < thr) print 1; else print 0}') } #---------------------------------------------------------- # define a function named 'check_out' #---------------------------------------------------------- -check_out(){ - #------------------------------------------------------ - # input file $1 is 'result.out' in each test directory - #------------------------------------------------------ - outfile=$1 - thr=$2 - force_thr=$3 - stress_thr=$4 - fatal_thr=$5 - descriptor_thr=$6 - wfc_thr=${7:-$thr} - - #------------------------------------------------------ - # outfile = result.out - #------------------------------------------------------ - properties=`awk '{print $1}' $outfile` - - #------------------------------------------------------ - # README - #------------------------------------------------------ - if test -e "README"; then - readme=`cat README` - echo "[----------] $readme" +check_out() { + #------------------------------------------------------ + # input file $1 is 'result.out' in each test directory + #------------------------------------------------------ + outfile=$1 + thr=$2 + force_thr=$3 + stress_thr=$4 + fatal_thr=$5 + descriptor_thr=$6 + wfc_thr=${7:-$thr} + + #------------------------------------------------------ + # outfile = result.out + #------------------------------------------------------ + properties=$(awk '{print $1}' $outfile) + + #------------------------------------------------------ + # README + #------------------------------------------------------ + if test -e "README"; then + readme=$(cat README) + echo "[----------] $readme" + fi + + #------------------------------------------------------ + # check every 'key' word + #------------------------------------------------------ + ifail=0 # if all properties have no warning. 0: no warning, 1: warning + ifatal=0 # if all properties have no fatal error. 0: no fatal error, 1: fatal error + for key in $properties; do + + if [ $key == "totaltimeref" ]; then + # echo "time=$cal ref=$ref" + break fi - #------------------------------------------------------ - # check every 'key' word - #------------------------------------------------------ - ifail=0 # if all properties have no warning. 0: no warning, 1: warning - ifatal=0 # if all properties have no fatal error. 0: no fatal error, 1: fatal error - for key in $properties; do - - if [ $key == "totaltimeref" ]; then - # echo "time=$cal ref=$ref" - break - fi + #-------------------------------------------------- + # calculated value + #-------------------------------------------------- + cal=$(grep -w "$key" result.out | awk '{printf "%.'$ca'f\n",$2}') + + #-------------------------------------------------- + # reference value + #-------------------------------------------------- + ref=$(grep -w "$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 deviation < thr, 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' + fatal_detail_list+="$dir: key $key not found in output\n" + break + else + compare_thr=$thr + if [[ $key == ml_desc_mean_* ]]; then + compare_thr=$descriptor_thr + elif [[ $key == wfi*.cube || $key == *_wfc_fp_rms || $key == *_wfc_fp_power_* || $key == *_wfc_fp_cross_* ]]; then + compare_thr=$wfc_thr + fi + if [ $(check_deviation_pass $deviation $compare_thr) = 0 ]; then + if [ $key == "totalforceref" ]; then + if [ $(check_deviation_pass $deviation $force_thr) = 0 ]; then + echo -e "[WARNING ] " \ + "$key cal=$cal ref=$ref deviation=$deviation" + ifail=1 + else + echo -e "\e[0;32m[ OK ] \e[0m $key" + fi + + elif [ $key == "totalstressref" ]; then + if [ $(check_deviation_pass $deviation $stress_thr) = 0 ]; then + echo -e "[WARNING ] " \ + "$key cal=$cal ref=$ref deviation=$deviation" + ifail=1 + else + echo -e "\e[0;32m[ OK ] \e[0m $key" + fi - #-------------------------------------------------- - # calculated value - #-------------------------------------------------- - cal=`grep -w "$key" result.out | awk '{printf "%.'$ca'f\n",$2}'` - - #-------------------------------------------------- - # reference value - #-------------------------------------------------- - ref=`grep -w "$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 deviation < thr, 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' - fatal_detail_list+="$dir: key $key not found in output\n" - break else - compare_thr=$thr - if [[ $key == ml_desc_mean_* ]]; then - compare_thr=$descriptor_thr - elif [[ $key == wfi*.cube || $key == *_wfc_fp_rms || $key == *_wfc_fp_power_* || $key == *_wfc_fp_cross_* ]]; then - compare_thr=$wfc_thr - fi - if [ $(check_deviation_pass $deviation $compare_thr) = 0 ]; then - if [ $key == "totalforceref" ]; then - if [ $(check_deviation_pass $deviation $force_thr) = 0 ]; then - echo -e "[WARNING ] "\ - "$key cal=$cal ref=$ref deviation=$deviation" - ifail=1 - else - echo -e "\e[0;32m[ OK ] \e[0m $key" - fi - - elif [ $key == "totalstressref" ]; then - if [ $(check_deviation_pass $deviation $stress_thr) = 0 ]; then - echo -e "[WARNING ] "\ - "$key cal=$cal ref=$ref deviation=$deviation" - ifail=1 - else - echo -e "\e[0;32m[ OK ] \e[0m $key" - fi - - else - echo -e "[WARNING ] "\ - "$key cal=$cal ref=$ref deviation=$deviation" - ifail=1 - fi - - if [ $(check_deviation_pass $deviation $fatal_thr) = 0 ]; then - ifatal=1 - fatal_detail_list+="$dir: $key cal=$cal ref=$ref deviation=$deviation\n" - fi - else - echo -e "\e[0;32m[ OK ] \e[0m $key" - fi + echo -e "[WARNING ] " \ + "$key cal=$cal ref=$ref deviation=$deviation" + ifail=1 fi - let ok++ - done - if [ $ifail -eq 1 ]; then - let failed++ - failed_case_list+=$dir'\n' - calculation=`grep calculation INPUT | grep -v '^#' | awk '{print $2}' | sed s/[[:space:]]//g` - # mohan comment out 2025-04-22, we don't need to print so many details on the screen - #running_path=`echo "OUT.autotest/running_$calculation"".log"` - #cat $running_path - case_status+=$dir' 0\n' - else - case_status+=$dir' 1\n' - fi - if [ $ifatal -eq 1 ]; then - let fatal++ - echo -e "\e[0;31m[ERROR ] \e[0m"\ - "An unacceptable deviation occurs." - fatal_case_list+=$dir'\n' + if [ $(check_deviation_pass $deviation $fatal_thr) = 0 ]; then + ifatal=1 + fatal_detail_list+="$dir: $key cal=$cal ref=$ref deviation=$deviation\n" + fi + else + echo -e "\e[0;32m[ OK ] \e[0m $key" + fi fi + let ok++ + done + if [ $ifail -eq 1 ]; then + let failed++ + failed_case_list+=$dir'\n' + calculation=$(grep calculation INPUT | grep -v '^#' | awk '{print $2}' | sed s/[[:space:]]//g) + # mohan comment out 2025-04-22, we don't need to print so many details on the screen + #running_path=`echo "OUT.autotest/running_$calculation"".log"` + #cat $running_path + case_status+=$dir' 0\n' + else + case_status+=$dir' 1\n' + fi + + if [ $ifatal -eq 1 ]; then + let fatal++ + echo -e "\e[0;31m[ERROR ] \e[0m" \ + "An unacceptable deviation occurs." + fatal_case_list+=$dir'\n' + fi } #--------------------------------------------- # function to read the threshold from the file #--------------------------------------------- -get_threshold() -{ - threshold_f=$1 - threshold_name=$2 - default_value=$3 - if [ -e $threshold_f ]; then - threshold_value=$(awk -v tn="$threshold_name" '$1==tn {print $2}' "$threshold_f") - if [ -n "$threshold_value" ]; then - echo $threshold_value - else - echo $default_value - fi +get_threshold() { + threshold_f=$1 + threshold_name=$2 + default_value=$3 + if [ -e $threshold_f ]; then + threshold_value=$(awk -v tn="$threshold_name" '$1==tn {print $2}' "$threshold_f") + if [ -n "$threshold_value" ]; then + echo $threshold_value else - echo $default_value + echo $default_value fi + else + echo $default_value + fi } #--------------------------------------------- @@ -326,100 +324,98 @@ get_threshold() # also written to "$result_dir/$1.res", so the caller can add them up even # when the case ran inside a subshell of the worker pool. #--------------------------------------------- -run_case() -{ - dir=$1 - - # These are per-case deltas here; the caller sums them over all cases. - failed=0 - ok=0 - fatal=0 - failed_case_list="" - fatal_case_list="" - fatal_detail_list="" - case_status="" - - if [ ! -d $dir ];then - echo -e "\e[0;31m[ERROR ]\e[0m $dir is not a directory.\n" - let fatal++ - fatal_case_list+=$dir'\n' - else - cd $dir - echo -e "\e[0;32m[ RUN ]\e[0m $dir" - TIMEFORMAT='[----------] Time elapsed: %R seconds' - #parallel test - time { - if [ "$np" -le 0 ] 2>/dev/null; then - # serial build: run the binary directly, no MPI launcher. - # This lets a serial ABACUS (ENABLE_MPI=OFF, e.g. the native - # Windows build) reuse this harness unchanged. - $abacus > log.txt - elif grep -qE '^[[:space:]]*of_ml_gene_data[[:space:]]+1([[:space:]]|$)' INPUT; then - # of_ml_gene_data supports single-rank only. - "$mpi_launcher" "$mpi_np_flag" 1 "${mpi_preflags[@]}" "$abacus" "${mpi_postflags[@]}" > log.txt - else - "$mpi_launcher" "$mpi_np_flag" $np "${mpi_preflags[@]}" "$abacus" "${mpi_postflags[@]}" > log.txt - fi - - # if ABACUS failed, print out the error message - if [ $? -ne 0 ]; then - echo -e "\e[0;31m[ERROR ]\e[0m $dir failed." - let failed++ - failed_case_list+=$dir'\n' - case_status+=$dir' 0\n' - cat log.txt - else - # check the output - test -d OUT.autotest || (echo "No 'OUT.autotest' dir presented. Some errors may happened in ABACUS." && exit 1) - if [ "$property_check" == false ]; then - echo "[----------] Property collectors skipped; use the dedicated validator for this output contract." - let ok++ - elif test -z $g - then - bash -e ../../integrate/validation_tools/catch_properties.sh result.out - if [ $? -ne 0 ]; then - echo -e "\e[0;31m [ERROR ] Fatal Error in catch_properties.sh \e[0m" - let fatal++ - fatal_case_list+=$dir'\n' - else - my_threshold=$(get_threshold $threshold_file "threshold" $threshold) - my_force_threshold=$(get_threshold $threshold_file "force_threshold" $force_threshold) - my_stress_threshold=$(get_threshold $threshold_file "stress_threshold" $stress_threshold) - my_fatal_threshold=$(get_threshold $threshold_file "fatal_threshold" $fatal_threshold) - my_descriptor_threshold=$(get_threshold $threshold_file "descriptor_threshold" $descriptor_threshold) - my_wfc_threshold=$(get_threshold $threshold_file "wfc_threshold" $my_threshold) - check_out result.out $my_threshold $my_force_threshold $my_stress_threshold $my_fatal_threshold $my_descriptor_threshold $my_wfc_threshold - fi - else - bash -e ../../integrate/validation_tools/catch_properties.sh result.ref - fi - 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 - } - echo "" - cd ../ - fi - - # The list variables hold literal "\n" escapes that printf %b expands at - # the very end, so each one still fits on a single line here. - { - echo "FAILED $failed" - echo "OK $ok" - echo "FATAL $fatal" - echo "FAILED_LIST $failed_case_list" - echo "FATAL_LIST $fatal_case_list" - echo "FATAL_DETAIL $fatal_detail_list" - echo "STATUS $case_status" - } > "$result_dir/$dir.res" +run_case() { + dir=$1 + + # These are per-case deltas here; the caller sums them over all cases. + failed=0 + ok=0 + fatal=0 + failed_case_list="" + fatal_case_list="" + fatal_detail_list="" + case_status="" + + if [ ! -d $dir ]; then + echo -e "\e[0;31m[ERROR ]\e[0m $dir is not a directory.\n" + let fatal++ + fatal_case_list+=$dir'\n' + else + cd $dir + echo -e "\e[0;32m[ RUN ]\e[0m $dir" + TIMEFORMAT='[----------] Time elapsed: %R seconds' + #parallel test + time { + if [ "$np" -le 0 ] 2>/dev/null; then + # serial build: run the binary directly, no MPI launcher. + # This lets a serial ABACUS (ENABLE_MPI=OFF, e.g. the native + # Windows build) reuse this harness unchanged. + $abacus >log.txt + elif grep -qE '^[[:space:]]*of_ml_gene_data[[:space:]]+1([[:space:]]|$)' INPUT; then + # of_ml_gene_data supports single-rank only. + "$mpi_launcher" "$mpi_np_flag" 1 "${mpi_preflags[@]}" "$abacus" "${mpi_postflags[@]}" >log.txt + else + "$mpi_launcher" "$mpi_np_flag" $np "${mpi_preflags[@]}" "$abacus" "${mpi_postflags[@]}" >log.txt + fi + + # if ABACUS failed, print out the error message + if [ $? -ne 0 ]; then + echo -e "\e[0;31m[ERROR ]\e[0m $dir failed." + let failed++ + failed_case_list+=$dir'\n' + case_status+=$dir' 0\n' + cat log.txt + else + # check the output + test -d OUT.autotest || (echo "No 'OUT.autotest' dir presented. Some errors may happened in ABACUS." && exit 1) + if [ "$property_check" == false ]; then + echo "[----------] Property collectors skipped; use the dedicated validator for this output contract." + let ok++ + elif test -z $g; then + bash -e ../../integrate/validation_tools/catch_properties.sh result.out + if [ $? -ne 0 ]; then + echo -e "\e[0;31m [ERROR ] Fatal Error in catch_properties.sh \e[0m" + let fatal++ + fatal_case_list+=$dir'\n' + else + my_threshold=$(get_threshold $threshold_file "threshold" $threshold) + my_force_threshold=$(get_threshold $threshold_file "force_threshold" $force_threshold) + my_stress_threshold=$(get_threshold $threshold_file "stress_threshold" $stress_threshold) + my_fatal_threshold=$(get_threshold $threshold_file "fatal_threshold" $fatal_threshold) + my_descriptor_threshold=$(get_threshold $threshold_file "descriptor_threshold" $descriptor_threshold) + my_wfc_threshold=$(get_threshold $threshold_file "wfc_threshold" $my_threshold) + check_out result.out $my_threshold $my_force_threshold $my_stress_threshold $my_fatal_threshold $my_descriptor_threshold $my_wfc_threshold + fi + else + bash -e ../../integrate/validation_tools/catch_properties.sh result.ref + fi + 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 + } + echo "" + cd ../ + fi + + # The list variables hold literal "\n" escapes that printf %b expands at + # the very end, so each one still fits on a single line here. + { + echo "FAILED $failed" + echo "OK $ok" + echo "FATAL $fatal" + echo "FAILED_LIST $failed_case_list" + echo "FATAL_LIST $fatal_case_list" + echo "FATAL_DETAIL $fatal_detail_list" + echo "STATUS $case_status" + } >"$result_dir/$dir.res" } #--------------------------------------------- @@ -427,7 +423,7 @@ run_case() #--------------------------------------------- test -e $cases_file || (echo "Please specify test cases file by -f option." && exit 1) -which $abacus > /dev/null || (echo "No ABACUS executable was found." && exit 1) +which $abacus >/dev/null || (echo "No ABACUS executable was found." && exit 1) testdir=$(grep -Ev '^[[:space:]]*(#|$)' "$cases_file" | grep -E "$case") failed=0 @@ -445,40 +441,40 @@ result_dir=$(mktemp -d "${TMPDIR:-/tmp}/abacus-autotest.XXXXXX") trap 'rm -rf "$result_dir"' EXIT 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 if [ "$njobs" -le 1 ]; then - # A subshell here too, so that a case's `cd` and its counters stay - # local exactly as they do in the worker pool below. - for dir in $testdir; do - ( run_case $dir ) - done + # A subshell here too, so that a case's `cd` and its counters stay + # local exactly as they do in the worker pool below. + for dir in $testdir; do + (run_case $dir) + done else - #----------------------------------------------------- - # Worker pool. Each case runs in its own subshell, so - # its `cd` and its counters stay local, and its console - # output is buffered to a file. - #----------------------------------------------------- - for dir in $testdir; do - ( run_case $dir ) > "$result_dir/$dir.out" 2>&1 & - while [ $(jobs -rp | wc -l) -ge $njobs ]; do - sleep 0.2 - done - done - wait - - #----------------------------------------------------- - # Replay the buffered logs in the order of the cases - # file, so a concurrent run reads like a serial one. - #----------------------------------------------------- - for dir in $testdir; do - test -f "$result_dir/$dir.out" && cat "$result_dir/$dir.out" + #----------------------------------------------------- + # Worker pool. Each case runs in its own subshell, so + # its `cd` and its counters stay local, and its console + # output is buffered to a file. + #----------------------------------------------------- + for dir in $testdir; do + (run_case $dir) >"$result_dir/$dir.out" 2>&1 & + while [ $(jobs -rp | wc -l) -ge $njobs ]; do + sleep 0.2 done + done + wait + + #----------------------------------------------------- + # Replay the buffered logs in the order of the cases + # file, so a concurrent run reads like a serial one. + #----------------------------------------------------- + for dir in $testdir; do + test -f "$result_dir/$dir.out" && cat "$result_dir/$dir.out" + done fi #----------------------------------------------------- @@ -493,46 +489,43 @@ fatal_case_list="" fatal_detail_list="" case_status="" for dir in $testdir; do - test -f "$result_dir/$dir.res" || continue - while read -r rkey rvalue; do - case "$rkey" in - FAILED) failed=$(expr $failed + $rvalue);; - OK) ok=$(expr $ok + $rvalue);; - FATAL) fatal=$(expr $fatal + $rvalue);; - FAILED_LIST) failed_case_list+=$rvalue;; - FATAL_LIST) fatal_case_list+=$rvalue;; - FATAL_DETAIL) fatal_detail_list+=$rvalue;; - STATUS) case_status+=$rvalue;; - esac - done < "$result_dir/$dir.res" + test -f "$result_dir/$dir.res" || continue + while read -r rkey rvalue; do + case "$rkey" in + FAILED) failed=$(expr $failed + $rvalue) ;; + OK) ok=$(expr $ok + $rvalue) ;; + FATAL) fatal=$(expr $fatal + $rvalue) ;; + FAILED_LIST) failed_case_list+=$rvalue ;; + FATAL_LIST) fatal_case_list+=$rvalue ;; + FATAL_DETAIL) fatal_detail_list+=$rvalue ;; + STATUS) case_status+=$rvalue ;; + esac + done <"$result_dir/$dir.res" 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 -printf "%b" "$case_status" > test.sum -if [[ "$failed" -eq 0 && "$fatal" -eq 0 ]] -then +if [ -z $g ]; then + printf "%b" "$case_status" >test.sum + if [[ "$failed" -eq 0 && "$fatal" -eq 0 ]]; then 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." + else + echo -e "[WARNING]\e[0m $failed test cases out of $(($failed + $ok)) failed." printf "%b" "$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." - printf "%b" "$fatal_case_list" - echo -e "\e[0;31m[ERROR ]\e[0m Fatal deviation details:" - printf "%b" "$fatal_detail_list" + if [ $fatal -gt 0 ]; then + echo -e "\e[0;31m[ERROR ]\e[0m $fatal test cases out of $(($failed + $ok)) produced fatal error." + printf "%b" "$fatal_case_list" + echo -e "\e[0;31m[ERROR ]\e[0m Fatal deviation details:" + printf "%b" "$fatal_detail_list" fi exit 1 -fi + fi else -echo "Generate test cases complete." + echo "Generate test cases complete." fi diff --git a/tests/integrate/Single_job.sh b/tests/integrate/Single_job.sh index 12dcfddba66..fc1715d8242 100755 --- a/tests/integrate/Single_job.sh +++ b/tests/integrate/Single_job.sh @@ -3,25 +3,23 @@ TOOLS_DIR="../../integrate/validation_tools/" # The note for using the script. -# input parameter: - #'none': run and check for this example; - #'debug': copy scripts to debug, then run and check this example; - #'other': run this example and generate reference file. +# input parameter: +#'none': run and check for this example; +#'debug': copy scripts to debug, then run and check this example; +#'other': run this example and generate reference file. -if test -z $1 -then - echo "Run this example and check!" - $TOOLS_DIR/run_check.sh -elif [ $1 == "debug" ] -then - echo "Begin debug!" - cp $TOOLS_DIR/run_check.sh ./ - # catch_properties.sh sources props_*.sh and the helper tools from its - # own directory, so copy the whole directory, not the entry script alone. - rm -rf ./validation_tools - cp -r $TOOLS_DIR ./validation_tools - ./run_check.sh debug +if test -z $1; then + echo "Run this example and check!" + $TOOLS_DIR/run_check.sh +elif [ $1 == "debug" ]; then + echo "Begin debug!" + cp $TOOLS_DIR/run_check.sh ./ + # catch_properties.sh sources props_*.sh and the helper tools from its + # own directory, so copy the whole directory, not the entry script alone. + rm -rf ./validation_tools + cp -r $TOOLS_DIR ./validation_tools + ./run_check.sh debug else - echo "Generate file result.ref ." - $TOOLS_DIR/run_check.sh $1 + echo "Generate file result.ref ." + $TOOLS_DIR/run_check.sh $1 fi diff --git a/tests/integrate/clean.sh b/tests/integrate/clean.sh index 86913799a9f..dfe93289ae0 100755 --- a/tests/integrate/clean.sh +++ b/tests/integrate/clean.sh @@ -2,92 +2,92 @@ for module in "_PW_" "_NO_" "_NP_" "_LJ_" "_OF_" "_RPA_" "tools"; do -echo $module - -for directory in `ls | grep $module`; do - - #-------------------------------------------- - # delete log.txt (if it exists) - #-------------------------------------------- - log_file="$directory/log.txt" - #test -e "$log_file" && echo $log_file - test -e "$log_file" && rm $log_file - - #-------------------------------------------- - # delete result.out (if it exists) - #-------------------------------------------- - result_file="$directory/result.out" - #test -e "$result_file" && echo $result_file - test -e "$result_file" && rm $result_file - - #-------------------------------------------- - # delete OUT.autotest (if it exists) - #-------------------------------------------- - OUT_directory="$directory/OUT.autotest" - #test -e "$OUT_directory" && echo $OUT_directory - test -e "$OUT_directory" && rm -rf $OUT_directory - - #-------------------------------------------- - # delete time.json (if it exists) - #-------------------------------------------- - time_json="$directory/time.json" - #test -e "$time_json" && echo $time_json - test -e "$time_json" && rm $time_json - - #-------------------------------------------- - # delete projected_DM.dat (if it exists) - #-------------------------------------------- - projected_DM="$directory/projected_DM.dat" - test -e "$projected_DM" && rm -rf $projected_DM - - #-------------------------------------------- - # delete Onsager.txt (if it exists) - #-------------------------------------------- - onsager_file="$directory/Onsager.txt" - test -e "$onsager_file" && rm -rf $onsager_file - - #-------------------------------------------- - # delete kpoints (if it exists) - #-------------------------------------------- - kpoints_file="$directory/kpoints" - test -e "$kpoints_file" && rm -rf $kpoints_file - - #-------------------------------------------- - # delete exec files in tools directory (if it exists) - #-------------------------------------------- - sumfile1="$directory/sum_cube" - test -e "$sumfile1" && rm -rf $sumfile1 - - #-------------------------------------------- - # delete KPT file in kspacing test (if it exists) - #-------------------------------------------- - if [ ${directory} == "121_PW_kspacing" ]; then - KPT_file="$directory/KPT" - test -e "$KPT_file" && rm -rf $KPT_file - fi - - #-------------------------------------------- - # delete RPA output directory (if it exists) - #-------------------------------------------- - if [ ${module} == "_RPA_" ]; then - RPA_OUT_directory="$directory/OUT.librpa" - test -e "$RPA_OUT_directory" && rm -rf "$RPA_OUT_directory" - fi - - #-------------------------------------------- - # delete *.npy (if it exists) - #-------------------------------------------- - num=$(find -name '*.npy' | wc -l) - if [ $num != "0" ]; then - rm -rf $directory/*.npy - fi - - #-------------------------------------------- - # delete test_exx (if it exists) - #-------------------------------------------- - test_exx="$directory/test_exx" - test -e "$test_exx" && rm -rf $test_exx - -done + echo $module + + for directory in $(ls | grep $module); do + + #-------------------------------------------- + # delete log.txt (if it exists) + #-------------------------------------------- + log_file="$directory/log.txt" + #test -e "$log_file" && echo $log_file + test -e "$log_file" && rm $log_file + + #-------------------------------------------- + # delete result.out (if it exists) + #-------------------------------------------- + result_file="$directory/result.out" + #test -e "$result_file" && echo $result_file + test -e "$result_file" && rm $result_file + + #-------------------------------------------- + # delete OUT.autotest (if it exists) + #-------------------------------------------- + OUT_directory="$directory/OUT.autotest" + #test -e "$OUT_directory" && echo $OUT_directory + test -e "$OUT_directory" && rm -rf $OUT_directory + + #-------------------------------------------- + # delete time.json (if it exists) + #-------------------------------------------- + time_json="$directory/time.json" + #test -e "$time_json" && echo $time_json + test -e "$time_json" && rm $time_json + + #-------------------------------------------- + # delete projected_DM.dat (if it exists) + #-------------------------------------------- + projected_DM="$directory/projected_DM.dat" + test -e "$projected_DM" && rm -rf $projected_DM + + #-------------------------------------------- + # delete Onsager.txt (if it exists) + #-------------------------------------------- + onsager_file="$directory/Onsager.txt" + test -e "$onsager_file" && rm -rf $onsager_file + + #-------------------------------------------- + # delete kpoints (if it exists) + #-------------------------------------------- + kpoints_file="$directory/kpoints" + test -e "$kpoints_file" && rm -rf $kpoints_file + + #-------------------------------------------- + # delete exec files in tools directory (if it exists) + #-------------------------------------------- + sumfile1="$directory/sum_cube" + test -e "$sumfile1" && rm -rf $sumfile1 + + #-------------------------------------------- + # delete KPT file in kspacing test (if it exists) + #-------------------------------------------- + if [ ${directory} == "121_PW_kspacing" ]; then + KPT_file="$directory/KPT" + test -e "$KPT_file" && rm -rf $KPT_file + fi + + #-------------------------------------------- + # delete RPA output directory (if it exists) + #-------------------------------------------- + if [ ${module} == "_RPA_" ]; then + RPA_OUT_directory="$directory/OUT.librpa" + test -e "$RPA_OUT_directory" && rm -rf "$RPA_OUT_directory" + fi + + #-------------------------------------------- + # delete *.npy (if it exists) + #-------------------------------------------- + num=$(find -name '*.npy' | wc -l) + if [ $num != "0" ]; then + rm -rf $directory/*.npy + fi + + #-------------------------------------------- + # delete test_exx (if it exists) + #-------------------------------------------- + test_exx="$directory/test_exx" + test -e "$test_exx" && rm -rf $test_exx + + done done diff --git a/tests/integrate/validation_tools/catch_properties.sh b/tests/integrate/validation_tools/catch_properties.sh index 72525f1b562..7605b44944a 100755 --- a/tests/integrate/validation_tools/catch_properties.sh +++ b/tests/integrate/validation_tools/catch_properties.sh @@ -11,7 +11,7 @@ props_init "$1" source "$PROPS_SCRIPT_DIR/props_lr.sh" if run_lr_tracking_props; then - exit 0 + exit 0 fi source "$PROPS_SCRIPT_DIR/props_basic.sh" @@ -80,7 +80,10 @@ run_ml_rpa_props # so a failing helper (get_sum_*.py, a missing deepks_desc.dat) left an # empty value for the threshold check instead of aborting the collection. # Keep that behavior with a subshell that disables errexit. -( set +e; run_deepks_props ) +( + set +e + run_deepks_props +) #-------------------------------------------- # basic collectors that run after deepks: symmetry diff --git a/tests/integrate/validation_tools/props_basic.sh b/tests/integrate/validation_tools/props_basic.sh index 04311083287..54e99e4bfe4 100644 --- a/tests/integrate/validation_tools/props_basic.sh +++ b/tests/integrate/validation_tools/props_basic.sh @@ -18,23 +18,21 @@ # # All result lines are appended to $props_result_file. -run_basic_props(){ - -#---------------------------- -# total energy information -#---------------------------- -if [ $calculation != "get_wf" ]\ -&& [ $calculation != "get_pchg" ] && [ $calculation != "get_s" ]\ -&& [ $is_lr == 0 ]; then - etot=$(grep "ETOT_" "$running_path" | tail -1 | awk '{print $2}') - etotperatom=`awk 'BEGIN {x='$etot';y='$natom';printf "%.10f\n",x/y}'` - echo "etotref $etot" >>$props_result_file - echo "etotperatomref $etotperatom" >>$props_result_file -fi - -# Opt-in collinear magnetic-state check. Comparing both moments distinguishes -# compensated AFM from NM; the reference tolerance is 1e-3 mu_B per cell. -if [ "$nspin" = "2" ] && [ -f magnetism.ref ]; then +run_basic_props() { + + #---------------------------- + # total energy information + #---------------------------- + if [ $calculation != "get_wf" ] && [ $calculation != "get_pchg" ] && [ $calculation != "get_s" ] && [ $is_lr == 0 ]; then + etot=$(grep "ETOT_" "$running_path" | tail -1 | awk '{print $2}') + etotperatom=$(awk 'BEGIN {x='$etot';y='$natom';printf "%.10f\n",x/y}') + echo "etotref $etot" >>$props_result_file + echo "etotperatomref $etotperatom" >>$props_result_file + fi + + # Opt-in collinear magnetic-state check. Comparing both moments distinguishes + # compensated AFM from NM; the reference tolerance is 1e-3 mu_B per cell. + if [ "$nspin" = "2" ] && [ -f magnetism.ref ]; then awk ' /Total magnetism \(Bohr mag\/cell\)/ {total = $NF; have_total = 1} /Absolute magnetism \(Bohr mag\/cell\)/ {absolute = $NF; have_absolute = 1} @@ -42,155 +40,155 @@ if [ "$nspin" = "2" ] && [ -f magnetism.ref ]; then if (!have_total || !have_absolute) exit 1 print total, absolute } - ' "$running_path" > magnetism.out + ' "$running_path" >magnetism.out record_compare_result "$props_result_file" "CompareMagnetism_pass" "magnetism.ref" "magnetism.out" 3 -fi + fi -#---------------------------- -# force information -#---------------------------- -if ! test -z "$has_force" && [ $has_force == 1 ] && [ $is_lr == 0 ]; then - nn3=`echo "$natom + 3" |bc` + #---------------------------- + # force information + #---------------------------- + if ! test -z "$has_force" && [ $has_force == 1 ] && [ $is_lr == 0 ]; then + nn3=$(echo "$natom + 3" | bc) # check the last step result - grep -A$nn3 "TOTAL-FORCE" $running_path |awk 'NF==4{print $2,$3,$4}' | tail -$natom > force.txt - total_force=`sum_file force.txt` + grep -A$nn3 "TOTAL-FORCE" $running_path | awk 'NF==4{print $2,$3,$4}' | tail -$natom >force.txt + total_force=$(sum_file force.txt) rm force.txt - echo "totalforceref $total_force" >>$props_result_file -fi - -#------------------------------- -# stress information -#------------------------------- -if ! test -z "$has_stress" && [ $has_stress == 1 ]; then - grep -A6 "TOTAL-STRESS" $running_path| awk 'NF==3' | tail -3> stress.txt - total_stress=`sum_file stress.txt` - rm stress.txt - echo "totalstressref $total_stress" >>$props_result_file -fi - -#------------------------------- -# DOS information -#------------------------------- -if ! test -z "$has_dos" && [ $has_dos == 1 ]; then - total_dos=`cat OUT.autotest/dos*.txt | awk 'END {print}' | awk '{print $3}'` - echo "totaldosref $total_dos" >> $props_result_file -fi - -#------------------------------- -# Onsager coefficiency -#------------------------------- -if ! test -z "$has_cond" && [ $has_cond == 1 ]; then - onref=refOnsager.txt - oncal=OUT.autotest/Onsager.txt - python3 $COMPARE_SCRIPT $onref $oncal 3 -com_type 0 + echo "totalforceref $total_force" >>$props_result_file + fi + + #------------------------------- + # stress information + #------------------------------- + if ! test -z "$has_stress" && [ $has_stress == 1 ]; then + grep -A6 "TOTAL-STRESS" $running_path | awk 'NF==3' | tail -3 >stress.txt + total_stress=$(sum_file stress.txt) + rm stress.txt + echo "totalstressref $total_stress" >>$props_result_file + fi + + #------------------------------- + # DOS information + #------------------------------- + if ! test -z "$has_dos" && [ $has_dos == 1 ]; then + total_dos=$(cat OUT.autotest/dos*.txt | awk 'END {print}' | awk '{print $3}') + echo "totaldosref $total_dos" >>$props_result_file + fi + + #------------------------------- + # Onsager coefficiency + #------------------------------- + if ! test -z "$has_cond" && [ $has_cond == 1 ]; then + onref=refOnsager.txt + oncal=OUT.autotest/Onsager.txt + python3 $COMPARE_SCRIPT $onref $oncal 3 -com_type 0 echo "CompareH_Failed $?" >>$props_result_file - rm -f je-je.txt Chebycoef -fi + rm -f je-je.txt Chebycoef + fi } -run_basic_props_post_ml(){ - -#-------------------------------------------- -# implicit solvation model -#-------------------------------------------- -if ! test -z "$imp_sol" && { [ "$imp_sol" = 1 ] || [ "$imp_sol" = 2 ]; }; then - esol_el=`grep E_sol_el $running_path | tail -1 | awk '{print $3}'` - esol_cav=`grep E_sol_cav $running_path | tail -1 | awk '{print $3}'` - echo "esolelref $esol_el" >>$props_result_file - echo "esolcavref $esol_cav" >>$props_result_file -fi - -# out_sol 1: both cubes must exist (the cases set imp_sol 2, or imp_sol 1 with -# eb_k > 1, so sol_cavity.cube is written). The cavity volume int s dV of -# sol_cavity.cube is compared; sol_eps.cube is only checked for presence, since -# its integral is dominated by the bulk permittivity times the volume. -if [[ "$out_sol" == "1" ]]; then - for cube in sol_eps.cube sol_cavity.cube; do - if [ ! -f "OUT.autotest/$cube" ]; then - echo "Error: out_sol 1 but OUT.autotest/$cube is missing" - exit 1 - fi - done - integral=$(python3 "$CUBE_TOOL" integrate "OUT.autotest/sol_cavity.cube") - echo "sol_cavity_integralref $integral" >>$props_result_file -fi - -#-------------------------------------------- -# vacuum point-countercharge correction -#-------------------------------------------- -if [[ "$assume_isolated" == "pcc_0d" || "$assume_isolated" == "pcc_2d" ]]; then - epcc=$(grep E_pcc "$running_path" | tail -1 | awk '{print $3}') - echo "epccref $epcc" >>$props_result_file -fi +run_basic_props_post_ml() { + + #-------------------------------------------- + # implicit solvation model + #-------------------------------------------- + if ! test -z "$imp_sol" && { [ "$imp_sol" = 1 ] || [ "$imp_sol" = 2 ]; }; then + esol_el=$(grep E_sol_el $running_path | tail -1 | awk '{print $3}') + esol_cav=$(grep E_sol_cav $running_path | tail -1 | awk '{print $3}') + echo "esolelref $esol_el" >>$props_result_file + echo "esolcavref $esol_cav" >>$props_result_file + fi + + # out_sol 1: both cubes must exist (the cases set imp_sol 2, or imp_sol 1 with + # eb_k > 1, so sol_cavity.cube is written). The cavity volume int s dV of + # sol_cavity.cube is compared; sol_eps.cube is only checked for presence, since + # its integral is dominated by the bulk permittivity times the volume. + if [[ "$out_sol" == "1" ]]; then + for cube in sol_eps.cube sol_cavity.cube; do + if [ ! -f "OUT.autotest/$cube" ]; then + echo "Error: out_sol 1 but OUT.autotest/$cube is missing" + exit 1 + fi + done + integral=$(python3 "$CUBE_TOOL" integrate "OUT.autotest/sol_cavity.cube") + echo "sol_cavity_integralref $integral" >>$props_result_file + fi + + #-------------------------------------------- + # vacuum point-countercharge correction + #-------------------------------------------- + if [[ "$assume_isolated" == "pcc_0d" || "$assume_isolated" == "pcc_2d" ]]; then + epcc=$(grep E_pcc "$running_path" | tail -1 | awk '{print $3}') + echo "epccref $epcc" >>$props_result_file + fi } -run_basic_props_post_deepks(){ - -#-------------------------------------------- -# check symmetry -#-------------------------------------------- -if ! test -z "$symmetry" && [ $symmetry == 1 ]; then - # exclude the nspin=4 MAGNETIC POINT/SPACE GROUP lines so they do not interfere - # with the crystallographic point-group / space-group detection below - pointgroup=`grep 'POINT GROUP =' $running_path | grep -v 'MAGNETIC' | grep -v 'BvK' | awk '{print $4}'` - spacegroup=`grep 'SPACE GROUP =' $running_path | grep -v 'MAGNETIC' | grep -v 'BvK' | awk '{print $7}'` - nksibz=`grep 'Number of irreducible k-points' $running_path | awk '{print $6}'` - echo "pointgroupref $pointgroup" >>$props_result_file - echo "spacegroupref $spacegroup" >>$props_result_file - echo "nksibzref $nksibz" >>$props_result_file - # (nspin=4) magnetic (Shubnikov) group analysis: capture the space-group-consistent - # magnetic point group. Only printed when the group is actually reduced (magnetic); - # non-magnetic nspin=4 does not print it, so the capture is skipped when empty. - if ! test -z "$nspin" && [ $nspin == 4 ]; then - magpointgroup=`grep 'MAGNETIC POINT GROUP IN SPACE GROUP' $running_path | awk '{print $NF}'` - if ! test -z "$magpointgroup"; then - echo "magpointgroupref $magpointgroup" >>$props_result_file - fi - fi -fi +run_basic_props_post_deepks() { + + #-------------------------------------------- + # check symmetry + #-------------------------------------------- + if ! test -z "$symmetry" && [ $symmetry == 1 ]; then + # exclude the nspin=4 MAGNETIC POINT/SPACE GROUP lines so they do not interfere + # with the crystallographic point-group / space-group detection below + pointgroup=$(grep 'POINT GROUP =' $running_path | grep -v 'MAGNETIC' | grep -v 'BvK' | awk '{print $4}') + spacegroup=$(grep 'SPACE GROUP =' $running_path | grep -v 'MAGNETIC' | grep -v 'BvK' | awk '{print $7}') + nksibz=$(grep 'Number of irreducible k-points' $running_path | awk '{print $6}') + echo "pointgroupref $pointgroup" >>$props_result_file + echo "spacegroupref $spacegroup" >>$props_result_file + echo "nksibzref $nksibz" >>$props_result_file + # (nspin=4) magnetic (Shubnikov) group analysis: capture the space-group-consistent + # magnetic point group. Only printed when the group is actually reduced (magnetic); + # non-magnetic nspin=4 does not print it, so the capture is skipped when empty. + if ! test -z "$nspin" && [ $nspin == 4 ]; then + magpointgroup=$(grep 'MAGNETIC POINT GROUP IN SPACE GROUP' $running_path | awk '{print $NF}') + if ! test -z "$magpointgroup"; then + echo "magpointgroupref $magpointgroup" >>$props_result_file + fi + fi + fi } -run_basic_props_post_rdmft(){ +run_basic_props_post_rdmft() { -#-------------------------------------------- -# Check if out_alllog is set to 1 -# and verify running*.log filenames -#-------------------------------------------- -if ! test -z "$out_alllog" && [ $out_alllog -eq 1 ]; then + #-------------------------------------------- + # Check if out_alllog is set to 1 + # and verify running*.log filenames + #-------------------------------------------- + if ! test -z "$out_alllog" && [ $out_alllog -eq 1 ]; then if [ -z "$calculation" ]; then - echo "Error: calculation parameter not found in INPUT" - exit 1 + echo "Error: calculation parameter not found in INPUT" + exit 1 fi # Find all running*.log files in OUT.autotest directory log_files=$(ls OUT.autotest/running*.log 2>/dev/null) if [ -z "$log_files" ]; then - echo "Error: No running*.log files found in OUT.autotest/" - exit 1 + echo "Error: No running*.log files found in OUT.autotest/" + exit 1 fi # Check each log file name contains the calculation parameter all_valid=true for log_file in $log_files; do - filename=$(basename "$log_file") - if [[ ! "$filename" =~ running_${calculation}_ ]]; then - echo "Error: Invalid log filename $filename - should contain 'running_${calculation}_'" - all_valid=false - fi + filename=$(basename "$log_file") + if [[ ! "$filename" =~ running_${calculation}_ ]]; then + echo "Error: Invalid log filename $filename - should contain 'running_${calculation}_'" + all_valid=false + fi done if $all_valid; then - echo "All log filenames contain 'running_${calculation}_' - validation passed" - echo "log_filename_validation 1" >>$props_result_file + echo "All log filenames contain 'running_${calculation}_' - validation passed" + echo "log_filename_validation 1" >>$props_result_file else - echo "Error: Some log filenames do not contain 'running_${calculation}_'" - echo "log_filename_validation 0" >>$props_result_file - exit 1 + echo "Error: Some log filenames do not contain 'running_${calculation}_'" + echo "log_filename_validation 0" >>$props_result_file + exit 1 fi -fi + fi } diff --git a/tests/integrate/validation_tools/props_common.sh b/tests/integrate/validation_tools/props_common.sh index 983d2f1b6d1..a29a7625829 100644 --- a/tests/integrate/validation_tools/props_common.sh +++ b/tests/integrate/validation_tools/props_common.sh @@ -28,145 +28,139 @@ COMPARE_MMN_SCRIPT="$PROPS_TOOLS_DIR/compare_mmn.py" CUBE_TOOL="$PROPS_TOOLS_DIR/cube_tool.py" COLLECT_NPY_MEANS="$PROPS_TOOLS_DIR/collect_npy_means.py" - -sum_file(){ - line=`grep -vc '^$' $1` - inc=1 - if ! test -z $2; then - inc=$2 - fi - sum=0.0 - for (( num=1 ; num<=$line ; num+=$inc ));do - value_line=(` sed -n "$num p" $1 | head -n1 `) - colume=`echo ${#value_line[@]}` - for (( col=0 ; col<$colume ; col++ ));do - value=`echo ${value_line[$col]}` - sum=`awk 'BEGIN {x='$sum';y='$value';printf "%.6f\n",x+sqrt(y*y)}'` - done - done - echo $sum +sum_file() { + line=$(grep -vc '^$' $1) + inc=1 + if ! test -z $2; then + inc=$2 + fi + sum=0.0 + for ((num = 1; num <= $line; num += $inc)); do + value_line=($(sed -n "$num p" $1 | head -n1)) + colume=$(echo ${#value_line[@]}) + for ((col = 0; col < $colume; col++)); do + value=$(echo ${value_line[$col]}) + sum=$(awk 'BEGIN {x='$sum';y='$value';printf "%.6f\n",x+sqrt(y*y)}') + done + done + echo $sum } - -get_input_key_value(){ - key=$1 - inputf=$2 - value=$(awk -v key=$key '{if($1==key) a=$2} END {print a}' $inputf) - echo $value +get_input_key_value() { + key=$1 + inputf=$2 + value=$(awk -v key=$key '{if($1==key) a=$2} END {print a}' $inputf) + echo $value } - -sanitize_result_key(){ - echo "$1" | sed 's/[^A-Za-z0-9_]/_/g' +sanitize_result_key() { + echo "$1" | sed 's/[^A-Za-z0-9_]/_/g' } - -record_compare_result(){ - result_file=$1 - result_key=$2 - ref_file=$3 - cal_file=$4 - accuracy=${5:-8} - use_abs=${6:-0} - - if [ ! -f "$ref_file" ] || [ ! -f "$cal_file" ]; then - echo "$result_key 1" >> "$result_file" - return - fi - - python3 $COMPARE_SCRIPT "$ref_file" "$cal_file" "$accuracy" -abs "$use_abs" - echo "$result_key $?" >> "$result_file" +record_compare_result() { + result_file=$1 + result_key=$2 + ref_file=$3 + cal_file=$4 + accuracy=${5:-8} + use_abs=${6:-0} + + if [ ! -f "$ref_file" ] || [ ! -f "$cal_file" ]; then + echo "$result_key 1" >>"$result_file" + return + fi + + python3 $COMPARE_SCRIPT "$ref_file" "$cal_file" "$accuracy" -abs "$use_abs" + echo "$result_key $?" >>"$result_file" } - # props_init RESULT_FILE # # Reads the shared INPUT switch keys once into global variables, locates the # running log, derives shared values (natom, is_lr, ...), and truncates the # result file. Must be called from the test-case directory (where INPUT and # OUT.autotest live) before any run__props function. -props_init(){ - props_result_file=$1 - - # the command will ignore lines starting with # - calculation=`grep calculation INPUT | grep -v '^#' | awk '{print $2}' | sed s/[[:space:]]//g` - - running_path=$(ls OUT.autotest/running_${calculation}*.log 2>/dev/null | head -1) - if [ -z "$running_path" ]; then - echo "Error: No running log file found for calculation=$calculation in OUT.autotest/" - exit 1 - fi - - natom=`grep -En '(^|[[:space:]])TOTAL ATOM NUMBER($|[[:space:]])' $running_path | tail -1 | awk '{print $6}'` - has_force=$(get_input_key_value "cal_force" "INPUT") - has_stress=$(get_input_key_value "cal_stress" "INPUT") - has_band=$(get_input_key_value "out_band" "INPUT") - has_dos=$(get_input_key_value "out_dos" "INPUT") - has_cond=$(get_input_key_value "cal_cond" "INPUT") - out_hsk=$(get_input_key_value "out_hsk" "INPUT") - out_hsr=$(get_input_key_value "out_hsr" "INPUT") - has_hs=$(get_input_key_value "out_mat_hs" "INPUT") - has_hs2=$(get_input_key_value "out_mat_hs2" "INPUT") - out_hr_npz=$(get_input_key_value "out_hr_npz" "INPUT") - out_hsr_npz=$(get_input_key_value "out_hsr_npz" "INPUT") - out_dm_npz=$(get_input_key_value "out_dm_npz" "INPUT") - if ! test -z "$out_hsk"; then - has_hs=$out_hsk - fi - if ! test -z "$out_hsr"; then - has_hs2=$out_hsr - fi - has_xc=$(get_input_key_value "out_mat_xc" "INPUT") - has_xc2=$(get_input_key_value "out_mat_xc2" "INPUT") - has_eband_separate=$(get_input_key_value "out_eband_terms" "INPUT") - has_lowf=$(get_input_key_value "out_wfc_lcao" "INPUT") - out_app_flag=$(get_input_key_value "out_app_flag" "INPUT") - has_wfc_r=$(get_input_key_value "out_wfc_r" "INPUT") - has_wfc_pw=$(get_input_key_value "out_wfc_pw" "INPUT") - out_dm=$(get_input_key_value "out_dm" "INPUT") - out_mul=$(get_input_key_value "out_mul" "INPUT") - gamma_only=$(get_input_key_value "gamma_only" "INPUT") - imp_sol=$(get_input_key_value "imp_sol" "INPUT") - out_sol=$(get_input_key_value "out_sol" "INPUT") - assume_isolated=$(get_input_key_value "assume_isolated" "INPUT") - run_rpa=$(get_input_key_value "rpa" "INPUT") - out_pot=$(get_input_key_value "out_pot" "INPUT") - out_elf=$(get_input_key_value "out_elf" "INPUT") - out_dm1=$(get_input_key_value "out_dm1" "INPUT") - out_pband=$(get_input_key_value "out_proj_band" "INPUT") - toW90=$(get_input_key_value "towannier90" "INPUT") - has_mat_r=$(get_input_key_value "out_mat_r" "INPUT") - has_mat_t=$(get_input_key_value "out_mat_t" "INPUT") - has_mat_syns=$(get_input_key_value "cal_syns" "INPUT") - has_mat_dh=$(get_input_key_value "out_mat_dh" "INPUT") - has_scan=$(get_input_key_value "dft_functional" "INPUT") - out_chg=$(get_input_key_value "out_chg" "INPUT") - has_ldos=$(get_input_key_value "out_ldos" "INPUT") - esolver_type=$(get_input_key_value "esolver_type" "INPUT") - rdmft=$(get_input_key_value "rdmft" "INPUT") - word_total_time="atomic_world" - symmetry=$(get_input_key_value "symmetry" "INPUT") - out_current=$(get_input_key_value "out_current" "INPUT") - out_efield=$(get_input_key_value "out_efield" "INPUT") - out_vecpot=$(get_input_key_value "out_vecpot" "INPUT") - nspin=$(get_input_key_value "nspin" "INPUT") - out_alllog=$(get_input_key_value "out_alllog" "INPUT") - test -e $props_result_file && rm $props_result_file - - # if NOT non-self-consistent calculations or linear response - is_lr=0 - if [ ! -z $esolver_type ] && ([ $esolver_type == "lr" ] || [ $esolver_type == "ks-lr" ]); then - is_lr=1 - fi +props_init() { + props_result_file=$1 + + # the command will ignore lines starting with # + calculation=$(grep calculation INPUT | grep -v '^#' | awk '{print $2}' | sed s/[[:space:]]//g) + + running_path=$(ls OUT.autotest/running_${calculation}*.log 2>/dev/null | head -1) + if [ -z "$running_path" ]; then + echo "Error: No running log file found for calculation=$calculation in OUT.autotest/" + exit 1 + fi + + natom=$(grep -En '(^|[[:space:]])TOTAL ATOM NUMBER($|[[:space:]])' $running_path | tail -1 | awk '{print $6}') + has_force=$(get_input_key_value "cal_force" "INPUT") + has_stress=$(get_input_key_value "cal_stress" "INPUT") + has_band=$(get_input_key_value "out_band" "INPUT") + has_dos=$(get_input_key_value "out_dos" "INPUT") + has_cond=$(get_input_key_value "cal_cond" "INPUT") + out_hsk=$(get_input_key_value "out_hsk" "INPUT") + out_hsr=$(get_input_key_value "out_hsr" "INPUT") + has_hs=$(get_input_key_value "out_mat_hs" "INPUT") + has_hs2=$(get_input_key_value "out_mat_hs2" "INPUT") + out_hr_npz=$(get_input_key_value "out_hr_npz" "INPUT") + out_hsr_npz=$(get_input_key_value "out_hsr_npz" "INPUT") + out_dm_npz=$(get_input_key_value "out_dm_npz" "INPUT") + if ! test -z "$out_hsk"; then + has_hs=$out_hsk + fi + if ! test -z "$out_hsr"; then + has_hs2=$out_hsr + fi + has_xc=$(get_input_key_value "out_mat_xc" "INPUT") + has_xc2=$(get_input_key_value "out_mat_xc2" "INPUT") + has_eband_separate=$(get_input_key_value "out_eband_terms" "INPUT") + has_lowf=$(get_input_key_value "out_wfc_lcao" "INPUT") + out_app_flag=$(get_input_key_value "out_app_flag" "INPUT") + has_wfc_r=$(get_input_key_value "out_wfc_r" "INPUT") + has_wfc_pw=$(get_input_key_value "out_wfc_pw" "INPUT") + out_dm=$(get_input_key_value "out_dm" "INPUT") + out_mul=$(get_input_key_value "out_mul" "INPUT") + gamma_only=$(get_input_key_value "gamma_only" "INPUT") + imp_sol=$(get_input_key_value "imp_sol" "INPUT") + out_sol=$(get_input_key_value "out_sol" "INPUT") + assume_isolated=$(get_input_key_value "assume_isolated" "INPUT") + run_rpa=$(get_input_key_value "rpa" "INPUT") + out_pot=$(get_input_key_value "out_pot" "INPUT") + out_elf=$(get_input_key_value "out_elf" "INPUT") + out_dm1=$(get_input_key_value "out_dm1" "INPUT") + out_pband=$(get_input_key_value "out_proj_band" "INPUT") + toW90=$(get_input_key_value "towannier90" "INPUT") + has_mat_r=$(get_input_key_value "out_mat_r" "INPUT") + has_mat_t=$(get_input_key_value "out_mat_t" "INPUT") + has_mat_syns=$(get_input_key_value "cal_syns" "INPUT") + has_mat_dh=$(get_input_key_value "out_mat_dh" "INPUT") + has_scan=$(get_input_key_value "dft_functional" "INPUT") + out_chg=$(get_input_key_value "out_chg" "INPUT") + has_ldos=$(get_input_key_value "out_ldos" "INPUT") + esolver_type=$(get_input_key_value "esolver_type" "INPUT") + rdmft=$(get_input_key_value "rdmft" "INPUT") + word_total_time="atomic_world" + symmetry=$(get_input_key_value "symmetry" "INPUT") + out_current=$(get_input_key_value "out_current" "INPUT") + out_efield=$(get_input_key_value "out_efield" "INPUT") + out_vecpot=$(get_input_key_value "out_vecpot" "INPUT") + nspin=$(get_input_key_value "nspin" "INPUT") + out_alllog=$(get_input_key_value "out_alllog" "INPUT") + test -e $props_result_file && rm $props_result_file + + # if NOT non-self-consistent calculations or linear response + is_lr=0 + if [ ! -z $esolver_type ] && ([ $esolver_type == "lr" ] || [ $esolver_type == "ks-lr" ]); then + is_lr=1 + fi } - # props_finalize RESULT_FILE # # Appends the always-present total-time entry. Kept as the single trailing # step so new modules can be inserted before it without touching the ending. -props_finalize(){ - props_result_file=$1 - ttot=`grep $word_total_time $running_path | awk '{print $3}'` - echo "totaltimeref $ttot" >> $props_result_file +props_finalize() { + props_result_file=$1 + ttot=$(grep $word_total_time $running_path | awk '{print $3}') + echo "totaltimeref $ttot" >>$props_result_file } diff --git a/tests/integrate/validation_tools/props_cube.sh b/tests/integrate/validation_tools/props_cube.sh index 68134aa6ffb..159a69b2308 100644 --- a/tests/integrate/validation_tools/props_cube.sh +++ b/tests/integrate/validation_tools/props_cube.sh @@ -14,120 +14,119 @@ # run_cube_tail_props() - mulliken, pchg cubes, get_wf/get_pchg cube # integration/fingerprints, nspin=4 spinor identity -run_cube_pot_props(){ +run_cube_pot_props() { -#------------------------------- -# echo $out_pot1 -#------------------------------- -if ! test -z "$out_pot" && [ $out_pot == 1 ]; then - pot1ref=pot.cube.ref - pot1cal=OUT.autotest/pot.cube - python3 $COMPARE_SCRIPT $pot1ref $pot1cal 3 - echo "ComparePot1_pass $?" >>$props_result_file -fi + #------------------------------- + # echo $out_pot1 + #------------------------------- + if ! test -z "$out_pot" && [ $out_pot == 1 ]; then + pot1ref=pot.cube.ref + pot1cal=OUT.autotest/pot.cube + python3 $COMPARE_SCRIPT $pot1ref $pot1cal 3 + echo "ComparePot1_pass $?" >>$props_result_file + fi -#------------------------------- -#echo $out_pot2 -#------------------------------- -if ! test -z "$out_pot" && [ $out_pot == 2 ]; then - pot1ref=potes.cube.ref - pot1cal=OUT.autotest/potes.cube - python3 $COMPARE_SCRIPT $pot1ref $pot1cal 8 - echo "ComparePot_pass $?" >>$props_result_file -fi + #------------------------------- + #echo $out_pot2 + #------------------------------- + if ! test -z "$out_pot" && [ $out_pot == 2 ]; then + pot1ref=potes.cube.ref + pot1cal=OUT.autotest/potes.cube + python3 $COMPARE_SCRIPT $pot1ref $pot1cal 8 + echo "ComparePot_pass $?" >>$props_result_file + fi -#------------------------------- -# Electron localized function -# echo $out_elf -#------------------------------- -if ! test -z "$out_elf" && [ $out_elf == 1 ]; then - elf1ref=elftot.cube.ref - elf1cal=OUT.autotest/elftot.cube - python3 $COMPARE_SCRIPT $elf1ref $elf1cal 3 - echo "ComparePot1_pass $?" >>$props_result_file -fi + #------------------------------- + # Electron localized function + # echo $out_elf + #------------------------------- + if ! test -z "$out_elf" && [ $out_elf == 1 ]; then + elf1ref=elftot.cube.ref + elf1cal=OUT.autotest/elftot.cube + python3 $COMPARE_SCRIPT $elf1ref $elf1cal 3 + echo "ComparePot1_pass $?" >>$props_result_file + fi } -run_cube_props(){ +run_cube_props() { -#--------------------------------------- -# Charge density -#--------------------------------------- -#echo $out_chg -if ! test -z "$out_chg" && [ $out_chg -ge 1 ]; then - record_compare_result "$props_result_file" "chg.cube_pass" "chg.cube.ref" "OUT.autotest/chg.cube" 6 -fi + #--------------------------------------- + # Charge density + #--------------------------------------- + #echo $out_chg + if ! test -z "$out_chg" && [ $out_chg -ge 1 ]; then + record_compare_result "$props_result_file" "chg.cube_pass" "chg.cube.ref" "OUT.autotest/chg.cube" 6 + fi - -#--------------------------------------- -# SCAN exchange-correlation information -#echo $has_scan -#--------------------------------------- -if ! test -z "$has_scan" && [ $has_scan == "scan" ] && \ - ! test -z "$out_chg" && [ $out_chg == 1 ]; then + #--------------------------------------- + # SCAN exchange-correlation information + #echo $has_scan + #--------------------------------------- + if ! test -z "$has_scan" && [ $has_scan == "scan" ] && + ! test -z "$out_chg" && [ $out_chg == 1 ]; then python3 $COMPARE_SCRIPT tau.cube.ref OUT.autotest/tau.cube 8 echo "tau.cube_pass $?" >>$props_result_file -fi + fi -#--------------------------------------- -# local density of states -# echo $has_ldos -#--------------------------------------- -if ! test -z "$has_ldos" && [ $has_ldos == 1 ]; then + #--------------------------------------- + # local density of states + # echo $has_ldos + #--------------------------------------- + if ! test -z "$has_ldos" && [ $has_ldos == 1 ]; then stm_bias=$(get_input_key_value "stm_bias" "OUT.autotest/INPUT.info") python3 $COMPARE_SCRIPT ldos.cube.ref OUT.autotest/ldos_"$stm_bias"ev.cube 8 - echo "ldos.cube_pass $?" >> $props_result_file -fi + echo "ldos.cube_pass $?" >>$props_result_file + fi -#--------------------------------------- -# wave functions in real space -# echo "$has_wfc_r" ## test out_wfc_r > 0 -#--------------------------------------- -if ! test -z "$has_wfc_r" && [ $has_wfc_r == 1 ]; then - if [[ ! -f OUT.autotest/running_scf.log ]];then - echo "Can't find file OUT.autotest/running_scf.log" - exit 1 - fi - nband=$(grep NBANDS OUT.autotest/running_scf.log|awk '{print $3}') + #--------------------------------------- + # wave functions in real space + # echo "$has_wfc_r" ## test out_wfc_r > 0 + #--------------------------------------- + if ! test -z "$has_wfc_r" && [ $has_wfc_r == 1 ]; then + if [[ ! -f OUT.autotest/running_scf.log ]]; then + echo "Can't find file OUT.autotest/running_scf.log" + exit 1 + fi + nband=$(grep NBANDS OUT.autotest/running_scf.log | awk '{print $3}') allgrid=$(grep "fft grid for wave functions" OUT.autotest/running_scf.log | awk -F "[=,\\\[\\\]]" '{print $3*$4*$5}') - for((band=0;band<$nband;band++));do - if [[ -f "OUT.autotest/wfc_realspace/wfc_realspace_0_$band" ]];then - variance_wfc_r=`sed -n "13,$"p OUT.autotest/wfc_realspace/wfc_realspace_0_$band | \ - awk -v all=$allgrid 'BEGIN {sumall=0} {for(i=1;i<=NF;i++) {sumall+=($i-1)*($i-1)}}\ - END {printf"%.5f",(sumall/all)}'` - echo "variance_wfc_r_0_$band $variance_wfc_r" >>$props_result_file - else - echo "Can't find file OUT.autotest/wfc_realspace/wfc_realspace_0_$band" - exit 1 - fi - done -fi + for ((band = 0; band < $nband; band++)); do + if [[ -f "OUT.autotest/wfc_realspace/wfc_realspace_0_$band" ]]; then + variance_wfc_r=$(sed -n "13,$"p OUT.autotest/wfc_realspace/wfc_realspace_0_$band | + awk -v all=$allgrid 'BEGIN {sumall=0} {for(i=1;i<=NF;i++) {sumall+=($i-1)*($i-1)}}\ + END {printf"%.5f",(sumall/all)}') + echo "variance_wfc_r_0_$band $variance_wfc_r" >>$props_result_file + else + echo "Can't find file OUT.autotest/wfc_realspace/wfc_realspace_0_$band" + exit 1 + fi + done + fi -#-------------------------------------------- -# wave functions in plane wave basis -# echo "$has_wfc_pw" ## test out_wfc_pw > 0 -#-------------------------------------------- -if ! test -z "$has_wfc_pw" && [ $has_wfc_pw == 1 ]; then + #-------------------------------------------- + # wave functions in plane wave basis + # echo "$has_wfc_pw" ## test out_wfc_pw > 0 + #-------------------------------------------- + if ! test -z "$has_wfc_pw" && [ $has_wfc_pw == 1 ]; then # according to nspin value if [ "$nspin" -eq 1 ]; then - filename="wfk1_pw.txt" + filename="wfk1_pw.txt" elif [ "$nspin" -eq 2 ]; then - filename="wfk1s1_pw.txt" + filename="wfk1s1_pw.txt" else - # other nspin cases - echo "Unsupported nspin value: $nspin" - exit 1 + # other nspin cases + echo "Unsupported nspin value: $nspin" + exit 1 fi full_path="OUT.autotest/$filename" - if [[ ! -f "$full_path" ]];then - echo "Can't find file $full_path" - exit 1 - fi - awk 'BEGIN {max=0;read=0;band=1} + if [[ ! -f "$full_path" ]]; then + echo "Can't find file $full_path" + exit 1 + fi + awk 'BEGIN {max=0;read=0;band=1} { if(read==0 && $2 == "Band" && $3 == band){read=1} else if(read==1 && $2 == "Band" && $3 == band) @@ -139,27 +138,26 @@ if ! test -z "$has_wfc_pw" && [ $has_wfc_pw == 1 ]; then if(sqrt($i*$i)>max) {max=sqrt($i*$i)} } } - }' "$full_path" >> "$props_result_file" -fi + }' "$full_path" >>"$props_result_file" + fi - -#-------------------------------------------- -# wave functions in LCAO basis -# echo "$has_lowf" # test out_wfc_lcao > 0 -#-------------------------------------------- -if ! test -z "$has_lowf" && [ "$has_lowf" == 1 ]; then - if ! test -z "$gamma_only" && [ $gamma_only == 1 ]; then - wfc_cal=OUT.autotest/wf_nao.txt - wfc_ref=wf_nao.txt.ref - else # multi-k point case - if ! test -z "$out_app_flag" && [ $out_app_flag == 0 ]; then - wfc_name=wfk1g3_nao - input_file=WFC/wfk1g3_nao - else - wfc_name=wfk2_nao - input_file=wfk2_nao - fi - awk 'BEGIN {flag=999} + #-------------------------------------------- + # wave functions in LCAO basis + # echo "$has_lowf" # test out_wfc_lcao > 0 + #-------------------------------------------- + if ! test -z "$has_lowf" && [ "$has_lowf" == 1 ]; then + if ! test -z "$gamma_only" && [ $gamma_only == 1 ]; then + wfc_cal=OUT.autotest/wf_nao.txt + wfc_ref=wf_nao.txt.ref + else # multi-k point case + if ! test -z "$out_app_flag" && [ $out_app_flag == 0 ]; then + wfc_name=wfk1g3_nao + input_file=WFC/wfk1g3_nao + else + wfc_name=wfk2_nao + input_file=wfk2_nao + fi + awk 'BEGIN {flag=999} { if($2 == "(band)") {flag=2;print $0} else if(flag>0) {flag-=1;print $0} @@ -170,133 +168,133 @@ if ! test -z "$has_lowf" && [ "$has_lowf" == 1 ]; then printf "\n" } else {print $0} - }' OUT.autotest/"$input_file".txt > OUT.autotest/"$wfc_name"_mod.txt - wfc_cal=OUT.autotest/"$wfc_name"_mod.txt - wfc_ref="$wfc_name"_mod.txt.ref - fi + }' OUT.autotest/"$input_file".txt >OUT.autotest/"$wfc_name"_mod.txt + wfc_cal=OUT.autotest/"$wfc_name"_mod.txt + wfc_ref="$wfc_name"_mod.txt.ref + fi - python3 $COMPARE_SCRIPT $wfc_cal $wfc_ref 8 -abs 1 - echo "Compare_wfc_lcao_pass $?" >>$props_result_file -fi + python3 $COMPARE_SCRIPT $wfc_cal $wfc_ref 8 -abs 1 + echo "Compare_wfc_lcao_pass $?" >>$props_result_file + fi } -run_cube_tail_props(){ +run_cube_tail_props() { -#-------------------------------------------- -# mulliken charge -#-------------------------------------------- -if ! test -z "$out_mul" && [ $out_mul == 1 ]; then + #-------------------------------------------- + # mulliken charge + #-------------------------------------------- + if ! test -z "$out_mul" && [ $out_mul == 1 ]; then python3 $COMPARE_SCRIPT mulliken.txt.ref OUT.autotest/mulliken.txt 3 - echo "Compare_mulliken_pass $?" >>$props_result_file -fi + echo "Compare_mulliken_pass $?" >>$props_result_file + fi -#-------------------------------------------- -# Process .cube files for: -# 1. get_wf/get_pchg calculation tag (LCAO) -# 2. out_wfc_norm/out_wfc_re_im/out_pchg (PW) -#-------------------------------------------- -shopt -s nullglob -local pchg_tol=1e-6 -if [ -f threshold ]; then + #-------------------------------------------- + # Process .cube files for: + # 1. get_wf/get_pchg calculation tag (LCAO) + # 2. out_wfc_norm/out_wfc_re_im/out_pchg (PW) + #-------------------------------------------- + shopt -s nullglob + local pchg_tol=1e-6 + if [ -f threshold ]; then local configured_tol configured_tol=$(get_input_key_value pchg_threshold threshold) if [ -n "$configured_tol" ]; then - pchg_tol=$configured_tol + pchg_tol=$configured_tol fi -fi -for pchg_ref in pchgi*.cube.ref; do + fi + for pchg_ref in pchgi*.cube.ref; do pchg_cube=${pchg_ref%.ref} pchg_key=$(sanitize_result_key "${pchg_cube}_compare") if [ ! -f "OUT.autotest/$pchg_cube" ]; then - echo "$pchg_key 1" >> "$props_result_file" - continue + echo "$pchg_key 1" >>"$props_result_file" + continue fi python3 "$COMPARE_SCRIPT" "$pchg_ref" "OUT.autotest/$pchg_cube" -tol "$pchg_tol" - echo "$pchg_key $?" >> "$props_result_file" -done -shopt -u nullglob + echo "$pchg_key $?" >>"$props_result_file" + done + shopt -u nullglob -need_process_cube=false -# Check if this is a LCAO calculation with get_wf/get_pchg -if [ $calculation == "get_wf" ] || [ $calculation == "get_pchg" ]; then + need_process_cube=false + # Check if this is a LCAO calculation with get_wf/get_pchg + if [ $calculation == "get_wf" ] || [ $calculation == "get_pchg" ]; then need_process_cube=true -fi -# Check if this is a PW calculation with out_wfc_norm/out_wfc_re_im -out_wfc_norm=$(get_input_key_value "out_wfc_norm" "INPUT") -out_wfc_re_im=$(get_input_key_value "out_wfc_re_im" "INPUT") -out_pchg=$(get_input_key_value "out_pchg" "INPUT") -if [ -n "$out_wfc_norm" ] || [ -n "$out_wfc_re_im" ] || [ -n "$out_pchg" ]; then + fi + # Check if this is a PW calculation with out_wfc_norm/out_wfc_re_im + out_wfc_norm=$(get_input_key_value "out_wfc_norm" "INPUT") + out_wfc_re_im=$(get_input_key_value "out_wfc_re_im" "INPUT") + out_pchg=$(get_input_key_value "out_pchg" "INPUT") + if [ -n "$out_wfc_norm" ] || [ -n "$out_wfc_re_im" ] || [ -n "$out_pchg" ]; then need_process_cube=true -fi -# Process .cube files if needed -if [ "$need_process_cube" = true ]; then + fi + # Process .cube files if needed + if [ "$need_process_cube" = true ]; then cubefiles=$(ls OUT.autotest/ | grep -E '.cube$') wavefunction_re_files=() if [ -z "$cubefiles" ]; then - echo "Error: No .cube files found in OUT.autotest/" - exit 1 + echo "Error: No .cube files found in OUT.autotest/" + exit 1 else - for cube in $cubefiles; do - if [[ "$cube" =~ ^wfi[0-9]+s[0-9]+(k[0-9]+)?re[.]cube$ ]]; then - wavefunction_re_files+=("$cube") - continue - fi - if [[ "$cube" =~ ^wfi[0-9]+s[0-9]+(k[0-9]+)?im[.]cube$ ]]; then - continue - fi - total_chg=$(python3 "$CUBE_TOOL" integrate "OUT.autotest/$cube") - echo "$cube $total_chg" >> $props_result_file - done + for cube in $cubefiles; do + if [[ "$cube" =~ ^wfi[0-9]+s[0-9]+(k[0-9]+)?re[.]cube$ ]]; then + wavefunction_re_files+=("$cube") + continue + fi + if [[ "$cube" =~ ^wfi[0-9]+s[0-9]+(k[0-9]+)?im[.]cube$ ]]; then + continue + fi + total_chg=$(python3 "$CUBE_TOOL" integrate "OUT.autotest/$cube") + echo "$cube $total_chg" >>$props_result_file + done fi for cube in "${wavefunction_re_files[@]}"; do - if [[ "$cube" =~ ^wfi([0-9]+)s([0-9]+)(k[0-9]+)?re[.]cube$ ]]; then - band=${BASH_REMATCH[1]} - spin=${BASH_REMATCH[2]} - kpoint=${BASH_REMATCH[3]} - state_prefix=${cube%re.cube} - fingerprint_args=( - "OUT.autotest/$cube" - "OUT.autotest/${state_prefix}im.cube" - ) - if [ "$nspin" = "4" ]; then - if [ "$spin" != "1" ]; then - continue - fi - lower_prefix="wfi${band}s2${kpoint}" - fingerprint_args+=( - "OUT.autotest/${lower_prefix}re.cube" - "OUT.autotest/${lower_prefix}im.cube" - ) - result_prefix="wfi${band}${kpoint}_spinor_wfc_fp" - else - result_prefix="${state_prefix}_wfc_fp" - fi + if [[ "$cube" =~ ^wfi([0-9]+)s([0-9]+)(k[0-9]+)?re[.]cube$ ]]; then + band=${BASH_REMATCH[1]} + spin=${BASH_REMATCH[2]} + kpoint=${BASH_REMATCH[3]} + state_prefix=${cube%re.cube} + fingerprint_args=( + "OUT.autotest/$cube" + "OUT.autotest/${state_prefix}im.cube" + ) + if [ "$nspin" = "4" ]; then + if [ "$spin" != "1" ]; then + continue + fi + lower_prefix="wfi${band}s2${kpoint}" + fingerprint_args+=( + "OUT.autotest/${lower_prefix}re.cube" + "OUT.autotest/${lower_prefix}im.cube" + ) + result_prefix="wfi${band}${kpoint}_spinor_wfc_fp" + else + result_prefix="${state_prefix}_wfc_fp" + fi - if fingerprint=$(python3 "$CUBE_TOOL" fingerprint-wfc "${fingerprint_args[@]}"); then - while read -r metric value; do - echo "${result_prefix}_${metric} $value" >> "$props_result_file" - done <<< "$fingerprint" - else - echo "Error: Failed to generate wavefunction fingerprint for $state_prefix" - exit 1 - fi + if fingerprint=$(python3 "$CUBE_TOOL" fingerprint-wfc "${fingerprint_args[@]}"); then + while read -r metric value; do + echo "${result_prefix}_${metric} $value" >>"$props_result_file" + done <<<"$fingerprint" + else + echo "Error: Failed to generate wavefunction fingerprint for $state_prefix" + exit 1 fi + fi done -fi + fi -# Check the pointwise Pauli identities when all PW nspin=4 spinor outputs are available. -nspin=$(get_input_key_value "nspin" "INPUT") -if_separate_k=$(get_input_key_value "if_separate_k" "INPUT") -if [ "$nspin" = "4" ] && { [ "$if_separate_k" = "1" ] || [ "$if_separate_k" = "true" ]; } \ - && [ -n "$out_wfc_norm" ] && [ -n "$out_wfc_re_im" ] && [ -n "$out_pchg" ]; then + # Check the pointwise Pauli identities when all PW nspin=4 spinor outputs are available. + nspin=$(get_input_key_value "nspin" "INPUT") + if_separate_k=$(get_input_key_value "if_separate_k" "INPUT") + if [ "$nspin" = "4" ] && { [ "$if_separate_k" = "1" ] || [ "$if_separate_k" = "true" ]; } && + [ -n "$out_wfc_norm" ] && [ -n "$out_wfc_re_im" ] && [ -n "$out_pchg" ]; then if python3 "$CUBE_TOOL" check-spinor OUT.autotest; then - echo "pw_spinor_cube_identity 0" >> "$props_result_file" + echo "pw_spinor_cube_identity 0" >>"$props_result_file" else - echo "pw_spinor_cube_identity 1" >> "$props_result_file" + echo "pw_spinor_cube_identity 1" >>"$props_result_file" fi -fi + fi } diff --git a/tests/integrate/validation_tools/props_deepks.sh b/tests/integrate/validation_tools/props_deepks.sh index 918eee161ac..ae3d8a69b14 100644 --- a/tests/integrate/validation_tools/props_deepks.sh +++ b/tests/integrate/validation_tools/props_deepks.sh @@ -13,225 +13,225 @@ # General function to process npy files process_npy() { - local mode=$1 - local op=$2 - local file_prefix=$3 - local base_prefix=$4 - local output_name=$5 - - local total="0" - local file_pattern="" - local base_pattern="" - - # Check if force or stress - local is_force_or_stress=0 - if [ "$file_prefix" = "ftot" ] || [ "$file_prefix" = "stot" ]; then - is_force_or_stress=1 + local mode=$1 + local op=$2 + local file_prefix=$3 + local base_prefix=$4 + local output_name=$5 + + local total="0" + local file_pattern="" + local base_pattern="" + + # Check if force or stress + local is_force_or_stress=0 + if [ "$file_prefix" = "ftot" ] || [ "$file_prefix" = "stot" ]; then + is_force_or_stress=1 + fi + + # Determine file pattern based on mode + if [ "$mode" = "multi" ]; then + # multi mode: multiple files with _e* suffix from different electronic steps, unless for force and stress + if [ "$is_force_or_stress" -eq 1 ]; then + file_pattern="OUT.autotest/DeePKS_Labels_Elec/${file_prefix}.npy" + base_pattern="OUT.autotest/DeePKS_Labels_Elec/${base_prefix}.npy" + else + file_pattern="OUT.autotest/DeePKS_Labels_Elec/${file_prefix}_e*.npy" + base_pattern="OUT.autotest/DeePKS_Labels_Elec/${base_prefix}_e*.npy" + fi + elif [ "$mode" = "single" ]; then + # single mode: single file + file_pattern="OUT.autotest/deepks_${file_prefix}.npy" + base_pattern="OUT.autotest/deepks_${base_prefix}.npy" + fi + + # Process files + for file in $file_pattern; do + if [ ! -f "$file" ]; then + continue fi - # Determine file pattern based on mode + # Get step number for multi mode + # Force/stress multi-mode files (ftot.npy, stot.npy) carry no e + # suffix, so grep legitimately finds no match and returns 1. Tolerate + # the empty match explicitly so the step extraction is also safe when + # this module is sourced under `bash -e`. + local step="" if [ "$mode" = "multi" ]; then - # multi mode: multiple files with _e* suffix from different electronic steps, unless for force and stress - if [ "$is_force_or_stress" -eq 1 ] ; then - file_pattern="OUT.autotest/DeePKS_Labels_Elec/${file_prefix}.npy" - base_pattern="OUT.autotest/DeePKS_Labels_Elec/${base_prefix}.npy" - else - file_pattern="OUT.autotest/DeePKS_Labels_Elec/${file_prefix}_e*.npy" - base_pattern="OUT.autotest/DeePKS_Labels_Elec/${base_prefix}_e*.npy" - fi - elif [ "$mode" = "single" ];then - # single mode: single file - file_pattern="OUT.autotest/deepks_${file_prefix}.npy" - base_pattern="OUT.autotest/deepks_${base_prefix}.npy" + step=$(basename "$file" | grep -oP 'e\d+' || true) fi - # Process files - for file in $file_pattern; do - if [ ! -f "$file" ]; then - continue - fi - - # Get step number for multi mode - # Force/stress multi-mode files (ftot.npy, stot.npy) carry no e - # suffix, so grep legitimately finds no match and returns 1. Tolerate - # the empty match explicitly so the step extraction is also safe when - # this module is sourced under `bash -e`. - local step="" - if [ "$mode" = "multi" ]; then - step=$(basename "$file" | grep -oP 'e\d+' || true) - fi - - # Get corresponding base file - local base_file="" - if [ "$mode" = "multi" ] && [ "$is_force_or_stress" -ne 1 ]; then - base_file="OUT.autotest/DeePKS_Labels_Elec/${base_prefix}_${step}.npy" - else - base_file=$base_pattern - fi - - # Calculate value based on operation - if [ "$op" = "abs" ]; then - val=$(python3 ../tools/get_sum_abs.py "$file") - elif [ "$op" = "delta" ] && [ -f "$base_file" ]; then - val=$(python3 ../tools/get_sum_delta.py "$file" "$base_file") - elif [ "$op" = "numpy" ]; then - val=$(python3 ../tools/get_sum_numpy.py "$file") - else - val=0 - fi - - if [ "$mode" = "multi" ]; then - #echo "total: $total, val: $val" - total=$(echo "$total + $val" | bc) - else - total=$val - fi - done - - echo "$output_name $total" >>$6 -} - -# Process a group of label outputs -process_many_npys() { - local mode=$1 - local suffix=$2 - local output_file=$3 - - # energy - process_npy "$mode" "abs" "etot" "" "deepks_e_label$suffix" "$output_file" - process_npy "$mode" "delta" "etot" "ebase" "deepks_edelta$suffix" "$output_file" - - # For deepks_bandgap > 0 - if ! test -z "$deepks_bandgap" && [ $deepks_bandgap -gt 0 ]; then - process_npy "$mode" "abs" "otot" "" "deepks_o_label$suffix" "$output_file" - process_npy "$mode" "delta" "otot" "obase" "deepks_odelta$suffix" "$output_file" - process_npy "$mode" "numpy" "orbpre" "" "deepks_oprec$suffix" "$output_file" + # Get corresponding base file + local base_file="" + if [ "$mode" = "multi" ] && [ "$is_force_or_stress" -ne 1 ]; then + base_file="OUT.autotest/DeePKS_Labels_Elec/${base_prefix}_${step}.npy" + else + base_file=$base_pattern fi - # For deepks_v_delta > 0 - if ! test -z "$deepks_v_delta" && [ $deepks_v_delta -gt 0 ]; then - process_npy "$mode" "abs" "htot" "" "deepks_h_label$suffix" "$output_file" - process_npy "$mode" "delta" "htot" "hbase" "deepks_vdelta$suffix" "$output_file" - - if [ $deepks_v_delta == 1 ]; then - process_npy "$mode" "abs" "vdpre" "" "deepks_vdp$suffix" "$output_file" - elif [ $deepks_v_delta == 2 ]; then - process_npy "$mode" "abs" "phialpha" "" "deepks_phialpha$suffix" "$output_file" - process_npy "$mode" "numpy" "gevdm" "" "deepks_gevdm$suffix" "$output_file" - fi + # Calculate value based on operation + if [ "$op" = "abs" ]; then + val=$(python3 ../tools/get_sum_abs.py "$file") + elif [ "$op" = "delta" ] && [ -f "$base_file" ]; then + val=$(python3 ../tools/get_sum_delta.py "$file" "$base_file") + elif [ "$op" = "numpy" ]; then + val=$(python3 ../tools/get_sum_numpy.py "$file") + else + val=0 fi - if ! test -z "$has_force" && [ $has_force == 1 ]; then - process_npy "$mode" "abs" "ftot" "" "deepks_f_label$suffix" "$output_file" - process_npy "$mode" "delta" "ftot" "fbase" "deepks_fdelta$suffix" "$output_file" + if [ "$mode" = "multi" ]; then + #echo "total: $total, val: $val" + total=$(echo "$total + $val" | bc) + else + total=$val fi + done - # For cal_stress = 1 - if ! test -z "$has_stress" && [ $has_stress == 1 ]; then - process_npy "$mode" "abs" "stot" "" "deepks_s_label$suffix" "$output_file" - process_npy "$mode" "delta" "stot" "sbase" "deepks_sdelta$suffix" "$output_file" + echo "$output_name $total" >>$6 +} + +# Process a group of label outputs +process_many_npys() { + local mode=$1 + local suffix=$2 + local output_file=$3 + + # energy + process_npy "$mode" "abs" "etot" "" "deepks_e_label$suffix" "$output_file" + process_npy "$mode" "delta" "etot" "ebase" "deepks_edelta$suffix" "$output_file" + + # For deepks_bandgap > 0 + if ! test -z "$deepks_bandgap" && [ $deepks_bandgap -gt 0 ]; then + process_npy "$mode" "abs" "otot" "" "deepks_o_label$suffix" "$output_file" + process_npy "$mode" "delta" "otot" "obase" "deepks_odelta$suffix" "$output_file" + process_npy "$mode" "numpy" "orbpre" "" "deepks_oprec$suffix" "$output_file" + fi + + # For deepks_v_delta > 0 + if ! test -z "$deepks_v_delta" && [ $deepks_v_delta -gt 0 ]; then + process_npy "$mode" "abs" "htot" "" "deepks_h_label$suffix" "$output_file" + process_npy "$mode" "delta" "htot" "hbase" "deepks_vdelta$suffix" "$output_file" + + if [ $deepks_v_delta == 1 ]; then + process_npy "$mode" "abs" "vdpre" "" "deepks_vdp$suffix" "$output_file" + elif [ $deepks_v_delta == 2 ]; then + process_npy "$mode" "abs" "phialpha" "" "deepks_phialpha$suffix" "$output_file" + process_npy "$mode" "numpy" "gevdm" "" "deepks_gevdm$suffix" "$output_file" fi + fi + + if ! test -z "$has_force" && [ $has_force == 1 ]; then + process_npy "$mode" "abs" "ftot" "" "deepks_f_label$suffix" "$output_file" + process_npy "$mode" "delta" "ftot" "fbase" "deepks_fdelta$suffix" "$output_file" + fi + + # For cal_stress = 1 + if ! test -z "$has_stress" && [ $has_stress == 1 ]; then + process_npy "$mode" "abs" "stot" "" "deepks_s_label$suffix" "$output_file" + process_npy "$mode" "delta" "stot" "sbase" "deepks_sdelta$suffix" "$output_file" + fi } -run_deepks_props(){ - -# Main script -# cal_force/cal_stress are also parsed by props_init(); they are re-read here -# because the standalone catch_deepks_properties.sh entry skips props_init(). -has_force=$(get_input_key_value "cal_force" "INPUT") -has_stress=$(get_input_key_value "cal_stress" "INPUT") -deepks_out_labels=$(get_input_key_value "deepks_out_labels" "INPUT") -deepks_scf=$(get_input_key_value "deepks_scf" "INPUT") -deepks_bandgap=$(get_input_key_value "deepks_bandgap" "INPUT") -deepks_v_delta=$(get_input_key_value "deepks_v_delta" "INPUT") -deepks_out_freq_elec=$(get_input_key_value "deepks_out_freq_elec" "INPUT") - -#--------------------------------------------------------------------------- -# Test for descriptor -#--------------------------------------------------------------------------- -if ! test -z "$deepks_scf" && [ $deepks_scf == 1 ]; then +run_deepks_props() { + + # Main script + # cal_force/cal_stress are also parsed by props_init(); they are re-read here + # because the standalone catch_deepks_properties.sh entry skips props_init(). + has_force=$(get_input_key_value "cal_force" "INPUT") + has_stress=$(get_input_key_value "cal_stress" "INPUT") + deepks_out_labels=$(get_input_key_value "deepks_out_labels" "INPUT") + deepks_scf=$(get_input_key_value "deepks_scf" "INPUT") + deepks_bandgap=$(get_input_key_value "deepks_bandgap" "INPUT") + deepks_v_delta=$(get_input_key_value "deepks_v_delta" "INPUT") + deepks_out_freq_elec=$(get_input_key_value "deepks_out_freq_elec" "INPUT") + + #--------------------------------------------------------------------------- + # Test for descriptor + #--------------------------------------------------------------------------- + if ! test -z "$deepks_scf" && [ $deepks_scf == 1 ]; then # Process descriptor data - sed '/n_des/d' OUT.autotest/deepks_desc.dat > des_tmp.txt + sed '/n_des/d' OUT.autotest/deepks_desc.dat >des_tmp.txt total_des=$(sum_file des_tmp.txt 5) rm des_tmp.txt echo "deepks_desc $total_des" >>$props_result_file process_npy "single" "abs" "dm_eig" "" "deepks_dm_eig" "$props_result_file" -fi + fi -#--------------------------------------------------------------------------- -# Test for deepks_out_labels = 1 and deepks_out_freq_elec > 0 -#--------------------------------------------------------------------------- -if ! test -z "$deepks_out_labels" && [ $deepks_out_labels == 1 ]; then + #--------------------------------------------------------------------------- + # Test for deepks_out_labels = 1 and deepks_out_freq_elec > 0 + #--------------------------------------------------------------------------- + if ! test -z "$deepks_out_labels" && [ $deepks_out_labels == 1 ]; then process_many_npys "single" "" "$props_result_file" - # gradvx and gvepsl not considered in deepks_out_freq_elec > 0, so not in process_many_npys + # gradvx and gvepsl not considered in deepks_out_freq_elec > 0, so not in process_many_npys # For cal_force = 1 if ! test -z "$has_force" && [ $has_force == 1 ]; then - process_npy "single" "abs" "gradvx" "" "deepks_fpre" "$props_result_file" + process_npy "single" "abs" "gradvx" "" "deepks_fpre" "$props_result_file" fi # For cal_stress = 1 if ! test -z "$has_stress" && [ $has_stress == 1 ]; then - process_npy "single" "abs" "gvepsl" "" "deepks_spre" "$props_result_file" + process_npy "single" "abs" "gvepsl" "" "deepks_spre" "$props_result_file" fi # For deepks_v_delta < 0 # CompareFile.py exits 1 when the files differ; capture the status in a # named variable so it is recorded even when sourced under `bash -e`. if ! test -z "$deepks_v_delta" && [ $deepks_v_delta -lt 0 ]; then - hr_pass=0 - python3 $COMPARE_SCRIPT "deepks_hrtot.csr.ref" "OUT.autotest/deepks_hrtot.csr" 8 || hr_pass=$? - echo "deepks_hr_label_pass $hr_pass" >>$props_result_file - hrdelta_pass=0 - python3 $COMPARE_SCRIPT "deepks_hrdelta.csr.ref" "OUT.autotest/deepks_hrdelta.csr" 8 || hrdelta_pass=$? - echo "deepks_vdelta_r_pass $hrdelta_pass" >>$props_result_file - # For deepks_v_delta = -1 - if [ $deepks_v_delta -eq -1 ]; then - process_npy "single" "abs" "vdrpre" "" "deepks_vdrp" "$props_result_file" - fi - # For deepks_v_delta = -2 - if [ $deepks_v_delta -eq -2 ]; then - process_npy "single" "abs" "phialpha_r" "" "deepks_phialpha_r" "$props_result_file" - process_npy "single" "numpy" "gevdm" "" "deepks_gevdm" "$props_result_file" - fi + hr_pass=0 + python3 $COMPARE_SCRIPT "deepks_hrtot.csr.ref" "OUT.autotest/deepks_hrtot.csr" 8 || hr_pass=$? + echo "deepks_hr_label_pass $hr_pass" >>$props_result_file + hrdelta_pass=0 + python3 $COMPARE_SCRIPT "deepks_hrdelta.csr.ref" "OUT.autotest/deepks_hrdelta.csr" 8 || hrdelta_pass=$? + echo "deepks_vdelta_r_pass $hrdelta_pass" >>$props_result_file + # For deepks_v_delta = -1 + if [ $deepks_v_delta -eq -1 ]; then + process_npy "single" "abs" "vdrpre" "" "deepks_vdrp" "$props_result_file" + fi + # For deepks_v_delta = -2 + if [ $deepks_v_delta -eq -2 ]; then + process_npy "single" "abs" "phialpha_r" "" "deepks_phialpha_r" "$props_result_file" + process_npy "single" "numpy" "gevdm" "" "deepks_gevdm" "$props_result_file" + fi fi # Process deepks_out_freq_elec > 0 if [ ! -z "$deepks_out_freq_elec" ] && [ $deepks_out_freq_elec -gt 0 ]; then - process_many_npys "multi" "_elec" "$props_result_file" - if ! test -z "$deepks_v_delta" && [[ $deepks_v_delta -gt 0 ]]; then - process_npy "single" "abs" "overlap" "" "deepks_overlap" "$props_result_file" - process_npy "multi" "abs" "overlap" "" "deepks_overlap_elec" "$props_result_file" + process_many_npys "multi" "_elec" "$props_result_file" + if ! test -z "$deepks_v_delta" && [[ $deepks_v_delta -gt 0 ]]; then + process_npy "single" "abs" "overlap" "" "deepks_overlap" "$props_result_file" + process_npy "multi" "abs" "overlap" "" "deepks_overlap_elec" "$props_result_file" - fi + fi fi -fi + fi -#--------------------------------------------------------------------------- -# Test for deepks_out_labels = 2 -#--------------------------------------------------------------------------- -if ! test -z "$deepks_out_labels" && [ $deepks_out_labels == 2 ]; then + #--------------------------------------------------------------------------- + # Test for deepks_out_labels = 2 + #--------------------------------------------------------------------------- + if ! test -z "$deepks_out_labels" && [ $deepks_out_labels == 2 ]; then process_npy "single" "numpy" "atom" "" "deepks_atom" "$props_result_file" process_npy "single" "numpy" "box" "" "deepks_box" "$props_result_file" process_npy "single" "numpy" "energy" "" "deepks_energy" "$props_result_file" if ! test -z "$has_force" && [ $has_force == 1 ]; then - process_npy "single" "numpy" "force" "" "deepks_force" "$props_result_file" + process_npy "single" "numpy" "force" "" "deepks_force" "$props_result_file" fi if ! test -z "$has_stress" && [ $has_stress == 1 ]; then - process_npy "single" "numpy" "stress" "" "deepks_stress" "$props_result_file" + process_npy "single" "numpy" "stress" "" "deepks_stress" "$props_result_file" fi if ! test -z "$deepks_bandgap" && [ $deepks_bandgap == 1 ]; then - process_npy "single" "numpy" "orbital" "" "deepks_orbital" "$props_result_file" + process_npy "single" "numpy" "orbital" "" "deepks_orbital" "$props_result_file" fi if ! test -z "$deepks_v_delta" && [[ $deepks_v_delta -gt 0 ]]; then - process_npy "single" "numpy" "hamiltonian" "" "deepks_hamiltonian" "$props_result_file" - process_npy "single" "numpy" "overlap" "" "deepks_overlap" "$props_result_file" + process_npy "single" "numpy" "hamiltonian" "" "deepks_hamiltonian" "$props_result_file" + process_npy "single" "numpy" "overlap" "" "deepks_overlap" "$props_result_file" fi -fi + fi } diff --git a/tests/integrate/validation_tools/props_lr.sh b/tests/integrate/validation_tools/props_lr.sh index eacd02fbe3c..bd754fc71ea 100644 --- a/tests/integrate/validation_tools/props_lr.sh +++ b/tests/integrate/validation_tools/props_lr.sh @@ -3,42 +3,42 @@ # LR-TDDFT collectors, sourced after props_common.sh and props_init(). # Tracking cases emit one invariant check and bypass single-point collectors. # Return success only when a tracking reference was handled. -run_lr_tracking_props(){ - if [ "$is_lr" != 1 ] || [ ! -f state_tracking.ref ]; then - return 1 - fi - if python3 "$PROPS_SCRIPT_DIR/excited_state_check.py" "$running_path" state_tracking.ref; then - echo "CompareStateTracking_pass 0" >> "$props_result_file" - else - echo "CompareStateTracking_pass 1" >> "$props_result_file" - fi - return 0 +run_lr_tracking_props() { + if [ "$is_lr" != 1 ] || [ ! -f state_tracking.ref ]; then + return 1 + fi + if python3 "$PROPS_SCRIPT_DIR/excited_state_check.py" "$running_path" state_tracking.ref; then + echo "CompareStateTracking_pass 0" >>"$props_result_file" + else + echo "CompareStateTracking_pass 1" >>"$props_result_file" + fi + return 0 } # Reuse the generic force property; LR cases set force_threshold in their # per-case threshold file, independently of excitation-energy accuracy. -run_lr_force_props(){ -# LR prints a separate force table for each excited state and spin channel. -if [ $is_lr == 1 ] && ! test -z "$has_force" && [ $has_force == 1 ]; then - awk '/Forces \(-gradients\) of each excited state/{flag=1; next} flag{for(i=1;i<=NF;i++) if($i=="force"){print $(i+1),$(i+2),$(i+3)}}' "$running_path" > lr_force.txt - # Accumulate all components before rounding the LR force total. - total_lr_force=$(awk '{for (i=1; i<=NF; ++i) sum += sqrt($i*$i)} END {printf "%.10f\n", sum}' lr_force.txt) - rm lr_force.txt - echo "totalforceref $total_lr_force" >>$props_result_file - # Keep the historical total, and independently check signed, labelled components. - local force_tolerance=0.000001 - if [ -f threshold ]; then - local configured_force_tolerance - configured_force_tolerance=$(get_input_key_value force_threshold threshold) - if [ -n "$configured_force_tolerance" ]; then - force_tolerance=$configured_force_tolerance - fi - fi - if python3 "$PROPS_SCRIPT_DIR/lr_force_check.py" "$running_path" lr_force.ref "$force_tolerance"; then - echo "CompareLRForce_pass 0" >> "$props_result_file" - else - echo "CompareLRForce_pass 1" >> "$props_result_file" - fi -fi +run_lr_force_props() { + # LR prints a separate force table for each excited state and spin channel. + if [ $is_lr == 1 ] && ! test -z "$has_force" && [ $has_force == 1 ]; then + awk '/Forces \(-gradients\) of each excited state/{flag=1; next} flag{for(i=1;i<=NF;i++) if($i=="force"){print $(i+1),$(i+2),$(i+3)}}' "$running_path" >lr_force.txt + # Accumulate all components before rounding the LR force total. + total_lr_force=$(awk '{for (i=1; i<=NF; ++i) sum += sqrt($i*$i)} END {printf "%.10f\n", sum}' lr_force.txt) + rm lr_force.txt + echo "totalforceref $total_lr_force" >>$props_result_file + # Keep the historical total, and independently check signed, labelled components. + local force_tolerance=0.000001 + if [ -f threshold ]; then + local configured_force_tolerance + configured_force_tolerance=$(get_input_key_value force_threshold threshold) + if [ -n "$configured_force_tolerance" ]; then + force_tolerance=$configured_force_tolerance + fi + fi + if python3 "$PROPS_SCRIPT_DIR/lr_force_check.py" "$running_path" lr_force.ref "$force_tolerance"; then + echo "CompareLRForce_pass 0" >>"$props_result_file" + else + echo "CompareLRForce_pass 1" >>"$props_result_file" + fi + fi } diff --git a/tests/integrate/validation_tools/props_mat.sh b/tests/integrate/validation_tools/props_mat.sh index 5128c3dd379..4f27ed8fe53 100644 --- a/tests/integrate/validation_tools/props_mat.sh +++ b/tests/integrate/validation_tools/props_mat.sh @@ -20,351 +20,351 @@ # stripped, and the E_Fermi values are compared separately at 1e-3 eV. # A missing file is reported as a failure (process substitution would # otherwise hand CompareFile.py an empty stream and pass silently). -compare_hr_csr(){ - local ref=$1 - local cal=$2 - local strip='s/, E_Fermi = [0-9.eE+-]* eV//' - local pick='s/.*E_Fermi = \([0-9.eE+-]*\) eV.*/\1/p' - if ! test -f "$ref" || ! test -f "$cal"; then - echo "Error: can not find file $ref or $cal" - return 1 - fi - python3 $COMPARE_SCRIPT <(sed "$strip" "$ref") <(sed "$strip" "$cal") 8 || return 1 - if [ "$(sed -n "$pick" "$ref" | wc -l)" -ne "$(sed -n "$pick" "$cal" | wc -l)" ]; then - echo "Error: E_Fermi annotation count differs between $ref and $cal" - return 1 - fi - python3 $COMPARE_SCRIPT <(sed -n "$pick" "$ref") <(sed -n "$pick" "$cal") 3 +compare_hr_csr() { + local ref=$1 + local cal=$2 + local strip='s/, E_Fermi = [0-9.eE+-]* eV//' + local pick='s/.*E_Fermi = \([0-9.eE+-]*\) eV.*/\1/p' + if ! test -f "$ref" || ! test -f "$cal"; then + echo "Error: can not find file $ref or $cal" + return 1 + fi + python3 $COMPARE_SCRIPT <(sed "$strip" "$ref") <(sed "$strip" "$cal") 8 || return 1 + if [ "$(sed -n "$pick" "$ref" | wc -l)" -ne "$(sed -n "$pick" "$cal" | wc -l)" ]; then + echo "Error: E_Fermi annotation count differs between $ref and $cal" + return 1 + fi + python3 $COMPARE_SCRIPT <(sed -n "$pick" "$ref") <(sed -n "$pick" "$cal") 3 } -run_mat_dm1_props(){ +run_mat_dm1_props() { -#------------------------------- -# echo $out_dm1 -#------------------------------- -if ! test -z "$out_dm1" && [ $out_dm1 == 1 ]; then - dm1ref=dmr_nao.csr.ref - dm1cal=OUT.autotest/dmr_nao.csr - python3 $COMPARE_SCRIPT $dm1ref $dm1cal 8 - echo "CompareDM1_pass $?" >>$props_result_file -fi + #------------------------------- + # echo $out_dm1 + #------------------------------- + if ! test -z "$out_dm1" && [ $out_dm1 == 1 ]; then + dm1ref=dmr_nao.csr.ref + dm1cal=OUT.autotest/dmr_nao.csr + python3 $COMPARE_SCRIPT $dm1ref $dm1cal 8 + echo "CompareDM1_pass $?" >>$props_result_file + fi } -run_mat_props(){ +run_mat_props() { -#------------------------------- -# Overlap matrix -# calculation == get_s -#------------------------------- -if [ "$calculation" == "get_s" ]; then - sref=sr_nao.csr.ref - scal=OUT.autotest/sr_nao.csr - python3 $COMPARE_SCRIPT $sref $scal 8 - echo "CompareS_pass $?" >>$props_result_file -fi + #------------------------------- + # Overlap matrix + # calculation == get_s + #------------------------------- + if [ "$calculation" == "get_s" ]; then + sref=sr_nao.csr.ref + scal=OUT.autotest/sr_nao.csr + python3 $COMPARE_SCRIPT $sref $scal 8 + echo "CompareS_pass $?" >>$props_result_file + fi -#------------------------------- -# Partial band structure -# echo $out_pband -#------------------------------- -if ! test -z "$out_pband" && [ $out_pband == 1 ]; then - orbref=refOrbital - orbcal=OUT.autotest/Orbital - python3 $COMPARE_SCRIPT $orbref $orbcal 8 - echo "CompareOrb_pass $?" >>$props_result_file -fi + #------------------------------- + # Partial band structure + # echo $out_pband + #------------------------------- + if ! test -z "$out_pband" && [ $out_pband == 1 ]; then + orbref=refOrbital + orbcal=OUT.autotest/Orbital + python3 $COMPARE_SCRIPT $orbref $orbcal 8 + echo "CompareOrb_pass $?" >>$props_result_file + fi -#------------------------------- -# Wannier90 information -# echo $toW90 -#------------------------------- -if ! test -z "$toW90" && [ $toW90 == 1 ]; then - amnref=diamond.amn - amncal=OUT.autotest/diamond.amn - mmnref=diamond.mmn - mmncal=OUT.autotest/diamond.mmn - eigref=diamond.eig - eigcal=OUT.autotest/diamond.eig - # AMN is covariant under the band gauge (A -> U^dagger A), so compare - # the gauge-invariant Gram matrix A^dagger A instead of the raw elements. - python3 $COMPARE_AMN_SCRIPT $amnref $amncal - echo "CompareAMN_pass $?" >>$props_result_file - # MMN is covariant as M(k,b) -> U_k^dagger M(k,b) U_{k+b}; CPU and GPU - # differ by per-band phases, under which |M_mn| is invariant. - python3 $COMPARE_MMN_SCRIPT $mmnref $mmncal - echo "CompareMMN_pass $?" >>$props_result_file - python3 $COMPARE_SCRIPT $eigref $eigcal 8 - echo "CompareEIG_pass $?" >>$props_result_file -fi + #------------------------------- + # Wannier90 information + # echo $toW90 + #------------------------------- + if ! test -z "$toW90" && [ $toW90 == 1 ]; then + amnref=diamond.amn + amncal=OUT.autotest/diamond.amn + mmnref=diamond.mmn + mmncal=OUT.autotest/diamond.mmn + eigref=diamond.eig + eigcal=OUT.autotest/diamond.eig + # AMN is covariant under the band gauge (A -> U^dagger A), so compare + # the gauge-invariant Gram matrix A^dagger A instead of the raw elements. + python3 $COMPARE_AMN_SCRIPT $amnref $amncal + echo "CompareAMN_pass $?" >>$props_result_file + # MMN is covariant as M(k,b) -> U_k^dagger M(k,b) U_{k+b}; CPU and GPU + # differ by per-band phases, under which |M_mn| is invariant. + python3 $COMPARE_MMN_SCRIPT $mmnref $mmncal + echo "CompareMMN_pass $?" >>$props_result_file + python3 $COMPARE_SCRIPT $eigref $eigcal 8 + echo "CompareEIG_pass $?" >>$props_result_file + fi -#------------------------------- -# Total DOS -# echo total_dos -# echo $has_band -#------------------------------- -if ! test -z "$has_band" && [ $has_band == 1 ]; then - bandref=band.txt.ref - bandcal=OUT.autotest/band.txt - python3 $COMPARE_SCRIPT $bandref $bandcal 8 - echo "CompareBand_pass $?" >>$props_result_file -fi + #------------------------------- + # Total DOS + # echo total_dos + # echo $has_band + #------------------------------- + if ! test -z "$has_band" && [ $has_band == 1 ]; then + bandref=band.txt.ref + bandcal=OUT.autotest/band.txt + python3 $COMPARE_SCRIPT $bandref $bandcal 8 + echo "CompareBand_pass $?" >>$props_result_file + fi -#-------------------------------- -# Hamiltonian and overlap matrix -# echo $has_hs -#-------------------------------- -if ! test -z "$has_hs" && [ $has_hs == 1 ]; then - if ! test -z "$gamma_only" && [ $gamma_only == 1 ]; then - # ========== Γ-point (single k-point) calculation ========== - if ! test -z "$nspin" && [ $nspin == 2 ]; then - # nspin=2 (spin-polarized): compare hks1 + hks2 Hamiltonian + sk overlap matrix - h1ref=hks1_nao.txt.ref - h1cal=OUT.autotest/hks1_nao.txt - h2ref=hks2_nao.txt.ref - h2cal=OUT.autotest/hks2_nao.txt - sref=sk_nao.txt.ref - scal=OUT.autotest/sk_nao.txt - # Compare Hamiltonian matrix for spin 1 - python3 $COMPARE_SCRIPT $h1ref $h1cal 6 - echo "CompareH1_pass $?" >>$props_result_file - # Compare Hamiltonian matrix for spin 2 - python3 $COMPARE_SCRIPT $h2ref $h2cal 6 - echo "CompareH2_pass $?" >>$props_result_file - # Compare overlap matrix - python3 $COMPARE_SCRIPT $sref $scal 8 - echo "CompareS_pass $?" >>$props_result_file - elif ! test -z "$nspin" && [ $nspin == 4 ]; then - # nspin=4 : do nothing, only matching condition without any operation - true - else - # nspin=1 (non-spin-polarized, default case): compare single hk + sk matrix set - href=hk_nao.txt.ref - hcal=OUT.autotest/hk_nao.txt - sref=sk_nao.txt.ref - scal=OUT.autotest/sk_nao.txt - # Compare Hamiltonian matrix - python3 $COMPARE_SCRIPT $href $hcal 6 - echo "CompareH_pass $?" >>$props_result_file - # Compare overlap matrix - python3 $COMPARE_SCRIPT $sref $scal 8 - echo "CompareS_pass $?" >>$props_result_file - fi - else - # ========== Multiple k-points calculation ========== - if ! test -z "$nspin" && [ $nspin == 2 ]; then - # nspin=2 (spin-polarized): compare spin-up/spin-down H(k) and S(k) at the second k-point - h1ref=hk2s1_nao.txt.ref - h1cal=OUT.autotest/hk2s1_nao.txt - h2ref=hk2s2_nao.txt.ref - h2cal=OUT.autotest/hk2s2_nao.txt - sref=sk2_nao.txt.ref - scal=OUT.autotest/sk2_nao.txt - # Compare Hamiltonian matrix for spin 1 - python3 $COMPARE_SCRIPT $h1ref $h1cal 6 - echo "CompareH1_pass $?" >>$props_result_file - # Compare Hamiltonian matrix for spin 2 - python3 $COMPARE_SCRIPT $h2ref $h2cal 6 - echo "CompareH2_pass $?" >>$props_result_file - # Compare overlap matrix - python3 $COMPARE_SCRIPT $sref $scal 8 - echo "CompareS_pass $?" >>$props_result_file - elif ! test -z "$nspin" && [ $nspin == 4 ]; then - # nspin=4 : do nothing, only matching condition without any operation - true - else - # nspin=1 (non-spin-polarized, default case): compare single hk2 + sk2 matrix set - href=hk2_nao.txt.ref - hcal=OUT.autotest/hk2_nao.txt - sref=sk2_nao.txt.ref - scal=OUT.autotest/sk2_nao.txt - # Compare Hamiltonian matrix - python3 $COMPARE_SCRIPT $href $hcal 6 - echo "CompareH_pass $?" >>$props_result_file - # Compare overlap matrix - python3 $COMPARE_SCRIPT $sref $scal 8 - echo "CompareS_pass $?" >>$props_result_file - fi - fi -elif ! test -z "$has_hs" && [ $has_hs == 2 ]; then - HSK_BINARY_COMPARE="$PROPS_TOOLS_DIR/compare_hsk_binary.py" + #-------------------------------- + # Hamiltonian and overlap matrix + # echo $has_hs + #-------------------------------- + if ! test -z "$has_hs" && [ $has_hs == 1 ]; then if ! test -z "$gamma_only" && [ $gamma_only == 1 ]; then - HSK_TEXT_REFERENCE_DIR="../scf_out_hk" - python3 $HSK_BINARY_COMPARE OUT.autotest/hk_nao.dat "$HSK_TEXT_REFERENCE_DIR/hk_nao.txt.ref" real 3 + # ========== Γ-point (single k-point) calculation ========== + if ! test -z "$nspin" && [ $nspin == 2 ]; then + # nspin=2 (spin-polarized): compare hks1 + hks2 Hamiltonian + sk overlap matrix + h1ref=hks1_nao.txt.ref + h1cal=OUT.autotest/hks1_nao.txt + h2ref=hks2_nao.txt.ref + h2cal=OUT.autotest/hks2_nao.txt + sref=sk_nao.txt.ref + scal=OUT.autotest/sk_nao.txt + # Compare Hamiltonian matrix for spin 1 + python3 $COMPARE_SCRIPT $h1ref $h1cal 6 + echo "CompareH1_pass $?" >>$props_result_file + # Compare Hamiltonian matrix for spin 2 + python3 $COMPARE_SCRIPT $h2ref $h2cal 6 + echo "CompareH2_pass $?" >>$props_result_file + # Compare overlap matrix + python3 $COMPARE_SCRIPT $sref $scal 8 + echo "CompareS_pass $?" >>$props_result_file + elif ! test -z "$nspin" && [ $nspin == 4 ]; then + # nspin=4 : do nothing, only matching condition without any operation + true + else + # nspin=1 (non-spin-polarized, default case): compare single hk + sk matrix set + href=hk_nao.txt.ref + hcal=OUT.autotest/hk_nao.txt + sref=sk_nao.txt.ref + scal=OUT.autotest/sk_nao.txt + # Compare Hamiltonian matrix + python3 $COMPARE_SCRIPT $href $hcal 6 echo "CompareH_pass $?" >>$props_result_file - python3 $HSK_BINARY_COMPARE OUT.autotest/sk_nao.dat "$HSK_TEXT_REFERENCE_DIR/sk_nao.txt.ref" real 3 + # Compare overlap matrix + python3 $COMPARE_SCRIPT $sref $scal 8 echo "CompareS_pass $?" >>$props_result_file + fi else - HSK_TEXT_REFERENCE_DIR="../scf_out_hsk" - python3 $HSK_BINARY_COMPARE OUT.autotest/hk2_nao.dat "$HSK_TEXT_REFERENCE_DIR/hk2_nao.txt.ref" complex 3 + # ========== Multiple k-points calculation ========== + if ! test -z "$nspin" && [ $nspin == 2 ]; then + # nspin=2 (spin-polarized): compare spin-up/spin-down H(k) and S(k) at the second k-point + h1ref=hk2s1_nao.txt.ref + h1cal=OUT.autotest/hk2s1_nao.txt + h2ref=hk2s2_nao.txt.ref + h2cal=OUT.autotest/hk2s2_nao.txt + sref=sk2_nao.txt.ref + scal=OUT.autotest/sk2_nao.txt + # Compare Hamiltonian matrix for spin 1 + python3 $COMPARE_SCRIPT $h1ref $h1cal 6 + echo "CompareH1_pass $?" >>$props_result_file + # Compare Hamiltonian matrix for spin 2 + python3 $COMPARE_SCRIPT $h2ref $h2cal 6 + echo "CompareH2_pass $?" >>$props_result_file + # Compare overlap matrix + python3 $COMPARE_SCRIPT $sref $scal 8 + echo "CompareS_pass $?" >>$props_result_file + elif ! test -z "$nspin" && [ $nspin == 4 ]; then + # nspin=4 : do nothing, only matching condition without any operation + true + else + # nspin=1 (non-spin-polarized, default case): compare single hk2 + sk2 matrix set + href=hk2_nao.txt.ref + hcal=OUT.autotest/hk2_nao.txt + sref=sk2_nao.txt.ref + scal=OUT.autotest/sk2_nao.txt + # Compare Hamiltonian matrix + python3 $COMPARE_SCRIPT $href $hcal 6 echo "CompareH_pass $?" >>$props_result_file - python3 $HSK_BINARY_COMPARE OUT.autotest/sk2_nao.dat "$HSK_TEXT_REFERENCE_DIR/sk2_nao.txt.ref" complex 3 + # Compare overlap matrix + python3 $COMPARE_SCRIPT $sref $scal 8 echo "CompareS_pass $?" >>$props_result_file + fi + fi + elif ! test -z "$has_hs" && [ $has_hs == 2 ]; then + HSK_BINARY_COMPARE="$PROPS_TOOLS_DIR/compare_hsk_binary.py" + if ! test -z "$gamma_only" && [ $gamma_only == 1 ]; then + HSK_TEXT_REFERENCE_DIR="../scf_out_hk" + python3 $HSK_BINARY_COMPARE OUT.autotest/hk_nao.dat "$HSK_TEXT_REFERENCE_DIR/hk_nao.txt.ref" real 3 + echo "CompareH_pass $?" >>$props_result_file + python3 $HSK_BINARY_COMPARE OUT.autotest/sk_nao.dat "$HSK_TEXT_REFERENCE_DIR/sk_nao.txt.ref" real 3 + echo "CompareS_pass $?" >>$props_result_file + else + HSK_TEXT_REFERENCE_DIR="../scf_out_hsk" + python3 $HSK_BINARY_COMPARE OUT.autotest/hk2_nao.dat "$HSK_TEXT_REFERENCE_DIR/hk2_nao.txt.ref" complex 3 + echo "CompareH_pass $?" >>$props_result_file + python3 $HSK_BINARY_COMPARE OUT.autotest/sk2_nao.dat "$HSK_TEXT_REFERENCE_DIR/sk2_nao.txt.ref" complex 3 + echo "CompareS_pass $?" >>$props_result_file fi -fi + fi -#-------------------------------- -# exchange-correlation potential -#-------------------------------- -if ! test -z "$has_xc" && [ "$has_xc" == 1 ]; then - if ! test -z "$gamma_only" && [ $gamma_only == 1 ]; then - xcref=vxc_nao.txt.ref - xccal=OUT.autotest/vxc_nao.txt - else - xcref=vxck2_nao.txt.ref - xccal=OUT.autotest/vxck2_nao.txt - fi - oeref=vxc.ref - oecal=OUT.autotest/vxc.txt - python3 $COMPARE_SCRIPT $xcref $xccal 4 - echo "CompareVXC_pass $?" >>$props_result_file - python3 $COMPARE_SCRIPT $oeref $oecal 5 + #-------------------------------- + # exchange-correlation potential + #-------------------------------- + if ! test -z "$has_xc" && [ "$has_xc" == 1 ]; then + if ! test -z "$gamma_only" && [ $gamma_only == 1 ]; then + xcref=vxc_nao.txt.ref + xccal=OUT.autotest/vxc_nao.txt + else + xcref=vxck2_nao.txt.ref + xccal=OUT.autotest/vxck2_nao.txt + fi + oeref=vxc.ref + oecal=OUT.autotest/vxc.txt + python3 $COMPARE_SCRIPT $xcref $xccal 4 + echo "CompareVXC_pass $?" >>$props_result_file + python3 $COMPARE_SCRIPT $oeref $oecal 5 echo "CompareOrbXC_pass $?" >>$props_result_file -fi + fi -#-------------------------------- -# exchange-correlation potential -#-------------------------------- -if ! test -z "$has_xc2" && [ $has_xc2 == 1 ]; then - xc2ref=Vxc_R_spin0.ref - xc2cal=OUT.autotest/Vxc_R_spin0.csr - python3 $COMPARE_SCRIPT $xc2ref $xc2cal 8 - echo "CompareVXC_R_pass $?" >>$props_result_file -fi + #-------------------------------- + # exchange-correlation potential + #-------------------------------- + if ! test -z "$has_xc2" && [ $has_xc2 == 1 ]; then + xc2ref=Vxc_R_spin0.ref + xc2cal=OUT.autotest/Vxc_R_spin0.csr + python3 $COMPARE_SCRIPT $xc2ref $xc2cal 8 + echo "CompareVXC_R_pass $?" >>$props_result_file + fi -#-------------------------------- -# separate terms in band enegy -#-------------------------------- -if ! test -z "$has_eband_separate" && [ $has_eband_separate == 1 ]; then - ekref=kinetic_out.ref - ekcal=OUT.autotest/kinetic_out.dat - python3 $COMPARE_SCRIPT $ekref $ekcal 4 - echo "CompareOrbKinetic_pass $?" >>$props_result_file - vlref=vpp_local_out.ref - vlcal=OUT.autotest/vpp_local_out.dat - python3 $COMPARE_SCRIPT $vlref $vlcal 4 - echo "CompareOrbVL_pass $?" >>$props_result_file - vnlref=vpp_nonlocal_out.ref - vnlcal=OUT.autotest/vpp_nonlocal_out.dat - python3 $COMPARE_SCRIPT $vnlref $vnlcal 4 - echo "CompareOrbVNL_pass $?" >>$props_result_file - vhref=vhartree_out.ref - vhcal=OUT.autotest/vhartree_out.dat - python3 $COMPARE_SCRIPT $vhref $vhcal 4 - echo "CompareOrbVHartree_pass $?" >>$props_result_file -fi + #-------------------------------- + # separate terms in band enegy + #-------------------------------- + if ! test -z "$has_eband_separate" && [ $has_eband_separate == 1 ]; then + ekref=kinetic_out.ref + ekcal=OUT.autotest/kinetic_out.dat + python3 $COMPARE_SCRIPT $ekref $ekcal 4 + echo "CompareOrbKinetic_pass $?" >>$props_result_file + vlref=vpp_local_out.ref + vlcal=OUT.autotest/vpp_local_out.dat + python3 $COMPARE_SCRIPT $vlref $vlcal 4 + echo "CompareOrbVL_pass $?" >>$props_result_file + vnlref=vpp_nonlocal_out.ref + vnlcal=OUT.autotest/vpp_nonlocal_out.dat + python3 $COMPARE_SCRIPT $vnlref $vnlcal 4 + echo "CompareOrbVNL_pass $?" >>$props_result_file + vhref=vhartree_out.ref + vhcal=OUT.autotest/vhartree_out.dat + python3 $COMPARE_SCRIPT $vhref $vhcal 4 + echo "CompareOrbVHartree_pass $?" >>$props_result_file + fi -#----------------------------------- -# Hamiltonian and overlap matrices -#----------------------------------- -#echo $has_hs2 -if ! test -z "$has_hs2" && [ $has_hs2 == 1 ]; then + #----------------------------------- + # Hamiltonian and overlap matrices + #----------------------------------- + #echo $has_hs2 + if ! test -z "$has_hs2" && [ $has_hs2 == 1 ]; then compare_hr_csr hrs1_nao.csr.ref OUT.autotest/hrs1_nao.csr echo "CompareHR_pass $?" >>$props_result_file if ! test -z "$nspin" && [ "$nspin" -eq 2 ]; then - compare_hr_csr hrs2_nao.csr.ref OUT.autotest/hrs2_nao.csr - echo "CompareHR2_pass $?" >>$props_result_file + compare_hr_csr hrs2_nao.csr.ref OUT.autotest/hrs2_nao.csr + echo "CompareHR2_pass $?" >>$props_result_file fi python3 $COMPARE_SCRIPT sr_nao.csr.ref OUT.autotest/sr_nao.csr 8 echo "CompareSR_pass $?" >>$props_result_file -elif ! test -z "$has_hs2" && [ "$has_hs2" == 2 ]; then + elif ! test -z "$has_hs2" && [ "$has_hs2" == 2 ]; then HSR_BINARY_COMPARE="$PROPS_TOOLS_DIR/compare_hsr_binary.py" python3 $HSR_BINARY_COMPARE OUT.autotest/hrs1_nao.dat hrs1_nao.csr.ref real 4 echo "CompareHR_pass $?" >>$props_result_file if ! test -z "$nspin" && [ "$nspin" -eq 2 ]; then - python3 $HSR_BINARY_COMPARE OUT.autotest/hrs2_nao.dat hrs2_nao.csr.ref real 4 - echo "CompareHR2_pass $?" >>$props_result_file + python3 $HSR_BINARY_COMPARE OUT.autotest/hrs2_nao.dat hrs2_nao.csr.ref real 4 + echo "CompareHR2_pass $?" >>$props_result_file fi python3 $HSR_BINARY_COMPARE OUT.autotest/sr_nao.dat sr_nao.csr.ref real 4 echo "CompareSR_pass $?" >>$props_result_file -fi + fi -#----------------------------------- -# H(R), S(R), and DM(R) matrices in NPZ format -#----------------------------------- -if { ! test -z "$out_hsr" && [ "$out_hsr" == 3 ]; } || { ! test -z "$out_hsr_npz" && [ "$out_hsr_npz" == 1 ]; }; then + #----------------------------------- + # H(R), S(R), and DM(R) matrices in NPZ format + #----------------------------------- + if { ! test -z "$out_hsr" && [ "$out_hsr" == 3 ]; } || { ! test -z "$out_hsr_npz" && [ "$out_hsr_npz" == 1 ]; }; then test -f OUT.autotest/sr_nao.npz echo "OutputSRNPZ_pass $?" >>$props_result_file -fi + fi -if { ! test -z "$out_hr_npz" && [ "$out_hr_npz" == 1 ]; } \ - || { ! test -z "$out_hsr" && [ "$out_hsr" == 3 ]; } \ - || { ! test -z "$out_hsr_npz" && [ "$out_hsr_npz" == 1 ]; }; then + if { ! test -z "$out_hr_npz" && [ "$out_hr_npz" == 1 ]; } || + { ! test -z "$out_hsr" && [ "$out_hsr" == 3 ]; } || + { ! test -z "$out_hsr_npz" && [ "$out_hsr_npz" == 1 ]; }; then test -f OUT.autotest/hrs1_nao.npz echo "OutputHRNPZ_pass $?" >>$props_result_file -fi + fi -if ! test -z "$out_dm_npz" && [ "$out_dm_npz" == 1 ]; then + if ! test -z "$out_dm_npz" && [ "$out_dm_npz" == 1 ]; then test -f OUT.autotest/output_DM0.npz echo "OutputDMNPZ_pass $?" >>$props_result_file -fi + fi -#----------------------------------- -# matrix -#----------------------------------- -#echo $has_mat_r -if ! test -z "$has_mat_r" && [ $has_mat_r == 1 ]; then + #----------------------------------- + # matrix + #----------------------------------- + #echo $has_mat_r + if ! test -z "$has_mat_r" && [ $has_mat_r == 1 ]; then python3 $COMPARE_SCRIPT rr_nao.txt.ref OUT.autotest/rr_nao.txt 8 echo "ComparerR_pass $?" >>$props_result_file -fi + fi -#----------------------------------- -# matrix -#----------------------------------- -#echo $has_mat_t -if ! test -z "$has_mat_t" && [ $has_mat_t == 1 ]; then + #----------------------------------- + # matrix + #----------------------------------- + #echo $has_mat_t + if ! test -z "$has_mat_t" && [ $has_mat_t == 1 ]; then python3 $COMPARE_SCRIPT tr_nao.csr.ref OUT.autotest/tr_nao.csr 8 echo "ComparerTR_pass $?" >>$props_result_file -fi + fi -#----------------------------------- -# Asynchronous overlap matrix for Hefei-NAMD -#----------------------------------- -#echo $has_mat_syns -if ! test -z "$has_mat_syns" && [ $has_mat_syns == 1 ]; then + #----------------------------------- + # Asynchronous overlap matrix for Hefei-NAMD + #----------------------------------- + #echo $has_mat_syns + if ! test -z "$has_mat_syns" && [ $has_mat_syns == 1 ]; then python3 $COMPARE_SCRIPT syns_nao.csr.ref OUT.autotest/syns_nao.csr 8 echo "CompareSYNS_pass $?" >>$props_result_file -fi + fi -#----------------------------------- -# matrix -#----------------------------------- -#echo $has_mat_dh -if ! test -z "$has_mat_dh" && [ $has_mat_dh == 1 ] && [ $gamma_only != 1 ]; then + #----------------------------------- + # matrix + #----------------------------------- + #echo $has_mat_dh + if ! test -z "$has_mat_dh" && [ $has_mat_dh == 1 ] && [ $gamma_only != 1 ]; then python3 $COMPARE_SCRIPT dhrxs1_nao.csr.ref OUT.autotest/dhrxs1_nao.csr 8 echo "ComparerdHRx_pass $?" >>$props_result_file python3 $COMPARE_SCRIPT dhrys1_nao.csr.ref OUT.autotest/dhrys1_nao.csr 8 echo "ComparerdHRy_pass $?" >>$props_result_file python3 $COMPARE_SCRIPT dhrzs1_nao.csr.ref OUT.autotest/dhrzs1_nao.csr 8 echo "ComparerdHRz_pass $?" >>$props_result_file -fi + fi -#----------------------------------- -# d (k) matrix -#----------------------------------- -#echo $has_mat_dh_terms -if ! test -z "$has_mat_dh" && [ $has_mat_dh == 1 ]; then + #----------------------------------- + # d (k) matrix + #----------------------------------- + #echo $has_mat_dh_terms + if ! test -z "$has_mat_dh" && [ $has_mat_dh == 1 ]; then shopt -s nullglob for reffile in dhk_ref/*.txt; do - fname=$(basename "$reffile") - key=$(sanitize_result_key "Compare_${fname%.txt}") - record_compare_result "$props_result_file" "${key}_pass" "$reffile" "OUT.autotest/$fname" 8 + fname=$(basename "$reffile") + key=$(sanitize_result_key "Compare_${fname%.txt}") + record_compare_result "$props_result_file" "${key}_pass" "$reffile" "OUT.autotest/$fname" 8 done shopt -u nullglob -fi + fi } -run_mat_dm_props(){ +run_mat_dm_props() { -#-------------------------------------------- -# density matrix information -#-------------------------------------------- -if ! test -z "$out_dm" && [ $out_dm == 1 ]; then - dmfile=OUT.autotest/dm_nao.txt - dmref=dm_nao.txt.ref - python3 $COMPARE_SCRIPT $dmref $dmfile 5 - echo "DM_different $?" >>$props_result_file -fi + #-------------------------------------------- + # density matrix information + #-------------------------------------------- + if ! test -z "$out_dm" && [ $out_dm == 1 ]; then + dmfile=OUT.autotest/dm_nao.txt + dmref=dm_nao.txt.ref + python3 $COMPARE_SCRIPT $dmref $dmfile 5 + echo "DM_different $?" >>$props_result_file + fi } diff --git a/tests/integrate/validation_tools/props_ml.sh b/tests/integrate/validation_tools/props_ml.sh index 167f5f18d81..3b9bbada15b 100644 --- a/tests/integrate/validation_tools/props_ml.sh +++ b/tests/integrate/validation_tools/props_ml.sh @@ -12,104 +12,104 @@ # run_ml_lr_props() - linear-response excitation energies # run_ml_rdmft_props() - RDMFT energy-term extraction -run_ml_descriptor_props(){ +run_ml_descriptor_props() { -#-------------------------------------------- -# ML gene data descriptors (.npy) -#-------------------------------------------- -descriptor_dir="OUT.autotest/MLKEDF_Descriptors" -if [ -d "$descriptor_dir" ]; then - python3 $COLLECT_NPY_MEANS "$descriptor_dir" >> "$props_result_file" -fi + #-------------------------------------------- + # ML gene data descriptors (.npy) + #-------------------------------------------- + descriptor_dir="OUT.autotest/MLKEDF_Descriptors" + if [ -d "$descriptor_dir" ]; then + python3 $COLLECT_NPY_MEANS "$descriptor_dir" >>"$props_result_file" + fi } -run_ml_rpa_props(){ - -#-------------------------------------------- -# random phase approximation -#-------------------------------------------- -if ! test -z "$run_rpa" && [ $run_rpa == 1 ]; then - Etot_without_rpa=`grep Etot_without_rpa log.txt | awk 'BEGIN{FS=":"} {print $2}' ` - echo "Etot_without_rpa $Etot_without_rpa" >> $props_result_file - rpa_outdir=$(get_input_key_value "rpa_outdir" "INPUT") - if [ -z "$rpa_outdir" ]; then - rpa_outdir="./OUT.librpa" - fi - rpa_outdir=${rpa_outdir%/} - shopt -s nullglob - rpa_ref_files=(refcoulomb_*.txt refCs_*.txt refshrink_sinvS_*.txt) - if [ ${#rpa_ref_files[@]} -gt 0 ]; then - IFS=$'\n' rpa_ref_files=($(printf '%s\n' "${rpa_ref_files[@]}" | LC_ALL=C sort)) - unset IFS - for onref in "${rpa_ref_files[@]}"; do - oncal_name=${onref#ref} - oncal="$rpa_outdir/$oncal_name" - compare_key="CompareRPA_$(sanitize_result_key "$oncal_name")_pass" - record_compare_result "$props_result_file" "$compare_key" "$onref" "$oncal" 8 1 - done - fi - shopt -u nullglob -fi +run_ml_rpa_props() { + + #-------------------------------------------- + # random phase approximation + #-------------------------------------------- + if ! test -z "$run_rpa" && [ $run_rpa == 1 ]; then + Etot_without_rpa=$(grep Etot_without_rpa log.txt | awk 'BEGIN{FS=":"} {print $2}') + echo "Etot_without_rpa $Etot_without_rpa" >>$props_result_file + rpa_outdir=$(get_input_key_value "rpa_outdir" "INPUT") + if [ -z "$rpa_outdir" ]; then + rpa_outdir="./OUT.librpa" + fi + rpa_outdir=${rpa_outdir%/} + shopt -s nullglob + rpa_ref_files=(refcoulomb_*.txt refCs_*.txt refshrink_sinvS_*.txt) + if [ ${#rpa_ref_files[@]} -gt 0 ]; then + IFS=$'\n' rpa_ref_files=($(printf '%s\n' "${rpa_ref_files[@]}" | LC_ALL=C sort)) + unset IFS + for onref in "${rpa_ref_files[@]}"; do + oncal_name=${onref#ref} + oncal="$rpa_outdir/$oncal_name" + compare_key="CompareRPA_$(sanitize_result_key "$oncal_name")_pass" + record_compare_result "$props_result_file" "$compare_key" "$onref" "$oncal" 8 1 + done + fi + shopt -u nullglob + fi } -run_ml_lr_props(){ - -#-------------------------------------------- -# Linear response function -#-------------------------------------------- -if [ $is_lr == 1 ]; then - shopt -s nullglob - lr_files=(OUT.autotest/trans_analysis_*_tda.dat) - if grep -q '^ LR excitation energies:' "$running_path"; then - # abs_gauge=none retains an energy-only report; ignore stale optical files. - awk '/^ LR excitation energies:/{p=1; next} /End LR excitation energies/{p=0} p && /^[[:space:]]*[0-9]+[[:space:]]/{printf "excitationenergyref%d %.6f\n", ++n, $2}' "$running_path" >> "$props_result_file" - elif [ ${#lr_files[@]} -gt 0 ]; then - cat "${lr_files[@]}" | awk '/Excitation Energy/{p=1; next} p && /^[[:space:]]*[0-9]+[[:space:]]/{printf "excitationenergyref%d %.6f\n", ++n, $2} /Occupied orbital/{p=0}' >>$props_result_file - fi - shopt -u nullglob -fi +run_ml_lr_props() { + + #-------------------------------------------- + # Linear response function + #-------------------------------------------- + if [ $is_lr == 1 ]; then + shopt -s nullglob + lr_files=(OUT.autotest/trans_analysis_*_tda.dat) + if grep -q '^ LR excitation energies:' "$running_path"; then + # abs_gauge=none retains an energy-only report; ignore stale optical files. + awk '/^ LR excitation energies:/{p=1; next} /End LR excitation energies/{p=0} p && /^[[:space:]]*[0-9]+[[:space:]]/{printf "excitationenergyref%d %.6f\n", ++n, $2}' "$running_path" >>"$props_result_file" + elif [ ${#lr_files[@]} -gt 0 ]; then + cat "${lr_files[@]}" | awk '/Excitation Energy/{p=1; next} p && /^[[:space:]]*[0-9]+[[:space:]]/{printf "excitationenergyref%d %.6f\n", ++n, $2} /Occupied orbital/{p=0}' >>$props_result_file + fi + shopt -u nullglob + fi } -run_ml_rdmft_props(){ +run_ml_rdmft_props() { -#-------------------------------------------- -# Check RDMFT method -#-------------------------------------------- -if ! test -z "$rdmft" && [[ $rdmft == 1 ]]; then - echo "" >>$props_result_file - echo "The following energy units are in Rydberg:" >>$props_result_file + #-------------------------------------------- + # Check RDMFT method + #-------------------------------------------- + if ! test -z "$rdmft" && [[ $rdmft == 1 ]]; then + echo "" >>$props_result_file + echo "The following energy units are in Rydberg:" >>$props_result_file - E_TV_RDMFT=$(grep "E_TV_RDMFT" "$running_path" | tail -1 | awk '{print $2}') - echo "E_TV_RDMFT_ref $E_TV_RDMFT" >>$props_result_file + E_TV_RDMFT=$(grep "E_TV_RDMFT" "$running_path" | tail -1 | awk '{print $2}') + echo "E_TV_RDMFT_ref $E_TV_RDMFT" >>$props_result_file - E_hartree_RDMFT=$(grep "E_hartree_RDMFT" "$running_path" | tail -1 | awk '{print $2}') - echo "E_hartree_RDMFT_ref $E_hartree_RDMFT" >>$props_result_file + E_hartree_RDMFT=$(grep "E_hartree_RDMFT" "$running_path" | tail -1 | awk '{print $2}') + echo "E_hartree_RDMFT_ref $E_hartree_RDMFT" >>$props_result_file - Exc_cwp22_RDMFT=$(grep "Exc_cwp22_RDMFT" "$running_path" | tail -1 | awk '{print $2}') - echo "Exc_cwp22_RDMFT_ref $Exc_cwp22_RDMFT" >>$props_result_file + Exc_cwp22_RDMFT=$(grep "Exc_cwp22_RDMFT" "$running_path" | tail -1 | awk '{print $2}') + echo "Exc_cwp22_RDMFT_ref $Exc_cwp22_RDMFT" >>$props_result_file - E_Ewald=$(grep "E_Ewald" "$running_path" | tail -1 | awk '{print $2}') - echo "E_Ewald_ref $E_Ewald" >>$props_result_file + E_Ewald=$(grep "E_Ewald" "$running_path" | tail -1 | awk '{print $2}') + echo "E_Ewald_ref $E_Ewald" >>$props_result_file - E_entropy=$(grep "E_entropy(-TS)" "$running_path" | tail -1 | awk '{print $2}') - echo "E_entropy_ref $E_entropy" >>$props_result_file + E_entropy=$(grep "E_entropy(-TS)" "$running_path" | tail -1 | awk '{print $2}') + echo "E_entropy_ref $E_entropy" >>$props_result_file - E_descf=$(grep "E_descf" "$running_path" | tail -1 | awk '{print $2}') - echo "E_descf_ref $E_descf" >>$props_result_file + E_descf=$(grep "E_descf" "$running_path" | tail -1 | awk '{print $2}') + echo "E_descf_ref $E_descf" >>$props_result_file - Etotal_RDMFT=$(grep "Etotal_RDMFT" "$running_path" | tail -1 | awk '{print $2}') - echo "Etotal_RDMFT_ref $Etotal_RDMFT" >>$props_result_file + Etotal_RDMFT=$(grep "Etotal_RDMFT" "$running_path" | tail -1 | awk '{print $2}') + echo "Etotal_RDMFT_ref $Etotal_RDMFT" >>$props_result_file - Exc_ksdft=$(grep "Exc_ksdft" "$running_path" | tail -1 | awk '{print $2}') - echo "Exc_ksdft_ref $Exc_ksdft" >>$props_result_file + Exc_ksdft=$(grep "Exc_ksdft" "$running_path" | tail -1 | awk '{print $2}') + echo "Exc_ksdft_ref $Exc_ksdft" >>$props_result_file - E_exx_ksdft=$(grep "E_exx_ksdft" "$running_path" | tail -1 | awk '{print $2}') - echo "E_exx_ksdft_ref $E_exx_ksdft" >>$props_result_file + E_exx_ksdft=$(grep "E_exx_ksdft" "$running_path" | tail -1 | awk '{print $2}') + echo "E_exx_ksdft_ref $E_exx_ksdft" >>$props_result_file - echo "" >>$props_result_file -fi + echo "" >>$props_result_file + fi } diff --git a/tests/integrate/validation_tools/props_tddft.sh b/tests/integrate/validation_tools/props_tddft.sh index d3b30991fda..e9af976d15a 100644 --- a/tests/integrate/validation_tools/props_tddft.sh +++ b/tests/integrate/validation_tools/props_tddft.sh @@ -6,57 +6,57 @@ # switch variables set by props_init() and appends result lines to # $props_result_file. -run_tddft_props(){ +run_tddft_props() { -#-------------------------------------------- -# Check spin observables in rt-TDDFT -#-------------------------------------------- -for spin_file in mag_tot.txt mag_atom.txt torque_tot.txt torque_atom.txt spincur_tot.txt; do - if [ -f "$spin_file.ref" ]; then - spin_key=$(sanitize_result_key "$spin_file") - record_compare_result "$props_result_file" "Compare${spin_key}_pass" "$spin_file.ref" "OUT.autotest/$spin_file" 8 - fi -done + #-------------------------------------------- + # Check spin observables in rt-TDDFT + #-------------------------------------------- + for spin_file in mag_tot.txt mag_atom.txt torque_tot.txt torque_atom.txt spincur_tot.txt; do + if [ -f "$spin_file.ref" ]; then + spin_key=$(sanitize_result_key "$spin_file") + record_compare_result "$props_result_file" "Compare${spin_key}_pass" "$spin_file.ref" "OUT.autotest/$spin_file" 8 + fi + done -#-------------------------------------------- -# Check currents in rt-TDDFT -#-------------------------------------------- -if ! test -z "$out_current" && [ $out_current ]; then - current1ref=current_tot.txt.ref - current1cal=OUT.autotest/current_tot.txt - local current_tol=1e-10 - if [ -f threshold ]; then - local configured_tol - configured_tol=$(get_input_key_value current_threshold threshold) - if [ -n "$configured_tol" ]; then - current_tol=$configured_tol - fi - fi - python3 "$COMPARE_SCRIPT" "$current1ref" "$current1cal" -tol "$current_tol" - echo "CompareCurrent_pass $?" >>$props_result_file -fi + #-------------------------------------------- + # Check currents in rt-TDDFT + #-------------------------------------------- + if ! test -z "$out_current" && [ $out_current ]; then + current1ref=current_tot.txt.ref + current1cal=OUT.autotest/current_tot.txt + local current_tol=1e-10 + if [ -f threshold ]; then + local configured_tol + configured_tol=$(get_input_key_value current_threshold threshold) + if [ -n "$configured_tol" ]; then + current_tol=$configured_tol + fi + fi + python3 "$COMPARE_SCRIPT" "$current1ref" "$current1cal" -tol "$current_tol" + echo "CompareCurrent_pass $?" >>$props_result_file + fi -#-------------------------------------------- -# Check electric fields in rt-TDDFT -#-------------------------------------------- -if ! test -z "$out_efield" && [ "$out_efield" == 1 ]; then - efield_refs=(efield_*.txt.ref) - if [ ! -e "${efield_refs[0]}" ]; then - echo "CompareEfieldReference_pass 1" >>$props_result_file - else - for efield_ref in "${efield_refs[@]}"; do - efield_name=${efield_ref%.ref} - efield_key=$(sanitize_result_key "$efield_name") - record_compare_result "$props_result_file" "Compare${efield_key}_pass" "$efield_ref" "OUT.autotest/$efield_name" 8 - done - fi -fi + #-------------------------------------------- + # Check electric fields in rt-TDDFT + #-------------------------------------------- + if ! test -z "$out_efield" && [ "$out_efield" == 1 ]; then + efield_refs=(efield_*.txt.ref) + if [ ! -e "${efield_refs[0]}" ]; then + echo "CompareEfieldReference_pass 1" >>$props_result_file + else + for efield_ref in "${efield_refs[@]}"; do + efield_name=${efield_ref%.ref} + efield_key=$(sanitize_result_key "$efield_name") + record_compare_result "$props_result_file" "Compare${efield_key}_pass" "$efield_ref" "OUT.autotest/$efield_name" 8 + done + fi + fi -#-------------------------------------------- -# Check vector potential in rt-TDDFT -#-------------------------------------------- -if ! test -z "$out_vecpot" && [ "$out_vecpot" == 1 ]; then - record_compare_result "$props_result_file" "CompareVectorPot_pass" "vector_pot.txt.ref" "OUT.autotest/vector_pot.txt" 8 -fi + #-------------------------------------------- + # Check vector potential in rt-TDDFT + #-------------------------------------------- + if ! test -z "$out_vecpot" && [ "$out_vecpot" == 1 ]; then + record_compare_result "$props_result_file" "CompareVectorPot_pass" "vector_pot.txt.ref" "OUT.autotest/vector_pot.txt" 8 + fi } diff --git a/tests/integrate/validation_tools/run_check.sh b/tests/integrate/validation_tools/run_check.sh index a1d390ab2c7..ea59f8b369c 100755 --- a/tests/integrate/validation_tools/run_check.sh +++ b/tests/integrate/validation_tools/run_check.sh @@ -5,43 +5,43 @@ GENERAL_INFO_FILE="../../integrate/general_info" # check_out: checking the output information # input: result.out -check_out(){ - outfile=$1 - worddir=`awk '{print $1}' $outfile` - for word in $worddir; do - # serach result.out and get information - cal=`grep "$word" $outfile | awk '{printf "%.'$CA'f\n",$2}'` - # echo "cal = $cal" - # search result.ref and get information - ref=`grep "$word" result.ref | awk '{printf "%.'$CA'f\n",$2}'` - # echo "ref = $ref" - # compute the error between 'cal' and 'ref' - error=`awk 'BEGIN {x='$ref';y='$cal';printf "%.'$CA'f\n",x-y}'` - # echo "error = $error" - # compare the total time - if [ $word == "totaltimeref" ]; then - echo "$word this-test: $cal ref-1core-test: $ref" - break - fi - # except the total time, other comparison may lead to 'wrong' results - if [ $(echo "$error == 0"|bc) = 0 ]; then - echo "----------Wrong!----------" - echo "word cal ref error" - echo "$word $cal $ref $error" - break - fi - done +check_out() { + outfile=$1 + worddir=$(awk '{print $1}' $outfile) + for word in $worddir; do + # serach result.out and get information + cal=$(grep "$word" $outfile | awk '{printf "%.'$CA'f\n",$2}') + # echo "cal = $cal" + # search result.ref and get information + ref=$(grep "$word" result.ref | awk '{printf "%.'$CA'f\n",$2}') + # echo "ref = $ref" + # compute the error between 'cal' and 'ref' + error=$(awk 'BEGIN {x='$ref';y='$cal';printf "%.'$CA'f\n",x-y}') + # echo "error = $error" + # compare the total time + if [ $word == "totaltimeref" ]; then + echo "$word this-test: $cal ref-1core-test: $ref" + break + fi + # except the total time, other comparison may lead to 'wrong' results + if [ $(echo "$error == 0" | bc) = 0 ]; then + echo "----------Wrong!----------" + echo "word cal ref error" + echo "$word $cal $ref $error" + break + fi + done } -test -e $GENERAL_INFO_FILE|| echo "current dir:`pwd`, plese prepare the general_info file." +test -e $GENERAL_INFO_FILE || echo "current dir:$(pwd), plese prepare the general_info file." -test -e $GENERAL_INFO_FILE|| exit 0 +test -e $GENERAL_INFO_FILE || exit 0 # EXEC may be a literal path, or one of the ABACUS_EXE placeholders # ($ABACUS_EXE, ${ABACUS_EXE}, ${ABACUS_EXE:-abacus}), so a single env var can # override the executable without editing general_info. Only these # placeholders are substituted; EXEC is never evaluated as shell code. -exec_path=`grep EXEC $GENERAL_INFO_FILE | awk '{printf $2}'` +exec_path=$(grep EXEC $GENERAL_INFO_FILE | awk '{printf $2}') abacus_exe_default=${ABACUS_EXE:-abacus} exec_path=${exec_path//'${ABACUS_EXE:-abacus}'/$abacus_exe_default} exec_path=${exec_path//'${ABACUS_EXE}'/$ABACUS_EXE} @@ -52,17 +52,17 @@ command -v "$exec_path" >/dev/null || echo "Error! ABACUS path was wrong!!" command -v "$exec_path" >/dev/null || exit 0 -CA=`grep CHECKACCURACY $GENERAL_INFO_FILE | awk '{printf $2}'` +CA=$(grep CHECKACCURACY $GENERAL_INFO_FILE | awk '{printf $2}') -NP=`grep NUMBEROFPROCESS $GENERAL_INFO_FILE | awk '{printf $2}'` +NP=$(grep NUMBEROFPROCESS $GENERAL_INFO_FILE | awk '{printf $2}') -path_here=`pwd` +path_here=$(pwd) echo "Test in $path_here" echo "Begin testing the example with $NP cores" #parallel test -mpirun -np $NP "$exec_path" > log.txt +mpirun -np $NP "$exec_path" >log.txt test -d OUT.autotest || echo "Some errors occured in ABACUS!" @@ -71,18 +71,16 @@ test -d OUT.autotest || exit 0 #---------------------------------------------------------------------- #if any input parameters for this script, just generate reference file. #---------------------------------------------------------------------- -if test -z $1 -then -$CATCH_SCRIPT result.out -check_out result.out -elif [ $1 == "debug" ] -then -# Single_job.sh debug copies validation_tools/ into the case directory; -# use that copy so local edits to the collectors take effect. -./validation_tools/catch_properties.sh result.out -check_out result.out +if test -z $1; then + $CATCH_SCRIPT result.out + check_out result.out +elif [ $1 == "debug" ]; then + # Single_job.sh debug copies validation_tools/ into the case directory; + # use that copy so local edits to the collectors take effect. + ./validation_tools/catch_properties.sh result.out + check_out result.out else -$CATCH_SCRIPT result.ref -rm -r OUT.autotest -rm log.txt + $CATCH_SCRIPT result.ref + rm -r OUT.autotest + rm log.txt fi diff --git a/tests/integrate/validation_tools/run_librpa_producer.sh b/tests/integrate/validation_tools/run_librpa_producer.sh index ab41653e004..2ae95ce0d47 100755 --- a/tests/integrate/validation_tools/run_librpa_producer.sh +++ b/tests/integrate/validation_tools/run_librpa_producer.sh @@ -3,8 +3,8 @@ set -euo pipefail if [ "$#" -ne 2 ]; then - echo "Usage: $0 ABACUS_EXECUTABLE CASES_DIRECTORY" >&2 - exit 2 + echo "Usage: $0 ABACUS_EXECUTABLE CASES_DIRECTORY" >&2 + exit 2 fi abacus=$1 @@ -15,8 +15,8 @@ cd "$cases_dir" bash "$script_dir/../Autotest.sh" -a "$abacus" -n 1 -j auto -p -f CASES_LIBRPA_PRODUCER.txt while read -r case_name; do - [ -z "$case_name" ] && continue - case_dir="$cases_dir/$case_name" - (cd "$case_dir" && python3 "$script_dir/check_librpa_producer.py" \ - --root . --manifest librpa_producer_manifest.json) -done < CASES_LIBRPA_PRODUCER.txt + [ -z "$case_name" ] && continue + case_dir="$cases_dir/$case_name" + (cd "$case_dir" && python3 "$script_dir/check_librpa_producer.py" \ + --root . --manifest librpa_producer_manifest.json) +done &2 - exit 2 + echo "Usage: $0 VALIDATION_TOOL_DIRECTORY" >&2 + exit 2 fi python3 -m unittest discover -s "$1" -p 'test_librpa_*.py' diff --git a/tests/performance/catch_properties.sh b/tests/performance/catch_properties.sh index 9ee3b44a8ef..49faccf3524 100644 --- a/tests/performance/catch_properties.sh +++ b/tests/performance/catch_properties.sh @@ -1,17 +1,17 @@ #!/bin/bash -sum_file(){ - line=`grep -vc '^$' $1` - sum=0.0 - for (( num=1 ; num<=$line ; num++ ));do - value_line=(` sed -n "$num p" $1 | head -n1 `) - colume=`echo ${#value_line[@]}` - for (( col=0 ; col<$colume ; col++ ));do - value=`echo ${value_line[$col]}` - sum=`awk 'BEGIN {x='$sum';y='$value';printf "%.6f\n",x+sqrt(y*y)}'` - done - done - echo $sum +sum_file() { + line=$(grep -vc '^$' $1) + sum=0.0 + for ((num = 1; num <= $line; num++)); do + value_line=($(sed -n "$num p" $1 | head -n1)) + colume=$(echo ${#value_line[@]}) + for ((col = 0; col < $colume; col++)); do + value=$(echo ${value_line[$col]}) + sum=$(awk 'BEGIN {x='$sum';y='$value';printf "%.6f\n",x+sqrt(y*y)}') + done + done + echo $sum } #answer=`sum_file test.txt` #echo $answer @@ -19,29 +19,30 @@ sum_file(){ file=$1 #echo $1 -suffix=`awk '$1=="suffix"{print $2}' INPUT` -if [[ "$suffix" == "" ]];then - suffix="ABACUS" +suffix=$(awk '$1=="suffix"{print $2}' INPUT) +if [[ "$suffix" == "" ]]; then + suffix="ABACUS" fi -calculation=`awk '$1=="calculation"{print $2}' INPUT` -if [[ "$suffix" == "" ]];then - calculation="scf" +calculation=$(awk '$1=="calculation"{print $2}' INPUT) +if [[ "$suffix" == "" ]]; then + calculation="scf" fi -running_path=`echo "OUT.${suffix}/running_$calculation"".log"` -natom=`grep -En '(^|[[:space:]])TOTAL ATOM NUMBER($|[[:space:]])' $running_path | awk '{print $6}'` -has_force=`grep -En '(^|[[:space:]])cal_force($|[[:space:]])' INPUT | awk '{print $2}'` -has_stress=`grep -En '(^|[[:space:]])cal_stress($|[[:space:]])' INPUT | awk '{print $2}'` -has_dftu=`grep -En '(^|[[:space:]])dft_plus_u($|[[:space:]])' INPUT | awk '{print $2}'` -has_band=`grep -En '(^|[[:space:]])out_band($|[[:space:]])' INPUT | awk '{print $2}'` -has_dos=`grep -En '(^|[[:space:]])out_dos($|[[:space:]])' INPUT | awk '{print $2}'` -has_hs=`grep -En '(^|[[:space:]])out_hs($|[[:space:]])' INPUT | awk '{print $2}'` -has_r=`grep -En '(^|[[:space:]])out_r($|[[:space:]])' INPUT | awk '{print $2}'` -out_descriptor=`grep out_descriptor INPUT | awk '{print $2}' | sed s/[[:space:]]//g` +running_path=$(echo "OUT.${suffix}/running_$calculation"".log") +natom=$(grep -En '(^|[[:space:]])TOTAL ATOM NUMBER($|[[:space:]])' $running_path | awk '{print $6}') +has_force=$(grep -En '(^|[[:space:]])cal_force($|[[:space:]])' INPUT | awk '{print $2}') +has_stress=$(grep -En '(^|[[:space:]])cal_stress($|[[:space:]])' INPUT | awk '{print $2}') +has_dftu=$(grep -En '(^|[[:space:]])dft_plus_u($|[[:space:]])' INPUT | awk '{print $2}') +has_band=$(grep -En '(^|[[:space:]])out_band($|[[:space:]])' INPUT | awk '{print $2}') +has_dos=$(grep -En '(^|[[:space:]])out_dos($|[[:space:]])' INPUT | awk '{print $2}') +has_hs=$(grep -En '(^|[[:space:]])out_hs($|[[:space:]])' INPUT | awk '{print $2}') +has_r=$(grep -En '(^|[[:space:]])out_r($|[[:space:]])' INPUT | awk '{print $2}') +out_descriptor=$(grep out_descriptor INPUT | awk '{print $2}' | sed s/[[:space:]]//g) #echo $running_path -base=`grep -En '(^|[[:space:]])basis_type($|[[:space:]])' INPUT | awk '{print $2}' | sed s/[[:space:]]//g` -if [ $base == "pw" ]; then word="plane_wave_line" +base=$(grep -En '(^|[[:space:]])basis_type($|[[:space:]])' INPUT | awk '{print $2}' | sed s/[[:space:]]//g) +if [ $base == "pw" ]; then + word="plane_wave_line" else -word="lcao_line" + word="lcao_line" fi #echo $word test -e $1 && rm $1 @@ -49,67 +50,63 @@ test -e $1 && rm $1 # if NOT non-self-consistent calculations #-------------------------------------------- if [ $calculation != "nscf" ]; then - etot=`grep ETOT_ $running_path | awk '{print $2}'` - etotperatom=`awk 'BEGIN {x='$etot';y='$natom';printf "%.10f\n",x/y}'` - echo "etotref $etot" >>$1 - echo "etotperatomref $etotperatom" >>$1 + etot=$(grep ETOT_ $running_path | awk '{print $2}') + etotperatom=$(awk 'BEGIN {x='$etot';y='$natom';printf "%.10f\n",x/y}') + echo "etotref $etot" >>$1 + echo "etotperatomref $etotperatom" >>$1 fi - #echo $etot #echo "hasforce:"$has_force if ! test -z "$has_force" && [ $has_force -eq 1 ]; then - nn3=`echo "$natom + 4" |bc` - #nn1=`echo "$natom + 1" |bc` - #nn5=`echo "$natom + 6" |bc` - #grep -A$nn3 "TOTAL-FORCE" $running_path|sed '1,5d'|sed ''$nn1','$nn5'd'|awk '{printf $2"\t"$3"\t"$4"\n"}' > force.txt - grep -A$nn3 "TOTAL-FORCE" $running_path |awk 'NF==4{print $2,$3,$4}' | tail -$natom > force.txt #check the last step result - total_force=`sum_file force.txt` - rm force.txt - echo "totalforceref $total_force" >>$1 + nn3=$(echo "$natom + 4" | bc) + #nn1=`echo "$natom + 1" |bc` + #nn5=`echo "$natom + 6" |bc` + #grep -A$nn3 "TOTAL-FORCE" $running_path|sed '1,5d'|sed ''$nn1','$nn5'd'|awk '{printf $2"\t"$3"\t"$4"\n"}' > force.txt + grep -A$nn3 "TOTAL-FORCE" $running_path | awk 'NF==4{print $2,$3,$4}' | tail -$natom >force.txt #check the last step result + total_force=$(sum_file force.txt) + rm force.txt + echo "totalforceref $total_force" >>$1 fi #echo $total_force #echo "has_stress:"$has_stress -if ! test -z "$has_stress" && [ $has_stress -eq 1 ]; then - #grep -A6 "TOTAL-STRESS" $running_path|sed '1,4d'|sed '4,8d' >stress.txt - grep -A6 "TOTAL-STRESS" $running_path| awk 'NF==3' | tail -3> stress.txt - total_stress=`sum_file stress.txt` - rm stress.txt - echo "totalstressref $total_stress" >>$1 +if ! test -z "$has_stress" && [ $has_stress -eq 1 ]; then + #grep -A6 "TOTAL-STRESS" $running_path|sed '1,4d'|sed '4,8d' >stress.txt + grep -A6 "TOTAL-STRESS" $running_path | awk 'NF==3' | tail -3 >stress.txt + total_stress=$(sum_file stress.txt) + rm stress.txt + echo "totalstressref $total_stress" >>$1 fi - #echo $total_stress #if ! test -z "$has_charge" && [ $has_charge -eq 1 ]; then # total_charge=`sum_file OUT.autotest/SPIN1_CHG` # echo "totalchargeref $total_charge" >>$1 #fi - #echo $total_charge -if ! test -z "$has_dos" && [ $has_dos -eq 1 ]; then - total_dos=`cat OUT.autotest/doss1g1.txt | awk 'END {print}' | awk '{print $3}'` - echo "totaldosref $total_dos" >> $1 +if ! test -z "$has_dos" && [ $has_dos -eq 1 ]; then + total_dos=$(cat OUT.autotest/doss1g1.txt | awk 'END {print}' | awk '{print $3}') + echo "totaldosref $total_dos" >>$1 fi # smearing_dos=`sum_file OUT.autotest/doss1g1.txt` # echo "totaldossmearing $smearing_dos" >> $1 - #echo total_dos #echo $has_band -if ! test -z "$has_band" && [ $has_band -eq 1 ]; then - total_band=`sum_file OUT.autotest/BANDS_1.dat` - echo "totalbandref $total_band" >>$1 +if ! test -z "$has_band" && [ $has_band -eq 1 ]; then + total_band=$(sum_file OUT.autotest/BANDS_1.dat) + echo "totalbandref $total_band" >>$1 fi #echo $has_hs -if ! test -z "$has_hs" && [ $has_hs -eq 1 ]; then - total_h=`sum_file OUT.autotest/data-H` - echo "totalHmatrix $total_h" >>$1 - total_s=`sum_file OUT.autotest/data-S` - echo "totalSmatrix $total_s" >>$1 +if ! test -z "$has_hs" && [ $has_hs -eq 1 ]; then + total_h=$(sum_file OUT.autotest/data-H) + echo "totalHmatrix $total_h" >>$1 + total_s=$(sum_file OUT.autotest/data-S) + echo "totalSmatrix $total_s" >>$1 fi #echo $total_band -ttot=`grep $word $running_path | awk '{print $3}'` +ttot=$(grep $word $running_path | awk '{print $3}') echo "totaltimeref $ttot" >>$1 diff --git a/tests/performance/clean.sh b/tests/performance/clean.sh index 3610262aa0b..e777e9726c4 100644 --- a/tests/performance/clean.sh +++ b/tests/performance/clean.sh @@ -1,7 +1,7 @@ #!/bin/bash -for i in P*;do - rm -rf $i/result.log $i/time.log $i/OUT.* $i/result.out +for i in P*; do + rm -rf $i/result.log $i/time.log $i/OUT.* $i/result.out done -rm -rf *cpu *kpar *bxyz sum.dat* *.old log +rm -rf *cpu *kpar *bxyz sum.dat* *.old log diff --git a/tests/performance/run.sh b/tests/performance/run.sh index f7eb746308a..3ea4292d3ab 100644 --- a/tests/performance/run.sh +++ b/tests/performance/run.sh @@ -5,11 +5,11 @@ abacus=abacus #ABACUS running path thread=1 #Thread number ca=6 #accuracy for comparing energy -cafs=3 #accuracy for comparing force, and stress +cafs=3 #accuracy for comparing force, and stress #ncpu=8 #parallel core number in mpirun, or use the below value ncpu=$(cat /proc/cpuinfo | grep "cpu cores" | uniq | awk '{print $NF}') #the CPU cores in current machine -ForceRun=0 #if ForceRun = 0, before run a job, it will check the file result.log - #and if this file has a normal ending, this job will be skipped +ForceRun=0 #if ForceRun = 0, before run a job, it will check the file result.log +#and if this file has a normal ending, this job will be skipped DoAllExampleRun=1 #if run allexample in allcase file or not, 0: not do, others: do @@ -32,39 +32,39 @@ BxyzList="2 3 4 6 8" #the grid number shold be divisible by these va #def function check_out #check_out result.dat check_out() { - outfile=$1 - properties=$(awk '{print $1}' $outfile) - for key in $properties; do - if [ $key == "totaltimeref" ]; then - break - elif [[ $key == "totalforceref" || $key == "totalstressref" ]]; then - tca=$cafs - else - tca=$ca - fi - - cal=$(grep "$key" $outfile | awk '{printf "%.'$tca'f\n",$2}') - ref=$(grep "$key" result.ref | awk '{printf "%.'$tca'f\n",$2}') - deviation=$(awk 'BEGIN {x='$ref';y='$cal';if (xresult.log 2>time.log - else - printf "**result.log is normal end, skip this job** " - fi - endtime=$(date +'%Y-%m-%d %H:%M:%S') - start_seconds=$(date --date="$starttime" +%s) - end_seconds=$(date --date="$endtime" +%s) - echo "Use time "$((end_seconds - start_seconds))"s" - - #running catch_properties.sh script to collect energy, force and stress to file result.out - #Then use function "check_out" to compare the results in result.out and result.ref - bash ../catch_properties.sh result.out - check_out result.out - cd .. + cd $3 + printf "Running %-20s: " "$3" + + starttime=$(date +'%Y-%m-%d %H:%M:%S') + #if there has result.log file, assign lastword="the first word of last line of result.log" + #and if lastword is equal to "SEE", we think this job is normal end, and it will be + #skipped when ForceRun is set to be 0 + lastword="" + if [[ $ForceRun == 0 && -f result.log ]]; then + lastword=$(tail -1 result.log | awk '{print $1}') + fi + if [[ $lastword != "SEE" ]]; then + OMP_NUM_THREADS=$2 /usr/bin/time -v mpirun -n $1 $abacus 1>result.log 2>time.log + else + printf "**result.log is normal end, skip this job** " + fi + endtime=$(date +'%Y-%m-%d %H:%M:%S') + start_seconds=$(date --date="$starttime" +%s) + end_seconds=$(date --date="$endtime" +%s) + echo "Use time "$((end_seconds - start_seconds))"s" + + #running catch_properties.sh script to collect energy, force and stress to file result.out + #Then use function "check_out" to compare the results in result.out and result.ref + bash ../catch_properties.sh result.out + check_out result.out + cd .. } ############################## usage() { - echo "" - echo " Usage:" - echo " bash run.sh [-n nprocs] [-t Threads] [-a Accuracy] [-f AccuracyForceStress] [...]" - echo " -n nprocs: core number for MPI parallel to run ABACUS" - echo " -t Threads: thread number to run ABACUS" - echo " -b abacus: the command to run ABACUS" - echo " -a Accuracy: the accuracy to judge if energy is right, e.g. 6 means 1e-6 eV" - echo " -f AccuracyForceStress: the accuracy to judge if the force and stress is right" - echo "" + echo "" + echo " Usage:" + echo " bash run.sh [-n nprocs] [-t Threads] [-a Accuracy] [-f AccuracyForceStress] [...]" + echo " -n nprocs: core number for MPI parallel to run ABACUS" + echo " -t Threads: thread number to run ABACUS" + echo " -b abacus: the command to run ABACUS" + echo " -a Accuracy: the accuracy to judge if energy is right, e.g. 6 means 1e-6 eV" + echo " -f AccuracyForceStress: the accuracy to judge if the force and stress is right" + echo "" } -while getopts 'n:t:b:c:a:f' args;do - case $args in - n) ncpu=$OPTARG;; - t) thread=$OPTARG;; - b) abacus=$OPTARG;; - a) ca=$OPTARG;; - f) cafs=$OPTARG;; - ?) usage;; - esac +while getopts 'n:t:b:c:a:f' args; do + case $args in + n) ncpu=$OPTARG ;; + t) thread=$OPTARG ;; + b) abacus=$OPTARG ;; + a) ca=$OPTARG ;; + f) cafs=$OPTARG ;; + ?) usage ;; + esac done -if [ "$ncpu" == "" ];then - echo "ncpu=$ncpu" - echo "Pleas use -n to set the parallel core number" - usage - exit 1 +if [ "$ncpu" == "" ]; then + echo "ncpu=$ncpu" + echo "Pleas use -n to set the parallel core number" + usage + exit 1 fi #echo $ncpu $thread $abacus $ca $cafs @@ -145,7 +145,7 @@ cat version >>sumall.dat date >>sumall.dat cat /proc/version >>sumall.dat cat /proc/cpuinfo | grep "model name" | tail -1 | cut -d ':' -f 2 >>sumall.dat -echo "ABACUS path: `which $abacus`" >>sumall.dat +echo "ABACUS path: $(which $abacus)" >>sumall.dat echo "Number of Cores: $ncpu" >>sumall.dat echo "Accuracy for energy: 1e-$ca" >>sumall.dat echo >>sumall.dat @@ -160,141 +160,141 @@ ok=0 ############################## #run all examples in allcase if [[ $DoAllExampleRun != 0 ]]; then - echo "run all examples in allcase" - for i in $(cat allcase); do - test -d $i || continue - run_abacus $ncpu $thread $i - done - - #sum the critical timing information - python3 sumdat.py -i allcase -o sum.dat - echo "##AllExampleRun" >>sumall.dat - cat sum.dat >>sumall.dat - echo "" >>sumall.dat - echo !!!all data are summarized in sum.dat - echo + echo "run all examples in allcase" + for i in $(cat allcase); do + test -d $i || continue + run_abacus $ncpu $thread $i + done + + #sum the critical timing information + python3 sumdat.py -i allcase -o sum.dat + echo "##AllExampleRun" >>sumall.dat + cat sum.dat >>sumall.dat + echo "" >>sumall.dat + echo !!!all data are summarized in sum.dat + echo fi ############################## #do NCpu test if [[ $DoNCpuTest != 0 ]]; then - echo "do N CPU test" - cpucore=$maxcpucore - test -f allcase.ncpu && rm allcase.ncpu - for case in $CpuTestExample; do - if [[ ! -d $case ]]; then - echo "Error: do NCpu test, can not find $case" - continue - fi - - for i in $NCpuList; do - if [[ $i -lt $cpucore ]]; then - echo ${case}_${i}cpu >>allcase.ncpu - test -d ${case}_${i}cpu || mkdir ${case}_${i}cpu - cp ${case}/INPUT ${case}/STRU ${case}/KPT ${case}/result.ref ${case}_${i}cpu - - run_abacus $i $thread ${case}_${i}cpu - fi - done - - echo $case >>allcase.ncpu - if [[ ! -f $case/result.log ]]; then - run_abacus $ncpu $thread ${case} - fi + echo "do N CPU test" + cpucore=$maxcpucore + test -f allcase.ncpu && rm allcase.ncpu + for case in $CpuTestExample; do + if [[ ! -d $case ]]; then + echo "Error: do NCpu test, can not find $case" + continue + fi + + for i in $NCpuList; do + if [[ $i -lt $cpucore ]]; then + echo ${case}_${i}cpu >>allcase.ncpu + test -d ${case}_${i}cpu || mkdir ${case}_${i}cpu + cp ${case}/INPUT ${case}/STRU ${case}/KPT ${case}/result.ref ${case}_${i}cpu + + run_abacus $i $thread ${case}_${i}cpu + fi done - #sum the critical timing information - bash sumdat.sh allcase.ncpu sum.dat.ncpu - echo "##NCpuTest" >>sumall.dat - cat sum.dat.ncpu >>sumall.dat - echo "" >>sumall.dat - echo "!!!all data are summarized in sum.dat.ncpu" - echo + echo $case >>allcase.ncpu + if [[ ! -f $case/result.log ]]; then + run_abacus $ncpu $thread ${case} + fi + done + + #sum the critical timing information + bash sumdat.sh allcase.ncpu sum.dat.ncpu + echo "##NCpuTest" >>sumall.dat + cat sum.dat.ncpu >>sumall.dat + echo "" >>sumall.dat + echo "!!!all data are summarized in sum.dat.ncpu" + echo fi ############################## #do KPar test if [[ $DoKParTest != 0 ]]; then - echo "do N KPar test" - test -f allcase.kpar && rm allcase.kpar - for case in $KParTestExample; do - if [[ ! -d $case ]]; then - echo "Error: do KPar test, can not find $case" - continue - fi - - echo $case >>allcase.kpar - if [[ ! -f $case/result.log ]]; then - run_abacus $ncpu $thread ${case} - fi - - for i in $KParList; do - if [[ $i -le $maxkpar ]]; then - echo ${case}_${i}kpar >>allcase.kpar - test -d ${case}_${i}kpar || mkdir ${case}_${i}kpar - cp ${case}/INPUT ${case}/STRU ${case}/KPT ${case}/result.ref ${case}_${i}kpar - echo "kpar $i" >>${case}_${i}kpar/INPUT - - run_abacus $ncpu $thread ${case}_${i}kpar - fi - done + echo "do N KPar test" + test -f allcase.kpar && rm allcase.kpar + for case in $KParTestExample; do + if [[ ! -d $case ]]; then + echo "Error: do KPar test, can not find $case" + continue + fi + + echo $case >>allcase.kpar + if [[ ! -f $case/result.log ]]; then + run_abacus $ncpu $thread ${case} + fi + + for i in $KParList; do + if [[ $i -le $maxkpar ]]; then + echo ${case}_${i}kpar >>allcase.kpar + test -d ${case}_${i}kpar || mkdir ${case}_${i}kpar + cp ${case}/INPUT ${case}/STRU ${case}/KPT ${case}/result.ref ${case}_${i}kpar + echo "kpar $i" >>${case}_${i}kpar/INPUT + + run_abacus $ncpu $thread ${case}_${i}kpar + fi done - #sum the critical timing information - bash sumdat.sh allcase.kpar sum.dat.kpar - echo "##KParTest" >>sumall.dat - cat sum.dat.kpar >>sumall.dat - echo "" >>sumall.dat - echo "!!!all data are summarized in sum.dat.kpar" - echo + done + #sum the critical timing information + bash sumdat.sh allcase.kpar sum.dat.kpar + echo "##KParTest" >>sumall.dat + cat sum.dat.kpar >>sumall.dat + echo "" >>sumall.dat + echo "!!!all data are summarized in sum.dat.kpar" + echo fi ############################## #do Bxyz test if [[ $DoBxyzTest != 0 ]]; then - echo "do bx by bz test" - test -f allcase.bxyz && rm allcase.bxyz - for case in $BxyzTestExample; do - if [[ ! -d $case ]]; then - echo "Error: do BxByBz test, can not find $case" - continue - fi - - echo $case >>allcase.bxyz - if [[ ! -f $case/result.log ]]; then - run_abacus $ncpu $thread ${case} - fi - - for i in $BxyzList; do - if [[ $i != 2 ]]; then - echo ${case}_${i}bxyz >>allcase.bxyz - test -d ${case}_${i}bxyz || mkdir ${case}_${i}bxyz - cp ${case}/INPUT ${case}/STRU ${case}/KPT ${case}/result.ref ${case}_${i}bxyz - printf " bx $i \n by $i \n bz $i" >>${case}_${i}bxyz/INPUT - - run_abacus $ncpu $thread ${case}_${i}bxyz - fi - done + echo "do bx by bz test" + test -f allcase.bxyz && rm allcase.bxyz + for case in $BxyzTestExample; do + if [[ ! -d $case ]]; then + echo "Error: do BxByBz test, can not find $case" + continue + fi + + echo $case >>allcase.bxyz + if [[ ! -f $case/result.log ]]; then + run_abacus $ncpu $thread ${case} + fi + + for i in $BxyzList; do + if [[ $i != 2 ]]; then + echo ${case}_${i}bxyz >>allcase.bxyz + test -d ${case}_${i}bxyz || mkdir ${case}_${i}bxyz + cp ${case}/INPUT ${case}/STRU ${case}/KPT ${case}/result.ref ${case}_${i}bxyz + printf " bx $i \n by $i \n bz $i" >>${case}_${i}bxyz/INPUT + + run_abacus $ncpu $thread ${case}_${i}bxyz + fi done - #sum the critical timing information - bash sumdat.sh allcase.bxyz sum.dat.bxyz - echo "##BxyzTest" >>sumall.dat - cat sum.dat.bxyz >>sumall.dat - echo "" >>sumall.dat - echo "!!!all data are summarized in sum.dat.bxyz" - echo + done + #sum the critical timing information + bash sumdat.sh allcase.bxyz sum.dat.bxyz + echo "##BxyzTest" >>sumall.dat + cat sum.dat.bxyz >>sumall.dat + echo "" >>sumall.dat + echo "!!!all data are summarized in sum.dat.bxyz" + echo fi ############################## #Final OUTPUT if [[ $failed -eq 0 ]]; then - echo "All jobs finished." | tee $GITHUB_STEP_SUMMARY - exit 0 + echo "All jobs finished." | tee $GITHUB_STEP_SUMMARY + exit 0 else - echo "Error: $failed jobs failed." | tee $GITHUB_STEP_SUMMARY - echo -e "$failedfile" - for ifile in `echo -e "$failedfile"`;do - echo "" | tee $GITHUB_STEP_SUMMARY - echo $ifile | tee $GITHUB_STEP_SUMMARY - cat $ifile/result.log | tee $GITHUB_STEP_SUMMARY - done - exit 1 + echo "Error: $failed jobs failed." | tee $GITHUB_STEP_SUMMARY + echo -e "$failedfile" + for ifile in $(echo -e "$failedfile"); do + echo "" | tee $GITHUB_STEP_SUMMARY + echo $ifile | tee $GITHUB_STEP_SUMMARY + cat $ifile/result.log | tee $GITHUB_STEP_SUMMARY + done + exit 1 fi