Skip to content

Test: separate from #7304 for test cases only - #7382

Merged
mohanchen merged 2 commits into
deepmodeling:developfrom
dyzheng:feat/tests-17-ds-dftu
May 25, 2026
Merged

mohanchen merged 2 commits into
deepmodeling:developfrom
dyzheng:feat/tests-17-ds-dftu

Conversation

@dyzheng

@dyzheng dyzheng commented May 25, 2026

Copy link
Copy Markdown
Collaborator

Reminder

  • Have you linked an issue with this pull request?
  • Have you added adequate unit tests and/or case tests for your pull request?
  • Have you noticed possible changes of behavior below or in the linked issue?
  • Have you explained the changes of codes in core modules of ESolver, HSolver, ElecState, Hamilt, Operator or Psi? (ignore if not applicable)

Linked Issue

Fix #...

Unit Tests and/or Case Tests for my changes

  • A unit test is added for each new feature or bug fix.

What's changed?

  • Example: My changes might affect the performance of the application under certain conditions, and I have tested the impact on various scenarios...

Any changes of core modules? (ignore if not applicable)

  • Example: I have added a new virtual function in the esolver base class in order to ...

dyzheng added 2 commits May 25, 2026 10:39
Add the 17_DS_DFTU test suite for DeltaSpin and DFT+U functionality:
- 47 test cases covering LCAO/PW basis, collinear/noncollinear spin,
  DFT+U, DeltaSpin, and their combinations
- Comment out tests in tests/CMakeLists.txt and tests/17_DS_DFTU/CMakeLists.txt
  to prevent CI failure until DeltaSpin code is merged into develop
- Add single-line README to each test directory (printed during Autotest.sh)
- Rewrite CASES_CPU.txt with clear English comments explaining disabled tests

@mohanchen mohanchen 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.

LGTM

@mohanchen mohanchen added Tests/Examples Issues/PR related to unit tests and integrate tests Features Needed The features are indeed needed, and developers should have sophisticated knowledge DFT+U Issues related to DFT plus U function labels May 25, 2026
@mohanchen
mohanchen merged commit 91c0c03 into deepmodeling:develop May 25, 2026
15 checks passed
dyzheng pushed a commit to dyzheng/abacus-develop that referenced this pull request Sep 16, 2026
The result.ref of these five PW DeltaSpin cases predates the DeltaSpin
PW rework (they were last written in deepmodeling#7382) and no longer matched the
code: 12/18 were off by 2.6/4.6 eV, while 19/21/41 differed only at the
1e-4-1e-7 eV level. Regenerate all five with the current code so the
17_DS_DFTU suite passes again.

12_PW_DS_S2_Z now agrees with the dedicated 01_PW/scf_deltaspin2
reference (-6369.19826815 eV), confirming the new value is the intended
one.
mohanchen pushed a commit that referenced this pull request Sep 18, 2026
* Fix(deltaspin): propagate current_spin through LCAO operator chain

HamiltLCAO::updateHk() sets current_spin on the root operator via
set_current_spin(isk[ik]), but the value was never forwarded to child
operators. DeltaSpin did not toggle its own current_spin, so it always
saw current_spin == 0 for nspin=2 and applied the same +lambda_z
coefficient to both spin channels instead of +lambda_z/-lambda_z. The
constraint therefore acted as a spin-independent potential and produced
wrong magnetic moments and total energies.

Propagate current_spin to the next operator in OperatorLCAO::init()
before processing the current node, so every node in the chain shares
the spin state set by the k-point loop.

Regenerate tests/03_NAO_multik/scf_deltaspin2/result.ref, whose previous
values encoded the buggy result.

* Fix(pw): correct nspin=2 DeltaSpin occupation output and per-atom labels

cal_occupations() read the becp layout with the npol=2 stride
(ib*2*nkb) and ignored the spin channel for nspin=2 (npol=1), so the
projected atomic magnetization printed by print_orb_chg() was wrong for
nspin=2. Index by the psi npol and store the spin-up/down occupancy in
the up-up/down-down Pauli blocks so that Charge = occ[0]+occ[3] and
Mag(z) = occ[0]-occ[3] print correctly; nspin=1 keeps a zero
magnetization; nspin=4 keeps the interleaved spinor layout.

Also build per-atom labels (Fe1, Fe2, ...) for the Total Magnetism /
Magnetic force tables in print_orb_chg(), print_Mi() and
print_Mag_Force(), instead of passing the per-type label vector (size
ntype) to tables with nat rows.

get_iat() is made const so the label helpers can read it from a
const SpinConstrain reference.

* Test: refresh stale DeltaSpin PW reference values

The result.ref of these five PW DeltaSpin cases predates the DeltaSpin
PW rework (they were last written in #7382) and no longer matched the
code: 12/18 were off by 2.6/4.6 eV, while 19/21/41 differed only at the
1e-4-1e-7 eV level. Regenerate all five with the current code so the
17_DS_DFTU suite passes again.

12_PW_DS_S2_Z now agrees with the dedicated 01_PW/scf_deltaspin2
reference (-6369.19826815 eV), confirming the new value is the intended
one.

* Refactor(pw): pass nspin explicitly to cal_occupations

The governance checker blocks PRs that increase GlobalV/GlobalC/PARAM
usage. cal_occupations() read PARAM.inp.nspin twice; pass it as an
explicit argument from ctrl_scf_pw() (which already holds the parsed
Input_para) instead. Also keep the print_orb_chg() header line using the
existing atom_label variable so the GlobalV::ofs_running line stays
untouched.

---------

Co-authored-by: dyzheng <zhengdy@bjaisi.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DFT+U Issues related to DFT plus U function Features Needed The features are indeed needed, and developers should have sophisticated knowledge Tests/Examples Issues/PR related to unit tests and integrate tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants