QMCPACK
MCWalkerConfiguration.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Jordan E. Vincent, University of Illinois at Urbana-Champaign
8 // Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
9 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
10 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
11 // Cynthia Gu, zg1@ornl.gov, Oak Ridge National Laboratory
12 // Raymond Clay III, j.k.rofling@gmail.com, Lawrence Livermore National Laboratory
13 // Ye Luo, yeluo@anl.gov, Argonne National Laboratory
14 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
15 //
16 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
17 //////////////////////////////////////////////////////////////////////////////////////
18 
19 
20 /** @file MCWalkerConfiguration.h
21  * @brief Declaration of a MCWalkerConfiguration
22  */
23 #ifndef QMCPLUSPLUS_MCWALKERCONFIGURATION_H
24 #define QMCPLUSPLUS_MCWALKERCONFIGURATION_H
25 #include "Particle/ParticleSet.h"
27 #include "Particle/Walker.h"
28 #include "Particle/SampleStack.h"
30 
31 namespace qmcplusplus
32 {
33 //Forward declaration
34 class MultiChain;
35 class HDFWalkerOutput;
36 class Reptile;
37 
38 /** A set of walkers that are to be advanced by Metropolis Monte Carlo.
39  *
40  *As a derived class from ParticleSet, MCWalkerConfiguration interacts with
41  *QMCHamiltonian and TrialWaveFunction as a ParticleSet, while QMCDrivers
42  *use it as multiple walkers whose configurations are advanced according
43  to MC algorithms.
44  *
45  Each walker is represented by Walker<PosVector_t> and
46  *MCWalkerConfiguration contains a list of
47  *the walkers. This class enables two possible moves:
48  *<ul>
49  *<li> move the entire active walkers, similarly to molecu. Suitable for
50  *small and big systems with a small time step.
51  *<li> move a particle for each walker. Suitable for large systems.
52 
53  *</ul>
54  */
56 {
57 public:
58  /**enumeration for update*/
59  enum
60  {
61  Update_All = 0, ///move all the active walkers
62  Update_Walker, ///move a walker by walker
63  Update_Particle ///move a particle by particle
64  };
65 
67  ///container type of the Properties of a Walker
69  ///container type of Walkers
70  using WalkerList_t = std::vector<std::unique_ptr<Walker_t>>;
71  /// FIX: a type alias of iterator for an object should not be for just one of many objects it holds.
72  using iterator = WalkerList_t::iterator;
73  ///const_iterator of Walker container
74  using const_iterator = WalkerList_t::const_iterator;
75 
77 
78  ///default constructor
79  MCWalkerConfiguration(const SimulationCell& simulation_cell,
81 
82  ///default constructor: copy only ParticleSet
85  /** create numWalkers Walkers
86  *
87  * Append Walkers to WalkerList.
88  */
89  void createWalkers(int numWalkers);
90  ///clean up the walker list and make a new list
91  void resize(int numWalkers, int numPtcls);
92 
93  ///clean up the walker list
95  ///resize Walker::PropertyHistory and Walker::PHindex:
96  void resizeWalkerHistories();
97 
98  ///make random moves for all the walkers
99  //void sample(iterator first, iterator last, value_type tauinv);
100  ///make a random move for a walker
101  void sample(iterator it, RealType tauinv);
102 
103  ///return the number of particles per walker
104  inline int getParticleNum() const { return R.size(); }
105  /**@}*/
106 
107  /** set LocalEnergy
108  * @param e current average Local Energy
109  */
110  inline void setLocalEnergy(RealType e) { LocalEnergy = e; }
111 
112  /** return LocalEnergy
113  */
114  inline RealType getLocalEnergy() const { return LocalEnergy; }
115 
116  inline MultiChain* getPolymer() { return Polymer; }
117 
118  inline void setPolymer(MultiChain* chain) { Polymer = chain; }
119 
120  void resetWalkerProperty(int ncopy = 1);
121 
122  inline bool updatePbyP() const { return ReadyForPbyP; }
123 
124  //@{save/load/clear function for optimization
125  //
126  int numSamples() const { return samples.getNumSamples(); }
127  ///set the number of max samples
128  void setNumSamples(int n);
129  ///save the position of current walkers to SampleStack
130  void saveEnsemble();
131  ///save the position of current walkers
133  /// load a single sample from SampleStack
134  void loadSample(ParticleSet& pset, size_t iw) const;
135  /// load SampleStack data to the current list of walker configurations
136  void loadEnsemble();
137  /// load the SampleStacks of others to the current list of walker configurations
138  void loadEnsemble(std::vector<MCWalkerConfiguration*>& others, bool doclean = true);
139  /** dump Samples to a file
140  * @param others MCWalkerConfigurations whose samples will be collected
141  * @param out engine to write the samples to state_0/walkers
142  * @param np number of processors
143  * @return true with non-zero samples
144  *
145  * CAUTION: The current implementation assumes the same amount of active walkers on all the MPI ranks.
146  */
147  static bool dumpEnsemble(std::vector<MCWalkerConfiguration*>& others, HDFWalkerOutput& out, int np, int nBlock);
148  ///clear the ensemble
149  void clearEnsemble();
150 
151  const SampleStack& getSampleStack() const { return samples; }
153 
154  /// Transitional forwarding methods
155  int getMaxSamples() const;
156  //@}
157 
158 protected:
159  ///true if the buffer is ready for particle-by-particle updates
161  ///update-mode index
163 
165 
166 public:
167  ///a collection of reptiles contained in MCWalkerConfiguration.
170 
171  friend class MCPopulation;
172 
173 private:
174  MultiChain* Polymer;
175 
177 };
178 } // namespace qmcplusplus
179 #endif
DynamicCoordinateKind
enumerator for DynamicCoordinates kinds
Stores particle configurations for later use in DMC and wavefunction optimization.
Walker< QMCTraits, PtclOnLatticeTraits > Walker_t
walker type
void saveEnsemble()
save the position of current walkers to SampleStack
void sample(iterator it, RealType tauinv)
make random moves for all the walkers
A set of walkers that are to be advanced by Metropolis Monte Carlo.
ReptileList_t ReptileList
a collection of reptiles contained in MCWalkerConfiguration.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
Declaration of a WalkerConfigurations.
void resizeWalkerHistories()
resize Walker::PropertyHistory and Walker::PHindex:
QTBase::RealType RealType
Definition: Configuration.h:58
Writes a set of walker configurations to an HDF5 file.
A set of light weight walkers that are carried between driver sections and restart.
int getMaxSamples() const
Transitional forwarding methods.
size_t getNumSamples() const
Definition: SampleStack.h:41
int first(int igroup) const
return the first index of a group i
Definition: ParticleSet.h:514
std::vector< std::unique_ptr< T > > UPtrVector
MCWalkerConfiguration(const SimulationCell &simulation_cell, const DynamicCoordinateKind kind=DynamicCoordinateKind::DC_POS)
default constructor
ConstantSizeMatrix< FullPrecRealType, std::allocator< FullPrecRealType > > PropertyContainer_t
typedef for the property container, fixed size
Definition: Walker.h:75
void loadEnsemble()
load SampleStack data to the current list of walker configurations
void clear()
clear the walker_list_ without destroying them
int getParticleNum() const
return the number of particles per walker
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
WalkerList_t::iterator iterator
FIX: a type alias of iterator for an object should not be for just one of many objects it holds...
size_type size() const
return the current size
Definition: OhmmsVector.h:162
bool ReadyForPbyP
true if the buffer is ready for particle-by-particle updates
WalkerList_t::const_iterator const_iterator
const_iterator of Walker container
ParticlePos R
Position.
Definition: ParticleSet.h:79
void setNumSamples(int n)
set the number of max samples
int last(int igroup) const
return the last index of a group i
Definition: ParticleSet.h:517
RealType getLocalEnergy() const
return LocalEnergy
void resize(int numWalkers, int numPtcls)
clean up the walker list and make a new list
static bool dumpEnsemble(std::vector< MCWalkerConfiguration *> &others, HDFWalkerOutput &out, int np, int nBlock)
dump Samples to a file
void setLocalEnergy(RealType e)
set LocalEnergy
void loadSample(ParticleSet &pset, size_t iw) const
load a single sample from SampleStack
const SampleStack & getSampleStack() const
void createWalkers(int numWalkers)
create numWalkers Walkers
std::vector< std::unique_ptr< Walker_t > > WalkerList_t
container type of Walkers
A container class to represent a walker.
Definition: Walker.h:49
void resetWalkerProperty(int ncopy=1)
reset the Property container of all the walkers