Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix single det + WFOpt #2683

Merged
merged 4 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/QMCDrivers/WFOpt/QMCCostFunctionBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ class QMCCostFunctionBase : public CostFunctionBase<QMCTraits::RealType>, public

inline const opt_variables_type& getOptVariables() const { return OptVariables; }

/// return variance after checkConfigurations
inline Return_rt getVariance() const
{
return SumValue[SUM_ESQ_WGT] / SumValue[SUM_WGT] -
(SumValue[SUM_E_WGT] / SumValue[SUM_WGT]) * (SumValue[SUM_E_WGT] / SumValue[SUM_WGT]);
}

protected:
///walker ensemble
MCWalkerConfiguration& W;
Expand Down
72 changes: 40 additions & 32 deletions src/QMCDrivers/WFOpt/QMCLinearOptimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,28 +79,35 @@ void QMCLinearOptimize::addConfiguration(const std::string& a)

void QMCLinearOptimize::start()
{
//close files automatically generated by QMCDriver
// branchEngine->finalize();
//generate samples
generate_samples_timer_.start();
generateSamples();
generate_samples_timer_.stop();
//store active number of walkers
NumOfVMCWalkers = W.getActiveWalkers();
{
//generate samples
ScopedTimer local(&generate_samples_timer_);
generateSamples();
//store active number of walkers
NumOfVMCWalkers = W.getActiveWalkers();
}

app_log() << "<opt stage=\"setup\">" << std::endl;
app_log() << " <log>" << std::endl;
//reset the rootname
optTarget->setRootName(RootName);
optTarget->setWaveFunctionNode(wfNode);
app_log() << " Reading configurations from h5FileRoot " << h5FileRoot << std::endl;
//get configuration from the previous run
Timer t1;
initialize_timer_.start();
optTarget->getConfigurations(h5FileRoot);
optTarget->setRng(vmcEngine->getRng());
optTarget->checkConfigurations();
initialize_timer_.stop();
app_log() << " Execution time = " << std::setprecision(4) << t1.elapsed() << std::endl;
{
//get configuration from the previous run
ScopedTimer local(&initialize_timer_);
Timer t2;
optTarget->getConfigurations(h5FileRoot);
optTarget->setRng(vmcEngine->getRng());
optTarget->checkConfigurations();
// check recomputed variance against VMC
auto sigma2_vmc = vmcEngine->getBranchEngine()->vParam[SimpleFixedNodeBranch::SBVP::SIGMA2];
auto sigma2_check = optTarget->getVariance();
if (sigma2_check > 2.0 * sigma2_vmc || sigma2_check < 0.5 * sigma2_vmc)
throw std::runtime_error(
"Safeguard failure: checkConfigurations variance out of [0.5, 2.0] * reference! Please report this bug.\n");
app_log() << " Execution time = " << std::setprecision(4) << t2.elapsed() << std::endl;
}
app_log() << " </log>" << std::endl;
app_log() << "</opt>" << std::endl;
app_log() << "<opt stage=\"main\" walkers=\"" << optTarget->getNumSamples() << "\">" << std::endl;
Expand All @@ -115,30 +122,31 @@ void QMCLinearOptimize::engine_start(cqmc::engine::LMYEngine<ValueType>* EngineO
{
app_log() << "entering engine_start function" << std::endl;

// generate samples
generate_samples_timer_.start();
generateSamples();
generate_samples_timer_.stop();
{
//generate samples
ScopedTimer local(&generate_samples_timer_);
generateSamples();
//store active number of walkers
NumOfVMCWalkers = W.getActiveWalkers();
}

// store active number of walkers
NumOfVMCWalkers = W.getActiveWalkers();
app_log() << "<opt stage=\"setup\">" << std::endl;
app_log() << " <log>" << std::endl;

// reset the root name
optTarget->setRootName(RootName);
optTarget->setWaveFunctionNode(wfNode);
app_log() << " Reading configurations from h5FileRoot " << h5FileRoot << std::endl;

// get configuration from the previous run
Timer t1;
initialize_timer_.start();
optTarget->getConfigurations(h5FileRoot);
optTarget->setRng(vmcEngine->getRng());
optTarget->engine_checkConfigurations(EngineObj, descentEngineObj,
MinMethod); // computes derivative ratios and pass into engine
initialize_timer_.stop();
app_log() << " Execution time = " << std::setprecision(4) << t1.elapsed() << std::endl;
{
// get configuration from the previous run
ScopedTimer local(&initialize_timer_);
Timer t2;
optTarget->getConfigurations(h5FileRoot);
optTarget->setRng(vmcEngine->getRng());
optTarget->engine_checkConfigurations(EngineObj, descentEngineObj,
MinMethod); // computes derivative ratios and pass into engine
app_log() << " Execution time = " << std::setprecision(4) << t2.elapsed() << std::endl;
}
app_log() << " </log>" << std::endl;
app_log() << "</opt>" << std::endl;
app_log() << "<opt stage=\"main\" walkers=\"" << optTarget->getNumSamples() << "\">" << std::endl;
Expand Down
3 changes: 3 additions & 0 deletions src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,9 @@ void DiracDeterminant<DU_TYPE>::recompute(ParticleSet& P)
{
invertPsiM(psiM_temp, psiM);
}

// invRow becomes invalid after updating the inverse matrix
invRow_id = -1;
}

template<typename DU_TYPE>
Expand Down