EXX cal_dHs including Hellmann-Feynman term#10
Open
maki49 wants to merge 4 commits into
Open
Conversation
maki49
commented
Jun 16, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a new cal_dHs API to compute dH contributions split into Pulay and Hellmann–Feynman (HF) components, and introduces save-flag setters to control output.
Changes:
- Introduced
Exx::cal_dHs(...)implementation to computedHs(Pulay) plus newdHs_HF(HF) terms. - Added public setters to toggle saving
dHs/dHRs. - Added
dHs_HFstorage and clarifieddHscomment/shape.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| include/RI/physics/Exx.hpp | Implements cal_dHs, including new HF accumulation via temporary slicing of Ds in lri.data_pool. |
| include/RI/physics/Exx.h | Exposes cal_dHs, adds save-flag setters, and introduces dHs_HF member with documentation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+487
to
+545
| auto set_D_slots = [&](const std::string& name) { | ||
| for (const Label::ab lab : { Label::ab::a1b1, Label::ab::a1b2, Label::ab::a2b1, Label::ab::a2b2 }) | ||
| this->lri.data_ab_name[lab] = name; | ||
| }; | ||
| auto install_slice = [&](std::map<TA, std::map<TAC, Tensor<Tdata>>> slice) { | ||
| Data_Pack<TA, TC, Tdata> pack; | ||
| pack.Ds_ab = std::move(slice); | ||
| pack.index_Ds_ab = RI_Tools::get_index(pack.Ds_ab); | ||
| this->lri.data_pool[tmp] = std::move(pack); | ||
| set_D_slots(tmp); | ||
| }; | ||
|
|
||
| for (const TA& Apin : pin_atoms) | ||
| { | ||
| // ===== a-side (K = Apin): slice Ds by OUTER key (TA) ===== | ||
| { | ||
| std::map<TA, std::map<TAC, Tensor<Tdata>>> slice; | ||
| slice[Apin] = Ds.at(Apin); // shallow; tensors shared | ||
| install_slice(std::move(slice)); | ||
| } | ||
| // dC part, sign-flipped vs Pulay block 0: a=dCs, a0b0=Vs, b=Cs | ||
| this->lri.data_ab_name[Label::ab::a] = dC; | ||
| this->lri.data_ab_name[Label::ab::a0b0] = "Vs_" + sfx1; | ||
| this->lri.data_ab_name[Label::ab::b] = "Cs_" + sfx0; | ||
| this->lri.cal_loop3({ Label::ab_ab::a0b0_a1b1, Label::ab_ab::a0b0_a1b2 }, this->dHs_HF[ipos][Apin], -1.0); | ||
| this->lri.cal_loop3({ Label::ab_ab::a0b0_a2b1, Label::ab_ab::a0b0_a2b2 }, this->dHs_HF[ipos][Apin], 1.0); | ||
| // dV part, a1 labels (V a-abf = K): a=Cs, a0b0=dVs, b=Cs | ||
| this->lri.data_ab_name[Label::ab::a] = "Cs_" + sfx0; | ||
| this->lri.data_ab_name[Label::ab::a0b0] = dV; | ||
| this->lri.cal_loop3({ Label::ab_ab::a0b0_a1b1, Label::ab_ab::a0b0_a1b2 }, this->dHs_HF[ipos][Apin], -1.0); | ||
|
|
||
| // ===== b-side (L = Apin): slice Ds by INNER key (TAC.first) ===== | ||
| { | ||
| std::map<TA, std::map<TAC, Tensor<Tdata>>> slice; | ||
| for (const auto& kv : Ds) | ||
| { | ||
| std::map<TAC, Tensor<Tdata>> inner; | ||
| for (const auto& lc : kv.second) | ||
| if (lc.first.first == Apin) | ||
| inner.insert(lc); // shallow | ||
| if (!inner.empty()) | ||
| slice[kv.first] = std::move(inner); | ||
| } | ||
| install_slice(std::move(slice)); | ||
| } | ||
| // dC part, sign-flipped vs Pulay block 1, in b-slot: a=Cs, a0b0=Vs, b=dCs | ||
| this->lri.data_ab_name[Label::ab::a] = "Cs_" + sfx0; | ||
| this->lri.data_ab_name[Label::ab::a0b0] = "Vs_" + sfx1; | ||
| this->lri.data_ab_name[Label::ab::b] = dC; | ||
| this->lri.cal_loop3({ Label::ab_ab::a0b0_a1b1, Label::ab_ab::a0b0_a2b1 }, this->dHs_HF[ipos][Apin], -1.0); | ||
| this->lri.cal_loop3({ Label::ab_ab::a0b0_a1b2, Label::ab_ab::a0b0_a2b2 }, this->dHs_HF[ipos][Apin], 1.0); | ||
| // dV part, b1 labels (V b-abf = L): a=Cs, a0b0=dVs, b=Cs | ||
| this->lri.data_ab_name[Label::ab::a] = "Cs_" + sfx0; | ||
| this->lri.data_ab_name[Label::ab::a0b0] = dV; | ||
| this->lri.data_ab_name[Label::ab::b] = "Cs_" + sfx0; | ||
| this->lri.cal_loop3({ Label::ab_ab::a0b0_a1b1, Label::ab_ab::a0b0_a2b1 }, this->dHs_HF[ipos][Apin], 1.0); | ||
| } | ||
| set_D_slots(Ds_full); // restore the four density-matrix slots | ||
| this->lri.data_pool.erase(tmp); |
| const std::string dC = "dCs_" + std::to_string(ipos) + "_" + save_names_suffix[3]; | ||
| const std::string dV = "dVs_" + std::to_string(ipos) + "_" + save_names_suffix[4]; | ||
| const std::string Ds_full = "Ds_" + save_names_suffix[2]; | ||
| const std::string tmp = "__Exx_HF_Ds_tmp"; |
Contributor
Author
|
Suggestions 2 and 3 about performance are adopted while others are not. |
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.