From 5e9f7fe503d4826b6af9ae68701d12cc9dc28ab7 Mon Sep 17 00:00:00 2001 From: Clang Robot Date: Thu, 17 Aug 2023 00:43:03 +0000 Subject: [PATCH] Committing clang-format changes --- .../macis/asci/determinant_contributions.hpp | 8 +- include/macis/asci/determinant_search.hpp | 2 +- include/macis/asci/determinant_sort.hpp | 3 +- include/macis/asci/mask_constraints.hpp | 10 +- include/macis/asci/pt2.hpp | 219 +++++++++--------- tests/standalone_driver.cxx | 12 +- 6 files changed, 128 insertions(+), 126 deletions(-) diff --git a/include/macis/asci/determinant_contributions.hpp b/include/macis/asci/determinant_contributions.hpp index 041979bb..759fea05 100644 --- a/include/macis/asci/determinant_contributions.hpp +++ b/include/macis/asci/determinant_contributions.hpp @@ -18,7 +18,7 @@ struct asci_contrib { WfnT state; double c_times_matel; double h_diag; - + auto rv() const { return c_times_matel / h_diag; } }; @@ -60,7 +60,7 @@ void append_singles_asci_contributions( // Calculate fast diagonal matrix element auto h_diag = ham_gen.fast_diag_single(eps_same[i], eps_same[a], i, a, root_diag); - //h_el /= (E0 - h_diag); + // h_el /= (E0 - h_diag); // Append to return values asci_contributions.push_back({ex_det, coeff * h_el, E0 - h_diag}); @@ -113,7 +113,7 @@ void append_ss_doubles_asci_contributions( auto h_diag = ham_gen.fast_diag_ss_double(eps_same[i], eps_same[j], eps_same[a], eps_same[b], i, j, a, b, root_diag); - //h_el /= (E0 - h_diag); + // h_el /= (E0 - h_diag); // Append {det, c*h_el} asci_contributions.push_back({ex_det, coeff * h_el, E0 - h_diag}); @@ -155,7 +155,7 @@ void append_os_doubles_asci_contributions( auto h_diag = ham_gen.fast_diag_os_double(eps_alpha[i], eps_beta[j], eps_alpha[a], eps_beta[b], i, j, a, b, root_diag); - //h_el /= (E0 - h_diag); + // h_el /= (E0 - h_diag); asci_contributions.push_back({ex_det, coeff * h_el, E0 - h_diag}); } // BJ loop diff --git a/include/macis/asci/determinant_search.hpp b/include/macis/asci/determinant_search.hpp index 03cc9b9d..c3c4fec2 100644 --- a/include/macis/asci/determinant_search.hpp +++ b/include/macis/asci/determinant_search.hpp @@ -529,7 +529,7 @@ std::vector> asci_search( // Finalize scores for(auto& x : asci_pairs) { x.c_times_matel = -std::abs(x.c_times_matel); - x.h_diag = std::abs(x.h_diag); + x.h_diag = std::abs(x.h_diag); } // Insert all dets with their coefficients as seeds diff --git a/include/macis/asci/determinant_sort.hpp b/include/macis/asci/determinant_sort.hpp index 9d37ce18..25de9878 100644 --- a/include/macis/asci/determinant_sort.hpp +++ b/include/macis/asci/determinant_sort.hpp @@ -108,7 +108,8 @@ void keep_only_largest_copy_asci_pairs( // Keep only max value else { - cur_it->c_times_matel = std::max(cur_it->c_times_matel, it->c_times_matel); + cur_it->c_times_matel = + std::max(cur_it->c_times_matel, it->c_times_matel); } } diff --git a/include/macis/asci/mask_constraints.hpp b/include/macis/asci/mask_constraints.hpp index 5430b00b..bf522f26 100644 --- a/include/macis/asci/mask_constraints.hpp +++ b/include/macis/asci/mask_constraints.hpp @@ -258,11 +258,11 @@ void generate_constraint_singles_contributions_ss( const size_t LDV2 = LDV * LDV; for(int ii = 0; ii < no; ++ii) { const auto i = fls(o); - o.flip(i); // Disable "i"-bit so it's not used in FLS next iteration + o.flip(i); // Disable "i"-bit so it's not used in FLS next iteration auto v_cpy = v; for(int aa = 0; aa < nv; ++aa) { const auto a = fls(v_cpy); - v_cpy.flip(a); // Disable "a"-bit so it's not used in FLS next iteration + v_cpy.flip(a); // Disable "a"-bit so it's not used in FLS next iteration double h_el = T_pq[a + i * LDT]; const double* G_ov = G_kpq + a * LDG + i * LDG2; @@ -283,7 +283,7 @@ void generate_constraint_singles_contributions_ss( // Compute Fast Diagonal Matrix Element auto h_diag = ham_gen.fast_diag_single(eps[i], eps[a], i, a, root_diag); - //h_el /= (E0 - h_diag); + // h_el /= (E0 - h_diag); asci_contributions.push_back({ex_det, coeff * h_el, E0 - h_diag}); } @@ -336,7 +336,7 @@ void generate_constraint_doubles_contributions_ss( // Evaluate fast diagonal matrix element auto h_diag = ham_gen.fast_diag_ss_double(eps[i], eps[j], eps[a], eps[b], i, j, a, b, root_diag); - //h_el /= (E0 - h_diag); + // h_el /= (E0 - h_diag); asci_contributions.push_back({full_ex, coeff * h_el, E0 - h_diag}); } @@ -394,7 +394,7 @@ void generate_constraint_doubles_contributions_os( auto h_diag = ham_gen.fast_diag_os_double(eps_same[i], eps_othr[j], eps_same[a], eps_othr[b], i, j, a, b, root_diag); - //h_el /= (E0 - h_diag); + // h_el /= (E0 - h_diag); asci_contributions.push_back({ex_det, coeff * h_el, E0 - h_diag}); } // BJ diff --git a/include/macis/asci/pt2.hpp b/include/macis/asci/pt2.hpp index 76a48132..8ef19245 100644 --- a/include/macis/asci/pt2.hpp +++ b/include/macis/asci/pt2.hpp @@ -12,21 +12,20 @@ namespace macis { - template -double asci_pt2_constraint( - wavefunction_iterator_t cdets_begin, wavefunction_iterator_t cdets_end, - const double E_ASCI, const std::vector& C, size_t norb, - const double* T_pq, const double* G_red, const double* V_red, - const double* G_pqrs, const double* V_pqrs, HamiltonianGenerator& ham_gen, - MPI_Comm comm) { - +double asci_pt2_constraint(wavefunction_iterator_t cdets_begin, + wavefunction_iterator_t cdets_end, + const double E_ASCI, const std::vector& C, + size_t norb, const double* T_pq, const double* G_red, + const double* V_red, const double* G_pqrs, + const double* V_pqrs, + HamiltonianGenerator& ham_gen, MPI_Comm comm) { using clock_type = std::chrono::high_resolution_clock; using duration_type = std::chrono::duration; auto logger = spdlog::get("asci_search"); const size_t ncdets = std::distance(cdets_begin, cdets_end); - std::cout << "NDETS PT = " << ncdets << " " << C.size() << std::endl; + std::cout << "NDETS PT = " << ncdets << " " << C.size() << std::endl; std::cout << "PT E0 = " << E_ASCI << std::endl; std::vector occ_alpha, vir_alpha; @@ -105,9 +104,8 @@ double asci_pt2_constraint( logger->info(" * NS = {} ND = {}", n_sing_alpha, n_doub_alpha); auto gen_c_st = clock_type::now(); - auto constraints = - dist_constraint_general(0, norb, - n_sing_alpha, n_doub_alpha, uniq_alpha_wfn, comm); + auto constraints = dist_constraint_general( + 0, norb, n_sing_alpha, n_doub_alpha, uniq_alpha_wfn, comm); auto gen_c_en = clock_type::now(); duration_type gen_c_dur = gen_c_en - gen_c_st; logger->info(" * GEN_DUR = {:.2e} ms", gen_c_dur.count()); @@ -119,113 +117,116 @@ double asci_pt2_constraint( )); double EPT2 = 0.0; - // Process ASCI pair contributions for each constraint - #pragma omp parallel +// Process ASCI pair contributions for each constraint +#pragma omp parallel { - asci_contrib_container> asci_pairs; - asci_pairs.reserve(max_size); - #pragma omp for reduction(+:EPT2) - for(size_t ic = 0; ic < constraints.size(); ++ic) { - const auto& con = constraints[ic]; - //std::cout << std::distance(&constraints[0], &con) << "/" << constraints.size() << std::endl; - const double h_el_tol = 1e-16; - const auto& [C, B, C_min] = con; - wfn_t O = full_mask(norb); - - // Loop over unique alpha strings - for(size_t i_alpha = 0; i_alpha < nuniq_alpha; ++i_alpha) { - const auto& det = uniq_alpha_wfn[i_alpha]; - const auto occ_alpha = bits_to_indices(det); - - // AA excitations - for(const auto& bcd : uad[i_alpha].bcd) { - const auto& beta = bcd.beta_string; - const auto& coeff = bcd.coeff; - const auto& h_diag = bcd.h_diag; - const auto& occ_beta = bcd.occ_beta; - const auto& orb_ens_alpha = bcd.orb_ens_alpha; - generate_constraint_singles_contributions_ss( - coeff, det, C, O, B, beta, occ_alpha, occ_beta, - orb_ens_alpha.data(), T_pq, norb, G_red, norb, V_red, norb, - h_el_tol, h_diag, E_ASCI, ham_gen, asci_pairs); - } - - // AAAA excitations - for(const auto& bcd : uad[i_alpha].bcd) { - const auto& beta = bcd.beta_string; - const auto& coeff = bcd.coeff; - const auto& h_diag = bcd.h_diag; - const auto& occ_beta = bcd.occ_beta; - const auto& orb_ens_alpha = bcd.orb_ens_alpha; - generate_constraint_doubles_contributions_ss( - coeff, det, C, O, B, beta, occ_alpha, occ_beta, - orb_ens_alpha.data(), G_pqrs, norb, h_el_tol, h_diag, E_ASCI, - ham_gen, asci_pairs); - } - - // AABB excitations - for(const auto& bcd : uad[i_alpha].bcd) { - const auto& beta = bcd.beta_string; - const auto& coeff = bcd.coeff; - const auto& h_diag = bcd.h_diag; - const auto& occ_beta = bcd.occ_beta; - const auto& vir_beta = bcd.vir_beta; - const auto& orb_ens_alpha = bcd.orb_ens_alpha; - const auto& orb_ens_beta = bcd.orb_ens_beta; - generate_constraint_doubles_contributions_os( - coeff, det, C, O, B, beta, occ_alpha, occ_beta, vir_beta, - orb_ens_alpha.data(), orb_ens_beta.data(), V_pqrs, norb, h_el_tol, - h_diag, E_ASCI, ham_gen, asci_pairs); - } - - // If the alpha determinant satisfies the constraint, - // append BB and BBBB excitations - if(satisfies_constraint(det, C, C_min)) { + asci_contrib_container> asci_pairs; + asci_pairs.reserve(max_size); +#pragma omp for reduction(+ : EPT2) + for(size_t ic = 0; ic < constraints.size(); ++ic) { + const auto& con = constraints[ic]; + // std::cout << std::distance(&constraints[0], &con) << "/" << + // constraints.size() << std::endl; + const double h_el_tol = 1e-16; + const auto& [C, B, C_min] = con; + wfn_t O = full_mask(norb); + + // Loop over unique alpha strings + for(size_t i_alpha = 0; i_alpha < nuniq_alpha; ++i_alpha) { + const auto& det = uniq_alpha_wfn[i_alpha]; + const auto occ_alpha = bits_to_indices(det); + + // AA excitations + for(const auto& bcd : uad[i_alpha].bcd) { + const auto& beta = bcd.beta_string; + const auto& coeff = bcd.coeff; + const auto& h_diag = bcd.h_diag; + const auto& occ_beta = bcd.occ_beta; + const auto& orb_ens_alpha = bcd.orb_ens_alpha; + generate_constraint_singles_contributions_ss( + coeff, det, C, O, B, beta, occ_alpha, occ_beta, + orb_ens_alpha.data(), T_pq, norb, G_red, norb, V_red, norb, + h_el_tol, h_diag, E_ASCI, ham_gen, asci_pairs); + } + + // AAAA excitations + for(const auto& bcd : uad[i_alpha].bcd) { + const auto& beta = bcd.beta_string; + const auto& coeff = bcd.coeff; + const auto& h_diag = bcd.h_diag; + const auto& occ_beta = bcd.occ_beta; + const auto& orb_ens_alpha = bcd.orb_ens_alpha; + generate_constraint_doubles_contributions_ss( + coeff, det, C, O, B, beta, occ_alpha, occ_beta, + orb_ens_alpha.data(), G_pqrs, norb, h_el_tol, h_diag, E_ASCI, + ham_gen, asci_pairs); + } + + // AABB excitations for(const auto& bcd : uad[i_alpha].bcd) { const auto& beta = bcd.beta_string; const auto& coeff = bcd.coeff; const auto& h_diag = bcd.h_diag; const auto& occ_beta = bcd.occ_beta; const auto& vir_beta = bcd.vir_beta; - const auto& eps_beta = bcd.orb_ens_beta; - - const auto state = det | beta; - const auto state_beta = bitset_hi_word(beta); - // BB Excitations - append_singles_asci_contributions<(N / 2), (N / 2)>( - coeff, state, state_beta, occ_beta, vir_beta, occ_alpha, - eps_beta.data(), T_pq, norb, G_red, norb, V_red, norb, h_el_tol, + const auto& orb_ens_alpha = bcd.orb_ens_alpha; + const auto& orb_ens_beta = bcd.orb_ens_beta; + generate_constraint_doubles_contributions_os( + coeff, det, C, O, B, beta, occ_alpha, occ_beta, vir_beta, + orb_ens_alpha.data(), orb_ens_beta.data(), V_pqrs, norb, h_el_tol, h_diag, E_ASCI, ham_gen, asci_pairs); + } + + // If the alpha determinant satisfies the constraint, + // append BB and BBBB excitations + if(satisfies_constraint(det, C, C_min)) { + for(const auto& bcd : uad[i_alpha].bcd) { + const auto& beta = bcd.beta_string; + const auto& coeff = bcd.coeff; + const auto& h_diag = bcd.h_diag; + const auto& occ_beta = bcd.occ_beta; + const auto& vir_beta = bcd.vir_beta; + const auto& eps_beta = bcd.orb_ens_beta; + + const auto state = det | beta; + const auto state_beta = bitset_hi_word(beta); + // BB Excitations + append_singles_asci_contributions<(N / 2), (N / 2)>( + coeff, state, state_beta, occ_beta, vir_beta, occ_alpha, + eps_beta.data(), T_pq, norb, G_red, norb, V_red, norb, h_el_tol, + h_diag, E_ASCI, ham_gen, asci_pairs); + + // BBBB Excitations + append_ss_doubles_asci_contributions( + coeff, state, state_beta, occ_beta, vir_beta, occ_alpha, + eps_beta.data(), G_pqrs, norb, h_el_tol, h_diag, E_ASCI, + ham_gen, asci_pairs); + + // No excition - to remove for PT2 + asci_pairs.push_back( + {state, std::numeric_limits::infinity(), 1.0}); + } // Beta Loop + } // Triplet Check + + } // Unique Alpha Loop + + double EPT2_local = 0.0; + // Local S&A for each quad + update EPT2 + { + auto uit = sort_and_accumulate_asci_pairs(asci_pairs.begin(), + asci_pairs.end()); + for(auto it = asci_pairs.begin(); it != uit; ++it) { + // if(std::find(cdets_begin, cdets_end, it->state) == cdets_end) + if(!std::isinf(it->c_times_matel)) + EPT2_local += (it->c_times_matel * it->c_times_matel) / it->h_diag; + } + asci_pairs.clear(); + } - // BBBB Excitations - append_ss_doubles_asci_contributions( - coeff, state, state_beta, occ_beta, vir_beta, occ_alpha, - eps_beta.data(), G_pqrs, norb, h_el_tol, h_diag, E_ASCI, ham_gen, - asci_pairs); - - // No excition - to remove for PT2 - asci_pairs.push_back({state, std::numeric_limits::infinity(), 1.0}); - } // Beta Loop - } // Triplet Check - - } // Unique Alpha Loop - - double EPT2_local = 0.0; - // Local S&A for each quad + update EPT2 - { - auto uit = sort_and_accumulate_asci_pairs(asci_pairs.begin(), asci_pairs.end()); - for(auto it = asci_pairs.begin(); it != uit; ++it) { - //if(std::find(cdets_begin, cdets_end, it->state) == cdets_end) - if(!std::isinf(it->c_times_matel)) - EPT2_local += (it->c_times_matel * it->c_times_matel) / it->h_diag; - } - asci_pairs.clear(); - } - - EPT2 += EPT2_local; - } // Constraint Loop + EPT2 += EPT2_local; + } // Constraint Loop } return EPT2; } -} +} // namespace macis diff --git a/tests/standalone_driver.cxx b/tests/standalone_driver.cxx index 8ce5cfe8..c00f497d 100644 --- a/tests/standalone_driver.cxx +++ b/tests/standalone_driver.cxx @@ -15,8 +15,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -382,9 +382,10 @@ int main(int argc, char** argv) { } #endif if(pt2) { - EPT2 = macis::asci_pt2_constraint( dets.begin(), dets.end(), E0 -(E_inactive + E_core), C, n_active, - ham_gen.T(), ham_gen.G_red(), ham_gen.V_red(),ham_gen.G(), ham_gen.V(), - ham_gen MACIS_MPI_CODE(, MPI_COMM_WORLD)); + EPT2 = macis::asci_pt2_constraint( + dets.begin(), dets.end(), E0 - (E_inactive + E_core), C, n_active, + ham_gen.T(), ham_gen.G_red(), ham_gen.V_red(), ham_gen.G(), + ham_gen.V(), ham_gen MACIS_MPI_CODE(, MPI_COMM_WORLD)); } } @@ -395,8 +396,7 @@ int main(int argc, char** argv) { console->info("E(CI+PT2) = {:.12f} Eh", E0 + EPT2); } - - // MCSCF + // MCSCF } else if(job == Job::MCSCF) { // Possibly read active RDMs if(rdm_fname.size()) {