Skip to content

Refactor occupation matrix initialization - #8147

Merged
mohanchen merged 5 commits into
deepmodeling:developfrom
lanshuyue:refactor/occ-matrix-complexity
Oct 17, 2026
Merged

mohanchen merged 5 commits into
deepmodeling:developfrom
lanshuyue:refactor/occ-matrix-complexity

Conversation

@lanshuyue

Copy link
Copy Markdown
Collaborator

Summary

  • Split occupation-matrix allocation and correlated-orbital mapping into private helpers allocate_atom_matrices() and build_corr_iwt() so init() is a clear top-level loop.
  • Remove duplicated saved-matrix flattening branches in write_save_to_flat(): channel 0 copy is shared across all supported spin modes, only nspin=2 additionally copies channel 1; use std::copy.
  • Add direct nspin=1/2/4 layout and flattening tests in MODULE_ESTATE_occ_matrix.

This is a behavior-preserving maintainability refactor; no numerical behavior, data layout, or public interface change.

Tests

  • cmake --build build --target MODULE_ESTATE_occ_matrix MODULE_ESTATE_occ_mixer -j2 -> both targets built successfully
  • ctest --test-dir build -V -R 'MODULE_ESTATE_occ_(matrix|mixer)' -> 100% tests passed, 0 tests failed out of 2 (13 gtest cases total)
  • python3 tools/03_code_analysis/code_quality_score.py source/source_estate/occ_matrix.cpp -> 100/100 (was 98/100; both high_cyclomatic_complexity deductions eliminated)
  • git diff --check -> PASS
  • python3 tools/03_code_analysis/agent_governance_check.py --staged -> one warning only: documentation sync review (no user-visible behavior change, so no docs update required)

Summary:
- Split occupation-matrix allocation and correlated-orbital mapping
  into private helpers allocate_atom_matrices() and build_corr_iwt()
  so init() is a clear top-level loop.
- Remove duplicated saved-matrix flattening branches in
  write_save_to_flat(): channel 0 copy is shared across all supported
  spin modes, only nspin=2 additionally copies channel 1; use std::copy.
- Add direct nspin=1/2/4 layout and flattening tests in
  MODULE_ESTATE_occ_matrix.

No change to numerical behavior, data layout, or public interface.

Tests:
- cmake --build build --target MODULE_ESTATE_occ_matrix MODULE_ESTATE_occ_mixer -j2
- ctest --test-dir build -V -R 'MODULE_ESTATE_occ_(matrix|mixer)'
  -> 100% tests passed, 0 tests failed out of 2 (13 gtest cases)
- python3 tools/03_code_analysis/code_quality_score.py source/source_estate/occ_matrix.cpp
  -> 100/100 (was 98/100; both high_cyclomatic_complexity deductions gone)
- git diff --check: PASS
- python3 tools/03_code_analysis/agent_governance_check.py --staged
  -> one warning only: documentation sync review (no user-visible
     behavior change, so no docs update required)
@lanshuyue
lanshuyue requested a review from mohanchen October 14, 2026 17:53
@mohanchen mohanchen added the Refactor Refactor ABACUS codes label Oct 15, 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.

Static review of 4d1069d: no correctness regression found in the inspected allocation, mapping, and saved-flattening paths. One optional test improvement below. No build or runtime tests were run; CI diagnostics were unavailable through the configured connector.

Comment thread source/source_estate/test/test_occ_matrix.cpp
@mohanchen

Copy link
Copy Markdown
Collaborator

LGTM. Thanks for your contributions. @lanshuyue

@mohanchen
mohanchen merged commit 401f8d9 into deepmodeling:develop Oct 17, 2026
17 checks passed
@mohanchen mohanchen added the DFT+U Issues related to DFT plus U function label Oct 17, 2026
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 Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants