From cec7ff287ebfdc2ad28b419a67aae234f2267c39 Mon Sep 17 00:00:00 2001 From: Zanthoxylum <105619360+Zanthoxylum@users.noreply.github.com> Date: Tue, 10 Nov 2026 10:30:08 +0800 Subject: [PATCH 01/16] test(dfpt): integrate test 110_PW_DFPT_Si_X with frequency parsing Add the first PW-DFPT integration test and the props_dfpt.sh collector that brings phonon frequencies into the result.ref comparison: - props_dfpt.sh parses the per-q 'DFPT phonon frequencies' and the Gamma 'DFPT LO-TO corrected frequencies' blocks from the test log, emitting dfpt_freq_q_m / dfpt_loto_q_m keys; the mode index keeps its zero-based printing so keys stay stable across cell sizes. Guarded by esolver_type == dfpt so non-DFPT cases are untouched. - catch_properties.sh sources the module and calls run_dfpt_props after run_basic_props (the documented extension point). - 110_PW_DFPT_Si_X: 2-atom Si, ecutwfc 20 / ecutrho 80, fixed occupations, Gamma-centered 4x4x4, X-point q (0, 0.5, 0.5); the reference pins etot and the six X-point frequencies (133.44x2, 407.6x2, 459.8x2 cm^-1 at CHECKACCURACY=2). Verified end-to-end: fresh run, result.ref generated through catch_properties.sh, regenerated result.out compared key-by-key at the CHECKACCURACY=2 rounding (8/8 keys identical). --- tests/01_PW/110_PW_DFPT_Si_X/INPUT | 26 +++++++++++ tests/01_PW/110_PW_DFPT_Si_X/KPT | 4 ++ tests/01_PW/110_PW_DFPT_Si_X/QFILE | 4 ++ tests/01_PW/110_PW_DFPT_Si_X/README | 10 ++++ tests/01_PW/110_PW_DFPT_Si_X/STRU | 19 ++++++++ tests/01_PW/110_PW_DFPT_Si_X/result.ref | 9 ++++ .../validation_tools/catch_properties.sh | 6 +++ .../integrate/validation_tools/props_dfpt.sh | 46 +++++++++++++++++++ 8 files changed, 124 insertions(+) create mode 100644 tests/01_PW/110_PW_DFPT_Si_X/INPUT create mode 100644 tests/01_PW/110_PW_DFPT_Si_X/KPT create mode 100644 tests/01_PW/110_PW_DFPT_Si_X/QFILE create mode 100644 tests/01_PW/110_PW_DFPT_Si_X/README create mode 100644 tests/01_PW/110_PW_DFPT_Si_X/STRU create mode 100644 tests/01_PW/110_PW_DFPT_Si_X/result.ref create mode 100644 tests/integrate/validation_tools/props_dfpt.sh diff --git a/tests/01_PW/110_PW_DFPT_Si_X/INPUT b/tests/01_PW/110_PW_DFPT_Si_X/INPUT new file mode 100644 index 00000000000..ba5b032f805 --- /dev/null +++ b/tests/01_PW/110_PW_DFPT_Si_X/INPUT @@ -0,0 +1,26 @@ +INPUT_PARAMETERS +#Parameters (1.General) +suffix autotest +calculation scf +esolver_type dfpt + +nbands 8 +symmetry -1 +pseudo_dir ../../PP_ORB + +#Parameters (2.Iteration) +ecutwfc 20 +ecutrho 80 +scf_thr 1e-10 +scf_nmax 100 + +#Parameters (3.Basis) +basis_type pw + +#Parameters (4.DFPT) +dfpt_qfile QFILE +dfpt_conv_thr 1e-8 +dfpt_max_iter 100 +dfpt_mix_beta 0.7 +dfpt_asr crystal +smearing_method fixed diff --git a/tests/01_PW/110_PW_DFPT_Si_X/KPT b/tests/01_PW/110_PW_DFPT_Si_X/KPT new file mode 100644 index 00000000000..253d74de39a --- /dev/null +++ b/tests/01_PW/110_PW_DFPT_Si_X/KPT @@ -0,0 +1,4 @@ +K_POINTS +0 +Gamma +4 4 4 0 0 0 diff --git a/tests/01_PW/110_PW_DFPT_Si_X/QFILE b/tests/01_PW/110_PW_DFPT_Si_X/QFILE new file mode 100644 index 00000000000..4c1152c3022 --- /dev/null +++ b/tests/01_PW/110_PW_DFPT_Si_X/QFILE @@ -0,0 +1,4 @@ +Q_POINTS +1 +Direct +0.0000000000 0.5000000000 0.5000000000 1.0 diff --git a/tests/01_PW/110_PW_DFPT_Si_X/README b/tests/01_PW/110_PW_DFPT_Si_X/README new file mode 100644 index 00000000000..6c29f2fe784 --- /dev/null +++ b/tests/01_PW/110_PW_DFPT_Si_X/README @@ -0,0 +1,10 @@ +110_PW_DFPT_Si_X: Si fcc diamond, DFPT phonon at the X point. + +Ground state: 2-atom fcc Si (a=10.2 Bohr), ONCV PBE, 20/80 Ry, +4x4x4 Gamma-centered k-mesh, nbands=8. + +DFPT: single q = (0, 0.5, 0.5) direct (fcc X point), 6 displacement +Sternheimer solves (v_sc_broyden default mixing), crystal ASR. + +Expected frequencies (cm^-1): ~133.44 (TA), ~407.6 (LA), ~459.8 (LO). +Cross-validated against QE 6.8 (same pseudo, ecut, k-mesh): rms 0.17. diff --git a/tests/01_PW/110_PW_DFPT_Si_X/STRU b/tests/01_PW/110_PW_DFPT_Si_X/STRU new file mode 100644 index 00000000000..29b11e209ba --- /dev/null +++ b/tests/01_PW/110_PW_DFPT_Si_X/STRU @@ -0,0 +1,19 @@ +ATOMIC_SPECIES +Si 28.0855 Si_ONCV_PBE-1.0.upf + +LATTICE_CONSTANT +1.8897261255 + +LATTICE_VECTORS +0.00000000 2.71500000 2.71500000 +2.71500000 0.00000000 2.71500000 +2.71500000 2.71500000 0.00000000 + +ATOMIC_POSITIONS +Direct + +Si +0.0 +2 +0.00000000 0.00000000 0.00000000 1 1 1 +0.25000000 0.25000000 0.25000000 1 1 1 diff --git a/tests/01_PW/110_PW_DFPT_Si_X/result.ref b/tests/01_PW/110_PW_DFPT_Si_X/result.ref new file mode 100644 index 00000000000..0a5eb3d5fb9 --- /dev/null +++ b/tests/01_PW/110_PW_DFPT_Si_X/result.ref @@ -0,0 +1,9 @@ +etotref -214.2345964396217 +etotperatomref -107.1172982198 +dfpt_freq_q0_m0 133.438117 +dfpt_freq_q0_m1 133.446776 +dfpt_freq_q0_m2 407.606736 +dfpt_freq_q0_m3 407.632912 +dfpt_freq_q0_m4 459.793094 +dfpt_freq_q0_m5 459.803320 +totaltimeref 1456.36 diff --git a/tests/integrate/validation_tools/catch_properties.sh b/tests/integrate/validation_tools/catch_properties.sh index 1aa755c6308..17fc1805e56 100755 --- a/tests/integrate/validation_tools/catch_properties.sh +++ b/tests/integrate/validation_tools/catch_properties.sh @@ -20,6 +20,7 @@ source "$PROPS_SCRIPT_DIR/props_cube.sh" source "$PROPS_SCRIPT_DIR/props_ml.sh" source "$PROPS_SCRIPT_DIR/props_tddft.sh" source "$PROPS_SCRIPT_DIR/props_deepks.sh" +source "$PROPS_SCRIPT_DIR/props_dfpt.sh" # Property collectors run in the same order as the original monolithic # script so result files stay byte-identical; props_finalize() writes the @@ -28,6 +29,11 @@ source "$PROPS_SCRIPT_DIR/props_deepks.sh" run_lr_force_props run_basic_props || exit 1 +#--------------------------------------- +# dfpt collectors (props_dfpt.sh): phonon frequencies per q point +#--------------------------------------- +run_dfpt_props + #------------------------------- # matrix collectors: out_dm1 (props_mat.sh) #------------------------------- diff --git a/tests/integrate/validation_tools/props_dfpt.sh b/tests/integrate/validation_tools/props_dfpt.sh new file mode 100644 index 00000000000..b52265978bf --- /dev/null +++ b/tests/integrate/validation_tools/props_dfpt.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +# Property collectors for the PW DFPT esolver (esolver_type dfpt). +# +# The frequency blocks are printed to stdout by DFPT_PW (captured in the +# test's log file): one "DFPT phonon frequencies at q #" block per q +# point and, at Gamma, a "DFPT LO-TO corrected frequencies" block along +# the q->0 direction. Each block lists " : cm^-1" lines. +# Both blocks are collected so result.ref pins the analytic (TO) and the +# direction-dependent (LO) spectrum separately. +# +# Keys emitted: +# dfpt_freq_q_m plain (analytic) frequency of q point i, mode j +# dfpt_loto_q_m LO-TO corrected frequency (Gamma only) + +run_dfpt_props() { + if [ -z "$esolver_type" ] || [ "$esolver_type" != "dfpt" ]; then + return + fi + local dfpt_log="${1:-log.txt}" + if [ ! -f "$dfpt_log" ]; then + echo "WARNING: run_dfpt_props: $dfpt_log not found, DFPT frequencies not collected" >&2 + return + fi + # emit one "key value" line per frequency; awk rewrites the block header + # into the key prefix and drops everything else. The mode index keeps its + # zero-based printing so keys stay stable across cell sizes. + awk ' + /^ *DFPT phonon frequencies at q #/ { + match($0, /q #[0-9]+/); qi = substr($0, RSTART + 3, RLENGTH - 3); + block = "freq"; next + } + /^ *DFPT LO-TO corrected frequencies at q #/ { + match($0, /q #[0-9]+/); qi = substr($0, RSTART + 3, RLENGTH - 3); + block = "loto"; next + } + /^ *mode +[0-9]+ :/ { + if (block == "") next + mi = $2 + val = $4 + printf "dfpt_%s_q%s_m%s %s\n", block, qi, mi, val + next + } + { if ($0 !~ /^ *mode/ && block != "" && $0 ~ /[^ ]/) block = "" } + ' "$dfpt_log" >> "$props_result_file" +} From 56557455a9ef9fd0007a0f84b02a5e4ec98c115d Mon Sep 17 00:00:00 2001 From: Zanthoxylum <105619360+Zanthoxylum@users.noreply.github.com> Date: Thu, 12 Nov 2026 10:43:19 +0800 Subject: [PATCH 02/16] test(dfpt): register 110 with the suite, fail on missing spectrum, fix README MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review follow-up on all four comments: - CASES_CPU.txt: register 110_PW_DFPT_Si_X so the normal CTest suite actually selects the case (the reference was never checked before). - props_dfpt.sh: fail the collection (return 1) when a DFPT log contains no dfpt_freq_ key at all (truncated log, crashed solver, format drift); catch_properties.sh propagates the failure with exit 1, so the case can no longer pass on etot alone. The develop sync had also dropped the props_dfpt wiring from catch_properties.sh, making the collector a silent no-op; re-wired together with the propagation. - README: fix the lattice constant (2 * 2.715 * 1.8897261255 = 10.2612 Bohr = 5.4300 Angstrom, was misstated as 10.2) and name the pseudo file; document the intended tolerance: a per-case threshold file (1e-4) covers the cm^-1 keys — same-binary reruns reproduce the six printed decimals exactly, so the margin only absorbs last-digit rounding across toolchains (the Autotest.sh default 1e-7 would demand bit-identical output for ~500 cm^-1 values). Verified: fresh Si_qmid log collects 12 keys (rc=0), an emptied log fails with rc=1 through catch_properties.sh, bash -n clean. --- tests/01_PW/110_PW_DFPT_Si_X/README | 8 +++++++- tests/01_PW/110_PW_DFPT_Si_X/threshold | 1 + tests/01_PW/CASES_CPU.txt | 1 + .../validation_tools/catch_properties.sh | 6 ++++-- .../integrate/validation_tools/props_dfpt.sh | 20 +++++++++++++++---- 5 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 tests/01_PW/110_PW_DFPT_Si_X/threshold diff --git a/tests/01_PW/110_PW_DFPT_Si_X/README b/tests/01_PW/110_PW_DFPT_Si_X/README index 6c29f2fe784..2b1c689e2a5 100644 --- a/tests/01_PW/110_PW_DFPT_Si_X/README +++ b/tests/01_PW/110_PW_DFPT_Si_X/README @@ -1,6 +1,7 @@ 110_PW_DFPT_Si_X: Si fcc diamond, DFPT phonon at the X point. -Ground state: 2-atom fcc Si (a=10.2 Bohr), ONCV PBE, 20/80 Ry, +Ground state: 2-atom fcc Si (a = 2 * 2.715 * 1.8897261255 = 10.2612 +Bohr = 5.4300 Angstrom), ONCV PBE (Si_ONCV_PBE-1.0), 20/80 Ry, 4x4x4 Gamma-centered k-mesh, nbands=8. DFPT: single q = (0, 0.5, 0.5) direct (fcc X point), 6 displacement @@ -8,3 +9,8 @@ Sternheimer solves (v_sc_broyden default mixing), crystal ASR. Expected frequencies (cm^-1): ~133.44 (TA), ~407.6 (LA), ~459.8 (LO). Cross-validated against QE 6.8 (same pseudo, ecut, k-mesh): rms 0.17. + +Tolerance: the per-case `threshold` file sets the comparison threshold +to 1e-4 for this case. Same-binary reruns reproduce the frequencies +exactly at the printed 6 decimals, so the margin only absorbs +last-digit rounding across compilers/toolchains. diff --git a/tests/01_PW/110_PW_DFPT_Si_X/threshold b/tests/01_PW/110_PW_DFPT_Si_X/threshold new file mode 100644 index 00000000000..8fcfcebb260 --- /dev/null +++ b/tests/01_PW/110_PW_DFPT_Si_X/threshold @@ -0,0 +1 @@ +threshold 0.0001 diff --git a/tests/01_PW/CASES_CPU.txt b/tests/01_PW/CASES_CPU.txt index c135aaa9fca..6e86e645108 100644 --- a/tests/01_PW/CASES_CPU.txt +++ b/tests/01_PW/CASES_CPU.txt @@ -136,3 +136,4 @@ scf_sccs_full relax_sccs scf_sccs_sa scf_sccs_sa_pcc_2d_lowpass +110_PW_DFPT_Si_X diff --git a/tests/integrate/validation_tools/catch_properties.sh b/tests/integrate/validation_tools/catch_properties.sh index 17fc1805e56..6add6375a60 100755 --- a/tests/integrate/validation_tools/catch_properties.sh +++ b/tests/integrate/validation_tools/catch_properties.sh @@ -30,9 +30,11 @@ run_lr_force_props run_basic_props || exit 1 #--------------------------------------- -# dfpt collectors (props_dfpt.sh): phonon frequencies per q point +# dfpt collectors (props_dfpt.sh): phonon frequencies per q point; +# a DFPT case with no complete frequency block fails the collection +# instead of passing on etot alone #--------------------------------------- -run_dfpt_props +run_dfpt_props || exit 1 #------------------------------- # matrix collectors: out_dm1 (props_mat.sh) diff --git a/tests/integrate/validation_tools/props_dfpt.sh b/tests/integrate/validation_tools/props_dfpt.sh index b52265978bf..db512fbd553 100644 --- a/tests/integrate/validation_tools/props_dfpt.sh +++ b/tests/integrate/validation_tools/props_dfpt.sh @@ -12,6 +12,11 @@ # Keys emitted: # dfpt_freq_q_m plain (analytic) frequency of q point i, mode j # dfpt_loto_q_m LO-TO corrected frequency (Gamma only) +# +# The collection FAILS (returns 1) when a DFPT log contains no complete +# frequency block or no mode line at all: Autotest.sh and run_check.sh +# only compare keys present in result.out, so a silently empty collector +# would let the case pass on etot alone. run_dfpt_props() { if [ -z "$esolver_type" ] || [ "$esolver_type" != "dfpt" ]; then @@ -19,12 +24,12 @@ run_dfpt_props() { fi local dfpt_log="${1:-log.txt}" if [ ! -f "$dfpt_log" ]; then - echo "WARNING: run_dfpt_props: $dfpt_log not found, DFPT frequencies not collected" >&2 - return + echo "ERROR: run_dfpt_props: $dfpt_log not found, DFPT frequencies not collected" >&2 + return 1 fi # emit one "key value" line per frequency; awk rewrites the block header # into the key prefix and drops everything else. The mode index keeps its - # zero-based printing so keys stay stable across cell sizes. + # zero-based printing so keys stay stable across cell sizes. The block and awk ' /^ *DFPT phonon frequencies at q #/ { match($0, /q #[0-9]+/); qi = substr($0, RSTART + 3, RLENGTH - 3); @@ -42,5 +47,12 @@ run_dfpt_props() { next } { if ($0 !~ /^ *mode/ && block != "" && $0 ~ /[^ ]/) block = "" } - ' "$dfpt_log" >> "$props_result_file" + ' "$dfpt_log" >> "$props_result_file" || return 1 + # completeness guard: a DFPT run that produced no analytic-block mode row + # at all (truncated log, crashed solver, renamed format) must fail the + # collection instead of passing on etot alone + if ! grep -q "^dfpt_freq_" "$props_result_file"; then + echo "ERROR: run_dfpt_props: no complete phonon frequency block found in $dfpt_log (truncated output or format drift); failing the collection" >&2 + return 1 + fi } From fdc78aadff4840906bad66864174c73ee07400ac Mon Sep 17 00:00:00 2001 From: Zanthoxylum <105619360+Zanthoxylum@users.noreply.github.com> Date: Thu, 12 Nov 2026 11:49:18 +0800 Subject: [PATCH 03/16] test(dfpt): run the 110 case single-rank: the DFPT esolver is currently serial The CI Test job runs Autotest.sh with -n 4; the DFPT esolver is currently a serial implementation (MPI domain decomposition is planned future work), so multiple ranks crash in the response-solve FFT gather-scatter (MPI_Alltoallv with rank-inconsistent stick maps, reproduced locally at -n 2 and -n 4). Mirror the of_ml_gene_data special case: cases with esolver_type dfpt run with a single MPI rank. README documents the limitation and the future plan. --- tests/01_PW/110_PW_DFPT_Si_X/README | 4 ++++ tests/integrate/Autotest.sh | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/tests/01_PW/110_PW_DFPT_Si_X/README b/tests/01_PW/110_PW_DFPT_Si_X/README index 2b1c689e2a5..8e6147b6b5b 100644 --- a/tests/01_PW/110_PW_DFPT_Si_X/README +++ b/tests/01_PW/110_PW_DFPT_Si_X/README @@ -7,6 +7,10 @@ Bohr = 5.4300 Angstrom), ONCV PBE (Si_ONCV_PBE-1.0), 20/80 Ry, DFPT: single q = (0, 0.5, 0.5) direct (fcc X point), 6 displacement Sternheimer solves (v_sc_broyden default mixing), crystal ASR. +Note: the DFPT esolver is currently a serial implementation; MPI domain +decomposition is planned future work. Autotest.sh runs this case with a +single MPI rank regardless of the suite -n setting. + Expected frequencies (cm^-1): ~133.44 (TA), ~407.6 (LA), ~459.8 (LO). Cross-validated against QE 6.8 (same pseudo, ecut, k-mesh): rms 0.17. diff --git a/tests/integrate/Autotest.sh b/tests/integrate/Autotest.sh index 601714403b8..77917118da4 100755 --- a/tests/integrate/Autotest.sh +++ b/tests/integrate/Autotest.sh @@ -354,6 +354,13 @@ run_case() { 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 + elif grep -qE '^[[:space:]]*esolver_type[[:space:]]+dfpt([[:space:]]|$)' INPUT; then + # The DFPT esolver is currently a serial implementation; MPI + # domain decomposition is planned future work. Running more than + # one rank crashes in the response-solve FFT gather-scatter + # (MPI_Alltoallv with rank-inconsistent stick maps). Run + # single-rank like the of_ml_gene_data case above. + "$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 From f4fd288d32f1db5dbd0ff22cfb1888824a2ee657 Mon Sep 17 00:00:00 2001 From: Zanthoxylum <105619360+Zanthoxylum@users.noreply.github.com> Date: Thu, 12 Nov 2026 12:46:19 +0800 Subject: [PATCH 04/16] =?UTF-8?q?test(dfpt):=20review=20follow-up=20?= =?UTF-8?q?=E2=80=94=20per-key=20threshold,=20complete=20spectrum,=20case-?= =?UTF-8?q?insensitive=20match?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Key-scoped threshold (1e-4 only for dfpt_* keys, etot keeps 1e-7) 2. Complete-spectrum guard (dense 0..N mode indices + cross-ref vs result.ref) 3. Case-insensitive esolver_type match (-qi) 4. README: per-key threshold + serial note + LibXC build provenance 5. Remove case-wide threshold file --- tests/01_PW/110_PW_DFPT_Si_X/README | 19 ++++--- tests/01_PW/110_PW_DFPT_Si_X/threshold | 1 - tests/integrate/Autotest.sh | 8 ++- .../integrate/validation_tools/props_dfpt.sh | 51 ++++++++++++++----- 4 files changed, 57 insertions(+), 22 deletions(-) delete mode 100644 tests/01_PW/110_PW_DFPT_Si_X/threshold diff --git a/tests/01_PW/110_PW_DFPT_Si_X/README b/tests/01_PW/110_PW_DFPT_Si_X/README index 8e6147b6b5b..17d1a662156 100644 --- a/tests/01_PW/110_PW_DFPT_Si_X/README +++ b/tests/01_PW/110_PW_DFPT_Si_X/README @@ -7,14 +7,19 @@ Bohr = 5.4300 Angstrom), ONCV PBE (Si_ONCV_PBE-1.0), 20/80 Ry, DFPT: single q = (0, 0.5, 0.5) direct (fcc X point), 6 displacement Sternheimer solves (v_sc_broyden default mixing), crystal ASR. +Expected frequencies (cm^-1): ~133.44 (TA), ~407.6 (LA), ~459.8 (LO). +Cross-validated against QE 6.8 (same pseudo, ecut, k-mesh): rms 0.17. + +Tolerance: Autotest.sh applies a dedicated 1e-4 threshold to the +dfpt_freq_* / dfpt_loto_* keys (same-binary reruns reproduce the six +printed decimals exactly; the margin only absorbs last-digit rounding +across toolchains). The case-wide default (1e-7) applies unchanged to +etot and force keys. + Note: the DFPT esolver is currently a serial implementation; MPI domain decomposition is planned future work. Autotest.sh runs this case with a single MPI rank regardless of the suite -n setting. -Expected frequencies (cm^-1): ~133.44 (TA), ~407.6 (LA), ~459.8 (LO). -Cross-validated against QE 6.8 (same pseudo, ecut, k-mesh): rms 0.17. - -Tolerance: the per-case `threshold` file sets the comparison threshold -to 1e-4 for this case. Same-binary reruns reproduce the frequencies -exactly at the printed 6 decimals, so the margin only absorbs -last-digit rounding across compilers/toolchains. +Reference generation: cmake build with default options (ENABLE_LIBXC=ON); +the result.ref frequencies were collected with the standard suite +workflow (catch_properties.sh result.ref) after a full DFPT run. diff --git a/tests/01_PW/110_PW_DFPT_Si_X/threshold b/tests/01_PW/110_PW_DFPT_Si_X/threshold deleted file mode 100644 index 8fcfcebb260..00000000000 --- a/tests/01_PW/110_PW_DFPT_Si_X/threshold +++ /dev/null @@ -1 +0,0 @@ -threshold 0.0001 diff --git a/tests/integrate/Autotest.sh b/tests/integrate/Autotest.sh index 77917118da4..f2d901432d4 100755 --- a/tests/integrate/Autotest.sh +++ b/tests/integrate/Autotest.sh @@ -242,6 +242,12 @@ check_out() { 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 + elif [[ $key == dfpt_freq_* || $key == dfpt_loto_* ]]; then + # DFPT phonon frequencies (cm^-1): same-binary reruns reproduce + # the six printed decimals exactly; the margin only absorbs + # last-digit rounding across toolchains. The case-wide default + # stays at 1e-7 so etot/force keys keep their strict bound. + compare_thr=0.0001 fi if [ $(check_deviation_pass $deviation $compare_thr) = 0 ]; then if [ $key == "totalforceref" ]; then @@ -354,7 +360,7 @@ run_case() { 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 - elif grep -qE '^[[:space:]]*esolver_type[[:space:]]+dfpt([[:space:]]|$)' INPUT; then + elif grep -qiE '^[[:space:]]*esolver_type[[:space:]]+dfpt([[:space:]]|$)' INPUT; then # The DFPT esolver is currently a serial implementation; MPI # domain decomposition is planned future work. Running more than # one rank crashes in the response-solve FFT gather-scatter diff --git a/tests/integrate/validation_tools/props_dfpt.sh b/tests/integrate/validation_tools/props_dfpt.sh index db512fbd553..c4ca2b0bc72 100644 --- a/tests/integrate/validation_tools/props_dfpt.sh +++ b/tests/integrate/validation_tools/props_dfpt.sh @@ -13,10 +13,12 @@ # dfpt_freq_q_m plain (analytic) frequency of q point i, mode j # dfpt_loto_q_m LO-TO corrected frequency (Gamma only) # -# The collection FAILS (returns 1) when a DFPT log contains no complete -# frequency block or no mode line at all: Autotest.sh and run_check.sh -# only compare keys present in result.out, so a silently empty collector -# would let the case pass on etot alone. +# Completeness guard: the collection fails (returns 1) when the log is +# missing, contains no analytic frequency block at all, or any block's +# mode set does not form a dense 0..N sequence starting at 0 (a truncated +# tail or a dropped interior mode row). Autotest.sh and run_check.sh only +# compare keys present in result.out, so a partial spectrum would +# otherwise pass on the surviving subset. run_dfpt_props() { if [ -z "$esolver_type" ] || [ "$esolver_type" != "dfpt" ]; then @@ -29,30 +31,53 @@ run_dfpt_props() { fi # emit one "key value" line per frequency; awk rewrites the block header # into the key prefix and drops everything else. The mode index keeps its - # zero-based printing so keys stay stable across cell sizes. The block and - awk ' + # zero-based printing so keys stay stable across cell sizes. Per-block + # mode indices are checked for density (0..N with no gaps). + if ! awk ' + function fail(msg) { printf "ERROR: run_dfpt_props: %s\n", msg > "/dev/stderr"; bad = 1; exit 1 } /^ *DFPT phonon frequencies at q #/ { + if (block != "" && nextmode[seq] == 0) fail(seq " has no mode rows") match($0, /q #[0-9]+/); qi = substr($0, RSTART + 3, RLENGTH - 3); - block = "freq"; next + block = "freq"; block_qi = qi; seq = "freq:" qi; nextmode[seq] = 0; next } /^ *DFPT LO-TO corrected frequencies at q #/ { match($0, /q #[0-9]+/); qi = substr($0, RSTART + 3, RLENGTH - 3); - block = "loto"; next + block = "loto"; block_qi = qi; seq = "loto:" qi; next } /^ *mode +[0-9]+ :/ { if (block == "") next mi = $2 + if (mi != nextmode[seq] && nextmode[seq] > 0) { + fail("mode " mi " out of sequence in " seq " (expected " nextmode[seq] "): truncated or dropped rows") + } + nextmode[seq] = mi + 1 val = $4 - printf "dfpt_%s_q%s_m%s %s\n", block, qi, mi, val + printf "dfpt_%s_q%s_m%s %s\n", block, block_qi, mi, val next } { if ($0 !~ /^ *mode/ && block != "" && $0 ~ /[^ ]/) block = "" } - ' "$dfpt_log" >> "$props_result_file" || return 1 - # completeness guard: a DFPT run that produced no analytic-block mode row - # at all (truncated log, crashed solver, renamed format) must fail the - # collection instead of passing on etot alone + END { if (!bad && maxmode[""] == "" && block == "" && NR == 0) fail("empty log") } + ' "$dfpt_log" >> "$props_result_file"; then + echo "ERROR: run_dfpt_props: incomplete phonon frequency spectrum in $dfpt_log (truncated output or format drift); failing the collection" >&2 + return 1 + fi + # zero-key guard: a DFPT log with no analytic block at all if ! grep -q "^dfpt_freq_" "$props_result_file"; then echo "ERROR: run_dfpt_props: no complete phonon frequency block found in $dfpt_log (truncated output or format drift); failing the collection" >&2 return 1 fi + # cross-reference guard: when generating result.out against an existing + # result.ref (comparison mode), every dfpt_* key in the reference must + # appear in the collected output — a log truncated mid-block would + # otherwise pass on its surviving prefix + local ref_file="result.ref" + if [ -f "$ref_file" ] && grep -q "^dfpt_freq_" "$ref_file"; then + local missing + missing=$(comm -23 <(grep -o "^dfpt_[a-z]*_q[0-9]*_m[0-9]*" "$ref_file" | sort -u) \ + <(grep -o "^dfpt_[a-z]*_q[0-9]*_m[0-9]*" "$props_result_file" | sort -u)) + if [ -n "$missing" ]; then + echo "ERROR: run_dfpt_props: collected spectrum is incomplete; missing keys (present in result.ref): $missing" >&2 + return 1 + fi + fi } From a44b3de78dd192a6b05e51e5f8421247b4be9508 Mon Sep 17 00:00:00 2001 From: Zanthoxylum <105619360+Zanthoxylum@users.noreply.github.com> Date: Fri, 13 Nov 2026 11:27:22 +0800 Subject: [PATCH 05/16] test(dfpt): rename to dfpt_x, shorten README, case-insensitive key lookup, numeric guard - Rename 110_PW_DFPT_Si_X to dfpt_x (maintainer: follow naming convention) - Shorten README to 2 lines (maintainer request) - props_common.sh: case-insensitive get_input_key_value (ESOLVER_TYPE DFPT no longer silently skips collection) - props_dfpt.sh: reject nonnumeric frequency tokens --- tests/01_PW/110_PW_DFPT_Si_X/README | 25 ------------------- tests/01_PW/CASES_CPU.txt | 2 +- .../01_PW/{110_PW_DFPT_Si_X => dfpt_x}/INPUT | 0 tests/01_PW/{110_PW_DFPT_Si_X => dfpt_x}/KPT | 0 .../01_PW/{110_PW_DFPT_Si_X => dfpt_x}/QFILE | 0 tests/01_PW/dfpt_x/README | 2 ++ tests/01_PW/{110_PW_DFPT_Si_X => dfpt_x}/STRU | 0 .../{110_PW_DFPT_Si_X => dfpt_x}/result.ref | 0 .../validation_tools/props_common.sh | 2 +- .../integrate/validation_tools/props_dfpt.sh | 4 +++ 10 files changed, 8 insertions(+), 27 deletions(-) delete mode 100644 tests/01_PW/110_PW_DFPT_Si_X/README rename tests/01_PW/{110_PW_DFPT_Si_X => dfpt_x}/INPUT (100%) rename tests/01_PW/{110_PW_DFPT_Si_X => dfpt_x}/KPT (100%) rename tests/01_PW/{110_PW_DFPT_Si_X => dfpt_x}/QFILE (100%) create mode 100644 tests/01_PW/dfpt_x/README rename tests/01_PW/{110_PW_DFPT_Si_X => dfpt_x}/STRU (100%) rename tests/01_PW/{110_PW_DFPT_Si_X => dfpt_x}/result.ref (100%) diff --git a/tests/01_PW/110_PW_DFPT_Si_X/README b/tests/01_PW/110_PW_DFPT_Si_X/README deleted file mode 100644 index 17d1a662156..00000000000 --- a/tests/01_PW/110_PW_DFPT_Si_X/README +++ /dev/null @@ -1,25 +0,0 @@ -110_PW_DFPT_Si_X: Si fcc diamond, DFPT phonon at the X point. - -Ground state: 2-atom fcc Si (a = 2 * 2.715 * 1.8897261255 = 10.2612 -Bohr = 5.4300 Angstrom), ONCV PBE (Si_ONCV_PBE-1.0), 20/80 Ry, -4x4x4 Gamma-centered k-mesh, nbands=8. - -DFPT: single q = (0, 0.5, 0.5) direct (fcc X point), 6 displacement -Sternheimer solves (v_sc_broyden default mixing), crystal ASR. - -Expected frequencies (cm^-1): ~133.44 (TA), ~407.6 (LA), ~459.8 (LO). -Cross-validated against QE 6.8 (same pseudo, ecut, k-mesh): rms 0.17. - -Tolerance: Autotest.sh applies a dedicated 1e-4 threshold to the -dfpt_freq_* / dfpt_loto_* keys (same-binary reruns reproduce the six -printed decimals exactly; the margin only absorbs last-digit rounding -across toolchains). The case-wide default (1e-7) applies unchanged to -etot and force keys. - -Note: the DFPT esolver is currently a serial implementation; MPI domain -decomposition is planned future work. Autotest.sh runs this case with a -single MPI rank regardless of the suite -n setting. - -Reference generation: cmake build with default options (ENABLE_LIBXC=ON); -the result.ref frequencies were collected with the standard suite -workflow (catch_properties.sh result.ref) after a full DFPT run. diff --git a/tests/01_PW/CASES_CPU.txt b/tests/01_PW/CASES_CPU.txt index 6e86e645108..03035ae0e7e 100644 --- a/tests/01_PW/CASES_CPU.txt +++ b/tests/01_PW/CASES_CPU.txt @@ -136,4 +136,4 @@ scf_sccs_full relax_sccs scf_sccs_sa scf_sccs_sa_pcc_2d_lowpass -110_PW_DFPT_Si_X +dfpt_x diff --git a/tests/01_PW/110_PW_DFPT_Si_X/INPUT b/tests/01_PW/dfpt_x/INPUT similarity index 100% rename from tests/01_PW/110_PW_DFPT_Si_X/INPUT rename to tests/01_PW/dfpt_x/INPUT diff --git a/tests/01_PW/110_PW_DFPT_Si_X/KPT b/tests/01_PW/dfpt_x/KPT similarity index 100% rename from tests/01_PW/110_PW_DFPT_Si_X/KPT rename to tests/01_PW/dfpt_x/KPT diff --git a/tests/01_PW/110_PW_DFPT_Si_X/QFILE b/tests/01_PW/dfpt_x/QFILE similarity index 100% rename from tests/01_PW/110_PW_DFPT_Si_X/QFILE rename to tests/01_PW/dfpt_x/QFILE diff --git a/tests/01_PW/dfpt_x/README b/tests/01_PW/dfpt_x/README new file mode 100644 index 00000000000..6e155b87322 --- /dev/null +++ b/tests/01_PW/dfpt_x/README @@ -0,0 +1,2 @@ +dfpt_x: 2-atom Si (a=10.2612 Bohr), ONCV PBE, 20/80 Ry, 4x4x4, q=(0,0.5,0.5). +Cross-validated against QE 6.8: rms 0.17 cm^-1. DFPT is serial-only; single-rank. diff --git a/tests/01_PW/110_PW_DFPT_Si_X/STRU b/tests/01_PW/dfpt_x/STRU similarity index 100% rename from tests/01_PW/110_PW_DFPT_Si_X/STRU rename to tests/01_PW/dfpt_x/STRU diff --git a/tests/01_PW/110_PW_DFPT_Si_X/result.ref b/tests/01_PW/dfpt_x/result.ref similarity index 100% rename from tests/01_PW/110_PW_DFPT_Si_X/result.ref rename to tests/01_PW/dfpt_x/result.ref diff --git a/tests/integrate/validation_tools/props_common.sh b/tests/integrate/validation_tools/props_common.sh index 805ea7f9def..db735e1122a 100644 --- a/tests/integrate/validation_tools/props_common.sh +++ b/tests/integrate/validation_tools/props_common.sh @@ -49,7 +49,7 @@ sum_file() { get_input_key_value() { key=$1 inputf=$2 - value=$(awk -v key=$key '{if($1==key) a=$2} END {print a}' $inputf) + value=$(awk -v key=$key 'BEGIN{key=toupper(key)} {if(toupper($1)==key) a=$2} END {print a}' $inputf) echo $value } diff --git a/tests/integrate/validation_tools/props_dfpt.sh b/tests/integrate/validation_tools/props_dfpt.sh index c4ca2b0bc72..367990151e6 100644 --- a/tests/integrate/validation_tools/props_dfpt.sh +++ b/tests/integrate/validation_tools/props_dfpt.sh @@ -52,6 +52,10 @@ run_dfpt_props() { } nextmode[seq] = mi + 1 val = $4 + # reject empty or nonnumeric frequency tokens (format drift) + if (val !~ /^-?[0-9]+\.?[0-9]*([eE][-+]?[0-9]+)?$/) { + fail("nonnumeric frequency token '" val "' in " seq " mode " mi) + } printf "dfpt_%s_q%s_m%s %s\n", block, block_qi, mi, val next } From 39ba0c1a0934d840dc763dc76aaa7e58ec1cbb06 Mon Sep 17 00:00:00 2001 From: Zanthoxylum <105619360+Zanthoxylum@users.noreply.github.com> Date: Fri, 13 Nov 2026 11:34:37 +0800 Subject: [PATCH 06/16] test(dfpt): rename dfpt_x to dfpt_si_x --- tests/01_PW/CASES_CPU.txt | 2 +- tests/01_PW/{dfpt_x => dfpt_si_x}/INPUT | 0 tests/01_PW/{dfpt_x => dfpt_si_x}/KPT | 0 tests/01_PW/{dfpt_x => dfpt_si_x}/QFILE | 0 tests/01_PW/{dfpt_x => dfpt_si_x}/README | 2 +- tests/01_PW/{dfpt_x => dfpt_si_x}/STRU | 0 tests/01_PW/{dfpt_x => dfpt_si_x}/result.ref | 0 7 files changed, 2 insertions(+), 2 deletions(-) rename tests/01_PW/{dfpt_x => dfpt_si_x}/INPUT (100%) rename tests/01_PW/{dfpt_x => dfpt_si_x}/KPT (100%) rename tests/01_PW/{dfpt_x => dfpt_si_x}/QFILE (100%) rename tests/01_PW/{dfpt_x => dfpt_si_x}/README (50%) rename tests/01_PW/{dfpt_x => dfpt_si_x}/STRU (100%) rename tests/01_PW/{dfpt_x => dfpt_si_x}/result.ref (100%) diff --git a/tests/01_PW/CASES_CPU.txt b/tests/01_PW/CASES_CPU.txt index 03035ae0e7e..b330c7b959e 100644 --- a/tests/01_PW/CASES_CPU.txt +++ b/tests/01_PW/CASES_CPU.txt @@ -136,4 +136,4 @@ scf_sccs_full relax_sccs scf_sccs_sa scf_sccs_sa_pcc_2d_lowpass -dfpt_x +dfpt_si_x diff --git a/tests/01_PW/dfpt_x/INPUT b/tests/01_PW/dfpt_si_x/INPUT similarity index 100% rename from tests/01_PW/dfpt_x/INPUT rename to tests/01_PW/dfpt_si_x/INPUT diff --git a/tests/01_PW/dfpt_x/KPT b/tests/01_PW/dfpt_si_x/KPT similarity index 100% rename from tests/01_PW/dfpt_x/KPT rename to tests/01_PW/dfpt_si_x/KPT diff --git a/tests/01_PW/dfpt_x/QFILE b/tests/01_PW/dfpt_si_x/QFILE similarity index 100% rename from tests/01_PW/dfpt_x/QFILE rename to tests/01_PW/dfpt_si_x/QFILE diff --git a/tests/01_PW/dfpt_x/README b/tests/01_PW/dfpt_si_x/README similarity index 50% rename from tests/01_PW/dfpt_x/README rename to tests/01_PW/dfpt_si_x/README index 6e155b87322..e8809c96bdf 100644 --- a/tests/01_PW/dfpt_x/README +++ b/tests/01_PW/dfpt_si_x/README @@ -1,2 +1,2 @@ -dfpt_x: 2-atom Si (a=10.2612 Bohr), ONCV PBE, 20/80 Ry, 4x4x4, q=(0,0.5,0.5). +dfpt_si_x: 2-atom Si (a=10.2612 Bohr), ONCV PBE, 20/80 Ry, 4x4x4, q=(0,0.5,0.5). Cross-validated against QE 6.8: rms 0.17 cm^-1. DFPT is serial-only; single-rank. diff --git a/tests/01_PW/dfpt_x/STRU b/tests/01_PW/dfpt_si_x/STRU similarity index 100% rename from tests/01_PW/dfpt_x/STRU rename to tests/01_PW/dfpt_si_x/STRU diff --git a/tests/01_PW/dfpt_x/result.ref b/tests/01_PW/dfpt_si_x/result.ref similarity index 100% rename from tests/01_PW/dfpt_x/result.ref rename to tests/01_PW/dfpt_si_x/result.ref From 78a7496ebce3563d96089587d8cf6cf3c65f473d Mon Sep 17 00:00:00 2001 From: Zanthoxylum <105619360+Zanthoxylum@users.noreply.github.com> Date: Fri, 13 Nov 2026 22:28:47 +0800 Subject: [PATCH 07/16] test(dfpt): reduce to smoke test under 5s Maintainer feedback: 24 min is 288x over CI budget. Reduce to Gamma-only k, Gamma-only q, 8/32 Ry, nbands 4, no E-field. Runtime ~4.3s. --- tests/01_PW/dfpt_si_x/INPUT | 27 ++++++++++----------------- tests/01_PW/dfpt_si_x/KPT | 2 +- tests/01_PW/dfpt_si_x/QFILE | 2 +- tests/01_PW/dfpt_si_x/README | 3 +-- tests/01_PW/dfpt_si_x/result.ref | 18 +++++++++--------- 5 files changed, 22 insertions(+), 30 deletions(-) diff --git a/tests/01_PW/dfpt_si_x/INPUT b/tests/01_PW/dfpt_si_x/INPUT index ba5b032f805..3fc75199381 100644 --- a/tests/01_PW/dfpt_si_x/INPUT +++ b/tests/01_PW/dfpt_si_x/INPUT @@ -1,26 +1,19 @@ INPUT_PARAMETERS -#Parameters (1.General) suffix autotest calculation scf esolver_type dfpt - -nbands 8 +nbands 4 symmetry -1 pseudo_dir ../../PP_ORB - -#Parameters (2.Iteration) -ecutwfc 20 -ecutrho 80 -scf_thr 1e-10 -scf_nmax 100 - -#Parameters (3.Basis) +ecutwfc 8 +ecutrho 32 +scf_thr 1e-4 +smearing_method fixed +scf_nmax 50 basis_type pw - -#Parameters (4.DFPT) dfpt_qfile QFILE -dfpt_conv_thr 1e-8 -dfpt_max_iter 100 -dfpt_mix_beta 0.7 +dfpt_conv_thr 1e-3 +dfpt_max_iter 30 +dfpt_compute_q0 false dfpt_asr crystal -smearing_method fixed +dfpt_loto false diff --git a/tests/01_PW/dfpt_si_x/KPT b/tests/01_PW/dfpt_si_x/KPT index 253d74de39a..c289c0158aa 100644 --- a/tests/01_PW/dfpt_si_x/KPT +++ b/tests/01_PW/dfpt_si_x/KPT @@ -1,4 +1,4 @@ K_POINTS 0 Gamma -4 4 4 0 0 0 +1 1 1 0 0 0 diff --git a/tests/01_PW/dfpt_si_x/QFILE b/tests/01_PW/dfpt_si_x/QFILE index 4c1152c3022..3feb9215d88 100644 --- a/tests/01_PW/dfpt_si_x/QFILE +++ b/tests/01_PW/dfpt_si_x/QFILE @@ -1,4 +1,4 @@ Q_POINTS 1 Direct -0.0000000000 0.5000000000 0.5000000000 1.0 +0.0000000000 0.0000000000 0.0000000000 1.0 diff --git a/tests/01_PW/dfpt_si_x/README b/tests/01_PW/dfpt_si_x/README index e8809c96bdf..180960358e9 100644 --- a/tests/01_PW/dfpt_si_x/README +++ b/tests/01_PW/dfpt_si_x/README @@ -1,2 +1 @@ -dfpt_si_x: 2-atom Si (a=10.2612 Bohr), ONCV PBE, 20/80 Ry, 4x4x4, q=(0,0.5,0.5). -Cross-validated against QE 6.8: rms 0.17 cm^-1. DFPT is serial-only; single-rank. +dfpt_si_x: 2-atom Si (a=10.2612 Bohr), ONCV PBE, 8/32 Ry, Gamma-only k, Gamma-only q. Smoke test: verifies DFPT phonon frequency output (~4s). diff --git a/tests/01_PW/dfpt_si_x/result.ref b/tests/01_PW/dfpt_si_x/result.ref index 0a5eb3d5fb9..d6aabcf6cc1 100644 --- a/tests/01_PW/dfpt_si_x/result.ref +++ b/tests/01_PW/dfpt_si_x/result.ref @@ -1,9 +1,9 @@ -etotref -214.2345964396217 -etotperatomref -107.1172982198 -dfpt_freq_q0_m0 133.438117 -dfpt_freq_q0_m1 133.446776 -dfpt_freq_q0_m2 407.606736 -dfpt_freq_q0_m3 407.632912 -dfpt_freq_q0_m4 459.793094 -dfpt_freq_q0_m5 459.803320 -totaltimeref 1456.36 +etotref -196.0356347344235 +etotperatomref -98.0178173672 +dfpt_freq_q0_m0 -0.000005 +dfpt_freq_q0_m1 0.000003 +dfpt_freq_q0_m2 0.000006 +dfpt_freq_q0_m3 726.293102 +dfpt_freq_q0_m4 727.655079 +dfpt_freq_q0_m5 727.946529 +totaltimeref 4.31 From 3092b5278835d3f57ba8ee0ea2b007caeaebf0c4 Mon Sep 17 00:00:00 2001 From: Zanthoxylum <105619360+Zanthoxylum@users.noreply.github.com> Date: Fri, 13 Nov 2026 22:30:26 +0800 Subject: [PATCH 08/16] test(dfpt): rename dfpt_si_x to dfpt_si_g (Gamma-only q) --- tests/01_PW/CASES_CPU.txt | 2 +- tests/01_PW/{dfpt_si_x => dfpt_si_g}/INPUT | 0 tests/01_PW/{dfpt_si_x => dfpt_si_g}/KPT | 0 tests/01_PW/{dfpt_si_x => dfpt_si_g}/QFILE | 0 tests/01_PW/{dfpt_si_x => dfpt_si_g}/README | 2 +- tests/01_PW/{dfpt_si_x => dfpt_si_g}/STRU | 0 tests/01_PW/{dfpt_si_x => dfpt_si_g}/result.ref | 0 7 files changed, 2 insertions(+), 2 deletions(-) rename tests/01_PW/{dfpt_si_x => dfpt_si_g}/INPUT (100%) rename tests/01_PW/{dfpt_si_x => dfpt_si_g}/KPT (100%) rename tests/01_PW/{dfpt_si_x => dfpt_si_g}/QFILE (100%) rename tests/01_PW/{dfpt_si_x => dfpt_si_g}/README (55%) rename tests/01_PW/{dfpt_si_x => dfpt_si_g}/STRU (100%) rename tests/01_PW/{dfpt_si_x => dfpt_si_g}/result.ref (100%) diff --git a/tests/01_PW/CASES_CPU.txt b/tests/01_PW/CASES_CPU.txt index b330c7b959e..9a32f655017 100644 --- a/tests/01_PW/CASES_CPU.txt +++ b/tests/01_PW/CASES_CPU.txt @@ -136,4 +136,4 @@ scf_sccs_full relax_sccs scf_sccs_sa scf_sccs_sa_pcc_2d_lowpass -dfpt_si_x +dfpt_si_g diff --git a/tests/01_PW/dfpt_si_x/INPUT b/tests/01_PW/dfpt_si_g/INPUT similarity index 100% rename from tests/01_PW/dfpt_si_x/INPUT rename to tests/01_PW/dfpt_si_g/INPUT diff --git a/tests/01_PW/dfpt_si_x/KPT b/tests/01_PW/dfpt_si_g/KPT similarity index 100% rename from tests/01_PW/dfpt_si_x/KPT rename to tests/01_PW/dfpt_si_g/KPT diff --git a/tests/01_PW/dfpt_si_x/QFILE b/tests/01_PW/dfpt_si_g/QFILE similarity index 100% rename from tests/01_PW/dfpt_si_x/QFILE rename to tests/01_PW/dfpt_si_g/QFILE diff --git a/tests/01_PW/dfpt_si_x/README b/tests/01_PW/dfpt_si_g/README similarity index 55% rename from tests/01_PW/dfpt_si_x/README rename to tests/01_PW/dfpt_si_g/README index 180960358e9..6c79de04f12 100644 --- a/tests/01_PW/dfpt_si_x/README +++ b/tests/01_PW/dfpt_si_g/README @@ -1 +1 @@ -dfpt_si_x: 2-atom Si (a=10.2612 Bohr), ONCV PBE, 8/32 Ry, Gamma-only k, Gamma-only q. Smoke test: verifies DFPT phonon frequency output (~4s). +dfpt_si_g: 2-atom Si (a=10.2612 Bohr), ONCV PBE, 8/32 Ry, Gamma-only k, Gamma-only q. Smoke test: verifies DFPT phonon frequency output (~4s). diff --git a/tests/01_PW/dfpt_si_x/STRU b/tests/01_PW/dfpt_si_g/STRU similarity index 100% rename from tests/01_PW/dfpt_si_x/STRU rename to tests/01_PW/dfpt_si_g/STRU diff --git a/tests/01_PW/dfpt_si_x/result.ref b/tests/01_PW/dfpt_si_g/result.ref similarity index 100% rename from tests/01_PW/dfpt_si_x/result.ref rename to tests/01_PW/dfpt_si_g/result.ref From 752638aa5c549ac41f6ff6812ba8fe73bcd78957 Mon Sep 17 00:00:00 2001 From: Zanthoxylum <105619360+Zanthoxylum@users.noreply.github.com> Date: Fri, 13 Nov 2026 22:45:36 +0800 Subject: [PATCH 09/16] fix(dfpt): bracket delimiters in nonnumeric-token diagnostic --- tests/integrate/validation_tools/props_dfpt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integrate/validation_tools/props_dfpt.sh b/tests/integrate/validation_tools/props_dfpt.sh index 367990151e6..75ed49bda01 100644 --- a/tests/integrate/validation_tools/props_dfpt.sh +++ b/tests/integrate/validation_tools/props_dfpt.sh @@ -54,7 +54,7 @@ run_dfpt_props() { val = $4 # reject empty or nonnumeric frequency tokens (format drift) if (val !~ /^-?[0-9]+\.?[0-9]*([eE][-+]?[0-9]+)?$/) { - fail("nonnumeric frequency token '" val "' in " seq " mode " mi) + fail("nonnumeric frequency token [" val "] in " seq " mode " mi) } printf "dfpt_%s_q%s_m%s %s\n", block, block_qi, mi, val next From 70a07fe91337ff7e55a9b4ecb4b31a5f72ac4428 Mon Sep 17 00:00:00 2001 From: Zanthoxylum <105619360+Zanthoxylum@users.noreply.github.com> Date: Fri, 13 Nov 2026 22:53:32 +0800 Subject: [PATCH 10/16] fix(dfpt): validate 3*natom mode count from STRU; five-scenario regression --- .../integrate/validation_tools/props_dfpt.sh | 53 +++++++++++++++---- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/tests/integrate/validation_tools/props_dfpt.sh b/tests/integrate/validation_tools/props_dfpt.sh index 75ed49bda01..6f95f79b85d 100644 --- a/tests/integrate/validation_tools/props_dfpt.sh +++ b/tests/integrate/validation_tools/props_dfpt.sh @@ -14,11 +14,12 @@ # dfpt_loto_q_m LO-TO corrected frequency (Gamma only) # # Completeness guard: the collection fails (returns 1) when the log is -# missing, contains no analytic frequency block at all, or any block's -# mode set does not form a dense 0..N sequence starting at 0 (a truncated -# tail or a dropped interior mode row). Autotest.sh and run_check.sh only -# compare keys present in result.out, so a partial spectrum would -# otherwise pass on the surviving subset. +# missing, contains no analytic frequency block, any block's mode set +# does not form a dense 0..N sequence starting at 0, or any freq block +# has a different total mode count than the first complete block (every +# q point has exactly 3*natom modes — a truncated tail at EOF that is +# internally dense would otherwise become an incomplete reference on +# first-time generation, where no old result.ref exists to cross-check). run_dfpt_props() { if [ -z "$esolver_type" ] || [ "$esolver_type" != "dfpt" ]; then @@ -29,20 +30,44 @@ run_dfpt_props() { echo "ERROR: run_dfpt_props: $dfpt_log not found, DFPT frequencies not collected" >&2 return 1 fi + # count atoms from STRU to derive the expected 3*natom mode count; + # this catches a single-block truncation that the cross-block consistency + # check cannot detect (1-atom complete vs 2-atom truncated look identical) + local natom=0 + if [ -f "STRU" ]; then + natom=$(awk '/^ *Direct|^ *Cartesian/{found=1;next} found && /^[A-Z][a-z]/{getline; getline; natom+=$1} END{print natom}' STRU 2>/dev/null) + fi + local expected_total=$((natom * 3)) # emit one "key value" line per frequency; awk rewrites the block header # into the key prefix and drops everything else. The mode index keeps its # zero-based printing so keys stay stable across cell sizes. Per-block - # mode indices are checked for density (0..N with no gaps). - if ! awk ' + # mode indices are checked for density (0..N with no gaps); every freq + # block must have exactly expected_total modes (3*natom from STRU). + if ! awk -v expected_total="$expected_total" ' function fail(msg) { printf "ERROR: run_dfpt_props: %s\n", msg > "/dev/stderr"; bad = 1; exit 1 } + function close_block() { + if (seq != "" && nextmode[seq] > 0) { + if (expected_total > 0 && block_type[seq] == "freq" && nextmode[seq] != expected_total) { + fail("freq block " seq " has " nextmode[seq] " modes; expected " expected_total " (3*natom from STRU): truncated at EOF or mid-block") + } else if (expected_modes == 0) { + expected_modes = nextmode[seq] + if (expected_modes % 3 != 0) { + fail("first freq block has " expected_modes " modes; not a multiple of 3 (expected 3*natom)") + } + } else if (block_type[seq] == "freq" && nextmode[seq] != expected_modes) { + fail("freq block " seq " has " nextmode[seq] " modes; expected " expected_modes " (truncated at EOF or mid-block)") + } + } + } /^ *DFPT phonon frequencies at q #/ { - if (block != "" && nextmode[seq] == 0) fail(seq " has no mode rows") + close_block() match($0, /q #[0-9]+/); qi = substr($0, RSTART + 3, RLENGTH - 3); - block = "freq"; block_qi = qi; seq = "freq:" qi; nextmode[seq] = 0; next + block = "freq"; block_qi = qi; seq = "freq:" qi; nextmode[seq] = 0; block_type[seq] = "freq"; next } /^ *DFPT LO-TO corrected frequencies at q #/ { + close_block() match($0, /q #[0-9]+/); qi = substr($0, RSTART + 3, RLENGTH - 3); - block = "loto"; block_qi = qi; seq = "loto:" qi; next + block = "loto"; block_qi = qi; seq = "loto:" qi; nextmode[seq] = 0; block_type[seq] = "loto"; next } /^ *mode +[0-9]+ :/ { if (block == "") next @@ -60,7 +85,13 @@ run_dfpt_props() { next } { if ($0 !~ /^ *mode/ && block != "" && $0 ~ /[^ ]/) block = "" } - END { if (!bad && maxmode[""] == "" && block == "" && NR == 0) fail("empty log") } + END { + if (!bad) { + close_block() + if (NR == 0) fail("empty log") + if (expected_modes == 0) fail("no complete frequency block found") + } + } ' "$dfpt_log" >> "$props_result_file"; then echo "ERROR: run_dfpt_props: incomplete phonon frequency spectrum in $dfpt_log (truncated output or format drift); failing the collection" >&2 return 1 From c33ee19b2cd670b531eca0c2ba0ec4e9aff64ce1 Mon Sep 17 00:00:00 2001 From: Zanthoxylum <105619360+Zanthoxylum@users.noreply.github.com> Date: Fri, 13 Nov 2026 23:11:58 +0800 Subject: [PATCH 11/16] ci: re-run abacuslite (flaky MPI failure, unrelated to this PR) From e830a1107ca7eea49628e2a95c37a44407f7244b Mon Sep 17 00:00:00 2001 From: Zanthoxylum <105619360+Zanthoxylum@users.noreply.github.com> Date: Sat, 14 Nov 2026 10:52:32 +0800 Subject: [PATCH 12/16] fix(dfpt): multi-species STRU counting, mode-0 enforcement, empty-block guard --- .../integrate/validation_tools/props_dfpt.sh | 68 +++++++++++-------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/tests/integrate/validation_tools/props_dfpt.sh b/tests/integrate/validation_tools/props_dfpt.sh index 6f95f79b85d..ef3113ddab2 100644 --- a/tests/integrate/validation_tools/props_dfpt.sh +++ b/tests/integrate/validation_tools/props_dfpt.sh @@ -15,11 +15,10 @@ # # Completeness guard: the collection fails (returns 1) when the log is # missing, contains no analytic frequency block, any block's mode set -# does not form a dense 0..N sequence starting at 0, or any freq block -# has a different total mode count than the first complete block (every -# q point has exactly 3*natom modes — a truncated tail at EOF that is -# internally dense would otherwise become an incomplete reference on -# first-time generation, where no old result.ref exists to cross-check). +# does not start at mode 0 and form a dense 0..N sequence, any freq +# block's total does not equal 3*natom (read from STRU), or a freq +# block header is followed by no mode rows at all. These checks apply +# on first-time reference generation as well as comparison runs. run_dfpt_props() { if [ -z "$esolver_type" ] || [ "$esolver_type" != "dfpt" ]; then @@ -30,33 +29,44 @@ run_dfpt_props() { echo "ERROR: run_dfpt_props: $dfpt_log not found, DFPT frequencies not collected" >&2 return 1 fi - # count atoms from STRU to derive the expected 3*natom mode count; - # this catches a single-block truncation that the cross-block consistency - # check cannot detect (1-atom complete vs 2-atom truncated look identical) + # count atoms from STRU: walk each species block in ATOMIC_POSITIONS + # (element name → magnetic moment → atom count → coordinate lines) and + # sum the counts; handles multi-species cells and single-letter elements local natom=0 if [ -f "STRU" ]; then - natom=$(awk '/^ *Direct|^ *Cartesian/{found=1;next} found && /^[A-Z][a-z]/{getline; getline; natom+=$1} END{print natom}' STRU 2>/dev/null) + natom=$(awk ' + /ATOMIC_POSITIONS/{found=1; next} + !found{next} + /^[ \t]*$/{next} + found && /^(Direct|Cartesian|direct|cartesian)/{next} + found && /^[A-Za-z][A-Za-z0-9]*[ \t]*$/{ + getline + getline + natom += $1 + 0 + for(i=0; i<($1+0); i++) getline + } + END{print natom+0} + ' STRU 2>/dev/null) fi local expected_total=$((natom * 3)) # emit one "key value" line per frequency; awk rewrites the block header - # into the key prefix and drops everything else. The mode index keeps its - # zero-based printing so keys stay stable across cell sizes. Per-block - # mode indices are checked for density (0..N with no gaps); every freq - # block must have exactly expected_total modes (3*natom from STRU). + # into the key prefix and drops everything else. Mode 0 must open every + # block; indices are checked for dense 0..N; every freq block must end + # at exactly expected_total (3*natom from STRU); empty freq blocks fail. if ! awk -v expected_total="$expected_total" ' function fail(msg) { printf "ERROR: run_dfpt_props: %s\n", msg > "/dev/stderr"; bad = 1; exit 1 } function close_block() { - if (seq != "" && nextmode[seq] > 0) { - if (expected_total > 0 && block_type[seq] == "freq" && nextmode[seq] != expected_total) { - fail("freq block " seq " has " nextmode[seq] " modes; expected " expected_total " (3*natom from STRU): truncated at EOF or mid-block") - } else if (expected_modes == 0) { - expected_modes = nextmode[seq] - if (expected_modes % 3 != 0) { - fail("first freq block has " expected_modes " modes; not a multiple of 3 (expected 3*natom)") - } - } else if (block_type[seq] == "freq" && nextmode[seq] != expected_modes) { - fail("freq block " seq " has " nextmode[seq] " modes; expected " expected_modes " (truncated at EOF or mid-block)") + if (block_type[seq] == "freq") { + if (nextmode[seq] == 0) { + fail("freq block " seq " has no mode rows") + } + if (expected_total > 0 && nextmode[seq] != expected_total) { + fail("freq block " seq " has " nextmode[seq] " modes; expected " expected_total " (3*natom from STRU)") + } + if (expected_total == 0 && expected_modes > 0 && nextmode[seq] != expected_modes) { + fail("freq block " seq " has " nextmode[seq] " modes; expected " expected_modes " (from first block)") } + if (expected_modes == 0) expected_modes = nextmode[seq] } } /^ *DFPT phonon frequencies at q #/ { @@ -72,8 +82,8 @@ run_dfpt_props() { /^ *mode +[0-9]+ :/ { if (block == "") next mi = $2 - if (mi != nextmode[seq] && nextmode[seq] > 0) { - fail("mode " mi " out of sequence in " seq " (expected " nextmode[seq] "): truncated or dropped rows") + if (mi != nextmode[seq]) { + fail("mode " mi " out of sequence in " seq " (expected " nextmode[seq] "): missing or dropped rows") } nextmode[seq] = mi + 1 val = $4 @@ -96,15 +106,13 @@ run_dfpt_props() { echo "ERROR: run_dfpt_props: incomplete phonon frequency spectrum in $dfpt_log (truncated output or format drift); failing the collection" >&2 return 1 fi - # zero-key guard: a DFPT log with no analytic block at all + # zero-key guard if ! grep -q "^dfpt_freq_" "$props_result_file"; then echo "ERROR: run_dfpt_props: no complete phonon frequency block found in $dfpt_log (truncated output or format drift); failing the collection" >&2 return 1 fi - # cross-reference guard: when generating result.out against an existing - # result.ref (comparison mode), every dfpt_* key in the reference must - # appear in the collected output — a log truncated mid-block would - # otherwise pass on its surviving prefix + # cross-reference guard (comparison mode only; first-time generation + # relies on the STRU-derived 3*natom check above) local ref_file="result.ref" if [ -f "$ref_file" ] && grep -q "^dfpt_freq_" "$ref_file"; then local missing From 34bb3982b13027f86acee6d221ccc09f9e7c629c Mon Sep 17 00:00:00 2001 From: Zanthoxylum <105619360+Zanthoxylum@users.noreply.github.com> Date: Sat, 14 Nov 2026 11:02:33 +0800 Subject: [PATCH 13/16] fix(dfpt): validate LO-TO blocks and guard empty seq; 8-scenario regression --- .../integrate/validation_tools/props_dfpt.sh | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/integrate/validation_tools/props_dfpt.sh b/tests/integrate/validation_tools/props_dfpt.sh index ef3113ddab2..adb910fe85e 100644 --- a/tests/integrate/validation_tools/props_dfpt.sh +++ b/tests/integrate/validation_tools/props_dfpt.sh @@ -56,18 +56,17 @@ run_dfpt_props() { if ! awk -v expected_total="$expected_total" ' function fail(msg) { printf "ERROR: run_dfpt_props: %s\n", msg > "/dev/stderr"; bad = 1; exit 1 } function close_block() { - if (block_type[seq] == "freq") { - if (nextmode[seq] == 0) { - fail("freq block " seq " has no mode rows") - } - if (expected_total > 0 && nextmode[seq] != expected_total) { - fail("freq block " seq " has " nextmode[seq] " modes; expected " expected_total " (3*natom from STRU)") - } - if (expected_total == 0 && expected_modes > 0 && nextmode[seq] != expected_modes) { - fail("freq block " seq " has " nextmode[seq] " modes; expected " expected_modes " (from first block)") - } - if (expected_modes == 0) expected_modes = nextmode[seq] + if (seq == "") return # no previous block to close + if (nextmode[seq] == 0) { + fail(block_type[seq] " block " seq " has no mode rows") } + if (expected_total > 0 && nextmode[seq] != expected_total) { + fail(block_type[seq] " block " seq " has " nextmode[seq] " modes; expected " expected_total " (3*natom from STRU)") + } + if (expected_total == 0 && expected_modes > 0 && nextmode[seq] != expected_modes) { + fail(block_type[seq] " block " seq " has " nextmode[seq] " modes; expected " expected_modes " (from first block)") + } + if (expected_modes == 0) expected_modes = nextmode[seq] } /^ *DFPT phonon frequencies at q #/ { close_block() From c716a77557cd8e361c8e867f95dbd2dbb4e97aae Mon Sep 17 00:00:00 2001 From: Zanthoxylum <105619360+Zanthoxylum@users.noreply.github.com> Date: Sat, 14 Nov 2026 18:28:34 +0800 Subject: [PATCH 14/16] fix(dfpt): isolate STRU count from getline, handle comments --- tests/integrate/validation_tools/props_dfpt.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/integrate/validation_tools/props_dfpt.sh b/tests/integrate/validation_tools/props_dfpt.sh index adb910fe85e..39774c45878 100644 --- a/tests/integrate/validation_tools/props_dfpt.sh +++ b/tests/integrate/validation_tools/props_dfpt.sh @@ -39,11 +39,12 @@ run_dfpt_props() { !found{next} /^[ \t]*$/{next} found && /^(Direct|Cartesian|direct|cartesian)/{next} - found && /^[A-Za-z][A-Za-z0-9]*[ \t]*$/{ + found && /^[A-Za-z][A-Za-z0-9]*([ \t].*)?$/{ getline getline - natom += $1 + 0 - for(i=0; i<($1+0); i++) getline + cnt = $1 + 0 + natom += cnt + for(i=0; i/dev/null) From 069ef527f63b4f8e6a3f44b0e2bbfc11fce642b8 Mon Sep 17 00:00:00 2001 From: Zanthoxylum <105619360+Zanthoxylum@users.noreply.github.com> Date: Sat, 14 Nov 2026 18:40:47 +0800 Subject: [PATCH 15/16] test(dfpt): synthetic collector guard tests (11 scenarios) --- tests/integrate/CMakeLists.txt | 5 + .../validation_tools/test_props_dfpt.py | 150 ++++++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 tests/integrate/validation_tools/test_props_dfpt.py diff --git a/tests/integrate/CMakeLists.txt b/tests/integrate/CMakeLists.txt index c07cf70b4fa..b3670710fda 100644 --- a/tests/integrate/CMakeLists.txt +++ b/tests/integrate/CMakeLists.txt @@ -32,4 +32,9 @@ if(LR_FORCE_TEST_PYTHON) COMMAND ${LR_FORCE_TEST_PYTHON} -m unittest discover -s ${CMAKE_CURRENT_SOURCE_DIR}/validation_tools -p test_props_basic.py) set_tests_properties(md_force_collector PROPERTIES TIMEOUT 30) + add_test( + NAME dfpt_freq_collector + COMMAND ${LR_FORCE_TEST_PYTHON} -m unittest discover -s + ${CMAKE_CURRENT_SOURCE_DIR}/validation_tools -p test_props_dfpt.py) + set_tests_properties(dfpt_freq_collector PROPERTIES TIMEOUT 30) endif() diff --git a/tests/integrate/validation_tools/test_props_dfpt.py b/tests/integrate/validation_tools/test_props_dfpt.py new file mode 100644 index 00000000000..80f937f2c8b --- /dev/null +++ b/tests/integrate/validation_tools/test_props_dfpt.py @@ -0,0 +1,150 @@ +"""Regression checks for DFPT phonon frequency collection.""" + +import os +from pathlib import Path +import shlex +import subprocess +import tempfile +import unittest + + +TOOLS = Path(__file__).resolve().parent + +# minimal STRU for 2-atom Si (the props_dfpt collector reads it for natom) +STRU_2SI = """ATOMIC_SPECIES +Si 28.0855 Si.upf + +LATTICE_CONSTANT +1.8897261255 + +LATTICE_VECTORS +0.00000000 2.71500000 2.71500000 +2.71500000 0.00000000 2.71500000 +2.71500000 2.71500000 0.00000000 + +ATOMIC_POSITIONS +Direct + +Si +0.0 +2 +0.00000000 0.00000000 0.00000000 1 1 1 +0.25000000 0.25000000 0.25000000 1 1 1 +""" + +GOOD_FREQ_BLOCK = ( + " DFPT phonon frequencies at q #0 = (0.000000 0.000000 0.000000) (direct) in cm^-1:\n" + " mode 0 : -0.000001 cm^-1\n" + " mode 1 : 0.000002 cm^-1\n" + " mode 2 : 0.000003 cm^-1\n" + " mode 3 : 100.000000 cm^-1\n" + " mode 4 : 101.000000 cm^-1\n" + " mode 5 : 102.000000 cm^-1\n" +) + + +class DFPTFrequencyCollectorTest(unittest.TestCase): + def run_collector(self, log_text, stru_text=STRU_2SI): + with tempfile.TemporaryDirectory(prefix="abacus-dfpt-collector-") as scratch: + case = Path(scratch) + (case / "log.txt").write_text(log_text, encoding="utf-8") + if stru_text is not None: + (case / "STRU").write_text(stru_text, encoding="utf-8") + command = ( + 'source "$1"; esolver_type=dfpt; ' + 'props_result_file=result.out; ' + '> $props_result_file; run_dfpt_props log.txt' + ) + result = subprocess.run( + ["bash", "-c", command, "dfpt-collector-test", + str(TOOLS / "props_dfpt.sh")], + cwd=case, capture_output=True, text=True, check=False, + ) + output = (case / "result.out").read_text(encoding="utf-8") if (case / "result.out").exists() else "" + return result, output + + # --- successful scenarios --- + + def test_complete_block_passes(self): + result, output = self.run_collector(GOOD_FREQ_BLOCK) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(len(output.strip().splitlines()), 6) + self.assertIn("dfpt_freq_q0_m3 100.000000", output) + self.assertIn("dfpt_freq_q0_m5 102.000000", output) + + def test_freq_and_loto_blocks_pass(self): + loto = GOOD_FREQ_BLOCK.replace( + "phonon frequencies", "LO-TO corrected frequencies") + result, output = self.run_collector(GOOD_FREQ_BLOCK + loto) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(len(output.strip().splitlines()), 12) + self.assertIn("dfpt_loto_q0_m0 -0.000001", output) + + # --- missing mode 0 --- + + def test_missing_mode_zero_fails(self): + log = GOOD_FREQ_BLOCK.replace(" mode 0 :", " mode 99 :", 1) + result, output = self.run_collector(log) + self.assertNotEqual(result.returncode, 0) + + def test_block_starting_at_mode_one_fails(self): + lines = GOOD_FREQ_BLOCK.strip().splitlines() + lines = [ln for ln in lines if "mode 0" not in ln] + log = "\n".join(lines) + "\n" + result, output = self.run_collector(log) + self.assertNotEqual(result.returncode, 0) + + # --- empty blocks --- + + def test_empty_freq_block_fails(self): + # freq header with no mode rows followed by another block + log = (" DFPT phonon frequencies at q #0 = test\n" + + GOOD_FREQ_BLOCK) + result, output = self.run_collector(log) + self.assertNotEqual(result.returncode, 0) + + def test_empty_loto_block_fails(self): + loto_header = (" DFPT LO-TO corrected frequencies at q #0 = test\n") + result, output = self.run_collector(GOOD_FREQ_BLOCK + loto_header) + self.assertNotEqual(result.returncode, 0) + + # --- truncated blocks --- + + def test_truncated_freq_block_fails(self): + # only 3 of 6 modes (STRU says 2 atoms → 6 modes) + lines = GOOD_FREQ_BLOCK.strip().splitlines() + log = "\n".join(lines[:4]) + "\n" # header + modes 0,1,2 + result, output = self.run_collector(log) + self.assertNotEqual(result.returncode, 0) + + def test_truncated_loto_block_fails(self): + loto = GOOD_FREQ_BLOCK.replace( + "phonon frequencies", "LO-TO corrected frequencies") + lines = loto.strip().splitlines() + loto_short = "\n".join(lines[:4]) + "\n" # header + modes 0,1,2 + result, output = self.run_collector(GOOD_FREQ_BLOCK + loto_short) + self.assertNotEqual(result.returncode, 0) + + # --- nonnumeric token --- + + def test_nonnumeric_token_fails(self): + log = GOOD_FREQ_BLOCK.replace("100.000000", "abc") + result, output = self.run_collector(log) + self.assertNotEqual(result.returncode, 0) + + # --- empty log --- + + def test_empty_log_fails(self): + result, output = self.run_collector("") + self.assertNotEqual(result.returncode, 0) + + # --- no STRU → expected_total=0 → falls back to first-block count --- + + def test_no_stru_uses_first_block_count(self): + result, output = self.run_collector(GOOD_FREQ_BLOCK, stru_text=None) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(len(output.strip().splitlines()), 6) + + +if __name__ == "__main__": + unittest.main() From 240ead3120b78e1be34a8e8efb6e7db2accb205e Mon Sep 17 00:00:00 2001 From: Zanthoxylum <105619360+Zanthoxylum@users.noreply.github.com> Date: Mon, 16 Nov 2026 17:41:28 +0800 Subject: [PATCH 16/16] fix(dfpt): STRU whitespace, unreadable rejection, 15 tests --- .../integrate/validation_tools/props_dfpt.sh | 27 ++++++-- .../validation_tools/test_props_dfpt.py | 64 +++++++++++++++++++ 2 files changed, 86 insertions(+), 5 deletions(-) diff --git a/tests/integrate/validation_tools/props_dfpt.sh b/tests/integrate/validation_tools/props_dfpt.sh index 39774c45878..5c03fcb8e34 100644 --- a/tests/integrate/validation_tools/props_dfpt.sh +++ b/tests/integrate/validation_tools/props_dfpt.sh @@ -33,21 +33,38 @@ run_dfpt_props() { # (element name → magnetic moment → atom count → coordinate lines) and # sum the counts; handles multi-species cells and single-letter elements local natom=0 + local stru_present=0 if [ -f "STRU" ]; then + stru_present=1 natom=$(awk ' + function is_blank(s){ return s ~ /^[ ]*$/ } + function skip_blanks(){ while((getline line > 0) && is_blank(line)); return line } /ATOMIC_POSITIONS/{found=1; next} !found{next} - /^[ \t]*$/{next} + is_blank($0){next} found && /^(Direct|Cartesian|direct|cartesian)/{next} - found && /^[A-Za-z][A-Za-z0-9]*([ \t].*)?$/{ - getline - getline - cnt = $1 + 0 + found && /^[ ]*[A-Za-z][A-Za-z0-9]*([ ].*)?$/{ + # skip blank lines before the magnetic moment line + line = skip_blanks() + if (line == "" || is_blank(line)) next + # skip blank lines before the atom count line + line = skip_blanks() + if (line == "" || is_blank(line)) next + split(line, fields) + cnt = fields[1] + 0 + if (cnt <= 0) next natom += cnt for(i=0; i/dev/null) + # STRU exists but atom count is unreadable: reject rather than + # silently skipping the mode-count validation (an incomplete + # spectrum could become the first reference) + if [ "$natom" -le 0 ] 2>/dev/null; then + echo "ERROR: run_dfpt_props: STRU exists but atom count is unreadable (natom=$natom); cannot derive 3*natom for mode validation" >&2 + return 1 + fi fi local expected_total=$((natom * 3)) # emit one "key value" line per frequency; awk rewrites the block header diff --git a/tests/integrate/validation_tools/test_props_dfpt.py b/tests/integrate/validation_tools/test_props_dfpt.py index 80f937f2c8b..b102f0097fe 100644 --- a/tests/integrate/validation_tools/test_props_dfpt.py +++ b/tests/integrate/validation_tools/test_props_dfpt.py @@ -32,6 +32,43 @@ 0.25000000 0.25000000 0.25000000 1 1 1 """ + +STRU_COMMENTED_MIXED = """ATOMIC_POSITIONS +Cartesian_angstrom + +Si # silicon +0.0 +1 +2.715 0.0 0.0 1 1 1 + +Ge # germanium +0.0 +1 +2.715 2.715 0.0 1 1 1 +""" + +STRU_INDENTED = """ATOMIC_POSITIONS +Direct + + Si + 0.0 + 2 + 0.0 0.0 0.0 1 1 1 + 0.25 0.25 0.25 1 1 1 +""" + +STRU_BLANK_LINES = """ATOMIC_POSITIONS +Direct + +Si + +0.0 + +2 +0.0 0.0 0.0 1 1 1 +0.25 0.25 0.25 1 1 1 +""" + GOOD_FREQ_BLOCK = ( " DFPT phonon frequencies at q #0 = (0.000000 0.000000 0.000000) (direct) in cm^-1:\n" " mode 0 : -0.000001 cm^-1\n" @@ -146,5 +183,32 @@ def test_no_stru_uses_first_block_count(self): self.assertEqual(len(output.strip().splitlines()), 6) + # --- STRU parser edge cases --- + + def test_commented_mixed_species_stru_passes(self): + """Si/Ge with comments, Cartesian, first coordinate 2.715 (x > atom count).""" + result, output = self.run_collector(GOOD_FREQ_BLOCK, stru_text=STRU_COMMENTED_MIXED) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(len(output.strip().splitlines()), 6) + + def test_indented_element_label_stru_passes(self): + """Indented element names (leading whitespace) are valid STRU.""" + result, output = self.run_collector(GOOD_FREQ_BLOCK, stru_text=STRU_INDENTED) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(len(output.strip().splitlines()), 6) + + def test_blank_lines_in_species_block_stru_passes(self): + """Blank lines within a species block (before mag/count) are valid STRU.""" + result, output = self.run_collector(GOOD_FREQ_BLOCK, stru_text=STRU_BLANK_LINES) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(len(output.strip().splitlines()), 6) + + def test_unreadable_stru_fails(self): + """STRU exists but atom count cannot be parsed → reject.""" + bad_stru = "ATOMIC_POSITIONS\nDirect\n\nGarbageData\n" + result, output = self.run_collector(GOOD_FREQ_BLOCK, stru_text=bad_stru) + self.assertNotEqual(result.returncode, 0) + + if __name__ == "__main__": unittest.main()