diff --git a/src/QMCDrivers/WFOpt/QMCCostFunctionBase.h b/src/QMCDrivers/WFOpt/QMCCostFunctionBase.h index 05e8111423..a7045b2405 100644 --- a/src/QMCDrivers/WFOpt/QMCCostFunctionBase.h +++ b/src/QMCDrivers/WFOpt/QMCCostFunctionBase.h @@ -176,6 +176,13 @@ class QMCCostFunctionBase : public CostFunctionBase, 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; diff --git a/src/QMCDrivers/WFOpt/QMCLinearOptimize.cpp b/src/QMCDrivers/WFOpt/QMCLinearOptimize.cpp index 7126d19454..c27a05c467 100644 --- a/src/QMCDrivers/WFOpt/QMCLinearOptimize.cpp +++ b/src/QMCDrivers/WFOpt/QMCLinearOptimize.cpp @@ -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() << "" << std::endl; app_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() << " " << std::endl; app_log() << "" << std::endl; app_log() << "getNumSamples() << "\">" << std::endl; @@ -115,13 +122,14 @@ void QMCLinearOptimize::engine_start(cqmc::engine::LMYEngine* 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() << "" << std::endl; app_log() << " " << std::endl; @@ -129,16 +137,16 @@ void QMCLinearOptimize::engine_start(cqmc::engine::LMYEngine* EngineO 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() << " " << std::endl; app_log() << "" << std::endl; app_log() << "getNumSamples() << "\">" << std::endl; diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp b/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp index 25fccc71af..cacf399afd 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp @@ -643,6 +643,9 @@ void DiracDeterminant::recompute(ParticleSet& P) { invertPsiM(psiM_temp, psiM); } + + // invRow becomes invalid after updating the inverse matrix + invRow_id = -1; } template