src/QMCDrivers/WalkerControlBase.cpp
/** Unified Driver version: evaluate curData and mark the bad/good walkers.
 *
 *  Somehow I don't think this belongs here
 *  
 *  Each good walker has a counter registering the
 *  number of copies needed to be generated from this walker.
 *  Bad walkers will be either recycled or removed later.
 */
Unified Driver version: evaluate curData and mark the bad/good walkers.
Somehow I don't think this belongs here

Each good walker has a counter registering the
number of copies needed to be generated from this walker.
Bad walkers will be either recycled or removed later.
Unified Driver version : evaluate curData and mark the bad / good walkers . Somehow I don ' t think this belongs here Each good walker has a counter registering the number of copies needed to be generated from this walker . Bad walkers will be either recycled or removed later .
WalkerControlBase::PopulationAdjustment WalkerControlBase::calcPopulationAdjustment(MCPopulation& pop)
{
  RefVector<MCPWalker> walkers(convertUPtrToRefVector(pop.get_walkers()));
  RefVector<MCPWalker> good_walkers;
  std::vector<int> copies_to_make_good_walkers;
  PopulationAdjustment adjustment;
  adjustment.num_walkers = 0;
  FullPrecRealType esum = 0.0, e2sum = 0.0, wsum = 0.0, ecum = 0.0, w2sum = 0.0, besum = 0.0, bwgtsum = 0.0;
  FullPrecRealType r2_accepted = 0.0, r2_proposed = 0.0;
  int nfn(0), nrn(0), ngoodfn(0), ncr(0);
  for(MCPWalker& walker : walkers)
  {
    bool inFN = (walker.ReleasedNodeAge == 0);
    auto calcNumberWalkerCopies = [this](int multiplicity)->int {
            return std::min(multiplicity, MaxCopy);
                                  };
    int nc = calcNumberWalkerCopies(walker.Multiplicity);
    if (write_release_nodes_)
    {
      if (walker.ReleasedNodeAge == 1)
        ncr += 1;
      else if (walker.ReleasedNodeAge == 0)
      {
        nfn += 1;
        ngoodfn += nc;
      }
      r2_accepted += walker.Properties(R2ACCEPTED);
      r2_proposed += walker.Properties(R2PROPOSED);
      FullPrecRealType local_energy(walker.Properties(LOCALENERGY));
      FullPrecRealType alternate_energy(walker.Properties(ALTERNATEENERGY));
      FullPrecRealType wgt   = walker.Weight;
      FullPrecRealType rnwgt = walker.ReleasedNodeWeight;
      esum += wgt * rnwgt * local_energy;
      e2sum += wgt * rnwgt * local_energy * local_energy;
      wsum += rnwgt * wgt;
      w2sum += rnwgt * rnwgt * wgt * wgt;
      ecum += local_energy;
      besum += alternate_energy * wgt;
      bwgtsum += wgt;
    }
    else
    {
      if (nc > 0)
        nfn++;
      else
        ncr++;
      r2_accepted += walker.Properties(R2ACCEPTED);
      r2_proposed += walker.Properties(R2PROPOSED);
      FullPrecRealType local_energy(walker.Properties(LOCALENERGY));
      FullPrecRealType wgt = walker.Weight;
      esum += wgt * local_energy;
      e2sum += wgt * local_energy * local_energy;
      wsum += wgt;
      w2sum += wgt * wgt;
      ecum += local_energy;
    }
    if ((nc) && (inFN))
    {
      adjustment.num_walkers += nc;
      adjustment.good_walkers.push_back(walker);
      adjustment.copies_to_make.push_back(nc - 1);
    }
    else if (nc)
    {
      adjustment.num_walkers += nc;
      nrn += nc;
      good_walkers.push_back(walker);
      copies_to_make_good_walkers.push_back(nc - 1);
    }
    else
    {
      adjustment.bad_walkers.push_back(walker);
    }
  }
  std::fill(curData.begin(), curData.end(), 0);
  curData[ENERGY_INDEX]     = esum;
  curData[ENERGY_SQ_INDEX]  = e2sum;
  curData[WALKERSIZE_INDEX] = pop.get_active_walkers();
  curData[WEIGHT_INDEX]     = wsum;
  curData[EREF_INDEX]       = ecum;
  curData[R2ACCEPTED_INDEX] = r2_accepted;
  curData[R2PROPOSED_INDEX] = r2_proposed;
  curData[FNSIZE_INDEX]     = good_walkers.size();
  curData[RNONESIZE_INDEX]  = ncr;
  curData[RNSIZE_INDEX]     = nrn;
  curData[B_ENERGY_INDEX]   = besum;
  curData[B_WGT_INDEX]      = bwgtsum;
  if (write_release_nodes_)
  {
    auto addWalkersWithReleaseNodeAge = [&adjustment](MCPWalker& walker, int copies) {
      adjustment.good_walkers.push_back(walker);
      adjustment.copies_to_make.push_back(copies);
                                        };                                          
    for(int iw = 0; iw < good_walkers.size(); ++iw)
      addWalkersWithReleaseNodeAge(good_walkers[iw],copies_to_make_good_walkers[iw]);
  }
  return adjustment;
}
WalkerControlBase :: PopulationAdjustment WalkerControlBase :: calcPopulationAdjustment ( MCPopulation & pop ) { RefVector < MCPWalker > walkers ( convertUPtrToRefVector ( pop . get_walkers ( ) ) ) ; RefVector < MCPWalker > good_walkers ; std :: vector < int > copies_to_make_good_walkers ; PopulationAdjustment adjustment ; adjustment . num_walkers = 0 ; FullPrecRealType esum = 0.0 , e2sum = 0.0 , wsum = 0.0 , ecum = 0.0 , w2sum = 0.0 , besum = 0.0 , bwgtsum = 0.0 ; FullPrecRealType r2_accepted = 0.0 , r2_proposed = 0.0 ; int nfn ( 0 ) , nrn ( 0 ) , ngoodfn ( 0 ) , ncr ( 0 ) ; for ( MCPWalker & walker : walkers ) { bool inFN = ( walker . ReleasedNodeAge == 0 ) ; auto calcNumberWalkerCopies = [ this ] ( int multiplicity ) -> int { return std :: min ( multiplicity , MaxCopy ) ; } ; int nc = calcNumberWalkerCopies ( walker . Multiplicity ) ; if ( write_release_nodes_ ) { if ( walker . ReleasedNodeAge == 1 ) ncr += 1 ; else if ( walker . ReleasedNodeAge == 0 ) { nfn += 1 ; ngoodfn += nc ; } r2_accepted += walker . Properties ( R2ACCEPTED ) ; r2_proposed += walker . Properties ( R2PROPOSED ) ; FullPrecRealType local_energy ( walker . Properties ( LOCALENERGY ) ) ; FullPrecRealType alternate_energy ( walker . Properties ( ALTERNATEENERGY ) ) ; FullPrecRealType wgt = walker . Weight ; FullPrecRealType rnwgt = walker . ReleasedNodeWeight ; esum += wgt * rnwgt * local_energy ; e2sum += wgt * rnwgt * local_energy * local_energy ; wsum += rnwgt * wgt ; w2sum += rnwgt * rnwgt * wgt * wgt ; ecum += local_energy ; besum += alternate_energy * wgt ; bwgtsum += wgt ; } else { if ( nc > 0 ) nfn ++ ; else ncr ++ ; r2_accepted += walker . Properties ( R2ACCEPTED ) ; r2_proposed += walker . Properties ( R2PROPOSED ) ; FullPrecRealType local_energy ( walker . Properties ( LOCALENERGY ) ) ; FullPrecRealType wgt = walker . Weight ; esum += wgt * local_energy ; e2sum += wgt * local_energy * local_energy ; wsum += wgt ; w2sum += wgt * wgt ; ecum += local_energy ; } if ( ( nc ) && ( inFN ) ) { adjustment . num_walkers += nc ; adjustment . good_walkers . push_back ( walker ) ; adjustment . copies_to_make . push_back ( nc - 1 ) ; } else if ( nc ) { adjustment . num_walkers += nc ; nrn += nc ; good_walkers . push_back ( walker ) ; copies_to_make_good_walkers . push_back ( nc - 1 ) ; } else { adjustment . bad_walkers . push_back ( walker ) ; } } std :: fill ( curData . begin ( ) , curData . end ( ) , 0 ) ; curData [ ENERGY_INDEX ] = esum ; curData [ ENERGY_SQ_INDEX ] = e2sum ; curData [ WALKERSIZE_INDEX ] = pop . get_active_walkers ( ) ; curData [ WEIGHT_INDEX ] = wsum ; curData [ EREF_INDEX ] = ecum ; curData [ R2ACCEPTED_INDEX ] = r2_accepted ; curData [ R2PROPOSED_INDEX ] = r2_proposed ; curData [ FNSIZE_INDEX ] = good_walkers . size ( ) ; curData [ RNONESIZE_INDEX ] = ncr ; curData [ RNSIZE_INDEX ] = nrn ; curData [ B_ENERGY_INDEX ] = besum ; curData [ B_WGT_INDEX ] = bwgtsum ; if ( write_release_nodes_ ) { auto addWalkersWithReleaseNodeAge = [ & adjustment ] ( MCPWalker & walker , int copies ) { adjustment . good_walkers . push_back ( walker ) ; adjustment . copies_to_make . push_back ( copies ) ; } ; for ( int iw = 0 ; iw < good_walkers . size ( ) ; ++ iw ) addWalkersWithReleaseNodeAge ( good_walkers [ iw ] , copies_to_make_good_walkers [ iw ] ) ; } return adjustment ; }
Unified Driver version: evaluate curData and mark the bad/good walkers.
Unified Driver version : evaluate curData and mark the bad / good walkers .
// So many sums and counters // Written as a lambda for emphasis // This seems odd since if write_release_nodes_ == false // num_new_walkers != sum(copies_to_make) // qmcpack style would be to use this as an ersatz flag somewhere // Nothing is every done with this except put its size in // curData[FNSIZE_INDEX] //temp is an array to perform reduction operations //update curData // so now if release nodes is on we push all the good nodes to good_walkers_temp, // if inFN you'll have two copies of each. // I'm just going to preserve this logic but there has to be a simpler way to express // whatever the point of this is.