24 std::unique_ptr<Resource>
makeClone()
const override {
return std::make_unique<SpinorSetMultiWalkerResource>(*this); }
36 spo_up->storeParamsBeforeRotation();
37 spo_dn->storeParamsBeforeRotation();
42 spo_up->applyRotation(rot_mat, use_stored_copy);
43 spo_dn->applyRotation(rot_mat, use_stored_copy);
49 IndexType spo_size_up = up->getOrbitalSetSize();
50 IndexType spo_size_down = dn->getOrbitalSetSize();
52 if (spo_size_up != spo_size_down)
53 throw std::runtime_error(
"SpinorSet::set_spos(...): up and down SPO components have different sizes.");
66 const size_t norb_requested = psi.size();
91 const std::pair<ValueVector, ValueVector>& spinor_multiplier,
93 std::vector<ValueType>& ratios)
95 assert(psi.size() == psiinv.size());
96 const size_t norb_requested = psi.size();
100 for (
size_t iat = 0.0; iat < VP.
getTotalNum(); iat++)
115 ratios[iat] =
simd::dot(psi.data(), psiinv.data(), psi.size());
121 const size_t norb_requested = psi.size();
160 const size_t norb_requested = psi.size();
204 assert(
this == &spo_leader);
208 auto& up_spo_leader = up_spo_list.getLeader();
209 auto& dn_spo_leader = dn_spo_list.getLeader();
214 for (
int iw = 0; iw < nw; iw++)
217 auto& psi = psi_v_list[iw].get();
218 const size_t norb_requested = psi.
size();
220 spo.psi_work_up.resize(norb_requested);
221 spo.psi_work_down.resize(norb_requested);
222 spo.dpsi_work_up.resize(norb_requested);
223 spo.dpsi_work_down.resize(norb_requested);
224 spo.d2psi_work_up.resize(norb_requested);
225 spo.d2psi_work_down.resize(norb_requested);
227 up_psi_v_list.push_back(spo.psi_work_up);
228 dn_psi_v_list.push_back(spo.psi_work_down);
229 up_dpsi_v_list.push_back(spo.dpsi_work_up);
230 dn_dpsi_v_list.push_back(spo.dpsi_work_down);
231 up_d2psi_v_list.push_back(spo.d2psi_work_up);
232 dn_d2psi_v_list.push_back(spo.d2psi_work_down);
235 up_spo_leader.mw_evaluateVGL(up_spo_list, P_list, iat, up_psi_v_list, up_dpsi_v_list, up_d2psi_v_list);
236 dn_spo_leader.mw_evaluateVGL(dn_spo_list, P_list, iat, dn_psi_v_list, dn_dpsi_v_list, dn_d2psi_v_list);
238 for (
int iw = 0; iw < nw; iw++)
248 psi_v_list[iw].get() = eis * up_psi_v_list[iw].get() + emis * dn_psi_v_list[iw].get();
249 dpsi_v_list[iw].get() = eis * up_dpsi_v_list[iw].get() + emis * dn_dpsi_v_list[iw].get();
250 d2psi_v_list[iw].get() = eis * up_d2psi_v_list[iw].get() + emis * dn_d2psi_v_list[iw].get();
251 for (
int iorb = 0; iorb < mw_dspin.
cols(); iorb++)
252 mw_dspin(iw, iorb) = eye * (eis * (up_psi_v_list[iw].get())[iorb] - emis * (dn_psi_v_list[iw].
get())[iorb]);
261 const std::vector<const ValueType*>& invRow_ptr_list,
263 std::vector<ValueType>& ratios,
264 std::vector<GradType>& grads,
265 std::vector<ValueType>& spingrads)
const 269 assert(
this == &spo_leader);
271 assert(phi_vgl_v.
size(1) == spo_list.size());
272 const size_t nw = spo_list.size();
273 const size_t norb_requested = phi_vgl_v.
size(2);
275 auto& mw_res = spo_leader.mw_res_handle_.getResource();
276 auto& up_phi_vgl_v = mw_res.up_phi_vgl_v;
277 auto& dn_phi_vgl_v = mw_res.dn_phi_vgl_v;
278 auto& up_ratios = mw_res.up_ratios;
279 auto& dn_ratios = mw_res.dn_ratios;
280 auto& up_grads = mw_res.up_grads;
281 auto& dn_grads = mw_res.dn_grads;
282 auto& spins = mw_res.spins;
284 up_phi_vgl_v.resize(
DIM_VGL, nw, norb_requested);
285 dn_phi_vgl_v.resize(
DIM_VGL, nw, norb_requested);
286 up_ratios.resize(nw);
287 dn_ratios.resize(nw);
293 auto& up_spo_leader = up_spo_list.getLeader();
294 auto& dn_spo_leader = dn_spo_list.getLeader();
296 up_spo_leader.mw_evaluateVGLandDetRatioGrads(up_spo_list, P_list, iat, invRow_ptr_list, up_phi_vgl_v, up_ratios,
298 dn_spo_leader.mw_evaluateVGLandDetRatioGrads(dn_spo_list, P_list, iat, invRow_ptr_list, dn_phi_vgl_v, dn_ratios,
300 for (
int iw = 0; iw < nw; iw++)
311 ratios[iw] = eis * up_ratios[iw] + emis * dn_ratios[iw];
312 grads[iw] = (eis * up_grads[iw] * up_ratios[iw] + emis * dn_grads[iw] * dn_ratios[iw]) / ratios[iw];
313 spingrads[iw] = eye * (eis * up_ratios[iw] - emis * dn_ratios[iw]) / ratios[iw];
316 auto* spins_ptr = spins.data();
318 auto* phi_vgl_ptr = phi_vgl_v.
data();
319 auto* up_phi_vgl_ptr = up_phi_vgl_v.data();
320 auto* dn_phi_vgl_ptr = dn_phi_vgl_v.data();
321 PRAGMA_OFFLOAD(
"omp target teams distribute map(to:spins_ptr[0:nw])")
322 for (
int iw = 0; iw < nw; iw++)
327 PRAGMA_OFFLOAD(
"omp parallel for collapse(2)")
328 for (
int idim = 0; idim <
DIM_VGL; idim++)
329 for (
int iorb = 0; iorb < norb_requested; iorb++)
331 auto offset = idim * nw * norb_requested + iw * norb_requested + iorb;
332 phi_vgl_ptr[offset] = eis * up_phi_vgl_ptr[offset] + emis * dn_phi_vgl_ptr[offset];
342 ValueMatrix& d2logdet)
346 const size_t norb_requested = logdet.cols();
361 for (
int iat = first; iat < last; iat++)
373 for (
int no = 0; no < norb_requested; no++)
392 assert(
this == &spo_leader);
395 IndexType nelec = P_leader.getTotalNum();
398 auto& up_spo_leader = up_spo_list.getLeader();
399 auto& dn_spo_leader = dn_spo_list.getLeader();
401 std::vector<ValueMatrix> mw_up_logdet, mw_dn_logdet;
402 std::vector<GradMatrix> mw_up_dlogdet, mw_dn_dlogdet;
403 std::vector<ValueMatrix> mw_up_d2logdet, mw_dn_d2logdet;
404 mw_up_logdet.reserve(nw);
405 mw_dn_logdet.reserve(nw);
406 mw_up_dlogdet.reserve(nw);
407 mw_dn_dlogdet.reserve(nw);
408 mw_up_d2logdet.reserve(nw);
409 mw_dn_d2logdet.reserve(nw);
414 up_logdet_list.reserve(nw);
415 dn_logdet_list.reserve(nw);
416 up_dlogdet_list.reserve(nw);
417 dn_dlogdet_list.reserve(nw);
418 up_d2logdet_list.reserve(nw);
419 dn_d2logdet_list.reserve(nw);
421 const size_t norb_requested = logdet_list.front().get().cols();
423 GradMatrix tmp_grad_mat(nelec, norb_requested);
424 for (
int iw = 0; iw < nw; iw++)
426 mw_up_logdet.emplace_back(tmp_val_mat);
427 up_logdet_list.emplace_back(mw_up_logdet.back());
428 mw_dn_logdet.emplace_back(tmp_val_mat);
429 dn_logdet_list.emplace_back(mw_dn_logdet.back());
431 mw_up_dlogdet.emplace_back(tmp_grad_mat);
432 up_dlogdet_list.emplace_back(mw_up_dlogdet.back());
433 mw_dn_dlogdet.emplace_back(tmp_grad_mat);
434 dn_dlogdet_list.emplace_back(mw_dn_dlogdet.back());
436 mw_up_d2logdet.emplace_back(tmp_val_mat);
437 up_d2logdet_list.emplace_back(mw_up_d2logdet.back());
438 mw_dn_d2logdet.emplace_back(tmp_val_mat);
439 dn_d2logdet_list.emplace_back(mw_dn_d2logdet.back());
442 up_spo_leader.mw_evaluate_notranspose(up_spo_list, P_list, first, last, up_logdet_list, up_dlogdet_list,
444 dn_spo_leader.mw_evaluate_notranspose(dn_spo_list, P_list, first, last, dn_logdet_list, dn_dlogdet_list,
447 for (
int iw = 0; iw < nw; iw++)
448 for (
int iat = first; iat < last; iat++)
456 for (
int no = 0; no < norb_requested; no++)
458 logdet_list[iw].get()(iat, no) =
459 eis * up_logdet_list[iw].
get()(iat, no) + emis * dn_logdet_list[iw].
get()(iat, no);
460 dlogdet_list[iw].get()(iat, no) =
461 eis * up_dlogdet_list[iw].
get()(iat, no) + emis * dn_dlogdet_list[iw].
get()(iat, no);
462 d2logdet_list[iw].get()(iat, no) =
463 eis * up_d2logdet_list[iw].
get()(iat, no) + emis * dn_d2logdet_list[iw].
get()(iat, no);
473 ValueMatrix& d2logdet,
474 ValueMatrix& dspinlogdet)
478 const size_t norb_requested = logdet.cols();
492 for (
int iat = 0; iat < nelec; iat++)
505 for (
int no = 0; no < norb_requested; no++)
518 const size_t norb_requested = psi.size();
551 const size_t norb_requested = gradphi.size();
554 spo_up->evaluateGradSource(P, first, last, source, iat_src, gradphi_up);
555 spo_dn->evaluateGradSource(P, first, last, source, iat_src, gradphi_dn);
557 for (
int iat = first; iat < last; iat++)
564 for (
int imo = 0; imo < norb_requested; imo++)
565 gradphi(iat, imo) = gradphi_up(iat, imo) * eis + gradphi_dn(iat, imo) * emis;
571 auto myclone = std::make_unique<SpinorSet>(
my_name_);
572 std::unique_ptr<SPOSet> cloneup(
spo_up->makeClone());
573 std::unique_ptr<SPOSet> clonedn(
spo_dn->makeClone());
574 myclone->set_spos(std::move(cloneup), std::move(clonedn));
580 spo_up->createResource(collection);
581 spo_dn->createResource(collection);
582 auto index = collection.
addResource(std::make_unique<SpinorSetMultiWalkerResource>());
589 auto& up_spo_leader = up_spo_list.getLeader();
590 auto& dn_spo_leader = dn_spo_list.getLeader();
592 dn_spo_leader.acquireResource(collection, dn_spo_list);
600 auto& up_spo_leader = up_spo_list.getLeader();
601 auto& dn_spo_leader = dn_spo_list.getLeader();
603 dn_spo_leader.releaseResource(collection, dn_spo_list);
612 SPOSet& up_spo_leader = *(spo_leader.spo_up);
613 SPOSet& dn_spo_leader = *(spo_leader.spo_dn);
616 up_spo_list.reserve(nw);
617 dn_spo_list.reserve(nw);
618 for (
int iw = 0; iw < nw; iw++)
621 up_spo_list.emplace_back(*(spinor.
spo_up));
622 dn_spo_list.emplace_back(*(spinor.
spo_dn));
624 return std::make_pair(up_spo_list, dn_spo_list);
std::pair< RefVectorWithLeader< SPOSet >, RefVectorWithLeader< SPOSet > > extractSpinComponentRefList(const RefVectorWithLeader< SPOSet > &spo_list) const
base class for Single-particle orbital sets
std::unique_ptr< SPOSet > makeClone() const override
make a clone of itself every derived class must implement this to have threading working correctly...
Class for Melton & Mitas style Spinors.
void evaluateVGL_spin(const ParticleSet &P, int iat, ValueVector &psi, GradVector &dpsi, ValueVector &d2psi, ValueVector &dspin) override
evaluate the values, gradients and laplacians of this single-particle orbital set ...
void createResource(ResourceCollection &collection) const override
initialize a shared resource and hand it to collection
size_t addResource(std::unique_ptr< Resource > &&res, bool noprint=false)
void takebackResource(ResourceHandle< RS > &res_handle)
std::vector< GradType > up_grads
helper functions for EinsplineSetBuilder
const std::string my_name_
name of the object, unique identifier
void evaluate_spin(const ParticleSet &P, int iat, ValueVector &psi, ValueVector &dpsi) override
Evaluate the values, spin gradients, and spin laplacians of single particle spinors corresponding to ...
T dot(const T *restrict a, const T *restrict b, int n, TRES res=TRES())
dot product
QTBase::RealType RealType
void storeParamsBeforeRotation() override
store parameters before getting destroyed by rotation.
ValueMatrix logpsi_work_up
std::vector< RealType > spins
void setOrbitalSetSize(int norbs) override
set the OrbitalSetSize
void mw_evaluateVGLandDetRatioGradsWithSpin(const RefVectorWithLeader< SPOSet > &spo_list, const RefVectorWithLeader< ParticleSet > &P_list, int iat, const std::vector< const ValueType *> &invRow_ptr_list, OffloadMWVGLArray &phi_vgl_v, std::vector< ValueType > &ratios, std::vector< GradType > &grads, std::vector< ValueType > &spingrads) const override
evaluate the values, gradients and laplacians of this single-particle orbital sets and determinant ra...
void releaseResource(ResourceCollection &collection, const RefVectorWithLeader< SPOSet > &spo_list) const override
return a shared resource to collection
size_t getTotalNum() const
MakeReturn< UnaryNode< FnSin, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sin(const Vector< T1, C1 > &l)
ValueVector d2psi_work_down
A ParticleSet that handles virtual moves of a selected particle of a given physical ParticleSet Virtu...
std::unique_ptr< SPOSet > spo_up
OrbitalSetTraits< ValueType >::ValueMatrix ValueMatrix
size_t getTotalNum() const
void evaluate_notranspose(const ParticleSet &P, int first, int last, ValueMatrix &logdet, GradMatrix &dlogdet, ValueMatrix &d2logdet) override
evaluate the values, gradients and laplacians of this single-particle orbital for [first...
SpinorSetMultiWalkerResource()
int size() const
return the size of the orbital set Ye: this needs to be replaced by getOrbitalSetSize(); ...
ValueVector d2psi_work_up
void mw_evaluate_notranspose(const RefVectorWithLeader< SPOSet > &spo_list, const RefVectorWithLeader< ParticleSet > &P_list, int first, int last, const RefVector< ValueMatrix > &logdet_list, const RefVector< GradMatrix > &dlogdet_list, const RefVector< ValueMatrix > &d2logdet_list) const override
void evaluateVGL(const ParticleSet &P, int iat, ValueVector &psi, GradVector &dpsi, ValueVector &d2psi) override
evaluate the values, gradients and laplacians of this single-particle orbital set ...
void evaluateValue(const ParticleSet &P, int iat, ValueVector &psi) override
evaluate the values of this spinor set
void acquireResource(ResourceCollection &collection, const RefVectorWithLeader< SPOSet > &spo_list) const override
acquire a shared resource from collection
const Scalar_t & activeSpin(int iat) const
return the active spin value if the particle is active or return the current spin value if not ...
OrbitalSetTraits< ValueType >::GradMatrix GradMatrix
Specialized paritlce class for atomistic simulations.
std::unique_ptr< Resource > makeClone() const override
void updateTo(size_type size=0, std::ptrdiff_t offset=0)
MakeReturn< UnaryNode< FnCos, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t cos(const Vector< T1, C1 > &l)
QTBase::ValueType ValueType
ValueMatrix d2logpsi_work_up
GradMatrix dlogpsi_work_down
void applyRotation(const ValueMatrix &rot_mat, bool use_stored_copy) override
apply rotation to all the orbitals
OrbitalSetTraits< ValueType >::ValueVector ValueVector
CASTTYPE & getCastedElement(size_t i) const
SpinorSet(const std::string &my_name)
constructor
IndexType OrbitalSetSize
number of Single-particle orbitals
QTFull::RealType Scalar_t
std::unique_ptr< SPOSet > spo_dn
ValueMatrix logpsi_work_down
GradMatrix dlogpsi_work_up
OHMMS_INDEXTYPE IndexType
define other types
std::vector< ValueType > dn_ratios
std::vector< GradType > dn_grads
OffloadMWVGLArray dn_phi_vgl_v
std::vector< std::reference_wrapper< T > > RefVector
CASTTYPE & getCastedLeader() const
virtual void evaluateGradSource(const ParticleSet &P, int first, int last, const ParticleSet &source, int iat_src, GradMatrix &gradphi) override
evaluate the gradients of this single-particle orbital for [first,last) target particles with respect...
void mw_evaluateVGLWithSpin(const RefVectorWithLeader< SPOSet > &spo_list, const RefVectorWithLeader< ParticleSet > &P_list, int iat, const RefVector< ValueVector > &psi_v_list, const RefVector< GradVector > &dpsi_v_list, const RefVector< ValueVector > &d2psi_v_list, OffloadMatrix< ComplexType > &mw_dspin) const override
evaluate the values, gradients and laplacians and spin gradient of this single-particle orbital sets ...
std::vector< ValueType > up_ratios
SpinorSetMultiWalkerResource(const SpinorSetMultiWalkerResource &)
void sincos(T a, T *restrict s, T *restrict c)
sincos function wrapper
GradVector dpsi_work_down
handle math function mapping inside OpenMP offload regions.
void evaluateDetSpinorRatios(const VirtualParticleSet &VP, ValueVector &psi, const std::pair< ValueVector, ValueVector > &spinor_multipler, const ValueVector &invrow, std::vector< ValueType > &ratios) override
evaluate determinant ratios for virtual moves, specifically for Spinor SPOSets
ResourceHandle< RS > lendResource()
void set_spos(std::unique_ptr< SPOSet > &&up, std::unique_ptr< SPOSet > &&dn)
ValueVector psi_work_down
A D-dimensional Array class based on PETE.
OffloadMWVGLArray up_phi_vgl_v
void evaluate_notranspose_spin(const ParticleSet &P, int first, int last, ValueMatrix &logdet, GradMatrix &dlogdet, ValueMatrix &d2logdet, ValueMatrix &dspinlogdet) override
evaluate the values, gradients and laplacians of this single-particle orbital for [first...
ValueMatrix d2logpsi_work_down