QMCPACK
WalkerControlBase.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) 2020 QMCPACK developers.
6 //
7 // File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
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 // Ye Luo, yeluo@anl.gov, Argonne National Laboratory
12 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
13 //
14 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
15 //////////////////////////////////////////////////////////////////////////////////////
16 
17 
18 #ifndef QMCPLUSPLUS_WALKER_CONTROL_BASE_H
19 #define QMCPLUSPLUS_WALKER_CONTROL_BASE_H
20 
21 #include "Configuration.h"
24 #include "Message/MPIObjectBase.h"
25 #include "Message/CommOperators.h"
26 // #include "QMCDrivers/ForwardWalking/ForwardWalkingStructure.h"
27 
28 #include <filesystem>
29 
30 namespace qmcplusplus
31 {
32 namespace testing
33 {
34 class UnifiedDriverWalkerControlMPITest;
35 }
36 
37 
38 /** Base class to control the walkers for DMC simulations.
39  *
40  * The virtual functions are implemented for a serial execution with a usual birth/death
41  * process. Inherited classes implement other WalkerControl algorithms by implementing
42  * branch function.
43  * - 2006/10/18
44  * -- curData and accumData are added.
45  * -- branch function handles averaging of the local energies to apply the weight over the
46  * current walker sample correctly.
47  * -- removes an extra global reduction.
48  * --- curData should be used for global reductions
49  * - 2007/11/07
50  * -- added functions to dump dmc histograms
51  */
53 {
54 public:
55  ///typedef of Walker_t
57  ///typedef of FullPrecRealType
59  ///typedef of IndexType
61 
62  /** An enum to access curData and accumData for reduction
63  *
64  * curData is larger than this //LE_MAX + n_rank * T
65  */
66  enum
67  {
82  };
83 
84  /** default constructor
85  *
86  * Set the SwapMode to zero so that instantiation can be done
87  */
89 
90  /** empty destructor to clean up the derived classes */
91  virtual ~WalkerControlBase();
92 
93  /** start a block */
94  void start();
95 
96  /** start controller and initialize the IDs of walkers
97  \todo remove when legacy is dropped*/
99 
100  /** take averages and writes to a file */
101  void measureProperties(int iter);
102 
103  /** set the trial energy
104  */
105  inline void setTrialEnergy(FullPrecRealType et) { trialEnergy = et; }
106 
107  /** return a value accumulated during a block
108  * @param i index of the data
109  *
110  * use enum for i, see DMCEnergyEstimator
111  */
112  inline FullPrecRealType getValue(int i) { return accumData[i]; }
113 
114  /** return a current value
115  * @param i index of the data
116  *
117  * use enum for i, see DMCEnergyEstimator
118  */
119  inline FullPrecRealType getCurrentValue(int i) { return curData[i]; }
120 
121  /** legacy: return global population
122  * update properties without branching
123  *
124  */
125  int doNotBranch(int iter, MCWalkerConfiguration& W);
126 
127  /** legacy: sort Walkers between good and bad and prepare branching
128  *
129  * not a sort changes internal state of walkers to copy and how many of each copy
130  */
132 
133  static std::vector<IndexType> syncFutureWalkersPerRank(Communicate* comm, IndexType n_walkers);
134 
135  /** legacy: apply per rank limit Nmax and Nmin
136  */
137  int applyNmaxNmin(int current_population);
138 
139  /** legacy: copy good walkers to W
140  */
142 
143  /** reset to accumulate data */
144  virtual void reset();
145 
146  /** legacy: perform branch and swap walkers as required
147  *
148  * \return global population
149  */
150  virtual int branch(int iter, MCWalkerConfiguration& W, FullPrecRealType trigger);
151 
152  bool put(xmlNodePtr cur);
153 
154  void setMinMax(int nw_in, int nmax_in);
155 
156  int get_n_max() const { return n_max_; }
157  int get_n_min() const { return n_min_; }
161  {
162  ensemble_property_ = ensemble_property;
163  }
165  IndexType get_method() const { return method_; }
166  void set_method(IndexType method) { method_ = method; }
167 
168 protected:
169  ///id for the method
171  ///minimum number of walkers
173  ///maximum number of walkers
175  ///maximum copy per walker
177  ///current number of walkers per processor
179  ///trial energy energy
181  ///target sigma to limit fluctuations of the trial energy
183  ///number of particle per rank
184  std::vector<int> NumPerRank;
185  ///offset of the particle index
186  std::vector<int> OffSet;
187  ///offset of the particle index for a fair distribution
188  std::vector<int> FairOffSet;
189 
190  ///filename for dmc.dat
191  std::filesystem::path dmcFname;
192  ///file to save energy histogram
193  std::unique_ptr<std::ofstream> dmcStream;
194  ///Number of walkers created by this rank
196  ///context id
198  ///number of contexts
200  ///0 is default
202  ///any accumulated data over a block
203  std::vector<FullPrecRealType> accumData;
204  ///any temporary data includes many ridiculous conversions of integral types to and from fp
205  std::vector<FullPrecRealType> curData;
206  ///temporary storage for good and bad walkers
207  std::vector<std::unique_ptr<Walker_t>> good_w, bad_w;
208  ///temporary storage for copy counters
209  std::vector<int> ncopy_w;
210  ///Use non-blocking isend/irecv
212 
213  ///ensemble properties
215 };
216 
217 } // namespace qmcplusplus
218 #endif
WalkerControlBase(Communicate *c)
default constructor
HamiltonianRef::FullPrecRealType FullPrecRealType
virtual void reset()
reset to accumulate data
std::vector< std::unique_ptr< Walker_t > > bad_w
FullPrecRealType get_target_sigma() const
FullPrecRealType target_sigma_
target sigma to limit fluctuations of the trial energy
IndexType NumWalkers
current number of walkers per processor
int copyWalkers(MCWalkerConfiguration &W)
legacy: copy good walkers to W
A set of walkers that are to be advanced by Metropolis Monte Carlo.
std::vector< int > NumPerRank
number of particle per rank
Base class for any object which needs to know about a MPI communicator.
Definition: MPIObjectBase.h:26
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
std::filesystem::path dmcFname
filename for dmc.dat
FullPrecRealType getValue(int i)
return a value accumulated during a block
void set_ensemble_property(MCDataType< FullPrecRealType > &ensemble_property)
std::vector< int > ncopy_w
temporary storage for copy counters
FullPrecRealType trialEnergy
trial energy energy
const char walkers[]
Definition: HDFVersion.h:36
std::vector< FullPrecRealType > accumData
any accumulated data over a block
declaration of MPIObjectBase
QMCTraits::IndexType IndexType
Definition: FSUtilities.h:11
bool use_nonblocking
Use non-blocking isend/irecv.
Wrapping information on parallelism.
Definition: Communicate.h:68
std::vector< int > FairOffSet
offset of the particle index for a fair distribution
static std::vector< IndexType > syncFutureWalkersPerRank(Communicate *comm, IndexType n_walkers)
int doNotBranch(int iter, MCWalkerConfiguration &W)
legacy: return global population update properties without branching
IndexType method_
id for the method
std::vector< int > OffSet
offset of the particle index
IndexType n_min_
minimum number of walkers
void measureProperties(int iter)
take averages and writes to a file
std::vector< FullPrecRealType > curData
any temporary data includes many ridiculous conversions of integral types to and from fp ...
MCDataType< FullPrecRealType > & get_ensemble_property()
FullPrecRealType getCurrentValue(int i)
return a current value
void setWalkerID(MCWalkerConfiguration &walkers)
start controller and initialize the IDs of walkers
IndexType NumWalkersCreated
Number of walkers created by this rank.
std::unique_ptr< std::ofstream > dmcStream
file to save energy histogram
IndexType num_contexts_
number of contexts
OHMMS_INDEXTYPE IndexType
define other types
Definition: Configuration.h:65
void setTrialEnergy(FullPrecRealType et)
set the trial energy
WalkerConfigurations::Walker_t Walker_t
std::vector< std::unique_ptr< Walker_t > > good_w
temporary storage for good and bad walkers
virtual int branch(int iter, MCWalkerConfiguration &W, FullPrecRealType trigger)
legacy: perform branch and swap walkers as required
void setMinMax(int nw_in, int nmax_in)
IndexType n_max_
maximum number of walkers
IndexType MaxCopy
maximum copy per walker
Base class to control the walkers for DMC simulations.
QTFull::RealType FullPrecRealType
Definition: Configuration.h:66
QMCTraits::FullPrecRealType FullPrecRealType
typedef of FullPrecRealType
virtual ~WalkerControlBase()
empty destructor to clean up the derived classes
int sortWalkers(MCWalkerConfiguration &W)
legacy: sort Walkers between good and bad and prepare branching
MCDataType< FullPrecRealType > ensemble_property_
ensemble properties
QMCTraits::IndexType IndexType
typedef of IndexType
IndexType SwapMode
0 is default
Declaration of a MCWalkerConfiguration.
A container class to represent a walker.
Definition: Walker.h:49
void set_method(IndexType method)
int applyNmaxNmin(int current_population)
legacy: apply per rank limit Nmax and Nmin