Skip to content

Fix(gint): remove extra conjugation in noncollinear Hamiltonian assembly - #8183

Open
zjdai wants to merge 2 commits into
deepmodeling:developfrom
zjdai:fix/8121-noncollinear-gint
Open

zjdai wants to merge 2 commits into
deepmodeling:developfrom
zjdai:fix/8121-noncollinear-gint

Conversation

@zjdai

@zjdai zjdai commented Oct 20, 2026 •

Copy link
Copy Markdown

Noncollinear states with a transverse y component can converge while the completed full Hamiltonian is non-Hermitian. This PR removes the extra conjugation in reverse spatial-block assembly and adds two compact O2 regression cases with complete raw H(R)/S(R) references.

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 focused regression cases.
  • I have reported the verification performed and its limitations.
  • I have described user-visible behavior and core-module impact.

Linked Issue

Fixes #8121

What's changed?

In ModuleGint::merge_hr_part_to_hR, exchanging spatial indices while keeping spin indices fixed requires a spatial transpose at the opposite translation. Full spinor Hermiticity also exchanges spin indices; Bx - i By and Bx + i By already supply the conjugate relationship. Applying an additional std::conj within a fixed spin block incorrectly reverses the imaginary sign.

The production change remains one assignment and its explanatory comment. It corrects Hamiltonian assembly, including exported H(R). There are no INPUT interface, output-format, dependency or global-state changes.

The two new flat cases are registered in tests/03_NAO_multik/CASES_CPU.txt:

  • scf_nspin4_nsoc_hr
  • scf_nspin4_soc_hr

Both use an O2 molecule in a 20-bohr cubic cell, a 2.3-bohr bond, the existing fully relativistic O pseudopotential and minimal 1s1p orbital file, PBE/LCAO, 20 Ry, Gamma 1x1x1, gamma_only 0, nspin 4, initial moments (1/sqrt(2),1/sqrt(2),0) per atom, Pulay mixing 0.4 and mixing_gg0 3.0. They perform full SCF with scf_thr 1e-6 and scf_nmax 50; no DeltaSpin constraint is enabled. lspinorb distinguishes the two cases.

The existing full-matrix comparison machinery is unchanged. References are the original complex 16x16 CSR outputs, with no Hermitian projection, symmetry averaging, rotation, energy alignment or numerical truncation beyond ABACUS output precision. Only R=0 is present; these cases do not test intercell Bloch phases. Pseudopotential and orbital files are reused from tests/PP_ORB.

Verification

At production commit f290f285 (four MPI ranks, OMP_NUM_THREADS=1):

  • NSOC and SOC converge in 29 and 30 iterations. Final grid magnetizations are approximately (1.41421,1.41421,0) and (1.41411,1.41411,0) muB per cell.
  • ABACUS-reported runtime is 2.77/2.86 seconds per case, approximately 4.07 seconds including MPI launch on the tested host; this is not a 1-second runtime claim.
  • Raw H Hermiticity residuals are below 6.3e-15 eV. H+S references total 26,287 bytes across both cases.
  • The existing collector reports H/S comparison success for the fixed outputs. Parent ffc4d0d3 converges but fails H comparison, with maximum raw H differences of 0.265885/0.268983 eV; S is unchanged. A fresh collector check using the final case names reproduced these outcomes without changing comparison tolerances.
  • ZIP integrity and every packaged file hash were checked. The staged governance check reports no findings. Raw CSR terminal blank lines are preserved byte-for-byte; the whitespace check with only blank-at-eof excluded passes.

Exact local commands included:

sbatch reports/pr_8121/o2_molecule_20ry_k111/run_gamma.sbatch
python3 reports/pr_8121/o2_covariance/publication/verify_candidates.py
python3 tools/03_code_analysis/agent_governance_check.py --staged
git -c core.whitespace=-blank-at-eof diff --cached --check

The reports/ commands are local validation records, not additional files in this PR. No new C++ build was required for this fixture-only commit; the numerical runs used the already-built fix and parent executables. Upstream CI is separate from these local results.

Additional covariance evidence and limitation

Separate local diagnostics checked each structure's finite magnetic group (16 operations for z moments, 8 for xy moments, including antiunitary operations) and the appropriate rotation relations.

  • With SOC, simultaneously rotating the entire cell, molecule, orbital basis and spin gives a raw H covariance residual of 1.95e-7 eV after the fix versus 0.268983 eV before it. A spin-only z-to-xy rotation of the unchanged molecule is not a SOC symmetry.
  • Without SOC, rebuilding H from the corresponding final converged full real-space densities gives a pure-spin rotation residual of 7.48e-11 eV after the fix versus 0.294177 eV before it. These are fixed-density NSCF diagnostics, not additional SCF convergence claims.
  • The original independently stopped NSOC SCF outputs retain a z-to-xy H residual of 6.51e-4 eV at scf_thr=1e-6, and 0.02414 eV in a separate 1e-9 diagnostic. Final densities and final effective potentials rotate consistently; the discrepancy lies between the retained last-diagonalization H and H rebuilt from the final density, primarily in the xy run. The last input potential was not directly sampled, so a specific threshold mechanism is not established. The reconstruction does not replace the original SCF references or count this residual as a pass.
  • Same-geometry z moments give identical pre/post H without SOC, but with SOC a 9.67e-5 eV difference remains in the affected reverse opposite-spin block. Nonzero local transverse magnetization persists even when its cell integral vanishes.

The compact cases protect the assembly regression; this PR does not claim that every SCF endpoint covariance check or every material is certified.

Downloadable case package

Download pr8183_o2_hr_tests.zip (10,257 bytes; 15 entries: the two cases and the case-list snapshot).

SHA256: 0fb04adc290246a3cea07ee658f781e092c4fcab6bfc95039eb9e8f4ba60951f.

The archive is also tracked beside the cases for review convenience; it is not registered as a test. It contains exactly the reviewed files and no program binaries, logs, duplicated PP/orbital resources, or diagnostic cube files.

Governance Notes

  • Core impact: one noncollinear Gint assembly assignment and its explanation; test fixtures use the existing collector and thresholds.
  • Documentation: no user-manual or Input_Item update is needed because INPUT interfaces and output formats are unchanged.
  • HSE periodic-image handling, EXX restart readers, DeltaSpin algorithm changes and SCF termination behavior are outside this change.

Transpose the reverse atom-pair block without conjugating its coefficients
while the spin indices are fixed. The opposite spin block already carries
the conjugate Pauli coefficients. The extra conjugation reverses the By
contribution and breaks full spinor Hermiticity.

Correct the adjacent comment to distinguish the spatial transpose from the
Hermitian adjoint of the full spinor matrix.

Fixes deepmodeling#8121
@zjdai
zjdai force-pushed the fix/8121-noncollinear-gint branch from 72e3fc2 to f290f28 Compare October 20, 2026 05:31

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

Thanks for your fix!

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.

Thanks for your fix! However, we should have a test! Either unittest or integrate test is OK.

@mohanchen mohanchen added Bugs Bugs that only solvable with sufficient knowledge of DFT Refactor Refactor ABACUS codes labels Oct 21, 2026

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.

the file is too large

basis_type lcao
ks_solver scalapack_gvx
dft_functional pbe
ecutwfc 60

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.

maybe consider lowering the ecut

@zjdai
zjdai force-pushed the fix/8121-noncollinear-gint branch from 20e3910 to f290f28 Compare October 21, 2026 06:05
@zjdai

zjdai commented Oct 21, 2026

Copy link
Copy Markdown
Author

Added the reviewed compact O2 cases in c085dde:

  • tests/03_NAO_multik/scf_nspin4_nsoc_hr
  • tests/03_NAO_multik/scf_nspin4_soc_hr

Download the exact reviewed ZIP (10,257 bytes). The archive is included in the commit; PP/orbital resources are reused from the repository.

The existing collector passes both fixed-build H/S references and detects the pre-fix H errors. The PR description now records the rotation diagnostics and the remaining difference between the NSOC last-SCF Hamiltonian and the Hamiltonian rebuilt from the final converged density; it does not claim that all SCF endpoint covariance checks passed.

This branch has not been deployed

No deployments
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.

Non-Hermitian and non-covariant H(R) output in ABACUS v3.11.0-beta10

2 participants