void SimpleFixedNodeBranch::initWalkerController(MCWalkerConfiguration& walkers, RealType tau, bool fixW) { vParam[B_TAU]=tau; if(!BranchMode[B_DMCSTAGE]) vParam[B_TAUEFF]=tau*R2Accepted.result()/R2Proposed.result(); if(WalkerController == 0) { if(iParam[B_TARGETWALKERS]==0) { Communicate* acomm=MyEstimator->getCommunicator(); int ncontexts=acomm->size(); vector<int> nw(ncontexts,0),nwoff(ncontexts+1,0); nw[acomm->rank()]=walkers.getActiveWalkers(); acomm->allreduce(nw); for(int ip=0; ip<ncontexts; ++ip) nwoff[ip+1]=nwoff[ip]+nw[ip]; walkers.setGlobalNumWalkers(nwoff[ncontexts]); walkers.setWalkerOffsets(nwoff); iParam[B_TARGETWALKERS]=nwoff[ncontexts]; } BranchMode.set(B_DMC,1);//set DMC BranchMode.set(B_POPCONTROL,!fixW);//fixW -> 0 WalkerController = createWalkerController(iParam[B_TARGETWALKERS], MyEstimator->getCommunicator(), myNode); iParam[B_MAXWALKERS]=WalkerController->Nmax; iParam[B_MINWALKERS]=WalkerController->Nmin; if(!fixW && sParam[MIXDMCOPT]=="yes") { app_log() << "Warmup DMC is done with a fixed population " << iParam[B_TARGETWALKERS] << endl; BackupWalkerController=WalkerController; //save the main controller WalkerController=createWalkerController(iParam[B_TARGETWALKERS],MyEstimator->getCommunicator(), myNode,true); BranchMode.set(B_POPCONTROL,0); } WalkerController->setWalkerID(walkers); PopHist.clear(); PopHist.reserve(std::max(iParam[B_ENERGYUPDATEINTERVAL],5)); } //save the BranchMode in anticipating state changes in reset bitset<B_MODE_MAX> bmode(BranchMode); //reset Feedback pararmeter this->reset(); MyEstimator->reset(); //update the simulation parameters WalkerController->put(myNode); //assign current Eref and a large number for variance WalkerController->setEnergyAndVariance(vParam[B_EREF],vParam[B_SIGMA]); //determine the branch cutoff to limit wild weights based on the sigma and sigmaBound RealType sigma=std::max(std::sqrt(static_cast<RealType>(iParam[B_TARGETWALKERS]))*vParam[B_SIGMA]*WalkerController->targetSigma, static_cast<RealType>(100.0)); vParam[B_BRANCHCUTOFF]=std::min(sigma,5.0/tau); //vParam[B_BRANCHCUTOFF]=vParam[B_SIGMA]*WalkerController->targetSigma; vParam[B_BRANCHMAX]=vParam[B_BRANCHCUTOFF]*1.5; vParam[B_BRANCHFILTER]=1.0/(vParam[B_BRANCHMAX]-vParam[B_BRANCHCUTOFF]); //reset controller WalkerController->reset(); if(BackupWalkerController) BackupWalkerController->reset(); BranchMode=bmode; app_log() << " QMC counter = " << iParam[B_COUNTER] << endl; app_log() << " time step = " << vParam[B_TAU] << endl; app_log() << " effective time step = " << vParam[B_TAUEFF] << endl; app_log() << " trial energy = " << vParam[B_ETRIAL] << endl; app_log() << " reference energy = " << vParam[B_EREF] << endl; app_log() << " Feedback = " << Feedback << endl; app_log() << " reference variance = " << vParam[B_SIGMA] << endl; app_log() << " target walkers = " << iParam[B_TARGETWALKERS] << endl; app_log() << " branch cutoff = " << vParam[B_BRANCHCUTOFF] << " " << vParam[B_BRANCHMAX] << endl; app_log() << " Max and mimum walkers per node= " << iParam[B_MAXWALKERS] << " " << iParam[B_MINWALKERS] << endl; app_log() << " QMC Status (BranchMode) = " << BranchMode << endl; }
//void SimpleFixedNodeBranch::initWalkerController(MCWalkerConfiguration& walkers, RealType tau, bool fixW, bool killwalker) void SimpleFixedNodeBranch::initWalkerController(MCWalkerConfiguration& walkers, bool fixW, bool killwalker) { BranchMode.set(B_DMC,1);//set DMC BranchMode.set(B_DMCSTAGE,iParam[B_WARMUPSTEPS]==0);//use warmup //this is not necessary //check if tau is different and set the initial values //vParam[B_TAU]=tau; bool fromscratch=false; RealType tau=vParam[B_TAU]; //this is the first time DMC is used if(WalkerController == 0) { if(iParam[B_TARGETWALKERS]==0) { Communicate* acomm=MyEstimator->getCommunicator(); int ncontexts=acomm->size(); vector<int> nw(ncontexts,0),nwoff(ncontexts+1,0); nw[acomm->rank()]=walkers.getActiveWalkers(); acomm->allreduce(nw); for(int ip=0; ip<ncontexts; ++ip) nwoff[ip+1]=nwoff[ip]+nw[ip]; walkers.setGlobalNumWalkers(nwoff[ncontexts]); walkers.setWalkerOffsets(nwoff); iParam[B_TARGETWALKERS]=nwoff[ncontexts]; } WalkerController = createWalkerController(iParam[B_TARGETWALKERS], MyEstimator->getCommunicator(), myNode); if(!BranchMode[B_RESTART]) { fromscratch=true; app_log() << " START ALL OVER " << endl; vParam[B_TAUEFF]=tau; BranchMode.set(B_POPCONTROL,!fixW);//fixW -> 0 BranchMode.set(B_KILLNODES,killwalker); iParam[B_MAXWALKERS]=WalkerController->Nmax; iParam[B_MINWALKERS]=WalkerController->Nmin; if(!fixW && sParam[MIXDMCOPT]=="yes") { app_log() << "Warmup DMC is done with a fixed population " << iParam[B_TARGETWALKERS] << endl; BackupWalkerController=WalkerController; //save the main controller WalkerController=createWalkerController(iParam[B_TARGETWALKERS],MyEstimator->getCommunicator(), myNode,true); BranchMode.set(B_POPCONTROL,0); } //PopHist.clear(); //PopHist.reserve(std::max(iParam[B_ENERGYUPDATEINTERVAL],5)); } WalkerController->setWalkerID(walkers); } //else //{ // BranchMode.set(B_DMCSTAGE,0);//always reset warmup //} MyEstimator->reset(); //update the simulation parameters WalkerController->put(myNode); //assign current Eref and a large number for variance WalkerController->setEnergyAndVariance(vParam[B_EREF],vParam[B_SIGMA]); this->reset(); if(fromscratch) { //determine the branch cutoff to limit wild weights based on the sigma and sigmaBound //RealType sigma=std::max(std::sqrt(static_cast<RealType>(iParam[B_TARGETWALKERS]))*vParam[B_SIGMA]*WalkerController->targetSigma,100.0); RealType sigma=std::max(std::sqrt(vParam[B_SIGMA])*WalkerController->targetSigma,50.0); vParam[B_BRANCHCUTOFF]=std::min(sigma,2.5/tau); //vParam[B_BRANCHCUTOFF]=vParam[B_SIGMA]*WalkerController->targetSigma; vParam[B_BRANCHMAX]=vParam[B_BRANCHCUTOFF]*1.5; vParam[B_BRANCHFILTER]=1.0/(vParam[B_BRANCHMAX]-vParam[B_BRANCHCUTOFF]); vParam[B_TAUEFF]=tau*R2Accepted.result()/R2Proposed.result(); } //reset controller WalkerController->reset(); if(BackupWalkerController) BackupWalkerController->reset(); app_log() << " QMC counter = " << iParam[B_COUNTER] << endl; app_log() << " time step = " << vParam[B_TAU] << endl; app_log() << " effective time step = " << vParam[B_TAUEFF] << endl; app_log() << " trial energy = " << vParam[B_ETRIAL] << endl; app_log() << " reference energy = " << vParam[B_EREF] << endl; app_log() << " Feedback = " << vParam[B_FEEDBACK] << endl; app_log() << " reference variance = " << vParam[B_SIGMA] << endl; app_log() << " target walkers = " << iParam[B_TARGETWALKERS] << endl; app_log() << " branch cutoff = " << vParam[B_BRANCHCUTOFF] << " " << vParam[B_BRANCHMAX] << endl; app_log() << " Max and mimum walkers per node= " << iParam[B_MAXWALKERS] << " " << iParam[B_MINWALKERS] << endl; app_log() << " QMC Status (BranchMode) = " << BranchMode << endl; }