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

Global driver_version switch for mapping input to drivers #3897

Merged
merged 28 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
07b4b03
add global parameter for driver_epoch, clean ProjectData a bit
PDoakORNL Mar 4, 2022
83e30a8
cleanup and testing
PDoakORNL Mar 4, 2022
c34bfd4
support global driver epoch switch
PDoakORNL Mar 4, 2022
99f8579
updating system tests for ecpoch_driver
PDoakORNL Mar 4, 2022
78119d5
fixing linear_batch system tests
PDoakORNL Mar 4, 2022
6dfe6a9
missed test update.
PDoakORNL Mar 4, 2022
95aa7dc
return vmc_batch, dmc_batch, linear_batch to previous functionality
PDoakORNL Mar 9, 2022
df8f3e6
better unit test for batched driver creation
PDoakORNL Mar 9, 2022
7a802d9
fixing bad input in test xml
PDoakORNL Mar 9, 2022
01d1f95
Formatting.
ye-luo Mar 10, 2022
541c257
Merge remote-tracking branch 'origin/develop' into pr/origin-3897
ye-luo Mar 10, 2022
855d249
refactored repetive code
PDoakORNL Mar 15, 2022
fe02def
remove name from ProjectData use enum for DriverEpoch
PDoakORNL Mar 15, 2022
2cb25fa
fix default constructor
PDoakORNL Mar 15, 2022
aa93224
better exception to throw. Fixed test input file.
PDoakORNL Mar 15, 2022
e5f199d
Fix warning.
ye-luo Mar 16, 2022
13150b1
Move string local.
ye-luo Mar 16, 2022
c043b49
Minor change.
ye-luo Mar 16, 2022
9c913e6
Set ProjectData title via the constructor or xml. No more setTitle().
ye-luo Mar 16, 2022
afb43c0
Merge remote-tracking branch 'origin/develop' into pr/origin-3897
ye-luo Mar 16, 2022
17297fb
fixing missing include only detected in some builds
PDoakORNL Mar 16, 2022
3531272
remove unneeded include from ProjectData
PDoakORNL Mar 16, 2022
35fcde1
Merge branch 'develop' into global_batch_switch
ye-luo Mar 16, 2022
e6bc85f
Update QMCDriverFactory.h
ye-luo Mar 17, 2022
48ad456
change driver epoch ->> driver version
PDoakORNL Mar 17, 2022
4381ad3
Merge branch 'global_batch_switch' of github.com:PDoakORNL/qmcpack in…
PDoakORNL Mar 17, 2022
5338776
typo
PDoakORNL Mar 17, 2022
eae3545
remove final uses of epoch update copyright
PDoakORNL Mar 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/QMCApp/QMCMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "QMCDrivers/QMCDriver.h"
#include "QMCDrivers/CloneManager.h"
#include "Message/Communicate.h"
#include "Message/UniformCommunicateError.h"
#include "Concurrency/OpenMP.h"
#include <queue>
#include <cstring>
Expand Down Expand Up @@ -205,7 +206,6 @@ bool QMCMain::execute()
}
#endif


NewTimer* t2 = timer_manager.createTimer("Total", timer_level_coarse);
t2->start();

Expand Down Expand Up @@ -392,7 +392,14 @@ bool QMCMain::validateXML()
}
else
{
myProject.put(result[0]);
try
{
myProject.put(result[0]);
}
catch (const UniformCommunicateError& ue)
{
myComm->barrier_and_abort(ue.what());
}
}
app_summary() << std::endl;
myProject.get(app_summary());
Expand Down Expand Up @@ -578,10 +585,16 @@ bool QMCMain::runQMC(xmlNodePtr cur, bool reuse)
else
{
QMCDriverFactory driver_factory(myProject);
QMCDriverFactory::DriverAssemblyState das = driver_factory.readSection(cur);

qmc_driver = driver_factory.createQMCDriver(cur, das, *qmcSystem, *ptclPool, *psiPool, *hamPool, myComm);
append_run = das.append_run;
try
{
QMCDriverFactory::DriverAssemblyState das = driver_factory.readSection(cur);
qmc_driver = driver_factory.createQMCDriver(cur, das, *qmcSystem, *ptclPool, *psiPool, *hamPool, myComm);
append_run = das.append_run;
}
catch (const UniformCommunicateError& ue)
{
myComm->barrier_and_abort(ue.what());
}
}

if (qmc_driver)
Expand Down
86 changes: 54 additions & 32 deletions src/QMCDrivers/QMCDriverFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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) 2022 QMCPACK developers.
//
// File developed by: Bryan Clark, bclark@Princeton.edu, Princeton University
// Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
Expand All @@ -12,6 +12,7 @@
// Raymond Clay III, j.k.rofling@gmail.com, Lawrence Livermore National Laboratory
// Mark Dewing, markdewing@gmail.com, University of Illinois at Urbana-Champaign
// Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
// Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
//
// File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
//////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -40,12 +41,13 @@
#include "OhmmsData/AttributeSet.h"
#include "OhmmsData/ParameterSet.h"
#include "QMCDrivers/WFOpt/QMCWFOptFactoryNew.h"
#include "Message/UniformCommunicateError.h"

namespace qmcplusplus
{
QMCDriverFactory::QMCDriverFactory(const ProjectData& project_data) : project_data_(project_data) {}

/** Read the xml specifify the driver for this QMC section
/** Read the xml defining the driver for this QMC section
*
* Copy elision should result in just a move of the
* DriverAssemblyState
Expand All @@ -57,7 +59,7 @@ QMCDriverFactory::QMCDriverFactory(const ProjectData& project_data) : project_da
QMCDriverFactory::DriverAssemblyState QMCDriverFactory::readSection(xmlNodePtr cur) const
{
DriverAssemblyState das;
std::string curName((const char*)cur->name);
std::string curName(castXMLCharToChar(cur->name));
std::string update_mode("pbyp");
std::string qmc_mode;
std::string multi_tag("no");
Expand Down Expand Up @@ -91,43 +93,64 @@ QMCDriverFactory::DriverAssemblyState QMCDriverFactory::readSection(xmlNodePtr c
infoSummary.flush();
infoLog.flush();

// Really by position if you don't write <qmc name="xxx",,,>
// you can write <vmc ...> so hacky
if (curName != "qmc")
qmc_mode = curName;

const int nchars = qmc_mode.size();

using DV = ProjectData::DriverVersion;
switch (project_data_.get_driver_version())
{
case DV::BATCH:
#if defined(QMC_CUDA)
if (qmc_mode.find("batch") < nchars)
throw std::runtime_error("Batched drivers don't support legacy CUDA build! "
"Please use OpenMP offload build.");
#endif

if (qmc_mode.find("linear_batch") < nchars)
das.new_run_type = QMCRunType::LINEAR_OPTIMIZE_BATCH;
else if (qmc_mode.find("linear") < nchars)
das.new_run_type = QMCRunType::LINEAR_OPTIMIZE;
else
{
if (qmc_mode.find("ptcl") < nchars)
das.what_to_do[UPDATE_MODE] = 1;
if (qmc_mode.find("mul") < nchars)
das.what_to_do[MULTIPLE_MODE] = 1;
if (qmc_mode.find("warp") < nchars)
das.what_to_do[SPACEWARP_MODE] = 1;

if (qmc_mode.find("rmc") < nchars)
das.new_run_type = QMCRunType::RMC;
else if (qmc_mode.find("vmc_batch") < nchars) // order matters here
if (qmc_mode.find("vmc") < nchars) // order matters here
das.new_run_type = QMCRunType::VMC_BATCH;
else if (qmc_mode.find("vmc") < nchars)
das.new_run_type = QMCRunType::VMC;
else if (qmc_mode.find("dmc_batch") < nchars) // order matters here
else if (qmc_mode.find("dmc") < nchars) // order matters here
das.new_run_type = QMCRunType::DMC_BATCH;
else if (qmc_mode.find("dmc") < nchars)
das.new_run_type = QMCRunType::DMC;
else if (qmc_mode == "wftest")
das.new_run_type = QMCRunType::WF_TEST;
else if (qmc_mode.find("linear") < nchars)
das.new_run_type = QMCRunType::LINEAR_OPTIMIZE_BATCH;
else
throw std::runtime_error("qmc method cannot be empty!");
throw UniformCommunicateError("QMC mode unknown. Valid modes for batched drivers are : vmc, dmc, linear.");
break;
// Begin to separate driver version = batch input reading from the legacy input parsing
case DV::LEGACY:
#if defined(QMC_CUDA)
if (qmc_mode.find("batch") < nchars)
throw std::runtime_error("Batched drivers don't support legacy CUDA build! "
"Please use OpenMP offload build.");
#endif
if (qmc_mode.find("linear_batch") < nchars) // order matters here
das.new_run_type = QMCRunType::LINEAR_OPTIMIZE_BATCH;
else if (qmc_mode.find("linear") < nchars)
das.new_run_type = QMCRunType::LINEAR_OPTIMIZE;
else
{
if (qmc_mode.find("ptcl") < nchars)
das.what_to_do[UPDATE_MODE] = 1;
if (qmc_mode.find("mul") < nchars)
das.what_to_do[MULTIPLE_MODE] = 1;
if (qmc_mode.find("warp") < nchars)
das.what_to_do[SPACEWARP_MODE] = 1;
if (qmc_mode.find("rmc") < nchars)
das.new_run_type = QMCRunType::RMC;
else if (qmc_mode.find("vmc_batch") < nchars) // order matters here
das.new_run_type = QMCRunType::VMC_BATCH;
else if (qmc_mode.find("vmc") < nchars)
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;
else if (qmc_mode == "wftest")
das.new_run_type = QMCRunType::WF_TEST;
else
throw std::runtime_error("qmc method cannot be empty!");
}
}
return das;
}
Expand Down Expand Up @@ -250,9 +273,8 @@ std::unique_ptr<QMCDriverInterface> QMCDriverFactory::createQMCDriver(xmlNodePtr
else if (das.new_run_type == QMCRunType::LINEAR_OPTIMIZE_BATCH)
{
#ifdef MIXED_PRECISION
APP_ABORT(
"QMCDriverFactory::createQMCDriver : method=\"linear_batch\" is not safe with CPU mixed precision. Please use "
"full precision build instead.");
APP_ABORT("QMCDriverFactory::createQMCDriver : method=\"linear_batch\" is not safe with CPU mixed precision. "
"Please use full precision build instead.");
#endif
QMCFixedSampleLinearOptimizeBatched* opt =
QMCWFOptLinearFactoryNew(cur, project_data_, qmc_system,
Expand Down
16 changes: 14 additions & 2 deletions src/QMCDrivers/QMCDriverFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// 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) 2022 QMCPACK developers.
//
// File developed by: Bryan Clark, bclark@Princeton.edu, Princeton University
// Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
// Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
// Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
// Raymond Clay III, j.k.rofling@gmail.com, Lawrence Livermore National Laboratory
// Mark Dewing, markdewing@gmail.com, University of Illinois at Urbana-Champaign
// Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
//
// File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
//////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -48,12 +49,23 @@ class QMCDriverFactory
QMCRunType new_run_type = QMCRunType::DUMMY;
};

/** Application uses this constructor
* param[in] project_data this is stored as a reference and this state controls later behavior.
* For both the driver factory i.e. driver verion. And the drivers it creates
* i.e. the section id and max CPU seconds.
*/
QMCDriverFactory(const ProjectData& project_data);

/** default constructor **/
//QMCDriverFactory() ;

/** read the current QMC Section */
/** read the current QMC Section
* In the application context project data can indicate the input be read in the context of
* the batched driver architecture.
* param[in] cur qmc section node
* param[in] force_batch forces input to be evaluated as if project driver type = batched
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There doesn't seem to be force_batch parameter.

* false does not force unbatched!
*/
DriverAssemblyState readSection(xmlNodePtr cur) const;

/** create a new QMCDriver
Expand Down
8 changes: 6 additions & 2 deletions src/QMCDrivers/QMCDriverNew.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ class QMCDriverNew : public QMCDriverInterface, public MPIObjectBase
* @param nwalkers number of walkers to add
*
*/
void makeLocalWalkers(int nwalkers,
RealType reserve);
void makeLocalWalkers(int nwalkers, RealType reserve);

DriftModifierBase& get_drift_modifier() const { return *drift_modifier_; }

Expand Down Expand Up @@ -199,6 +198,11 @@ class QMCDriverNew : public QMCDriverInterface, public MPIObjectBase
///return the i-th random generator
inline RandomGenerator& getRng(int i) override { return (*Rng[i]); }

/** intended for logging output and debugging
* you should base behavior on type preferably at compile time or if
* necessary at runtime using and protected by dynamic cast.
* QMCType is primarily for use in the debugger.
*/
std::string getEngineName() override { return QMCType; }
unsigned long getDriverMode() override { return qmc_driver_mode_.to_ulong(); }

Expand Down
58 changes: 44 additions & 14 deletions src/QMCDrivers/tests/ValidQMCInputSections.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace qmcplusplus
namespace testing
{
// clang-format: off
constexpr std::array<const char*, 3> valid_vmc_input_sections{
constexpr std::array<const char*, 4> valid_vmc_input_sections{
R"(
<qmc method="vmc" move="pbyp">
<estimator name="LocalEnergy" hdf5="no" />
Expand All @@ -38,8 +38,8 @@ constexpr std::array<const char*, 3> valid_vmc_input_sections{
<parameter name="usedrift"> no </parameter>
</qmc>
)",
R"(
<qmc method="vmc_batch" move="pbyp">
R"(
<qmc method="vmc" move="pbyp">
<parameter name="crowds"> 8 </parameter>
<estimator name="LocalEnergy" hdf5="no" />
<parameter name="total_walkers"> 32 </parameter>
Expand All @@ -51,8 +51,8 @@ constexpr std::array<const char*, 3> valid_vmc_input_sections{
<parameter name="usedrift"> no </parameter>
</qmc>
)",
R"(
<qmc method="vmc_batch" move="pbyp">
R"(
<qmc method="vmc" move="pbyp">
<parameter name="crowds"> 1 </parameter>
<estimator name="LocalEnergy" hdf5="no" />
<parameter name="total_walkers"> 1 </parameter>
Expand All @@ -63,15 +63,29 @@ constexpr std::array<const char*, 3> valid_vmc_input_sections{
<parameter name="timestep"> 1.0 </parameter>
<parameter name="usedrift"> no </parameter>
</qmc>
)",
R"(
<qmc method="vmc_batch" move="pbyp">
<parameter name="crowds"> 8 </parameter>
<estimator name="LocalEnergy" hdf5="no" />
<parameter name="total_walkers"> 32 </parameter>
<parameter name="warmupSteps"> 5 </parameter>
<parameter name="substeps"> 5 </parameter>
<parameter name="steps"> 1 </parameter>
<parameter name="blocks"> 2 </parameter>
<parameter name="timestep"> 1.0 </parameter>
<parameter name="usedrift"> no </parameter>
</qmc>
)"};


// to avoid creating a situation where section test xml is in two places
constexpr int valid_vmc_input_vmc_index = 0;
constexpr int valid_vmc_input_vmc_batch_index = 1;
constexpr int valid_vmc_input_vmc_tiny_index = 2;
constexpr int valid_vmc_input_vmc_index = 0;
constexpr int valid_vmc_input_vmc_batch_index = 1;
constexpr int valid_vmc_input_vmc_tiny_index = 2;
constexpr int valid_vmc_batch_input_vmc_batch_index = 3;

constexpr std::array<const char*, 2> valid_dmc_input_sections{
constexpr std::array<const char*, 3> valid_dmc_input_sections{
R"(
<qmc method="dmc" move="pbyp" gpu="yes">
<estimator name="LocalEnergy" hdf5="no" />
Expand All @@ -84,7 +98,21 @@ constexpr std::array<const char*, 2> valid_dmc_input_sections{
<parameter name="nonlocalmoves"> no </parameter>
</qmc>
)",
R"(
R"(
<qmc method="dmc" move="pbyp">
<parameter name="crowds"> 4 </parameter>
<estimator name="LocalEnergy" hdf5="no" />
<parameter name="total_walkers"> 8 </parameter>
<parameter name="reserve"> 1.25 </parameter>
<parameter name="warmupSteps"> 5 </parameter>
<parameter name="substeps"> 5 </parameter>
<parameter name="steps"> 1 </parameter>
<parameter name="blocks"> 2 </parameter>
<parameter name="timestep"> 1.0 </parameter>
<parameter name="usedrift"> no </parameter>
</qmc>
)",
R"(
<qmc method="dmc_batch" move="pbyp">
<parameter name="crowds"> 4 </parameter>
<estimator name="LocalEnergy" hdf5="no" />
Expand All @@ -100,16 +128,18 @@ constexpr std::array<const char*, 2> valid_dmc_input_sections{
)"};

// to avoid creating a situation where section test xml is in two places
constexpr int valid_dmc_input_dmc_index = 0;
constexpr int valid_dmc_input_dmc_batch_index = 1;
constexpr int valid_dmc_input_dmc_index = 0;
constexpr int valid_dmc_input_dmc_batch_index = 1;
constexpr int valid_dmc_batch_input_dmc_batch_index = 2;

/** As far as I can tell these are no longer valid */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to update the WFOptDriverInput class, and I'll change these tests then as well.

constexpr std::array<const char*, 2> valid_opt_input_sections{
R"(
<qmc method="opt_batch" move="pbyp" gpu="yes">
<qmc method="opt" move="pbyp" gpu="yes">
</qmc>
)",
R"(
<qmc method="opt_batch" move="pbyp">
<qmc method="opt" move="pbyp">
<optimize method="test" output_param_file="yes"/>
<parameter name="opt_num_crowds"> 4 </parameter>
<parameter name="opt_crowd_size"> 8 </parameter>
Expand Down
Loading