QMCPACK
WalkerConfigurations Class Reference

A set of light weight walkers that are carried between driver sections and restart. More...

+ Inheritance diagram for WalkerConfigurations:
+ Collaboration diagram for WalkerConfigurations:

Public Types

using Walker_t = Walker< QMCTraits, PtclOnLatticeTraits >
 walker type More...
 
using FullPrecRealType = QMCTraits::FullPrecRealType
 
using walker_list__t = std::vector< std::unique_ptr< Walker_t > >
 container type of Walkers More...
 
using iterator = walker_list__t::iterator
 FIX: a type alias of iterator for an object should not be for just one of many objects it holds. More...
 
using const_iterator = walker_list__t::const_iterator
 const_iterator of Walker container More...
 

Public Member Functions

 WalkerConfigurations ()
 
 ~WalkerConfigurations ()
 default destructor More...
 
 WalkerConfigurations (const WalkerConfigurations &)=delete
 
WalkerConfigurationsoperator= (const WalkerConfigurations &)=delete
 
 WalkerConfigurations (WalkerConfigurations &&)=default
 
WalkerConfigurationsoperator= (WalkerConfigurations &&)=default
 
void createWalkers (int numWalkers, size_t numPtcls)
 create numWalkers Walkers More...
 
void createWalkers (iterator first, iterator last)
 create walkers More...
 
void copyWalkers (iterator first, iterator last, iterator start)
 copy walkers More...
 
iterator destroyWalkers (iterator first, iterator last)
 destroy Walkers from itstart to itend More...
 
void destroyWalkers (int nw)
 destroy Walkers More...
 
void resize (int numWalkers, size_t numPtcls)
 clean up the walker list and make a new list More...
 
size_t getActiveWalkers () const
 return the number of active walkers More...
 
size_t getGlobalNumWalkers () const
 return the total number of active walkers among a MPI group More...
 
void setWalkerOffsets (const std::vector< int > &o)
 return the total number of active walkers among a MPI group More...
 
const std::vector< int > & getWalkerOffsets () const
 
iterator begin ()
 return the first iterator More...
 
iterator end ()
 return the last iterator, [begin(), end()) More...
 
const_iterator begin () const
 return the first const_iterator More...
 
const_iterator end () const
 return the last const_iterator [begin(), end()) More...
 
void clear ()
 clear the walker_list_ without destroying them More...
 
template<class INPUT_ITER >
void insert (iterator it, INPUT_ITER first, INPUT_ITER last)
 insert elements More...
 
void push_back (std::unique_ptr< Walker_t > awalker)
 add Walker_t* at the end More...
 
void pop_back ()
 delete the last Walker_t* More...
 
Walker_toperator[] (int i)
 
const Walker_toperator[] (int i) const
 
void reset ()
 reset the Walkers More...
 
void putConfigurations (Walker_t::RealType *target, QMCTraits::FullPrecRealType *weights) const
 save the particle positions of all the walkers into target More...
 

Public Attributes

MCDataType< FullPrecRealTypeEnsembleProperty
 

Protected Attributes

walker_list__t walker_list_
 a collection of walkers More...
 

Private Attributes

std::vector< int > walker_offsets_
 starting index of the walkers in a processor group More...
 

Detailed Description

A set of light weight walkers that are carried between driver sections and restart.

Definition at line 56 of file WalkerConfigurations.h.

Member Typedef Documentation

◆ const_iterator

using const_iterator = walker_list__t::const_iterator

const_iterator of Walker container

Definition at line 67 of file WalkerConfigurations.h.

◆ FullPrecRealType

◆ iterator

using iterator = walker_list__t::iterator

FIX: a type alias of iterator for an object should not be for just one of many objects it holds.

Definition at line 65 of file WalkerConfigurations.h.

◆ walker_list__t

using walker_list__t = std::vector<std::unique_ptr<Walker_t> >

container type of Walkers

Definition at line 63 of file WalkerConfigurations.h.

◆ Walker_t

walker type

Definition at line 60 of file WalkerConfigurations.h.

Constructor & Destructor Documentation

◆ WalkerConfigurations() [1/3]

WalkerConfigurations ( )
default

◆ ~WalkerConfigurations()

default destructor

Definition at line 29 of file WalkerConfigurations.cpp.

References WalkerConfigurations::destroyWalkers(), and WalkerConfigurations::walker_list_.

29 { destroyWalkers(walker_list_.begin(), walker_list_.end()); }
iterator destroyWalkers(iterator first, iterator last)
destroy Walkers from itstart to itend
walker_list__t walker_list_
a collection of walkers

◆ WalkerConfigurations() [2/3]

◆ WalkerConfigurations() [3/3]

Member Function Documentation

◆ begin() [1/2]

◆ begin() [2/2]

const_iterator begin ( ) const
inline

return the first const_iterator

Definition at line 126 of file WalkerConfigurations.h.

References WalkerConfigurations::walker_list_.

126 { return walker_list_.begin(); }
walker_list__t walker_list_
a collection of walkers

◆ clear()

void clear ( )
inline

clear the walker_list_ without destroying them

Provide std::vector::clear interface

Definition at line 136 of file WalkerConfigurations.h.

References WalkerConfigurations::walker_list_.

136 { walker_list_.clear(); }
walker_list__t walker_list_
a collection of walkers

◆ copyWalkers()

void copyWalkers ( iterator  first,
iterator  last,
iterator  start 
)

copy walkers

Parameters
firstinput walker iterator
lastinput walker iterator
startfirst target iterator

No memory allocation is allowed.

Definition at line 115 of file WalkerConfigurations.cpp.

116 {
117  while (first != last)
118  {
119  (*it++)->makeCopy(**first++);
120  }
121 }

◆ createWalkers() [1/2]

void createWalkers ( int  numWalkers,
size_t  numPtcls 
)

create numWalkers Walkers

Append Walkers to walker_list_.

Definition at line 32 of file WalkerConfigurations.cpp.

References qmcplusplus::n, and WalkerConfigurations::walker_list_.

Referenced by MCWalkerConfiguration::createWalkers(), HDFWalkerInput_0_4::read_hdf5(), HDFWalkerInput_0_4::read_hdf5_scatter(), HDFWalkerInput_0_4::read_phdf5(), WalkerConfigurations::resize(), and qmcplusplus::TEST_CASE().

33 {
34  if (walker_list_.empty())
35  {
36  while (n)
37  {
38  walker_list_.push_back(std::make_unique<Walker_t>(numPtcls));
39  --n;
40  }
41  }
42  else
43  {
44  if (walker_list_.size() >= n)
45  {
46  int iw = walker_list_.size(); //copy from the back
47  for (int i = 0; i < n; ++i)
48  {
49  walker_list_.push_back(std::make_unique<Walker_t>(*walker_list_[--iw]));
50  }
51  }
52  else
53  {
54  int nc = n / walker_list_.size();
55  int nw0 = walker_list_.size();
56  for (int iw = 0; iw < nw0; ++iw)
57  {
58  for (int ic = 0; ic < nc; ++ic)
59  walker_list_.push_back(std::make_unique<Walker_t>(*walker_list_[iw]));
60  }
61  n -= nc * nw0;
62  while (n > 0)
63  {
64  walker_list_.push_back(std::make_unique<Walker_t>(*walker_list_[--nw0]));
65  --n;
66  }
67  }
68  }
69 }
walker_list__t walker_list_
a collection of walkers

◆ createWalkers() [2/2]

void createWalkers ( iterator  first,
iterator  last 
)

create walkers

Parameters
firstwalker iterator
lastwalker iterator

Definition at line 93 of file WalkerConfigurations.cpp.

References WalkerConfigurations::destroyWalkers(), and WalkerConfigurations::walker_list_.

94 {
96  while (first != last)
97  {
98  walker_list_.push_back(std::make_unique<Walker_t>(**first));
99  ++first;
100  }
101 }
iterator destroyWalkers(iterator first, iterator last)
destroy Walkers from itstart to itend
walker_list__t walker_list_
a collection of walkers

◆ destroyWalkers() [1/2]

WalkerConfigurations::iterator destroyWalkers ( iterator  first,
iterator  last 
)

destroy Walkers from itstart to itend

returns the next valid iterator

Parameters
firststarting iterator of the walkers
lastending iterator of the walkers

Definition at line 88 of file WalkerConfigurations.cpp.

References WalkerConfigurations::walker_list_.

Referenced by QMCDriver::addWalkers(), WalkerConfigurations::createWalkers(), QMCFixedSampleLinearOptimize::finish(), and WalkerConfigurations::~WalkerConfigurations().

89 {
90  return walker_list_.erase(first, last);
91 }
walker_list__t walker_list_
a collection of walkers

◆ destroyWalkers() [2/2]

void destroyWalkers ( int  nw)

destroy Walkers

Parameters
nwnumber of walkers to be destroyed

Definition at line 103 of file WalkerConfigurations.cpp.

References qmcplusplus::app_warning(), and WalkerConfigurations::walker_list_.

104 {
105  if (nw > walker_list_.size())
106  {
107  app_warning() << " Cannot remove walkers. Current Walkers = " << walker_list_.size() << std::endl;
108  return;
109  }
110  nw = walker_list_.size() - nw;
111  int iw = nw;
112  walker_list_.erase(walker_list_.begin() + nw, walker_list_.end());
113 }
walker_list__t walker_list_
a collection of walkers
std::ostream & app_warning()
Definition: OutputManager.h:69

◆ end() [1/2]

◆ end() [2/2]

const_iterator end ( ) const
inline

return the last const_iterator [begin(), end())

Definition at line 129 of file WalkerConfigurations.h.

References WalkerConfigurations::walker_list_.

129 { return walker_list_.end(); }
walker_list__t walker_list_
a collection of walkers

◆ getActiveWalkers()

◆ getGlobalNumWalkers()

size_t getGlobalNumWalkers ( ) const
inline

return the total number of active walkers among a MPI group

Definition at line 114 of file WalkerConfigurations.h.

References WalkerConfigurations::walker_offsets_.

Referenced by EstimatorManagerBase::accumulate(), QMCDriverNew::finalize(), and QMCDriver::process().

114 { return walker_offsets_.empty() ? 0 : walker_offsets_.back(); }
std::vector< int > walker_offsets_
starting index of the walkers in a processor group

◆ getWalkerOffsets()

const std::vector<int>& getWalkerOffsets ( ) const
inline

Definition at line 118 of file WalkerConfigurations.h.

References WalkerConfigurations::walker_offsets_.

Referenced by MCWalkerConfiguration::MCWalkerConfiguration(), and HDFWalkerOutput::write_configuration().

118 { return walker_offsets_; }
std::vector< int > walker_offsets_
starting index of the walkers in a processor group

◆ insert()

void insert ( iterator  it,
INPUT_ITER  first,
INPUT_ITER  last 
)
inline

insert elements

Parameters
itlocator where the inserting begins
firststarting iterator
lastending iterator

Provide std::vector::insert interface

Definition at line 146 of file WalkerConfigurations.h.

References WalkerConfigurations::walker_list_.

Referenced by WalkerControlBase::copyWalkers().

147  {
148  walker_list_.insert(it, first, last);
149  }
walker_list__t walker_list_
a collection of walkers

◆ operator=() [1/2]

WalkerConfigurations& operator= ( const WalkerConfigurations )
delete

◆ operator=() [2/2]

WalkerConfigurations& operator= ( WalkerConfigurations &&  )
default

◆ operator[]() [1/2]

Walker_t* operator[] ( int  i)
inline

Definition at line 164 of file WalkerConfigurations.h.

References WalkerConfigurations::walker_list_.

164 { return walker_list_[i].get(); }
walker_list__t walker_list_
a collection of walkers

◆ operator[]() [2/2]

const Walker_t* operator[] ( int  i) const
inline

Definition at line 166 of file WalkerConfigurations.h.

References WalkerConfigurations::walker_list_.

166 { return walker_list_[i].get(); }
walker_list__t walker_list_
a collection of walkers

◆ pop_back()

void pop_back ( )
inline

delete the last Walker_t*

Provide std::vector::pop_back interface

Definition at line 162 of file WalkerConfigurations.h.

References WalkerConfigurations::walker_list_.

Referenced by MCWalkerConfiguration::loadEnsemble(), and WalkerReconfigurationMPI::swapWalkers().

162 { walker_list_.pop_back(); }
walker_list__t walker_list_
a collection of walkers

◆ push_back()

void push_back ( std::unique_ptr< Walker_t awalker)
inline

add Walker_t* at the end

Parameters
awalkerpointer to a walker

Provide std::vector::push_back interface

Definition at line 156 of file WalkerConfigurations.h.

References WalkerConfigurations::walker_list_.

Referenced by MCWalkerConfiguration::dumpEnsemble().

156 { walker_list_.push_back(std::move(awalker)); }
walker_list__t walker_list_
a collection of walkers

◆ putConfigurations()

void putConfigurations ( Walker_t::RealType target,
QMCTraits::FullPrecRealType weights 
) const

save the particle positions of all the walkers into target

Definition at line 138 of file WalkerConfigurations.cpp.

References copy(), qmcplusplus::get_first_address(), qmcplusplus::get_last_address(), qmcplusplus::walker, and WalkerConfigurations::walker_list_.

Referenced by HDFWalkerOutput::write_configuration().

139 {
140  for (const auto& walker : walker_list_)
141  {
143  target += get_last_address(walker->R) - get_first_address(walker->R);
144  *weights = walker->Weight;
145  ++weights;
146  }
147 }
T * get_first_address(ParticleAttrib< TinyVector< T, D >> &a)
T * get_last_address(ParticleAttrib< TinyVector< T, D >> &a)
walker_list__t walker_list_
a collection of walkers
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
Definition: Blitz.h:639

◆ reset()

void reset ( )

reset the Walkers

Make Metropolis move to the walkers and save in a temporary array.

Parameters
itthe iterator of the first walker to work on
tauinvinverse of the time step

R + D + X

Definition at line 129 of file WalkerConfigurations.cpp.

References qmcplusplus::walker, and WalkerConfigurations::walker_list_.

130 {
131  for (auto& walker : walker_list_)
132  {
133  walker->Weight = 1.0;
134  walker->Multiplicity = 1.0;
135  }
136 }
walker_list__t walker_list_
a collection of walkers

◆ resize()

void resize ( int  numWalkers,
size_t  numPtcls 
)

clean up the walker list and make a new list

Definition at line 72 of file WalkerConfigurations.cpp.

References WalkerConfigurations::createWalkers(), and WalkerConfigurations::walker_list_.

Referenced by MCWalkerConfiguration::resize(), MCPopulation::saveWalkerConfigurations(), and qmcplusplus::TEST_CASE().

73 {
74  int dn = numWalkers - walker_list_.size();
75  if (dn > 0)
76  createWalkers(dn, numPtcls);
77  if (dn < 0)
78  {
79  int nw = -dn;
80  if (nw < walker_list_.size())
81  {
82  walker_list_.erase(walker_list_.begin(), walker_list_.begin() - dn);
83  }
84  }
85 }
walker_list__t walker_list_
a collection of walkers
void createWalkers(int numWalkers, size_t numPtcls)
create numWalkers Walkers

◆ setWalkerOffsets()

void setWalkerOffsets ( const std::vector< int > &  o)
inline

return the total number of active walkers among a MPI group

Definition at line 117 of file WalkerConfigurations.h.

References WalkerConfigurations::walker_offsets_.

Referenced by MCWalkerConfiguration::dumpEnsemble(), MCWalkerConfiguration::MCWalkerConfiguration(), QMCDriver::putWalkers(), QMCDriver::setWalkerOffsets(), QMCDriverNew::setWalkerOffsets(), and qmcplusplus::TEST_CASE().

117 { walker_offsets_ = o; }
std::vector< int > walker_offsets_
starting index of the walkers in a processor group

Member Data Documentation

◆ EnsembleProperty

◆ walker_list_

◆ walker_offsets_

std::vector<int> walker_offsets_
private

starting index of the walkers in a processor group

walker_offsets_[0]=0 and walker_offsets_[walker_offsets_.size()-1]=total number of walkers in a group walker_offsets_[processorid+1]-walker_offsets_[processorid] is equal to the number of walkers on a processor, i.e., W.getActiveWalkers(). walker_offsets_ is added to handle parallel I/O with hdf5

Definition at line 187 of file WalkerConfigurations.h.

Referenced by WalkerConfigurations::getGlobalNumWalkers(), WalkerConfigurations::getWalkerOffsets(), and WalkerConfigurations::setWalkerOffsets().


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