int Dmc_method::allocateIntermediateVariables(System * sys, Wavefunction_data * wfdata) { if(wf) delete wf; wf=NULL; if(sample) delete sample; sample=NULL; nelectrons=sys->nelectrons(0)+sys->nelectrons(1); wfdata->generateWavefunction(wf); sys->generateSample(sample); sample->attachObserver(wf); nwf=wf->nfunc(); if(wf->nfunc() >1) error("DMC doesn't support more than one guiding wave function"); guidingwf=new Primary; pts.Resize(nconfig); for(int i=0; i < nconfig; i++) { pts(i).age.Resize(nelectrons); pts(i).age=0; } average_var.Resize(avg_words.size()); average_var=NULL; for(int i=0; i< average_var.GetDim(0); i++) { allocate(avg_words[i], sys, wfdata, average_var(i)); } return 1; }
int Reptation_method::deallocateIntermediateVariables() { if(wf) delete wf; if(sample) delete sample; wf=NULL; sample=NULL; for(int i=0; i< average_var.GetDim(0); i++) { if(average_var(i)) delete average_var(i); average_var(i)=NULL; } return 1; }
//---------------------------------------------------------------------- int Postprocess_method::gen_point(Wavefunction * wf, Sample_point * sample, Config_save_point & configpos, doublevar weight, Properties_point & pt) { Primary guide; Properties_gather gather; configpos.restorePos(sample); pseudo->randomize(); if(evaluate_energy) gather.gatherData(pt,pseudo,sys,wfdata,wf,sample,&guide); pt.avgrets.Resize(1,average_var.GetDim(0)); //cout << mpi_info.node << " generating a point with " << average_var.GetDim(0) << " avgrets " << endl; for(int i=0; i< average_var.GetDim(0); i++) { average_var(i)->randomize(wfdata,wf,sys,sample); average_var(i)->evaluate(wfdata, wf, sys, pseudo,sample,pt, pt.avgrets(0,i)); } for(int i=0; i< densplt.GetDim(0); i++) densplt(i)->accumulate(sample,weight); pt.weight(0)=weight; }
/*! */ void Postprocess_method::read(vector <string> words, unsigned int & pos, Program_options & options) { if(!readvalue(words, pos=0, configfile, "READCONFIG")) error("Need READCONFIG in Postprocess"); if(!readvalue(words, pos=0, nskip, "NSKIP")) nskip=0; evaluate_energy=true; if(haskeyword(words,pos=0,"NOENERGY")) evaluate_energy=false; vector <vector < string> > dens_words; vector<string> tmp_dens; pos=0; while(readsection(words, pos, tmp_dens, "DENSITY")) { dens_words.push_back(tmp_dens); } vector <vector < string> > avg_words; pos=0; while(readsection(words, pos, tmp_dens, "AVERAGE")) { avg_words.push_back(tmp_dens); } sys=NULL; allocate(options.systemtext[0], sys); sys->generatePseudo(options.pseudotext, pseudo); debug_write(cout, "wfdata allocate\n"); wfdata=NULL; if(options.twftext.size() < 1) error("Need TRIALFUNC section for POSTPROCESS"); allocate(options.twftext[0], sys, wfdata); average_var.Resize(avg_words.size()); average_var=NULL; for(int i=0; i< average_var.GetDim(0); i++) { allocate(avg_words[i], sys, wfdata, average_var(i)); } densplt.Resize(dens_words.size()); for(int i=0; i< densplt.GetDim(0); i++) { allocate(dens_words[i], sys, options.runid,densplt(i)); } }
int Reptation_method::allocateIntermediateVariables(System * locsys, Wavefunction_data * locwfdata) { //----------------------------------- //Sample point initialization debug_write(cout, "electrons\n"); sample=NULL; locsys->generateSample(sample); wf=NULL; locwfdata->generateWavefunction(wf); sample->attachObserver(wf); average_var.Resize(avg_words.size()); average_var=NULL; for(int i=0; i< average_var.GetDim(0); i++) { allocate(avg_words[i], locsys, locwfdata, average_var(i)); } return 1; }
/*! */ void Dmc_method::runWithVariables(Properties_manager & prop, System * sys, Wavefunction_data * wfdata, Pseudopotential * pseudo, ostream & output) { allocateIntermediateVariables(sys, wfdata); if(!wfdata->supports(laplacian_update)) error("DMC doesn't support all-electron moves..please" " change your wave function to use the new Jastrow"); cout.precision(15); output.precision(10); prop.setSize(wf->nfunc(), nblock, nstep, nconfig, sys, wfdata); restorecheckpoint(readconfig, sys, wfdata, pseudo); prop.initializeLog(average_var); //MB: new properties manager for forward walking (one per each length) Array1 <Properties_manager> prop_fw; prop_fw.Resize(fw_length.GetSize()); if(max_fw_length){ for(int s=0;s<fw_length.GetSize();s++){ string logfile, label_temp; prop.getLog(logfile, label_temp); char strbuff[40]; sprintf(strbuff, "%d", fw_length(s)); label_temp+="_fw"; label_temp+=strbuff; prop_fw(s).setLog(logfile, label_temp); prop_fw(s).setSize(wf->nfunc(), nblock, nstep, nconfig, sys, wfdata); prop_fw(s).initializeLog(average_var); } } if(nhist==-1) nhist=1; doublevar teff=timestep; for(int block=0; block < nblock; block++) { int totkilled=0; int totbranch=0; int totpoints=0; for(int step=0; step < nstep; ) { int npsteps=min(feedback_interval, nstep-step); Dynamics_info dinfo; doublevar acsum=0; doublevar deltar2=0; Array1 <doublevar> epos(3); doublevar avg_acceptance=0; for(int walker=0; walker < nconfig; walker++) { pts(walker).config_pos.restorePos(sample); wf->updateLap(wfdata, sample); //------Do several steps without branching for(int p=0; p < npsteps; p++) { pseudo->randomize(); for(int e=0; e< nelectrons; e++) { int acc; acc=dyngen->sample(e, sample, wf, wfdata, guidingwf, dinfo, timestep); if(dinfo.accepted) deltar2+=dinfo.diffusion_rate/(nconfig*nelectrons*npsteps); if(dinfo.accepted) { pts(walker).age(e)=0; } else { pts(walker).age(e)++; } avg_acceptance+=dinfo.acceptance/(nconfig*nelectrons*npsteps); if(acc>0) acsum++; } totpoints++; Properties_point pt; if(tmoves or tmoves_sizeconsistent) { //------------------T-moves doTmove(pt,pseudo,sys,wfdata,wf,sample,guidingwf); } ///---------------------------------done with the T-moves else { mygather.gatherData(pt, pseudo, sys, wfdata, wf, sample, guidingwf); } Dmc_history new_hist; new_hist.main_en=pts(walker).prop.energy(0); pts(walker).past_energies.push_front(new_hist); deque<Dmc_history> & past(pts(walker).past_energies); if(past.size() > nhist) past.erase(past.begin()+nhist, past.end()); pts(walker).prop=pt; if(!pure_dmc) { pts(walker).weight*=getWeight(pts(walker),teff,etrial); //Introduce potentially a small bias to avoid instability. if(pts(walker).weight>max_poss_weight) pts(walker).weight=max_poss_weight; } else pts(walker).weight=getWeightPURE_DMC(pts(walker),teff,etrial); if(pts(walker).ignore_walker) { pts(walker).ignore_walker=0; pts(walker).weight=1; pts(walker).prop.count=0; } pts(walker).prop.weight=pts(walker).weight; //This is somewhat inaccurate..will need to change it later //For the moment, the autocorrelation will be slightly //underestimated pts(walker).prop.parent=walker; pts(walker).prop.nchildren=1; pts(walker).prop.children(0)=walker; pts(walker).prop.avgrets.Resize(1,average_var.GetDim(0)); for(int i=0; i< average_var.GetDim(0); i++) { average_var(i)->randomize(wfdata,wf,sys,sample); average_var(i)->evaluate(wfdata, wf, sys, pseudo, sample, pts(walker).prop.avgrets(0,i)); } prop.insertPoint(step+p, walker, pts(walker).prop); for(int i=0; i< densplt.GetDim(0); i++) densplt(i)->accumulate(sample,pts(walker).prop.weight(0)); for(int i=0; i< nldensplt.GetDim(0); i++) nldensplt(i)->accumulate(sample,pts(walker).prop.weight(0), wfdata,wf); //MB: making the history of prop.avgrets for forward walking if(max_fw_length){ forwardWalking(walker, step+p,prop_fw); }//if FW } pts(walker).config_pos.savePos(sample); } //---Finished moving all walkers doublevar accept_ratio=acsum/(nconfig*nelectrons*npsteps); teff=timestep*accept_ratio; //deltar2/rf_diffusion; updateEtrial(feedback); step+=npsteps; int nkilled; if(!pure_dmc) nkilled=calcBranch(); else nkilled=0; totkilled+=nkilled; totbranch+=nkilled; } ///----Finished block if(!low_io || block==nblock-1) { savecheckpoint(storeconfig,sample); for(int i=0; i< densplt.GetDim(0); i++) densplt(i)->write(); for(int i=0; i< nldensplt.GetDim(0); i++) nldensplt(i)->write(log_label); } if(!pure_dmc){ prop.endBlock(); } else prop.endBlockSHDMC(); if(max_fw_length){ for(int s=0;s<fw_length.GetSize();s++){ //prop_fw(s).endBlock(); prop_fw(s).endBlock_per_step(); } } totbranch=parallel_sum(totbranch); totkilled=parallel_sum(totkilled); totpoints=parallel_sum(totpoints); Properties_final_average finavg; prop.getFinal(finavg); eref=finavg.avg(Properties_types::total_energy,0); updateEtrial(feedback); doublevar maxage=0; doublevar avgage=0; for(int w=0;w < nconfig; w++) { for(int e=0; e< nelectrons; e++) { if(maxage<pts(w).age(e)) maxage=pts(w).age(e); avgage+=pts(w).age(e); } } avgage/=(nconfig*nelectrons); if(output) { //cout << "Block " << block // << " nconfig " << totconfig // << " etrial " << etrial << endl; if(global_options::rappture ) { ofstream rapout("rappture.log"); rapout << "=RAPPTURE-PROGRESS=>" << int(100.0*doublevar(block+1)/doublevar(nblock)) << " Diffusion Monte Carlo" << endl; cout << "=RAPPTURE-PROGRESS=>" << int(100.0*doublevar(block+1)/doublevar(nblock)) << " Diffusion Monte Carlo" << endl; rapout.close(); } output << "***" << endl; output << "Block " << block << " etrial " << etrial << endl; output << "maximum age " << maxage << " average age " << avgage << endl; dyngen->showStats(output); prop.printBlockSummary(output); output << "Branched " << totbranch << " times. So a branch every " << doublevar(totpoints)/doublevar(totbranch) << " steps " << endl; } dyngen->resetStats(); } if(output) { output << "\n ----------Finished DMC------------\n\n"; prop.printSummary(output,average_var); //MB: final printout for FW if(max_fw_length){ for(int s=0;s<fw_length.GetSize();s++) prop_fw(s).printSummary(output,average_var); } } wfdata->clearObserver(); deallocateIntermediateVariables(); }
doublevar Reptation_method::slither(int direction, deque <Reptile_point> & reptile, Properties_gather & mygather, Reptile_point & pt, doublevar & main_diffusion) { Dynamics_info dinfo; int nelectrons=sample->electronSize(); for(int e=0; e<nelectrons; e++) { sampler->sample(e,sample, wf, mywfdata, guidewf, dinfo, timestep); } //Update all the quantities we want mygather.gatherData(pt.prop, pseudo, sys, mywfdata, wf, sample, guidewf); pt.savePos(sample); doublevar nen=pt.prop.energy(0); doublevar olden=0.0; deque<Reptile_point>::iterator last_point; if(reptile.size() >0) { if(direction==1 ) last_point=(reptile.end()-1); else last_point=reptile.begin(); olden=last_point->prop.energy(0); } //Cutting off the energy doublevar fbet=max(eref-nen,eref-olden); doublevar cutoff=1; if(fbet > 1.5*energy_cutoff) cutoff=0; else if(fbet > energy_cutoff) cutoff*=(1.-(fbet-energy_cutoff)/(.5*energy_cutoff)); pt.branching=-0.5*timestep*cutoff*(olden+nen); //Acceptance.. doublevar lost_branching=0; if(reptile.size()>0) { if(direction==1 ) lost_branching=(reptile.begin()+1)->branching; else lost_branching=(reptile.end()-1)->branching; } doublevar accept=exp(pt.branching-lost_branching); if(pt.prop.wf_val.amp(0,0) < -1e12 ) { cout << "rejecting based on wf value" << endl; accept=0; } pt.prop.avgrets.Resize(1,average_var.GetDim(0)); for(int i=0; i< average_var.GetDim(0); i++) { average_var(i)->evaluate(mywfdata, wf, sys, sample, pt.prop.avgrets(0,i)); } return accept; }