-
Notifications
You must be signed in to change notification settings - Fork 31
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
FCI and GENCI initial core guess determinants for Davidson-Liu solver #377
base: main
Are you sure you want to change the base?
Changes from 14 commits
f7e0344
60b7d8e
e891a28
96e970b
bcf73ed
5c1656a
8a947a1
901d81a
1fbb90f
759b538
bb1db16
a51f901
992fab9
4f81d37
e2af024
814d664
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,9 +39,9 @@ namespace forte { | |
|
||
StateInfo::StateInfo(int na, int nb, int multiplicity, int twice_ms, int irrep, | ||
const std::string& irrep_label, const std::vector<size_t> gas_min, | ||
const std::vector<size_t> gas_max) | ||
const std::vector<size_t> gas_max, bool core_guess) | ||
: na_(na), nb_(nb), multiplicity_(multiplicity), twice_ms_(twice_ms), irrep_(irrep), | ||
irrep_label_(irrep_label), gas_min_(gas_min), gas_max_(gas_max) {} | ||
irrep_label_(irrep_label), gas_min_(gas_min), gas_max_(gas_max), core_guess_(core_guess) {} | ||
|
||
const std::vector<std::string> StateInfo::multiplicity_labels{ | ||
"Singlet", "Doublet", "Triplet", "Quartet", "Quintet", "Sextet", "Septet", "Octet", | ||
|
@@ -58,6 +58,8 @@ int StateInfo::twice_ms() const { return twice_ms_; } | |
|
||
int StateInfo::irrep() const { return irrep_; } | ||
|
||
bool StateInfo::core_guess() const { return core_guess_; } | ||
|
||
const std::string& StateInfo::irrep_label() const { return irrep_label_; } | ||
|
||
const std::string& StateInfo::multiplicity_label() const { | ||
|
@@ -71,8 +73,8 @@ const std::vector<size_t>& StateInfo::gas_max() const { return gas_max_; } | |
bool StateInfo::operator<(const StateInfo& rhs) const { | ||
// Make sure the roots are in increasing energy order for core-excited state calcualtions | ||
if ((gas_min_ == rhs.gas_min_) && (gas_max_ == rhs.gas_max_)) { | ||
return std::tie(na_, nb_, multiplicity_, twice_ms_, irrep_) < | ||
std::tie(rhs.na_, rhs.nb_, rhs.multiplicity_, rhs.twice_ms_, rhs.irrep_); | ||
return std::tie(na_, nb_, multiplicity_, twice_ms_, irrep_, core_guess_) < | ||
std::tie(rhs.na_, rhs.nb_, rhs.multiplicity_, rhs.twice_ms_, rhs.irrep_, rhs.core_guess_); | ||
} else if (gas_max_ == rhs.gas_max_) { | ||
// The state with a smaller gas occupation in the first gas space is 'bigger'. | ||
// Ground state is smaller than core-excited state under this definition. | ||
|
@@ -83,15 +85,15 @@ bool StateInfo::operator<(const StateInfo& rhs) const { | |
} | ||
|
||
bool StateInfo::operator!=(const StateInfo& rhs) const { | ||
return std::tie(na_, nb_, multiplicity_, twice_ms_, irrep_, gas_min_, gas_max_) != | ||
return std::tie(na_, nb_, multiplicity_, twice_ms_, irrep_, gas_min_, gas_max_, core_guess_) != | ||
std::tie(rhs.na_, rhs.nb_, rhs.multiplicity_, rhs.twice_ms_, rhs.irrep_, rhs.gas_min_, | ||
rhs.gas_max_); | ||
rhs.gas_max_, rhs.core_guess_); | ||
} | ||
|
||
bool StateInfo::operator==(const StateInfo& rhs) const { | ||
return std::tie(na_, nb_, multiplicity_, twice_ms_, irrep_, gas_min_, gas_max_) == | ||
return std::tie(na_, nb_, multiplicity_, twice_ms_, irrep_, gas_min_, gas_max_, core_guess_) == | ||
std::tie(rhs.na_, rhs.nb_, rhs.multiplicity_, rhs.twice_ms_, rhs.irrep_, rhs.gas_min_, | ||
rhs.gas_max_); | ||
rhs.gas_max_, rhs.core_guess_); | ||
} | ||
|
||
StateInfo make_state_info_from_psi(std::shared_ptr<ForteOptions> options) { | ||
|
@@ -194,6 +196,13 @@ std::size_t StateInfo::hash() const { | |
repr += "_" + std::to_string(i); | ||
for (size_t i : gas_max_) | ||
repr += "_" + std::to_string(i); | ||
|
||
if (core_guess_) { | ||
repr += "_" + std::to_string(1); | ||
} else { | ||
repr += "_" + std::to_string(0); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. repr += "" + std::to_string(core_guess ? 1 : 0); |
||
return std::hash<std::string>{}(repr); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,14 +63,26 @@ std::vector<Determinant> FCISolver::initial_guess_generate_dets(std::shared_ptr< | |
vec_e_I.begin(), vec_e_I.end(), | ||
[&e](const std::tuple<double, size_t>& t) { return e < std::get<0>(t); }); | ||
vec_e_I.insert(it, std::make_tuple(e, I)); | ||
emax = std::get<0>(vec_e_I.back()); | ||
// Do not update the maximum energy threshold if using core determinants as initial guess | ||
if (!(core_guess_)){ | ||
emax = std::get<0>(vec_e_I.back()); | ||
} | ||
added++; | ||
} | ||
} | ||
|
||
std::vector<Determinant> guess_dets; | ||
for (const auto& [e, I] : vec_e_I) { | ||
guess_dets.push_back(lists_->determinant(I, symmetry_)); | ||
const auto& det = lists_->determinant(I, symmetry_); | ||
// If using core determinants as initial guess include those with | ||
// single and double holes in first bit position | ||
if (core_guess_){ | ||
if (!(det.get_alfa_bit(0) and det.get_beta_bit(0))){ | ||
guess_dets.push_back(det); | ||
} | ||
} else { | ||
guess_dets.push_back(det); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let us change push_back to emplace_back here, though the speed does not matter at this place. I can barely find a place where emplace_back is worse than push_back |
||
} | ||
} | ||
|
||
// Make sure that the spin space is complete | ||
|
@@ -99,7 +111,8 @@ FCISolver::initial_guess_det(std::shared_ptr<psi::Vector> diag, size_t num_guess | |
// here we use a standard guess procedure | ||
return find_initial_guess_det(guess_dets, guess_dets_pos, num_guess_states, fci_ints, | ||
state().multiplicity(), true, print_ >= PrintLevel::Default, | ||
std::vector<std::vector<std::pair<size_t, double>>>()); | ||
std::vector<std::vector<std::pair<size_t, double>>>(), | ||
core_guess_); | ||
} | ||
|
||
sparse_mat FCISolver::initial_guess_csf(std::shared_ptr<psi::Vector> diag, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# LiH 6-31g basis FCI core excited roots | ||
import forte | ||
|
||
refscf = -7.9791777935853290 | ||
reffci = -5.851395993559 | ||
reffci_avg = -5.5360452551438 | ||
|
||
molecule { | ||
0 1 | ||
Li | ||
H 1 R | ||
|
||
R = 3.0 | ||
units bohr | ||
} | ||
|
||
set { | ||
basis 6-31g | ||
scf_type pk | ||
e_convergence 12 | ||
} | ||
|
||
set forte { | ||
active_space_solver genci | ||
core_guess 1 | ||
} | ||
|
||
energy('scf') | ||
compare_values(refscf, variable("CURRENT ENERGY"),11, "SCF energy") #TEST | ||
|
||
energy('forte') | ||
compare_values(reffci, variable("CURRENT ENERGY"),11, "FCI energy") #TEST | ||
|
||
set forte { | ||
active_space_solver genci | ||
avg_state [[1,1,3]] | ||
core_guess [1] | ||
} | ||
|
||
energy('forte') | ||
compare_values(reffci_avg, variable("CURRENT ENERGY"),11, "FCI avg energy") #TEST |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need a better name for this. Core_guess does not make sense to me. Making it longer and clearer what it means.