Example #1
0
/** advance all the walkers with killnode==yes
 */
void WFMCUpdateAllWithReweight::advanceWalkers(WalkerIter_t it
        , WalkerIter_t it_end, bool measure)
{
    for (; it != it_end; ++it)
    {
        Walker_t& thisWalker(**it);
        W.loadWalker(thisWalker,false);
        setScaledDriftPbyPandNodeCorr(m_tauovermass,W.G,drift);
        //create a 3N-Dimensional Gaussian with variance=1
        makeGaussRandomWithEngine(deltaR,RandomGen);
        //reject illegal positions or big displacement
        if (!W.makeMoveWithDrift(thisWalker,drift,deltaR, m_sqrttau))
        {
            H.rejectedMove(W,thisWalker);
            H.auxHevaluate(W,thisWalker);
            continue;
        }
        ///W.R = m_sqrttau*deltaR + thisWalker.Drift;
        ///W.R += thisWalker.R;
        ///W.update();
        //save old local energy
        RealType eold = thisWalker.Properties(LOCALENERGY);
        RealType enew = eold;
        //evaluate wave function
        RealType logpsi(Psi.evaluateLog(W));
        bool accepted=false;
        enew=H.evaluate(W);
        RealType logGf = -0.5*Dot(deltaR,deltaR);
        setScaledDriftPbyPandNodeCorr(m_tauovermass,W.G,drift);
        deltaR = thisWalker.R - W.R - drift;
        RealType logGb = -m_oneover2tau*Dot(deltaR,deltaR);
        RealType prob= std::min(std::exp(logGb-logGf +2.0*(logpsi-thisWalker.Properties(LOGPSI))),1.0);
        if (RandomGen() > prob)
        {
            enew=eold;
            thisWalker.Age++;
            //           thisWalker.Properties(R2ACCEPTED)=0.0;
            //           thisWalker.Properties(R2PROPOSED)=rr_proposed;
            H.rejectedMove(W,thisWalker);
        }
        else
        {
            thisWalker.Age=0;
            accepted=true;
            W.saveWalker(thisWalker);
            //           rr_accepted = rr_proposed;
            //           thisWalker.resetProperty(logpsi,Psi.getPhase(),enew,rr_accepted,rr_proposed,nodecorr);
            thisWalker.resetProperty(logpsi,Psi.getPhase(),enew);
            H.auxHevaluate(W,thisWalker);
            H.saveProperty(thisWalker.getPropertyBase());
        }
        thisWalker.Weight *= std::exp(-Tau*(enew -thisWalker.PropertyHistory[Eindex][Elength]));
        thisWalker.addPropertyHistoryPoint(Eindex,enew);
        if (accepted)
            ++nAccept;
        else
            ++nReject;
    }
}
Example #2
0
  void VMCUpdatePbyP::advanceWalkers(WalkerIter_t it, WalkerIter_t it_end) 
  {

    while(it != it_end) 
    {
      Walker_t& thisWalker(**it);
      Walker_t::Buffer_t& w_buffer(thisWalker.DataSet);

      W.R = thisWalker.R;
      w_buffer.rewind();
      W.copyFromBuffer(w_buffer);
      Psi.copyFromBuffer(W,w_buffer);

      RealType psi_old = thisWalker.Properties(SIGN);
      RealType psi = psi_old;

      for(int iter=0; iter<nSubSteps; iter++) {

        makeGaussRandomWithEngine(deltaR,RandomGen);
        bool stucked=true;
        for(int iat=0; iat<W.getTotalNum(); iat++) {

          PosType dr = m_sqrttau*deltaR[iat];
          PosType newpos = W.makeMove(iat,dr);

          RealType ratio = Psi.ratio(W,iat);
          RealType prob = std::min(1.0e0,ratio*ratio);
          if(RandomGen() < prob) { 
            stucked=false;
            ++nAccept;
            W.acceptMove(iat);
            Psi.acceptMove(W,iat);
          } else {
            ++nReject; 
            W.rejectMove(iat); 
            Psi.rejectMove(iat);
          }
        }
        if(stucked) {
          ++nAllRejected;
        }
      }

      thisWalker.R = W.R;
      w_buffer.rewind();
      W.updateBuffer(w_buffer);
      RealType logpsi = Psi.updateBuffer(W,w_buffer);
      //W.copyToBuffer(w_buffer);
      //RealType logpsi = Psi.evaluate(W,w_buffer);

      RealType eloc=H.evaluate(W);

      thisWalker.resetProperty(logpsi,Psi.getPhase(),eloc);
      H.saveProperty(thisWalker.getPropertyBase());
      ++it;
    }
  }
Example #3
0
  bool DMCPeta::run() {

    resetUpdateEngine();

    //estimator is ready to collect data
    Estimators->setCollectionMode(true);
    Estimators->start(nBlocks,true);

    Timer myclock;
    IndexType block = 0;
    IndexType numPtcls=W.getTotalNum();

    RealType oneover2tau = 0.5/Tau;
    RealType sqrttau = std::sqrt(Tau);

    //temporary data to store differences
    ParticleSet::ParticlePos_t deltaR(numPtcls);
    ParticleSet::ParticleGradient_t G(numPtcls), dG(numPtcls);
    ParticleSet::ParticleLaplacian_t L(numPtcls), dL(numPtcls);

    CurrentStep = 0;
    typedef MCWalkerConfiguration::iterator WalkerIter_t;
    do // block
    {
      Mover->startBlock(nSteps);
      for(IndexType step=0; step< nSteps; step++, CurrentStep+=BranchInterval)
      {
        for(IndexType interval=0; interval<BranchInterval; ++interval)
        {
          for(WalkerIter_t it=W.begin();it != W.end(); ++it) 
          {
            //MCWalkerConfiguration::WalkerData_t& w_buffer = *(W.DataSet[iwalker]);
            Walker_t& thisWalker(**it);
            Walker_t::Buffer_t& w_buffer(thisWalker.DataSet);

            W.R = thisWalker.R;
            w_buffer.rewind();
            W.copyFromBuffer(w_buffer);
            Psi.copyFromBuffer(W,w_buffer);

            //create a 3N-Dimensional Gaussian with variance=1
            makeGaussRandomWithEngine(deltaR,Random);
            int nAcceptTemp(0);
            int nRejectTemp(0);
            RealType eold(thisWalker.Properties(LOCALENERGY));
            RealType enew(eold);
            RealType rr_proposed=0.0;
            RealType rr_accepted=0.0;

            //loop over particles
            for(int iat=0; iat<numPtcls; iat++) 
            {
              PosType dr(sqrttau*deltaR[iat]+thisWalker.Drift[iat]);
              PosType newpos(W.makeMove(iat,dr));

              RealType ratio=Psi.ratio(W,iat,dG,dL);

              RealType rr=dot(dr,dr);
              rr_proposed+=rr;

              if(branchEngine->phaseChanged(Psi.getPhaseDiff())) 
              {//node crossing detected
                ++nRejectTemp;
                W.rejectMove(iat); Psi.rejectMove(iat);
              } 
              else 
              {
                G = W.G+dG;
                RealType logGf = -0.5*dot(deltaR[iat],deltaR[iat]);
                RealType scale=getDriftScale(Tau,G);
                dr = thisWalker.R[iat]-newpos-scale*real(G[iat]); 

                RealType logGb = -oneover2tau*dot(dr,dr);
                RealType prob = std::min(1.0,ratio*ratio*std::exp(logGb-logGf));
                if(Random() < prob) 
                {//move is accepted 
                  ++nAcceptTemp;
                  W.acceptMove(iat);
                  Psi.acceptMove(W,iat);
                  W.G = G;
                  W.L += dL;

                  assignDrift(scale,G,thisWalker.Drift);

                  rr_accepted+=rr;
                } 
                else 
                {
                  ++nRejectTemp; 
                  W.rejectMove(iat); Psi.rejectMove(iat);
                }
              } 
            }//for(int iat=0; iat<NumPtcl; iat++) 

            if(nAcceptTemp>0) 
            {//need to overwrite the walker properties
              thisWalker.R = W.R;
              w_buffer.rewind();
              W.copyToBuffer(w_buffer);
              //RealType psi = Psi.evaluate(W,w_buffer);
              RealType logpsi = Psi.evaluateLog(W,w_buffer);
              enew= H.evaluate(W);
              //thisWalker.resetProperty(std::log(abs(psi)),psi,enew,rr_accepted,rr_proposed,1.0);
              thisWalker.resetProperty(logpsi,Psi.getPhase(),enew,rr_accepted,rr_proposed,1.0 );
              H.auxHevaluate(W,thisWalker);
              H.saveProperty(thisWalker.getPropertyBase());
            } 
            else 
            {
              thisWalker.rejectedMove();
              thisWalker.Age++;
              rr_accepted=0.0;
              enew=eold;//copy back old energy
            }

            thisWalker.Weight *= branchEngine->branchWeight(eold,enew);

            nAccept += nAcceptTemp;
            nReject += nRejectTemp;
          }//for(WalkerIter_t it=W.begin();it != W.end(); ++it)
        }//interval

        //calculate multiplicity based on the weights: see QMCUpdateBase::setMultiplicity
        Mover->setMultiplicity(W.begin(),W.end());
        //time to branch: see SimpleFixedNodeBranch::branch
        branchEngine->branch(CurrentStep,W);        
        if(storeConfigs && (CurrentStep%storeConfigs == 0)) { 
          ForwardWalkingHistory.storeConfigsForForwardWalking(W);
          W.resetWalkerParents();
        }
      }//steps

      ++block;
      Estimators->stopBlock(static_cast<RealType>(nAccept)/static_cast<RealType>(nAccept+nReject));
      recordBlock(block);
    } while(block<nBlocks &&  myclock.elapsed()<MaxCPUSecs);

    Estimators->stop();
    return finalize(block);
  }
Example #4
0
bool VMCcuda::run() {
    if (UseDrift == "yes")
        return runWithDrift();

    resetRun();
    IndexType block = 0;
    IndexType nAcceptTot = 0;
    IndexType nRejectTot = 0;
    IndexType updatePeriod= (QMCDriverMode[QMC_UPDATE_MODE])
                            ? Period4CheckProperties
                            : (nBlocks+1)*nSteps;

    int nat = W.getTotalNum();
    int nw  = W.getActiveWalkers();

    vector<RealType>  LocalEnergy(nw);
    vector<PosType>   delpos(nw);
    vector<PosType>   newpos(nw);
    vector<ValueType> ratios(nw);
    vector<GradType>  oldG(nw), newG(nw);
    vector<ValueType> oldL(nw), newL(nw);
    vector<Walker_t*> accepted(nw);
    Matrix<ValueType> lapl(nw, nat);
    Matrix<GradType>  grad(nw, nat);
    double Esum;

    // First do warmup steps
    for (int step=0; step<myWarmupSteps; step++) {
        for(int iat=0; iat<nat; ++iat)  {
            //create a 3N-Dimensional Gaussian with variance=1
            makeGaussRandomWithEngine(delpos,Random);
            for(int iw=0; iw<nw; ++iw) {
                PosType G = W[iw]->Grad[iat];
                newpos[iw]=W[iw]->R[iat] + m_sqrttau*delpos[iw];
                ratios[iw] = 1.0;
            }
            W.proposeMove_GPU(newpos, iat);

            Psi.ratio(W,iat,ratios,newG, newL);

            accepted.clear();
            vector<bool> acc(nw, false);
            for(int iw=0; iw<nw; ++iw) {
                if(ratios[iw]*ratios[iw] > Random()) {
                    accepted.push_back(W[iw]);
                    nAccept++;
                    W[iw]->R[iat] = newpos[iw];
                    acc[iw] = true;
                }
                else
                    nReject++;
            }
            W.acceptMove_GPU(acc);
            if (accepted.size())
                Psi.update(accepted,iat);
        }
    }

    do {
        IndexType step = 0;
        nAccept = nReject = 0;
        Esum = 0.0;
        Estimators->startBlock(nSteps);
        do
        {
            ++step;
            ++CurrentStep;
            for (int isub=0; isub<nSubSteps; isub++) {
                for(int iat=0; iat<nat; ++iat)  {
                    //create a 3N-Dimensional Gaussian with variance=1
                    makeGaussRandomWithEngine(delpos,Random);
                    for(int iw=0; iw<nw; ++iw) {
                        PosType G = W[iw]->Grad[iat];
                        newpos[iw]=W[iw]->R[iat] + m_sqrttau*delpos[iw];
                        ratios[iw] = 1.0;
                    }
                    W.proposeMove_GPU(newpos, iat);

                    Psi.ratio(W,iat,ratios,newG, newL);

                    accepted.clear();
                    vector<bool> acc(nw, false);
                    for(int iw=0; iw<nw; ++iw) {
                        if(ratios[iw]*ratios[iw] > Random()) {
                            accepted.push_back(W[iw]);
                            nAccept++;
                            W[iw]->R[iat] = newpos[iw];
                            acc[iw] = true;
                        }
                        else
                            nReject++;
                    }
                    W.acceptMove_GPU(acc);
                    if (accepted.size())
                        Psi.update(accepted,iat);
                }
            }
            Psi.gradLapl(W, grad, lapl);
            H.evaluate (W, LocalEnergy);
            if (myPeriod4WalkerDump && (CurrentStep % myPeriod4WalkerDump)==0)
                W.saveEnsemble();
            Estimators->accumulate(W);
        } while(step<nSteps);
        Psi.recompute(W);

        // vector<RealType> logPsi(W.WalkerList.size(), 0.0);
        // Psi.evaluateLog(W, logPsi);

        double accept_ratio = (double)nAccept/(double)(nAccept+nReject);
        Estimators->stopBlock(accept_ratio);

        nAcceptTot += nAccept;
        nRejectTot += nReject;
        ++block;
        recordBlock(block);
    } while(block<nBlocks);

    //Mover->stopRun();

    //finalize a qmc section
    return finalize(block);
}
Example #5
0
bool VMCcuda::runWithDrift()
{
    resetRun();
    IndexType block = 0;
    IndexType nAcceptTot = 0;
    IndexType nRejectTot = 0;
    int nat = W.getTotalNum();
    int nw  = W.getActiveWalkers();

    vector<RealType>  LocalEnergy(nw), oldScale(nw), newScale(nw);
    vector<PosType>   delpos(nw);
    vector<PosType>   dr(nw);
    vector<PosType>   newpos(nw);
    vector<ValueType> ratios(nw), rplus(nw), rminus(nw);
    vector<PosType>  oldG(nw), newG(nw);
    vector<ValueType> oldL(nw), newL(nw);
    vector<Walker_t*> accepted(nw);
    Matrix<ValueType> lapl(nw, nat);
    Matrix<GradType>  grad(nw, nat);

    // First, do warmup steps
    for (int step=0; step<myWarmupSteps; step++) {
        for(int iat=0; iat<nat; iat++) {
            Psi.getGradient (W, iat, oldG);

            //create a 3N-Dimensional Gaussian with variance=1
            makeGaussRandomWithEngine(delpos,Random);
            for(int iw=0; iw<nw; iw++) {
                oldScale[iw] = getDriftScale(m_tauovermass,oldG[iw]);
                dr[iw] = (m_sqrttau*delpos[iw]) + (oldScale[iw]*oldG[iw]);
                newpos[iw]=W[iw]->R[iat] + dr[iw];
                ratios[iw] = 1.0;
            }
            W.proposeMove_GPU(newpos, iat);

            Psi.ratio(W,iat,ratios,newG, newL);

            accepted.clear();
            vector<bool> acc(nw, false);
            for(int iw=0; iw<nw; ++iw) {
                PosType drOld =
                    newpos[iw] - (W[iw]->R[iat] + oldScale[iw]*oldG[iw]);
                RealType logGf = -m_oneover2tau * dot(drOld, drOld);
                newScale[iw]   = getDriftScale(m_tauovermass,newG[iw]);
                PosType drNew  =
                    (newpos[iw] + newScale[iw]*newG[iw]) - W[iw]->R[iat];

                RealType logGb =  -m_oneover2tau * dot(drNew, drNew);
                RealType x = logGb - logGf;
                RealType prob = ratios[iw]*ratios[iw]*std::exp(x);

                if(Random() < prob) {
                    accepted.push_back(W[iw]);
                    nAccept++;
                    W[iw]->R[iat] = newpos[iw];
                    acc[iw] = true;
                }
                else
                    nReject++;
            }
            W.acceptMove_GPU(acc);
            if (accepted.size())
                Psi.update(accepted,iat);
        }
    }

    // Now do data collection steps
    do {
        IndexType step = 0;
        nAccept = nReject = 0;
        Estimators->startBlock(nSteps);
        do {
            step++;
            CurrentStep++;
            for (int isub=0; isub<nSubSteps; isub++) {
                for(int iat=0; iat<nat; iat++) {
                    Psi.getGradient (W, iat, oldG);

                    //create a 3N-Dimensional Gaussian with variance=1
                    makeGaussRandomWithEngine(delpos,Random);
                    for(int iw=0; iw<nw; iw++) {
                        oldScale[iw] = getDriftScale(m_tauovermass,oldG[iw]);
                        dr[iw] = (m_sqrttau*delpos[iw]) + (oldScale[iw]*oldG[iw]);
                        newpos[iw]=W[iw]->R[iat] + dr[iw];
                        ratios[iw] = 1.0;
                    }
                    W.proposeMove_GPU(newpos, iat);

                    Psi.ratio(W,iat,ratios,newG, newL);

                    accepted.clear();
                    vector<bool> acc(nw, false);
                    for(int iw=0; iw<nw; ++iw) {
                        PosType drOld =
                            newpos[iw] - (W[iw]->R[iat] + oldScale[iw]*oldG[iw]);
                        // if (dot(drOld, drOld) > 25.0)
                        //   cerr << "Large drift encountered!  Old drift = " << drOld << endl;
                        RealType logGf = -m_oneover2tau * dot(drOld, drOld);
                        newScale[iw]   = getDriftScale(m_tauovermass,newG[iw]);
                        PosType drNew  =
                            (newpos[iw] + newScale[iw]*newG[iw]) - W[iw]->R[iat];
                        // if (dot(drNew, drNew) > 25.0)
                        //   cerr << "Large drift encountered!  Drift = " << drNew << endl;
                        RealType logGb =  -m_oneover2tau * dot(drNew, drNew);
                        RealType x = logGb - logGf;
                        RealType prob = ratios[iw]*ratios[iw]*std::exp(x);

                        if(Random() < prob) {
                            accepted.push_back(W[iw]);
                            nAccept++;
                            W[iw]->R[iat] = newpos[iw];
                            acc[iw] = true;
                        }
                        else
                            nReject++;
                    }
                    W.acceptMove_GPU(acc);
                    if (accepted.size())
                        Psi.update(accepted,iat);
                }
                // cerr << "Rank = " << myComm->rank() <<
                //   "  CurrentStep = " << CurrentStep << "  isub = " << isub << endl;
            }
            Psi.gradLapl(W, grad, lapl);
            H.evaluate (W, LocalEnergy);
            if (myPeriod4WalkerDump && (CurrentStep % myPeriod4WalkerDump)==0)
                W.saveEnsemble();
            Estimators->accumulate(W);
        } while(step<nSteps);
        Psi.recompute(W);

        double accept_ratio = (double)nAccept/(double)(nAccept+nReject);
        Estimators->stopBlock(accept_ratio);

        nAcceptTot += nAccept;
        nRejectTot += nReject;
        ++block;
        recordBlock(block);
    } while(block<nBlocks);
    //finalize a qmc section
    if (!myComm->rank())
        gpu::cuda_memory_manager.report();
    return finalize(block);
}
Example #6
0
  void CSVMCUpdatePbyP::advanceWalkers(WalkerIter_t it, WalkerIter_t it_end, bool measure)
  {
    int iwalker=0; 
    //only used locally
    vector<RealType> ratio(nPsi), uw(nPsi);
    while(it != it_end) 
    {  //Walkers loop

      Walker_t& thisWalker(**it);
      Walker_t::Buffer_t& w_buffer(thisWalker.DataSet);

      W.R = thisWalker.R;
      w_buffer.rewind();

      // Copy walker info in W
      W.copyFromBuffer(w_buffer);
      for(int ipsi=0; ipsi<nPsi; ipsi++){
        // Copy wave function info in W and Psi1
        Psi1[ipsi]->copyFromBuffer(W,w_buffer);  
        Psi1[ipsi]->G=W.G;
        Psi1[ipsi]->L=W.L;
      }

      makeGaussRandomWithEngine(deltaR,RandomGen);

      for(int ipsi=0; ipsi<nPsi; ipsi++)
      {
        uw[ipsi]= thisWalker.Properties(ipsi,UMBRELLAWEIGHT);
      }

      // Point to the correct walker in the ratioij buffer
      RealType* restrict ratioijPtr=ratioIJ[iwalker];

      bool moved = false;
      for(int iat=0; iat<W.getTotalNum(); iat++) {  //Particles loop

        PosType dr = m_sqrttau*deltaR[iat];
        PosType newpos = W.makeMove(iat,dr);

        RealType ratio_check=1.0;
        for(int ipsi=0; ipsi<nPsi; ipsi++)
        {
         // Compute ratios before and after the move
          ratio_check *= ratio[ipsi] = Psi1[ipsi]->ratio(W,iat,*G1[ipsi],*L1[ipsi]); 
          logpsi[ipsi]=std::log(ratio[ipsi]*ratio[ipsi]);
          // Compute Gradient in new position
          //*G1[ipsi]=Psi1[ipsi]->G + dG;
          // Initialize: sumratio[i]=(Psi[i]/Psi[i])^2=1.0
          sumratio[ipsi]=1.0;
        }

        bool accept_move=false;
        if(ratio_check>1e-12)//if any ratio is too small, reject the move automatically
        {
          int indexij(0);
          // Compute new (Psi[i]/Psi[j])^2 and their sum
          for(int ipsi=0; ipsi< nPsi-1; ipsi++)
          {
            for(int jpsi=ipsi+1; jpsi < nPsi; jpsi++, indexij++)
            {
              // Ratio between norms is already included in ratioijPtr from initialize.
              RealType rji=std::exp(logpsi[jpsi]-logpsi[ipsi])*ratioijPtr[indexij];
              instRij[indexij]=rji;
              //ratioij[indexij]=rji;
              sumratio[ipsi] += rji;
              sumratio[jpsi] += 1.0/rji;
            }
          }

          // Evaluate new Umbrella Weight
          for(int ipsi=0; ipsi< nPsi ;ipsi++) invsumratio[ipsi]=1.0/sumratio[ipsi];

          RealType td=ratio[0]*ratio[0]*sumratio[0]/(*it)->Multiplicity;
          accept_move=Random()<std::min(1.0,td);
        }
        //RealType prob = std::min(1.0,td);
        //if(Random() < prob) 
        if(accept_move)
        { 
          /* Electron move is accepted. Update:
             -ratio (Psi[i]/Psi[j])^2 for this walker
             -Gradient and laplacian for each Psi1[i]
             -Drift
             -buffered info for each Psi1[i]*/
          moved = true;
          ++nAccept;
          W.acceptMove(iat);
          // Update Buffer for (Psi[i]/Psi[j])^2 
          std::copy(instRij.begin(),instRij.end(),ratioijPtr);
          // copy new Umbrella weight for averages
          uw=invsumratio;

          // Store sumratio for next Accept/Reject step to Multiplicity
          //thisWalker.Properties(SUMRATIO)=sumratio[0];
          thisWalker.Multiplicity=sumratio[0];
          for(int ipsi=0; ipsi< nPsi; ipsi++)
          {
            //Update local Psi1[i] buffer for the next move
            Psi1[ipsi]->acceptMove(W,iat);  
            //Update G and L in Psi1[i]
            //Psi1[ipsi]->G = *G1[ipsi];
            Psi1[ipsi]->G += *G1[ipsi];
            Psi1[ipsi]->L += *L1[ipsi];
            thisWalker.Properties(ipsi,LOGPSI)+=std::log(abs(ratio[ipsi]));
          }
        } else {
          ++nReject;
          W.rejectMove(iat);
          for(int ipsi=0; ipsi< nPsi; ipsi++)
            Psi1[ipsi]->rejectMove(iat);
        }
      }

      if(moved) {
        /* The walker moved: Info are copied back to buffers:
           -copy (Psi[i]/Psi[j])^2 to ratioijBuffer
           -Gradient and laplacian for each Psi1[i]
           -Drift
           -buffered info for each Psi1[i]
           Physical properties are updated */
        (*it)->Age=0;
        (*it)->R = W.R;
        w_buffer.rewind();
        W.copyToBuffer(w_buffer);
        for(int ipsi=0; ipsi< nPsi; ipsi++){
          W.G=Psi1[ipsi]->G;
          W.L=Psi1[ipsi]->L;
          //ValueType psi = Psi1[ipsi]->evaluate(W,w_buffer);
          ValueType logpsi = Psi1[ipsi]->evaluateLog(W,w_buffer);
          RealType et = H1[ipsi]->evaluate(W);

          //multiEstimator->updateSample(iwalker,ipsi,et,UmbrellaWeight[ipsi]);
          //Properties is used for UmbrellaWeight and UmbrellaEnergy
          thisWalker.Properties(ipsi,UMBRELLAWEIGHT)=uw[ipsi];
          thisWalker.Properties(ipsi,LOCALENERGY)=et;
          H1[ipsi]->saveProperty(thisWalker.getPropertyBase(ipsi));
        }
      }
      else 
      {
        ++nAllRejected;
      }
      ++it; ++iwalker;
    }
  }
Example #7
0
  void VMCUpdatePbyPWithDrift::advanceWalkers(WalkerIter_t it, WalkerIter_t it_end) 
  {

    while(it != it_end) 
    {
      Walker_t& thisWalker(**it);
      Walker_t::Buffer_t& w_buffer(thisWalker.DataSet);

      W.R = thisWalker.R;
      w_buffer.rewind();
      W.copyFromBuffer(w_buffer);
      Psi.copyFromBuffer(W,w_buffer);

      RealType psi_old = thisWalker.Properties(SIGN);
      RealType psi = psi_old;
      //create a 3N-Dimensional Gaussian with variance=1
      makeGaussRandomWithEngine(deltaR,RandomGen);

      bool moved = false;

      for(int iat=0; iat<W.getTotalNum(); iat++) {

        PosType dr = m_sqrttau*deltaR[iat]+thisWalker.Drift[iat];
        PosType newpos = W.makeMove(iat,dr);

        //RealType ratio = Psi.ratio(W,iat);
        RealType ratio = Psi.ratio(W,iat,dG,dL);

        G = W.G+dG;

        //RealType forwardGF = exp(-0.5*dot(deltaR[iat],deltaR[iat]));
        //dr = (*it)->R[iat]-newpos-Tau*G[iat]; 
        //RealType backwardGF = exp(-oneover2tau*dot(dr,dr));
        RealType logGf = -0.5e0*dot(deltaR[iat],deltaR[iat]);

        RealType scale=getDriftScale(Tau,G);
        //COMPLEX WARNING
        //dr = thisWalker.R[iat]-newpos-scale*G[iat];
        dr = thisWalker.R[iat]-newpos-scale*real(G[iat]);

        RealType logGb = -m_oneover2tau*dot(dr,dr);

        RealType prob = std::min(1.0e0,ratio*ratio*exp(logGb-logGf));

        //alternatively
        if(RandomGen() < prob) { 
          moved = true;
          ++nAccept;
          W.acceptMove(iat);
          Psi.acceptMove(W,iat);
          W.G = G;
          W.L += dL;

          //thisWalker.Drift = scale*G;
          assignDrift(scale,G,thisWalker.Drift);

        } else {
          ++nReject; 
          W.rejectMove(iat); Psi.rejectMove(iat);
        }
      }

      if(moved) {
        w_buffer.rewind();
        W.copyToBuffer(w_buffer);
        psi = Psi.evaluate(W,w_buffer);

        thisWalker.R = W.R;
        RealType eloc=H.evaluate(W);
        thisWalker.resetProperty(log(abs(psi)), psi,eloc);
        H.saveProperty(thisWalker.getPropertyBase());
      }
      else {
        ++nAllRejected;
      }
      ++it;
    }
  }
Example #8
0
  bool DMCcuda::run() 
  { 
    bool NLmove = NonLocalMove == "yes";
    bool scaleweight = ScaleWeight == "yes";
    if (NLmove) 
      app_log() << "  Using Casula nonlocal moves in DMCcuda.\n";
    if (scaleweight)
      app_log() << "  Scaling weight per Umrigar/Nightengale.\n";
      
    resetRun();
    Mover->MaxAge = 1;
    IndexType block = 0;
    IndexType nAcceptTot = 0;
    IndexType nRejectTot = 0;
    int nat = W.getTotalNum();
    int nw  = W.getActiveWalkers();
    
    vector<RealType>  LocalEnergy(nw), LocalEnergyOld(nw), 
      oldScale(nw), newScale(nw);
    vector<PosType>   delpos(nw);
    vector<PosType>   dr(nw);
    vector<PosType>   newpos(nw);
    vector<ValueType> ratios(nw), rplus(nw), rminus(nw), R2prop(nw), R2acc(nw);
    vector<PosType>  oldG(nw), newG(nw);
    vector<ValueType> oldL(nw), newL(nw);
    vector<Walker_t*> accepted(nw);
    Matrix<ValueType> lapl(nw, nat);
    Matrix<GradType>  grad(nw, nat);
    vector<ValueType> V2(nw), V2bar(nw);
    vector<vector<NonLocalData> > Txy(nw);

    for (int iw=0; iw<nw; iw++)
      W[iw]->Weight = 1.0;
    do {
      IndexType step = 0;
      nAccept = nReject = 0;
      Estimators->startBlock(nSteps);
      
      do {
        step++;
	CurrentStep++;
	nw = W.getActiveWalkers();
	ResizeTimer.start();
	LocalEnergy.resize(nw);       oldScale.resize(nw);
	newScale.resize(nw);          delpos.resize(nw);
	dr.resize(nw);                newpos.resize(nw);
	ratios.resize(nw);            rplus.resize(nw);
	rminus.resize(nw);            oldG.resize(nw);
	newG.resize(nw);              oldL.resize(nw);
	newL.resize(nw);              accepted.resize(nw);
	lapl.resize(nw, nat);         grad.resize(nw, nat);
	R2prop.resize(nw,0.0);        R2acc.resize(nw,0.0);
	V2.resize(nw,0.0);            V2bar.resize(nw,0.0);

	W.updateLists_GPU();
	ResizeTimer.stop();

	if (NLmove) {
	  Txy.resize(nw);
	  for (int iw=0; iw<nw; iw++) {
	    Txy[iw].clear();
	    Txy[iw].push_back(NonLocalData(-1, 1.0, PosType()));
	  }
	}

	for (int iw=0; iw<nw; iw++)
	  W[iw]->Age++;
	
	DriftDiffuseTimer.start();
        for(int iat=0; iat<nat; iat++) {
	  Psi.getGradient (W, iat, oldG);

          //create a 3N-Dimensional Gaussian with variance=1
          makeGaussRandomWithEngine(delpos,Random);
          for(int iw=0; iw<nw; iw++) {
	    delpos[iw] *= m_sqrttau;
	    oldScale[iw] = getDriftScale(m_tauovermass,oldG[iw]);
	    dr[iw] = delpos[iw] + (oldScale[iw]*oldG[iw]);
            newpos[iw]=W[iw]->R[iat] + dr[iw];
	    ratios[iw] = 1.0;
	    R2prop[iw] += dot(delpos[iw], delpos[iw]);
	  }
	  W.proposeMove_GPU(newpos, iat);
	  
          Psi.ratio(W,iat,ratios,newG, newL);
	  	  
          accepted.clear();
	  vector<bool> acc(nw, false);
          for(int iw=0; iw<nw; ++iw) {
	    PosType drOld = 
	      newpos[iw] - (W[iw]->R[iat] + oldScale[iw]*oldG[iw]);
	    RealType logGf = -m_oneover2tau * dot(drOld, drOld);
	    newScale[iw]   = getDriftScale(m_tauovermass,newG[iw]);
	    PosType drNew  = 
	      (newpos[iw] + newScale[iw]*newG[iw]) - W[iw]->R[iat];
	    RealType logGb =  -m_oneover2tau * dot(drNew, drNew);
	    RealType x = logGb - logGf;
	    RealType prob = ratios[iw]*ratios[iw]*std::exp(x);
	    
            if(Random() < prob && ratios[iw] > 0.0) {
              accepted.push_back(W[iw]);
	      nAccept++;
	      W[iw]->R[iat] = newpos[iw];
	      W[iw]->Age = 0;
	      acc[iw] = true;
	      R2acc[iw] += dot(delpos[iw], delpos[iw]);
	      V2[iw]    += m_tauovermass * m_tauovermass * dot(newG[iw],newG[iw]);
	      V2bar[iw] +=  newScale[iw] *  newScale[iw] * dot(newG[iw],newG[iw]);
	    }
	    else {
	      nReject++;
	      V2[iw]    += m_tauovermass * m_tauovermass * dot(oldG[iw],oldG[iw]);
	      V2bar[iw] +=  oldScale[iw] *  oldScale[iw] * dot(oldG[iw],oldG[iw]);
	    }	      
	  }
	  W.acceptMove_GPU(acc);
	  if (accepted.size())
	    Psi.update(accepted,iat);
	}
	DriftDiffuseTimer.stop();
	//	Psi.recompute(W, false);
	Psi.gradLapl(W, grad, lapl);
	HTimer.start();
	if (NLmove)	  H.evaluate (W, LocalEnergy, Txy);
	else    	  H.evaluate (W, LocalEnergy);
	HTimer.stop();
// 	for (int iw=0; iw<nw; iw++) {
// 	  branchEngine->clampEnergy(LocalEnergy[iw]);
// 	  W[iw]->getPropertyBase()[LOCALENERGY] = LocalEnergy[iw];
// 	}
	if (CurrentStep == 1)
	  LocalEnergyOld = LocalEnergy;
	
	if (NLmove) {
	  // Now, attempt nonlocal move
	  accepted.clear();
	  vector<int> iatList;
	  vector<PosType> accPos;
	  for (int iw=0; iw<nw; iw++) {
	    /// HACK HACK HACK
// 	    if (LocalEnergy[iw] < -2300.0) {
// 	      cerr << "Walker " << iw << " has energy " 
// 		   << LocalEnergy[iw] << endl;;
// 	      double maxWeight = 0.0;
// 	      int elMax = -1;
// 	      PosType posMax;
// 	      for (int j=1; j<Txy[iw].size(); j++)
// 		if (std::fabs(Txy[iw][j].Weight) > std::fabs(maxWeight)) {
// 		  maxWeight = Txy[iw][j].Weight;
// 		  elMax = Txy[iw][j].PID;
// 		  posMax = W[iw]->R[elMax] + Txy[iw][j].Delta;
// 		}
// 	      cerr << "Maximum weight is " << maxWeight << " for electron " 
// 		   << elMax << " at position " << posMax << endl;
// 	      PosType unit = W.Lattice.toUnit(posMax);
// 	      unit[0] -= round(unit[0]);
// 	      unit[1] -= round(unit[1]);
// 	      unit[2] -= round(unit[2]);
// 	      cerr << "Reduced position = " << unit << endl;
// 	    }

	    int ibar = NLop.selectMove(Random(), Txy[iw]);
		    
	    if (ibar) {
	      accepted.push_back(W[iw]);
	      int iat = Txy[iw][ibar].PID;
	      iatList.push_back(iat);
	      accPos.push_back(W[iw]->R[iat] + Txy[iw][ibar].Delta);
	    }
	  }
	  if (accepted.size()) {
	    Psi.ratio(accepted,iatList, accPos, ratios, newG, newL);
	    Psi.update(accepted,iatList);
	    for (int i=0; i<accepted.size(); i++)
	      accepted[i]->R[iatList[i]] = accPos[i];
	    W.NLMove_GPU (accepted, accPos, iatList);
	    // HACK HACK HACK
	    // Recompute the kinetic energy
	    // Psi.gradLapl(W, grad, lapl);
	    // H.evaluate (W, LocalEnergy);
	    //W.copyWalkersToGPU();
	  }
	}

	// Now branch
	BranchTimer.start();
	for (int iw=0; iw<nw; iw++) {
	  RealType v2=0.0, v2bar=0.0;
	  for(int iat=0; iat<nat; iat++) {
	    v2 += dot(W.G[iat],W.G[iat]);
	    RealType newscale = getDriftScale(m_tauovermass,newG[iw]);
	    v2 += m_tauovermass * m_tauovermass * dot(newG[iw],newG[iw]);
	    v2bar +=  newscale * newscale * dot(newG[iw],newG[iw]);
	  }
	  //RealType scNew = std::sqrt(V2bar[iw] / V2[iw]);
	  RealType scNew = std::sqrt(v2bar/v2);
	  RealType scOld = (CurrentStep == 1) ? scNew : W[iw]->getPropertyBase()[DRIFTSCALE];

	  W[iw]->getPropertyBase()[DRIFTSCALE] = scNew;
	  // fprintf (stderr, "iw = %d  scNew = %1.8f  scOld = %1.8f\n", iw, scNew, scOld);
	  RealType tauRatio = R2acc[iw] / R2prop[iw];
	  if (tauRatio < 0.5) 
	    cerr << "  tauRatio = " << tauRatio << endl;
	  RealType taueff = m_tauovermass * tauRatio;
	  if (scaleweight) 
	    W[iw]->Weight *= branchEngine->branchWeightTau
	      (LocalEnergy[iw], LocalEnergyOld[iw], scNew, scOld, taueff);
	  else
	    W[iw]->Weight *= branchEngine->branchWeight
	      (LocalEnergy[iw], LocalEnergyOld[iw]);

	  W[iw]->getPropertyBase()[R2ACCEPTED] = R2acc[iw];
	  W[iw]->getPropertyBase()[R2PROPOSED] = R2prop[iw];
	  
	}
	Mover->setMultiplicity(W.begin(), W.end());
	branchEngine->branch(CurrentStep,W);
	nw = W.getActiveWalkers();
	LocalEnergyOld.resize(nw);
	for (int iw=0; iw<nw; iw++)
	  LocalEnergyOld[iw] = W[iw]->getPropertyBase()[LOCALENERGY];
	BranchTimer.stop();
      } while(step<nSteps);
      Psi.recompute(W, true);


      double accept_ratio = (double)nAccept/(double)(nAccept+nReject);
      Estimators->stopBlock(accept_ratio);

      nAcceptTot += nAccept;
      nRejectTot += nReject;
      ++block;
      
      recordBlock(block);
    } while(block<nBlocks);
    //finalize a qmc section
    return finalize(block);
  }
Example #9
0
  bool DMCcuda::runWithNonlocal() 
  { 
    resetRun();
    Mover->MaxAge = 1;
    IndexType block = 0;
    IndexType nAcceptTot = 0;
    IndexType nRejectTot = 0;
    int nat = W.getTotalNum();
    int nw  = W.getActiveWalkers();
    
    vector<RealType>  LocalEnergy(nw), LocalEnergyOld(nw), 
      oldScale(nw), newScale(nw);
    vector<PosType>   delpos(nw);
    vector<PosType>   dr(nw);
    vector<PosType>   newpos(nw);
    vector<ValueType> ratios(nw), rplus(nw), rminus(nw), R2prop(nw), R2acc(nw);
    vector<PosType>  oldG(nw), newG(nw);
    vector<ValueType> oldL(nw), newL(nw);
    vector<Walker_t*> accepted(nw);
    Matrix<ValueType> lapl(nw, nat);
    Matrix<GradType>  grad(nw, nat);
    vector<vector<NonLocalData> > Txy(nw);
    for (int iw=0; iw<nw; iw++)
      W[iw]->Weight = 1.0;
    do {
      IndexType step = 0;
      nAccept = nReject = 0;
      Estimators->startBlock(nSteps);
      
      do {
        step++;
	CurrentStep++;
	nw = W.getActiveWalkers();
	LocalEnergy.resize(nw);    	oldScale.resize(nw);
	newScale.resize(nw);    	delpos.resize(nw);
	dr.resize(nw);                  newpos.resize(nw);
	ratios.resize(nw);	        rplus.resize(nw);
	rminus.resize(nw);              oldG.resize(nw);
	newG.resize(nw);                oldL.resize(nw);
	newL.resize(nw);                accepted.resize(nw);
	lapl.resize(nw, nat);           grad.resize(nw, nat);
	R2prop.resize(nw,0.0);          R2acc.resize(nw,0.0);

	W.updateLists_GPU();

	Txy.resize(nw);
	for (int iw=0; iw<nw; iw++) {
	  Txy[iw].clear();
	  Txy[iw].push_back(NonLocalData(-1, 1.0, PosType()));
	  W[iw]->Age++;
	}
	
        for(int iat=0; iat<nat; iat++) {
	  Psi.getGradient (W, iat, oldG);
	  
          //create a 3N-Dimensional Gaussian with variance=1
          makeGaussRandomWithEngine(delpos,Random);
          for(int iw=0; iw<nw; iw++) {
	    delpos[iw] *= m_sqrttau;
	    oldScale[iw] = getDriftScale(m_tauovermass,oldG[iw]);
	    dr[iw] = delpos[iw] + (oldScale[iw]*oldG[iw]);
            newpos[iw]=W[iw]->R[iat] + dr[iw];
	    ratios[iw] = 1.0;
	    R2prop[iw] += dot(delpos[iw], delpos[iw]);
	  }
	  W.proposeMove_GPU(newpos, iat);
	  
          Psi.ratio(W,iat,ratios,newG, newL);
	  	  
          accepted.clear();
	  vector<bool> acc(nw, false);
          for(int iw=0; iw<nw; ++iw) {
	    PosType drOld = 
	      newpos[iw] - (W[iw]->R[iat] + oldScale[iw]*oldG[iw]);
	    RealType logGf = -m_oneover2tau * dot(drOld, drOld);
	    newScale[iw]   = getDriftScale(m_tauovermass,newG[iw]);
	    PosType drNew  = 
	      (newpos[iw] + newScale[iw]*newG[iw]) - W[iw]->R[iat];
	    RealType logGb =  -m_oneover2tau * dot(drNew, drNew);
	    RealType x = logGb - logGf;
	    RealType prob = ratios[iw]*ratios[iw]*std::exp(x);
	    
            if(Random() < prob && ratios[iw] > 0.0) {
              accepted.push_back(W[iw]);
	      nAccept++;
	      W[iw]->R[iat] = newpos[iw];
	      W[iw]->Age = 0;
	      acc[iw] = true;
	      R2acc[iw] += dot(delpos[iw], delpos[iw]);
	    }
	    else 
	      nReject++;
	  }
	  W.acceptMove_GPU(acc);
	  if (accepted.size())
	    Psi.update(accepted,iat);
	}
	for (int iw=0; iw < nw; iw++) 
	  if (W[iw]->Age)
	    cerr << "Encountered stuck walker with iw=" << iw << endl;

	//	Psi.recompute(W, false);
	Psi.gradLapl(W, grad, lapl);
	H.evaluate (W, LocalEnergy, Txy);
	if (CurrentStep == 1)
	  LocalEnergyOld = LocalEnergy;
	
	// Now, attempt nonlocal move
	accepted.clear();
	vector<int> iatList;
	vector<PosType> accPos;
	for (int iw=0; iw<nw; iw++) {
	  int ibar = NLop.selectMove(Random(), Txy[iw]);
	  // cerr << "Txy[iw].size() = " << Txy[iw].size() << endl;
	  if (ibar) {
	    accepted.push_back(W[iw]);
	    int iat = Txy[iw][ibar].PID;
	    iatList.push_back(iat);
	    accPos.push_back(W[iw]->R[iat] + Txy[iw][ibar].Delta);
	  }
	}
	if (accepted.size()) {
	  //   W.proposeMove_GPU(newpos, iatList);
	  Psi.ratio(accepted,iatList, accPos, ratios, newG, newL);
	  Psi.update(accepted,iatList);
	  for (int i=0; i<accepted.size(); i++)
	    accepted[i]->R[iatList[i]] = accPos[i];
	  W.copyWalkersToGPU();
	}

	// Now branch
	for (int iw=0; iw<nw; iw++) {
	  W[iw]->Weight *= branchEngine->branchWeight(LocalEnergy[iw], LocalEnergyOld[iw]);
	  W[iw]->getPropertyBase()[R2ACCEPTED] = R2acc[iw];
	  W[iw]->getPropertyBase()[R2PROPOSED] = R2prop[iw];
	}
	Mover->setMultiplicity(W.begin(), W.end());
	branchEngine->branch(CurrentStep,W);
	nw = W.getActiveWalkers();
	LocalEnergyOld.resize(nw);
	for (int iw=0; iw<nw; iw++)
	  LocalEnergyOld[iw] = W[iw]->getPropertyBase()[LOCALENERGY];
      } while(step<nSteps);
      Psi.recompute(W, true);


      double accept_ratio = (double)nAccept/(double)(nAccept+nReject);
      Estimators->stopBlock(accept_ratio);

      nAcceptTot += nAccept;
      nRejectTot += nReject;
      ++block;
      
      recordBlock(block);
    } while(block<nBlocks);
    //finalize a qmc section
    return finalize(block);
  }
Example #10
0
  /** advance all the walkers with killnode==no
   * @param nat number of particles to move
   * 
   * When killnode==no, any move resulting in node-crossing is treated
   * as a normal rejection.
   */
  void DMCNonLocalUpdate::advanceWalkers(WalkerIter_t it, WalkerIter_t it_end,
      bool measure) 
  {

    //RealType plusFactor(Tau*Gamma);
    //RealType minusFactor(-Tau*(1.0-Alpha*(1.0+Gamma)));

    for(; it!=it_end; ++it)
    {
      Walker_t& thisWalker(**it);

      //save old local energy
      RealType eold    = thisWalker.Properties(LOCALENERGY);
      RealType signold = thisWalker.Properties(SIGN);
      RealType enew  = eold;

      //create a 3N-Dimensional Gaussian with variance=1
      makeGaussRandomWithEngine(deltaR,RandomGen);

      W.R = m_sqrttau*deltaR + thisWalker.R + thisWalker.Drift;
      
      //update the distance table associated with W
      //DistanceTable::update(W);
      W.update();
      
      //evaluate wave function
      RealType logpsi(Psi.evaluateLog(W));

      nonLocalOps.reset();

      bool accepted=false; 
      if(branchEngine->phaseChanged(Psi.getPhase(),thisWalker.Properties(SIGN))) 
      {
        thisWalker.Age++;
        ++nReject;
      } 
      else 
      {
        //RealType enew(H.evaluate(W,nonLocalOps.Txy));
        enew=H.evaluate(W,nonLocalOps.Txy);
        RealType logGf = -0.5*Dot(deltaR,deltaR);
        setScaledDrift(Tau,W.G,drift);

        deltaR = (*it)->R - W.R - drift;
        RealType logGb = -m_oneover2tau*Dot(deltaR,deltaR);

        RealType prob= std::min(std::exp(logGb-logGf +2.0*(logpsi-thisWalker.Properties(LOGPSI))),1.0);
        if(RandomGen() > prob){
          thisWalker.Age++;
          ++nReject;
          enew=eold;
        } else {
          accepted=true;  
          thisWalker.R = W.R;
          thisWalker.Drift = drift;
          thisWalker.resetProperty(logpsi,Psi.getPhase(),enew);
          H.saveProperty(thisWalker.getPropertyBase());
          //emixed = (emixed+enew)*0.5;
          //eold=enew;
          ++nAccept;
        }
      }

      int ibar=nonLocalOps.selectMove(RandomGen());

      //make a non-local move
      if(ibar) {
        int iat=nonLocalOps.id(ibar);
        W.R[iat] += nonLocalOps.delta(ibar);
        W.update();
        logpsi=Psi.evaluateLog(W);
        setScaledDrift(Tau,W.G,thisWalker.Drift);
        thisWalker.resetProperty(logpsi,Psi.getPhase(),eold);
        thisWalker.R[iat] = W.R[iat];
        ++NonLocalMoveAccepted;
      } 

      thisWalker.Weight *= branchEngine->branchWeight(eold,enew);
      //branchEngine->accumulate(eold,1);
    }
  }
Example #11
0
  /** advance all the walkers with killnode==no
   * @param nat number of particles to move
   * 
   * When killnode==no, any move resulting in node-crossing is treated
   * as a normal rejection.
   */
  void DMCUpdatePbyPWithRejection::advanceWalkers(WalkerIter_t it, WalkerIter_t it_end,
      bool measure) 
  {

    myTimers[0]->start();
    for(;it != it_end;++it) 
    {
      //MCWalkerConfiguration::WalkerData_t& w_buffer = *(W.DataSet[iwalker]);
      Walker_t& thisWalker(**it);
      Walker_t::Buffer_t& w_buffer(thisWalker.DataSet);

      W.loadWalker(thisWalker,true);
      //W.R = thisWalker.R;
      //w_buffer.rewind();
      //W.copyFromBuffer(w_buffer);
      Psi.copyFromBuffer(W,w_buffer);

      //create a 3N-Dimensional Gaussian with variance=1
      makeGaussRandomWithEngine(deltaR,RandomGen);
      int nAcceptTemp(0);
      int nRejectTemp(0);
      //copy the old energy and scale factor of drift
      RealType eold(thisWalker.Properties(LOCALENERGY));
      RealType vqold(thisWalker.Properties(DRIFTSCALE));
      RealType enew(eold);
      RealType rr_proposed=0.0;
      RealType rr_accepted=0.0;
      RealType gf_acc=1.0;

      myTimers[1]->start();
      for(int iat=0; iat<NumPtcl; ++iat) 
      {
        PosType dr;
        //get the displacement
        //RealType sc=getDriftScale(m_tauovermass,W.G[iat]);
        //PosType dr(m_sqrttau*deltaR[iat]+sc*real(W.G[iat]));
        getScaledDrift(m_tauovermass,W.G[iat],dr);
        dr += m_sqrttau*deltaR[iat];

        //RealType rr=dot(dr,dr);
        RealType rr=m_tauovermass*dot(deltaR[iat],deltaR[iat]);
        rr_proposed+=rr;

        if(rr>m_r2max)
        {
          ++nRejectTemp; continue;
        }

        //PosType newpos(W.makeMove(iat,dr));
        if(!W.makeMoveAndCheck(iat,dr)) continue;
        PosType newpos(W.R[iat]);
        RealType ratio=Psi.ratio(W,iat,dG,dL);
        bool valid_move=false;

        //node is crossed reject the move
        //if(Psi.getPhase() > numeric_limits<RealType>::epsilon()) 
        if(branchEngine->phaseChanged(Psi.getPhaseDiff())) 
        {
          ++nRejectTemp;
          ++nNodeCrossing;
          W.rejectMove(iat); Psi.rejectMove(iat);
        } 
        else 
        {
          G = W.G+dG;
          RealType logGf = -0.5*dot(deltaR[iat],deltaR[iat]);
          
          //Use the force of the particle iat
          //RealType scale=getDriftScale(m_tauovermass,G[iat]);
          //dr = thisWalker.R[iat]-newpos-scale*real(G[iat]);
          getScaledDrift(m_tauovermass, G[iat], dr);
          dr = thisWalker.R[iat] - newpos - dr;

          RealType logGb = -m_oneover2tau*dot(dr,dr);
          RealType prob = ratio*ratio*std::exp(logGb-logGf);
          //this is useless
          //RealType prob = std::min(1.0,ratio*ratio*std::exp(logGb-logGf));
          if(RandomGen() < prob) 
          { 
            valid_move=true;
            ++nAcceptTemp;
            W.acceptMove(iat);
            Psi.acceptMove(W,iat);
            W.G = G;
            W.L += dL;
            rr_accepted+=rr;
            gf_acc *=prob;//accumulate the ratio 
          } 
          else 
          {
            ++nRejectTemp; 
            W.rejectMove(iat); Psi.rejectMove(iat);
          }
        } 

      }
      myTimers[1]->stop();
      
      RealType nodecorr_old=thisWalker.Properties(DRIFTSCALE);
      RealType nodecorr=nodecorr_old;
      bool advanced=true;

      if(UseTMove) nonLocalOps.reset();

      if(nAcceptTemp>0) 
      {//need to overwrite the walker properties
        myTimers[2]->start();
        thisWalker.Age=0;
        thisWalker.R = W.R;

        nodecorr=getNodeCorrection(W.G,drift);

        //w_buffer.rewind();
        //W.copyToBuffer(w_buffer);
        RealType logpsi = Psi.evaluateLog(W,w_buffer);
        W.saveWalker(thisWalker);

        myTimers[2]->stop();

        myTimers[3]->start();
        if(UseTMove)
          enew= H.evaluate(W,nonLocalOps.Txy);
        else
          enew= H.evaluate(W);
        myTimers[3]->stop();

        //thisWalker.resetProperty(std::log(abs(psi)),psi,enew,rr_accepted,rr_proposed,nodecorr);
        thisWalker.resetProperty(logpsi,Psi.getPhase(),enew,rr_accepted,rr_proposed,nodecorr );
        H.auxHevaluate(W,thisWalker);
        H.saveProperty(thisWalker.getPropertyBase());
      } 
      else 
      {//all moves are rejected: does not happen normally with reasonable wavefunctions
        advanced=false;
        H.rejectedMove(W,thisWalker); 
        thisWalker.Age++;
        thisWalker.Properties(R2ACCEPTED)=0.0;
        ++nAllRejected;
        enew=eold;//copy back old energy
        gf_acc=1.0;
      }

      if(UseTMove)
      {
        //make a non-local move
        int ibar=nonLocalOps.selectMove(RandomGen());
        if(ibar) 
        {
          myTimers[2]->start();
          int iat=nonLocalOps.id(ibar);
          PosType newpos(W.makeMove(iat, nonLocalOps.delta(ibar)));
          RealType ratio=Psi.ratio(W,iat,dG,dL);
          W.acceptMove(iat);
          Psi.acceptMove(W,iat);
          W.G += dG;
          W.L += dL;

          //PAOps<RealType,OHMMS_DIM>::copy(W.G,thisWalker.Drift);

          //thisWalker.R[iat]=W.R[iat];
          //w_buffer.rewind();
          //W.copyToBuffer(w_buffer);
          RealType logpsi = Psi.evaluateLog(W,w_buffer);
          W.saveWalker(thisWalker);
          ++NonLocalMoveAccepted;
          myTimers[2]->stop();
        }
      }

      //2008-06-26: select any
      //bare green function by setting nodecorr=nodecorr_old=1.0
      thisWalker.Weight *= branchEngine->branchWeight(enew,eold);


      //Filtering extreme energies
      //thisWalker.Weight *= branchEngine->branchWeight(eold,enew);

      //using the corrections: see QMCUpdateBase::getNodeCorrection 
      //thisWalker.Weight *= branchEngine->branchWeight(enew,eold,nodecorr,nodecorr_old);
      
      //using the corrections: see QMCUpdateBase::getNodeCorrection  including gf_acc
      //RealType odd=std::min(gf_acc,1.0)
      //thisWalker.Weight *= branchEngine->branchWeight(enew,eold,nodecorr,nodecorr_oldi,odd);

      nAccept += nAcceptTemp;
      nReject += nRejectTemp;

    }
    myTimers[0]->stop();
  }
Example #12
0
void VMCUpdateRenyiWithDriftFast::advanceWalkers(WalkerIter_t it, WalkerIter_t it_end, bool measure)
{
  myTimers[0]->start();
  WalkerIter_t begin(it);
  for (; it != it_end; ++it)
  {
    Walker_t& thisWalker(**it);
    Walker_t::Buffer_t& w_buffer(thisWalker.DataSet);
    W.loadWalker(thisWalker,true);
    Psi.copyFromBuffer(W,w_buffer);
    myTimers[1]->start();
    bool moved = false;
    for (int iter=0; iter<nSubSteps; ++iter)
    {
      //create a 3N-Dimensional Gaussian with variance=1
      makeGaussRandomWithEngine(deltaR,RandomGen);
      moved = false;
      for(int ig=0; ig<W.groups(); ++ig) //loop over species
      {
        RealType tauovermass = Tau*MassInvS[ig];
        RealType oneover2tau = 0.5/(tauovermass);
        RealType sqrttau = std::sqrt(tauovermass);
        for (int iat=W.first(ig); iat<W.last(ig); ++iat)
        {
          GradType grad_now=Psi.evalGrad(W,iat), grad_new;
          PosType dr;
          getScaledDrift(tauovermass,grad_now,dr);
          dr += sqrttau*deltaR[iat];
          if (!W.makeMoveAndCheck(iat,dr))
          {
            ++nReject;
            continue;
          }
          //PosType newpos = W.makeMove(iat,dr);
          RealType ratio = Psi.ratioGrad(W,iat,grad_new);
          RealType prob = ratio*ratio;
          //zero is always rejected
          if (prob<numeric_limits<RealType>::epsilon())
          {
            ++nReject;
            W.rejectMove(iat);
            Psi.rejectMove(iat);
            continue;
          }
          RealType logGf = -0.5e0*dot(deltaR[iat],deltaR[iat]);
          getScaledDrift(tauovermass,grad_new,dr);
          dr = thisWalker.R[iat]-W.R[iat]-dr;
          RealType logGb = -oneover2tau*dot(dr,dr);
          if (RandomGen() < prob*std::exp(logGb-logGf))
          {
            moved = true;
            ++nAccept;
            W.acceptMove(iat);
            Psi.acceptMove(W,iat);
          }
          else
          {
            ++nReject;
            W.rejectMove(iat);
            Psi.rejectMove(iat);
          }
        }
      }
      //for subSteps must update thiswalker
      thisWalker.R=W.R;
      thisWalker.G=W.G;
      thisWalker.L=W.L;
    }
    myTimers[1]->stop();
    //Always compute the energy
    //if(moved)
    {
      myTimers[2]->start();
      //thisWalker.R = W.R;
      //w_buffer.rewind();
      //W.updateBuffer(w_buffer);
      RealType logpsi = Psi.updateBuffer(W,w_buffer,false);
      W.saveWalker(thisWalker);
      myTimers[2]->stop();
      myTimers[3]->start();
      RealType eloc=H.evaluate(W);
      myTimers[3]->stop();
      //thisWalker.resetProperty(std::log(abs(psi)), psi,eloc);
      thisWalker.resetProperty(logpsi,Psi.getPhase(), eloc);
      H.auxHevaluate(W,thisWalker);
      H.saveProperty(thisWalker.getPropertyBase());
    }
    if(!moved)
      ++nAllRejected;
    //else
    //{
    //  ++nAllRejected;
    //  H.rejectedMove(W,thisWalker);
    //}
  }
  myTimers[0]->stop();
}
Example #13
0
void VMCUpdatePbyP::advanceWalkers(WalkerIter_t it, WalkerIter_t it_end, bool measure)
{
  myTimers[0]->start();
  for (; it != it_end; ++it)
  {
    Walker_t& thisWalker(**it);
    W.loadWalker(thisWalker,true);
    Walker_t::Buffer_t& w_buffer(thisWalker.DataSet);
    Psi.copyFromBuffer(W,w_buffer);
    myTimers[1]->start();
    for (int iter=0; iter<nSubSteps; ++iter)
    {
      makeGaussRandomWithEngine(deltaR,RandomGen);
      bool stucked=true;
      for(int ig=0; ig<W.groups(); ++ig) //loop over species
      {
        RealType sqrttau = std::sqrt(Tau*MassInvS[ig]);
        for (int iat=W.first(ig); iat<W.last(ig); ++iat)
        {
          PosType dr = sqrttau*deltaR[iat];
          //replace makeMove by makeMoveAndCheck
          //PosType newpos = W.makeMove(iat,dr);
          if (W.makeMoveAndCheck(iat,dr))
          {
            RealType ratio = Psi.ratio(W,iat);
            RealType prob = ratio*ratio;
            //RealType prob = std::min(1.0e0,ratio*ratio);
            if (RandomGen() < prob)
            {
              stucked=false;
              ++nAccept;
              W.acceptMove(iat);
              Psi.acceptMove(W,iat);
            }
            else
            {
              ++nReject;
              W.rejectMove(iat);
              Psi.rejectMove(iat);
            }
          }
          else //reject illegal moves
            ++nReject;
        } //iat
      }//ig for the species
      if (stucked)
      {
        ++nAllRejected;
        //H.rejectedMove(W,thisWalker);
      }
      thisWalker.R=W.R;
    }
    myTimers[1]->stop();
    myTimers[2]->start();
    //thisWalker.R = W.R;
    //PAOps<RealType,OHMMS_DIM>::copy(W.G,thisWalker.Drift);
    //w_buffer.rewind();
    //W.updateBuffer(w_buffer);
    RealType logpsi = Psi.updateBuffer(W,w_buffer,false);
    W.saveWalker(thisWalker);
    //W.copyToBuffer(w_buffer);
    //RealType logpsi = Psi.evaluate(W,w_buffer);
    myTimers[2]->stop();
    myTimers[3]->start();
    RealType eloc=H.evaluate(W);
    myTimers[3]->stop();
    thisWalker.resetProperty(logpsi,Psi.getPhase(),eloc);
    H.auxHevaluate(W,thisWalker);
    H.saveProperty(thisWalker.getPropertyBase());
  }
  myTimers[0]->stop();
}