Skip to content

fix: preserve HR data when wrapping HContainer with external data_array#7536

Merged
mohanchen merged 1 commit into
deepmodeling:developfrom
dyzheng:fix_hr_out_nspin2
Jun 30, 2026
Merged

fix: preserve HR data when wrapping HContainer with external data_array#7536
mohanchen merged 1 commit into
deepmodeling:developfrom
dyzheng:fix_hr_out_nspin2

Conversation

@dyzheng

@dyzheng dyzheng commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

The HContainer copy constructor was unconditionally zeroing out the data_array when wrapping existing memory. This caused getHR_vector() to erase both spin channels' HR data for nspin=2, resulting in all-zero HR output when out_mat_hs2 is enabled.

Fix: only zero memory when data_array is nullptr (fresh allocation); preserve existing data when wrapping external memory.

Also add integration test scf_out_hsr_spin2 (nspin=2 + out_mat_hs2) and update catch_properties.sh to compare hrs2_nao.csr for nspin=2.

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 #7535

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

The HContainer copy constructor was unconditionally zeroing out the
data_array when wrapping existing memory. This caused getHR_vector()
to erase both spin channels' HR data for nspin=2, resulting in all-zero
HR output when out_mat_hs2 is enabled.

Fix: only zero memory when data_array is nullptr (fresh allocation);
preserve existing data when wrapping external memory.

Also add integration test scf_out_hsr_spin2 (nspin=2 + out_mat_hs2)
and update catch_properties.sh to compare hrs2_nao.csr for nspin=2.

@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 Bugs Bugs that only solvable with sufficient knowledge of DFT Refactor Refactor ABACUS codes Input&Output Suitable for coders without knowing too many DFT details labels Jun 30, 2026
@mohanchen mohanchen merged commit 64d11d0 into deepmodeling:develop Jun 30, 2026
16 checks passed
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 Input&Output Suitable for coders without knowing too many DFT details Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nspin=2 + out_mat_hs2 writes empty hrs1/hrs2 CSR files while srs1 and dmrs are valid

2 participants