37 const std::vector<ci_configuration2>& configlist_unsorted,
38 const std::vector<size_t>& C2nodes_unsorted,
39 std::vector<size_t>& C2nodes_sorted)
41 auto& ref = configlist_unsorted[ref_det_id];
48 const size_t nci = configlist_unsorted.size();
49 std::vector<std::pair<int, int>> pairs_local;
56 std::map<int, std::vector<int>> dataMap;
57 std::map<int, std::vector<int>> sortMap;
58 std::vector<RealType> tmp_sign(nci, 0);
59 for (
size_t i = 0; i < nci; i++)
62 tmp_sign[i] = ref.calculateExcitations(configlist_unsorted[i], nex, pos, ocp, uno);
63 nex_max = std::max(nex, nex_max);
64 dataMap[nex].push_back(nex);
65 sortMap[nex].push_back(i);
66 for (
int k = 0; k < nex; k++)
67 dataMap[nex].push_back(pos[k]);
68 for (
int k = 0; k < nex; k++)
69 dataMap[nex].push_back(uno[k]);
70 for (
int k = 0; k < nex; k++)
71 dataMap[nex].push_back(ocp[k]);
75 for (
int k1 = 0; k1 < nex; k1++)
76 for (
int k2 = 0; k2 < nex; k2++)
79 std::pair<int, int> temp(pos[k1], uno[k2]);
80 if (find(pairs_local.begin(), pairs_local.end(), temp) == pairs_local.end())
81 pairs_local.push_back(temp);
84 pairs.resize(pairs_local.size());
85 int* first = pairs.data(0);
86 int*
second = pairs.data(1);
88 for (
size_t i = 0; i < pairs_local.size(); i++)
90 first[i] = pairs_local[i].first;
91 second[i] = pairs_local[i].second;
95 app_log() <<
"Number of terms in pairs array: " << pairs.size() << std::endl;
96 ndets_per_excitation_level.resize(nex_max + 1, 0);
98 std::vector<size_t> det_idx_order;
99 std::vector<size_t> det_idx_reverse(nci, 0);
103 std::vector<int> data_local;
107 for (
const auto& [nex, det_idx_old] : sortMap)
109 data_local.insert(data_local.end(), dataMap[nex].begin(), dataMap[nex].end());
110 det_idx_order.insert(det_idx_order.end(), det_idx_old.begin(), det_idx_old.end());
111 ndets_per_excitation_level[nex] = det_idx_old.size();
113 data.resize(data_local.size());
114 for (
size_t i = 0; i < data_local.size(); i++)
115 data[i] = data_local[i];
117 assert(det_idx_order.size() == nci);
120 configlist_sorted.resize(nci);
122 for (
size_t i = 0; i < nci; i++)
124 det_idx_reverse[det_idx_order[i]] = i;
125 configlist_sorted[i] = configlist_unsorted[det_idx_order[i]];
126 sign[i] = tmp_sign[det_idx_order[i]];
131 for (
size_t i = 0; i <
NumPtcls; i++)
132 refdet_occup_ref[i] = configlist_unsorted[ref_det_id].occup[i];
139 refdet_occup_ref.updateTo();
142 C2nodes_sorted.resize(C2nodes_unsorted.size());
143 for (
int i = 0; i < C2nodes_unsorted.size(); i++)
144 C2nodes_sorted[i] = det_idx_reverse[C2nodes_unsorted[i]];
185 for (
size_t i = 0; i <
NumPtcls; i++)
187 for (
size_t j = 0; j <
NumPtcls; j++)
192 for (
size_t i = 0; i <
NumPtcls; i++)
196 std::complex<RealType> logValueRef;
207 for (
size_t iat = 0; iat <
NumPtcls; iat++)
212 for (
size_t i = 0; i <
NumPtcls; i++)
219 for (
size_t idim = 0; idim <
OHMMS_DIM; idim++)
223 for (
size_t i = 0; i <
NumPtcls; i++)
233 for (
size_t i = 0; i <
NumPtcls; i++)
264 Phi->evaluate_notranspose_spin(P,
FirstIndex,
LastIndex, psiM_host_view, dpsiM_host_view, d2psiM_host_view,
275 std::complex<RealType> logValueRef;
280 for (
size_t i = 0; i <
NumPtcls; i++)
282 for (
size_t j = 0; j <
NumPtcls; j++)
286 for (
size_t i = 0; i <
NumPtcls; i++)
298 for (
size_t iat = 0; iat <
NumPtcls; iat++)
304 for (
size_t i = 0; i <
NumPtcls; i++)
313 for (
size_t idim = 0; idim <
OHMMS_DIM; idim++)
317 for (
size_t i = 0; i <
NumPtcls; i++)
327 for (
size_t i = 0; i <
NumPtcls; i++)
338 for (
size_t i = 0; i <
NumPtcls; i++)
368 buf.
put(
psiM.first_address(),
psiM.last_address());
387 buf.
get(
psiM.first_address(),
psiM.last_address());
402 int n1 =
psiM.extent(0);
403 int n2 =
psiM.extent(1);
404 for (
int i = 0; i < n1; i++)
405 for (
int j = 0; j < n2; j++)
418 std::ostringstream msg;
419 msg <<
"MultiDiracDeterminant::acceptMove curRatio is " <<
curRatio <<
"! Report a bug." << std::endl;
420 throw std::runtime_error(msg.str());
502 TpsiM(i, WorkingIndex) =
psiM(WorkingIndex, i);
530 const std::vector<bool>& isAccepted)
533 for (
int iw = 0; iw < wfc_list.size(); iw++)
535 wfc_list[iw].acceptMove(p_list[iw], iat,
false);
537 wfc_list[iw].restore(iat);
543 inverse_timer(
s.inverse_timer),
544 buildTable_timer(
s.buildTable_timer),
545 table2ratios_timer(
s.table2ratios_timer),
546 evalWalker_timer(
s.evalWalker_timer),
547 evalOrbValue_timer(
s.evalOrbValue_timer),
548 evalOrbVGL_timer(
s.evalOrbVGL_timer),
549 updateInverse_timer(
s.updateInverse_timer),
550 calculateRatios_timer(
s.calculateRatios_timer),
551 calculateGradRatios_timer(
s.calculateGradRatios_timer),
552 updateRatios_timer(
s.updateRatios_timer),
553 evaluateDetsForPtclMove_timer(
s.evaluateDetsForPtclMove_timer),
554 evaluateDetsAndGradsForPtclMove_timer(
s.evaluateDetsAndGradsForPtclMove_timer),
555 evaluateGrads_timer(
s.evaluateGrads_timer),
556 offload_timer(
s.offload_timer),
557 transferH2D_timer(
s.transferH2D_timer),
558 transferD2H_timer(
s.transferD2H_timer),
559 lookup_tbl(
s.lookup_tbl),
560 Phi(
s.Phi->makeClone()),
561 NumOrbitals(Phi->getOrbitalSetSize()),
562 FirstIndex(
s.FirstIndex),
563 NumPtcls(
s.NumPtcls),
564 LastIndex(
s.LastIndex),
565 ciConfigList(
s.ciConfigList),
566 refdet_occup(
s.refdet_occup),
567 is_spinor_(
s.is_spinor_),
569 uniquePairs(
s.uniquePairs),
570 DetSigns(
s.DetSigns),
571 ndets_per_excitation_level_(
s.ndets_per_excitation_level_)
580 APP_ABORT(
" Illegal action. Cannot use MultiDiracDeterminant::makeClone");
581 return std::unique_ptr<MultiDiracDeterminant>();
598 calculateGradRatios_timer(
createGlobalTimer(getClassName() +
"::calcGradRatios")),
600 evaluateDetsForPtclMove_timer(
createGlobalTimer(getClassName() +
"::evaluateDet")),
601 evaluateDetsAndGradsForPtclMove_timer(
createGlobalTimer(getClassName() +
"::evaluateDetAndGrad")),
606 Phi(
std::move(spos)),
607 NumOrbitals(Phi->getOrbitalSetSize()),
610 LastIndex(first + nel),
613 ciConfigList = std::make_shared<std::vector<ci_configuration2>>();
614 refdet_occup = std::make_shared<OffloadVector<size_t>>();
615 detData = std::make_shared<OffloadVector<int>>();
616 uniquePairs = std::make_shared<VectorSoaContainer<int, 2, OffloadPinnedAllocator<int>>>();
617 DetSigns = std::make_shared<OffloadVector<RealType>>();
635 buf.
add(
psiM.first_address(),
psiM.last_address());
652 collection.
addResource(std::make_unique<MultiDiracDetMultiWalkerResource>());
660 auto& mw_res = wfc_leader.mw_res_handle_.getResource();
662 const size_t nw = wfc_list.size();
678 psiV_temp_deviceptr_list.resize(nw);
679 psiMinv_temp_deviceptr_list.resize(nw);
680 dpsiMinv_deviceptr_list.resize(nw);
681 workV1_deviceptr_list.resize(nw);
682 workV2_deviceptr_list.resize(nw);
684 psiV_deviceptr_list.resize(nw);
685 dpsiV_deviceptr_list.resize(nw);
686 TpsiM_deviceptr_list.resize(nw);
687 psiM_deviceptr_list.resize(nw);
688 psiMinv_deviceptr_list.resize(nw);
689 dpsiM_deviceptr_list.resize(nw);
691 for (
size_t iw = 0; iw < nw; iw++)
694 psiV_temp_deviceptr_list[iw] =
det.psiV_temp.device_data();
695 psiMinv_temp_deviceptr_list[iw] =
det.psiMinv_temp.device_data();
696 dpsiMinv_deviceptr_list[iw] =
det.dpsiMinv.device_data();
697 workV1_deviceptr_list[iw] =
det.workV1.device_data();
698 workV2_deviceptr_list[iw] =
det.workV2.device_data();
700 psiV_deviceptr_list[iw] =
det.psiV.device_data();
701 dpsiV_deviceptr_list[iw] =
det.dpsiV.device_data();
702 TpsiM_deviceptr_list[iw] =
det.TpsiM.device_data();
703 psiM_deviceptr_list[iw] =
det.psiM.device_data();
704 psiMinv_deviceptr_list[iw] =
det.psiMinv.device_data();
705 dpsiM_deviceptr_list[iw] =
det.dpsiM.device_data();
708 psiV_temp_deviceptr_list.updateTo();
709 psiMinv_temp_deviceptr_list.updateTo();
710 dpsiMinv_deviceptr_list.updateTo();
711 workV1_deviceptr_list.updateTo();
712 workV2_deviceptr_list.updateTo();
714 psiV_deviceptr_list.updateTo();
715 dpsiV_deviceptr_list.updateTo();
716 TpsiM_deviceptr_list.updateTo();
717 psiM_deviceptr_list.updateTo();
718 psiMinv_deviceptr_list.updateTo();
719 dpsiM_deviceptr_list.updateTo();
749 WorkSpace.resize(std::max(nel, NumDets));
780 std::vector<int> occupancy_vector(nmo, 0);
789 for (
int i(0); i < C2node.size(); i++)
795 std::vector<std::pair<int, int>> m_act_rot_inds;
796 std::vector<std::pair<int, int>> other_rot_inds;
798 for (
int i = 0; i < nmo; i++)
799 for (
int j = i + 1; j < nmo; j++)
801 bool core_i(!occupancy_vector[i] and i <= nel - 1);
802 bool core_j(!occupancy_vector[j] and j <= nel - 1);
803 bool virt_i(!occupancy_vector[i] and i > nel - 1);
804 bool virt_j(!occupancy_vector[j] and j > nel - 1);
805 if (!((core_i and core_j) or (virt_i and virt_j)))
807 m_act_rot_inds.push_back(
815 other_rot_inds.push_back(std::pair<int, int>(i, j));
819 std::vector<std::pair<int, int>> full_rot_inds;
822 full_rot_inds = m_act_rot_inds;
824 full_rot_inds.insert(full_rot_inds.end(), other_rot_inds.begin(), other_rot_inds.end());
837 std::vector<int>& occ_vec)
841 while (it < data.
size())
851 for (
int i = 0; i < k; i++)
854 occ_vec[data[it + 1 + i]]++;
855 occ_vec[data[it + 1 + k + i]]++;
871 const std::vector<ValueType>& Coeff,
872 const std::vector<size_t>& C2node_up,
873 const std::vector<size_t>& C2node_dn)
890 std::vector<int> detData_local(
detData->size());
891 for (
size_t i = 0; i <
detData->size(); i++)
892 detData_local[i] = (*
detData)[i];
898 const size_t NP2 = pseudo_dn.
NumPtcls;
907 Phi->evaluateDerivatives(P, optvars, dlogpsi, dhpsioverpsi, psiCurrent, Coeff, C2node_up, C2node_dn,
908 detValues_up_host_view, detValues_dn_host_view, grads_up, grads_dn, lapls_up, lapls_dn,
909 M_up_host_view, M_dn_host_view, Minv_up_host_view, Minv_dn_host_view, B_grad_host_view,
910 B_lapl_host_view, detData_local, N1, N2, NP1, NP2,
lookup_tbl);
919 const std::vector<ValueType>& Coeff,
920 const std::vector<size_t>& C2node_up,
921 const std::vector<size_t>& C2node_dn)
933 std::vector<int> detData_local(
detData->size());
934 for (
size_t i = 0; i <
detData->size(); i++)
935 detData_local[i] = (*
detData)[i];
942 Phi->evaluateDerivativesWF(P, optvars, dlogpsi, psiCurrent, Coeff, C2node_up, C2node_dn, detValues_up_host_view,
943 detValues_dn_host_view, M_up_host_view, M_dn_host_view, Minv_up_host_view,
944 Minv_dn_host_view, detData_local,
lookup_tbl);
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Vector< IndexType > Pivot
~MultiDiracDeterminant() override
default destructor
OffloadVector< ValueType * > TpsiM_deviceptr_list
ValueType * LastAddressOfGrads
Container_t::iterator begin()
std::shared_ptr< OffloadVector< size_t > > refdet_occup
reference determinant occupation
Matrix< ValueType > lapls
store determinant lapls (old and new)
OffloadMatrix< ValueType > dpsiMinv
size_t addResource(std::unique_ptr< Resource > &&res, bool noprint=false)
std::shared_ptr< std::vector< ci_configuration2 > > ciConfigList
use shared_ptr
void takebackResource(ResourceHandle< RS > &res_handle)
Matrix< GradType > new_grads
helper functions for EinsplineSetBuilder
std::shared_ptr< OffloadVector< int > > detData
Tensor< T, D >::Type_t det(const Tensor< T, D > &a)
void createResource(ResourceCollection &collection) const override
initialize a shared resource and hand it to a collection
OffloadVector< GradType * > dpsiM_deviceptr_list
const int NumPtcls
number of particles which belong to this Dirac determinant
const std::unique_ptr< SPOSet > Phi
a set of single-particle orbitals used to fill in the values of the matrix
OffloadMatrix< GradType > dpsiM
dpsiM(i,j)
LogValue log_value_ref_det_
log value of the reference determinant
OffloadMatrix< ValueType > psiMinv_temp
Matrix< GradType > grads
store determinant grads (old and new)
LatticeGaussianProduct::GradType GradType
std::shared_ptr< std::vector< int > > ndets_per_excitation_level_
number of unique determinants at each excitation level (relative to reference) {1, n_singles, n_doubles, n_triples, ...}
void resize(size_type n, size_type m)
Resize the container.
std::complex< T > convertValueToLog(const std::complex< T > &logpsi)
evaluate log(psi) as log(|psi|) and phase
LogValue updateBuffer(ParticleSet &P, WFBufferType &buf, bool fromscratch=false) override
For particle-by-particle move.
void evaluateForWalkerMoveWithSpin(const ParticleSet &P, bool fromScratch=true)
OffloadVector< ValueType * > psiMinv_temp_deviceptr_list
void createDetData(const int ref_det_id, const std::vector< ci_configuration2 > &configlist_unsorted, const std::vector< size_t > &C2nodes_unsorted, std::vector< size_t > &C2nodes_sorted)
create necessary structures related to unique determinants sort configlist_unsorted by excitation lev...
static void mw_accept_rejectMove(const RefVectorWithLeader< MultiDiracDeterminant > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, int iat, const std::vector< bool > &isAccepted)
OffloadVector< ValueType * > workV2_deviceptr_list
static constexpr int ReferenceDeterminant
all the unique determinants are sorted, the id of the reference det id is always 0 ...
OffloadVector< ValueType * > psiMinv_deviceptr_list
OffloadMatrix< ValueType > TpsiM
ValueType * LastAddressOfdpsiM
std::complex< QTFull::RealType > LogValue
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
void buildOptVariables(std::vector< size_t > &C2node)
create optimizable orbital rotation parameters
void buildOptVariables(size_t nel)
An abstract class for a component of a many-body trial wave function.
Specialized paritlce class for atomistic simulations.
void buildTableMatrix_calculateRatiosValueMatrixOneParticle(int ref, const OffloadMatrix< ValueType > &psiinv, const OffloadMatrix< ValueType > &psi, const OffloadVector< int > &data, const VectorSoaContainer< int, 2, OffloadPinnedAllocator< int >> &pairs, const OffloadVector< RealType > &sign, OffloadMatrix< ValueType > &table_matrix, int iat, Matrix< ValueType > &ratios)
void acquireResource(ResourceCollection &collection, const RefVectorWithLeader< MultiDiracDeterminant > &wfc_list) const
OffloadVector< ValueType > ratios_to_ref_
determinant ratios with respect to the reference determinant
void releaseResource(ResourceCollection &collection, const RefVectorWithLeader< MultiDiracDeterminant > &wfc_list) const
size_type size() const
return the current size
OffloadVector< ValueType > psiV
value of single-particle orbital for particle-by-particle update
QTBase::ValueType ValueType
std::shared_ptr< OffloadVector< RealType > > DetSigns
OffloadVector< ValueType > workV1
void InvertWithLog(T *restrict x, int n, int m, T *restrict work, int *restrict pivot, std::complex< T1 > &logdet)
void resizeConstants(size_t nw)
OffloadMatrix< ValueType > psiMinv
inverse Dirac determinant matrix of the reference det
CASTTYPE & getCastedElement(size_t i) const
NewTimer & createGlobalTimer(const std::string &myname, timer_levels mylevel)
Matrix< ValueType > spingrads
class to handle a set of variables that can be modified during optimizations
int build_occ_vec(const OffloadVector< int > &data, const size_t nel, const size_t nmo, std::vector< int > &occ_vec)
helper function to buildOptVariables
std::shared_ptr< VectorSoaContainer< int, 2, OffloadPinnedAllocator< int > > > uniquePairs
Matrix< ValueType > new_spingrads
OffloadVector< ValueType * > psiV_deviceptr_list
ValueType curRatio
new value of the reference determinant over the old value upon a proposed move
OffloadVector< ValueType > WorkSpace
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
QTFull::ValueType PsiValue
void registerData(ParticleSet &P, WFBufferType &buf) override
For particle-by-particle move.
OffloadVector< ValueType * > psiV_temp_deviceptr_list
void acceptMove(ParticleSet &P, int iat, bool safe_to_delay=false) override
move was accepted, update the real container
void evaluateDerivatives(ParticleSet &P, const opt_variables_type &optvars, Vector< ValueType > &dlogpsi, Vector< ValueType > &dhpsioverpsi) override
OffloadVector< ValueType * > dpsiMinv_deviceptr_list
OffloadMatrix< ValueType > d2psiM
d2psiM(i,j)
bool isOptimizable() const final
if true, this contains optimizable components
OffloadMatrix< ValueType > table_matrix
SmallMatrixDetCalculator< ValueType > det_calculator_
OffloadVector< ValueType > psiV_temp
std::unique_ptr< SPOSet > clonePhi() const
return a clone of Phi
Define determinant operators.
void evaluateDerivativesWF(ParticleSet &P, const opt_variables_type &optvars, Vector< ValueType > &dlogpsi, const MultiDiracDeterminant &pseudo_dn, const PsiValue &psiCurrent, const std::vector< ValueType > &Coeff, const std::vector< size_t > &C2node_up, const std::vector< size_t > &C2node_dn)
CASTTYPE & getCastedLeader() const
const int NumOrbitals
number of single-particle orbitals which belong to this Dirac determinant
MultiDiracDeterminant(std::unique_ptr< SPOSet > &&spos, bool spinor, int first, int nel)
constructor
OffloadMatrix< ValueType > psiM
psiM(i,j) TpsiM(i,j)
OffloadVector< ValueType > new_ratios_to_ref_
new determinant ratios with respect to the updated reference determinant upon a proposed move ...
ResourceHandle< MultiDiracDetMultiWalkerResource > mw_res_handle_
void restore(int iat) override
move was rejected.
ValueType * FirstAddressOfdpsiM
void evaluateForWalkerMove(const ParticleSet &P, bool fromScratch=true)
OffloadVector< GradType > dpsiV
LatticeGaussianProduct::ValueType ValueType
void resize()
reset the size: with the number of particles
OffloadVector< ValueType * > workV1_deviceptr_list
void buildTableMatrix_calculateRatios(int ref, const OffloadMatrix< ValueType > &psiinv, const OffloadMatrix< ValueType > &psi, const OffloadVector< int > &data, const VectorSoaContainer< int, 2, OffloadPinnedAllocator< int >> &pairs, const OffloadVector< RealType > &sign, OffloadMatrix< ValueType > &table_matrix, OffloadVector< ValueType > &ratios)
compute the ratio of the excited determinants to the reference determinant
const int FirstIndex
index of the first particle with respect to the particle set
ResourceHandle< RS > lendResource()
OffloadVector< ValueType * > psiM_deviceptr_list
Matrix< ValueType > new_lapls
const int LastIndex
index of the last particle with respect to the particle set
void copyFromBuffer(ParticleSet &P, WFBufferType &buf) override
For particle-by-particle move.
OffloadVector< GradType * > dpsiV_deviceptr_list
std::vector< std::vector< int > > lookup_tbl
Container_t::iterator end()
std::unique_ptr< WaveFunctionComponent > makeClone(ParticleSet &tqp) const override
make clone
const OffloadVector< ValueType > & getRatiosToRefDet() const
void put(std::complex< T1 > &x)
NewTimer & transferH2D_timer
OffloadVector< ValueType > d2psiV
OffloadVector< ValueType > workV2
ValueType * FirstAddressOfGrads
void InverseUpdateByColumn(Matrix< T, ALLOC > &Minv, Vector< T, ALLOC > &newcol, Vector< T, ALLOC > &rvec, Vector< T, ALLOC > &rvecinv, int colchanged, T c_ratio)
void buildTableMatrix_calculateGradRatios(int ref, const OffloadMatrix< ValueType > &psiinv, const OffloadMatrix< ValueType > &psi, const OffloadVector< int > &data, const VectorSoaContainer< int, 2, OffloadPinnedAllocator< int >> &pairs, const OffloadVector< RealType > &sign, const ValueType &det0_grad, OffloadMatrix< ValueType > &table_matrix, int dx, int iat, Matrix< GradType > &grads)
Function to calculate the ratio of the gradients of the excited determinant to the reference determin...
void add(std::complex< T1 > &x)
int UpdateMode
current update mode
void get(std::complex< T1 > &x)
NewTimer & evalWalker_timer