Skip to content

add generalized eigenvalue test for diago_cg_float_test#7408

Open
kevin0x3f wants to merge 1 commit into
deepmodeling:developfrom
kevin0x3f:diago-generalized-test
Open

add generalized eigenvalue test for diago_cg_float_test#7408
kevin0x3f wants to merge 1 commit into
deepmodeling:developfrom
kevin0x3f:diago-generalized-test

Conversation

@kevin0x3f
Copy link
Copy Markdown

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?

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

Copilot AI review requested due to automatic review settings May 30, 2026 15:08
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support in the test mock Hamiltonian for a diagonal overlap matrix (S) to exercise generalized eigenproblem paths in the CG float tests.

Changes:

  • Introduced diagonal S storage in DIAGOTEST and applied it in HamiltPW::sPsi.
  • Added a LAPACK-based reference solver for the diagonal-S generalized eigenproblem.
  • Added a new parametrized test that generates a positive diagonal S and compares eigenvalues.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
source/source_hsolver/test/diago_mock.h Adds global diagonal-S vectors and updates sPsi to apply S to psi.
source/source_hsolver/test/diago_cg_float_test.cpp Adds generalized-eigen LAPACK reference and a new test covering non-identity diagonal S.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +15 to +19
// diagonal representation of overlap (S) for simple mock of generalized eigenproblem
// if empty, sPsi will treat S as identity
std::vector<double> sdiag_d; // for double / complex<double>
std::vector<std::complex<float> > sdiag_f;
std::vector<std::complex<double>> sdiag;
Comment on lines +418 to 426
if (DIAGOTEST::sdiag_d.size() < static_cast<size_t>(nrow)) {
DIAGOTEST::sdiag_d.assign(nrow, 1.0); // 默认单位 S
}
for (int v = 0; v < nbands; ++v) {
for (int i = 0; i < nrow; ++i) {
size_t idx = static_cast<size_t>(v) * nrow + i;
spsi[idx] = psi_in[idx] * DIAGOTEST::sdiag_d[i];
}
}
Comment on lines +62 to +72
void lapackGeneralEigen(int &npw, std::vector<std::complex<float>> &hm, const std::vector<std::complex<float>> &sdiag, float *e, bool outtime = false)
{
// build transformed matrix tmp = S^{-1/2} H S^{-1/2}
std::vector<std::complex<float>> tmp(npw * npw);
for (int i = 0; i < npw; ++i) {
std::complex<float> si = std::sqrt(sdiag[i]);
for (int j = 0; j < npw; ++j) {
std::complex<float> sj = std::sqrt(sdiag[j]);
tmp[i * npw + j] = hm[i * npw + j] / (si * sj);
}
}
Comment on lines +81 to +83
cheev_(&tmp_c1, &tmp_c2, &npw, tmp.data(), &npw, e, work2, &lwork, rwork, &info);
end = clock();
if (outtime) std::cout << "Lapack General Run time: " << (float)(end - start) / CLOCKS_PER_SEC << " S" << std::endl;
Comment on lines +281 to +285
// 生成正定对角 S(范围 0.5..1.5)
DIAGOTEST::sdiag_f.resize(dcp.npw);
std::default_random_engine eng(123);
std::uniform_real_distribution<float> ud(0.5f, 1.5f);
for (int i = 0; i < dcp.npw; ++i) DIAGOTEST::sdiag_f[i] = std::complex<float>(ud(eng), 0.0f);
{
spsi[i] = psi_in[i];
if (DIAGOTEST::sdiag_d.size() < static_cast<size_t>(nrow)) {
DIAGOTEST::sdiag_d.assign(nrow, 1.0); // 默认单位 S
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants