Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PT2 #26

Open
wants to merge 88 commits into
base: master
Choose a base branch
from
Open

PT2 #26

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
5aa09cf
Confirmed CASCI with Open-Shell (O2 Triplet), added guards around unt…
wavefunction91 Jun 5, 2023
bd1091a
Committing clang-format changes
Jun 5, 2023
b75ff55
Validated Open Shell CASSCF
wavefunction91 Jun 6, 2023
6cfb79a
Minor
wavefunction91 Jun 6, 2023
6a5528e
Adding open-shell logic to ASCI
wavefunction91 Jun 6, 2023
385a5b5
Committing clang-format changes
Jun 7, 2023
5f0eebe
Merge branch 'master' into feature/open_shell
wavefunction91 Jun 13, 2023
1bf63c8
Separate numerator / denominator in ASCI scores to allow for reuse in…
wavefunction91 Aug 16, 2023
f33f0f3
Initial implementation of EN-PT2
wavefunction91 Aug 17, 2023
5e9f7fe
Committing clang-format changes
Aug 17, 2023
b17a823
PT2 works with MPI
wavefunction91 Aug 31, 2023
7a4097e
Start generic wfn implementations
wavefunction91 Sep 6, 2023
5e0ab33
Generic Hamiltonian Generator
wavefunction91 Sep 7, 2023
c9579eb
Refactor HamiltonianGenerator into Base + implementation to encapsula…
wavefunction91 Sep 7, 2023
979b1b0
Refactor source locations for CAS(SCF) utilities
wavefunction91 Sep 8, 2023
bc4ed60
Generic ASCI contributions w/o constraints
wavefunction91 Sep 8, 2023
e17fc9d
First attempt at wfn-generic constraint code
wavefunction91 Sep 8, 2023
e80b9d2
Introduce wavefunction_traits, move most bitset-specific logic into t…
wavefunction91 Sep 11, 2023
3bbd61b
Work on generic constraints, added templates over constraint type
wavefunction91 Sep 11, 2023
e224338
changed wfn_constraint -> alpha_constraint and made appropriate changes
wavefunction91 Sep 13, 2023
0b82008
Merge branch 'feature/pt2' of github.com:wavefunction91/MACIS into fe…
wavefunction91 Sep 13, 2023
e8782cc
Merge 0b82008ec72e137638ff7e4d44be29b7da6ea02f into c103c74fa547a191a…
wavefunction91 Sep 13, 2023
29e8fc8
Committing license headers
Sep 13, 2023
840e80e
Added serious unit tests for constraint generation code + misc consis…
wavefunction91 Sep 22, 2023
4555334
Further generalizations of ASCI constraint code
wavefunction91 Sep 22, 2023
947a351
More generalization of constraint code: removal of most bitset::flip …
wavefunction91 Sep 22, 2023
cebfc4c
Merge branch 'feature/open_shell' into merge/open_shell
wavefunction91 Sep 25, 2023
b033244
Merge branch 'feature/pt2' of github.com:wavefunction91/MACIS into fe…
wavefunction91 Sep 25, 2023
3eb8f13
Committing clang-format changes
Sep 25, 2023
f91ee6b
ASCI nominally works for open shells
wavefunction91 Sep 25, 2023
36fc52d
Fix bugs in UINT128 interfaces
wavefunction91 Oct 2, 2023
a218f73
Fix bug in constraint search + pruning
wavefunction91 Oct 2, 2023
e5e99d4
Committing clang-format changes
Oct 3, 2023
a43e254
Cleanup of bitset operations + UTs, extension of more functions to la…
wavefunction91 Oct 5, 2023
1fc06d4
Merge branch 'feature/pt2' of github.com:wavefunction91/MACIS into fe…
wavefunction91 Oct 5, 2023
8ae7f33
Committing clang-format changes
Oct 5, 2023
0fd26cd
Added SortedDoubleLoop + required sparsexx functions and UTs, correct…
wavefunction91 Oct 10, 2023
2bb0cf0
Fixed bug in COO -> CSR conversion when rows are empty, added UTs for…
wavefunction91 Oct 12, 2023
8a65301
Exploit Hamiltonian symmetry for diagonal blocks
wavefunction91 Oct 13, 2023
73e08ac
Adding more print, found potential hang for large determinant counts …
wavefunction91 Oct 13, 2023
3b2ed25
Accelerate PT2 based on the assumption that the wave function is alph…
wavefunction91 Oct 20, 2023
4db310e
Propagate PT2 improvements to ASCI search, refactor KEEP_LARGEST to u…
wavefunction91 Oct 20, 2023
5fbc8f6
Print NPT2
wavefunction91 Oct 20, 2023
43488f2
Improve load balancer by passing beta degeneracy to constraint distri…
wavefunction91 Oct 20, 2023
3d21260
Refactor dist_constraint_gen into separate generation + distribution …
wavefunction91 Oct 30, 2023
12cb760
Committing clang-format changes
Oct 30, 2023
e068dc5
Various config fixes
wavefunction91 Oct 30, 2023
7bdec40
Start TREXIO integration
wavefunction91 Oct 30, 2023
54b7258
Merge branch 'feature/pt2' of github.com:wavefunction91/MACIS into fe…
wavefunction91 Oct 30, 2023
ddb59ed
Merge branch 'feature/pt2' of github.com:wavefunction91/MACIS into fe…
wavefunction91 Oct 30, 2023
f35d5b2
Merge branch 'feature/pt2' of github.com:wavefunction91/MACIS into fe…
wavefunction91 Oct 30, 2023
17c5abe
Committing clang-format changes
Oct 30, 2023
c0416eb
Enable MPI+OpenMP in PT2
wavefunction91 Oct 31, 2023
342f81a
Merge branch 'feature/pt2' of github.com:wavefunction91/MACIS into fe…
wavefunction91 Oct 31, 2023
a407a1a
Committing clang-format changes
Oct 31, 2023
65caa18
Merge branch 'feature/pt2' of github.com:wavefunction91/MACIS into fe…
wavefunction91 Oct 31, 2023
5e5b03d
Add TREXIO interface + FCIDUMP converter. Integrated into Standalone …
wavefunction91 Nov 2, 2023
2831b59
Add OpenMP to SortedDoubleLoop Hamiltonian Generation
wavefunction91 Nov 2, 2023
4274499
Refactored NXTVAL functionality into a proper C++ type (global_atomic)
wavefunction91 Nov 2, 2023
d0809f7
Minor cleanup
wavefunction91 Nov 3, 2023
3a61cbd
Merge d0809f70efa89ac03633e5724e2bd5c22d9e41f7 into c103c74fa547a191a…
wavefunction91 Nov 3, 2023
4773a17
Committing license headers
Nov 3, 2023
6521725
Add MPI+OpenMP (+NXTVAL) to ASCI search, lift some index restrictions…
wavefunction91 Nov 3, 2023
a9a0208
Add preallocation for thread insetion in ASCI search, misc print impr…
wavefunction91 Nov 6, 2023
f249eee
Started TREXIO wfn IO, not fully tested
wavefunction91 Nov 6, 2023
b6f9e54
Committing clang-format changes
Nov 6, 2023
9109b59
Misc QOL
wavefunction91 Nov 7, 2023
ef9ad88
Bump default bit width to 256 for current test cases
wavefunction91 Nov 9, 2023
82285a2
Committing clang-format changes
Nov 9, 2023
105b973
improve insertion performance in SortedDoubleLoop
wavefunction91 Nov 9, 2023
f6a2270
Merge branch 'feature/pt2' of github.com:wavefunction91/MACIS into fe…
wavefunction91 Nov 9, 2023
3e586dc
Committing clang-format changes
Nov 9, 2023
7514991
Added Olsen correction for Davidson
wavefunction91 Nov 9, 2023
da4030b
Merge branch 'feature/pt2' of github.com:wavefunction91/MACIS into fe…
wavefunction91 Nov 9, 2023
ee037ac
Fix bug in COO -> CSR
wavefunction91 Nov 12, 2023
139e789
Added OpenMP to constraint generation
wavefunction91 Nov 13, 2023
17e9265
adding safeguards to PT2 - avoid precomputation of orbital energies t…
wavefunction91 Nov 14, 2023
d868a9e
Expose additional PT2 options, refactor sort_and_accumulate, add coef…
wavefunction91 Nov 14, 2023
fc5acc4
Add big/small constraint seapration to PT2, accelerate case when alph…
wavefunction91 Nov 15, 2023
8d6fd71
Added print to show % of wfn in core dets in ASCI search
wavefunction91 Nov 15, 2023
d7c0d6a
Make NXTVAL + B/S configuration cutoff in PT2 configurable
wavefunction91 Nov 15, 2023
9f409f7
Major fixes
wavefunction91 Nov 18, 2023
fe6948b
Add option to selectively force refinement of top constraints
wavefunction91 Nov 20, 2023
05d6390
Committing clang-format changes
Nov 21, 2023
6fadd7a
Revert "Committing clang-format changes"
wavefunction91 Nov 23, 2023
cecc6eb
Add pruning back to search
wavefunction91 Dec 4, 2023
9d7d51d
Committing clang-format changes
Dec 4, 2023
d3c351f
Add Hamiltonian output as an option
wavefunction91 Jul 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ project(MACIS VERSION 0.1 LANGUAGES C CXX)
option( MACIS_ENABLE_MPI "Enable MPI Bindings" ON )
option( MACIS_ENABLE_OPENMP "Enable OpenMP Bindings" ON )
option( MACIS_ENABLE_BOOST "Enable Boost" ON )
option( MACIS_ENABLE_TREXIO "Enable TrexIO" ON )

# CMake Modules
list( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake )
Expand Down
82 changes: 82 additions & 0 deletions include/macis/asci/alpha_constraint.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* MACIS Copyright (c) 2023, The Regents of the University of California,
* through Lawrence Berkeley National Laboratory (subject to receipt of
* any required approvals from the U.S. Dept. of Energy). All rights reserved.
*
* See LICENSE.txt for details
*/

#pragma once

#include <macis/wfn/raw_bitset.hpp>
namespace macis {

template <typename WfnTraits>
class alpha_constraint {
public:
using wfn_traits = WfnTraits;
using wfn_type = typename WfnTraits::wfn_type;
using spin_wfn_type = spin_wfn_t<wfn_type>;

using constraint_type = spin_wfn_type;
using constraint_traits = wavefunction_traits<spin_wfn_type>;

private:
constraint_type C_;
constraint_type B_;
uint32_t C_min_;
uint32_t count_;

public:
alpha_constraint(constraint_type C, constraint_type B, uint32_t C_min)
: C_(C), B_(B), C_min_(C_min), count_(constraint_traits::count(C)) {}

alpha_constraint(const alpha_constraint&) = default;
alpha_constraint& operator=(const alpha_constraint&) = default;

alpha_constraint(alpha_constraint&& other) noexcept = default;
alpha_constraint& operator=(alpha_constraint&&) noexcept = default;

inline auto C() const { return C_; }
inline auto B() const { return B_; }
inline auto C_min() const { return C_min_; }
inline auto count() const { return count_; }

inline spin_wfn_type c_mask_union(spin_wfn_type state) const {
return state & C_;
}
inline spin_wfn_type b_mask_union(spin_wfn_type state) const {
return state & B_;
}

inline spin_wfn_type symmetric_difference(spin_wfn_type state) const {
return state ^ C_;
}
// inline spin_wfn_type symmetric_difference(wfn_type state) const {
// return symmetric_difference(wfn_traits::alpha_string(state));
// }

template <typename WfnType>
inline auto overlap(WfnType state) const {
return constraint_traits::count(c_mask_union(state));
}

template <typename WfnType>
inline bool satisfies_constraint(WfnType state) const {
return overlap(state) == count_ and
constraint_traits::count(symmetric_difference(state) >> C_min_) == 0;
}

static alpha_constraint make_triplet(unsigned i, unsigned j, unsigned k) {
constraint_type C = 0;
C.flip(i).flip(j).flip(k);
// constraint_type B = 1;
// static_assert(B.size() <= 64, "ULLONG NOT POSSIBLE HERE");
// B <<= k;
// B = B.to_ullong() - 1;
constraint_type B = full_mask<B.size()>(k);
return alpha_constraint(C, B, k);
}
};

} // namespace macis
91 changes: 61 additions & 30 deletions include/macis/asci/determinant_contributions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,27 @@ namespace macis {
template <typename WfnT>
struct asci_contrib {
WfnT state;
double rv;
double c_times_matel;
double h_diag;

auto rv() const { return c_times_matel / h_diag; }
auto pt2() const { return rv() * c_times_matel; }
};

template <typename WfnT>
using asci_contrib_container = std::vector<asci_contrib<WfnT>>;

template <size_t N, size_t NShift>
template <Spin Sigma, typename WfnType, typename SpinWfnType>
void append_singles_asci_contributions(
double coeff, wfn_t<2 * N> state_full, wfn_t<N> state_same,
double coeff, WfnType state_full, SpinWfnType state_same,
const std::vector<uint32_t>& occ_same,
const std::vector<uint32_t>& vir_same,
const std::vector<uint32_t>& occ_othr, const double* eps_same,
const double* T_pq, const size_t LDT, const double* G_kpq, const size_t LDG,
const double* V_kpq, const size_t LDV, double h_el_tol, double root_diag,
double E0, HamiltonianGenerator<2 * N>& ham_gen,
asci_contrib_container<wfn_t<2 * N>>& asci_contributions) {
double E0, const HamiltonianGeneratorBase<double>& ham_gen,
asci_contrib_container<WfnType>& asci_contributions) {
using wfn_traits = wavefunction_traits<WfnType>;
const auto LDG2 = LDG * LDG;
const auto LDV2 = LDV * LDV;
for(auto i : occ_same)
Expand All @@ -44,11 +49,11 @@ void append_singles_asci_contributions(
for(auto p : occ_othr) h_el += V_ov[p];

// Early Exit
if(std::abs(h_el) < h_el_tol) continue;
if(std::abs(coeff * h_el) < h_el_tol) continue;

// Calculate Excited Determinant
auto ex_det = state_full;
ex_det.flip(i + NShift).flip(a + NShift);
auto ex_det = wfn_traits::template single_excitation_no_check<Sigma>(
state_full, i, a);

// Calculate Excitation Sign in a Canonical Way
auto sign = single_excitation_sign(state_same, a, i);
Expand All @@ -57,22 +62,25 @@ 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});
asci_contributions.push_back({ex_det, coeff * h_el, E0 - h_diag});

} // Loop over single extitations
}

template <size_t N, size_t NShift>
template <Spin Sigma, typename WfnType, typename SpinWfnType>
void append_ss_doubles_asci_contributions(
double coeff, wfn_t<2 * N> state_full, wfn_t<N> state_spin,
const std::vector<uint32_t>& ss_occ, const std::vector<uint32_t>& vir,
const std::vector<uint32_t>& os_occ, const double* eps_same,
const double* G, size_t LDG, double h_el_tol, double root_diag, double E0,
HamiltonianGenerator<2 * N>& ham_gen,
asci_contrib_container<wfn_t<2 * N>>& asci_contributions) {
double coeff, WfnType state_full, SpinWfnType state_same,
SpinWfnType state_other, const std::vector<uint32_t>& ss_occ,
const std::vector<uint32_t>& vir, const std::vector<uint32_t>& os_occ,
const double* eps_same, const double* G, size_t LDG, double h_el_tol,
double root_diag, double E0,
const HamiltonianGeneratorBase<double>& ham_gen,
asci_contrib_container<WfnType>& asci_contributions) {
using wfn_traits = wavefunction_traits<WfnType>;
using spin_wfn_traits = wavefunction_traits<SpinWfnType>;
const size_t nocc = ss_occ.size();
const size_t nvir = vir.size();

Expand All @@ -90,8 +98,9 @@ void append_ss_doubles_asci_contributions(
const auto jb = b + j * LDG;
const auto G_aibj = G_ai[jb];

if(std::abs(G_aibj) < h_el_tol) continue;
if(std::abs(coeff * G_aibj) < h_el_tol) continue;

#if 0
// Calculate excited determinant string (spin)
const auto full_ex_spin = wfn_t<N>(0).flip(i).flip(j).flip(a).flip(b);
auto ex_det_spin = state_spin ^ full_ex_spin;
Expand All @@ -102,6 +111,21 @@ void append_ss_doubles_asci_contributions(
// Calculate full excited determinant
const auto full_ex = expand_bitset<2 * N>(full_ex_spin) << NShift;
auto ex_det = state_full ^ full_ex;
#else
// TODO: Can this be made faster since the orbital indices are known
// in advance?
// Compute excited determinant (spin)
const auto full_ex_spin = spin_wfn_traits::double_excitation_no_check(
SpinWfnType(0), i, j, a, b);
const auto ex_det_spin = state_same ^ full_ex_spin;

// Calculate the sign in a canonical way
double sign = doubles_sign(state_same, ex_det_spin, full_ex_spin);

// Calculate full excited determinant
auto ex_det =
wfn_traits::template from_spin<Sigma>(ex_det_spin, state_other);
#endif

// Update sign of matrix element
auto h_el = sign * G_aibj;
Expand All @@ -110,25 +134,27 @@ 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});
asci_contributions.push_back({ex_det, coeff * h_el, E0 - h_diag});

} // Restricted BJ loop
} // AI Loop
}

template <size_t N>
template <typename WfnType, typename SpinWfnType>
void append_os_doubles_asci_contributions(
double coeff, wfn_t<2 * N> state_full, wfn_t<N> state_alpha,
wfn_t<N> state_beta, const std::vector<uint32_t>& occ_alpha,
double coeff, WfnType state_full, SpinWfnType state_alpha,
SpinWfnType state_beta, const std::vector<uint32_t>& occ_alpha,
const std::vector<uint32_t>& occ_beta,
const std::vector<uint32_t>& vir_alpha,
const std::vector<uint32_t>& vir_beta, const double* eps_alpha,
const double* eps_beta, const double* V, size_t LDV, double h_el_tol,
double root_diag, double E0, HamiltonianGenerator<2 * N>& ham_gen,
asci_contrib_container<wfn_t<2 * N>>& asci_contributions) {
double root_diag, double E0,
const HamiltonianGeneratorBase<double>& ham_gen,
asci_contrib_container<WfnType>& asci_contributions) {
using wfn_traits = wavefunction_traits<WfnType>;
const size_t LDV2 = LDV * LDV;
for(auto i : occ_alpha)
for(auto a : vir_alpha) {
Expand All @@ -140,21 +166,26 @@ void append_os_doubles_asci_contributions(
const auto jb = b + j * LDV;
const auto V_aibj = V_ai[jb * LDV2];

if(std::abs(V_aibj) < h_el_tol) continue;
if(std::abs(coeff * V_aibj) < h_el_tol) continue;

double sign_beta = single_excitation_sign(state_beta, b, j);
double sign = sign_alpha * sign_beta;
auto ex_det = state_full;
ex_det.flip(a).flip(i).flip(j + N).flip(b + N);
// auto ex_det = state_full;
// ex_det.flip(a).flip(i).flip(j + N).flip(b + N);
auto ex_det =
wfn_traits::template single_excitation_no_check<Spin::Alpha>(
state_full, a, i);
ex_det = wfn_traits::template single_excitation_no_check<Spin::Beta>(
ex_det, b, j);
auto h_el = sign * V_aibj;

// Evaluate fast diagonal element
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});
asci_contributions.push_back({ex_det, coeff * h_el, E0 - h_diag});
} // BJ loop
} // AI loop
}
Expand Down
Loading
Loading