51 : RecordCount(0), my_comm_(c), max4ascii(8), FieldWidth(20)
53 app_log() <<
" Legacy constructor adding a default LocalEnergyEstimator for the MainEstimator " << std::endl;
61 [](
auto& oper_est) {
return oper_est->isListenerRequired(); });
64 template<
class EstInputType,
typename... Args>
67 if (has<EstInputType>(
input))
69 operator_ests_.push_back(std::make_unique<typename EstInputType::Consumer>(std::move(std::get<EstInputType>(
input)),
70 std::forward<Args>(args)...));
77 template<
class EstInputType,
typename... Args>
80 if (has<EstInputType>(
input))
82 auto estimator = std::make_unique<typename EstInputType::Consumer>(std::move(std::get<EstInputType>(
input)),
83 std::forward<Args>(args)...);
84 if (estimator->isMainEstimator())
100 : RecordCount(0), my_comm_(c), max4ascii(8), FieldWidth(20)
103 if (!(createEstimator<SpinDensityInput>(est_input,
pset.getLattice(),
pset.getSpeciesSet()) ||
104 createEstimator<MomentumDistributionInput>(est_input,
pset.getTotalNum(),
pset.getTwist(),
105 pset.getLattice()) ||
106 createEstimator<SelfHealingOverlapInput>(est_input,
twf) ||
107 createEstimator<OneBodyDensityMatricesInput>(est_input,
pset.getLattice(),
pset.getSpeciesSet(),
109 createEstimator<MagnetizationDensityInput>(est_input,
pset.getLattice()) ||
110 createEstimator<PerParticleHamiltonianLoggerInput>(est_input,
my_comm_->
rank())))
112 "cannot construct an estimator from estimator input object.");
115 if (!(createScalarEstimator<LocalEnergyInput>(
scalar_input, H) ||
116 createScalarEstimator<CSLocalEnergyInput>(
scalar_input, H) ||
117 createScalarEstimator<RMCLocalEnergyInput>(
scalar_input, H)))
119 "cannot construct a scalar estimator from scalar estimator input object.");
123 app_log() <<
" Adding a default LocalEnergyEstimator for the MainEstimator " << std::endl;
163 os <<
"EstimatorManager setup for this section:\n" 167 os <<
" ScalarEstimators:\n";
169 os <<
" " << scalar_est->getSubTypeStr() <<
'\n';
173 os <<
" General Estimators:\n";
175 os <<
" " << est->get_my_name() <<
'\n';
181 o.setf(std::ios::scientific, std::ios::floatfield);
182 o.setf(std::ios::left, std::ios::adjustfield);
190 for (
int i = 0; i < maxobjs; i++)
195 o.setf(std::ios::right, std::ios::adjustfield);
210 #if defined(DEBUG_ESTIMATOR_ARCHIVE) 213 std::array<char, 128> fname;
214 if (std::snprintf(fname.data(), fname.size(),
"%s.p%03d.scalar.dat",
my_comm_->
getName().c_str(),
216 throw std::runtime_error(
"Error generating filename");
217 DebugArchive = std::make_unique<std::ofstream>(fname.data());
224 fname.concat(
".scalar.dat");
225 Archive = std::make_unique<std::ofstream>(fname);
232 h_file = std::make_unique<hdf_archive>();
238 uope->registerOperatorEstimator(*
h_file);
273 assert(crowd_scalar_ests[0].size() ==
scalar_ests_.size());
277 for (
int icrowd = 0; icrowd < crowd_scalar_ests.size(); ++icrowd)
278 this_scalar_est_for_all_crowds.emplace_back(crowd_scalar_ests[icrowd][iop]);
292 for (
int icrowd = 0; icrowd < crowd_op_ests.size(); ++icrowd)
293 this_op_est_for_all_crowds.emplace_back(crowd_op_ests[icrowd][iop]);
305 std::vector<unsigned long> accepts_and_rejects(
my_comm_->
size() * 2, 0);
309 int64_t total_block_accept =
310 std::accumulate(accepts_and_rejects.begin(), accepts_and_rejects.begin() +
my_comm_->
size(), int64_t(0));
311 int64_t total_block_reject = std::accumulate(accepts_and_rejects.begin() +
my_comm_->
size(),
312 accepts_and_rejects.begin() +
my_comm_->
size() * 2, int64_t(0));
320 std::vector<double> reduce_buffer(n2, 0.0);
322 auto cur = reduce_buffer.begin();
329 my_comm_->comm.reduce_in_place_n(reduce_buffer.begin(), reduce_buffer.size(), std::plus<>{});
333 auto cur = reduce_buffer.begin();
345 static_cast<FullPrecRealType>(total_block_accept + total_block_reject);
357 for (
int o = 0; o <
h5desc.size(); ++o)
367 for (
int j = 0; j < maxobjs; j++)
381 for (
int iop = 0; iop < operator_data_sizes.size(); ++iop)
383 operator_data_sizes[iop] =
operator_ests_[iop]->get_data().size();
386 size_t nops = *(std::max_element(operator_data_sizes.begin(), operator_data_sizes.end())) + 1;
387 std::vector<RealType> operator_send_buffer;
388 std::vector<RealType> operator_recv_buffer;
389 operator_send_buffer.reserve(nops);
390 operator_recv_buffer.reserve(nops);
394 auto& data = estimator.get_data();
395 size_t adjusted_size = data.size() + 1;
396 operator_send_buffer.resize(adjusted_size, 0.0);
397 operator_recv_buffer.resize(adjusted_size, 0.0);
398 std::copy_n(data.begin(), data.size(), operator_send_buffer.begin());
399 operator_send_buffer[data.size()] = estimator.get_walkers_weight();
402 my_comm_->comm.reduce_n(operator_send_buffer.begin(), adjusted_size, operator_recv_buffer.begin(), std::plus<>{},
405 operator_recv_buffer = operator_send_buffer;
409 std::copy_n(operator_recv_buffer.begin(), data.size(), data.begin());
410 size_t reduced_walker_weights = operator_recv_buffer[data.size()];
445 var = tmp[2] / tmp[0] -
e *
e;
450 std::vector<std::string> extra_types;
451 std::vector<std::string> extra_names;
453 std::string MainEstimatorName(
"LocalEnergy");
456 std::string cname((
const char*)(cur->name));
457 if (cname ==
"estimator")
459 std::string est_type(
"none");
460 std::string est_name(MainEstimatorName);
461 std::string use_hdf5(
"yes");
463 hAttrib.
add(est_type,
"type");
464 hAttrib.
add(est_name,
"name");
465 hAttrib.
add(use_hdf5,
"hdf5");
467 if ((est_name == MainEstimatorName) || (est_name ==
"elocal"))
470 addMainEstimator(std::make_unique<LocalEnergyEstimator>(H, use_hdf5 ==
"yes"));
472 else if (est_name ==
"RMC")
476 hAttrib.
add(nobs,
"nobs");
481 else if (est_name ==
"CSLocalEnergy")
485 hAttrib.
add(nPsi,
"nPsi");
488 app_log() <<
" Adding a CSLocalEnergy estimator for the MainEstimator " << std::endl;
490 else if (est_name ==
"SpinDensityNew")
497 operator_ests_.emplace_back(std::make_unique<SpinDensityNew>(std::move(spdi),
pset.getSpeciesSet(), dl));
500 std::make_unique<SpinDensityNew>(std::move(spdi),
pset.getLattice(),
pset.getSpeciesSet(), dl));
502 else if (est_type ==
"MomentumDistribution")
506 operator_ests_.emplace_back(std::make_unique<MomentumDistribution>(std::move(mdi),
pset.getTotalNum(),
507 pset.getTwist(),
pset.getLattice(), dl));
509 else if (est_type ==
"OneBodyDensityMatrices")
515 pset.getSpeciesSet(),
twf.getSPOMap(),
518 else if (est_type ==
"MagnetizationDensity")
522 operator_ests_.emplace_back(std::make_unique<MagnetizationDensity>(std::move(magdensinput),
pset.getLattice()));
526 extra_types.push_back(est_type);
527 extra_names.push_back(est_name);
534 app_log() <<
" ::put Adding a default LocalEnergyEstimator for the MainEstimator " << std::endl;
538 if (!extra_types.empty())
540 app_log() <<
"\nUnrecognized estimators in input:" << std::endl;
541 for (
int i = 0; i < extra_types.size(); i++)
543 app_log() <<
" type: " << extra_types[i] <<
" name: " << extra_names[i] << std::endl;
546 throw UniformCommunicateError(
"Unrecognized estimators encountered in input. See log message for more details.");
554 app_log() <<
" EstimatorManagerNew replaced its main estimator with " << estimator->getSubTypeStr()
555 <<
" estimator." << std::endl;
void resize(size_type n, Type_t val=Type_t())
Resize the container.
int addScalarEstimator(std::unique_ptr< ScalarEstimatorBase > &&estimator)
add an Estimator
std::unique_ptr< std::ofstream > Archive
file handler to write data
void zeroOperatorEstimators()
OperatorEstimators need to be zeroed out after the block is finished.
ScalarEstimatorInputs & get_scalar_estimator_inputs()
void makeBlockAverages(unsigned long accept, unsigned long reject)
collect data and write
helper functions for EinsplineSetBuilder
int rank() const
return the rank
void writeOperatorEstimators()
Write OperatorEstimator data to *.stat.h5.
QTBase::RealType RealType
std::vector< std::unique_ptr< OperatorEstBase > > operator_ests_
OperatorEst Observables.
int max4ascii
number of maximum data for a scalar.dat
bool put(xmlNodePtr cur)
assign attributes to the set
Vector< RealType > AverageCache
cached block averages of the values
void addMainEstimator(std::unique_ptr< ScalarEstimatorBase > &&estimator)
std::vector< ObservableHelper > h5desc
convenient descriptors for hdf5
Collection of Local Energy Operators.
void stopDriverRun()
Stop the manager at the end of a driver run().
int weightInd
index for the block weight PropertyCache(weightInd)
static constexpr std::string_view error_tag_
std::unique_ptr< std::ofstream > DebugArchive
file handler to write data for debugging
int RecordCount
number of records in a block
EstimatorManagerInput emi(estimators_doc.getRoot())
void writeScalarH5()
write scalars to scalar.dat and h5
EstimatorManagerNew(const QMCHamiltonian &ham, Communicate *comm)
default constructor
int size() const
return the number of tasks
static RefVector< T > convertUPtrToRefVector(const UPtrVector< T > &ptr_list)
convert a vector of std::unique_ptrs<T> to a refvector<T>
void collectScalarEstimators(const std::vector< RefVector< ScalarEstimatorBase >> &scalar_ests)
Deals with possible free form scalar estimators.
void reduceOperatorEstimators()
do the rank wise reduction of the OperatorEstimators
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
bool createScalarEstimator(ScalarEstimatorInput &input, Args &&... args)
Construct scalar estimator of type matching the underlying ScalarEstimatorInput type Consumer and pus...
Wrapping information on parallelism.
std::vector< std::string > Names
Specialized paritlce class for atomistic simulations.
const std::string & getName() const
Native representation for DensityMatrices1B Estimator's inputs.
void makeConfigReport(std::ostream &os) const
Return a string with information about which estimators estimator manager is holding.
size_type size() const
return the current size
int acceptRatioInd
index for the accept counter PropertyCache(acceptInd)
void getApproximateEnergyVariance(RealType &e, RealType &var)
get the average of per-block energy and variance of all the blocks Note: this is not weighted average...
ScalarEstimatorBase::accumulator_type energyAccumulator
accumulator for the energy
Compilation units that construct QMCDriverInput need visibility to the actual input classes types in ...
int add(const std::string &aname)
~EstimatorManagerNew()
destructor
class to handle a set of attributes of an xmlNode
This a subclass for runtime errors that will occur on all ranks.
int cpuInd
index for the block cpu PropertyCache(cpuInd)
Vector< RealType > PropertyCache
cached block averages of properties, e.g. BlockCPU
define convenience functions for mpi operations.
void stopBlock(unsigned long accept, unsigned long reject, RealType block_weight)
unified: stop a block
ScalarEstimatorBase::accumulator_type varAccumulator
accumulator for the variance
std::variant< std::monostate, MomentumDistributionInput, SpinDensityInput, OneBodyDensityMatricesInput, SelfHealingOverlapInput, MagnetizationDensityInput, PerParticleHamiltonianLoggerInput > EstimatorInput
int sizeOfObservables() const
return the size of observables
OneBodyDensityMatricesInput obdmi(node)
void collectOperatorEstimators(const std::vector< RefVector< OperatorEstBase >> &op_ests)
Reduces OperatorEstimator data from Crowds to the manager's OperatorEstimator data.
void collectMainEstimators(const RefVector< ScalarEstimatorBase > &scalar_estimators)
At end of block collect the main scalar estimators for the entire rank.
EstimatorInputs & get_estimator_inputs()
bool createEstimator(EstimatorInput &input, Args &&... args)
Construct estimator of type matching the underlying EstimatorInput type Consumer and push its its uni...
Native representation for Spin Density Estimators inputs.
bool get_save_memory() const
UPtr< ScalarEstimatorBase > main_estimator_
main estimator i.e. some version of a local energy estimator.
RecordNamedProperty< RealType > BlockAverages
manager of scalar data
std::vector< std::reference_wrapper< T > > RefVector
Timer block_timer_
block timer
sycl::event copy_n(sycl::queue &aq, const T1 *restrict VA, size_t array_size, T2 *restrict VC, const std::vector< sycl::event > &events)
return_type result() const
return the sum
Class to represent a many-body trial wave function.
void reset()
reset the estimator
std::map< std::string, const std::unique_ptr< const SPOSet > > SPOMap
Input type for EstimatorManagerNew Parses Estimators level of input and and delegates child estimator...
void startDriverRun()
Start the manager at the beginning of a driver run().
DataLocality
data locality with respect to walker buffer
std::unique_ptr< hdf_archive > h_file
hdf5 handler
std::variant< std::monostate, LocalEnergyInput, CSLocalEnergyInput, RMCLocalEnergyInput > ScalarEstimatorInput
Communicate * my_comm_
communicator to handle communication
return_type count() const
return the count
declare a handler of DMC branching
bool explicitly_defined
true, the lattice is defined by the input instead of an artificial default
QMCTraits::FullPrecRealType FullPrecRealType
Abstract class for an estimator of a scalar operator.
void addHeader(std::ostream &o)
add header to an std::ostream
A collection of functions to help with the use of variants.
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
bool put(QMCHamiltonian &H, const ParticleSet &pset, const TrialWaveFunction &twf, xmlNodePtr cur)
process xml tag associated with estimators
RecordNamedProperty< RealType > BlockProperties
manager of property data
bool areThereListeners() const
Do any of the instantiated estimators in operator_ests_ listen to per particle hamiltonian values...
QMCTraits::FullPrecRealType RealType
This is to deal with vague expression of precision in legacy code. Don't use in new code...
Native representation for Momentum Distribution Estimators inputs.
std::vector< UPtr< ScalarEstimatorBase > > scalar_ests_
non main scalar estimators collecting simple scalars, are there any? with the removal of collectables...
void startBlock(int steps)
start a block
Declaration of QMCHamiltonian.