Skip to content

Commit

Permalink
Merge branch 'QMCPACK:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
zenandrea authored May 3, 2022
2 parents 0b72c9e + 85251a9 commit 87eca12
Show file tree
Hide file tree
Showing 23 changed files with 392 additions and 51 deletions.
21 changes: 20 additions & 1 deletion src/Estimators/CSEnergyEstimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace qmcplusplus
* @param h QMCHamiltonian to define the components
* @param hcopy number of copies of QMCHamiltonians
*/
CSEnergyEstimator::CSEnergyEstimator(QMCHamiltonian& h, int hcopy)
CSEnergyEstimator::CSEnergyEstimator(const QMCHamiltonian& h, int hcopy)
{
int NumObservables = h.sizeOfObservables();

Expand All @@ -45,6 +45,25 @@ CSEnergyEstimator::CSEnergyEstimator(QMCHamiltonian& h, int hcopy)
scalars_saved.resize(scalars.size());
}

CSEnergyEstimator::CSEnergyEstimator(CSLocalEnergyInput&& input, const QMCHamiltonian& h) : input_(input)
{
int NumObservables = h.sizeOfObservables();

NumCopies = input_.get_n_psi();
FirstHamiltonian = h.startIndex();
LastHamiltonian = FirstHamiltonian + NumObservables;

//add names
h_components.push_back("LocEne");
h_components.push_back("LocPot");
for (int i = 0; i < NumObservables; ++i)
h_components.push_back(h.getObservableName(i));

scalars.resize(NumCopies + h_components.size() * (NumCopies + NumCopies * (NumCopies - 1) / 2));
scalars_saved.resize(scalars.size());
}


CSEnergyEstimator* CSEnergyEstimator::clone() { return new CSEnergyEstimator(*this); }

/** add the local energy, variance and all the Hamiltonian components to the scalar record container
Expand Down
13 changes: 10 additions & 3 deletions src/Estimators/CSEnergyEstimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// This file is distributed under the University of Illinois/NCSA Open Source License.
// See LICENSE file in top directory for details.
//
// Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
// Copyright (c) 2022 QMCPACK developers.
//
// File developed by: Ken Esler, [email protected], University of Illinois at Urbana-Champaign
// Jeongnim Kim, [email protected], University of Illinois at Urbana-Champaign
// Jeremy McMinnis, [email protected], University of Illinois at Urbana-Champaign
// Mark A. Berrill, [email protected], Oak Ridge National Laboratory
// Peter Doak, [email protected], Oak Ridge National Laboratory
//
// File created by: Jeongnim Kim, [email protected], University of Illinois at Urbana-Champaign
//////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -17,6 +18,7 @@
#define QMCPLUSPLUS_CORRELATEDLOCALENERGYESTIMATOR_H

#include "Estimators/ScalarEstimatorBase.h"
#include "ScalarEstimatorInputs.h"

namespace qmcplusplus
{
Expand Down Expand Up @@ -46,11 +48,14 @@ struct CSEnergyEstimator : public ScalarEstimatorBase
Matrix<RealType> tmp_data;
///name of hamiltonian components
std::vector<std::string> h_components;
const CSLocalEnergyInput input_;
/** constructor
* @param h QMCHamiltonian to define the components
* @param hcopy number of copies of QMCHamiltonians
*/
CSEnergyEstimator(QMCHamiltonian& h, int hcopy = 1);
CSEnergyEstimator(const QMCHamiltonian& h, int hcopy = 1);

CSEnergyEstimator(CSLocalEnergyInput&& input, const QMCHamiltonian& h);

inline RealType getUmbrellaWeight(int ipsi)
{
Expand Down Expand Up @@ -83,8 +88,10 @@ struct CSEnergyEstimator : public ScalarEstimatorBase
void add2Record(RecordNamedProperty<RealType>& record) override;
void registerObservables(std::vector<ObservableHelper>& h5dec, hid_t gid) override;
CSEnergyEstimator* clone() override;

const std::string& getSubTypeStr() const override { return input_.get_type(); }
void evaluateDiff();
// CSEnergyEstimator is the main estimator for
bool isMainEstimator() const override { return true; }
};

} // namespace qmcplusplus
Expand Down
3 changes: 3 additions & 0 deletions src/Estimators/CollectablesEstimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class CollectablesEstimator : public ScalarEstimatorBase
for (int i = 0; i < data.size(); ++i)
scalars[i](data[i], wgt);
}

const std::string type_str = "ColletiblesEstimatorNotSupportedInBatchedVersion";
const std::string& getSubTypeStr() const override { return type_str; }
};
} // namespace qmcplusplus
#endif
5 changes: 2 additions & 3 deletions src/Estimators/EstimatorInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
* Many variables have default values we don't want overwritten and that we want expressed in native c++
* Define macro to avoid repeating code for this lambda
*/
#define LAMBDA_setIfInInput [&](auto& var, const std::string& tag) -> bool { return input_section_.setIfInInput(var, tag); }
#define LAMBDA_setIfInInput \
[&](auto& var, const std::string& tag) -> bool { return input_section_.setIfInInput(var, tag); }

namespace qmcplusplus
{

namespace estimatorinput
{

void checkCenterCorner(InputSection& input_section, const std::string& error_tag);


} // namespace estimatorinput
} // namespace qmcplusplus
#endif
39 changes: 34 additions & 5 deletions src/Estimators/EstimatorManagerInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,59 @@ EstimatorManagerInput::EstimatorManagerInput(xmlNodePtr cur) { readXML(cur); }
void EstimatorManagerInput::readXML(xmlNodePtr cur)
{
const std::string error_tag{"EstimatorManager input:"};
xmlNodePtr child = cur->xmlChildrenNode;
std::string cur_name{lowerCase(castXMLCharToChar(cur->name))};
xmlNodePtr child;
if (cur_name == "estimators")
child = cur->xmlChildrenNode;
else
child = cur;
while (child != NULL)
{
std::string cname{lowerCase(castXMLCharToChar(child->name))};
if (cname == "estimator")
{
std::string atype(lowerCase(getXMLAttributeValue(child, "type")));
if (atype == "localenergy")
std::string aname(lowerCase(getXMLAttributeValue(child, "name")));
if (atype.empty() && !aname.empty())
atype = aname;
if (aname.empty() && !atype.empty())
aname = atype;
if (atype == "localenergy" || atype == "elocal")
appendScalarEstimatorInput<LocalEnergyInput>(child);
else if (atype == "cslocalenergy")
{
appendScalarEstimatorInput<CSLocalEnergyInput>(child);
app_warning() << "CSLocalEnergyEstimator support is at best experimental with batch drivers";
}
else if (atype == "rmc")
{
appendScalarEstimatorInput<RMCLocalEnergyInput>(child);
app_warning() << "RMCLocalEnergyEstimator support is at best experimental with batch drivers";
}
else if (atype == "onebodydensitymatrices")
appendEstimatorInput<OneBodyDensityMatricesInput>(child);
else if (atype == "spindensity")
appendEstimatorInput<SpinDensityInput>(child);
else if (atype == "momentumdistribution")
appendEstimatorInput<MomentumDistributionInput>(child);
else
throw UniformCommunicateError(error_tag + "unparsable child node, name: " + cname + " type: " + atype +
throw UniformCommunicateError(error_tag + "unparsable <estimator> node, name: " + aname + " type: " + atype +
" in Estimators input.");
}
else
else if (cname != "text")
{
std::string atype(lowerCase(getXMLAttributeValue(child, "type")));
std::string aname(lowerCase(getXMLAttributeValue(child, "name")));
throw UniformCommunicateError(error_tag + "<Estimators> can only contain <Estimator> nodes");
child = child->next;
}

if (cur_name == "estimators")
child = child->next;
else
{
app_summary() << "<estimator> nodes not contained in <estimators></estimators> is a deprecated input xml idiom";
break;
}
}
}

Expand Down
11 changes: 6 additions & 5 deletions src/Estimators/EstimatorManagerInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ using EstimatorInputs = std::vector<EstimatorInput>;
*/
class LocalEnergyInput;
class CSLocalEnergyInput;
using ScalarEstimatorInput = std::variant<LocalEnergyInput, CSLocalEnergyInput>;
class RMCLocalEnergyInput;
using ScalarEstimatorInput = std::variant<LocalEnergyInput, CSLocalEnergyInput, RMCLocalEnergyInput>;
using ScalarEstimatorInputs = std::vector<ScalarEstimatorInput>;

/** Input type for EstimatorManagerNew
Expand All @@ -62,8 +63,10 @@ class EstimatorManagerInput
EstimatorManagerInput(xmlNodePtr cur);
EstimatorInputs& get_estimator_inputs() { return estimator_inputs_; }
ScalarEstimatorInputs& get_scalar_estimator_inputs() { return scalar_estimator_inputs_; }
/** read <Estimators> node
* Note that this can be done multiple times to combine global and section local estimator inputs.

/** read <Estimators> node or (<estimators> node for legacy support)
* This can be done multiple times with <estimators> nodes
* or with <estimator> nodes to support deprecated bare <estimator> definitions
*/
void readXML(xmlNodePtr cur);

Expand All @@ -76,14 +79,12 @@ class EstimatorManagerInput
void appendEstimatorInput(Args&&... args)
{
estimator_inputs_.emplace_back(std::in_place_type<T>, std::forward<Args>(args)...);
;
}

template<typename T, typename... Args>
void appendScalarEstimatorInput(Args&&... args)
{
scalar_estimator_inputs_.emplace_back(std::in_place_type<T>, std::forward<Args>(args)...);
;
}

friend class testing::EstimatorManagerInputTests;
Expand Down
10 changes: 9 additions & 1 deletion src/Estimators/LocalEnergyEstimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@

namespace qmcplusplus
{
LocalEnergyEstimator::LocalEnergyEstimator(QMCHamiltonian& h, bool use_hdf5) : UseHDF5(use_hdf5), refH(h)
LocalEnergyEstimator::LocalEnergyEstimator(const QMCHamiltonian& h, bool use_hdf5) : UseHDF5(use_hdf5), refH(h)
{
SizeOfHamiltonians = h.sizeOfObservables();
FirstHamiltonian = h.startIndex();
scalars.resize(SizeOfHamiltonians + LE_MAX);
scalars_saved.resize(SizeOfHamiltonians + LE_MAX);
}

LocalEnergyEstimator::LocalEnergyEstimator(LocalEnergyInput&& input, const QMCHamiltonian& h) : UseHDF5(input.get_use_hdf5()), refH(h), input_(input)
{
SizeOfHamiltonians = h.sizeOfObservables();
FirstHamiltonian = h.startIndex();
scalars.resize(SizeOfHamiltonians + LE_MAX);
scalars_saved.resize(SizeOfHamiltonians + LE_MAX);
}

LocalEnergyEstimator* LocalEnergyEstimator::clone() { return new LocalEnergyEstimator(*this); }

void LocalEnergyEstimator::registerObservables(std::vector<ObservableHelper>& h5desc, hid_t gid)
Expand Down
17 changes: 14 additions & 3 deletions src/Estimators/LocalEnergyEstimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// This file is distributed under the University of Illinois/NCSA Open Source License.
// See LICENSE file in top directory for details.
//
// Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
// Copyright (c) 2022 QMCPACK developers.
//
// File developed by: Jeongnim Kim, [email protected], University of Illinois at Urbana-Champaign
// Jeremy McMinnis, [email protected], University of Illinois at Urbana-Champaign
// Mark A. Berrill, [email protected], Oak Ridge National Laboratory
// Peter Doak, [email protected], Oak Ridge National Laboratory
//
// File created by: Jeongnim Kim, [email protected], University of Illinois at Urbana-Champaign
//////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -18,6 +19,7 @@
#include "QMCHamiltonians/QMCHamiltonian.h"
#include "QMCDrivers/WalkerProperties.h"
#include "QMCHamiltonians/ObservableHelper.h"
#include "ScalarEstimatorInputs.h"

namespace qmcplusplus
{
Expand All @@ -40,13 +42,18 @@ class LocalEnergyEstimator : public ScalarEstimatorBase
int SizeOfHamiltonians;
bool UseHDF5;
const QMCHamiltonian& refH;
const LocalEnergyInput input_;

public:
/** constructor
* @param h QMCHamiltonian to define the components
*/
LocalEnergyEstimator(QMCHamiltonian& h, bool use_hdf5);

LocalEnergyEstimator(const QMCHamiltonian& h, bool use_hdf5);
/** Construct from LocalEnergyInput and const reference to hamiltonian.
* \param[in] LocalEnergyInput contains input parameters for LocalEnergyEstimator
* \param[in] is taken as a local reference and used to size scalars data
*/
LocalEnergyEstimator(LocalEnergyInput&& input, const QMCHamiltonian& ham);
/** accumulation per walker
* @param awalker current walker
* @param wgt weight
Expand Down Expand Up @@ -83,6 +90,10 @@ class LocalEnergyEstimator : public ScalarEstimatorBase
for (MCPWalker& walker : walkers)
accumulate(walker, 1.0);
}

/// LocalEnergyEstimator is the main estimator for VMC and DMC
bool isMainEstimator() const override { return true; }
const std::string& getSubTypeStr() const override { return input_.get_type(); }
};
} // namespace qmcplusplus
#endif
3 changes: 3 additions & 0 deletions src/Estimators/LocalEnergyOnlyEstimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ struct LocalEnergyOnlyEstimator : public ScalarEstimatorBase
}

LocalEnergyOnlyEstimator* clone() override { return new LocalEnergyOnlyEstimator(); }

const std::string type_str = "LocalEnergyOnlyEstimatorNotSupportedInBatchedVersion";
const std::string& getSubTypeStr() const override { return type_str; }
};
} // namespace qmcplusplus
#endif
17 changes: 13 additions & 4 deletions src/Estimators/RMCLocalEnergyEstimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@

namespace qmcplusplus
{
RMCLocalEnergyEstimator::RMCLocalEnergyEstimator(QMCHamiltonian& h, int nobs) : refH(h), NObs(nobs)
RMCLocalEnergyEstimator::RMCLocalEnergyEstimator(QMCHamiltonian& ham, int nobs) : refH(ham), NObs(nobs)
{
SizeOfHamiltonians = h.sizeOfObservables();
FirstHamiltonian = h.startIndex();
RMCSpecificTerms = 8;
resizeBasedOnHamiltonian(ham);
}

RMCLocalEnergyEstimator::RMCLocalEnergyEstimator(RMCLocalEnergyInput&& input, const QMCHamiltonian& ham) : refH(ham), NObs(input.get_n_obs()), input_(input)
{
resizeBasedOnHamiltonian(ham);
}

void RMCLocalEnergyEstimator::resizeBasedOnHamiltonian(const QMCHamiltonian& ham)
{
SizeOfHamiltonians = ham.sizeOfObservables();
FirstHamiltonian = ham.startIndex();
scalars.resize(2 * SizeOfHamiltonians + RMCSpecificTerms);
scalars_saved.resize(2 * SizeOfHamiltonians + RMCSpecificTerms);
}
Expand Down
25 changes: 18 additions & 7 deletions src/Estimators/RMCLocalEnergyEstimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This file is distributed under the University of Illinois/NCSA Open Source License.
// See LICENSE file in top directory for details.
//
// Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
// Copyright (c) 2022 QMCPACK developers.
//
// File developed by: Jeremy McMinnis, [email protected], University of Illinois at Urbana-Champaign
// Raymond Clay III, [email protected], Lawrence Livermore National Laboratory
Expand All @@ -18,7 +18,7 @@
#include "QMCHamiltonians/QMCHamiltonian.h"
#include "Particle/Reptile.h"
#include "QMCDrivers/WalkerProperties.h"

#include "ScalarEstimatorInputs.h"
namespace qmcplusplus
{
/** Class to accumulate the local energy and components
Expand All @@ -32,14 +32,21 @@ class RMCLocalEnergyEstimator : public ScalarEstimatorBase
int SizeOfHamiltonians;
const QMCHamiltonian& refH;
int NObs;
int RMCSpecificTerms;
int RMCSpecificTerms = 8;

// This is just to allow compilation batched version does not support RMC at this time.
const RMCLocalEnergyInput input_;
public:
/** constructor
* @param h QMCHamiltonian to define the components
*/
RMCLocalEnergyEstimator(QMCHamiltonian& h, int nobs = 2);

RMCLocalEnergyEstimator(QMCHamiltonian& ham, int nobs = 2);
/** Construct from LocalEnergyInput and const reference to hamiltonian.
* \param[in] RMCLocalEnergyEstimatorInput contains input parameters for RMCLocalEnergyEstimator
* \param[in] is taken as a local reference and used to size scalars data and to get obs output names
*/
RMCLocalEnergyEstimator(RMCLocalEnergyInput&& input, const QMCHamiltonian& ham);

/** accumulation per walker
* @param awalker current walker
* @param wgt weight
Expand All @@ -52,7 +59,6 @@ class RMCLocalEnergyEstimator : public ScalarEstimatorBase
{
throw std::runtime_error("RMC not supported by Unified Driver interfaces");
}
/*@{*/
inline void accumulate(const MCWalkerConfiguration& W,
WalkerIterator first,
WalkerIterator last,
Expand Down Expand Up @@ -144,7 +150,12 @@ class RMCLocalEnergyEstimator : public ScalarEstimatorBase
void add2Record(RecordListType& record) override;
void registerObservables(std::vector<ObservableHelper>& h5dec, hid_t gid) override {}
RMCLocalEnergyEstimator* clone() override;
/*@}*/
const std::string& getSubTypeStr() const override { return input_.get_type(); }
/// RMCLocalEnergyEstimator is the main estimator type for RMC driver
bool isMainEstimator() const override { return true; }

private:
void resizeBasedOnHamiltonian(const QMCHamiltonian& ham);
};
} // namespace qmcplusplus
#endif
Loading

0 comments on commit 87eca12

Please sign in to comment.