Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
cec7ff2
test(dfpt): integrate test 110_PW_DFPT_Si_X with frequency parsing
Zanthoxylum Nov 10, 2026
7e4a3d3
Merge branch 'deepmodeling:develop' into test-dfpt-integration
Zanthoxylum Nov 11, 2026
5655745
test(dfpt): register 110 with the suite, fail on missing spectrum, fi…
Zanthoxylum Nov 12, 2026
fdc78aa
test(dfpt): run the 110 case single-rank: the DFPT esolver is current…
Zanthoxylum Nov 12, 2026
f4fd288
test(dfpt): review follow-up — per-key threshold, complete spectrum, …
Zanthoxylum Nov 12, 2026
a44b3de
test(dfpt): rename to dfpt_x, shorten README, case-insensitive key lo…
Zanthoxylum Nov 13, 2026
cc9dcfb
Merge branch 'develop' into test-dfpt-integration
Zanthoxylum Nov 13, 2026
39ba0c1
test(dfpt): rename dfpt_x to dfpt_si_x
Zanthoxylum Nov 13, 2026
78a7496
test(dfpt): reduce to smoke test under 5s
Zanthoxylum Nov 13, 2026
3092b52
test(dfpt): rename dfpt_si_x to dfpt_si_g (Gamma-only q)
Zanthoxylum Nov 13, 2026
752638a
fix(dfpt): bracket delimiters in nonnumeric-token diagnostic
Zanthoxylum Nov 13, 2026
608dbdb
Merge branch 'develop' into test-dfpt-integration
Zanthoxylum Nov 13, 2026
70a07fe
fix(dfpt): validate 3*natom mode count from STRU; five-scenario regre…
Zanthoxylum Nov 13, 2026
c33ee19
ci: re-run abacuslite (flaky MPI failure, unrelated to this PR)
Zanthoxylum Nov 13, 2026
e830a11
fix(dfpt): multi-species STRU counting, mode-0 enforcement, empty-blo…
Zanthoxylum Nov 14, 2026
34bb398
fix(dfpt): validate LO-TO blocks and guard empty seq; 8-scenario regr…
Zanthoxylum Nov 14, 2026
c716a77
fix(dfpt): isolate STRU count from getline, handle comments
Zanthoxylum Nov 14, 2026
069ef52
test(dfpt): synthetic collector guard tests (11 scenarios)
Zanthoxylum Nov 14, 2026
240ead3
fix(dfpt): STRU whitespace, unreadable rejection, 15 tests
Zanthoxylum Nov 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/01_PW/CASES_CPU.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,4 @@ scf_sccs_full
relax_sccs
scf_sccs_sa
scf_sccs_sa_pcc_2d_lowpass
dfpt_si_g
19 changes: 19 additions & 0 deletions tests/01_PW/dfpt_si_g/INPUT
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
INPUT_PARAMETERS
suffix autotest
calculation scf
esolver_type dfpt
nbands 4
symmetry -1
pseudo_dir ../../PP_ORB
ecutwfc 8
ecutrho 32
scf_thr 1e-4
smearing_method fixed
scf_nmax 50
basis_type pw
dfpt_qfile QFILE
dfpt_conv_thr 1e-3
dfpt_max_iter 30
dfpt_compute_q0 false
dfpt_asr crystal
dfpt_loto false
4 changes: 4 additions & 0 deletions tests/01_PW/dfpt_si_g/KPT
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
K_POINTS
0
Gamma
1 1 1 0 0 0
4 changes: 4 additions & 0 deletions tests/01_PW/dfpt_si_g/QFILE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Q_POINTS
1
Direct
0.0000000000 0.0000000000 0.0000000000 1.0
1 change: 1 addition & 0 deletions tests/01_PW/dfpt_si_g/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
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).
19 changes: 19 additions & 0 deletions tests/01_PW/dfpt_si_g/STRU
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions tests/01_PW/dfpt_si_g/result.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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
13 changes: 13 additions & 0 deletions tests/integrate/Autotest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -354,6 +360,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 -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
# (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
Comment thread
Zanthoxylum marked this conversation as resolved.
Resolved
else
"$mpi_launcher" "$mpi_np_flag" $np "${mpi_preflags[@]}" "$abacus" "${mpi_postflags[@]}" >log.txt
fi
Expand Down
5 changes: 5 additions & 0 deletions tests/integrate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
8 changes: 8 additions & 0 deletions tests/integrate/validation_tools/catch_properties.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,6 +29,13 @@ 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;
# a DFPT case with no complete frequency block fails the collection
# instead of passing on etot alone
#---------------------------------------
run_dfpt_props || exit 1

#-------------------------------
# matrix collectors: out_dm1 (props_mat.sh)
#-------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tests/integrate/validation_tools/props_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
143 changes: 143 additions & 0 deletions tests/integrate/validation_tools/props_dfpt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#!/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 #<i>" block per q
# point and, at Gamma, a "DFPT LO-TO corrected frequencies" block along
# the q->0 direction. Each block lists "<mode j> : <freq> 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<i>_m<j> plain (analytic) frequency of q point i, mode j
# dfpt_loto_q<i>_m<j> LO-TO corrected frequency (Gamma only)
#
# Completeness guard: the collection fails (returns 1) when the log is
# missing, contains no analytic frequency block, any block's mode set
# 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
return
fi
local dfpt_log="${1:-log.txt}"
if [ ! -f "$dfpt_log" ]; then
echo "ERROR: run_dfpt_props: $dfpt_log not found, DFPT frequencies not collected" >&2
return 1
fi
# 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
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}
is_blank($0){next}
found && /^(Direct|Cartesian|direct|cartesian)/{next}
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<cnt; i++) getline
}
END{print natom+0}
' STRU 2>/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
# 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 == "") 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()
match($0, /q #[0-9]+/); qi = substr($0, RSTART + 3, RLENGTH - 3);
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; nextmode[seq] = 0; block_type[seq] = "loto"; next
}
/^ *mode +[0-9]+ :/ {
if (block == "") next
mi = $2
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
Comment thread
Zanthoxylum marked this conversation as resolved.
Resolved
# 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
}
{ if ($0 !~ /^ *mode/ && block != "" && $0 ~ /[^ ]/) block = "" }
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
fi
# 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 (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
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
}
Expand Down
Loading
Loading