QMCPACK
WalkerLogBuffer< T > Class Template Reference

Data buffer for walker log quantities. More...

+ Inheritance diagram for WalkerLogBuffer< T >:
+ Collaboration diagram for WalkerLogBuffer< T >:

Public Member Functions

 WalkerLogBuffer ()
 
size_t nrows ()
 current number of rows in the data buffer More...
 
size_t ncols ()
 current number of columns in the data buffer (row size) More...
 
void resetBuffer ()
 resize the buffer to zero More...
 
void resetCollect ()
 reset member variables at end of each WalkerLogCollector::collect() call More...
 
bool sameAs (const WalkerLogBuffer< T > &ref)
 compare row size of this buffer to another one More...
 
void collect (const std::string &name, const T &value)
 collect data for a single walker quantity of scalar type into the current buffer row More...
 
template<unsigned D>
void collect (const std::string &name, Array< T, D > arr)
 collect data for a single walker quantity of array type into the current buffer row More...
 
template<unsigned D>
void collect (const std::string &name, Array< std::complex< T >, D > arr)
 collect data for a single walker quantity of complex array type into the current buffer row More...
 
void addRow (WalkerLogBuffer< T > other, size_t i)
 add a data row from another buffer to this one More...
 
void writeSummary (std::string pad=" ")
 write a summary of quantities in the buffer More...
 
void registerHDFData (hdf_archive &f)
 write the data_layout for all walker quantities in the HDF file More...
 
void writeHDF (hdf_archive &f)
 write the buffer data into the HDF file More...
 
void writeHDF (hdf_archive &f, hsize_t &file_pointer)
 write the buffer data into the HDF file More...
 

Public Attributes

std::string label
 label for this data in HDF file More...
 
bool first_collect
 marks first WalkerLogCollector::collect() call More...
 
hsize_t hdf_file_pointer
 HDF file pointer. More...
 

Private Member Functions

void resetRowSize (size_t row_size)
 make space as quantities are added to the buffer for the first time More...
 
void makeNewRow ()
 allocate a full new row at the end of the buffer More...
 

Private Attributes

size_t quantity_index
 index of current quantity during WalkerLogCollector::collect() More...
 
std::vector< WalkerQuantityInfoquantity_info
 buffer row location data for each walker quantity used to populate "data_layout" field in HDF file More...
 
size_t walker_data_size
 total size of walker data stored in a buffer row More...
 
Array< T, 2 > buffer
 the walker data buffer itself More...
 

Detailed Description

template<typename T>
class qmcplusplus::WalkerLogBuffer< T >

Data buffer for walker log quantities.

Each row in the buffer contains all quantities for one walker from a single step. Rows are added throughout an MC block. See WalkerLogCollector::collect()

Buffer data is written to HDF at the end of each MC block. See WalkerLogManager::writeBuffers()

Definition at line 111 of file WalkerLogBuffer.h.

Constructor & Destructor Documentation

◆ WalkerLogBuffer()

WalkerLogBuffer ( )
inline

Definition at line 134 of file WalkerLogBuffer.h.

135  {
136  label = "?";
137  first_collect = true;
138  walker_data_size = 0;
139  quantity_index = 0;
140  resetBuffer();
141  }
bool first_collect
marks first WalkerLogCollector::collect() call
size_t quantity_index
index of current quantity during WalkerLogCollector::collect()
std::string label
label for this data in HDF file
void resetBuffer()
resize the buffer to zero
size_t walker_data_size
total size of walker data stored in a buffer row

Member Function Documentation

◆ addRow()

void addRow ( WalkerLogBuffer< T >  other,
size_t  i 
)
inline

add a data row from another buffer to this one

Definition at line 272 of file WalkerLogBuffer.h.

Referenced by WalkerLogManager::writeBuffers().

273  {
274  auto& other_buffer = other.buffer;
275  if (first_collect)
276  {
277  resetRowSize(other_buffer.size(1));
278  quantity_info = other.quantity_info;
279  first_collect = false;
280  }
281  else
282  {
283  if (buffer.size(1) != other_buffer.size(1))
284  throw std::runtime_error("WalkerLogBuffer::add_row Row sizes must match.");
285  makeNewRow();
286  }
287  size_t ib = buffer.size(0) - 1;
288  for (size_t j = 0; j < buffer.size(1); ++j)
289  buffer(ib, j) = other_buffer(i, j);
290  }
bool first_collect
marks first WalkerLogCollector::collect() call
Array< T, 2 > buffer
the walker data buffer itself
std::vector< WalkerQuantityInfo > quantity_info
buffer row location data for each walker quantity used to populate "data_layout" field in HDF file ...
size_t size() const
Definition: OhmmsArray.h:57
void resetRowSize(size_t row_size)
make space as quantities are added to the buffer for the first time
void makeNewRow()
allocate a full new row at the end of the buffer

◆ collect() [1/3]

void collect ( const std::string &  name,
const T &  value 
)
inline

collect data for a single walker quantity of scalar type into the current buffer row

Definition at line 166 of file WalkerLogBuffer.h.

167  {
168  size_t irow = 0;
169  if (first_collect)
170  { // cache walker quantity info on first collect
171  WalkerQuantityInfo wqi_(name, 1, walker_data_size);
172  quantity_info.push_back(wqi_);
173  walker_data_size = wqi_.buffer_end;
175  }
176  else
177  { // make a new buffer row if needed
178  if (quantity_index == 0)
179  makeNewRow();
180  irow = buffer.size(0) - 1;
181  }
182  // place the scalar walker quantity into the current buffer row
183  auto& wqi = quantity_info[quantity_index];
184  buffer(irow, wqi.buffer_start) = value;
185  quantity_index++;
186  }
bool first_collect
marks first WalkerLogCollector::collect() call
Array< T, 2 > buffer
the walker data buffer itself
size_t quantity_index
index of current quantity during WalkerLogCollector::collect()
std::vector< WalkerQuantityInfo > quantity_info
buffer row location data for each walker quantity used to populate "data_layout" field in HDF file ...
size_t size() const
Definition: OhmmsArray.h:57
size_t walker_data_size
total size of walker data stored in a buffer row
void resetRowSize(size_t row_size)
make space as quantities are added to the buffer for the first time
void makeNewRow()
allocate a full new row at the end of the buffer

◆ collect() [2/3]

void collect ( const std::string &  name,
Array< T, D >  arr 
)
inline

collect data for a single walker quantity of array type into the current buffer row

Definition at line 191 of file WalkerLogBuffer.h.

192  {
193  size_t n1 = arr.size(0);
194  size_t n2, n3, n4;
195  n2 = n3 = n4 = 0;
196  if (D > 4)
197  throw std::runtime_error("WalkerLogBuffer::collect Only arrays up to dimension 4 are currently supported.");
198  if (D > 1)
199  n2 = arr.size(1);
200  if (D > 2)
201  n3 = arr.size(2);
202  if (D > 3)
203  n4 = arr.size(3);
204  size_t irow = 0;
205  if (first_collect)
206  { // cache walker quantity info on first collect
207  WalkerQuantityInfo wqi_(name, 1, walker_data_size, n1, n2, n3, n4);
208  quantity_info.push_back(wqi_);
209  walker_data_size = wqi_.buffer_end;
211  }
212  else
213  { // make a new buffer row if needed
214  if (quantity_index == 0)
215  makeNewRow();
216  irow = buffer.size(0) - 1;
217  }
218  // place the array walker quantity into the current buffer row
219  auto& wqi = quantity_info[quantity_index];
220  auto& arr1d = arr.storage();
221  for (size_t n = 0; n < arr1d.size(); ++n)
222  buffer(irow, wqi.buffer_start + n) = arr1d[n];
223  quantity_index++;
224  }
bool first_collect
marks first WalkerLogCollector::collect() call
Array< T, 2 > buffer
the walker data buffer itself
size_t quantity_index
index of current quantity during WalkerLogCollector::collect()
std::vector< WalkerQuantityInfo > quantity_info
buffer row location data for each walker quantity used to populate "data_layout" field in HDF file ...
Container_t & storage()
Definition: OhmmsArray.h:60
size_t size() const
Definition: OhmmsArray.h:57
size_t walker_data_size
total size of walker data stored in a buffer row
void resetRowSize(size_t row_size)
make space as quantities are added to the buffer for the first time
void makeNewRow()
allocate a full new row at the end of the buffer

◆ collect() [3/3]

void collect ( const std::string &  name,
Array< std::complex< T >, D >  arr 
)
inline

collect data for a single walker quantity of complex array type into the current buffer row

Definition at line 229 of file WalkerLogBuffer.h.

230  {
231  size_t n1 = arr.size(0);
232  size_t n2, n3, n4;
233  n2 = n3 = n4 = 0;
234  if (D > 4)
235  throw std::runtime_error("WalkerLogBuffer::collect Only arrays up to dimension 4 are currently supported.");
236  if (D > 1)
237  n2 = arr.size(1);
238  if (D > 2)
239  n3 = arr.size(2);
240  if (D > 3)
241  n4 = arr.size(3);
242  size_t irow = 0;
243  if (first_collect)
244  { // cache walker quantity info on first collect
245  WalkerQuantityInfo wqi_(name, 2, walker_data_size, n1, n2, n3, n4);
246  quantity_info.push_back(wqi_);
247  walker_data_size = wqi_.buffer_end;
249  }
250  else
251  { // make a new buffer row if needed
252  if (quantity_index == 0)
253  makeNewRow();
254  irow = buffer.size(0) - 1;
255  }
256  // place the complex array walker quantity into the current buffer row
257  auto& wqi = quantity_info[quantity_index];
258  auto& arr1d = arr.storage();
259  size_t n = 0;
260  for (size_t i = 0; i < arr1d.size(); ++i)
261  {
262  buffer(irow, wqi.buffer_start + n) = std::real(arr1d[i]);
263  ++n;
264  buffer(irow, wqi.buffer_start + n) = std::imag(arr1d[i]);
265  ++n;
266  }
267  quantity_index++;
268  }
bool first_collect
marks first WalkerLogCollector::collect() call
Array< T, 2 > buffer
the walker data buffer itself
size_t quantity_index
index of current quantity during WalkerLogCollector::collect()
QMCTraits::RealType real
std::vector< WalkerQuantityInfo > quantity_info
buffer row location data for each walker quantity used to populate "data_layout" field in HDF file ...
Container_t & storage()
Definition: OhmmsArray.h:60
float imag(const float &c)
imaginary part of a scalar. Cannot be replaced by std::imag due to AFQMC specific needs...
size_t size() const
Definition: OhmmsArray.h:57
size_t walker_data_size
total size of walker data stored in a buffer row
void resetRowSize(size_t row_size)
make space as quantities are added to the buffer for the first time
void makeNewRow()
allocate a full new row at the end of the buffer

◆ makeNewRow()

void makeNewRow ( )
inlineprivate

allocate a full new row at the end of the buffer

Definition at line 379 of file WalkerLogBuffer.h.

Referenced by WalkerLogBuffer< WLog::Real >::addRow(), and WalkerLogBuffer< WLog::Real >::collect().

380  {
381  size_t nrows = buffer.size(0);
382  size_t row_size = buffer.size(1);
383  if (row_size == 0)
384  throw std::runtime_error("WalkerLogBuffer::makeNewRow Cannot make a new row of size zero.");
385  nrows++;
386  // resizing buffer(type Array) doesn't preserve data. Thus keep old data and copy over
387  auto buffer_old(buffer);
388  buffer.resize(nrows, row_size);
389  std::copy_n(buffer_old.data(), buffer_old.size(), buffer.data());
390  }
Array< T, 2 > buffer
the walker data buffer itself
Type_t * data()
Definition: OhmmsArray.h:87
void resize(const std::array< SIZET, D > &dims)
Resize the container.
Definition: OhmmsArray.h:65
size_t size() const
Definition: OhmmsArray.h:57
size_t nrows()
current number of rows in the data buffer
sycl::event copy_n(sycl::queue &aq, const T1 *restrict VA, size_t array_size, T2 *restrict VC, const std::vector< sycl::event > &events)
Definition: syclBLAS.cpp:548

◆ ncols()

size_t ncols ( )
inline

current number of columns in the data buffer (row size)

Definition at line 147 of file WalkerLogBuffer.h.

147 { return buffer.size(1); }
Array< T, 2 > buffer
the walker data buffer itself
size_t size() const
Definition: OhmmsArray.h:57

◆ nrows()

size_t nrows ( )
inline

current number of rows in the data buffer

Definition at line 144 of file WalkerLogBuffer.h.

Referenced by WalkerLogCollector::checkBuffers(), WalkerLogBuffer< WLog::Real >::makeNewRow(), and WalkerLogBuffer< WLog::Real >::resetRowSize().

144 { return buffer.size(0); }
Array< T, 2 > buffer
the walker data buffer itself
size_t size() const
Definition: OhmmsArray.h:57

◆ registerHDFData()

void registerHDFData ( hdf_archive f)
inline

write the data_layout for all walker quantities in the HDF file

Definition at line 312 of file WalkerLogBuffer.h.

Referenced by WalkerLogManager::writeBuffersHDF().

313  {
314  auto& top = label;
315  f.push(top);
316  f.push("data_layout");
317  for (auto& wqi : quantity_info)
318  {
319  f.push(wqi.name);
320  f.write(wqi.dimension, "dimension");
321  f.write(wqi.shape, "shape");
322  f.write(wqi.size, "size");
323  f.write(wqi.unit_size, "unit_size");
324  f.write(wqi.buffer_start, "index_start");
325  f.write(wqi.buffer_end, "index_end");
326  f.pop();
327  }
328  f.pop();
329  f.pop();
330  if (!f.open_groups())
331  throw std::runtime_error("WalkerLogBuffer(" + label +
332  ")::register_hdf_data() some hdf groups are still open at the end of registration");
333  hdf_file_pointer = 0;
334  }
std::string label
label for this data in HDF file
std::vector< WalkerQuantityInfo > quantity_info
buffer row location data for each walker quantity used to populate "data_layout" field in HDF file ...
hsize_t hdf_file_pointer
HDF file pointer.

◆ resetBuffer()

void resetBuffer ( )
inline

resize the buffer to zero

Definition at line 150 of file WalkerLogBuffer.h.

Referenced by WalkerLogCollector::resetBuffers(), WalkerLogBuffer< WLog::Real >::WalkerLogBuffer(), and WalkerLogManager::writeBuffers().

150 { buffer.resize(0, buffer.size(1)); }
Array< T, 2 > buffer
the walker data buffer itself
void resize(const std::array< SIZET, D > &dims)
Resize the container.
Definition: OhmmsArray.h:65
size_t size() const
Definition: OhmmsArray.h:57

◆ resetCollect()

void resetCollect ( )
inline

reset member variables at end of each WalkerLogCollector::collect() call

Definition at line 153 of file WalkerLogBuffer.h.

154  {
155  if (quantity_index != quantity_info.size())
156  throw std::runtime_error(
157  "WalkerLogBuffer quantity_index has not been moved through all quantities prior during collect() call.");
158  first_collect = false;
159  quantity_index = 0;
160  }
bool first_collect
marks first WalkerLogCollector::collect() call
size_t quantity_index
index of current quantity during WalkerLogCollector::collect()
std::vector< WalkerQuantityInfo > quantity_info
buffer row location data for each walker quantity used to populate "data_layout" field in HDF file ...

◆ resetRowSize()

void resetRowSize ( size_t  row_size)
inlineprivate

make space as quantities are added to the buffer for the first time

Definition at line 359 of file WalkerLogBuffer.h.

Referenced by WalkerLogBuffer< WLog::Real >::addRow(), and WalkerLogBuffer< WLog::Real >::collect().

360  {
361  auto nrows = buffer.size(0);
362  if (nrows == 0)
363  nrows++;
364  if (nrows != 1)
365  throw std::runtime_error("WalkerLogBuffer::reset_rowsize row_size (number of columns) should only be changed "
366  "during growth of the first row.");
367  auto buffer_old(buffer);
368  buffer.resize(nrows, row_size);
369  std::copy_n(buffer_old.data(), buffer_old.size(), buffer.data());
370  if (buffer.size(0) != 1)
371  throw std::runtime_error(
372  "WalkerLogBuffer::reset_rowsize buffer should contain only a single row upon completion.");
373  if (buffer.size(1) != row_size)
374  throw std::runtime_error("WalkerLogBuffer::reset_rowsize length of buffer row should match the requested "
375  "row_size following the reset/udpate.");
376  }
Array< T, 2 > buffer
the walker data buffer itself
Type_t * data()
Definition: OhmmsArray.h:87
void resize(const std::array< SIZET, D > &dims)
Resize the container.
Definition: OhmmsArray.h:65
size_t size() const
Definition: OhmmsArray.h:57
size_t nrows()
current number of rows in the data buffer
sycl::event copy_n(sycl::queue &aq, const T1 *restrict VA, size_t array_size, T2 *restrict VC, const std::vector< sycl::event > &events)
Definition: syclBLAS.cpp:548

◆ sameAs()

bool sameAs ( const WalkerLogBuffer< T > &  ref)
inline

compare row size of this buffer to another one

Definition at line 163 of file WalkerLogBuffer.h.

Referenced by WalkerLogManager::checkCollectors().

163 { return buffer.size(1) == ref.buffer.size(1); }
Array< T, 2 > buffer
the walker data buffer itself
size_t size() const
Definition: OhmmsArray.h:57

◆ writeHDF() [1/2]

void writeHDF ( hdf_archive f)
inline

write the buffer data into the HDF file

Definition at line 338 of file WalkerLogBuffer.h.

Referenced by WalkerLogManager::writeBuffersHDF(), and WalkerLogBuffer< WLog::Real >::writeHDF().

338 { writeHDF(f, hdf_file_pointer); }
void writeHDF(hdf_archive &f)
write the buffer data into the HDF file
hsize_t hdf_file_pointer
HDF file pointer.

◆ writeHDF() [2/2]

void writeHDF ( hdf_archive f,
hsize_t &  file_pointer 
)
inline

write the buffer data into the HDF file

Definition at line 342 of file WalkerLogBuffer.h.

343  {
344  auto& top = label;
345  hsize_t dims[2];
346  dims[0] = buffer.size(0);
347  dims[1] = buffer.size(1);
348  if (dims[0] > 0)
349  {
350  f.push(top);
351  h5d_append(f.top(), "data", file_pointer, buffer.dim(), dims, buffer.data());
352  f.pop();
353  }
354  f.flush();
355  }
Array< T, 2 > buffer
the walker data buffer itself
bool h5d_append(hid_t grp, const std::string &aname, hsize_t &current, hsize_t ndims, const hsize_t *const dims, const T *const first, hsize_t chunk_size=1, hid_t xfer_plist=H5P_DEFAULT)
Type_t * data()
Definition: OhmmsArray.h:87
std::string label
label for this data in HDF file
size_t size() const
Definition: OhmmsArray.h:57
std::vector< int > dims
unsigned dim() const
Definition: OhmmsArray.h:55

◆ writeSummary()

void writeSummary ( std::string  pad = "  ")
inline

write a summary of quantities in the buffer

Definition at line 294 of file WalkerLogBuffer.h.

295  {
296  std::string pad2 = pad + " ";
297  std::string pad3 = pad2 + " ";
298  app_log() << std::endl;
299  app_log() << pad << "WalkerLogBuffer(" << label << ")" << std::endl;
300  app_log() << pad2 << "nrows = " << buffer.size(0) << std::endl;
301  app_log() << pad2 << "row_size = " << buffer.size(1) << std::endl;
302  for (size_t n = 0; n < quantity_info.size(); ++n)
303  {
304  auto& wqi = quantity_info[n];
305  app_log() << pad2 << "quantity " << n << ": " << wqi.dimension << " " << wqi.size << " " << wqi.unit_size
306  << " " << wqi.buffer_start << " " << wqi.buffer_end << " (" << wqi.name << ")" << std::endl;
307  }
308  app_log() << pad << "end WalkerLogBuffer(" << label << ")" << std::endl;
309  }
Array< T, 2 > buffer
the walker data buffer itself
std::ostream & app_log()
Definition: OutputManager.h:65
std::string label
label for this data in HDF file
std::vector< WalkerQuantityInfo > quantity_info
buffer row location data for each walker quantity used to populate "data_layout" field in HDF file ...
size_t size() const
Definition: OhmmsArray.h:57

Member Data Documentation

◆ buffer

◆ first_collect

◆ hdf_file_pointer

hsize_t hdf_file_pointer

◆ label

◆ quantity_index

◆ quantity_info

std::vector<WalkerQuantityInfo> quantity_info
private

buffer row location data for each walker quantity used to populate "data_layout" field in HDF file

Definition at line 127 of file WalkerLogBuffer.h.

Referenced by WalkerLogBuffer< WLog::Real >::addRow(), WalkerLogBuffer< WLog::Real >::collect(), WalkerLogBuffer< WLog::Real >::registerHDFData(), WalkerLogBuffer< WLog::Real >::resetCollect(), and WalkerLogBuffer< WLog::Real >::writeSummary().

◆ walker_data_size

size_t walker_data_size
private

total size of walker data stored in a buffer row

Definition at line 129 of file WalkerLogBuffer.h.

Referenced by WalkerLogBuffer< WLog::Real >::collect(), and WalkerLogBuffer< WLog::Real >::WalkerLogBuffer().


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