Skip to content

Refactor(io): modularize sparse matrix writer interface#7468

Open
goodchong wants to merge 9 commits into
deepmodeling:developfrom
goodchong:inandout
Open

Refactor(io): modularize sparse matrix writer interface#7468
goodchong wants to merge 9 commits into
deepmodeling:developfrom
goodchong:inandout

Conversation

@goodchong

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?

This PR refactors the sparse CSR writer interface in ModuleIO.
Summary:
Redesigns ModuleIO::save_sparse to use a structured SparseWriteOptions object instead of a long parameter list.
Adds type aliases for sparse real-space matrix data:RCoordinate
SparseRBlock
SparseRMatrix

Updates save_sparse and output_single_R so matrix dimensions are derived from Parallel_Orbitals::get_global_row_size() instead of PARAM.globalv.nlocal.
Refactors save_sparse internals into smaller helper routines for:counting nonzero entries by R
counting output R vectors
opening output files
writing CSR headers
writing R records

Updates output_single_R to use the same SparseWriteOptions context, including threshold, binary mode, reduce mode, and temporary file directory.
Updates all affected call sites, including:write_HS_R.cpp
write_vxc_r.hpp
restart_exx_csr.hpp
cal_r_overlap_R.cpp

Fixes the EXX restart CSR path so it no longer passes a default-constructed Parallel_Orbitals; it now initializes a serial Parallel_Orbitals with the correct matrix dimension before writing.
Updates tests to verify that CSR output uses the dimension from pv, not the global nlocal.
Tests run:
git diff --check
cmake --build build-phase0 --target MODULE_IO_single_R_test -j8
cmake --build build-phase0 --target MODULE_IO_write_hs_r_compat_test -j8
ctest --test-dir build-phase0 -R MODULE_IO_write_hs_r_compat_test -V
ctest --test-dir build-phase0 -R MODULE_IO_single_R_test -V
cmake --build build-phase0 --target io_advanced -j8
cmake --build build-phase1-nompi --target io_advanced -j8

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

Add a Phase 0 compatibility test suite for write_HS_R-related output contracts and save the refactor plan.

Tests: ctest --test-dir build-phase0 -R MODULE_IO_write_hs_r_compat_test -V
Fix sparse binary header writing, non-MPI save_mat stream opening, Vxc(R) ownership, and AngularMomentumCalculator null logging.

Extend write_HS_R compatibility coverage for legacy binary sparse headers and update the refactor plan with Phase 1 status.

Tests: ctest --test-dir build-phase0 -R MODULE_IO_write_hs_r_compat_test -V

Tests: ctest --test-dir build-phase0 -R MODULE_IO_cal_pLpR_test -V

Tests: ctest --test-dir build-phase0 -R MODULE_IO_single_R_test -V

Tests: ctest --test-dir build-phase0 -R MODULE_IO_sparse_matrix_test -V

Builds: cmake --build build-phase0 --target io_advanced -j8

Builds: cmake -B build-phase1-nompi -DBUILD_TESTING=OFF -DENABLE_MPI=OFF && cmake --build build-phase1-nompi --target io_advanced -j8
Keep the local markdown file untracked while removing it from the remote branch contents.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant