32 const std::optional<EstimatorManagerInput>& global_emi,
39 std::move(qmcdriver_input),
46 vmcdriver_input_(
input),
48 collect_samples_(false)
51 template<CoordsType CT>
57 bool accumulate_this_step)
59 if (
crowd.size() == 0)
61 auto& ps_dispatcher =
crowd.dispatchers_.ps_dispatcher_;
62 auto& twf_dispatcher =
crowd.dispatchers_.twf_dispatcher_;
63 auto& ham_dispatcher =
crowd.dispatchers_.ham_dispatcher_;
81 auto& walker_leader = walker_elecs.getLeader();
82 const int num_particles = walker_leader.getTotalNum();
88 std::vector<TrialWaveFunction::PsiValue> ratios(
num_walkers);
94 std::vector<bool> isAccepted;
95 std::vector<std::reference_wrapper<TrialWaveFunction>> twf_accept_list, twf_reject_list;
108 for (
int ig = 0; ig < walker_leader.groups(); ++ig)
113 twf_dispatcher.flex_prepareGroup(walker_twfs, walker_elecs, ig);
115 for (
int iat = walker_leader.first(ig); iat < walker_leader.last(ig); ++iat)
123 twf_dispatcher.flex_evalGrad(walker_twfs, walker_elecs, iat, grads_now);
130 ps_dispatcher.flex_makeMove(walker_elecs, iat, drifts);
135 twf_dispatcher.flex_calcRatioGrad(walker_twfs, walker_elecs, iat, ratios, grads_new);
141 drifts_reverse += drifts;
146 twf_dispatcher.flex_calcRatio(walker_twfs, walker_elecs, iat, ratios);
148 std::transform(ratios.begin(), ratios.end(), prob.begin(), [](
auto ratio) {
return std::norm(ratio); });
152 for (
int i_accept = 0; i_accept <
num_walkers; ++i_accept)
153 if (prob[i_accept] >= std::numeric_limits<RealType>::epsilon() &&
157 isAccepted.push_back(
true);
162 isAccepted.push_back(
false);
165 twf_dispatcher.flex_accept_rejectMove(walker_twfs, walker_elecs, iat, isAccepted,
true);
167 ps_dispatcher.flex_accept_rejectMove<CT>(walker_elecs, iat, isAccepted);
170 twf_dispatcher.flex_completeUpdates(walker_twfs);
173 ps_dispatcher.flex_donePbyP(walker_elecs);
178 twf_dispatcher.flex_evaluateGL(walker_twfs, walker_elecs, recompute);
184 crowd.get_walker_hamiltonians());
188 std::vector<QMCHamiltonian::FullPrecRealType> local_energies(
189 ham_dispatcher.flex_evaluate(walker_hamiltonians, walker_twfs, walker_elecs));
192 walker.resetProperty(
twf.getLogPsi(),
twf.getPhase(), local_energy);
194 for (
int iw = 0; iw <
crowd.size(); ++iw)
195 resetSigNLocalEnergy(
walkers[iw], walker_twfs[iw], local_energies[iw]);
203 for (
int iw = 0; iw <
crowd.size(); ++iw)
204 evaluateNonPhysicalHamiltonianElements(walker_hamiltonians[iw], walker_elecs[iw],
walkers[iw]);
209 for (
int iw = 0; iw <
crowd.size(); ++iw)
210 savePropertiesIntoWalker(walker_hamiltonians[iw],
walkers[iw]);
213 if (accumulate_this_step)
226 template void VMCBatched::advanceWalkers<CoordsType::POS>(
const StateForThread& sft,
231 bool accumulate_this_step);
233 template void VMCBatched::advanceWalkers<CoordsType::POS_SPIN>(
const StateForThread& sft,
238 bool accumulate_this_step);
250 crowd.setRNGForHamiltonian(context_for_steps[crowd_id]->get_random_gen());
255 const bool accumulate_this_step =
true;
258 advanceWalkers<CoordsType::POS_SPIN>(sft,
crowd, timers, *context_for_steps[crowd_id], recompute_this_step,
259 accumulate_this_step);
261 advanceWalkers<CoordsType::POS>(sft,
crowd, timers, *context_for_steps[crowd_id], recompute_this_step,
262 accumulate_this_step);
288 const size_t samples_per_block,
289 const size_t local_walkers)
291 return num_blocks * samples_per_block * local_walkers;
345 const bool recompute =
false;
346 const bool accumulate_this_step =
false;
347 const bool spin_move = sft.population.get_golden_electrons().isSpinor();
349 advanceWalkers<CoordsType::POS_SPIN>(sft,
crowd, timers, *context_for_steps[crowd_id], recompute,
350 accumulate_this_step);
352 advanceWalkers<CoordsType::POS>(sft,
crowd, timers, *context_for_steps[crowd_id], recompute,
353 accumulate_this_step);
363 app_log() <<
"VMC Warmup completed in " << std::setprecision(4) << warmup_timer.
elapsed() <<
" secs" << std::endl;
373 for (
int block = 0; block <
num_blocks; ++block)
391 vmc_state.
step = step;
398 for (
const auto&
walker : elec_psets)
413 bool stop_requested =
false;
416 stop_requested = runtimeControl.checkStop(vmc_loop);
420 app_log() << runtimeControl.generateProgressMessage(
"VMCBatched", block,
num_blocks);
424 app_log() << runtimeControl.generateStopMessage(
"VMCBatched", block);
442 std::ostringstream o;
445 o <<
"====================================================";
446 o <<
"\n End of a VMC section";
449 o <<
"\n reference energy = " << ene;
450 o <<
"\n reference variance = " << var;
451 o <<
"\n====================================================";
452 app_log() << o.str() << std::endl;
465 assert(
steps_per_block_ > 0 &&
"VMCBatched::enable_sample_collection steps_per_block_ must be positive!");
472 app_log() <<
"VMCBatched Driver collecting samples, samples per rank = " << samples << std::endl
473 <<
" total samples = " << total_samples << std::endl
RandomBase< FullPrecRealType > & get_random_gen()
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
Runs the actual VMC section.
size_t steps_per_block_
actual number of steps per block
const QMCDriverInput & qmcdrv_input
Stores particle configurations for later use in DMC and wavefunction optimization.
const ParticleSet & get_golden_electrons() const
NewTimer & hamiltonian_timer
void process(xmlNodePtr node) override
QMCDriverNew driver second (3rd, 4th...) stage of constructing a valid driver.
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
QMCTraits::FullPrecRealType FullPrecRealType
size_t getActiveWalkers() const
return the number of active walkers
NewTimer & init_walkers_timer
if(!okay) throw std xmlNodePtr node
Input representation for VMC driver class runtime parameters.
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
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
const size_t steps_per_block
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()
void saveProperty(IT first)
save the values of Hamiltonian elements to the Properties
A set of light weight walkers that are carried between driver sections and restart.
RunTimeManager< ChronoClock > run_time_manager
Collection of Local Energy Operators.
int get_num_ranks() const
The number of cases in which this and get_num_local_walkers is so few that I strongly suspect it is a...
static void scaleBySqrtTau(const TauParams< RT, CT > &taus, MCCoords< CT > &coords)
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.
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)
IndexType get_sub_steps() const
NewTimer & run_steps_timer
The timers for the driver.
DriverDebugChecks get_debug_checks() const
std::bitset< QMC_MODE_MAX > qmc_driver_mode_
bits to classify QMCDriver
store minimum Walker data
VMCBatched(const ProjectData &project_data, QMCDriverInput &&qmcdriver_input, const std::optional< EstimatorManagerInput > &global_emi, VMCDriverInput &&input, WalkerConfigurations &wc, MCPopulation &&pop, SampleStack &samples_, Communicate *comm)
Constructor.
bool collect_samples_
Sample collection flag.
Driver-level resource for walker log collection.
Wrapping information on parallelism.
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
Specialized paritlce class for atomistic simulations.
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
To avoid 10's of arguments to runVMCStep.
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
const MCPopulation & population
double norm(const zVec &c)
bool is_recomputing_block
static void initialLogEvaluation(int crowd_id, UPtrVector< Crowd > &crowds, UPtrVector< ContextForSteps > &step_context)
static void advanceWalkers(const StateForThread &sft, Crowd &crowd, DriverTimers &timers, ContextForSteps &move_context, bool recompute, bool accumulate_this_step)
Refactor of VMCUpdatePbyP in crowd 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 ...
Communicate * myComm
pointer to Communicate
void enable_sample_collection()
Enable collecting samples during the VMC run.
This a subclass for runtime errors that will occur on all ranks.
RealType get_spin_mass() const
const VMCDriverInput & vmcdrv_input
Thread local context for moving walkers.
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 std::vector< RealType > & get_ptclgrp_inv_mass() const
std::unique_ptr< DriftModifierBase > drift_modifier_
drift modifer
static void runVMCStep(int crowd_id, const StateForThread &sft, DriverTimers &timers, UPtrVector< ContextForSteps > &context_for_steps, UPtrVector< Crowd > &crowds)
Thread body for VMC step.
void setMaxSamples(size_t n, size_t number_of_ranks=1)
set the number of max samples per rank.
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
void auxHevaluate(ParticleSet &P)
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.
NewTimer & resource_timer
SampleStack & samples_
Storage for samples (later used in optimizer)
void appendSample(MCSample &&sample)
handles acquire/release resource by the consumer (RefVectorWithLeader type).
IndexType get_warmup_steps() const
IndexType get_max_blocks() const
const ProjectData & project_data_
project info for accessing global fileroot and series id
int getSeriesIndex() const noexcept
QMCTraits::RealType RealType
IndexType recalculate_properties_period
VMCDriverInput vmcdriver_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.
IndexType get_num_local_walkers() const
DriverTimers timers_
period of dumping walker configurations and everything else for restart
static size_t compute_samples_per_rank(const size_t num_blocks, const size_t samples_per_block, const size_t local_walkers)
function to calculate samples per MPI rank
UPtrVector< ParticleSet > & get_elec_particle_sets()
const DriftModifierBase & drift_modifier
std::ostream & app_debug_stream()
NewTimer & estimators_timer
A container class to represent a walker.
bool get_measure_imbalance() const
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.
bool get_use_drift() const
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)