QMCPACK
DMCBatched.cpp
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 //
9 // File refactored from: DMC.cpp
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 #include <functional>
13 #include <cassert>
14 #include <cmath>
15 
16 #include "DMCBatched.h"
19 #include "Concurrency/Info.hpp"
21 #include "Message/CommOperators.h"
26 #include "QMCDrivers/SFNBranch.h"
28 #include "MemoryUsage.h"
30 #include "TauParams.hpp"
31 #include "WalkerLogManager.h"
32 #include "CPU/math.hpp"
33 
34 namespace qmcplusplus
35 {
36 using std::placeholders::_1;
39 
40 /** Constructor maintains proper ownership of input parameters
41  *
42  * Note you must call the Base constructor before the derived class sets QMCType
43  */
44 DMCBatched::DMCBatched(const ProjectData& project_data,
45  QMCDriverInput&& qmcdriver_input,
46  const std::optional<EstimatorManagerInput>& global_emi,
49  MCPopulation&& pop,
51  : QMCDriverNew(project_data,
52  std::move(qmcdriver_input),
53  global_emi,
54  wc,
55  std::move(pop),
56  "DMCBatched::",
57  comm,
58  "DMCBatched"),
59  dmcdriver_input_(input),
60  dmc_timers_("DMCBatched::")
61 {}
62 
63 DMCBatched::~DMCBatched() = default;
64 
66 {
69 }
70 
71 template<CoordsType CT>
73  Crowd& crowd,
74  DriverTimers& timers,
75  DMCTimers& dmc_timers,
76  ContextForSteps& step_context,
77  bool recompute,
78  bool accumulate_this_step)
79 {
80  auto& ps_dispatcher = crowd.dispatchers_.ps_dispatcher_;
81  auto& twf_dispatcher = crowd.dispatchers_.twf_dispatcher_;
82  auto& ham_dispatcher = crowd.dispatchers_.ham_dispatcher_;
83 
84  auto& walkers = crowd.get_walkers();
85  const RefVectorWithLeader<ParticleSet> walker_elecs(crowd.get_walker_elecs()[0], crowd.get_walker_elecs());
86  const RefVectorWithLeader<TrialWaveFunction> walker_twfs(crowd.get_walker_twfs()[0], crowd.get_walker_twfs());
87  const RefVectorWithLeader<QMCHamiltonian> walker_hamiltonians(crowd.get_walker_hamiltonians()[0],
88  crowd.get_walker_hamiltonians());
89 
90  timers.resource_timer.start();
91  ResourceCollectionTeamLock<ParticleSet> pset_res_lock(crowd.getSharedResource().pset_res, walker_elecs);
92  ResourceCollectionTeamLock<TrialWaveFunction> twfs_res_lock(crowd.getSharedResource().twf_res, walker_twfs);
93  ResourceCollectionTeamLock<QMCHamiltonian> hams_res_lock(crowd.getSharedResource().ham_res, walker_hamiltonians);
94  timers.resource_timer.stop();
95 
96  {
97  ScopedTimer recompute_timer(dmc_timers.step_begin_recompute_timer);
98  std::vector<bool> recompute_mask;
99  recompute_mask.reserve(walkers.size());
100  for (MCPWalker& awalker : walkers)
101  if (awalker.wasTouched)
102  {
103  recompute_mask.push_back(true);
104  awalker.wasTouched = false;
105  }
106  else
107  recompute_mask.push_back(false);
108  ps_dispatcher.flex_loadWalker(walker_elecs, walkers, recompute_mask, true);
109  twf_dispatcher.flex_recompute(walker_twfs, walker_elecs, recompute_mask);
110  }
111 
112  const int num_walkers = crowd.size();
113  auto& pset_leader = walker_elecs.getLeader();
114  const int num_particles = pset_leader.getTotalNum();
115 
116  MCCoords<CT> drifts(num_walkers), drifts_reverse(num_walkers);
117  MCCoords<CT> walker_deltas(num_walkers * num_particles), deltas(num_walkers);
118  TWFGrads<CT> grads_now(num_walkers), grads_new(num_walkers);
119 
120  //This generates an entire steps worth of deltas.
121  makeGaussRandomWithEngine(walker_deltas, step_context.get_random_gen());
122 
123  std::vector<PsiValue> ratios(num_walkers, PsiValue(0.0));
124  std::vector<RealType> log_gf(num_walkers, 0.0);
125  std::vector<RealType> log_gb(num_walkers, 0.0);
126  std::vector<RealType> prob(num_walkers, 0.0);
127 
128  // local list to handle accept/reject
129  std::vector<bool> isAccepted;
130  isAccepted.reserve(num_walkers);
131 
132  //save the old energies for branching needs.
133  std::vector<FullPrecRealType> old_energies(num_walkers);
134  for (int iw = 0; iw < num_walkers; ++iw)
135  old_energies[iw] = walkers[iw].get().Properties(WP::LOCALENERGY);
136 
137  std::vector<RealType> rr_proposed(num_walkers, 0.0);
138  std::vector<RealType> rr_accepted(num_walkers, 0.0);
139 
140  {
141  ScopedTimer pbyp_local_timer(timers.movepbyp_timer);
142  for (int ig = 0; ig < pset_leader.groups(); ++ig)
143  {
146 
147  twf_dispatcher.flex_prepareGroup(walker_twfs, walker_elecs, ig);
148 
149  for (int iat = pset_leader.first(ig); iat < pset_leader.last(ig); ++iat)
150  {
151  //This is very useful thing to be able to look at in the debugger
152 #ifndef NDEBUG
153  std::vector<int> walkers_who_have_been_on_wire(num_walkers, 0);
154  for (int iw = 0; iw < walkers.size(); ++iw)
155  {
156  walkers[iw].get().get_has_been_on_wire() ? walkers_who_have_been_on_wire[iw] = 1
157  : walkers_who_have_been_on_wire[iw] = 0;
158  }
159 #endif
160  //get deltas for this particle for all walkers
161  walker_deltas.getSubset(iat * num_walkers, num_walkers, deltas);
162 
163  // only DMC does this
164  // TODO: rr needs a real name
165  std::vector<RealType> rr(num_walkers, 0.0);
166  assert(rr.size() == deltas.positions.size());
167  std::transform(deltas.positions.begin(), deltas.positions.end(), rr.begin(),
168  [t = taus.tauovermass](auto& delta_r) { return t * dot(delta_r, delta_r); });
169 
170  twf_dispatcher.flex_evalGrad(walker_twfs, walker_elecs, iat, grads_now);
171  sft.drift_modifier.getDrifts(taus, grads_now, drifts);
172 
173  scaleBySqrtTau(taus, deltas);
174  drifts += deltas;
175 
176 // in DMC this was done here, changed to match VMCBatched pending factoring to common source
177 // if (rr > m_r2max)
178 // {
179 // ++nRejectTemp;
180 // continue;
181 // }
182 #ifndef NDEBUG
183  for (int i = 0; i < rr.size(); ++i)
184  assert(qmcplusplus::isfinite(rr[i]));
185 #endif
186 
187  ps_dispatcher.flex_makeMove(walker_elecs, iat, drifts);
188 
189  twf_dispatcher.flex_calcRatioGrad(walker_twfs, walker_elecs, iat, ratios, grads_new);
190 
191  computeLogGreensFunction(deltas, taus, log_gf);
192 
193  sft.drift_modifier.getDrifts(taus, grads_new, drifts_reverse);
194 
195  drifts_reverse += drifts;
196 
197  computeLogGreensFunction(drifts_reverse, taus, log_gb);
198 
199  auto checkPhaseChanged = [&sft](const PsiValue& ratio, int& is_reject) {
200  if (ratio == PsiValue(0) || sft.branch_engine.phaseChanged(std::arg(ratio)))
201  is_reject = 1;
202  else
203  is_reject = 0;
204  };
205 
206  // Hopefully a phase change doesn't make any of these transformations fail.
207  std::vector<int> rejects(num_walkers); // instead of std::vector<bool>
208  for (int iw = 0; iw < num_walkers; ++iw)
209  {
210  checkPhaseChanged(ratios[iw], rejects[iw]);
211  //This is just convenient to do here
212  rr_proposed[iw] += rr[iw];
213  }
214 
215  for (int iw = 0; iw < num_walkers; ++iw)
216  prob[iw] = std::norm(ratios[iw]) * std::exp(log_gb[iw] - log_gf[iw]);
217 
218  isAccepted.clear();
219 
220  for (int iw = 0; iw < num_walkers; ++iw)
221  if ((!rejects[iw]) && prob[iw] >= std::numeric_limits<RealType>::epsilon() &&
222  step_context.get_random_gen()() < prob[iw])
223  {
224  crowd.incAccept();
225  isAccepted.push_back(true);
226  rr_accepted[iw] += rr[iw];
227  }
228  else
229  {
230  crowd.incReject();
231  isAccepted.push_back(false);
232  }
233 
234  twf_dispatcher.flex_accept_rejectMove(walker_twfs, walker_elecs, iat, isAccepted, true);
235 
236  ps_dispatcher.flex_accept_rejectMove<CT>(walker_elecs, iat, isAccepted);
237  }
238  }
239 
240  twf_dispatcher.flex_completeUpdates(walker_twfs);
241  ps_dispatcher.flex_donePbyP(walker_elecs);
242  }
243 
244  { // collect GL for KE.
245  ScopedTimer buffer_local(timers.buffer_timer);
246  twf_dispatcher.flex_evaluateGL(walker_twfs, walker_elecs, recompute);
248  checkLogAndGL(crowd, "checkGL_after_moves");
249  ps_dispatcher.flex_saveWalker(walker_elecs, walkers);
250  }
251 
252  { // hamiltonian
253  ScopedTimer ham_local(timers.hamiltonian_timer);
254 
255  std::vector<QMCHamiltonian::FullPrecRealType> new_energies(
256  ham_dispatcher.flex_evaluateWithToperator(walker_hamiltonians, walker_twfs, walker_elecs));
257 
258  auto resetSigNLocalEnergy = [](MCPWalker& walker, TrialWaveFunction& twf, auto local_energy, auto rr_acc,
259  auto rr_prop) {
260  walker.resetProperty(twf.getLogPsi(), twf.getPhase(), local_energy, rr_acc, rr_prop, 1.0);
261  };
262 
263  for (int iw = 0; iw < walkers.size(); ++iw)
264  {
265  resetSigNLocalEnergy(walkers[iw], walker_twfs[iw], new_energies[iw], rr_accepted[iw], rr_proposed[iw]);
266  FullPrecRealType branch_weight = sft.branch_engine.branchWeight(new_energies[iw], old_energies[iw]);
267  walkers[iw].get().Weight *= branch_weight;
268  if (rr_proposed[iw] > 0)
269  walkers[iw].get().Age = 0;
270  else
271  walkers[iw].get().Age++;
272  }
273  }
274 
275  { // estimator collectables
276  ScopedTimer collectable_local(timers.collectables_timer);
277 
278  // evaluate non-physical hamiltonian elements
279  for (int iw = 0; iw < walkers.size(); ++iw)
280  walker_hamiltonians[iw].auxHevaluate(walker_elecs[iw], walkers[iw]);
281 
282  // save properties into walker
283  for (int iw = 0; iw < walkers.size(); ++iw)
284  walker_hamiltonians[iw].saveProperty(walkers[iw].get().getPropertyBase());
285  }
286 
287  if (accumulate_this_step)
288  {
289  ScopedTimer est_timer(timers.estimators_timer);
290  crowd.accumulate(step_context.get_random_gen());
291  }
292 
293  // collect walker logs
294  crowd.collectStepWalkerLog(sft.global_step);
295 
296  { // T-moves
297  ScopedTimer tmove_timer(dmc_timers.tmove_timer);
298 
299  const auto num_walkers = walkers.size();
300  std::vector<int> walker_non_local_moves_accepted(num_walkers, 0);
301  RefVector<MCPWalker> moved_nonlocal_walkers;
302  RefVectorWithLeader<ParticleSet> moved_nonlocal_walker_elecs(crowd.get_walker_elecs()[0]);
303  RefVectorWithLeader<TrialWaveFunction> moved_nonlocal_walker_twfs(crowd.get_walker_twfs()[0]);
304  moved_nonlocal_walkers.reserve(num_walkers);
305  moved_nonlocal_walker_elecs.reserve(num_walkers);
306  moved_nonlocal_walker_twfs.reserve(num_walkers);
307 
308  for (int iw = 0; iw < walkers.size(); ++iw)
309  {
310  walker_non_local_moves_accepted[iw] = walker_hamiltonians[iw].makeNonLocalMoves(walker_elecs[iw]);
311 
312  if (walker_non_local_moves_accepted[iw] > 0)
313  {
314  crowd.incNonlocalAccept(walker_non_local_moves_accepted[iw]);
315  moved_nonlocal_walkers.push_back(walkers[iw]);
316  moved_nonlocal_walker_elecs.push_back(walker_elecs[iw]);
317  moved_nonlocal_walker_twfs.push_back(walker_twfs[iw]);
318  }
319  }
320 
321  if (moved_nonlocal_walkers.size())
322  {
323  twf_dispatcher.flex_evaluateGL(moved_nonlocal_walker_twfs, moved_nonlocal_walker_elecs, false);
325  checkLogAndGL(crowd, "checkGL_after_tmove");
326  ps_dispatcher.flex_saveWalker(moved_nonlocal_walker_elecs, moved_nonlocal_walkers);
327  }
328  }
329 }
330 
331 template void DMCBatched::advanceWalkers<CoordsType::POS>(const StateForThread& sft,
332  Crowd& crowd,
333  DriverTimers& timers,
334  DMCTimers& dmc_timers,
335  ContextForSteps& step_context,
336  bool recompute,
337  bool accumulate_this_step);
338 
339 template void DMCBatched::advanceWalkers<CoordsType::POS_SPIN>(const StateForThread& sft,
340  Crowd& crowd,
341  DriverTimers& timers,
342  DMCTimers& dmc_timers,
343  ContextForSteps& step_context,
344  bool recompute,
345  bool accumulate_this_step);
346 
347 void DMCBatched::runDMCStep(int crowd_id,
348  const StateForThread& sft,
349  DriverTimers& timers,
350  DMCTimers& dmc_timers,
351  UPtrVector<ContextForSteps>& context_for_steps,
352  UPtrVector<Crowd>& crowds)
353 {
354  Crowd& crowd = *(crowds[crowd_id]);
355 
356  if (crowd.size() == 0)
357  return;
358 
359  auto& rng = context_for_steps[crowd_id]->get_random_gen();
360  crowd.setRNGForHamiltonian(rng);
361 
362  const IndexType step = sft.step;
363  // Are we entering the the last step of a block to recompute at?
364  const bool recompute_this_step = (sft.is_recomputing_block && (step + 1) == sft.steps_per_block);
365  const bool accumulate_this_step = true;
366  const bool spin_move = sft.population.get_golden_electrons().isSpinor();
367  if (spin_move)
368  advanceWalkers<CoordsType::POS_SPIN>(sft, crowd, timers, dmc_timers, *context_for_steps[crowd_id],
369  recompute_this_step, accumulate_this_step);
370  else
371  advanceWalkers<CoordsType::POS>(sft, crowd, timers, dmc_timers, *context_for_steps[crowd_id], recompute_this_step,
372  accumulate_this_step);
373 }
374 
375 void DMCBatched::process(xmlNodePtr node)
376 {
377  print_mem("DMCBatched before initialization", app_log());
378  try
379  {
384 
388 
389  Base::initializeQMC(awc);
390  }
391  catch (const UniformCommunicateError& ue)
392  {
393  myComm->barrier_and_abort(ue.what());
394  }
395 
396  {
397  ReportEngine PRE("DMC", "resetUpdateEngines");
398  Timer init_timer;
399  // Here DMC loads "Ensemble of cloned MCWalkerConfigurations"
400  // I'd like to do away with this method in DMCBatched.
401 
402  app_log() << " Creating the branching engine and walker controler" << std::endl;
403  const auto refE_update_scheme = dmcdriver_input_.get_refenergy_update_scheme();
404  app_log() << " Reference energy is updated using the "
405  << (refE_update_scheme == DMCRefEnergyScheme::UNLIMITED_HISTORY ? "unlimited_history" : "limited_history")
406  << " scheme" << std::endl;
408  std::make_unique<SFNBranch>(qmcdriver_input_.get_tau(), dmcdriver_input_.get_feedback(), refE_update_scheme);
409  branch_engine_->put(node);
410 
411  walker_controller_ = std::make_unique<WalkerControl>(myComm, Random, dmcdriver_input_.get_reconfiguration());
413  walker_controller_->start();
414  walker_controller_->put(node);
415 
416  std::ostringstream o;
418  o << " Fixed population using reconfiguration method\n";
419  else
420  o << " Fluctuating population\n";
421 
422  o << " Persistent walkers are killed after " << dmcdriver_input_.get_max_age() << " MC sweeps\n";
423  o << " BranchInterval = " << dmcdriver_input_.get_branch_interval() << "\n";
424  o << " Steps per block = " << steps_per_block_ << "\n";
425  o << " Number of blocks = " << qmcdriver_input_.get_max_blocks() << "\n";
426  app_log() << o.str() << std::endl;
427 
428  app_log() << " DMC Engine Initialization = " << init_timer.elapsed() << " secs" << std::endl;
429  }
430 }
431 
433 {
435 
436  estimator_manager_->startDriverRun();
437 
438  //initialize WalkerLogManager and collectors
440  for (auto& crowd : crowds_)
441  crowd->setWalkerLogCollector(wlog_manager.makeCollector());
442  //register walker log collectors into the manager
444 
446 
447  LoopTimer<> dmc_loop;
449  myComm->rank() == 0);
450 
451  { // walker initialization
453  ParallelExecutor<> section_start_task;
454  section_start_task(crowds_.size(), initialLogEvaluation, std::ref(crowds_), std::ref(step_contexts_));
455 
456  FullPrecRealType energy, variance;
457  population_.measureGlobalEnergyVariance(*myComm, energy, variance);
458  // false indicates we do not support kill at node crossings.
459  branch_engine_->initParam(population_, energy, variance, dmcdriver_input_.get_reconfiguration(), false);
460  walker_controller_->setTrialEnergy(branch_engine_->getEtrial());
461 
462  print_mem("DMCBatched after initialLogEvaluation", app_summary());
464  measureImbalance("InitialLogEvaluation");
465  }
466 
467  // this barrier fences all previous load imbalance. Avoid block 0 timing pollution.
468  myComm->barrier();
469 
470  ScopedTimer local_timer(timers_.production_timer);
471  ParallelExecutor<> crowd_task;
472 
473  int global_step = 0;
474  for (int block = 0; block < num_blocks; ++block)
475  {
476  {
477  ScopeGuard<LoopTimer<>> dmc_local_timer(dmc_loop);
479 
484  ? (1 + block) % qmcdriver_input_.get_blocks_between_recompute() == 0
485  : false;
486 
487  for (UPtr<Crowd>& crowd : crowds_)
488  crowd->startBlock(steps_per_block_);
489 
490  for (int step = 0; step < steps_per_block_; ++step, ++global_step)
491  {
492  ScopedTimer local_timer(timers_.run_steps_timer);
493 
494  // ensure all the live walkers carry the up-to-date T-move settings.
495  // Such info should be removed from each NLPP eventually and be kept in the driver.
498 
499  dmc_state.step = step;
500  dmc_state.global_step = global_step;
501  crowd_task(crowds_.size(), runDMCStep, dmc_state, timers_, dmc_timers_, std::ref(step_contexts_),
502  std::ref(crowds_));
503 
504  {
505  const int iter = block * steps_per_block_ + step;
506  walker_controller_->branch(iter, population_, iter == 0);
507  branch_engine_->updateParamAfterPopControl(walker_controller_->get_ensemble_property(),
509  walker_controller_->setTrialEnergy(branch_engine_->getEtrial());
510  }
511 
513  }
514  print_mem("DMCBatched after a block", app_debug_stream());
516  measureImbalance("Block " + std::to_string(block));
517  endBlock();
518  wlog_manager.writeBuffers();
519  recordBlock(block);
520  }
521 
522  bool stop_requested = false;
523  // Rank 0 decides whether the time limit was reached
524  if (!myComm->rank())
525  stop_requested = runtimeControl.checkStop(dmc_loop);
526  myComm->bcast(stop_requested);
527  // Progress messages before possibly stopping
528  if (!myComm->rank())
529  app_log() << runtimeControl.generateProgressMessage("DMCBatched", block, num_blocks);
530  if (stop_requested)
531  {
532  if (!myComm->rank())
533  app_log() << runtimeControl.generateStopMessage("DMCBatched", block);
534  run_time_manager.markStop();
535  break;
536  }
537  }
538 
539  branch_engine_->printStatus();
540 
541  print_mem("DMCBatched ends", app_log());
542 
543  wlog_manager.stopRun();
544  estimator_manager_->stopDriverRun();
545 
546  return finalize(num_blocks, true);
547 }
548 
549 } // namespace qmcplusplus
RandomBase< FullPrecRealType > & get_random_gen()
WaveFunctionComponent::PsiValue PsiValue
const std::string & getTitle() const noexcept
returns the title of the project <project id="det_qmc_short_sdbatch_vmcbatch_mwalkers" series="0"> tr...
bool run() override
Definition: DMCBatched.cpp:432
size_t steps_per_block_
actual number of steps per block
Definition: QMCDriverNew.h:407
double elapsed() const
Definition: Timer.h:30
void setNonLocalMoves(xmlNodePtr cur)
set non local moves options
const ParticleSet & get_golden_electrons() const
Definition: MCPopulation.h:176
void barrier() const
WaveFunctionComponent::PsiValue PsiValue
Definition: SlaterDet.cpp:25
Abstraction of information on executor environments.
MCPopulation population_
the entire (on node) walker population it serves VMCBatch and DMCBatch right now but will be polymorp...
Definition: QMCDriverNew.h:426
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
int rank() const
return the rank
Definition: Communicate.h:116
size_t getActiveWalkers() const
return the number of active walkers
if(!okay) throw std xmlNodePtr node
Abstraction for running concurrent tasks in parallel by an executor executor workers can be OpenMP th...
This is a data structure strictly for QMCDriver and its derived classes.
Definition: QMCDriverNew.h:116
void recordBlock(int block) override
record the state of the block
std::unique_ptr< WalkerControl > walker_controller_
walker controller for load-balance
Definition: DMCBatched.h:142
IndexType get_requested_steps() const
WalkerLogInput walker_logs_input
walker logs input
Definition: QMCDriverNew.h:108
QMCDriverNew Base class for Unified Drivers.
Definition: QMCDriverNew.h:75
virtual void getDrifts(RealType tau, const std::vector< GradType > &qf, std::vector< PosType > &) const =0
size_t getTotalNum() const
Definition: ParticleSet.h:493
std::ostream & app_log()
Definition: OutputManager.h:65
DMCRefEnergyScheme get_refenergy_update_scheme() const
class ProjectData
Definition: ProjectData.h:36
void startRun(RefVector< WalkerLogCollector > &&collectors)
open the logs file and check consistency of the collectors at the start of a run
std::ostream & app_summary()
Definition: OutputManager.h:63
A set of light weight walkers that are carried between driver sections and restart.
const char num_walkers[]
Definition: HDFVersion.h:37
RealType get_reserve() const
RunTimeManager< ChronoClock > run_time_manager
static void advanceWalkers(const StateForThread &sft, Crowd &crowd, DriverTimers &timers, DMCTimers &dmc_timers, ContextForSteps &move_context, bool recompute, bool accumulate_this_step)
Definition: DMCBatched.cpp:72
const char num_blocks[]
Definition: HDFVersion.h:44
Collection of Local Energy Operators.
static void scaleBySqrtTau(const TauParams< RT, CT > &taus, MCCoords< CT > &coords)
Definition: QMCDriverNew.h:257
const std::string & get_non_local_move() const
To avoid 10&#39;s of arguments to runDMCStep.
Definition: DMCBatched.h:47
Object to encapsulate appropriate tau derived parameters for a particular CoordsType specialization...
Definition: TauParams.hpp:25
void stopRun()
close the logs file at the end of a run
std::vector< std::unique_ptr< T > > UPtrVector
#define Random
const char walkers[]
Definition: HDFVersion.h:36
Driver synchronized step context.
Definition: Crowd.h:38
UPtrVector< QMCHamiltonian > & get_hamiltonians()
Definition: MCPopulation.h:203
std::unique_ptr< EstimatorManagerNew > estimator_manager_
Observables manager Has very problematic owner ship and life cycle.
Definition: QMCDriverNew.h:443
void print_mem(const std::string &title, std::ostream &log)
Definition: MemoryUsage.cpp:30
bool isfinite(float a)
return true if the value is finite.
Definition: math.cpp:21
The timers for the driver.
Definition: QMCDriverNew.h:338
DMCTimers dmc_timers_
I think its better if these have there own type and variable name.
Definition: DMCBatched.h:136
DriverDebugChecks get_debug_checks() const
std::bitset< QMC_MODE_MAX > qmc_driver_mode_
bits to classify QMCDriver
Definition: QMCDriverNew.h:103
Input representation for DMC driver class runtime parameters.
Driver-level resource for walker log collection.
void measureGlobalEnergyVariance(Communicate &comm, FullPrecRealType &ener, FullPrecRealType &variance) const
Wrapping information on parallelism.
Definition: Communicate.h:68
IndexType get_max_age() const
IndexType get_num_crowds() const
static size_t determineStepsPerBlock(IndexType global_walkers, IndexType requested_samples, IndexType requested_steps, IndexType blocks)
pure function calculating the actual number of steps per block
bool finalize(int block, bool dumpwalkers=true)
finalize a qmc section
IndexType get_total_walkers() const
int getMaxCPUSeconds() const noexcept
const std::string & get_root_name() const override
Definition: QMCDriverNew.h:331
static RefVector< WalkerLogCollector > getWalkerLogCollectorRefs(const UPtrVector< Crowd > &crowds)
get refereces of active walker log collectors. If walker logging is disabled, the RefVector size can ...
Definition: Crowd.cpp:106
void writeBuffers()
collect min/max/median walker data and write buffered walker log data to file
double norm(const zVec &c)
Definition: VectorOps.h:118
WalkerProperties::Indexes WP
Definition: ParticleSet.cpp:34
static void initialLogEvaluation(int crowd_id, UPtrVector< Crowd > &crowds, UPtrVector< ContextForSteps > &step_context)
IndexType get_walkers_per_rank() const
WalkerConfigurations & walker_configs_ref_
Definition: QMCDriverNew.h:481
Compilation units that construct QMCDriverInput need visibility to the actual input classes types in ...
Final class and should not be derived.
Communicate * myComm
pointer to Communicate
Definition: MPIObjectBase.h:62
This a subclass for runtime errors that will occur on all ranks.
declaration of ProgressReportEngine
RealType get_spin_mass() const
void setNonLocalMoveHandler(QMCHamiltonian &hamiltonian)
Definition: DMCBatched.cpp:65
Thread local context for moving walkers.
QMCTraits::FullPrecRealType FullPrecRealType
Definition: DMCBatched.h:39
static void computeLogGreensFunction(const MCCoords< CT > &coords, const TauParams< RT, CT > &taus, std::vector< QMCTraits::RealType > &log_gb)
calculates Green Function from displacements stored in MCCoords [param, out] log_g ...
Definition: QMCDriverNew.h:270
static QMCDriverNew::AdjustedWalkerCounts adjustGlobalWalkerCount(Communicate &comm, const IndexType current_configs, const IndexType requested_total_walkers, const IndexType requested_walkers_per_rank, const RealType reserve_walkers, int num_crowds)
}@
QMCTraits::IndexType IndexType
Definition: QMCDriverNew.h:79
UPtrVector< ContextForSteps > step_contexts_
Per crowd move contexts, this is where the DistanceTables etc.
Definition: QMCDriverNew.h:450
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
const DMCDriverInput dmcdriver_input_
Definition: DMCBatched.h:132
DMCBatched(const ProjectData &project_data, QMCDriverInput &&qmcdriver_input, const std::optional< EstimatorManagerInput > &global_emi, DMCDriverInput &&input, WalkerConfigurations &wc, MCPopulation &&pop, Communicate *comm)
Constructor.
Definition: DMCBatched.cpp:44
const std::vector< RealType > & get_ptclgrp_inv_mass() const
Definition: MCPopulation.h:224
std::unique_ptr< T > UPtr
std::unique_ptr< DriftModifierBase > drift_modifier_
drift modifer
Definition: QMCDriverNew.h:394
IndexType get_branch_interval() const
bool allow_walker_logs
whether to allow walker logs
Definition: QMCDriverNew.h:106
static void checkLogAndGL(Crowd &crowd, const std::string_view location)
check logpsi and grad and lap against values computed from scratch
const DriftModifierBase & drift_modifier
Definition: DMCBatched.h:50
std::vector< std::reference_wrapper< T > > RefVector
Class for determining elapsed run time enabling simulations to adjust to time limits.
Class to represent a many-body trial wave function.
IndexType get_num_global_walkers() const
Definition: MCPopulation.h:168
std::unique_ptr< SFNBranch > branch_engine_
branch engine
Definition: DMCBatched.h:140
Indexes
an enum denoting index of physical properties
RealType branchWeight(FullPrecRealType enew, FullPrecRealType eold) const
return the bare branch weight with a filtering using an energy window
Definition: SFNBranch.h:199
handles acquire/release resource by the consumer (RefVectorWithLeader type).
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
IndexType get_max_blocks() const
const ProjectData & project_data_
project info for accessing global fileroot and series id
Definition: QMCDriverNew.h:478
void bcast(T &)
static void runDMCStep(int crowd_id, const StateForThread &sft, DriverTimers &timers, DMCTimers &dmc_timers, UPtrVector< ContextForSteps > &move_context, UPtrVector< Crowd > &crowds)
Definition: DMCBatched.cpp:347
const QMCDriverInput & qmcdrv_input
Definition: DMCBatched.h:49
IndexType get_blocks_between_recompute() const
UPtrVector< Crowd > crowds_
}@
Definition: QMCDriverNew.h:389
void barrier_and_abort(const std::string &msg) const
QMCDriverInput qmcdriver_input_
Definition: QMCDriverNew.h:372
IndexType get_requested_samples() const
void measureImbalance(const std::string &tag) const
inject additional barrier and measure load imbalance.
DriverTimers timers_
period of dumping walker configurations and everything else for restart
Definition: QMCDriverNew.h:472
std::ostream & app_debug_stream()
Definition: OutputManager.h:71
A container class to represent a walker.
Definition: Walker.h:49
bool phaseChanged(RealType psi0) const
Definition: SFNBranch.h:161
void process(xmlNodePtr cur) override
DMCBatched driver will eventually ignore cur.
Definition: DMCBatched.cpp:375
void redistributeWalkers(WTTV &walker_consumers)
distributes walkers and their "cloned" elements to the elements of a vector of unique_ptr to "walker_...
Definition: MCPopulation.h:131
void initializeQMC(const AdjustedWalkerCounts &awc)
Do common section starting tasks for VMC and DMC.
std::unique_ptr< WalkerLogCollector > makeCollector() const
create a WalkerLogCollector
Input representation for Driver base class runtime parameters.
void endBlock()
end of a block operations. Aggregates statistics across all MPI ranks and write to disk...
int get_recalculate_properties_period() const
void makeGaussRandomWithEngine(ParticleAttrib< TinyVector< T, D >> &a, RG &rng)