Skip to content

Fix silent skip of single-precision PW onsite corrections - #8231

Merged
mohanchen merged 4 commits into
deepmodeling:developfrom
lanshuyue:codex/fix-pw-onsite-single-precision
Nov 4, 2026
Merged

mohanchen merged 4 commits into
deepmodeling:developfrom
lanshuyue:codex/fix-pw-onsite-single-precision

Conversation

@lanshuyue

@lanshuyue lanshuyue commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Reminder

  • I read AGENTS.md and docs/developers_guide/agent_governance.md.
  • No linked issue: this failure mode was identified during a focused code review.
  • Focused tests and PW case checks are listed below.
  • User-visible INPUT behavior and core-module impact are described below.
  • No governance exception is requested.

Linked Issue

No linked issue; this PR addresses the single-precision PW onsite silent-skip path found during review.

Unit Tests and/or Case Tests for my changes

  • cmake --build build --target MODULE_IO_read_item_serial abacus_basic_para -j 4 — passed.
  • cmake --build build --target module_pwdft -j 4 — passed.
  • cmake --build build --target onsite_op_test MODULE_PW_dftu_base_test MODULE_PW_test_dftu_pw_tools -j 4 — passed.
  • OMP_NUM_THREADS=1 ctest --test-dir build --output-on-failure -R '^(onsite_op_test|MODULE_PW_dftu_base_test|MODULE_PW_test_dftu_pw_tools|MODULE_IO_read_item_serial)$' — 4/4 passed outside the restricted sandbox. The first sandboxed run could not initialize MPI; the rerun passed.
  • build/abacus_basic_para --version — v3.11.0-beta11; build/abacus_basic_para -h precision — displays the new restriction.
  • OMP_NUM_THREADS=1 build/abacus_basic_para --check-input on isolated copies of PW DFT+U and DeltaSpin cases with precision single — both exited 1 with feature-specific errors before SCF.
  • Double-precision case checks in /tmp: relax_dftu_spin2 (1 rank) and scf_deltaspin2 (2 MPI ranks) completed. DeltaSpin energy, force, and stress match result.ref. The DFT+U relax values differ from the repository reference by 0.0004037623 eV, 0.002652 force sum, and 0.602177 stress sum. The unmodified upstream/develop code, rebuilt and run on the same isolated input, produced exactly the same values as this patch, so there is no numerical drift from this change.
  • python3 tools/03_code_analysis/agent_governance_check.py --staged — no errors; two review warnings explained below.
  • git diff --cached --check — passed.
  • Follow-up for ABACUS-PR-BOT review: cmake --build build --target MODULE_IO_read_item_serial -j 4 and OMP_NUM_THREADS=1 ctest --test-dir build --output-on-failure -R '^MODULE_IO_read_item_serial$' — passed (1/1); staged governance check and diff whitespace check passed.
  • python3 tools/03_code_analysis/code_quality_score.py --format json source/source_pw/module_pwdft/op_pw_proj.cpp — 79 before, 91 after. This is static quality evidence, not numerical validation.

What's changed?

  • Reject single-precision PW Kohn–Sham or TDDFT input when DFT+U or DeltaSpin onsite corrections are enabled, instead of silently applying an empty float operator.
  • Pass nspin to OnsiteProj at construction and use it for the existing nspin=1/2/4 potential layout and spin selection. No double-precision arithmetic or kernel was changed.
  • Clarify the early diagnostic for PW RT-TDDFT: DFT+U and spin constraints are unsupported at every precision, with the corresponding input setting named in each error. Add focused input regression coverage for both TDDFT paths. The unused pointer-copy constructor and existing float stubs remain untouched to keep this fix narrow.

Governance Notes

  • INPUT/docs changes: the precision Input_Item help text now states the Kohn–Sham double-precision requirement and the RT-TDDFT solver restriction at any precision. Generated documentation is a build artifact and was not committed.
  • Core module impact: the PW Hamiltonian passes its existing PARAM.inp.nspin value once into the operator. Four global reads are removed from op_pw_proj.cpp; the PR has a net reduction of five global references. The remaining reads belong at the existing Hamiltonian construction boundary.
  • CPU/GPU coverage: CPU build and tests passed. GPU/CUDA/ROCm kernels and runtime were not executed because this build is CPU-only. No float onsite kernel support is claimed.
  • Exceptions requested: none.

Conflict resolution and latest verification

  • Merged upstream develop at d20090cc1 into the existing PR branch. Resolved the sole conflict in hamilt_pw.cpp by retaining the explicit nspin argument while incorporating upstream's other changes.
  • Rebuilt MODULE_IO_read_item_serial, module_pwdft, onsite_op_test, MODULE_PW_dftu_base_test, and MODULE_PW_test_dftu_pw_tools successfully.
  • OMP_NUM_THREADS=1 ctest --test-dir build --output-on-failure -R '^(onsite_op_test|MODULE_PW_dftu_base_test|MODULE_PW_test_dftu_pw_tools|MODULE_IO_read_item_serial)$' — 4/4 passed with MPI access. The first restricted-environment run failed to initialize MPI for MODULE_PW_dftu_base_test; the rerun passed.
  • python3 tools/03_code_analysis/agent_governance_check.py --base upstream/develop --head HEAD --format text — no errors. Global-dependency warnings reflect the existing Hamiltonian construction boundary, with a net reduction of five references. The precision help text is updated in Input_Item; generated docs are not committed.
  • git diff --check upstream/develop...HEAD — passed. The PR diff against the updated base remains five files.

ASE CI rerun

  • The first ASE run failed in two LCAO silicon tests with Can't find even an electron! after the electron density became negative. This matches the intermittent failure documented in #7794; the PR changes no LCAO calculation path.
  • Rerun of the failed ASE workflow completed successfully: both unit and integration test steps passed. No code change was needed for this CI retry.

Maintainer review follow-up

  • Replaced auto with the explicit Input_Item iterator type in the focused precision test.
  • Kept all six OnsiteProj constructor arguments on one line. Named local values preserve the original condition and keep the call within the 120-character style limit.
  • Rebuilt MODULE_IO_read_item_serial and module_pwdft; the four focused tests passed (4/4) with MPI access. The diff whitespace check passed; the governance check has no errors and reports a net reduction of five global references.

@mohanchen mohanchen added the Bugs Bugs that only solvable with sufficient knowledge of DFT label Oct 29, 2026

@ABACUS-PR-BOT ABACUS-PR-BOT left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No new correctness defect found in the inspected precision guard and nspin handoff. One nonblocking diagnostic suggestion is inline. This was a static review of 7df13fa89513e8227924262bf1541a46c987b14e against e5ad53046d4f4c4502bd04657b7fbeba60d97ad4; builds, tests, CLI and numerical checks were not run, and CI diagnostics were unavailable.

@mohanchen

Copy link
Copy Markdown
Collaborator

reopen when it is not a draft

@mohanchen mohanchen closed this Nov 1, 2026
@lanshuyue lanshuyue reopened this Nov 1, 2026
@lanshuyue
lanshuyue marked this pull request as ready for review November 1, 2026 17:00
@mohanchen
mohanchen merged commit 48209ad into deepmodeling:develop Nov 4, 2026
20 checks passed
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants