Skip to content

Commit

Permalink
Merge pull request #1476 from mmorale3/print_additional_afqmc_estimators
Browse files Browse the repository at this point in the history
Print additional afqmc estimators
  • Loading branch information
ye-luo authored Mar 24, 2019
2 parents 015141b + 1a1a891 commit 99bb3f9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
7 changes: 5 additions & 2 deletions src/AFQMC/Estimators/BackPropagatedEstimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class BackPropagatedEstimator: public EstimatorBase

void print(std::ofstream& out, hdf_archive& dump, WalkerSet& wset)
{
// I doubt we will ever collect a billion blocks of data.
int n_zero = 9;
if(writer) {
if(write_metadata) {
dump.push("Metadata");
Expand All @@ -126,8 +128,9 @@ class BackPropagatedEstimator: public EstimatorBase
DMAverage[i] /= block_size;
denom_average[0] /= block_size;
dump.push("BackPropagated");
dump.write(DMAverage, "one_rdm_"+std::to_string(iblock));
dump.write(denom_average, "one_rdm_denom_"+std::to_string(iblock));
std::string padded_iblock = std::string(n_zero-std::to_string(iblock).length(),'0')+std::to_string(iblock);
dump.write(DMAverage, "one_rdm_"+padded_iblock);
dump.write(denom_average, "one_rdm_denom_"+padded_iblock);
dump.pop();
std::fill(DMAverage.begin(), DMAverage.end(), ComplexType(0.0,0.0));
std::fill(denom_average.begin(), denom_average.end(), ComplexType(0.0,0.0));
Expand Down
29 changes: 26 additions & 3 deletions src/AFQMC/Estimators/EnergyEstimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,21 @@ class EnergyEstimator: public EstimatorBase

EnergyEstimator(afqmc::TaskGroup_& tg_, AFQMCInfo info, xmlNodePtr cur,
Wavefunction& wfn, bool impsamp_=true, bool timer=true):
EstimatorBase(info),TG(tg_),wfn0(wfn),importanceSampling(impsamp_)
EstimatorBase(info),TG(tg_),wfn0(wfn),importanceSampling(impsamp_),energy_components(false)
{

data.resize(2);
if(cur != NULL) {
ParameterSet m_param;
std::string print_components;
m_param.add(print_components, "print_components", "str::string");
m_param.put(cur);
if(print_components == "true" || print_components == "yes") {
energy_components = true;
} else {
energy_components = false;
}
}
data.resize(5);
}

~EnergyEstimator() {}
Expand All @@ -60,7 +71,7 @@ class EnergyEstimator: public EstimatorBase
wset.getProperty(WEIGHT,wprop[0]);
wset.getProperty(OVLP,wprop[1]);
wset.getProperty(PHASE,wprop[2]);
data[0] = data[1] = std::complex<double>(0,0);
std::fill_n(data.begin(), data.size(), ComplexType(0.0));
for(int i=0; i<nwalk; i++) {
if(std::isnan(real(wprop[0][i]))) continue;
if(importanceSampling) {
Expand All @@ -72,6 +83,9 @@ class EnergyEstimator: public EstimatorBase
if( (!std::isfinite(real(dum))) || (!std::isfinite(real(et*dum))) ) continue;
data[1] += dum;
data[0] += et*dum;
data[2] += eloc_[i][0]*dum;
data[3] += eloc_[i][1]*dum;
data[4] += eloc_[i][2]*dum;
}
TG.TG_heads().all_reduce_in_place_n(data.begin(),data.size(),std::plus<>());
}
Expand All @@ -85,6 +99,11 @@ class EnergyEstimator: public EstimatorBase
out<<"EnergyEstim_" <<name <<"_nume_real EnergyEstim_" <<name <<"_nume_imag "
<<"EnergyEstim_" <<name <<"_deno_real EnergyEstim_" <<name <<"_deno_imag "
<<"EnergyEstim_" <<name <<"_timer ";
if(energy_components) {
out<<"OneBodyEnergyEstim__nume_real "
<<"ECoulEnergyEstim__nume_real "
<<"EXXEnergyEstim__nume_real ";
}
}
}

Expand All @@ -95,6 +114,9 @@ class EnergyEstimator: public EstimatorBase
out<< data[0].real()/n << " " << data[0].imag()/n << " "
<< data[1].real()/n << " " << data[1].imag()/n << " "
<<AFQMCTimers[energy_timer]->get_total() <<" ";
if(energy_components) {
out<< data[2].real()/n << " " << data[3].real()/n << " " << data[4].real()/n << " ";
}
AFQMCTimers[energy_timer]->reset();
}
}
Expand All @@ -114,6 +136,7 @@ class EnergyEstimator: public EstimatorBase
std::vector<std::complex<double> > data;

bool importanceSampling;
bool energy_components;

};
}
Expand Down
7 changes: 5 additions & 2 deletions src/AFQMC/Estimators/MixedRDMEstimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class MixedRDMEstimator: public EstimatorBase

void print(std::ofstream& out, hdf_archive& dump, WalkerSet& wset)
{
// I doubt we will ever collect a billion blocks of data.
int n_zero = 9;
if(writer) {
for(int i = 0; i < DMBuffer.size(); i++)
DMAverage[i] += DMBuffer[i];
Expand All @@ -97,8 +99,9 @@ class MixedRDMEstimator: public EstimatorBase
DMAverage[i] /= block_size;
denom_average[0] /= block_size;
dump.push("Mixed");
dump.write(DMAverage, "one_rdm_"+std::to_string(iblock));
dump.write(denom_average, "one_rdm_denom_"+std::to_string(iblock));
std::string padded_iblock = std::string(n_zero-std::to_string(iblock).length(),'0')+std::to_string(iblock);
dump.write(DMAverage, "one_rdm_"+padded_iblock);
dump.write(denom_average, "one_rdm_denom_"+padded_iblock);
dump.pop();
std::fill(DMAverage.begin(), DMAverage.end(), ComplexType(0.0,0.0));
std::fill(denom_average.begin(), denom_average.end(), ComplexType(0.0,0.0));
Expand Down
4 changes: 2 additions & 2 deletions src/AFQMC/Estimators/tests/test_estimators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ TEST_CASE("reduced_density_matrix", "[estimators]")
app_error()<<" Error opening estimates.h5. \n";
APP_ABORT("");
}
reader.read(read_data, "BackPropagated/one_rdm_4");
reader.read(denom, "BackPropagated/one_rdm_denom_4");
reader.read(read_data, "BackPropagated/one_rdm_000000004");
reader.read(denom, "BackPropagated/one_rdm_denom_000000004");
// Test EstimatorHandler eventually.
//int NAEA_READ, NAEB_READ, NMO_READ, WALKER_TYPE_READ;
//reader.read(NAEA_READ, "Metadata/NAEA");
Expand Down

0 comments on commit 99bb3f9

Please sign in to comment.