int WalkerControlBase::branch(int iter, MCWalkerConfiguration& W, RealType trigger) { int prefill_numwalkers = sortWalkers(W); measureProperties(iter); W.EnsembleProperty=EnsembleProperty; //un-biased variance but we use the saimple one //W.EnsembleProperty.Variance=(e2sum*wsum-esum*esum)/(wsum*wsum-w2sum); ////add to the accumData for block average: REMOVE THIS //accumData[ENERGY_INDEX] += curData[ENERGY_INDEX]*wgtInv; //accumData[ENERGY_SQ_INDEX] += curData[ENERGY_SQ_INDEX]*wgtInv; //accumData[WALKERSIZE_INDEX] += curData[WALKERSIZE_INDEX]; //accumData[WEIGHT_INDEX] += curData[WEIGHT_INDEX]; int nw_tot = copyWalkers(W); //set Weight and Multiplicity to default values MCWalkerConfiguration::iterator it(W.begin()),it_end(W.end()); while(it != it_end) { (*it)->Weight= 1.0; (*it)->Multiplicity=1.0; ++it; } //set the global number of walkers W.setGlobalNumWalkers(nw_tot); return prefill_numwalkers; }
int WalkerControlMPI::branch(int iter, MCWalkerConfiguration& W, RealType trigger) { std::fill(curData.begin(),curData.end(),0); //std::fill(NumPerNode.begin(),NumPerNode.end(),0); sortWalkers(W); //update the number of walkers for this node curData[LE_MAX+MyContext]=NumWalkers; int nw = copyWalkers(W); myComm->allreduce(curData); RealType wgtInv(1.0/curData[WEIGHT_INDEX]); accumData[ENERGY_INDEX] += curData[ENERGY_INDEX]*wgtInv; accumData[ENERGY_SQ_INDEX] += curData[ENERGY_SQ_INDEX]*wgtInv; accumData[WALKERSIZE_INDEX] += curData[WALKERSIZE_INDEX]; accumData[WEIGHT_INDEX] += curData[WEIGHT_INDEX]; Cur_pop=0; for(int i=0, j=LE_MAX; i<NumContexts; i++,j++) { Cur_pop+= NumPerNode[i]=static_cast<int>(curData[j]); } swapWalkersSimple(W); //Do not need to use a trigger. //Cur_min=Nmax; //Cur_max=0; //Cur_pop=0; //for(int i=0, j=LE_MAX; i<NumContexts; i++,j++) { // Cur_pop+= NumPerNode[i]=static_cast<int>(curData[j]); // Cur_min = std::min(Cur_min,NumPerNode[i]); // Cur_max = std::max(Cur_max,NumPerNode[i]); //} //int max_diff = std::max(Cur_max*NumContexts-Cur_pop,Cur_pop-Cur_min*NumContexts); //double diff_pop = static_cast<double>(max_diff)/static_cast<double>(Cur_pop); //if(diff_pop > trigger) { // swapWalkersSimple(W); // //swapWalkersMap(W); //} //set Weight and Multiplicity to default values MCWalkerConfiguration::iterator it(W.begin()),it_end(W.end()); while(it != it_end) { (*it)->Weight= 1.0; (*it)->Multiplicity=1.0; ++it; } //update the global number of walkers W.setGlobalNumWalkers(Cur_pop); return Cur_pop; }
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; }