add generalized eigenvalue test for diago_cg_float_test#7408
Open
kevin0x3f wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
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
DIAGOTESTand applied it inHamiltPW::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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reminder
Linked Issue
Fix #...
Unit Tests and/or Case Tests for my changes
What's changed?
Any changes of core modules? (ignore if not applicable)