Skip to content

Fix: Correct PW KPAR/BNDPAR occupations and distributed output - #7845

Open
AsTonyshment wants to merge 2 commits into
deepmodeling:developfrom
AsTonyshment:fix/bndpar_kpar
Open

Fix: Correct PW KPAR/BNDPAR occupations and distributed output#7845
AsTonyshment wants to merge 2 commits into
deepmodeling:developfrom
AsTonyshment:fix/bndpar_kpar

Conversation

@AsTonyshment

Copy link
Copy Markdown
Collaborator

Summary

This PR fixes several PW KPAR/BNDPAR correctness issues. The changes correct fixed and explicitly supplied occupations under distributed k-point and band layouts, reconstruct complete band data before shared-file output, and fix the real-space grid collection used by charge-density .cube output.

The kpar, bndpar, and ocp_set parameter descriptions are also updated to match the current implementation.

Problems addressed

  • With smearing_method=fixed and bndpar>1, every band group treated its local band zero as global band zero. Multiple groups therefore occupied their first local bands repeatedly, producing incorrect electron counts, charge densities, band energies, and SCF results.
  • ocp_set validated its input length using the pool-local number of k-points and indexed the input with a local-band stride. KPAR could reject a correctly sized input, while BNDPAR could silently assign occupations to the wrong bands.
  • out_chg used source ranks derived from a larger process layout as ranks in POOL_WORLD. Under BPCG this could pass an invalid communicator rank to MPI_Recv after the SCF calculation had completed.
  • out_band and eigenvalue/occupation output treated band-local matrices as if they contained all global bands. This could cause out-of-bounds access, omit bands owned by other band groups, duplicate k-point contributions, or allow multiple groups to write the same shared file.

Validation

A standalone edge-case test was carried out with 21 calculations: 17 CPU cases and 4 GPU cases. PW CPU cases used 6 MPI ranks, 8 k-points, 7 bands, and BPCG. The following layouts were compared:

Layout Coverage
kpar=1,bndpar=1 Reference layout
kpar=2,bndpar=1 KPAR only
kpar=1,bndpar=3 Uneven band ownership, 3+2+2
kpar=2,bndpar=3 Mixed KPAR/BNDPAR
kpar=3,bndpar=2 Uneven k-point pools, 3+3+2, and uneven band ownership, 4+3

The edge-case test covered nspin=1 and nspin=2, fixed occupations, k-point-dependent ocp_set values, PW CPU/GPU execution, and LCAO temporary kpar=1/2/3 diagonalization. Every PW case checked the complete occupation table, total energy, band table, charge-density .cube values, and .cube integral.

All 21 cases completed successfully and reported no failures.

Test group Maximum energy difference / eV Maximum band-table difference Maximum Cube point difference Maximum Cube integral difference
PW CPU 7.190692e-12 1.534826e-10 2.299966e-13 1.199041e-14
LCAO CPU 8.526513e-14 1.163514e-13 1.000589e-14 2.042810e-14
PW GPU 0.000000e+00 3.730349e-14 1.000589e-14 5.329071e-15

@AsTonyshment
AsTonyshment requested review from mohanchen and a lite review from Copilot and removed request for Copilot August 21, 2026 10:06
@AsTonyshment
AsTonyshment requested a lite review from Copilot and removed request for Copilot August 21, 2026 11:58
@mohanchen mohanchen added Refactor Refactor ABACUS codes Bugs Bugs that only solvable with sufficient knowledge of DFT labels Aug 21, 2026
@mohanchen

Copy link
Copy Markdown
Collaborator

Could you add some unit tests or integrate tests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bugs Bugs that only solvable with sufficient knowledge of DFT Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants