コード例 #1
0
 //NOTE: weights are not handled nicely.
 //weight should be done carefully, not valid for DMC
 //will add a function to MCWalkerConfiguration to track total weight
 void EstimatorManager::accumulate(MCWalkerConfiguration& W)
 {
   BlockWeight += W.getActiveWalkers();
   RealType norm=1.0/W.getGlobalNumWalkers();
   for(int i=0; i< Estimators.size(); i++) 
     Estimators[i]->accumulate(W,W.begin(),W.end(),norm);
 }
コード例 #2
0
  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;
  }
コード例 #3
0
/** accumulate Local energies and collectables
 * @param W ensemble
 */
void EstimatorManager::accumulate(MCWalkerConfiguration& W)
{
  BlockWeight += W.getActiveWalkers();
  RealType norm=1.0/W.getGlobalNumWalkers();
  for(int i=0; i< Estimators.size(); i++)
    Estimators[i]->accumulate(W,W.begin(),W.end(),norm);
  if(Collectables)//collectables are normalized by QMC drivers
    Collectables->accumulate_all(W.Collectables,1.0);
}
コード例 #4
0
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;
}
コード例 #5
0
/**  Write the set of walker configurations to the HDF5 file.  
 *@param W set of walker configurations
 *@param ic the number of frames
 *
 * \if ic==-1
 *  use only the last frame for a restart
 * \else if ic>=0
 *  use ic frames from the file for opitimizations
 */
bool  
HDFWalkerInput0::put(MCWalkerConfiguration& W, int ic){

  if(Counter<0) return false;

  int selected = ic;
  if(ic<0) {
    XMLReport("Will use the last set from " << NumSets << " of configurations.")
    selected = NumSets-1;
  }

  typedef MCWalkerConfiguration::PosType PosType;
  typedef MCWalkerConfiguration::PropertyContainer_t ProtertyContainer_t;

  typedef Matrix<PosType>  PosContainer_t;

  int nwt = 0;
  int npt = 0;
  //2D array of PosTypes (x,y,z) indexed by (walker,particle)
  PosContainer_t Pos_temp;

  //open the group
  char GrpName[128];
  sprintf(GrpName,"config%04d",selected);
  hid_t group_id = H5Gopen(h_config,GrpName);
    
  HDFAttribIO<PosContainer_t> Pos_in(Pos_temp);
  //read the dataset
  Pos_in.read(group_id,"coord");
  //close the group
  H5Gclose(group_id);

  /*check to see if the number of walkers and particles is  consistent with W */
  int nptcl = Pos_temp.cols();
  nwt = Pos_temp.rows();

  int curWalker = W.getActiveWalkers();
  if(curWalker) {
    LOGMSG("Adding " << nwt << " walkers to " << curWalker)
    W.createWalkers(nwt);
  } else {
    W.resize(nwt,nptcl); 
  }

  //assign configurations to W
  int iw=0;
  MCWalkerConfiguration::iterator it = W.begin()+curWalker; 
  MCWalkerConfiguration::iterator it_end = W.end(); 
  while(it != it_end) {
    std::copy(Pos_temp[iw],Pos_temp[iw+1], (*it)->R.begin());
    ++it;++iw;
  }

  return true;
}
コード例 #6
0
/**
   @brief accumulate data for all the estimators
*/
void 
ScalarEstimatorManager::accumulate(const MCWalkerConfiguration& W) {

  for(MCWalkerConfiguration::const_iterator it = W.begin(); 
      it != W.end(); it++){    
    RealType wgt = (*it)->Properties(WEIGHT);
    WeightSum += wgt;
    for(int i=0; i< Estimators.size(); i++) 
      Estimators[i]->accumulate(**it,wgt);
  }
}
コード例 #7
0
 void WalkerControlBase::setWalkerID(MCWalkerConfiguration& walkers)
 {
   start(); //do the normal start
   MCWalkerConfiguration::iterator wit(walkers.begin());
   MCWalkerConfiguration::iterator wit_end(walkers.end());
   for(; wit != wit_end; ++wit)
   {
     if((*wit)->ID==0) 
     {
       (*wit)->ID=(++NumWalkersCreated)*NumContexts+MyContext;
       (*wit)->ParentID=(*wit)->ID;
     }
   }
 }
コード例 #8
0
 void EstimatorManager::getCurrentStatistics(MCWalkerConfiguration& W
     , RealType& eavg, RealType& var)
 {
   LocalEnergyOnlyEstimator energynow;
   energynow.clear();
   energynow.accumulate(W,W.begin(),W.end(),1.0);
   vector<RealType> tmp(3);
   tmp[0]= energynow.scalars[0].result();
   tmp[1]= energynow.scalars[0].result2();
   tmp[2]= energynow.scalars[0].count();
   myComm->allreduce(tmp);
   eavg=tmp[0]/tmp[2];
   var=tmp[1]/tmp[2]-eavg*eavg;
 }
コード例 #9
0
/** accumulate data for all the estimators
 */
void 
ScalarEstimatorManager::accumulate(const MCWalkerConfiguration& W) {

  RealType wgt_sum=0;
  MCWalkerConfiguration::const_iterator it(W.begin()),it_end(W.end());
  while(it != it_end) {
    RealType wgt = (*it)->Weight;
    wgt_sum+= wgt;
    for(int i=0; i< Estimators.size(); i++) Estimators[i]->accumulate(**it,wgt);
    ++it;
  }

  MyData[WEIGHT_INDEX]+=wgt_sum;
}
コード例 #10
0
bool  
HDFWalkerInput0::append(MCWalkerConfiguration& W, int blocks){

  if(Counter<0) return false;

  //if(nwalkers<0) return put(W,-1);

  typedef MCWalkerConfiguration::PosType PosType;
  typedef Matrix<PosType>  PosContainer_t;
  PosContainer_t Pos_temp;

  int nw_in=0;
  int firstConf=std::max(0,NumSets-blocks);
  if(blocks<0) firstConf=0;

  for(int iconf=firstConf; iconf<NumSets; iconf++) {
    //open the group
    char GrpName[128];
    sprintf(GrpName,"config%04d",iconf);
    hid_t group_id = H5Gopen(h_config,GrpName);
    HDFAttribIO<PosContainer_t> Pos_in(Pos_temp);
    //read the dataset
    Pos_in.read(group_id,"coord");
    //close the group
    H5Gclose(group_id);
    /*check to see if the number of walkers and particles is  consistent with W */
    int nptcl = Pos_temp.cols();
    int nwt = Pos_temp.rows();
    int curWalker=0;
    if(nptcl != W.getParticleNum()) {
      W.resize(nwt,nptcl); 
    } else {
      curWalker=W.getActiveWalkers();
      W.createWalkers(nwt);
    }
    MCWalkerConfiguration::iterator it = W.begin()+curWalker; 
    for(int iw=0; iw<nwt; iw++) {
      //std::copy(Post_temp[iw],Post_temp[iw+1], (*it)->R.begin());
      for(int iat=0; iat < nptcl; iat++){
        (*it)->R(iat) = Pos_temp(iw,iat);
      }
      ++it;
    }
    nw_in += nwt; 
  }

  LOGMSG("Total " << nw_in << " walkers are loaded using " << NumSets-firstConf << " blocks.")
  return true;
}
コード例 #11
0
 void Write2XYZ(MCWalkerConfiguration& W)
 {
   ofstream fout("bad.xyz");
   MCWalkerConfiguration::iterator it(W.begin());
   MCWalkerConfiguration::iterator it_end(W.end());
   int nptcls(W.getTotalNum());
   while(it != it_end) {
     fout << nptcls << endl 
       << "# E = " << (*it)->Properties(LOCALENERGY) 
       << " Wgt= " << (*it)->Weight << endl;
     for(int i=0; i<nptcls; i++)
       fout << "H " << (*it)->R[i] << endl;
     ++it;
   }
 }
コード例 #12
0
ファイル: CloneManager.cpp プロジェクト: digideskio/qmcpack
  void CloneManager::makeClones(MCWalkerConfiguration& w, 
      TrialWaveFunction& psi, QMCHamiltonian& ham)
  {

    if(wClones.size()) {
      app_log() << "  Cannot make clones again. Use existing " << NumThreads << " clones" << endl;
      return;
    }

    app_log() << "Number of threads = " << NumThreads << endl;
    wClones.resize(NumThreads,0);
    psiClones.resize(NumThreads,0);
    hClones.resize(NumThreads,0);

    wClones[0]=&w;
    psiClones[0]=&psi;
    hClones[0]=&ham;

#if defined(ENABLE_CLONE_PSI_AND_H)
    char pname[16];
    for(int ip=1; ip<NumThreads; ++ip) 
    {
      sprintf(pname,"%s.c%i",w.getName().c_str(),ip);
      wClones[ip]=new MCWalkerConfiguration(w);
      wClones[ip]->setName(pname);
      psiClones[ip]=psi.makeClone(*wClones[ip]);
      hClones[ip]=ham.makeClone(*wClones[ip],*psiClones[ip]);
    }
#else
    cloneEngine.clone(w,psi,ham,wClones,psiClones,hClones);
#endif
  }
コード例 #13
0
void
initialize(TrialWaveFunction& Psi, MCWalkerConfiguration& el,
           ParticleBase& ion) {

    enum {Up = 0, Down};

    ///add a distance table for ee IndexTypeeractions
    IndexType iee = DistanceTable::add(el,"ee");
    DistanceTableData* d_ee = DistanceTable::getTable(iee);
    ///add a distance table for ie interactions
    int iei = DistanceTable::add(ion,el,"ie");
    DistanceTableData* d_ei = DistanceTable::getTable(iei);

    ///create molecular orbital
    MolecularOrbitals<SlaterTypeOrbitals_t> *MO =
        new MolecularOrbitals<SlaterTypeOrbitals_t>;

    AtomicOrbitalBuilder<SlaterTypeOrbitals_t> orbitalbuilder;
    for(int iat=0; iat<ion.getTotalNum(); iat++) {
        orbitalbuilder.add("He",*MO);
    }
    MO->setTable(d_ei);

    typedef SlaterDeterminant<MolecularOrbitals<SlaterTypeOrbitals_t> > Det_t;
    Det_t *DetU = new Det_t(*MO,el.first(Up));
    DetU->set(el.first(Up),el.last(Up)-el.first(Up));

    Det_t* DetD = new Det_t(*MO,el.first(Down));
    DetD->set(el.first(Down),el.last(Down)-el.first(Down));

    LinearSlaterDeterminant<MolecularOrbitals<SlaterTypeOrbitals_t> >
    *asymmpsi
        = new LinearSlaterDeterminant<MolecularOrbitals<SlaterTypeOrbitals_t> >;

    asymmpsi->add(DetU);
    asymmpsi->add(DetD);

    Psi.add(asymmpsi,d_ei);

    /*
    OneBodyJastrow<PadeJastrow<ValueType>,FastWalkerIndex> *Jie
      = new OneBodyJastrow<PadeJastrow<ValueType>,FastWalkerIndex>;
    Jie->F.push_back(PadeJastrow<ValueType>(1.0,1.0));
    Psi.add(Jie,d_ei);
    */

    TwoBodyJastrow<PadeJastrow<ValueType>,FastWalkerIndex> *Jee
        = new TwoBodyJastrow<PadeJastrow<ValueType>,FastWalkerIndex>;

    Jee->F.push_back(PadeJastrow<double>(0.5,1.0));
    Jee->F.push_back(PadeJastrow<double>(1.0/6.0,1.0));
    Jee->F.push_back(PadeJastrow<double>(1.0/6.0,1.0));
    Jee->F.push_back(PadeJastrow<double>(0.5,1.0));
    Psi.add(Jee,d_ee);

}
コード例 #14
0
 void EstimatorManager::accumulate(MCWalkerConfiguration& W 
    , MCWalkerConfiguration::iterator it, MCWalkerConfiguration::iterator it_end)
 {
   BlockWeight += it_end-it;
   RealType norm=1.0/W.getGlobalNumWalkers();
   for(int i=0; i< Estimators.size(); i++) 
     Estimators[i]->accumulate(W,it,it_end,norm);
 }
コード例 #15
0
  int WalkerControlBase::copyWalkers(MCWalkerConfiguration& W) {
    //clear the WalkerList to populate them with the good walkers
    W.clear();
    W.insert(W.begin(), good_w.begin(), good_w.end());

    int cur_walker = good_w.size();
    for(int i=0; i<good_w.size(); i++) { //,ie+=ncols) {
      for(int j=0; j<ncopy_w[i]; j++, cur_walker++) 
      {
        Walker_t* awalker=new Walker_t(*(good_w[i]));
        awalker->ID=(++NumWalkersCreated)*NumContexts+MyContext;
        awalker->ParentID=good_w[i]->ParentID;
        W.push_back(awalker);
      }
    }

    //clear good_w and ncopy_w for the next branch
    good_w.clear();
    ncopy_w.clear();
    return W.getActiveWalkers();
  }
コード例 #16
0
int WalkerControlBase::doNotBranch(int iter, MCWalkerConfiguration& W)
{
    MCWalkerConfiguration::iterator it(W.begin());
    MCWalkerConfiguration::iterator it_end(W.end());
    RealType esum=0.0,e2sum=0.0,wsum=0.0,ecum=0.0, w2sum=0.0;
    RealType r2_accepted=0.0,r2_proposed=0.0;
    for(; it!=it_end; ++it)
    {
        r2_accepted+=(*it)->Properties(R2ACCEPTED);
        r2_proposed+=(*it)->Properties(R2PROPOSED);
        RealType e((*it)->Properties(LOCALENERGY));
        int nc= std::min(static_cast<int>((*it)->Multiplicity),MaxCopy);
        RealType wgt((*it)->Weight);
        esum += wgt*e;
        e2sum += wgt*e*e;
        wsum += wgt;
        w2sum += wgt*wgt;
        ecum += e;
    }

    //temp is an array to perform reduction operations
    std::fill(curData.begin(),curData.end(),0);

    curData[ENERGY_INDEX]=esum;
    curData[ENERGY_SQ_INDEX]=e2sum;
    curData[WALKERSIZE_INDEX]=W.getActiveWalkers();
    curData[WEIGHT_INDEX]=wsum;
    curData[EREF_INDEX]=ecum;
    curData[R2ACCEPTED_INDEX]=r2_accepted;
    curData[R2PROPOSED_INDEX]=r2_proposed;

    myComm->allreduce(curData);

    measureProperties(iter);
    trialEnergy=EnsembleProperty.Energy;
    W.EnsembleProperty=EnsembleProperty;

    //return the current data
    return W.getGlobalNumWalkers();
}
コード例 #17
0
int 
WalkerReconfigurationMPI::branch(int iter, MCWalkerConfiguration& W, RealType trigger) {

  int nwkept = swapWalkers(W);

  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] += nwkept;
  //accumData[WALKERSIZE_INDEX] += curData[WALKERSIZE_INDEX];
  accumData[WEIGHT_INDEX]     += curData[WEIGHT_INDEX];

  //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;
  }

  return nwkept;
}
コード例 #18
0
int 
GlobalWalkerControl::branch(int iter, MCWalkerConfiguration& W, RealType trigger) {

  std::fill(NumPerNode.begin(),NumPerNode.end(),0);

  sortWalkers(W);

  NumPerNode[MyContext] = NumWalkers;

  int nw = copyWalkers(W);

  //wait until everynode comes here
  OHMMS::Controller->barrier();
  gsum(NumPerNode,0);

  Cur_min=Nmax; Cur_max=0; Cur_pop=0;
  for(int i=0; i<NumContexts; i++) {
    Cur_pop+= NumPerNode[i];
    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) { 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;
  }

  return Cur_pop;
}
コード例 #19
0
  void CompositeEstimatorSet::accumulate(MCWalkerConfiguration& W,
      MCWalkerConfiguration::iterator wit, 
      MCWalkerConfiguration::iterator wit_end,
      RealType wgtnorm)
  {
    //initialize temporary data
    for(int i=0; i< Estimators.size(); i++) Estimators[i]->startAccumulate();

    typedef MCWalkerConfiguration::Walker_t Walker_t;
    if(W.updatePbyP())
    {
      while(wit != wit_end)
      {
        Walker_t& thisWalker(**wit);
        Walker_t::Buffer_t& w_buffer(thisWalker.DataSet);
        w_buffer.rewind();
        W.copyFromBuffer(w_buffer);
        for(int i=0; i< Estimators.size(); i++) Estimators[i]->accumulate(W);
        ++wit;
      }
    }
    else
    {
      while(wit != wit_end)
      {
        Walker_t& thisWalker(**wit);
        W.R=thisWalker.R;
        W.update();
        for(int i=0; i< Estimators.size(); i++) Estimators[i]->accumulate(W);
        ++wit;
      }
    }

    for(int i=0; i< Estimators.size(); i++) Estimators[i]->stopAccumulate(wgtnorm);
    //curSteps++;
  }
コード例 #20
0
 void 
 TrialWaveFunction::evaluateOptimizableLog (MCWalkerConfiguration &W,  
					    vector<RealType>& logpsi_opt,  
					    GradMatrix_t&  optG,
					    ValueMatrix_t& optL)
 {
   for (int iw=0; iw<W.getActiveWalkers(); iw++) 
     logpsi_opt[iw] = RealType();
   optG = GradType();
   optL = RealType();
   
   // Sum optimizable part of log Psi
   for (int i=0,ii=RECOMPUTE_TIMER; i<Z.size(); i++,ii+=TIMER_SKIP) {
     myTimers[ii]->start();
     if (Z[i]->Optimizable) {
       Z[i]->addLog(W, logpsi_opt);
       Z[i]->gradLapl(W, optG, optL);
     }
     myTimers[ii]->stop();
   }
 }
コード例 #21
0
  /** evaluate curData and mark the bad/good walkers
   */
  int WalkerControlBase::sortWalkers(MCWalkerConfiguration& W) {

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

    vector<Walker_t*> bad,good_rn;
    vector<int> ncopy_rn;
    NumWalkers=0;
    MCWalkerConfiguration::iterator it_end(W.end());
    RealType esum=0.0,e2sum=0.0,wsum=0.0,ecum=0.0, w2sum=0.0, besum=0.0, bwgtsum=0.0;
    RealType r2_accepted=0.0,r2_proposed=0.0;
    int nrn(0),ncr(0);
    while(it != it_end) 
    {
      bool inFN=(((*it)->ReleasedNodeAge)==0);
      if ((*it)->ReleasedNodeAge==1) ncr+=1;
      int nc= std::min(static_cast<int>((*it)->Multiplicity),MaxCopy);
      r2_accepted+=(*it)->Properties(R2ACCEPTED);
      r2_proposed+=(*it)->Properties(R2PROPOSED);
      RealType e((*it)->Properties(LOCALENERGY));
      RealType bfe((*it)->Properties(ALTERNATEENERGY));
      RealType rnwgt(0.0);
      if (inFN)
        rnwgt=((*it)->Properties(SIGN));
      
//       RealType wgt((*it)->Weight);
      RealType wgt(0.0);
      if (inFN)
        wgt=((*it)->Weight); 
      
      esum += wgt*e;
      e2sum += wgt*e*e;
      wsum += wgt;
      w2sum += wgt*wgt;
      ecum += e;
      besum += bfe*rnwgt*wgt;
      bwgtsum += rnwgt*wgt;

      if((nc) && (inFN))
      {
        NumWalkers += nc;
        good_w.push_back(*it);
        ncopy_w.push_back(nc-1);
      }
      else if (nc)
      {
        NumWalkers += nc;
        nrn+=nc;
        good_rn.push_back(*it);
        ncopy_rn.push_back(nc-1);
      }
      else
      {
        bad.push_back(*it);
      }
      ++it;
    }

    //temp is an array to perform reduction operations
    std::fill(curData.begin(),curData.end(),0);

    //update curData
    curData[ENERGY_INDEX]=esum;
    curData[ENERGY_SQ_INDEX]=e2sum;
    curData[WALKERSIZE_INDEX]=W.getActiveWalkers();
    curData[WEIGHT_INDEX]=wsum;
    curData[EREF_INDEX]=ecum;
    curData[R2ACCEPTED_INDEX]=r2_accepted;
    curData[R2PROPOSED_INDEX]=r2_proposed;
    curData[FNSIZE_INDEX]=static_cast<RealType>(good_w.size());
    curData[RNONESIZE_INDEX]=static_cast<RealType>(ncr);
    curData[RNSIZE_INDEX]=nrn;
    curData[B_ENERGY_INDEX]=besum;
    curData[B_WGT_INDEX]=bwgtsum;
    
    ////this should be move
    //W.EnsembleProperty.NumSamples=curData[WALKERSIZE_INDEX];
    //W.EnsembleProperty.Weight=curData[WEIGHT_INDEX];
    //W.EnsembleProperty.Energy=(esum/=wsum);
    //W.EnsembleProperty.Variance=(e2sum/wsum-esum*esum);
    //W.EnsembleProperty.Variance=(e2sum*wsum-esum*esum)/(wsum*wsum-w2sum);

    //remove bad walkers empty the container
    for(int i=0; i<bad.size(); i++) delete bad[i];
    if (!WriteRN)
    {
     if(good_w.empty()) {
      app_error() << "All the walkers have died. Abort. " << endl;
      APP_ABORT("WalkerControlBase::sortWalkers");
     }

     int sizeofgood = good_w.size();
     //check if the projected number of walkers is too small or too large
     if(NumWalkers>Nmax) {
      int nsub=0;
      int nsub_target=(NumWalkers-nrn)-static_cast<int>(0.9*Nmax);
      int i=0;
      while(i< sizeofgood && nsub<nsub_target) {
        if(ncopy_w[i]) {ncopy_w[i]--; nsub++;}
        ++i;
      }
      NumWalkers -= nsub;
     } else  if(NumWalkers < Nmin) {
      int nadd=0;
      int nadd_target = static_cast<int>(Nmin*1.1)-(NumWalkers-nrn);
      if(nadd_target> sizeofgood) {
        app_warning() << "The number of walkers is running low. Requested walkers " 
          << nadd_target << " good walkers = " << sizeofgood << endl;
      }
      int i=0;
      while(i< sizeofgood && nadd<nadd_target) {
        ncopy_w[i]++; ++nadd;++i;
      }
      NumWalkers +=  nadd;
     }
    }
    else
    {
    it=good_rn.begin(); it_end=good_rn.end();
    int indy(0);
    while(it!=it_end) {
      good_w.push_back(*it);
      ncopy_w.push_back(ncopy_rn[indy]);
      it++,indy++;
    }
    }
    return NumWalkers;
  }
コード例 #22
0
  int WalkerControlBase::doNotBranch(int iter, MCWalkerConfiguration& W)
  {
    MCWalkerConfiguration::iterator it(W.begin());
    MCWalkerConfiguration::iterator it_end(W.end());
    RealType esum=0.0,e2sum=0.0,wsum=0.0,ecum=0.0, w2sum=0.0, besum=0.0, bwgtsum=0.0;
    RealType r2_accepted=0.0,r2_proposed=0.0;
    int nrn(0),ncr(0),nfn(0),ngoodfn(0);
    for(; it!=it_end;++it)
    {
      bool inFN=(((*it)->ReleasedNodeAge)==0);
      int nc= std::min(static_cast<int>((*it)->Multiplicity),MaxCopy);
      
      if ((*it)->ReleasedNodeAge==1) ncr+=1;
      else if ((*it)->ReleasedNodeAge==0) 
      {
        nfn+=1;
        ngoodfn+=nc;
      }
      
      r2_accepted+=(*it)->Properties(R2ACCEPTED);
      r2_proposed+=(*it)->Properties(R2PROPOSED);
      RealType e((*it)->Properties(LOCALENERGY));
      RealType bfe((*it)->Properties(ALTERNATEENERGY));
      RealType rnwgt(0.0);
      if (inFN)
        rnwgt=((*it)->Properties(SIGN));
      else
        nrn+=nc;
      //       RealType wgt((*it)->Weight);
      RealType wgt(0.0);
      if (inFN)
        wgt=((*it)->Weight); 
      
      esum += wgt*e;
      e2sum += wgt*e*e;
      wsum += wgt;
      w2sum += wgt*wgt;
      ecum += e;
      besum += bfe*rnwgt*wgt;
      bwgtsum += rnwgt*wgt;
    }

    //temp is an array to perform reduction operations
    std::fill(curData.begin(),curData.end(),0);

    curData[ENERGY_INDEX]=esum;
    curData[ENERGY_SQ_INDEX]=e2sum;
    curData[WALKERSIZE_INDEX]=W.getActiveWalkers();
    curData[WEIGHT_INDEX]=wsum;
    curData[EREF_INDEX]=ecum;
    curData[R2ACCEPTED_INDEX]=r2_accepted;
    curData[R2PROPOSED_INDEX]=r2_proposed;
    curData[FNSIZE_INDEX]=static_cast<RealType>(nfn);
    curData[RNONESIZE_INDEX]=static_cast<RealType>(ncr);
    curData[RNSIZE_INDEX]=nrn;
    curData[B_ENERGY_INDEX]=besum;
    curData[B_WGT_INDEX]=bwgtsum;

    myComm->allreduce(curData);

    measureProperties(iter);
    trialEnergy=EnsembleProperty.Energy;
    W.EnsembleProperty=EnsembleProperty;

    return W.getActiveWalkers();
  }
コード例 #23
0
int WalkerReconfigurationMPI::swapWalkers(MCWalkerConfiguration& W) {
  //ostringstream o;
  //o << "check." << MyContext << ".dat";
  //ofstream fout(o.str().c_str(),ios::app);

  int nw=W.getActiveWalkers();
  if(TotalWalkers ==0) {
    FirstWalker=nw*MyContext;
    LastWalker=FirstWalker+nw;
    TotalWalkers = nw*NumContexts;
    nwInv = 1.0/static_cast<RealType>(TotalWalkers);
    DeltaStep = UnitZeta*nwInv;

    ncopy_w.resize(nw);
    wConf.resize(nw);
    //wSum.resize(NumContexts);
    wOffset.resize(NumContexts+1);
    dN.resize(NumContexts+1);
  }

  //std::fill(wSum.begin(),wSum.end(),0.0);

  MCWalkerConfiguration::iterator it(W.begin()), it_end(W.end());
  int iw=0;
  RealType esum=0.0,e2sum=0.0,wtot=0.0,ecum=0.0;
  while(it != it_end) {
    RealType wgt((*it)->Weight);
    RealType e((*it)->Properties(LOCALENERGY));
    esum += wgt*e;
    e2sum += wgt*e*e;
    wtot += wgt;
    ecum += e;
    wConf[iw++]=wgt;
    ++it;
  }
  //wSum[MyContext]=wtot;
  curData[ENERGY_INDEX]=esum;
  curData[ENERGY_SQ_INDEX]=e2sum;
  curData[WALKERSIZE_INDEX]=nw;
  curData[WEIGHT_INDEX]=wtot;
  curData[EREF_INDEX]=ecum;
  std::fill(curData.begin()+LE_MAX,curData.end(),0.0);
  curData[LE_MAX+MyContext]=wtot;

  //collect everything
  myComm->allreduce(curData);

  //wOffset[ip] is the partial sum update to ip
  wOffset[0]=0;
  //for(int ip=0; ip<NumContexts; ip++) wOffset[ip+1]=wOffset[ip]+wSum[ip];
  for(int ip=0,jp=LE_MAX; ip<NumContexts; ip++,jp++) 
    wOffset[ip+1]=wOffset[ip]+curData[jp];

  wtot=wOffset[NumContexts]; //wtot is the total weight

  //find the lower and upper bound of index
  int minIndex=static_cast<int>((wOffset[MyContext]/wtot-DeltaStep)*static_cast<RealType>(TotalWalkers))-1;
  int maxIndex=static_cast<int>((wOffset[MyContext+1]/wtot-DeltaStep)*static_cast<RealType>(TotalWalkers))+1;
  int nb=maxIndex-minIndex+1;
  vector<RealType> Zeta(nb);

  for(int i=minIndex, ii=0; i<maxIndex; i++,ii++) {
    Zeta[ii]= wtot*(DeltaStep+static_cast<RealType>(i)*nwInv);
  }

  RealType wCur=wOffset[MyContext];
  int ind=0;
  while(Zeta[ind]<wCur) {ind++;} 

  //surviving walkers
  int icdiff=0;
  for(iw=0; iw<nw; iw++) {
    RealType tryp=wCur+abs(wConf[iw]);
    int ni=0;
    while(Zeta[ind]<tryp && Zeta[ind] >= wCur) {
      ind++;
      ni++;
    }
    wCur+=abs(wConf[iw]);
    if(ni) {
      icdiff++;
    } 
    ncopy_w[iw]=ni;
  }

  vector<int> plus, minus;
  for(iw=0;iw<nw; iw++) {
    int m=ncopy_w[iw];
    if(m>1) {// add the index of this walker to plus, duplicate m-1 times
      plus.insert(plus.end(),m-1,iw);
    } else if(m==0) { // add the walker index to be killed/overwritten
      minus.push_back(iw);
    }
  }

  //copy within the local node
  int lower=std::min(plus.size(),minus.size()); 
  while(lower>0) {
    --lower;
    W[minus[lower]]->assign(*(W[plus[lower]]));
    minus.pop_back();
    plus.pop_back();
  }


  //dN[ip] extra/missing walkers
  //dN[NumContexts] contains the number of surviving walkers
  std::fill(dN.begin(),dN.end(),0);
  dN[NumContexts]=icdiff;
  if(plus.size()) { dN[MyContext]=plus.size();}
  if(minus.size()) { dN[MyContext]=-minus.size();}

  //collect the data
  myComm->allreduce(dN);

  if(plus.size()) sendWalkers(W,plus);
  if(minus.size()) recvWalkers(W,minus);

  //vector<int> minusN, plusN;
  //bool tosend=false, torecv=false;
  //for(int ip=0; ip<NumContexts; ip++) {
  //  if(dN[ip]>0) {
  //    plusN.insert(plusN.end(),dN[ip],ip);
  //    tosend=true;
  //  } else if(dN[ip]<0) {
  //    minusN.insert(minusN.end(),-dN[ip],ip);
  //    torecv=true;
  //  }
  //}

  //int wbuffer_size=W[0]->byteSize();

  //int nswap=plusN.size();
  //int last = abs(dN[MyContext])-1;
  //int ic=0;
  //while(ic<nswap && last>=0) {
  //  if(plusN[ic]==MyContext) {
  //    OOMPI_Packed sendBuffer(wbuffer_size,OOMPI_COMM_WORLD);
  //    W[plus[last]]->putMessage(sendBuffer);
  //    OOMPI_COMM_WORLD[minusN[ic]].Send(sendBuffer);
  //    --last; 
  //  } 
  //  if(minusN[ic]==MyContext) {
  //    OOMPI_Packed recvBuffer(wbuffer_size,OOMPI_COMM_WORLD);
  //    OOMPI_COMM_WORLD[plusN[ic]].Recv(recvBuffer);
  //    W[minus[last]]->getMessage(recvBuffer);
  //    --last;
  //  }
  //  ++ic;
  //}

  //collect surviving walkers
  return dN[NumContexts];
}
コード例 #24
0
int main(int argc, char **argv) {

    using namespace ohmmsqmc;

    xmlDocPtr m_doc;
    xmlNodePtr m_root;
    xmlXPathContextPtr m_context;

    enum {SourceIndex  = DistanceTableData::SourceIndex};

    OHMMS::Controller->initialize(argc,argv);
    OhmmsInfo welcome(argc,argv,OHMMS::Controller->mycontext());

    ///project description
    OHMMS::ProjectData myProject;

    ///random number controller
    OHMMS::RandomNumberControl myRandomControl;

    if(argc>1) {
        // build an XML tree from a the file;
        LOGMSG("Opening file " << argv[1])
        m_doc = xmlParseFile(argv[1]);
        if (m_doc == NULL) {
            ERRORMSG("File " << argv[1] << " is invalid")
            xmlFreeDoc(m_doc);
            return 1;
        }
        // Check the document is of the right kind
        m_root = xmlDocGetRootElement(m_doc);
        if (m_root == NULL) {
            ERRORMSG("Empty document");
            xmlFreeDoc(m_doc);
            return 1;
        }
    } else {
        WARNMSG("No argument is given. Assume that  does not need an input file")
    }

    m_context = xmlXPathNewContext(m_doc);


    xmlXPathObjectPtr result
        = xmlXPathEvalExpression((const xmlChar*)"//project",m_context);
    if(xmlXPathNodeSetIsEmpty(result->nodesetval)) {
        WARNMSG("Project is not defined")
        myProject.reset();
    } else {
        myProject.put(result->nodesetval->nodeTab[0]);
    }
    xmlXPathFreeObject(result);
    //initialize the random number generator
    xmlNodePtr rptr = myRandomControl.initialize(m_context);
    if(rptr) {
        xmlAddChild(m_root,rptr);
    }

    ///the ions
    ParticleSet ion;

    MCWalkerConfiguration el;
    el.setName("e");
    int iu = el.Species.addSpecies("u");
    int id = el.Species.addSpecies("d");
    int icharge = el.Species.addAttribute("charge");
    el.Species(icharge,iu) = -1;
    el.Species(icharge,id) = -1;

    bool init_els = determineNumOfElectrons(el,m_context);

    result
        = xmlXPathEvalExpression((const xmlChar*)"//particleset",m_context);

    xmlNodePtr el_ptr=NULL, ion_ptr=NULL;
    for(int i=0; i<result->nodesetval->nodeNr; i++) {
        xmlNodePtr cur=result->nodesetval->nodeTab[i];
        xmlChar* aname= xmlGetProp(cur,(const xmlChar*)"name");
        if(aname) {
            char fc = aname[0];
            if(fc == 'e') {
                el_ptr=cur;
            }
            else if(fc == 'i') {
                ion_ptr=cur;
            }
        }
    }

    bool donotresize = false;
    if(init_els) {
        el.setName("e");
        XMLReport("The configuration for electrons is already determined by the wave function")
        donotresize = true;
    }
    if(el_ptr) {
        XMLParticleParser pread(el,donotresize);
        pread.put(el_ptr);
    }

    if(ion_ptr) {
        XMLParticleParser pread(ion);
        pread.put(ion_ptr);
    }

    xmlXPathFreeObject(result);

    if(!ion.getTotalNum()) {
        ion.setName("i");
        ion.create(1);
        ion.R[0] = 0.0;
    }

    //The ion-ion distance-table
    DistanceTableData* d_ii = DistanceTable::getTable(DistanceTable::add(ion));
    d_ii->create(1);
    d_ii->evaluate(ion);

    vector<double> Cut, Core;
    int Centers = ion.getTotalNum();
    //attribute id for cut
    int icut = ion.Species.addAttribute("cut");
    //store the max distance from atom
    Cut.resize(Centers);
    for(int iat=0; iat<Centers; iat++) {
        int id = ion.GroupID[iat];
        Cut[iat] = ion.Species(icut,id);
    }

    int icore = ion.Species.addAttribute("core");
    //store the max distance from atom
    Core.resize(Centers);
    for(int iat=0; iat<Centers; iat++) {
        Core[iat]=ion.Species(icore,ion.GroupID[iat]);
    }

    //3N-dimensional Gaussian
    ParticleSet::ParticlePos_t chi(el.getTotalNum());
    makeGaussRandom(chi);

    //determine if odd or even number of particles
    int irem = el.getTotalNum()%2;
    int ihalf = el.getTotalNum()/2;

    //assign the core
    int ncore(0);
    for(int iat=0; iat<Centers; iat++) {
        double sep=0.8*Cut[iat];
        for(int iel=0; iel<Core[iat]/2; iel++,ncore++) {
            el.R[ncore]=ion.R[iat]+sep*chi[ncore];
            el.R[ncore+ihalf]=ion.R[iat]+sep*chi[ncore+ihalf];
        }
    }

    int ipart = ncore;
    int isave_iat=0;

    for(int iat=0; iat<Centers; iat++) {
        for(int nn=d_ii->M[iat]; nn<d_ii->M[iat+1]; nn++) {
            double bondlength = d_ii->r(nn);
            int jat = d_ii->J[nn];
            //only assign if the half bond-length < cutoff
            if(bondlength < Cut[iat]+Cut[jat]) {
                if(ipart < ihalf) {
                    XMLReport("Assigning particles = " << ipart << " and " << ipart+ihalf)
                    /*place 2 electrons (an up and a down) at half
                      the bond-length plus a random number multiplied
                      by 10% of the bond-length*/
                    el.R[ipart] = ion.R[iat]+0.5*d_ii->dr(nn)+0.1*bondlength*chi[ipart];
                    el.R[ipart+ihalf] = ion.R[iat]+0.5*d_ii->dr(nn)+0.1*bondlength*chi[ipart+ihalf];
                    ipart++;
                    isave_iat = iat;
                }
            }
        }
    }

    //assign the last particle (if odd number of particles)
    int flag = 1;
    ipart = el.getTotalNum()-1;
    if(irem) {
        XMLReport("Assigning last particle.")
        for(int iat = isave_iat+1; iat<Centers; iat++) {
            for(int nn=d_ii->M[iat]; nn<d_ii->M[iat+1]; nn++) {
                double bondlength = d_ii->r(nn);
                if((0.5*bondlength < Cut[iat]) && flag) {
                    XMLReport("Assigning particle = " << ipart)
                    el.R[ipart] = ion.R[iat]+0.5*d_ii->dr(nn)+0.1*bondlength*chi[ipart];
                    flag = 0;
                }
            }
        }
    }

    cout << "Ionic configuration : " << ion.getName() << endl;
    ion.get(cout);

    cout << "Electronic configuration : " << el.getName() << endl;
    el.get(cout);

    string newxml(myProject.CurrentRoot());
    newxml.append(".ptcl.xml");
    ofstream ptcl_out(newxml.c_str());

    /*
      ofstream molmol("assign.xyz");

      molmol << Centers+el.getTotalNum() << endl;
      molmol << endl;

      for(int iat=0; iat<Centers; iat++)
      molmol << ion.Species.speciesName[ion.GroupID[iat]] << 0.5292*ion.R[iat] << endl;

      for(int ipart=0; ipart<el.getTotalNum(); ipart++)
      molmol << "He" << 0.5292*el.R[ipart] << endl;

      molmol.close();
    */

    xmlXPathFreeContext(m_context);
    xmlFreeDoc(m_doc);

    int nup = el.last(0);
    int ndown = el.last(1)-el.last(0);

    ptcl_out << "<?xml version=\"1.0\"?>" << endl;
    ptcl_out << "<particleset name=\"e\">" << endl;
    ptcl_out << "<group name=\"u\" size=\"" << nup << "\">" << endl;
    ptcl_out << "<parameter name=\"charge\">-1</parameter>" << endl;
    ptcl_out << "<attrib name=\"position\" datatype=\"posArray\">" << endl;
    for (int ipart=0; ipart<nup; ++ipart)
        ptcl_out << el.R[ipart] << endl;
    ptcl_out << "</attrib>" << endl;
    ptcl_out << "</group>" << endl;
    ptcl_out << "<group name=\"d\" size=\"" << ndown << "\">" << endl;
    ptcl_out << "<parameter name=\"charge\">-1</parameter>" << endl;
    ptcl_out << "<attrib name=\"position\" datatype=\"posArray\">" << endl;
    for (int ipart=nup; ipart<el.getTotalNum(); ++ipart)
        ptcl_out << el.R[ipart] << endl;
    ptcl_out << "</attrib>" << endl;
    ptcl_out << "</group>" << endl;
    ptcl_out << "</particleset>" << endl;

    OHMMS::Controller->finalize();
    return 0;
}
コード例 #25
0
  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;
  }
コード例 #26
0
//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;
  }
コード例 #27
0
bool
HDFWalkerInputCollect::read(MCWalkerConfiguration& W, int firstConf, int lastConf) {

    int myID = OHMMS::Controller->mycontext();
    hid_t mastercf = H5Gopen(fileID,"config_collection");

    char confName[128];
    char coordName[128];

#if H5_VERS_RELEASE < 4
    hssize_t offset[3];
#else
    hsize_t offset[3];
#endif
    hsize_t dimIn[3],dimTot[3];
    offset[0]=0;
    offset[1]=0;
    offset[2]=0;

    typedef MCWalkerConfiguration::PosType PosType;

    vector<PosType> pos;
    int nwRead=0;

    for(int iconf=firstConf; iconf<lastConf; iconf++) {

        sprintf(coordName,"config%04d/coord",iconf);
        hid_t dataset = H5Dopen(mastercf,coordName);
        hid_t dataspace = H5Dget_space(dataset);
        int rank = H5Sget_simple_extent_ndims(dataspace);
        int status_n = H5Sget_simple_extent_dims(dataspace, dimTot, NULL);

        if(CollectMode) {
            distribute(dimTot[0]);
        } else  {
            OffSet[myID]=0;
            OffSet[myID+1]=dimTot[0];
        }

        //get the input dimension
        dimIn[0]=OffSet[myID+1]-OffSet[myID];
        dimIn[1]=dimTot[1];
        dimIn[2]=dimTot[2];
        offset[0]=OffSet[myID];

        vector<PosType> posIn(dimIn[0]*dimIn[1]);

        hid_t memspace = H5Screate_simple(3, dimIn, NULL);
        herr_t status = H5Sselect_hyperslab(dataspace,H5S_SELECT_SET, offset,NULL,dimIn,NULL);
        status = H5Dread(dataset, H5T_NATIVE_DOUBLE, memspace, dataspace, H5P_DEFAULT, &(posIn[0][0]));

        H5Sclose(memspace);
        H5Dclose(dataset);
        H5Sclose(dataspace);

        pos.insert(pos.end(), posIn.begin(), posIn.end());
        nwRead += dimIn[0];
    }

    H5Gclose(mastercf);

    int curWalker = W.getActiveWalkers();
    int nptcl=W.getTotalNum();
    if(curWalker) {
        W.createWalkers(nwRead);
    } else {
        W.resize(nwRead,nptcl);
    }

    MCWalkerConfiguration::iterator it = W.begin()+curWalker;
    int ii=0;
    for(int iw=0; iw<nwRead; iw++) {
        //std::copy(Post_temp[iw],Post_temp[iw+1], (*it)->R.begin());
        for(int iat=0; iat < nptcl; iat++,ii++) {
            (*it)->R(iat) = pos[ii];
        }
        ++it;
    }

    return true;
}
コード例 #28
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;
      }
    }
コード例 #29
0
 /** accumulate data over walkers
  * @param W MCWalkerConfiguration
  * @param wgt weight
  */
 void CompositeEstimatorSet::accumulate(MCWalkerConfiguration& W, RealType wgtnorm) 
 {
   accumulate(W,W.begin(),W.end(),wgtnorm);
 }
コード例 #30
0
  ParticleSet* ParticleSetPool::createESParticleSet(xmlNodePtr cur, const string& target)
  {
    TinyVector<int,OHMMS_DIM> tilefactor;
    Tensor<int,OHMMS_DIM> tilematrix(1,0,0,0,1,0,0,0,1);
    double lr_cut=10;
    string h5name;
    string source("i");
    string bc("p p p");

    OhmmsAttributeSet attribs;
    attribs.add(h5name, "href");
    attribs.add(tilefactor, "tile");
    attribs.add(tilematrix, "tilematrix");
    attribs.add(source, "source");
    attribs.add(bc, "bconds");
    attribs.add(lr_cut, "LR_dim_cutoff");
    attribs.put(cur);

    ParticleSet* ions=getParticleSet(source);
    if(ions==0)
    {
      ions=new MCWalkerConfiguration;
      ions->setName(source);
    }

    //set the boundary condition
    ions->Lattice.LR_dim_cutoff=lr_cut;
    std::istringstream  is(bc);
    char c;
    int idim=0;
    while(!is.eof() && idim<OHMMS_DIM) 
    { 
      if(is>>c) ions->Lattice.BoxBConds[idim++]=(c=='p');
    }
    
    //initialize ions from hdf5
    hid_t h5=-1;
    if(myComm->rank()==0)
      h5 = H5Fopen(h5name.c_str(),H5F_ACC_RDONLY,H5P_DEFAULT);
    ESHDFIonsParser ap(*ions,h5,myComm);
    ap.put(cur);
    ap.expand(tilematrix);
    if(h5>-1) H5Fclose(h5);

    //failed to initialize the ions
    if(ions->getTotalNum() == 0) return 0;

    typedef ParticleSet::SingleParticleIndex_t SingleParticleIndex_t;
    vector<SingleParticleIndex_t> grid(OHMMS_DIM,SingleParticleIndex_t(1));
    ions->Lattice.reset();
    ions->Lattice.makeGrid(grid);

    if(SimulationCell==0)
    {
      SimulationCell = new ParticleSet::ParticleLayout_t(ions->Lattice);
    }

    //create the electrons
    MCWalkerConfiguration* qp = new MCWalkerConfiguration;
    qp->setName(target);
    qp->Lattice.copy(ions->Lattice);

    //qp->Lattice.reset();
    //qp->Lattice.makeGrid(grid);

    app_log() << "  Simulation cell radius = " << qp->Lattice.SimulationCellRadius << endl;
    app_log() << "  Wigner-Seitz    radius = " << qp->Lattice.WignerSeitzRadius    << endl;
    SimulationCell->print(app_log());

    myPool[target]=qp;
    myPool[source]=ions;
    //addParticleSet(qp);
    //addParticleSet(ions);

    {//get the number of electrons per spin
      vector<int> num_spin;
      xmlNodePtr cur1=cur->children;
      while(cur1!=NULL)
      {
        string cname1((const char*)cur1->name);
        if(cname1 == OrbitalBuilderBase::sd_tag)
        {
          num_spin.clear();
          xmlNodePtr cur2=cur1->children;
          while(cur2!=NULL)
          {
            string cname2((const char*)cur2->name);
            if(cname2 == OrbitalBuilderBase::det_tag)
            {
              int n=0;
              OhmmsAttributeSet a;
              a.add(n,"size");
              a.put(cur2);
              if(num_spin.size()<2) num_spin.push_back(n);
            }
            cur2=cur2->next;
          }
        }
        cur1=cur1->next;
      }
      //create species
      SpeciesSet& species=qp->getSpeciesSet();
      //add up and down
      species.addSpecies("u");
      if(num_spin.size()>1) species.addSpecies("d");
      int chid=species.addAttribute("charge");
      for(int i=0; i<num_spin.size(); ++i) species(chid,i)=-1.0;
      int mid=species.addAttribute("membersize");
      for(int i=0; i<num_spin.size(); ++i) species(mid,i)=num_spin[i];
      mid=species.addAttribute("mass");
      for(int i=0; i<num_spin.size(); ++i) species(mid,i)=1.0;
      qp->create(num_spin);
    }
    //name it with the target
    qp->setName(target);

    //assign non-trivial positions for the quanmtum particles
    if(qp->Lattice.SuperCellEnum)
    {
      makeUniformRandom(qp->R);
      qp->R.setUnit(PosUnit::LatticeUnit);
      qp->convert2Cart(qp->R);
      qp->createSK();
    }
    else
    {
      InitMolecularSystem mole(this);
      if(ions->getTotalNum()>1)
        mole.initMolecule(ions,qp);
      else
        mole.initAtom(ions,qp);
    }

    //for(int i=0; i<qp->getTotalNum(); ++i)
    //  cout << qp->GroupID[i] << " " << qp->R[i] << endl;

    if(qp->getTotalNum() == 0 || ions->getTotalNum() == 0)
    {
      delete qp;
      delete ions;
      APP_ABORT("ParticleSetPool failed to create particlesets for the electron structure calculation");
      return 0;
    }
    return qp;
  }