Skip to content

Fix bug (deltaspin): restore LCAO spin rotation invariance - #7914

Open
Tao-Xia wants to merge 4 commits into
deepmodeling:developfrom
Tao-Xia:codex/fix-deltaspin-spin-rotation
Open

Fix bug (deltaspin): restore LCAO spin rotation invariance#7914
Tao-Xia wants to merge 4 commits into
deepmodeling:developfrom
Tao-Xia:codex/fix-deltaspin-spin-rotation

Conversation

@Tao-Xia

@Tao-Xia Tao-Xia commented Sep 6, 2026

Copy link
Copy Markdown

Reminder

  • I have read AGENTS.md and docs/developers_guide/agent_governance.md.
  • I have linked an issue or explained why this PR does not need one.
  • I have added adequate unit tests and/or case tests, or explained why not.
  • I have listed the exact verification commands run and their results.
  • I have described user-visible behavior changes, including INPUT parameter changes.
  • 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

Fixes #7913

Unit Tests and/or Case Tests for my changes

  • Commands run:
    • cmake --build build-elpa-cpu --target deltaspin_core_test MODULE_HSOLVER_LCAO abacus_basic_para -j 12
    • build-elpa-cpu/source/source_lcao/module_deltaspin/test/deltaspin_core_test
    • From source/source_hsolver/test: build-elpa-cpu/source/source_hsolver/test/MODULE_HSOLVER_LCAO
    • From the same directory: mpirun -np 4 build-elpa-cpu/source/source_hsolver/test/MODULE_HSOLVER_LCAO --gtest_filter='DiagoElpaComplexTest.UsesAuthoritativeUpperTriangle:DiagoTest/DiagoKPointsTest.LCAO/0'
    • Two 12-rank bcc-Fe LCAO DeltaSpin integration runs with equivalent x and y target moments, no SOC, and ks_solver genelpa.
  • Result summary:
    • DeltaSpin: 22/22 tests passed.
    • LCAO eigensolver: 7/7 single-rank tests passed; 2/2 selected 4-rank tests passed.
    • Both new regression tests were also checked against the old behavior and failed as intended.
    • bcc-Fe x/y total energies differ by only 1.82e-8 eV; both target moments converge with transverse residuals of order 1e-6 mu_B.
  • Checks not run, with reason:
    • Full repository test suite was not run because the change is confined to the complex genelpa transform and DeltaSpin coefficient mapping; the focused module tests and end-to-end integration runs exercise both paths.

What's changed?

  • Use PZHEMM with the authoritative upper triangle when the complex custom ELPA solver forms the generalized Hamiltonian. This prevents stale lower-triangle entries from entering the eigensolve without allocating an extra full matrix.
  • Define the Cartesian-Pauli-to-spinor conversion once and use it in the LCAO DeltaSpin operator.
  • Add an invariant test requiring <psi | lambda dot sigma | psi> = lambda dot M, including the sign-sensitive y channel.
  • Add a complex genelpa regression that deliberately corrupts the non-authoritative lower triangle and compares with the upper-triangle LAPACK reference.

There are no INPUT parameter or serialized-data changes. The user-visible correction is restored non-SOC spin-rotation invariance for LCAO DeltaSpin with genelpa.

Governance Notes

  • INPUT/docs changes: none; no user-facing option or default changes.
  • Core module impact: HSolver changes one complex generalized-transform kernel from general to Hermitian distributed multiplication; OperatorLCAO uses a shared DeltaSpin Pauli conversion. ESolver, ElecState, and Psi interfaces are unchanged.
  • Exceptions requested: none.

@dyzheng dyzheng 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,This PR may resolve the numerical instability issue in non‑collinear spin calculations with the LCAO basis set. Thank you for your submission.

@mohanchen mohanchen added Bugs Bugs that only solvable with sufficient knowledge of DFT Refactor Refactor ABACUS codes labels Sep 6, 2026
@mohanchen mohanchen changed the title fix(deltaspin): restore LCAO spin rotation invariance Fx bug (deltaspin): restore LCAO spin rotation invariance Sep 6, 2026
@mohanchen mohanchen changed the title Fx bug (deltaspin): restore LCAO spin rotation invariance Fix bug (deltaspin): restore LCAO spin rotation invariance Sep 6, 2026
@mohanchen

Copy link
Copy Markdown
Collaborator

该测试算例破坏了 /08_EXX/08_KP_HSE_symm 的结果

信息如下:
结论
会调用 ELPA_Solver::generalized_eigenvector 的复数重载。

判定依据
输入:basis_type=lcao、ks_solver=genelpa、gamma_only=0(多 k)、nspin=1。genelpa 只在定义 __ELPA 时可用。
k 点类型:KPT 是 2 2 2 多 k,波函数类型为 std::complex,因此模板实参 T = std::complex。
代码路径(kpar=1,走非 pool 路径):
hsolver_lcao.cpp:148-152:method == "genelpa" → DiagoElpa::diag。
diago_elpa.cpp:66-95:DiagoElpa<std::complex>::diag 在第 89 行调用 es.generalized_eigenvector(h_mat.p, s_mat.p, this->DecomposedState, eigen.data(), psi.get_pointer()),正是上一轮定位到的复数重载调用点 2。
运行日志印证:running_scf.log 中 HSolverLCAO hamiltSolvePsiK 被调用 63 次,与 21 SCF 步 × 3 个不可约 k 点吻合(每次 k 点求解都会进入一次该函数)。
不会命中的路径
DiagoElpa 实数重载:本算例为多 k 复数,不会走。
DiagoElpa<std::complex>::diag_pool:需要 kpar>1,INPUT 未设置,默认 kpar=1,不走 parakSolve。
hsolver::elpa_diag(diag_hs_para.cpp):仅 dav_subspace 子空间对角化用,本算例不是 dav。
补充:该调用成立的前提是编译时启用了 __ELPA(ENABLE_ELPA),日志能正常出结果说明该二进制已启用 ELPA。

@mohanchen

Copy link
Copy Markdown
Collaborator

Please confirm the modification is correct. @Tao-Xia @dyzheng @maki49

@mohanchen

Copy link
Copy Markdown
Collaborator

The error is:

image

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

See comments.

@Growl1234

Growl1234 commented Sep 9, 2026

Copy link
Copy Markdown
  • Looks like fallback path (DecomposedState == 3) is forgotten.
  • Has all related comments (inline documentation) been updated?

Wrt EXX issues, I believe this was a bug and #7923 gave the right fix.

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.

bug(deltaspin): non-SOC LCAO spin rotation invariance breaks with genelpa

4 participants