Skip to content

Commit

Permalink
Committing clang-format changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Clang Robot committed Aug 17, 2023
1 parent f33f0f3 commit 5e9f7fe
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 126 deletions.
8 changes: 4 additions & 4 deletions include/macis/asci/determinant_contributions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
};

Expand Down Expand Up @@ -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});
Expand Down Expand Up @@ -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});
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/macis/asci/determinant_search.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ std::vector<wfn_t<N>> 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
Expand Down
3 changes: 2 additions & 1 deletion include/macis/asci/determinant_sort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
10 changes: 5 additions & 5 deletions include/macis/asci/mask_constraints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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});
}
Expand Down Expand Up @@ -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});
}
Expand Down Expand Up @@ -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
Expand Down
219 changes: 110 additions & 109 deletions include/macis/asci/pt2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@

namespace macis {


template <size_t N>
double asci_pt2_constraint(
wavefunction_iterator_t<N> cdets_begin, wavefunction_iterator_t<N> cdets_end,
const double E_ASCI, const std::vector<double>& 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<N>& ham_gen,
MPI_Comm comm) {

double asci_pt2_constraint(wavefunction_iterator_t<N> cdets_begin,
wavefunction_iterator_t<N> cdets_end,
const double E_ASCI, const std::vector<double>& 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<N>& ham_gen, MPI_Comm comm) {
using clock_type = std::chrono::high_resolution_clock;
using duration_type = std::chrono::duration<double, std::milli>;

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<uint32_t> occ_alpha, vir_alpha;
Expand Down Expand Up @@ -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());
Expand All @@ -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<wfn_t<N>> 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<N> O = full_mask<N>(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<wfn_t<N>> 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<N> O = full_mask<N>(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<N / 2, N / 2>(
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<double>::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<N / 2, N / 2>(
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<double>::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
12 changes: 6 additions & 6 deletions tests/standalone_driver.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include <iomanip>
#include <iostream>
#include <macis/asci/grow.hpp>
#include <macis/asci/refine.hpp>
#include <macis/asci/pt2.hpp>
#include <macis/asci/refine.hpp>
#include <macis/hamiltonian_generator/double_loop.hpp>
#include <macis/util/cas.hpp>
#include <macis/util/detail/rdm_files.hpp>
Expand Down Expand Up @@ -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));
}
}

Expand All @@ -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()) {
Expand Down

0 comments on commit 5e9f7fe

Please sign in to comment.