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

Batched driver move abstraction #3762

Merged
merged 40 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a6d3e61
add abstraction layer in batched qmc
camelto2 Jan 21, 2022
b1c36c0
add spin moves to abstraction
camelto2 Jan 24, 2022
c7a11ff
add selection in VMCBatched
camelto2 Jan 24, 2022
5b8cd85
add advanceWalkers<POSITIONS_SPINS> to vmcbatched
camelto2 Jan 24, 2022
b71e250
add DMC move abstraction
camelto2 Jan 24, 2022
39e809a
add advanceWalkers<POSITIONS_SPINS>
camelto2 Jan 24, 2022
40dfce7
Merge remote-tracking branch 'upstream/develop' into batched_driver_m…
camelto2 Jan 25, 2022
71ef608
add comments to MoveAbtraction class
camelto2 Jan 25, 2022
f46a9bf
add docs for spin mass to batched drivers
camelto2 Jan 25, 2022
5169590
remove unused variable
camelto2 Jan 25, 2022
1f28c8b
move CoordsToMove enum to MoveAbstraction
camelto2 Jan 25, 2022
cd29a55
remove TWFdispatcher from MoveAbstraction, add elecs
camelto2 Jan 25, 2022
cdbe395
separate mw_ spatial and spin moves in ParticleSet to individual APIs
camelto2 Jan 26, 2022
9132b29
change move to mover in drivers
camelto2 Jan 26, 2022
b65d664
use golden_electrons to get spinor info
camelto2 Jan 26, 2022
7e4e77e
use golden electrons
camelto2 Jan 26, 2022
e77f2fe
Merge branch 'develop' into batched_driver_move_abstraction
camelto2 Feb 2, 2022
34b4b7a
Merge remote-tracking branch 'upstream/develop' into batched_driver_m…
camelto2 Feb 7, 2022
ea7c681
remove extra definition of function
camelto2 Feb 7, 2022
8d0eab8
change MoveAbtraction to template on CoordsType
camelto2 Feb 8, 2022
97a737c
use Taus object
camelto2 Feb 8, 2022
b10e42d
change MoveAbstraction members to use MCCoords
camelto2 Feb 9, 2022
fb1e55f
Merge remote-tracking branch 'upstream/develop' into batched_driver_m…
camelto2 Feb 9, 2022
c98ed9c
Add template version of flex/mw_makeMove.
ye-luo Feb 9, 2022
fe2b054
add template version of flex accept/reject
camelto2 Feb 9, 2022
28dc604
simplify check on CoordsType in MoveAbstraction
camelto2 Feb 9, 2022
c5991a4
add TWFGrads<CT> and template TWFdispatcher flex_ and DriftModifierBase
camelto2 Feb 9, 2022
618b262
remove MoveAbstraction
camelto2 Feb 9, 2022
2f58150
call accept_rejectSpinMove first
camelto2 Feb 9, 2022
877233d
fix failing test
camelto2 Feb 10, 2022
a6a2f15
Fix template.
ye-luo Feb 11, 2022
4e5e965
Add TauParams.hpp
ye-luo Feb 11, 2022
bda3f0b
Simplify ContextForSteps
ye-luo Feb 11, 2022
95ae489
move switch from TWFdispatcher into TrialWaveFunction
camelto2 Feb 15, 2022
41236e9
Merge pull request #1 from camelto2/move_switch_to_TWF
camelto2 Feb 16, 2022
60abdad
Update header info
ye-luo Feb 16, 2022
c2220ae
update spinor tests to use templated APIs in ParticleSet
camelto2 Feb 16, 2022
22521d2
add unit test for TWFGrads
camelto2 Feb 16, 2022
6593e7a
Merge branch 'develop' into batched_driver_move_abstraction
ye-luo Feb 16, 2022
3c7aeb6
add test_TWFGrads to cmake
camelto2 Feb 16, 2022
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
12 changes: 12 additions & 0 deletions docs/methods.rst
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ The following is an example of VMC section storing configurations (walker sample
+--------------------------------+--------------+-------------------------+-------------+-----------------------------------------------+
| ``debug_checks`` | text | see additional info | dep. | Turn on/off additional recompute and checks |
+--------------------------------+--------------+-------------------------+-------------+-----------------------------------------------+
| ``spin_mass`` | real | :math:`\geq 0` | 1.0 | Effective mass for spin sampling |
+--------------------------------+--------------+-------------------------+-------------+-----------------------------------------------+


Additional information:

Expand Down Expand Up @@ -357,6 +360,9 @@ Additional information:

- ``debug_checks`` valid values are 'no', 'all', 'checkGL_after_load', 'checkGL_after_moves', 'checkGL_after_tmove'. If the build type is `debug`, the default value is 'all'. Otherwise, the default value is 'no'.

- ``spin_mass`` Optional parameter to allow the user to change the rate of spin sampling. If spin sampling is on using ``spinor`` == yes in the electron ParticleSet input, the spin mass determines the rate
of spin sampling, resulting in an effective spin timestep :math:`\tau_s = \frac{\tau}{\mu_s}`. The algorithm is described in detail in :cite:`Melton2016-1` and :cite:`Melton2016-2`.

An example VMC section for a simple ``vmc_batch`` run:

::
Expand Down Expand Up @@ -1550,6 +1556,9 @@ Combining VMC and DMC in a single run (wavefunction optimization can be combined
+--------------------------------+--------------+-------------------------+-------------+-----------------------------------------------+
| ``debug_checks`` | text | see additional info | dep. | Turn on/off additional recompute and checks |
+--------------------------------+--------------+-------------------------+-------------+-----------------------------------------------+
| ``spin_mass`` | real | :math:`\geq 0` | 1.0 | Effective mass for spin sampling |
+--------------------------------+--------------+-------------------------+-------------+-----------------------------------------------+


- ``crowds`` The number of crowds that the walkers are subdivided into on each MPI rank. If not provided, it is set equal to the number of OpenMP threads.

Expand All @@ -1566,6 +1575,9 @@ Combining VMC and DMC in a single run (wavefunction optimization can be combined

- ``debug_checks`` valid values are 'no', 'all', 'checkGL_after_load', 'checkGL_after_moves', 'checkGL_after_tmove'. If the build type is `debug`, the default value is 'all'. Otherwise, the default value is 'no'.

- ``spin_mass`` Optional parameter to allow the user to change the rate of spin sampling. If spin sampling is on using ``spinor`` == yes in the electron ParticleSet input, the spin mass determines the rate
of spin sampling, resulting in an effective spin timestep :math:`\tau_s = \frac{\tau}{\mu_s}`. The algorithm is described in detail in :cite:`Melton2016-1` and :cite:`Melton2016-2`.

.. code-block::
:caption: The following is an example of a minimal DMC section using the ``dmc_batch`` driver
:name: Listing 48b
Expand Down
9 changes: 5 additions & 4 deletions src/Particle/MCCoords.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This file is distributed under the University of Illinois/NCSA Open Source License.
// See LICENSE file in top directory for details.
//
// Copyright (c) 2022 developers.
// Copyright (c) 2022 QMCPACK developers.
//
// File developed by: Peter Doak, [email protected], Oak Ridge National Laboratory
//
Expand All @@ -13,12 +13,13 @@

namespace qmcplusplus
{
template<CoordsType MCT>
void MCCoords<MCT>::resize(const std::size_t size)
void MCCoords<CoordsType::POS>::resize(const std::size_t size) { positions.resize(size); }

void MCCoords<CoordsType::POS_SPIN>::resize(const std::size_t size)
{
positions.resize(size);
spins.resize(size);
}

template struct MCCoords<CoordsType::POS>;
template struct MCCoords<CoordsType::POS_SPIN>;
} // namespace qmcplusplus
61 changes: 9 additions & 52 deletions src/Particle/MCCoords.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This file is distributed under the University of Illinois/NCSA Open Source License.
// See LICENSE file in top directory for details.
//
// Copyright (c) 2022 developers.
// Copyright (c) 2022 QMCPACK developers.
//
// File developed by: Peter Doak, [email protected], Oak Ridge National Laboratory
//
Expand All @@ -19,75 +19,32 @@

namespace qmcplusplus
{

enum class CoordsType
{
POS,
POS_SPIN
};

template<CoordsType MCT = CoordsType::POS>
struct MCCoords
template<CoordsType MCT>
struct MCCoords;

template<>
struct MCCoords<CoordsType::POS>
{
// This cleans up some other code.
void resize(const std::size_t size);

std::vector<QMCTraits::PosType> positions;
};

template<>
struct MCCoords<CoordsType::POS_SPIN>
{
// This cleans up some other code.
void resize(const std::size_t size)
{
positions.resize(size);
spins.resize(size);
}
void resize(const std::size_t size);

std::vector<QMCTraits::PosType> positions;
std::vector<QMCTraits::FullPrecRealType> spins;
};

/** Object to encapsulate appropriate tau derived values
* for a particular MCCoords specialization
*/
template<typename Real, CoordsType CT = CoordsType::POS>
struct Taus
{
Real tauovermass;
Real oneover2tau;
Real sqrttau;
Taus(Real tau, Real grp_inv_mass)
{
tauovermass = tau * grp_inv_mass;
oneover2tau = 0.5 / (tauovermass);
sqrttau = std::sqrt(tauovermass);
}
};

template<typename Real>
struct Taus<Real, CoordsType::POS_SPIN> : public Taus<Real, CoordsType::POS>
{
using Base = Taus<Real, CoordsType::POS>;
Real spin_tauovermass;
Real spin_oneover2tau;
Real spin_sqrttau;
Taus(Real tau, Real grp_inv_mass, Real spin_mass) : Base(tau, grp_inv_mass)
{
spin_tauovermass = Base::tauovermass / spin_mass;
spin_oneover2tau = 0.5 / (spin_tauovermass);
spin_sqrttau = std::sqrt(spin_tauovermass);
}
};

/** Factory function for Taus based on MCCoordsTypes
* Note as in previous code value of tau derived values is not full precision.
*/
template<CoordsType CT, typename... ARGS>
auto makeTaus(MCCoords<CT>& mc_coords, const ARGS&... args)
{
return Taus<QMCTraits::RealType, CT>(args...);
}

extern template struct MCCoords<CoordsType::POS>;
extern template struct MCCoords<CoordsType::POS_SPIN>;
} // namespace qmcplusplus
Expand Down
37 changes: 22 additions & 15 deletions src/Particle/PSdispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,36 +42,29 @@ void PSdispatcher::flex_update(const RefVectorWithLeader<ParticleSet>& p_list, b
pset.update(skipSK);
}

template<CoordsType CT>
void PSdispatcher::flex_makeMove(const RefVectorWithLeader<ParticleSet>& p_list,
int iat,
const std::vector<SingleParticlePos>& displs) const
const MCCoords<CT>& displs) const
{
if (use_batch_)
ParticleSet::mw_makeMove(p_list, iat, displs);
else
for (size_t iw = 0; iw < p_list.size(); iw++)
p_list[iw].makeMove(iat, displs[iw]);
}

void PSdispatcher::flex_makeMoveWithSpin(const RefVectorWithLeader<ParticleSet>& p_list,
int iat,
const std::vector<SingleParticlePos>& displs,
const std::vector<Scalar_t>& sdispls) const
{
if (use_batch_)
ParticleSet::mw_makeMoveWithSpin(p_list, iat, displs, sdispls);
else
for (size_t iw = 0; iw < p_list.size(); iw++)
p_list[iw].makeMoveWithSpin(iat, displs[iw], sdispls[iw]);
if constexpr (CT == CoordsType::POS_SPIN)
p_list[iw].makeMoveWithSpin(iat, displs.positions[iw], displs.spins[iw]);
else
p_list[iw].makeMove(iat, displs.positions[iw]);
}

template<CoordsType CT>
void PSdispatcher::flex_accept_rejectMove(const RefVectorWithLeader<ParticleSet>& p_list,
int iat,
const std::vector<bool>& isAccepted,
bool forward_mode) const
{
if (use_batch_)
ParticleSet::mw_accept_rejectMove(p_list, iat, isAccepted, forward_mode);
ParticleSet::mw_accept_rejectMove<CT>(p_list, iat, isAccepted, forward_mode);
else
for (size_t iw = 0; iw < p_list.size(); iw++)
p_list[iw].accept_rejectMove(iat, isAccepted[iw], forward_mode);
Expand All @@ -96,4 +89,18 @@ void PSdispatcher::flex_saveWalker(const RefVectorWithLeader<ParticleSet>& p_lis
p_list[iw].saveWalker(walkers[iw]);
}

template void PSdispatcher::flex_makeMove<CoordsType::POS>(const RefVectorWithLeader<ParticleSet>& p_list,
int iat,
const MCCoords<CoordsType::POS>& displs) const;
template void PSdispatcher::flex_makeMove<CoordsType::POS_SPIN>(const RefVectorWithLeader<ParticleSet>& p_list,
int iat,
const MCCoords<CoordsType::POS_SPIN>& displs) const;
template void PSdispatcher::flex_accept_rejectMove<CoordsType::POS>(const RefVectorWithLeader<ParticleSet>& p_list,
int iat,
const std::vector<bool>& isAccepted,
bool forward_mode) const;
template void PSdispatcher::flex_accept_rejectMove<CoordsType::POS_SPIN>(const RefVectorWithLeader<ParticleSet>& p_list,
int iat,
const std::vector<bool>& isAccepted,
bool forward_mode) const;
} // namespace qmcplusplus
11 changes: 3 additions & 8 deletions src/Particle/PSdispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,10 @@ class PSdispatcher

void flex_update(const RefVectorWithLeader<ParticleSet>& p_list, bool skipSK = false) const;

void flex_makeMove(const RefVectorWithLeader<ParticleSet>& p_list,
int iat,
const std::vector<SingleParticlePos>& displs) const;

void flex_makeMoveWithSpin(const RefVectorWithLeader<ParticleSet>& p_list,
int iat,
const std::vector<SingleParticlePos>& displs,
const std::vector<Scalar_t>& sdispls) const;
template<CoordsType CT>
void flex_makeMove(const RefVectorWithLeader<ParticleSet>& p_list, int iat, const MCCoords<CT>& displs) const;

template<CoordsType CT>
void flex_accept_rejectMove(const RefVectorWithLeader<ParticleSet>& p_list,
int iat,
const std::vector<bool>& isAccepted,
Expand Down
16 changes: 8 additions & 8 deletions src/Particle/ParticleBase/RandomSeqGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,6 @@ inline void makeGaussRandomWithEngine(std::vector<TinyVector<T, D>>& a, RG& rng)
assignGaussRand(&(a[0][0]), a.size() * D, rng);
}

template<CoordsType CT, class RG>
inline void makeGaussRandomWithEngine(MCCoords<CT>& a, RG& rng)
{
makeGaussRandomWithEngine(a.positions, rng);
if constexpr (std::is_same<MCCoords<CT>, MCCoords<CoordsType::POS_SPIN>>::value)
makeGaussRandomWithEngine(a.spins, rng);
}

template<typename T, class RG>
inline void makeGaussRandomWithEngine(std::vector<T>& a, RG& rng)
{
Expand All @@ -101,5 +93,13 @@ inline void makeGaussRandomWithEngine(ParticleAttrib<T>& a, RG& rng)
assignGaussRand(&(a[0]), a.size(), rng);
}

template<CoordsType CT, class RG>
inline void makeGaussRandomWithEngine(MCCoords<CT>& a, RG& rng)
{
makeGaussRandomWithEngine(a.positions, rng);
if constexpr (CT == CoordsType::POS_SPIN)
makeGaussRandomWithEngine(a.spins, rng);
}

} // namespace qmcplusplus
#endif
Loading