36 using std::placeholders::_1;
46 const std::optional<EstimatorManagerInput>& global_emi,
52 std::move(qmcdriver_input),
59 dmcdriver_input_(
input),
60 dmc_timers_(
"DMCBatched::")
71 template<CoordsType CT>
78 bool accumulate_this_step)
80 auto& ps_dispatcher =
crowd.dispatchers_.ps_dispatcher_;
81 auto& twf_dispatcher =
crowd.dispatchers_.twf_dispatcher_;
82 auto& ham_dispatcher =
crowd.dispatchers_.ham_dispatcher_;
88 crowd.get_walker_hamiltonians());
98 std::vector<bool> recompute_mask;
99 recompute_mask.reserve(
walkers.size());
101 if (awalker.wasTouched)
103 recompute_mask.push_back(
true);
104 awalker.wasTouched =
false;
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);
113 auto& pset_leader = walker_elecs.getLeader();
114 const int num_particles = pset_leader.getTotalNum();
129 std::vector<bool> isAccepted;
133 std::vector<FullPrecRealType> old_energies(
num_walkers);
135 old_energies[iw] =
walkers[iw].
get().Properties(WP::LOCALENERGY);
137 std::vector<RealType> rr_proposed(
num_walkers, 0.0);
138 std::vector<RealType> rr_accepted(
num_walkers, 0.0);
142 for (
int ig = 0; ig < pset_leader.groups(); ++ig)
147 twf_dispatcher.flex_prepareGroup(walker_twfs, walker_elecs, ig);
149 for (
int iat = pset_leader.first(ig); iat < pset_leader.last(ig); ++iat)
153 std::vector<int> walkers_who_have_been_on_wire(
num_walkers, 0);
154 for (
int iw = 0; iw <
walkers.size(); ++iw)
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;
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); });
170 twf_dispatcher.flex_evalGrad(walker_twfs, walker_elecs, iat, grads_now);
183 for (
int i = 0; i < rr.size(); ++i)
187 ps_dispatcher.flex_makeMove(walker_elecs, iat, drifts);
189 twf_dispatcher.flex_calcRatioGrad(walker_twfs, walker_elecs, iat, ratios, grads_new);
195 drifts_reverse += drifts;
199 auto checkPhaseChanged = [&sft](
const PsiValue& ratio,
int& is_reject) {
210 checkPhaseChanged(ratios[iw], rejects[iw]);
212 rr_proposed[iw] += rr[iw];
221 if ((!rejects[iw]) && prob[iw] >= std::numeric_limits<RealType>::epsilon() &&
225 isAccepted.push_back(
true);
226 rr_accepted[iw] += rr[iw];
231 isAccepted.push_back(
false);
234 twf_dispatcher.flex_accept_rejectMove(walker_twfs, walker_elecs, iat, isAccepted,
true);
236 ps_dispatcher.flex_accept_rejectMove<CT>(walker_elecs, iat, isAccepted);
240 twf_dispatcher.flex_completeUpdates(walker_twfs);
241 ps_dispatcher.flex_donePbyP(walker_elecs);
246 twf_dispatcher.flex_evaluateGL(walker_twfs, walker_elecs, recompute);
249 ps_dispatcher.flex_saveWalker(walker_elecs,
walkers);
255 std::vector<QMCHamiltonian::FullPrecRealType> new_energies(
256 ham_dispatcher.flex_evaluateWithToperator(walker_hamiltonians, walker_twfs, walker_elecs));
260 walker.resetProperty(
twf.getLogPsi(),
twf.getPhase(), local_energy, rr_acc, rr_prop, 1.0);
263 for (
int iw = 0; iw <
walkers.size(); ++iw)
265 resetSigNLocalEnergy(
walkers[iw], walker_twfs[iw], new_energies[iw], rr_accepted[iw], rr_proposed[iw]);
267 walkers[iw].get().Weight *= branch_weight;
268 if (rr_proposed[iw] > 0)
279 for (
int iw = 0; iw <
walkers.size(); ++iw)
280 walker_hamiltonians[iw].auxHevaluate(walker_elecs[iw],
walkers[iw]);
283 for (
int iw = 0; iw <
walkers.size(); ++iw)
284 walker_hamiltonians[iw].saveProperty(
walkers[iw].
get().getPropertyBase());
287 if (accumulate_this_step)
300 std::vector<int> walker_non_local_moves_accepted(
num_walkers, 0);
308 for (
int iw = 0; iw <
walkers.size(); ++iw)
310 walker_non_local_moves_accepted[iw] = walker_hamiltonians[iw].makeNonLocalMoves(walker_elecs[iw]);
312 if (walker_non_local_moves_accepted[iw] > 0)
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]);
321 if (moved_nonlocal_walkers.size())
323 twf_dispatcher.flex_evaluateGL(moved_nonlocal_walker_twfs, moved_nonlocal_walker_elecs,
false);
326 ps_dispatcher.flex_saveWalker(moved_nonlocal_walker_elecs, moved_nonlocal_walkers);
331 template void DMCBatched::advanceWalkers<CoordsType::POS>(
const StateForThread& sft,
333 DriverTimers& timers,
337 bool accumulate_this_step);
339 template void DMCBatched::advanceWalkers<CoordsType::POS_SPIN>(
const StateForThread& sft,
341 DriverTimers& timers,
345 bool accumulate_this_step);
356 if (
crowd.size() == 0)
359 auto& rng = context_for_steps[crowd_id]->get_random_gen();
360 crowd.setRNGForHamiltonian(rng);
365 const bool accumulate_this_step =
true;
368 advanceWalkers<CoordsType::POS_SPIN>(sft,
crowd, timers, dmc_timers, *context_for_steps[crowd_id],
369 recompute_this_step, accumulate_this_step);
371 advanceWalkers<CoordsType::POS>(sft,
crowd, timers, dmc_timers, *context_for_steps[crowd_id], recompute_this_step,
372 accumulate_this_step);
402 app_log() <<
" Creating the branching engine and walker controler" << std::endl;
404 app_log() <<
" Reference energy is updated using the " 406 <<
" scheme" << std::endl;
416 std::ostringstream o;
418 o <<
" Fixed population using reconfiguration method\n";
420 o <<
" Fluctuating population\n";
426 app_log() << o.str() << std::endl;
428 app_log() <<
" DMC Engine Initialization = " << init_timer.
elapsed() <<
" secs" << std::endl;
474 for (
int block = 0; block <
num_blocks; ++block)
499 dmc_state.
step = step;
522 bool stop_requested =
false;
525 stop_requested = runtimeControl.checkStop(dmc_loop);
529 app_log() << runtimeControl.generateProgressMessage(
"DMCBatched", block,
num_blocks);
533 app_log() << runtimeControl.generateStopMessage(
"DMCBatched", block);
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...
size_t steps_per_block_
actual number of steps per block
void setNonLocalMoves(xmlNodePtr cur)
set non local moves options
const ParticleSet & get_golden_electrons() const
NewTimer & hamiltonian_timer
WaveFunctionComponent::PsiValue PsiValue
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...
helper functions for EinsplineSetBuilder
int rank() const
return the rank
size_t getActiveWalkers() const
return the number of active walkers
NewTimer & init_walkers_timer
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.
void recordBlock(int block) override
record the state of the block
const MCPopulation & population
std::unique_ptr< WalkerControl > walker_controller_
walker controller for load-balance
IndexType get_requested_steps() const
WalkerLogInput walker_logs_input
walker logs input
QMCDriverNew Base class for Unified Drivers.
virtual void getDrifts(RealType tau, const std::vector< GradType > &qf, std::vector< PosType > &) const =0
size_t getTotalNum() const
DMCRefEnergyScheme get_refenergy_update_scheme() const
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()
A set of light weight walkers that are carried between driver sections and restart.
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)
Collection of Local Energy Operators.
static void scaleBySqrtTau(const TauParams< RT, CT > &taus, MCCoords< CT > &coords)
const std::string & get_non_local_move() const
To avoid 10's of arguments to runDMCStep.
Object to encapsulate appropriate tau derived parameters for a particular CoordsType specialization...
void stopRun()
close the logs file at the end of a run
std::vector< std::unique_ptr< T > > UPtrVector
Driver synchronized step context.
UPtrVector< QMCHamiltonian > & get_hamiltonians()
std::unique_ptr< EstimatorManagerNew > estimator_manager_
Observables manager Has very problematic owner ship and life cycle.
void print_mem(const std::string &title, std::ostream &log)
NewTimer & run_steps_timer
bool isfinite(float a)
return true if the value is finite.
The timers for the driver.
DMCTimers dmc_timers_
I think its better if these have there own type and variable name.
DriverDebugChecks get_debug_checks() const
std::bitset< QMC_MODE_MAX > qmc_driver_mode_
bits to classify QMCDriver
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.
IndexType get_max_age() const
NewTimer & movepbyp_timer
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
static RefVector< WalkerLogCollector > getWalkerLogCollectorRefs(const UPtrVector< Crowd > &crowds)
get refereces of active walker log collectors. If walker logging is disabled, the RefVector size can ...
void writeBuffers()
collect min/max/median walker data and write buffered walker log data to file
double norm(const zVec &c)
WalkerProperties::Indexes WP
static void initialLogEvaluation(int crowd_id, UPtrVector< Crowd > &crowds, UPtrVector< ContextForSteps > &step_context)
IndexType get_walkers_per_rank() const
WalkerConfigurations & walker_configs_ref_
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
const size_t steps_per_block
This a subclass for runtime errors that will occur on all ranks.
declaration of ProgressReportEngine
RealType get_spin_mass() const
double get_feedback() const
NewTimer & step_begin_recompute_timer
void setNonLocalMoveHandler(QMCHamiltonian &hamiltonian)
Thread local context for moving walkers.
QMCTraits::FullPrecRealType FullPrecRealType
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 ...
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
UPtrVector< ContextForSteps > step_contexts_
Per crowd move contexts, this is where the DistanceTables etc.
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
const DMCDriverInput dmcdriver_input_
DMCBatched(const ProjectData &project_data, QMCDriverInput &&qmcdriver_input, const std::optional< EstimatorManagerInput > &global_emi, DMCDriverInput &&input, WalkerConfigurations &wc, MCPopulation &&pop, Communicate *comm)
Constructor.
const std::vector< RealType > & get_ptclgrp_inv_mass() const
std::unique_ptr< T > UPtr
std::unique_ptr< DriftModifierBase > drift_modifier_
drift modifer
IndexType get_branch_interval() const
bool allow_walker_logs
whether to allow walker logs
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
std::vector< std::reference_wrapper< T > > RefVector
bool get_reconfiguration() const
NewTimer & production_timer
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
NewTimer & resource_timer
std::unique_ptr< SFNBranch > branch_engine_
branch engine
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
bool is_recomputing_block
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
static void runDMCStep(int crowd_id, const StateForThread &sft, DriverTimers &timers, DMCTimers &dmc_timers, UPtrVector< ContextForSteps > &move_context, UPtrVector< Crowd > &crowds)
SFNBranch & branch_engine
const QMCDriverInput & qmcdrv_input
IndexType get_blocks_between_recompute() const
UPtrVector< Crowd > crowds_
}@
void barrier_and_abort(const std::string &msg) const
QMCDriverInput qmcdriver_input_
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
std::ostream & app_debug_stream()
NewTimer & estimators_timer
A container class to represent a walker.
bool phaseChanged(RealType psi0) const
void process(xmlNodePtr cur) override
DMCBatched driver will eventually ignore cur.
bool get_measure_imbalance() const
void redistributeWalkers(WTTV &walker_consumers)
distributes walkers and their "cloned" elements to the elements of a vector of unique_ptr to "walker_...
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...
NewTimer & collectables_timer
int get_recalculate_properties_period() const
void makeGaussRandomWithEngine(ParticleAttrib< TinyVector< T, D >> &a, RG &rng)
IndexType recalculate_properties_period