Пример #1
0
TrialWaveFunction::RealType TrialWaveFunction::registerData(ParticleSet& P, PooledData<RealType>& buf)
{
  delta_G.resize(P.getTotalNum());
  delta_L.resize(P.getTotalNum());
  P.G = 0.0;
  P.L = 0.0;
  //save the current position
  BufferCursor=buf.current();
  ValueType logpsi(0.0);
  PhaseValue=0.0;
  vector<OrbitalBase*>::iterator it(Z.begin());
  vector<OrbitalBase*>::iterator it_end(Z.end());
  for (; it!=it_end; ++it)
  {
    logpsi += (*it)->registerData(P,buf);
    PhaseValue += (*it)->PhaseValue;
  }
  convert(logpsi,LogValue);
  //LogValue=real(logpsi);
//append current gradients and laplacians to the buffer
  NumPtcls = P.getTotalNum();
  TotalDim = PosType::Size*NumPtcls;
  buf.add(PhaseValue);
  buf.add(LogValue);
  buf.add(&(P.G[0][0]), &(P.G[0][0])+TotalDim);
  buf.add(&(P.L[0]), &(P.L[P.getTotalNum()]));
  return LogValue;
}
Пример #2
0
  TrialWaveFunction::RealType
  TrialWaveFunction::registerData(ParticleSet& P, PooledData<RealType>& buf) {
    delta_G.resize(P.getTotalNum());
    delta_L.resize(P.getTotalNum());

    P.G = 0.0;
    P.L = 0.0;

    ValueType logpsi(0.0);
    PhaseValue=0.0;
    vector<OrbitalBase*>::iterator it(Z.begin());
    vector<OrbitalBase*>::iterator it_end(Z.end());
    for(;it!=it_end; ++it)
    {
      logpsi += (*it)->registerData(P,buf);
      PhaseValue += (*it)->PhaseValue;
    }

    LogValue=real(logpsi);

    //append current gradients and laplacians to the buffer
    NumPtcls = P.getTotalNum();
    TotalDim = PosType::Size*NumPtcls;

    buf.add(&(P.G[0][0]), &(P.G[0][0])+TotalDim);
    buf.add(&(P.L[0]), &(P.L[P.getTotalNum()]));

    return LogValue;
//     cout << "Registering gradients and laplacians " << endl;
//     for(int i=0; i<P.getLocalNum(); i++) {
//       cout << P.G[i] << " " << P.L[i] << endl;
//     }
  }
Пример #3
0
TrialWaveFunction::RealType TrialWaveFunction::evaluateDeltaLog(ParticleSet& P, PooledData<RealType>& buf)
{
  P.G = 0.0;
  P.L = 0.0;
  ValueType logpsi(0.0);
  PhaseValue=0.0;
  buf.rewind();
  vector<OrbitalBase*>::iterator it(Z.begin());
  vector<OrbitalBase*>::iterator it_end(Z.end());
  for (; it!=it_end; ++it)
  {
// mmorales: I don't remember if I did this, but eliminating the "if ((*it)->Optimizable)"
//           forces everything to be evaluated. This was probably done because for optm with the
//           nonlocal component in the cost function, the slater determinant might not be optimizable
//           but this must be called anyway to load the inverse. CHECK CHECK CHECK, FIX FIX FIX
    if ((*it)->Optimizable)
    {
      logpsi += (*it)->evaluateLog(P, P.G, P.L,buf,false);
      PhaseValue += (*it)->PhaseValue;
    }
    else
//          ValueType x = (*it)->evaluateLog(P, P.G, P.L,buf,false);
      (*it)->copyFromDerivativeBuffer(P,buf);//keep buffer synched
  }
  convert(logpsi,LogValue);
  return LogValue;
  //return LogValue=real(logpsi);
}
Пример #4
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;
    }
}
Пример #5
0
  ///initialize polymers
  void ReptationMC::initReptile() {
    
    //overwrite the number of cuts for Bounce algorithm
    if(UseBounce) NumCuts = 1;

    app_log() << "Moving " << NumCuts << " for each reptation step" << endl;

    //Reptile is NOT allocated. Create one.
    if(Reptile == 0) {
      MCWalkerConfiguration::iterator it(W.begin());
      Walker_t* cur(*it);
      cur->Weight=1.0;     
      W.R = cur->R;
      //DistanceTable::update(W);
      W.update();
      RealType logpsi(Psi.evaluateLog(W));
      RealType  eloc_cur = H.evaluate(W);
      cur->resetProperty(logpsi,Psi.getPhase(),eloc_cur);
      H.saveProperty(cur->getPropertyBase());
      cur->Drift = W.G;
      Reptile  = new PolymerChain(cur,PolymerLength,NumCuts);
      Reptile->resizeArrays(1);
    }

    //If ClonePolyer==false, generate configuration using diffusion
    //Not so useful
    if(!ClonePolymer) {
      Walker_t* cur((*Reptile)[0]);
      RealType g = std::sqrt(Tau);
      for(int i=0; i<NumCuts-1; i++ ) {
        //create a 3N-Dimensional Gaussian with variance=1
        makeGaussRandom(deltaR);
        W.R = cur->R + g*deltaR + Tau*cur->Drift;
        
        //update the distance table associated with W
        //DistanceTable::update(W);
        W.update();
        
        //evaluate wave function
        RealType logpsic(Psi.evaluateLog(W));
        RealType e0=H.evaluate(W);
        cur = (*Reptile)[i+1];	  
        cur->resetProperty(logpsic,Psi.getPhase(),e0);
        H.saveProperty(cur->getPropertyBase());

        cur->R = W.R;
        cur->Drift = W.G;
      }
    }
  }
Пример #6
0
 /** evaluate the log value of a many-body wave function
  * @param P input configuration containing N particles
  * @param needratio users request ratio evaluation
  * @param buf anonymous storage for the reusable data
  * @return the value of \f$ \log( \Pi_i \Psi_i) \f$  many-body wave function
  *
  * @if needratio == true
  *  need to update the data from buf, since external objects need to evaluate ratios, e.g., non-local pseudopotentials
  * @else
  *  evaluate the value only
  *
  * Upon return, the gradient and laplacian operators are added by the components.
  * Each OrbitalBase evaluates PhaseValue and LogValue = log(abs(psi_i))
  * Jastrow functions always have PhaseValue=1.
  */
 TrialWaveFunction::RealType 
 TrialWaveFunction::evaluateDeltaLog(ParticleSet& P) {
   P.G = 0.0;
   P.L = 0.0;
   ValueType logpsi(0.0);
   PhaseValue=0.0;
   vector<OrbitalBase*>::iterator it(Z.begin());
   vector<OrbitalBase*>::iterator it_end(Z.end());
   for(; it!=it_end; ++it)
   {
     if((*it)->Optimizable) {
       logpsi += (*it)->evaluateLog(P, P.G, P.L); 
       PhaseValue += (*it)->PhaseValue;
     }
   }
   return LogValue=real(logpsi);
 }
Пример #7
0
  /** return log(|psi|)
   *
   * PhaseValue is the phase for the complex wave function
   */
  TrialWaveFunction::RealType
  TrialWaveFunction::evaluateLog(ParticleSet& P) {
    P.G = 0.0;
    P.L = 0.0;

    ValueType logpsi(0.0);
    PhaseValue=0.0;
    vector<OrbitalBase*>::iterator it(Z.begin());
    vector<OrbitalBase*>::iterator it_end(Z.end());

    //WARNING: multiplication for PhaseValue is not correct, fix this!!
    for(; it!=it_end; ++it)
    {
      logpsi += (*it)->evaluateLog(P, P.G, P.L); 
      PhaseValue += (*it)->PhaseValue;
    }
    return LogValue=real(logpsi);
  }
Пример #8
0
/** return log(|psi|)
*
* PhaseValue is the phase for the complex wave function
*/
TrialWaveFunction::RealType
TrialWaveFunction::evaluateLogOnly(ParticleSet& P)
{
  //TAU_PROFILE("TrialWaveFunction::evaluateLogOnly","ParticleSet& P", TAU_USER);
  tempP->R=P.R;
  tempP->L=0.0;
  tempP->G=0.0;
  ValueType logpsi(0.0);
  PhaseValue=0.0;
  vector<OrbitalBase*>::iterator it(Z.begin());
  vector<OrbitalBase*>::iterator it_end(Z.end());
  //WARNING: multiplication for PhaseValue is not correct, fix this!!
  for (; it!=it_end; ++it)
  {
    logpsi += (*it)->evaluateLog(*tempP, tempP->G, tempP->L);
    PhaseValue += (*it)->PhaseValue;
  }
  convert(logpsi,LogValue);
  return LogValue;
  //return LogValue=real(logpsi);
}
Пример #9
0
  TrialWaveFunction::RealType
  TrialWaveFunction::updateBuffer(ParticleSet& P, PooledData<RealType>& buf,
      bool fromscratch) {
    P.G = 0.0;
    P.L = 0.0;

    ValueType logpsi(0.0);
    PhaseValue=0.0;
    vector<OrbitalBase*>::iterator it(Z.begin());
    vector<OrbitalBase*>::iterator it_end(Z.end());
    for(int ii=1; it!=it_end; ++it,ii+=TIMER_SKIP)
    {
      myTimers[ii]->start();
      logpsi += (*it)->updateBuffer(P,buf,fromscratch);
      PhaseValue += (*it)->PhaseValue;
      myTimers[ii]->stop();
    }

    LogValue=real(logpsi);
    buf.put(&(P.G[0][0]), &(P.G[0][0])+TotalDim);
    buf.put(&(P.L[0]), &(P.L[0])+NumPtcls);
    return LogValue;
  }
Пример #10
0
bool DummyQMC::run()
{
  m_oneover2tau = 0.5/Tau;
  m_sqrttau = sqrt(Tau);
  cout << "Lattice of ParticleSet " << endl;
  W.Lattice.print(cout);
  //property container to hold temporary properties, such as a local energy
  //MCWalkerConfiguration::PropertyContainer_t Properties;
  MCWalkerConfiguration::Walker_t& thisWalker(**W.begin());
  //create a 3N-Dimensional Gaussian with variance=1
  makeGaussRandom(deltaR);
  //new poosition
  W.R = m_sqrttau*deltaR + thisWalker.R + thisWalker.Drift;
  //apply boundary condition: put everything back to a unit cell
  W.applyBC(W.R);
  //update the distance table associated with W
  W.update();
  //evaluate wave function
  //update the properties: note that we are getting \f$\sum_i \ln(|psi_i|)\f$ and catching the sign separately
  ValueType logpsi(Psi.evaluateLog(W));
  RealType eloc=H.evaluate(W);
  return true;
}
Пример #11
0
TrialWaveFunction::RealType TrialWaveFunction::updateBuffer(ParticleSet& P
    , PooledData<RealType>& buf, bool fromscratch)
{
  //TAU_PROFILE("TrialWaveFunction::updateBuffer","(P,..)", TAU_USER);
  P.G = 0.0;
  P.L = 0.0;
  buf.rewind(BufferCursor);
  ValueType logpsi(0.0);
  PhaseValue=0.0;
  vector<OrbitalBase*>::iterator it(Z.begin());
  vector<OrbitalBase*>::iterator it_end(Z.end());
  for (; it!=it_end; ++it)
  {
    logpsi += (*it)->updateBuffer(P,buf,fromscratch);
    PhaseValue += (*it)->PhaseValue;
  }
  convert(logpsi,LogValue);
  //LogValue=real(logpsi);
  buf.put(PhaseValue);
  buf.put(LogValue);
  buf.put(&(P.G[0][0]), &(P.G[0][0])+TotalDim);
  buf.put(&(P.L[0]), &(P.L[0])+NumPtcls);
  return LogValue;
}
Пример #12
0
  bool FWSingleOMP::run() 
  {
    hdf_WGT_data.setFileName(xmlrootName);
    hdf_OBS_data.setFileName(xmlrootName);

    if (doWeights==1)
    {
      fillIDMatrix();        
      hdf_WGT_data.makeFile();
      hdf_WGT_data.openFile();
      hdf_WGT_data.addFW(0);
      for (int i=0;i<Weights.size();i++) hdf_WGT_data.addStep(i,Weights[i]);
      hdf_WGT_data.closeFW();
      hdf_WGT_data.closeFile();
      for(int ill=1;ill<weightLength;ill++)
      {
        transferParentsOneGeneration();
        FWOneStep();
        //       WeightHistory.push_back(Weights);
        hdf_WGT_data.openFile();
        hdf_WGT_data.addFW(ill);
        for (int i=0;i<Weights.size();i++) hdf_WGT_data.addStep(i,Weights[i]);
        hdf_WGT_data.closeFW();
        hdf_WGT_data.closeFile();
      }
    }
    else
    {
      fillIDMatrix();
      //           find weight length from the weight file
      hid_t f_file = H5Fopen(hdf_WGT_data.getFileName().c_str(),H5F_ACC_RDONLY,H5P_DEFAULT);
      hsize_t numGrps = 0;
      H5Gget_num_objs(f_file, &numGrps);
      weightLength = static_cast<int> (numGrps)-1;
      if (H5Fclose(f_file)>-1) f_file=-1;
      if (verbose>0) app_log()<<" weightLength "<<weightLength<<endl;
    }
    if (verbose>0) app_log()<<" Done Computing Weights"<<endl;


    if (doObservables==1)
    {
      int nprops = H.sizeOfObservables();//local energy, local potnetial and all hamiltonian elements
      int FirstHamiltonian = H.startIndex();
      //     vector<vector<vector<RealType> > > savedValues;

      int nelectrons = W[0]->R.size();
      int nfloats=OHMMS_DIM*nelectrons;


      //     W.clearEnsemble();
      makeClones(W,Psi,H);

      vector<ForwardWalkingData* > FWvector;
      for(int ip=0; ip<NumThreads; ip++) FWvector.push_back(new ForwardWalkingData(nelectrons));


      if (myComm->rank()==0) hdf_OBS_data.makeFile();
      hdf_float_data.openFile(fname.str());

      for(int step=0;step<numSteps;step++)
      {
        hdf_float_data.setStep(step);


        vector<RealType> stepObservables(walkersPerBlock[step]*(nprops+2), 0);
        for(int wstep=0; wstep<walkersPerBlock[step];)
        {
          vector<float> ThreadsCoordinate(NumThreads*nfloats);
          int nwalkthread = hdf_float_data.getFloat(wstep*nfloats, (wstep+NumThreads)*nfloats, ThreadsCoordinate) / nfloats;
          //         for(int j=0;j<ThreadsCoordinate.size();j++)cout<<ThreadsCoordinate[j]<<" ";
          //         cout<<endl;
#pragma omp parallel for
          for(int ip=0; ip<nwalkthread; ip++) 
          {
            vector<float> SINGLEcoordinate(0);
            vector<float>::iterator TCB1(ThreadsCoordinate.begin()+ip*nfloats), TCB2(ThreadsCoordinate.begin()+(1+ip)*nfloats);

            SINGLEcoordinate.insert(SINGLEcoordinate.begin(),TCB1,TCB2);
            FWvector[ip]->fromFloat(SINGLEcoordinate);
            wClones[ip]->R=FWvector[ip]->Pos;
            wClones[ip]->update();
            RealType logpsi(psiClones[ip]->evaluateLog(*wClones[ip]));
            RealType eloc=hClones[ip]->evaluate( *wClones[ip] );
            hClones[ip]->auxHevaluate(*wClones[ip]);
            int indx=(wstep+ip)*(nprops+2);
            stepObservables[indx]= eloc;
            stepObservables[indx+1]= hClones[ip]->getLocalPotential();
            for(int i=0;i<nprops;i++) stepObservables[indx+i+2] = hClones[ip]->getObservable(i) ;
          }
          wstep+=nwalkthread;
          for(int ip=0; ip<NumThreads; ip++)  wClones[ip]->resetCollectables();
        }
        hdf_OBS_data.openFile();
        hdf_OBS_data.addStep(step, stepObservables);
        hdf_OBS_data.closeFile();
        //       savedValues.push_back(stepObservables);
        hdf_float_data.endStep();
        if (verbose >1) cout<<"Done with step: "<<step<<endl;
      }
    }


    if(doDat>=1)
    {
      vector<int> Dimensions(4);
      hdf_WGT_data.openFile();
      hdf_OBS_data.openFile();
      Estimators->start(weightLength,1);
      int nprops;
      if (doObservables==1) nprops = H.sizeOfObservables()+2;
      else
      {
        int Noo = hdf_OBS_data.numObsStep(0);
        int Nwl = hdf_WGT_data.numWgtStep(0);
        nprops = Noo/Nwl;
      }
      for(int ill=0;ill<weightLength;ill++)
      {    
        Dimensions[0]=ill;
        Dimensions[1]= nprops ;
        Dimensions[2]=numSteps;
        Dimensions[3]=startStep;
        Estimators->startBlock(1);
        Estimators->accumulate(hdf_OBS_data,hdf_WGT_data,Dimensions);
        Estimators->stopBlock(getNumberOfSamples(ill));
      }
      hdf_OBS_data.closeFile();
      hdf_WGT_data.closeFile();
      Estimators->stop();
    }
    return true;
  }
Пример #13
0
  void 
  ReptationMC::moveReptile(){
    
    //RealType oneovertau = 1.0/Tau;
    //RealType oneover2tau = 0.5*oneovertau;
    RealType tauover2 = 0.5*Tau;
    RealType g = std::sqrt(Tau);
    
    typedef MCWalkerConfiguration::PropertyContainer_t PropertyContainer_t;
    if(!UseBounce && Random()<0.5) {
      Reptile->flip(); 	  
      NumTurns++;
    }

    Walker_t* anchor = Reptile->makeEnds();
      
    //save the local energies of the anchor and tails
    //eloc_xp = the energy of the front
    //eloc_yp = the energy of the proposed move
    //eloc_x = the energy of the tail
    //eloc_y = the energy of the tail-1
    RealType eloc_xp = anchor->Properties(LOCALENERGY);
    RealType eloc_x =  Reptile->tails[0]->Properties(LOCALENERGY);
    RealType eloc_y =  Reptile->tails[1]->Properties(LOCALENERGY);

    NumCuts = Reptile->NumCuts;
    RealType Wpolymer=0.0;

    for(int i=0; i<NumCuts; ) {

      Walker_t* head=Reptile->heads[i];
      
      //create a 3N-Dimensional Gaussian with variance=1
      makeGaussRandom(deltaR);
      W.R = anchor->R + g*deltaR + Tau* anchor->Drift;
      
      //update the distance table associated with W
      //DistanceTable::update(W);
      W.update();
      
      //evaluate wave function
      RealType logpsi(Psi.evaluateLog(W));
      
      //update the properties of the front chain
      //RealType eloc_yp = head->Properties(LOCALENERGY) = H.evaluate(W);
      //H.copy(head->getEnergyBase());
      //head->Properties(LOCALPOTENTIAL) = H.getLocalPotential();
      RealType eloc_yp = H.evaluate(W);
      head->resetProperty(logpsi,Psi.getPhase(),eloc_yp);
      H.saveProperty(head->getPropertyBase());
      
      head->R = W.R;
      
      //ValueType vsq = Dot(W.G,W.G);
      //ValueType scale = ((-1.0+sqrt(1.0+2.0*Tau*vsq))/vsq);
      //head->Drift = scale*W.G;
      head->Drift = W.G;
      
      //\f${x-y-\tau\nabla \ln \Psi_{T}(y))\f$
      //deltaR = anchor->R - W.R - heads[i]->Drift;
      //Gdrift *= exp(-oneover2tau*Dot(deltaR,deltaR));
      /* 
         \f$ X= \{R_0, R_1, ... , R_M\}\f$
         \f$ X' = \{R_1, .., R_M, R_{M+1}\}\f$
         \f[ G_B(R_{M+1}\leftarrow R_{M}, \tau)/G_B(R_{0}\leftarrow R_{1}, \tau)
         = exp\(-\tau/2[E_L(R_{M+1})+E_L(R_M)-E_L(R_1)-E_L(R_0)]\)\f]
         *
         -  eloc_yp = \f$E_L(R_{M+1})\f$
         -  eloc_xp = \f$E_L(R_{M})\f$
         -  eloc_y = \f$E_L(R_{1})\f$
         -  eloc_x = \f$E_L(R_{0})\f$
      */ 
      //Wpolymer *= exp(-oneover2tau*(eloc_yp+eloc_xp-eloc_x-eloc_y));
      Wpolymer +=(eloc_yp+eloc_xp-eloc_x-eloc_y);

      //move the anchor and swap the local energies for Wpolymer
      anchor=head;
      
      //increment the index
      i++;
      if(i<NumCuts) {
        eloc_xp  = eloc_yp;
        eloc_x = eloc_y;
        eloc_y = Reptile->tails[i+1]->Properties(LOCALENERGY);
      }
    }

    Wpolymer = std::exp(-tauover2*Wpolymer);
    double accept = std::min(1.0,Wpolymer);
    if(Random() < accept){//move accepted
      Reptile->updateEnds();
      ++nAccept;
    } else {
      ++nReject; 
      if(UseBounce) {
        NumTurns++;
        Reptile->flip();
      }
    }
    //RealType Bounce =  UseBounce ? 1.0-accept: 0.5;
    //if(Random()<Bounce) {
    //  Reptile->flip();
    //  LogOut->getStream() << "Bounce = " << Bounce << " " << NumTurns << " " << polymer.MoveHead << endl;
    //  NumTurns++;//increase the number of turns
    //}
  }
Пример #14
0
  void 
  DMCWOS::advanceWalkerByWalker(BRANCHER& Branch) {
    

    //Pooma::Clock timer;
    RealType oneovertau = 1.0/Tau;
    RealType oneover2tau = 0.5*oneovertau;
    RealType g = sqrt(Tau);
    RealType vwos;

    //MCWalkerConfiguration::PropertyContainer_t Properties;
    int nh = H.size()+1;
    
    // extract the WOS potential
    //WOSPotential* wos = dynamic_cast<WOSPotential*>(H.getHamiltonian("wos"));


    MCWalkerConfiguration::iterator it = W.begin(); 
    MCWalkerConfiguration::iterator it_end = W.end(); 
    while(it != it_end) {
      
      (*it)->Properties(WEIGHT) = 1.0;
      (*it)->Properties(MULTIPLICITY) = 1.0;
      
      //copy the properties of the working walker
      W.Properties = (*it)->Properties;

      //save old local energy
      ValueType eold = W.Properties(LOCALENERGY);

      /*
	If doing WOS then we have to redo the old calculation for ROld to
	calculate G(Rold,Rnew). So we extract wos from the Hamiltonian and
	re-evaluate it.
      */
      ValueType emixed = eold;

      if(wos_ref) {
	W.R = (*it)->R;
	DistanceTable::update(W);
	ValueType psi(Psi.evaluateLog(W));//not used anyway
	eold = H.evaluate(W);
	emixed += 0.5*W.Properties(WOSVAR)*Tau_var;
      }
      //ValueType emixed = eold + 0.5*W.Properties(WOSVAR)*Tau;  

      //create a 3N-Dimensional Gaussian with variance=1
      makeGaussRandom(deltaR);
      
      W.R = g*deltaR + (*it)->R + (*it)->Drift;
      
      //update the distance table associated with W
      DistanceTable::update(W);
      
      //evaluate wave function
      ValueType logpsi(Psi.evaluateLog(W));
      //update the properties
      W.Properties(LOCALENERGY) = H.evaluate(W);
      W.Properties(LOGPSI) =logpsi;
      W.Properties(SIGN) = Psi.getSign();
      bool accepted=false; 

      //deltaR = W.R - (*it)->R - (*it)->Drift;
      //RealType forwardGF = exp(-oneover2tau*Dot(deltaR,deltaR));
      //RealType forwardGF = exp(-0.5*Dot(deltaR,deltaR));
      RealType logGf = -0.5*Dot(deltaR,deltaR);
      
      //scale the drift term to prevent persistent cofigurations
      ValueType vsq = Dot(W.G,W.G);
      
      //converting gradients to drifts, D = tau*G (reuse G)
      //   W.G *= Tau;//original implementation with bare drift
      ValueType scale = ((-1.0+sqrt(1.0+2.0*Tau*vsq))/vsq);
      drift = scale*W.G;
      deltaR = (*it)->R - W.R - drift;
      //RealType backwardGF = exp(-oneover2tau*Dot(deltaR,deltaR));
      RealType logGb = -oneover2tau*Dot(deltaR,deltaR);
      
      //set acceptance probability
      //RealType prob= std::min(backwardGF/forwardGF*W.Properties(PSISQ)/(*it)->Properties(PSISQ),1.0);
      //RealType prob= std::min(exp(logGb-logGf)*W.Properties(PSISQ)/(*it)->Properties(PSISQ),1.0);
      RealType prob= std::min(exp(logGb-logGf +2.0*(W.Properties(LOGPSI)-(*it)->Properties(LOGPSI))),1.0);
      
      if(Random() > prob){
	(*it)->Properties(AGE)++;
	emixed += emixed;
      } else {
	accepted=true;  
	W.Properties(AGE) = 0;
	(*it)->R = W.R;
	(*it)->Drift = drift;
	(*it)->Properties = W.Properties;
	H.copy((*it)->getEnergyBase());
	emixed += W.Properties(LOCALENERGY) + 0.5*W.Properties(WOSVAR)*Tau_var;
      }
      
      //calculate the weight and multiplicity
      ValueType M = Branch.branchGF(Tau,emixed*0.5,1.0-prob);
      if((*it)->Properties(AGE) > 3.0) M = min(0.5,M);
      if((*it)->Properties(AGE) > 0.9) M = min(1.0,M);
      (*it)->Properties(WEIGHT) = M; 
      (*it)->Properties(MULTIPLICITY) = M + Random();
      
      //node-crossing: kill it for the time being
      if(Branch(W.Properties(SIGN),(*it)->Properties(SIGN))) {
	accepted=false;     
	(*it)->Properties(WEIGHT) = 0.0; 
	(*it)->Properties(MULTIPLICITY) = 0.0;
      }
      /*      
      if(Branch(W.Properties(PSI),(*it)->Properties(PSI))) {
	accepted=false;     
	(*it)->Properties(WEIGHT) = 0.0; 
	(*it)->Properties(MULTIPLICITY) = 0.0;
      } else {

	RealType logGf = -0.5*Dot(deltaR,deltaR);

	ValueType vsq = Dot(W.G,W.G);
	ValueType scale = ((-1.0+sqrt(1.0+2.0*Tau*vsq))/vsq);
	drift = scale*W.G;
	deltaR = (*it)->R - W.R - drift;
	RealType logGb = -oneover2tau*Dot(deltaR,deltaR);
      
	RealType prob
	  = std::min(exp(logGb-logGf)*W.Properties(PSISQ)/(*it)->Properties(PSISQ),1.0);
      
	if(Random() > prob){
	  (*it)->Properties(AGE)++;
	  emixed += emixed;
	} else {
	  accepted=true;  
	  W.Properties(AGE) = 0;
	  (*it)->R = W.R;
	  (*it)->Drift = drift;
	  (*it)->Properties = W.Properties;
	  // H.update(W.Energy[(*it)->ID]);
	  //H.get((*it)->E);
	  H.copy((*it)->getEnergyBase());
	  emixed += W.Properties(LOCALENERGY) + 0.5*W.Properties(WOSVAR)*Tau_var;
	}
	
	//calculate the weight and multiplicity
	ValueType M = Branch.branchGF(Tau,emixed*0.5,1.0-prob);
	if((*it)->Properties(AGE) > 3.0) M = min(0.5,M);
	if((*it)->Properties(AGE) > 0.9) M = min(1.0,M);
	(*it)->Properties(WEIGHT) = M; 
	(*it)->Properties(MULTIPLICITY) = M + Random();
      }
      */
      if(accepted) 
        ++nAccept;
      else 
        ++nReject;
      ++it;
    }
  }
Пример #15
0
bool FWSingle::run()
{
  Estimators->start(weightLength,1);
  fillIDMatrix();
  //we do this once because we only want to link parents to parents if we need to
  //     if (verbose>1) app_log()<<" getting weights for generation "<<gensTransferred<<endl;
  vector<vector<vector<int> > > WeightHistory;
  WeightHistory.push_back(Weights);
  for(int ill=1; ill<weightLength; ill++)
  {
    transferParentsOneGeneration();
    FWOneStep();
    WeightHistory.push_back(Weights);
  }
  if (verbose>0)
    app_log()<<" Done Computing Weights"<<endl;
  int nprops = H.sizeOfObservables();//local energy, local potnetial and all hamiltonian elements
  int FirstHamiltonian = H.startIndex();
  vector<vector<vector<RealType> > > savedValues;
  int nelectrons = W[0]->R.size();
  int nfloats=OHMMS_DIM*nelectrons;
  ForwardWalkingData fwer;
  fwer.resize(nelectrons);
  //      MCWalkerConfiguration* savedW = new MCWalkerConfiguration(W);
  for(int step=0; step<numSteps; step++)
  {
    vector<float> ALLcoordinates;
    readInFloat(step,ALLcoordinates);
    vector<float> SINGLEcoordinate(nfloats);
    vector<float>::iterator fgg(ALLcoordinates.begin()), fgg2(ALLcoordinates.begin()+nfloats);
    W.resetCollectables();
    vector<vector<RealType> > stepObservables;
    for(int wstep=0; wstep<walkersPerBlock[step]; wstep++)
    {
      std::copy( fgg,fgg2,SINGLEcoordinate.begin());
      fwer.fromFloat(SINGLEcoordinate);
      W.R=fwer.Pos;
      fgg+=nfloats;
      fgg2+=nfloats;
      W.update();
      RealType logpsi(Psi.evaluateLog(W));
      RealType eloc=H.evaluate( W );
      //             (*W[0]).resetProperty(logpsi,1,eloc);
      H.auxHevaluate(W);
      H.saveProperty(W.getPropertyBase());
      vector<RealType> walkerObservables(nprops+2,0);
      walkerObservables[0]= eloc;
      walkerObservables[1]= H.getLocalPotential();
      const RealType* restrict ePtr = W.getPropertyBase();
      for(int i=0; i<nprops; i++)
        walkerObservables[i+2] = ePtr[FirstHamiltonian+i] ;
      stepObservables.push_back(walkerObservables);
    }
    savedValues.push_back(stepObservables);
  }
  for(int ill=0; ill<weightLength; ill++)
  {
    Estimators->startBlock(1);
    Estimators->accumulate(savedValues,WeightHistory[ill],getNumberOfSamples(ill));
    Estimators->stopBlock(getNumberOfSamples(ill));
  }
  Estimators->stop();
  return true;
}
Пример #16
0
  void 
    RQMCEstimator
    ::initialize(MCWalkerConfiguration& W, vector<ParticleSet*>& WW,
        SpaceWarp& Warp,
        vector<QMCHamiltonian*>& h, 
        vector<TrialWaveFunction*>& psi,
        RealType tau,vector<RealType>& Norm,
        bool require_register) {

      NumWalkers = W.getActiveWalkers();

      int numPtcls(W.getTotalNum());

      RatioIJ.resize(NumWalkers,NumCopies*(NumCopies-1)/2);

      vector<RealType> invsumratio(NumCopies);
      MCWalkerConfiguration::ParticlePos_t drift(numPtcls);

      MCWalkerConfiguration::iterator it(W.begin()); 
      MCWalkerConfiguration::iterator it_end(W.end()); 

      vector<RealType> sumratio(NumCopies), logpsi(NumCopies);
      vector<RealType> Jacobian(NumCopies);

      int jindex=W.addProperty("Jacobian");
      int iw(0);
      int DataSetSize((*it)->DataSet.size());
      while(it != it_end) {
        Walker_t& thisWalker(**it);
        (*it)->DataSet.rewind();

        //NECESSARY SINCE THE DISTANCE TABLE OF W ARE USED TO WARP
        if(require_register) {
          W.registerData(thisWalker,(*it)->DataSet);
        } else {
          W.R = thisWalker.R;
          W.update();
          if(DataSetSize) W.updateBuffer((*it)->DataSet);
        }

        for(int ipsi=0; ipsi<NumCopies; ipsi++) Jacobian[ipsi]=1.e0;
        for(int iptcl=0; iptcl< numPtcls; iptcl++){
          Warp.warp_one(iptcl,0);
          for(int ipsi=0; ipsi<NumCopies; ipsi++){
            WW[ipsi]->R[iptcl]=W.R[iptcl]+Warp.get_displacement(iptcl,ipsi);
            Jacobian[ipsi]*=Warp.get_Jacobian(iptcl,ipsi);
          }
          if(require_register || DataSetSize) Warp.update_one_ptcl_Jacob(iptcl);
        }

        for(int ipsi=0; ipsi<NumCopies; ipsi++){
          thisWalker.Properties(ipsi,jindex)=Jacobian[ipsi];
        }

        //update distance table and bufferize it if necessary
        if(require_register) {
          for(int ipsi=0; ipsi<NumCopies; ipsi++){ 
            WW[ipsi]->registerData((*it)->DataSet);
          }
          Warp.registerData(WW,(*it)->DataSet);
        } else {
          for(int ipsi=0; ipsi<NumCopies; ipsi++){
            WW[ipsi]->update();
            if(DataSetSize) WW[ipsi]->updateBuffer((*it)->DataSet);
          }
          if(DataSetSize) Warp.updateBuffer((*it)->DataSet);
        }



        //evalaute the wavefunction and hamiltonian
        for(int ipsi=0; ipsi< NumCopies;ipsi++) {			  
          psi[ipsi]->G.resize(numPtcls);
          psi[ipsi]->L.resize(numPtcls);
          //Need to modify the return value of OrbitalBase::registerData
          if(require_register) {
            logpsi[ipsi]=psi[ipsi]->registerData(*WW[ipsi],(*it)->DataSet);
          }else{
            if(DataSetSize)logpsi[ipsi]=psi[ipsi]->updateBuffer(*WW[ipsi],(*it)->DataSet);
            else logpsi[ipsi]=psi[ipsi]->evaluateLog(*WW[ipsi]); 		 
          }
          psi[ipsi]->G=WW[ipsi]->G;
          thisWalker.Properties(ipsi,LOGPSI)=logpsi[ipsi];
          thisWalker.Properties(ipsi,LOCALENERGY)=h[ipsi]->evaluate(*WW[ipsi]);
          h[ipsi]->saveProperty(thisWalker.getPropertyBase(ipsi));
          sumratio[ipsi]=1.0;
        } 							

        //Check SIMONE's note
        //Compute the sum over j of Psi^2[j]/Psi^2[i] for each i
        int indexij(0);
        RealType *rPtr=RatioIJ[iw];
        for(int ipsi=0; ipsi< NumCopies-1; ipsi++) {			  
          for(int jpsi=ipsi+1; jpsi< NumCopies; jpsi++){     		 
            RealType r= std::exp(2.0*(logpsi[jpsi]-logpsi[ipsi]))*Norm[ipsi]/Norm[jpsi];
            //BEWARE: RatioIJ DOES NOT INCLUDE THE JACOBIANS!
            rPtr[indexij++]=r;
            r*=(Jacobian[jpsi]/Jacobian[ipsi]);
            sumratio[ipsi] += r;                            
            sumratio[jpsi] += 1.0/r;		
          }                                              
        }                                               

        //Re-use Multiplicity as the sumratio
        thisWalker.Multiplicity=sumratio[0];

        /*START COMMENT
          QMCTraits::PosType WarpDrift;
          RealType denom(0.e0),wgtpsi;
          thisWalker.Drift=0.e0; 
          for(int ipsi=0; ipsi< NumCopies; ipsi++) {
          wgtpsi=1.e0/sumratio[ipsi];
          thisWalker.Properties(ipsi,UMBRELLAWEIGHT)=wgtpsi;
          denom += wgtpsi;
          for(int iptcl=0; iptcl< numPtcls; iptcl++){
          WarpDrift=dot( psi[ipsi]->G[iptcl], Warp.get_Jacob_matrix(iptcl,ipsi)  )
          +5.0e-1*Warp.get_grad_ln_Jacob(iptcl,ipsi) ;
          thisWalker.Drift[iptcl] += (wgtpsi*WarpDrift);
          }
          }
        //Drift = denom*Drift;
        thisWalker.Drift *= (tau/denom);
        END COMMENT*/
        for(int ipsi=0; ipsi< NumCopies ;ipsi++){
          invsumratio[ipsi]=1.0/sumratio[ipsi];
          thisWalker.Properties(ipsi,UMBRELLAWEIGHT)=invsumratio[ipsi];
        }
        setScaledDrift(tau,psi[0]->G,drift);
        thisWalker.Drift=invsumratio[0]*drift;
        for(int ipsi=1; ipsi< NumCopies ;ipsi++) {               		
          setScaledDrift(tau,psi[ipsi]->G,drift);
          thisWalker.Drift += (invsumratio[ipsi]*drift);
        }
        ++it;++iw;
      }
    }
Пример #17
0
  // old ones
  void 
    RQMCEstimator
    ::initialize(MCWalkerConfiguration& W, 
        vector<QMCHamiltonian*>& h, 
        vector<TrialWaveFunction*>& psi,
        RealType tau,vector<RealType>& Norm,
        bool require_register) {

      NumWalkers = W.getActiveWalkers();
      //allocate UmbrellaEnergy
      int numPtcls(W.getTotalNum());
      RatioIJ.resize(NumWalkers,NumCopies*(NumCopies-1)/2);

      MCWalkerConfiguration::iterator it(W.begin()); 
      MCWalkerConfiguration::iterator it_end(W.end()); 

      vector<RealType> sumratio(NumCopies), logpsi(NumCopies);
      int iw(0);
      int DataSetSize((*it)->DataSet.size());
      while(it != it_end) {

        Walker_t& thisWalker(**it);
        (*it)->DataSet.rewind();

        if(require_register) {
          W.registerData(thisWalker,(*it)->DataSet);
        } else {
          W.R = thisWalker.R;
          W.update();
          if(DataSetSize) W.updateBuffer((*it)->DataSet);
        }

        //evalaute the wavefunction and hamiltonian
        for(int ipsi=0; ipsi< NumCopies;ipsi++) {
          psi[ipsi]->G.resize(numPtcls);
          psi[ipsi]->L.resize(numPtcls);
          //Need to modify the return value of OrbitalBase::registerData
          if(require_register) {
            logpsi[ipsi]=psi[ipsi]->registerData(W,(*it)->DataSet);
          } else {
            if(DataSetSize)logpsi[ipsi]=psi[ipsi]->updateBuffer(W,(*it)->DataSet);
            else logpsi[ipsi]=psi[ipsi]->evaluateLog(W); 		 
          }
          psi[ipsi]->G=W.G;
          thisWalker.Properties(ipsi,LOGPSI)=logpsi[ipsi];
          thisWalker.Properties(ipsi,LOCALENERGY)=h[ipsi]->evaluate(W);
          h[ipsi]->saveProperty(thisWalker.getPropertyBase(ipsi));
          sumratio[ipsi]=1.0;
        } 							

        //Check SIMONE's note
        //Compute the sum over j of Psi^2[j]/Psi^2[i] for each i
        int indexij(0);
        RealType *rPtr=RatioIJ[iw];
        for(int ipsi=0; ipsi< NumCopies-1; ipsi++) {			  
          for(int jpsi=ipsi+1; jpsi< NumCopies; jpsi++){     		 
            RealType r= std::exp(2.0*(logpsi[jpsi]-logpsi[ipsi])); 
            rPtr[indexij++]=r*Norm[ipsi]/Norm[jpsi];
            sumratio[ipsi] += r;                            
            sumratio[jpsi] += 1.0/r;		
          }                                              
        }                                               

        //Re-use Multiplicity as the sumratio
        thisWalker.Multiplicity=sumratio[0];
        //DON't forget DRIFT!!!
        thisWalker.Drift=0.0;

        for(int ipsi=0; ipsi< NumCopies; ipsi++) {
          RealType wgt=1.0/sumratio[ipsi];
          thisWalker.Properties(ipsi,UMBRELLAWEIGHT)=wgt;

          //thisWalker.Drift += wgt*psi[ipsi]->G;
          PAOps<RealType,DIM>::axpy(wgt,psi[ipsi]->G,thisWalker.Drift);
        }
        thisWalker.Drift *= tau;
        ++it;++iw;
      }
    }
Пример #18
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);
    }
  }