QMCPACK
WalkerReconfiguration Struct Reference

Class to handle walker controls with simple global sum. More...

+ Inheritance diagram for WalkerReconfiguration:
+ Collaboration diagram for WalkerReconfiguration:

Public Member Functions

 WalkerReconfiguration (Communicate *c)
 default constructor More...
 
int branch (int iter, MCWalkerConfiguration &W, FullPrecRealType trigger) override
 perform branch and swap walkers as required More...
 
int getIndexPermutation (MCWalkerConfiguration &W)
 return the surviving Walkers More...
 
int shuffleIndex (int nw)
 
- Public Member Functions inherited from WalkerControlBase
 WalkerControlBase (Communicate *c)
 default constructor More...
 
virtual ~WalkerControlBase ()
 empty destructor to clean up the derived classes More...
 
void start ()
 start a block More...
 
void setWalkerID (MCWalkerConfiguration &walkers)
 start controller and initialize the IDs of walkers More...
 
void measureProperties (int iter)
 take averages and writes to a file More...
 
void setTrialEnergy (FullPrecRealType et)
 set the trial energy More...
 
FullPrecRealType getValue (int i)
 return a value accumulated during a block More...
 
FullPrecRealType getCurrentValue (int i)
 return a current value More...
 
int doNotBranch (int iter, MCWalkerConfiguration &W)
 legacy: return global population update properties without branching More...
 
int sortWalkers (MCWalkerConfiguration &W)
 legacy: sort Walkers between good and bad and prepare branching More...
 
int applyNmaxNmin (int current_population)
 legacy: apply per rank limit Nmax and Nmin More...
 
int copyWalkers (MCWalkerConfiguration &W)
 legacy: copy good walkers to W More...
 
virtual void reset ()
 reset to accumulate data More...
 
bool put (xmlNodePtr cur)
 
void setMinMax (int nw_in, int nmax_in)
 
int get_n_max () const
 
int get_n_min () const
 
FullPrecRealType get_target_sigma () const
 
MCDataType< FullPrecRealType > & get_ensemble_property ()
 
void set_ensemble_property (MCDataType< FullPrecRealType > &ensemble_property)
 
IndexType get_num_contexts () const
 
IndexType get_method () const
 
void set_method (IndexType method)
 
- Public Member Functions inherited from MPIObjectBase
 MPIObjectBase (Communicate *c)
 constructor with communicator More...
 
int rank () const
 return the rank of the communicator More...
 
int getGroupID () const
 return the group id of the communicator More...
 
CommunicategetCommunicator () const
 return myComm More...
 
CommunicategetCommRef () const
 return a TEMPORARY reference to Communicate More...
 
mpi_comm_type getMPI () const
 return MPI communicator if one wants to use MPI directly More...
 
bool is_manager () const
 return true if the rank == 0 More...
 
const std::string & getName () const
 return the name More...
 
void setName (const std::string &aname)
 

Public Attributes

FullPrecRealType UnitZeta
 
std::vector< int > IndexCopy
 
std::vector< FullPrecRealTypewConf
 
std::vector< FullPrecRealTypeZeta
 

Additional Inherited Members

- Public Types inherited from WalkerControlBase
enum  {
  ENERGY_INDEX = 0, ENERGY_SQ_INDEX, WALKERSIZE_INDEX, WEIGHT_INDEX,
  EREF_INDEX, R2ACCEPTED_INDEX, R2PROPOSED_INDEX, FNSIZE_INDEX,
  RNONESIZE_INDEX, RNSIZE_INDEX, B_ENERGY_INDEX, B_WGT_INDEX,
  SENTWALKERS_INDEX, LE_MAX
}
 An enum to access curData and accumData for reduction. More...
 
using Walker_t = MCWalkerConfiguration::Walker_t
 typedef of Walker_t More...
 
using FullPrecRealType = QMCTraits::FullPrecRealType
 typedef of FullPrecRealType More...
 
using IndexType = QMCTraits::IndexType
 typedef of IndexType More...
 
- Public Types inherited from MPIObjectBase
using mpi_comm_type = Communicate::mpi_comm_type
 
- Static Public Member Functions inherited from WalkerControlBase
static std::vector< IndexTypesyncFutureWalkersPerRank (Communicate *comm, IndexType n_walkers)
 
- Protected Attributes inherited from WalkerControlBase
IndexType method_
 id for the method More...
 
IndexType n_min_
 minimum number of walkers More...
 
IndexType n_max_
 maximum number of walkers More...
 
IndexType MaxCopy
 maximum copy per walker More...
 
IndexType NumWalkers
 current number of walkers per processor More...
 
FullPrecRealType trialEnergy
 trial energy energy More...
 
FullPrecRealType target_sigma_
 target sigma to limit fluctuations of the trial energy More...
 
std::vector< int > NumPerRank
 number of particle per rank More...
 
std::vector< int > OffSet
 offset of the particle index More...
 
std::vector< int > FairOffSet
 offset of the particle index for a fair distribution More...
 
std::filesystem::path dmcFname
 filename for dmc.dat More...
 
std::unique_ptr< std::ofstream > dmcStream
 file to save energy histogram More...
 
IndexType NumWalkersCreated
 Number of walkers created by this rank. More...
 
IndexType MyContext
 context id More...
 
IndexType num_contexts_
 number of contexts More...
 
IndexType SwapMode
 0 is default More...
 
std::vector< FullPrecRealTypeaccumData
 any accumulated data over a block More...
 
std::vector< FullPrecRealTypecurData
 any temporary data includes many ridiculous conversions of integral types to and from fp More...
 
std::vector< std::unique_ptr< Walker_t > > good_w
 temporary storage for good and bad walkers More...
 
std::vector< std::unique_ptr< Walker_t > > bad_w
 
std::vector< int > ncopy_w
 temporary storage for copy counters More...
 
bool use_nonblocking
 Use non-blocking isend/irecv. More...
 
MCDataType< FullPrecRealTypeensemble_property_
 ensemble properties More...
 
- Protected Attributes inherited from MPIObjectBase
CommunicatemyComm
 pointer to Communicate More...
 
std::string ClassName
 class Name More...
 
std::string myName
 name of the object More...
 

Detailed Description

Class to handle walker controls with simple global sum.

Base class to handle serial mode with branching only

Definition at line 26 of file WalkerReconfiguration.h.

Constructor & Destructor Documentation

◆ WalkerReconfiguration()

default constructor

Set the SwapMode to zero so that instantiation can be done

set SwapMode

Definition at line 29 of file WalkerReconfiguration.cpp.

References WalkerControlBase::SwapMode.

30 {
31  SwapMode = 1;
32  //ofstream fout("check.dat");
33 }
WalkerControlBase(Communicate *c)
default constructor
IndexType SwapMode
0 is default

Member Function Documentation

◆ branch()

int branch ( int  iter,
MCWalkerConfiguration W,
FullPrecRealType  trigger 
)
overridevirtual

perform branch and swap walkers as required

Reimplemented from WalkerControlBase.

Definition at line 162 of file WalkerReconfiguration.cpp.

References WalkerControlBase::ensemble_property_, WalkerConfigurations::EnsembleProperty, WalkerReconfiguration::getIndexPermutation(), WalkerControlBase::measureProperties(), and qmcplusplus::walker.

163 {
164  int nwkept = getIndexPermutation(W);
165  //update EnsembleProperty
166  measureProperties(iter);
167  W.EnsembleProperty = ensemble_property_;
168  //W.EnsembleProperty.NumSamples=curData[WALKERSIZE_INDEX];
169  //W.EnsembleProperty.Weight=curData[WEIGHT_INDEX];
170  //RealType wgtInv(1.0/curData[WEIGHT_INDEX]);
171  //accumData[ENERGY_INDEX] += curData[ENERGY_INDEX]*wgtInv;
172  //accumData[ENERGY_SQ_INDEX] += curData[ENERGY_SQ_INDEX]*wgtInv;
173  //accumData[WALKERSIZE_INDEX] += nwkept;
174  ////accumData[WALKERSIZE_INDEX] += curData[WALKERSIZE_INDEX];
175  //accumData[WEIGHT_INDEX] += curData[WEIGHT_INDEX];
176  //set Weight and Multiplicity to default values
177  for (auto& walker : W)
178  {
179  walker->Weight = 1.0;
180  walker->Multiplicity = 1.0;
181  }
182  //curData[WALKERSIZE_INDEX]=nwkept;
183  return nwkept;
184 }
void measureProperties(int iter)
take averages and writes to a file
int getIndexPermutation(MCWalkerConfiguration &W)
return the surviving Walkers
MCDataType< FullPrecRealType > ensemble_property_
ensemble properties

◆ getIndexPermutation()

int getIndexPermutation ( MCWalkerConfiguration W)

return the surviving Walkers

Definition at line 35 of file WalkerReconfiguration.cpp.

References qmcplusplus::abs(), WalkerControlBase::curData, qmcplusplus::Units::charge::e, WalkerControlBase::ENERGY_INDEX, WalkerControlBase::ENERGY_SQ_INDEX, WalkerControlBase::EREF_INDEX, WalkerControlBase::FNSIZE_INDEX, WalkerConfigurations::getActiveWalkers(), WalkerReconfiguration::IndexCopy, qmcplusplus::Units::distance::m, WalkerControlBase::MyContext, WalkerControlBase::num_contexts_, WalkerControlBase::NumWalkersCreated, WalkerControlBase::R2ACCEPTED_INDEX, WalkerControlBase::R2PROPOSED_INDEX, Random, WalkerControlBase::RNONESIZE_INDEX, WalkerReconfiguration::UnitZeta, qmcplusplus::walker, WalkerControlBase::WALKERSIZE_INDEX, WalkerReconfiguration::wConf, WalkerControlBase::WEIGHT_INDEX, and WalkerReconfiguration::Zeta.

Referenced by WalkerReconfiguration::branch().

36 {
37  int nw(W.getActiveWalkers());
38  if (Zeta.size() != nw)
39  {
40  Zeta.resize(nw + 1);
41  IndexCopy.resize(nw);
42  wConf.resize(nw);
43  }
44  //accumulate the energies
45  FullPrecRealType esum = 0.0, e2sum = 0.0, wtot = 0.0, ecum = 0.0;
46  FullPrecRealType r2_accepted = 0.0, r2_proposed = 0.0;
47  for (int iw = 0; iw < nw; iw++)
48  {
49  const auto &walker = W[iw];
50  r2_accepted += walker->Properties(WP::R2ACCEPTED);
51  r2_proposed += walker->Properties(WP::R2PROPOSED);
52  FullPrecRealType wgt(walker->Weight);
53  FullPrecRealType e(walker->Properties(WP::LOCALENERGY));
54  esum += wgt * e;
55  e2sum += wgt * e * e;
56  ecum += e;
57  wtot += wConf[iw] = wgt;
58  }
59  curData[ENERGY_INDEX] = esum;
60  curData[ENERGY_SQ_INDEX] = e2sum;
62  curData[WEIGHT_INDEX] = wtot;
63  curData[EREF_INDEX] = ecum;
64  curData[R2ACCEPTED_INDEX] = r2_accepted;
65  curData[R2PROPOSED_INDEX] = r2_proposed;
66  FullPrecRealType nwInv = 1.0 / static_cast<FullPrecRealType>(nw);
67  UnitZeta = Random();
68  FullPrecRealType dstep = UnitZeta * nwInv;
69  for (int iw = 0; iw < nw; iw++)
70  {
71  Zeta[iw] = wtot * (dstep + static_cast<FullPrecRealType>(iw) * nwInv);
72  }
73  Zeta[nw] = wtot + 1.0;
74  //for(int iw=0; iw<nw; iw++) {
75  // fout << iw << " " << Zeta[iw+1]-Zeta[iw] << " " << wConf[iw] << std::endl;
76  //}
77  //assign negative
78  //std::fill(IndexCopy.begin(),IndexCopy.end(),-1);
79  int ind = 0;
80  FullPrecRealType wCur = 0.0;
81  //surviving walkers
82  int icdiff = 0;
83  std::vector<int> ipip(nw, 0);
84  for (int iw = 0; iw < nw; iw++)
85  {
86  FullPrecRealType tryp = wCur + std::abs(wConf[iw]);
87  int ni = 0;
88  while (Zeta[ind] < tryp && Zeta[ind] >= wCur)
89  {
90  //IndexCopy[ind]=iw;
91  ind++;
92  ni++;
93  }
94  wCur += std::abs(wConf[iw]);
95  if (ni)
96  {
97  icdiff++;
98  }
99  ipip[iw] = ni;
100  }
101  //ofstream fout("check.dat", std::ios::app);
102  //fout << wtot << " " << icdiff << std::endl;
103  std::vector<int> plus, minus;
104  for (int iw = 0; iw < nw; iw++)
105  {
106  int m = ipip[iw];
107  if (m > 1)
108  plus.insert(plus.end(), m - 1, iw);
109  else if (m == 0)
110  minus.push_back(iw);
111  }
112  curData[FNSIZE_INDEX] = nw - minus.size();
113  curData[RNONESIZE_INDEX] = minus.size();
114  for (int i = 0; i < plus.size(); i++)
115  {
116  int im = minus[i], ip = plus[i];
117  W[im]->makeCopy(*(W[ip]));
118  W[im]->setParentID(W[ip]->getWalkerID());
119  W[im]->setWalkerID((++NumWalkersCreated) * num_contexts_ + MyContext);
120  }
121  //int killed = shuffleIndex(nw);
122  //fout << "# Total weight " << wtot << " " << killed << std::endl;
123  //cout << "<<<< CopyIndex " << std::endl;
124  //std::copy(IndexCopy.begin(), IndexCopy.end(), std::ostream_iterator<int>(std::cout, " "));
125  //cout << std::endl << "<<<<<<" << std::endl;
126  //for(int iw=0; iw<nw; iw++) {
127  // if(IndexCopy[iw] != iw) {
128  // W[iw]->assign(*(W[IndexCopy[iw]]));
129  // }
130  //}
131  return icdiff;
132 }
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
#define Random
std::vector< FullPrecRealType > Zeta
std::vector< FullPrecRealType > wConf
std::vector< FullPrecRealType > curData
any temporary data includes many ridiculous conversions of integral types to and from fp ...
IndexType NumWalkersCreated
Number of walkers created by this rank.
IndexType num_contexts_
number of contexts
QMCTraits::FullPrecRealType FullPrecRealType
typedef of FullPrecRealType

◆ shuffleIndex()

int shuffleIndex ( int  nw)

Definition at line 134 of file WalkerReconfiguration.cpp.

References WalkerReconfiguration::IndexCopy.

135 {
136  std::vector<int> ipip(nw, 0);
137  for (int iw = 0; iw < nw; iw++)
138  ipip[IndexCopy[iw]] += 1;
139  std::vector<int> indz;
140  for (int iw = 0; iw < nw; iw++)
141  {
142  if (ipip[iw] == 0)
143  {
144  indz.push_back(iw);
145  }
146  }
147  int ikilled = 0;
148  for (int iw = 0; iw < nw; iw++)
149  {
150  if (ipip[iw] != 0)
151  {
152  IndexCopy[iw] = iw;
153  for (int i = 1; i < ipip[iw]; i++)
154  {
155  IndexCopy[indz[ikilled++]] = iw;
156  }
157  }
158  }
159  return indz.size();
160 }

Member Data Documentation

◆ IndexCopy

std::vector<int> IndexCopy

◆ UnitZeta

FullPrecRealType UnitZeta

Definition at line 29 of file WalkerReconfiguration.h.

Referenced by WalkerReconfiguration::getIndexPermutation().

◆ wConf

std::vector<FullPrecRealType> wConf

Definition at line 33 of file WalkerReconfiguration.h.

Referenced by WalkerReconfiguration::getIndexPermutation().

◆ Zeta

std::vector<FullPrecRealType> Zeta

Definition at line 35 of file WalkerReconfiguration.h.

Referenced by WalkerReconfiguration::getIndexPermutation().


The documentation for this struct was generated from the following files: