Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unified driver dmc batched #1947

Merged
merged 9 commits into from
Sep 27, 2019
15 changes: 15 additions & 0 deletions src/Estimators/EstimatorManagerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,21 @@ void EstimatorManagerBase::getCurrentStatistics(MCWalkerConfiguration& W, RealTy
var = tmp[1] / tmp[2] - eavg * eavg;
}

void EstimatorManagerBase::getCurrentStatistics(const int global_walkers, RefVector<MCPWalker>& walkers, RealType& eavg, RealType& var)
{
LocalEnergyOnlyEstimator energynow;
energynow.clear();
energynow.accumulate(global_walkers, walkers, 1.0);
std::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;
}


EstimatorManagerBase::EstimatorType* EstimatorManagerBase::getMainEstimator()
{
if (MainEstimator == 0)
Expand Down
7 changes: 7 additions & 0 deletions src/Estimators/EstimatorManagerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "Message/Communicate.h"
#include "Estimators/ScalarEstimatorBase.h"
#include "Estimators/EstimatorManagerInterface.h"
#include "Particle/Walker.h"
#include "OhmmsPETE/OhmmsVector.h"
#include "OhmmsData/HDFAttribIO.h"
#include <bitset>
Expand All @@ -44,6 +45,8 @@ class EstimatorManagerBase : public EstimatorManagerInterface
typedef QMCTraits::FullPrecRealType RealType;
typedef ScalarEstimatorBase EstimatorType;
typedef std::vector<RealType> BufferType;
using MCPWalker = Walker<QMCTraits, PtclOnLatticeTraits>;

//enum { WEIGHT_INDEX=0, BLOCK_CPU_INDEX, ACCEPT_RATIO_INDEX, TOTAL_INDEX};

///name of the primary estimator name
Expand Down Expand Up @@ -210,6 +213,10 @@ class EstimatorManagerBase : public EstimatorManagerInterface

void getCurrentStatistics(MCWalkerConfiguration& W, RealType& eavg, RealType& var);

/** Unified walker variant of this method
*/
void getCurrentStatistics(const int global_walkers, RefVector<MCPWalker>& walkers, RealType& eavg, RealType& var);

template<class CT>
void write(CT& anything, bool doappend)
{
Expand Down
15 changes: 15 additions & 0 deletions src/Particle/ParticleSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,21 @@ void ParticleSet::saveWalker(Walker_t& awalker)
//awalker.DataSet.rewind();
}

void ParticleSet::flex_saveWalker(RefVector<ParticleSet>& psets, RefVector<Walker_t>& walkers)
{
int num_sets = psets.size();
auto saveWalker = [](ParticleSet& pset, Walker_t& walker){
walker.R = pset.R;
#if !defined(SOA_MEMORY_OPTIMIZED)
walker.G = pset.G;
walker.L = pset.L;
#endif
};
for(int iw = 0; iw < num_sets; ++iw)
saveWalker(psets[iw], walkers[iw]);
}


void ParticleSet::initPropertyList()
{
PropertyList.clear();
Expand Down
7 changes: 7 additions & 0 deletions src/Particle/ParticleSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,16 @@ class ParticleSet : public QMCTraits, public OhmmsElementBase, public PtclOnLatt
/** save this to awalker
*
* just the R, G, and L
* More duplicate data that makes code difficult to reason about should be removed.
*/
void saveWalker(Walker_t& awalker);

/** batched version of saveWalker
*
* just the R, G, and L
*/
static void flex_saveWalker(RefVector<ParticleSet>& psets, RefVector<Walker_t>& walkers);

/** update structure factor and unmark activePtcl
*
* The Coulomb interaction evaluation needs the structure factor.
Expand Down
19 changes: 16 additions & 3 deletions src/QMCApp/QMCDriverFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "QMCDrivers/VMC/VMCFactory.h"
#include "QMCDrivers/VMC/VMCFactoryNew.h"
#include "QMCDrivers/DMC/DMCFactory.h"
#include "QMCDrivers/DMC/DMCFactoryNew.h"
#include "QMCDrivers/RMC/RMCFactory.h"
#include "QMCDrivers/QMCOptimize.h"
#include "QMCDrivers/QMCFixedSampleLinearOptimize.h"
Expand Down Expand Up @@ -125,6 +126,10 @@ QMCDriverFactory::DriverAssemblyState QMCDriverFactory::readSection(int curSerie
{
das.new_run_type = QMCRunType::VMC;
}
else if (qmc_mode.find("dmc_batch") < nchars) // order matters here
{
das.new_run_type = QMCRunType::DMC_BATCH;
}
else if (qmc_mode.find("dmc") < nchars)
{
das.new_run_type = QMCRunType::DMC;
Expand All @@ -149,6 +154,7 @@ std::unique_ptr<QMCDriverInterface> QMCDriverFactory::newQMCDriver(std::unique_p
ParticleSetPool& particle_pool,
WaveFunctionPool& wavefunction_pool,
HamiltonianPool& hamiltonian_pool,
MCPopulation& population,
Communicate* comm)
{
//initialize to 0
Expand All @@ -165,7 +171,7 @@ std::unique_ptr<QMCDriverInterface> QMCDriverFactory::newQMCDriver(std::unique_p

//create a driver
std::unique_ptr<QMCDriverInterface> new_driver =
createQMCDriver(cur, das, qmc_system, particle_pool, wavefunction_pool, hamiltonian_pool, comm);
createQMCDriver(cur, das, qmc_system, particle_pool, wavefunction_pool, hamiltonian_pool, population, comm);
//initialize QMCDriver::myComm
//branchEngine has to be transferred to a new QMCDriver
if (branchEngine)
Expand All @@ -185,6 +191,7 @@ std::unique_ptr<QMCDriverInterface> QMCDriverFactory::createQMCDriver(xmlNodePtr
ParticleSetPool& particle_pool,
WaveFunctionPool& wavefunction_pool,
HamiltonianPool& hamiltonian_pool,
MCPopulation& population,
Communicate* comm)
{
///////////////////////////////////////////////
Expand Down Expand Up @@ -238,6 +245,7 @@ std::unique_ptr<QMCDriverInterface> QMCDriverFactory::createQMCDriver(xmlNodePtr
}
//set primaryH->Primary
primaryH->setPrimary(true);

////flux is evaluated only with single-configuration VMC
//if(curRunType ==QMCRunType::VMC && !curQmcModeBits[MULTIPLE_MODE])
//{
Expand All @@ -262,15 +270,20 @@ std::unique_ptr<QMCDriverInterface> QMCDriverFactory::createQMCDriver(xmlNodePtr
else if (das.new_run_type == QMCRunType::VMC_BATCH)
{
VMCFactoryNew fac(cur, das.what_to_do[UPDATE_MODE], qmc_common.qmc_counter);
MCPopulation qmc_pop(comm->size(), qmc_system, particle_pool.getParticleSet("e"), wavefunction_pool.getPrimary(), hamiltonian_pool.getPrimary());
new_driver.reset(
fac.create(std::move(qmc_pop), *primaryPsi, *primaryH, particle_pool, hamiltonian_pool, wavefunction_pool, comm));
fac.create(population, *primaryPsi, *primaryH, wavefunction_pool, comm));
}
else if (das.new_run_type == QMCRunType::DMC)
{
DMCFactory fac(das.what_to_do[UPDATE_MODE], das.what_to_do[GPU_MODE], cur);
new_driver.reset(fac.create(qmc_system, *primaryPsi, *primaryH, hamiltonian_pool, wavefunction_pool, comm));
}
else if (das.new_run_type == QMCRunType::DMC_BATCH)
{
DMCFactoryNew fac(cur, das.what_to_do[UPDATE_MODE], qmc_common.qmc_counter);
new_driver.reset(
fac.create(population, *primaryPsi, *primaryH, wavefunction_pool, comm));
}
else if (das.new_run_type == QMCRunType::RMC)
{
RMCFactory fac(das.what_to_do[UPDATE_MODE], cur);
Expand Down
3 changes: 3 additions & 0 deletions src/QMCApp/QMCDriverFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "OhmmsData/OhmmsElementBase.h"
#include "QMCDrivers/DriverTraits.h"
#include "QMCDrivers/MCPopulation.h"
#include "QMCApp/ParticleSetPool.h"

class Communicate;
Expand Down Expand Up @@ -61,6 +62,7 @@ class QMCDriverFactory
ParticleSetPool& particle_pool,
WaveFunctionPool& wave_function_pool,
HamiltonianPool& hamiltonian_pool,
MCPopulation& population,
Communicate* comm);

private:
Expand All @@ -74,6 +76,7 @@ class QMCDriverFactory
ParticleSetPool& particle_pool,
WaveFunctionPool& wave_function_pool,
HamiltonianPool& hamiltonian_pool,
MCPopulation& population,
Communicate* comm);
};
} // namespace qmcplusplus
Expand Down
6 changes: 5 additions & 1 deletion src/QMCApp/QMCMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,14 +546,18 @@ bool QMCMain::runQMC(xmlNodePtr cur, bool reuse)
std::string prev_config_file = last_driver ? last_driver->get_root_name() : "";
bool append_run = false;

if(!population_)
{
population_.reset(new MCPopulation(myComm->size(), *qmcSystem, ptclPool->getParticleSet("e"), psiPool->getPrimary(), hamPool->getPrimary()));
}
if (reuse)
qmc_driver = std::move(last_driver);
else
{
QMCDriverFactory driver_factory;
QMCDriverFactory::DriverAssemblyState das = driver_factory.readSection(myProject.m_series, cur);
qmc_driver = driver_factory.newQMCDriver(std::move(last_driver), myProject.m_series, cur, das, *qmcSystem, *ptclPool,
*psiPool, *hamPool, myComm);
*psiPool, *hamPool, *population_, myComm);
append_run = das.append_run;
}

Expand Down
4 changes: 4 additions & 0 deletions src/QMCApp/QMCMainState.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "Message/MPIObjectBase.h"
#include "QMCApp/ParticleSetPool.h"
#include "QMCApp/QMCDriverFactory.h"
#include "QMCDrivers/MCPopulation.h"
#include "type_traits/template_types.hpp"

class Communicate;

Expand Down Expand Up @@ -64,6 +66,8 @@ struct QMCMainState : public MPIObjectBase
*/
HamiltonianPool* hamPool;

UPtr<MCPopulation> population_;

/** default constructor **/
QMCMainState(Communicate* c);

Expand Down
84 changes: 82 additions & 2 deletions src/QMCApp/tests/test_QMCDriverFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ TEST_CASE("QMCDriverFactory create VMC Driver", "[qmcapp]")

std::unique_ptr<QMCDriverInterface> last_driver;
std::unique_ptr<QMCDriverInterface> qmc_driver;

MCPopulation population(comm->size(), particle_pool.getParticleSet("e"), wavefunction_pool.getPrimary(),
hamiltonian_pool.getPrimary());

qmc_driver = driver_factory.newQMCDriver(std::move(last_driver), 0, node, das, *qmc_system, particle_pool,
wavefunction_pool, hamiltonian_pool, comm);
wavefunction_pool, hamiltonian_pool, population, comm);
REQUIRE(qmc_driver != nullptr);
}

Expand Down Expand Up @@ -91,8 +95,84 @@ TEST_CASE("QMCDriverFactory create VMCBatched driver", "[qmcapp]")

std::unique_ptr<QMCDriverInterface> last_driver;
std::unique_ptr<QMCDriverInterface> qmc_driver;
MCPopulation population(comm->size(), particle_pool.getParticleSet("e"), wavefunction_pool.getPrimary(),
hamiltonian_pool.getPrimary());

qmc_driver = driver_factory.newQMCDriver(std::move(last_driver), 0, node, das, *qmc_system, particle_pool,
wavefunction_pool, hamiltonian_pool, population, comm);
REQUIRE(qmc_driver != nullptr);
}

TEST_CASE("QMCDriverFactory create DMC driver", "[qmcapp]")
{
using namespace testing;
Communicate* comm;
OHMMS::Controller->initialize(0, NULL);
comm = OHMMS::Controller;

QMCDriverFactory driver_factory;

Libxml2Document doc;
bool okay = doc.parseFromString(valid_dmc_input_sections[valid_dmc_input_dmc_index]);
REQUIRE(okay);
xmlNodePtr node = doc.getRoot();
QMCDriverFactory::DriverAssemblyState das = driver_factory.readSection(0, node);
REQUIRE(das.new_run_type == QMCRunType::DMC);

MinimalParticlePool mpp;
ParticleSetPool particle_pool = mpp(comm);
MinimalWaveFunctionPool wfp(comm);
WaveFunctionPool wavefunction_pool = wfp(&particle_pool);
wavefunction_pool.setPrimary(wavefunction_pool.getWaveFunction("psi0"));
MinimalHamiltonianPool mhp(comm);
HamiltonianPool hamiltonian_pool = mhp(&particle_pool, &wavefunction_pool);
std::string target("e");
MCWalkerConfiguration* qmc_system = particle_pool.getWalkerSet(target);

std::unique_ptr<QMCDriverInterface> last_driver;
std::unique_ptr<QMCDriverInterface> qmc_driver;
MCPopulation population(comm->size(), particle_pool.getParticleSet("e"), wavefunction_pool.getPrimary(),
hamiltonian_pool.getPrimary());

qmc_driver = driver_factory.newQMCDriver(std::move(last_driver), 0, node, das, *qmc_system, particle_pool,
wavefunction_pool, hamiltonian_pool, population, comm);
REQUIRE(qmc_driver != nullptr);
}

TEST_CASE("QMCDriverFactory create DMCBatched driver", "[qmcapp]")
{
using namespace testing;
Communicate* comm;
OHMMS::Controller->initialize(0, NULL);
comm = OHMMS::Controller;

QMCDriverFactory driver_factory;

Libxml2Document doc;
bool okay = doc.parseFromString(valid_dmc_input_sections[valid_dmc_input_dmc_batch_index]);
REQUIRE(okay);
xmlNodePtr node = doc.getRoot();
QMCDriverFactory::DriverAssemblyState das = driver_factory.readSection(0, node);
REQUIRE(das.new_run_type == QMCRunType::DMC_BATCH);

MinimalParticlePool mpp;
ParticleSetPool particle_pool = mpp(comm);
MinimalWaveFunctionPool wfp(comm);
WaveFunctionPool wavefunction_pool = wfp(&particle_pool);
wavefunction_pool.setPrimary(wavefunction_pool.getWaveFunction("psi0"));
MinimalHamiltonianPool mhp(comm);
HamiltonianPool hamiltonian_pool = mhp(&particle_pool, &wavefunction_pool);
std::string target("e");
MCWalkerConfiguration* qmc_system = particle_pool.getWalkerSet(target);

std::unique_ptr<QMCDriverInterface> last_driver;
std::unique_ptr<QMCDriverInterface> qmc_driver;
MCPopulation population(comm->size(), particle_pool.getParticleSet("e"), wavefunction_pool.getPrimary(),
hamiltonian_pool.getPrimary());

qmc_driver = driver_factory.newQMCDriver(std::move(last_driver), 0, node, das, *qmc_system, particle_pool,
wavefunction_pool, hamiltonian_pool, comm);
wavefunction_pool, hamiltonian_pool, population, comm);
REQUIRE(qmc_driver != nullptr);
}

} // namespace qmcplusplus
5 changes: 4 additions & 1 deletion src/QMCApp/tests/test_QMCDriverFactory_CUDA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@ TEST_CASE("QMCDriverFactory create VMC_CUDA Driver", "[qmcapp]")
std::string target("e");
MCWalkerConfiguration* qmc_system = particle_pool.getWalkerSet(target);

MCPopulation population(comm->size(), particle_pool.getParticleSet("e"), wavefunction_pool.getPrimary(),
hamiltonian_pool.getPrimary());

std::unique_ptr<QMCDriverInterface> last_driver;
std::unique_ptr<QMCDriverInterface> qmc_driver;
qmc_driver = driver_factory.newQMCDriver(std::move(last_driver), 0, node, das, *qmc_system, particle_pool,
wavefunction_pool, hamiltonian_pool, comm);
wavefunction_pool, hamiltonian_pool, population, comm);
REQUIRE(qmc_driver != nullptr);
}

Expand Down
15 changes: 9 additions & 6 deletions src/QMCDrivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
#// This file is distributed under the University of Illinois/NCSA Open Source License.
#// See LICENSE file in top directory for details.
#//
#// Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
#// Copyright (c) 2019 QMCPACK developers.
#//
#// File developed by: Bryan Clark, bclark@Princeton.edu, Princeton University
#// File developed by: Peter Doak, , doakpw@ornl.gov, Oak Ridge National Laboratory
#// Bryan Clark, bclark@Princeton.edu, Princeton University
#// Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
#// Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
#// Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
Expand Down Expand Up @@ -50,6 +51,9 @@ SET(QMCDRIVERS
DMC/DMCUpdateAll.cpp
DMC/DMCUpdatePbyPFast.cpp
DMC/DMCFactory.cpp
DMC/DMCFactoryNew.cpp
DMC/DMCBatched.cpp
DMC/DMCDriverInput.cpp
DMC/WalkerControlFactory.cpp
DMC/WalkerReconfiguration.cpp
RMC/RMC.cpp
Expand All @@ -75,12 +79,11 @@ IF(QMC_CUDA)
QMCCostFunctionCUDA.cpp)
ENDIF(QMC_CUDA)

SET(QMCDRIVERS ${QMCDRIVERS}
SET(QMCDRIVERS ${QMCDRIVERS}
VMC/VMC.cpp
VMC/VMCBatched.cpp
VMC/VMCLinearOpt.cpp
QMCCostFunction.cpp
)
VMC/VMCLinearOpt.cpp
QMCCostFunction.cpp)

IF(HAVE_MPI)
SET(QMCDRIVERS ${QMCDRIVERS}
Expand Down
6 changes: 4 additions & 2 deletions src/QMCDrivers/Crowd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ void Crowd::loadWalkers()

void Crowd::startBlock(int num_steps)
{
n_accept = 0;
n_reject = 0;
n_accept_ = 0;
n_reject_ = 0;
// VMCBatched does no nonlocal moves
n_nonlocal_accept_ = 0;
estimator_manager_crowd_.startBlock(num_steps);
}

Expand Down
Loading