Skip to content

[Fix] Skip DSP kpar/bndpar layout check for esolver_type=dp/nep - #8313

Merged
mohanchen merged 4 commits into
developfrom
ZhouXY-DSP
Nov 13, 2026
Merged

mohanchen merged 4 commits into
developfrom
ZhouXY-DSP

Conversation

@ZhouXY-PKU

Copy link
Copy Markdown
Collaborator

Reminder

[x] I have read AGENTS.md and docs/developers_guide/agent_governance.md.
[x] I have linked an issue or explained why this PR does not need one.
[x] I have added adequate unit tests and/or case tests (explained below).
[x] I have listed the exact verification commands run and their results.
[x] I have described user-visible behavior changes, including INPUT parameter changes.
[x] I have explained core-module impact for ESolver, HSolver, ElecState, Hamilt, Operator, Psi, or other source/ changes.
[ ] I have requested any needed governance exception below.

Linked Issue

Fix #8228

Unit Tests and/or Case Tests for my changes

Commands run:

# 1. Configure a non-DSP build with tests and LCAO enabled,
#    so the helper-function UT is compiled
cmake -B build -DBUILD_TESTING=ON \
      -DELPA=OFF -DUSE_CUDA=OFF -DUSE_ROCM=OFF \
      -DCMAKE_BUILD_TYPE=Release
cmake --build build -j$(nproc) --target module_io_parameter_test

# 2. Run the new UT
cd build && ctest -R module_io_parameter_test --output-on-failure

# 3. Regression: make sure existing input-parsing UT still passes
ctest -R read_input --output-on-failure

# 4. Smoke test (non-DSP host): compile and run to confirm
#    nothing is broken by the macros
cmake --build build -j$(nproc) --target abacus
./build/abacus --version

Result summary:

All newly added test cases in source/source_io/module_parameter/test/parameter_dsp_layout_test.cpp pass (11 cases, 0 failures). Coverage:
    dp / nep return true (i.e., are not rejected) for any mismatched kpar * bndpar vs nproc.
    ksdft + pw validates layout against kpar; mismatch returns false.
    ksdft + lcao validates layout against kpar_lcao; a valid LCAO configuration returns true regardless of the kpar value (this case fails under the previous std::max implementation); mismatch returns false.
    Case-insensitivity: "DP" and "NEP" are treated as "dp" / "nep" (the helper normalizes via std::tolower before comparison).
Existing read_input UT: pass, no regressions.
Test build on a non-DSP host: clean, no compiler warnings.

Checks not run, with reason:

DSP-hardware verification: no DSP hardware is available, so an end-to-end run against the vendor mtblas/C_PACK libraries could not be executed. The #ifdef __DSP path is verified via the UT of the inline helper (hosted on non-DSP builds) plus manual review of the check_value flow. A maintainer with DSP access is asked to confirm two workflows: (a) esolver_type=dp with basis_type=lcao and kpar*1 != nproc produces no diagnostic at startup; and (b) esolver_type=ksdft with basis_type=pw and kpar*bndpar != nproc still produces the diagnostic.

What’s changed?

This PR refines the DSP-specific kpar / bndpar layout check to skip esolver_type = dp / nep, and fixes a latent false positive caused by std::max(kpar, kpar_lcao).

Problem analysis

esolver_type = dp and nep are machine-learning interatomic-potential solvers. They never build a PW/LCAO Hamiltonian, never create k-point pools or band groups, and never invoke the DSP mtblas/C_PACK libraries. The Availability field of bndpar already restricts its use to (basis_type==pw and esolver_type==sdft) or (basis_type==pw and esolver_type==ksdft and ks_solver==bpcg). The current #ifdef __DSP check_value has no short-circuit on esolver_type, so ML-potential workflows (MD/relax with a DP/NEP model) get hit by an irrelevant diagnostic output even though the constraint is physically inapplicable.
ModuleIO::dsp_kpar_layout_valid uses std::max(kpar, kpar_lcao). This relies on an implicit invariant (established by reset_value): for basis_type == "lcao", input.kpar is reset to 1 and sys.kpar_lcao carries the user value. The invariant is correct, but std::max hides it and is fragile if kpar_lcao is ever populated unexpectedly. The two fields are semantically mutually exclusive (PW vs. LCAO) and should be selected explicitly.
kpar’s item.description claims *“ABACUS aborts at startup otherwise”*, but the current check_value has WARNING_QUIT commented out and only prints to stdout. This PR makes the two consistent (warn, not abort), matching the intended behavior already present in check_value.

Changes made

source/source_io/module_parameter/read_input_tool.h
    Split ModuleIO::dsp_kpar_layout_valid into three inline helpers:
        dsp_layout_check_needed(esolver_type) — returns false for dp / nep.
        dsp_effective_kpar(basis_type, kpar, kpar_lcao) — explicitly selects the correct field based on basis_type, replacing std::max.
        dsp_kpar_layout_valid(nproc, basis_type, kpar, kpar_lcao, bndpar, esolver_type) — the new signature; wraps the two helpers above.
source/source_io/module_parameter/read_inp_sys.cpp (kpar item)
    Added a second early return in check_value: if (!ModuleIO::dsp_layout_check_needed(para.input.esolver_type)) return; before dsp_kpar_layout_valid is called.
    The diagnostic now prints basis_type, the correct kpar field name (kpar or kpar_lcao), and the effective pool count, instead of always printing both fields.
    The commented-out WARNING_QUIT behavior (warn-only) is confirmed and documented in a code comment.
source/source_io/module_parameter/read_input_item_sys.cpp (kpar item description text)
    Rewrote the DSP-related sentence from “ABACUS aborts at startup otherwise” to “ABACUS emits a diagnostic warning at startup; the run is not aborted”, so the documentation matches the actual behavior. Also clarified that dp/nep are exempt from this check.
New UT: source/source_io/module_parameter/test/parameter_dsp_layout_test.cpp (11 GoogleTest cases).

User-visible behavior changes

INPUT parameters: kpar, bndpar, esolver_type — no addition, removal, or renaming; only the check scope changed.
Behavior change 1: On DSP builds, esolver_type = dp or nep no longer triggers the kpar * bndpar != NPROC diagnostic output when kpar * bndpar != nproc. Such workflows previously got hit by an irrelevant output and now run cleanly.
Behavior change 2: On DSP builds, basis_type = pw with kpar * bndpar == nproc no longer produces a spurious diagnostic (this occurred when kpar_lcao was set to a non-1 value by external code — now fixed).
Behavior change 3: For basis_type = lcao, the diagnostic now suggests kpar_lcao = <nproc / bndpar> instead of the previously misleading “Please set kpar=…” line.
For ksdft / sdft / ofdft / tddft (all non-ML esolver_type), the DSP layout check behavior is unchanged.

Governance Notes

INPUT/docs changes:

The kpar item.description string is updated (the DSP-constraint sentence). No further change is expected for the documentation website, since the rendered INPUT description is derived from the same metadata.
No metadata change for bndpar.

Core module impact:

Changes are confined to the input-parsing layer under source/source_io/module_parameter/.
No changes to ESolver / HSolver / ElecState / Hamilt / Operator / Psi / K_Vectors / Parallel_Kpoints — no runtime path, no interface signature, and no data layout are affected. The ML-potential solvers (dp / nep) never consume kpar / bndpar / sys.kpar_lcao for their parallel layout, so this fix affects startup-time input validation only, not any execution path.
The helpers in read_input_tool.h are inline free functions, deliberately testable on non-DSP hosts (as recommended by the governance doc for DSP-specific logic).

Exceptions requested:

None. The __DSP code path cannot be exercised end-to-end on CI hardware; the mitigation is the inline-helper UT, which has been run as described above. If the governance rules require real-DSP-hardware checks before merge, please flag accordingly.

Refactor DSP layout validation functions for clarity and correctness.
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Agent Governance Check

Severity Rule Location Reason Suggested action Exception
warning PR metadata completeness pull_request.body missing sections: Linked Issue, Unit Tests and/or Case Tests for my changes, What's changed? Fill the PR template with issue linkage, test evidence, and a concise change summary. allowed
warning Documentation sync review pull_request.body Source changes have no docs change or explicit no-docs-needed statement. Add documentation updates for behavior/interface changes, or state why documentation is not required. allowed

Updated comments for clarity and accuracy regarding DSP layout constraints and effective k-point calculations.
@mohanchen mohanchen added GPU & DCU & HPC GPU and DCU and HPC related any issues Refactor Refactor ABACUS codes labels Nov 13, 2026
@mohanchen
mohanchen merged commit 48e2494 into develop Nov 13, 2026
29 of 31 checks passed
@Cstandardlib Cstandardlib mentioned this pull request Nov 30, 2026
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

GPU & DCU & HPC GPU and DCU and HPC related any issues Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DSP][LCAO] SCF diverges with default kpar=1 on multiple MPI processes; the DSP guard for this configuration was removed in #7420

2 participants