50 #include "AFQMC/AFQMCFactory.h" 53 #define STR_VAL(arg) #arg 54 #define GET_MACRO_VAL(arg) STR_VAL(arg) 62 psi_pool_(
std::make_unique<
WaveFunctionPool>(my_project_.getRuntimeOptions(), *particle_set_pool_, myComm)),
66 walker_logs_xml_(NULL)
67 #
if !defined(REMOVE_TRACEMANAGER)
76 app_summary() <<
"================================================================\n" 77 <<
" QMCPACK " << QMCPACK_VERSION_MAJOR <<
"." << QMCPACK_VERSION_MINOR <<
"." 78 << QMCPACK_VERSION_PATCH <<
"\n" 80 <<
" (c) Copyright 2003-2023 QMCPACK developers\n" 83 <<
" J. Kim et al. J. Phys. Cond. Mat. 30 195901 (2018)\n" 84 <<
" https://doi.org/10.1088/1361-648X/aab9c3\n" 86 <<
" P. Kent et al. J. Chem. Phys. 152 174105 (2020)\n" 87 <<
" https://doi.org/10.1063/5.0004860\n";
89 app_summary() <<
"================================================================\n";
93 #if !defined(HAVE_MPI) 94 <<
"\n Built without MPI. Running in serial or with OMP threads." << std::endl
99 <<
"\n Number of ranks in group = " <<
myComm->
size()
100 <<
"\n MPI ranks per node = " << node_comm.size()
101 #if defined(ENABLE_OFFLOAD) || defined(ENABLE_CUDA) || defined(ENABLE_HIP) || defined(ENABLE_SYCL) 116 if (L1_tid == 0 && L2_tid == 0)
118 if (L2_num_threads == 1)
119 app_summary() <<
" OMP nested threading disabled or only 1 thread on the 2nd level" << std::endl;
121 app_summary() <<
" OMP 2nd level threads = " << L2_num_threads << std::endl;
125 app_summary() <<
"\n Precision used in this calculation, see definitions in the manual:" 127 <<
"\n Full precision = " <<
GET_MACRO_VAL(OHMMS_PRECISION_FULL) << std::endl;
131 #if !defined(ENABLE_OFFLOAD) && !defined(ENABLE_CUDA) && !defined(ENABLE_HIP) && !defined(ENABLE_SYCL) 134 #if defined(ENABLE_OFFLOAD) 135 app_summary() <<
" OpenMP target offload to accelerators build option is enabled" << std::endl;
137 #if defined(ENABLE_HIP) 138 app_summary() <<
" HIP acceleration with direct HIP source code build option is enabled" << std::endl;
141 #if defined(QMC_CUDA2HIP) && defined(ENABLE_CUDA) 142 app_summary() <<
" HIP acceleration with CUDA source code build option is enabled" << std::endl;
143 #elif defined(ENABLE_CUDA) 144 app_summary() <<
" CUDA acceleration build option is enabled" << std::endl;
145 #elif defined(ENABLE_SYCL) 146 app_summary() <<
" SYCL acceleration build option is enabled" << std::endl;
148 #endif // GPU case end 151 app_summary() <<
" Complex build. QMC_COMPLEX=ON" << std::endl;
153 app_summary() <<
" Real build. QMC_COMPLEX=OFF" << std::endl;
156 app_summary() <<
" Timer build option is enabled. Current timer level is " 177 ERRORMSG(
"No valid input file exists! Aborting QMCMain::execute")
181 std::string simulationType =
"realspaceQMC";
185 simType.
add(simulationType,
"type");
186 simType.
add(simulationType,
"name");
187 simType.
add(simulationType,
"method");
192 if (simulationType ==
"afqmc")
196 <<
"/*************************************************\n" 197 <<
" ******** This is an AFQMC calculation ********\n" 198 <<
" *************************************************" << std::endl;
201 xmlXPathContextPtr m_context =
xml_doc_stack_.top()->getXPathContext();
205 auto world = boost::mpi3::environment::get_world_instance();
206 afqmc::AFQMCFactory afqmc_fac(world);
207 if (!afqmc_fac.parse(cur))
209 app_log() <<
" Error in AFQMCFactory::parse() ." << std::endl;
213 return afqmc_fac.execute(cur);
216 if (simulationType ==
"afqmc")
218 app_error() <<
" Executable not compiled with AFQMC. Recompile with BUILD_AFQMC set to 1." << std::endl;
238 app_log() <<
" Initialization Execution time = " << std::setprecision(4) << t0.
elapsed() <<
" secs" << std::endl;
240 app_log() <<
"=========================================================\n";
241 app_log() <<
" Summary of QMC systems \n";
242 app_log() <<
"=========================================================\n";
249 app_log() <<
" dryrun == 1 : Skipping all QMC and loop elements " << std::endl;
259 std::string cname((
const char*)cur->name);
260 if (cname ==
"qmc" || cname ==
"optimize")
265 else if (cname ==
"loop")
271 else if (cname ==
"cmc")
275 else if (cname ==
"debug")
278 app_log() <<
" Debug is done. Skip the rest of the input " << std::endl;
284 if (!qmcactionPair.second)
285 xmlFreeNode(qmcactionPair.first);
289 app_log() <<
" Total Execution time = " << std::setprecision(4) << t1.
elapsed() <<
" secs" << std::endl;
293 xmlNodePtr mcptr = NULL;
303 std::ostringstream np_str, v_str;
306 v_str << cur_version[0] <<
" " << cur_version[1];
307 xmlNodePtr newmcptr = xmlNewNode(NULL, (
const xmlChar*)
"mcwalkerset");
309 xmlNewProp(newmcptr, (
const xmlChar*)
"node", (
const xmlChar*)
"-1");
310 xmlNewProp(newmcptr, (
const xmlChar*)
"nprocs", (
const xmlChar*)np_str.str().c_str());
311 xmlNewProp(newmcptr, (
const xmlChar*)
"version", (
const xmlChar*)v_str.str().c_str());
312 xmlNewProp(newmcptr, (
const xmlChar*)
"collected", (
const xmlChar*)
"yes");
319 xmlReplaceNode(mcptr, newmcptr);
335 app_log() <<
"Loop execution max-interations = " << niter << std::endl;
336 for (
int iter = 0; iter < niter; iter++)
340 xmlNodePtr tcur = cur->children;
343 std::string cname((
const char*)tcur->name);
350 app_warning() <<
" Terminated loop execution. A sub section returns false." << std::endl;
378 xmlXPathContextPtr m_context =
xml_doc_stack_.top()->getXPathContext();
383 app_warning() <<
"Project is not defined" << std::endl;
407 for (
int i = 0; i <
ham.
size(); ++i)
409 xmlNodePtr cur =
ham[i]->children;
412 std::string aname =
"0";
414 a.
add(aname,
"type");
416 if (aname ==
"mpc" || aname ==
"MPC")
426 app_log() <<
" hamiltonian has MPC. Will read density if it is found." << std::endl << std::endl;
436 std::string cname((
const char*)cur->name);
437 bool inputnode =
true;
438 if (cname ==
"particleset")
442 else if (cname ==
"wavefunction")
446 else if (cname ==
"hamiltonian")
450 else if (cname ==
"include")
454 if (!include_name.empty())
468 else if (cname ==
"qmcsystem")
472 else if (cname ==
"init")
477 #if !defined(REMOVE_TRACEMANAGER) 478 else if (cname ==
"traces")
483 else if (cname ==
"walkerlogs")
490 qmc_action_.push_back(std::pair<xmlNodePtr, bool>(cur,
true));
527 bool inputnode =
false;
529 xmlNodePtr cur_root = cur;
533 std::string cname((
const char*)cur->name);
534 if (cname ==
"simulationcell")
539 else if (cname ==
"particleset")
544 else if (cname ==
"wavefunction")
549 else if (cname ==
"hamiltonian")
554 else if (cname ==
"estimators")
561 "QMCMain::validateXML. Illegal Input, only one global <estimators> node is permitted");
572 qmc_action_.push_back(std::pair<xmlNodePtr, bool>(xmlCopyNode(cur, 1),
false));
588 std::unique_ptr<QMCDriverInterface> qmc_driver;
589 bool append_run =
false;
629 #if !defined(REMOVE_TRACEMANAGER) 635 Timer process_and_run;
636 qmc_driver->process(cur);
641 app_log() <<
" " << qmc_driver->getEngineName() <<
" Execution time = " << std::setprecision(4)
642 << process_and_run.
elapsed() <<
" secs" << std::endl;
666 for (
int iconf = 0; iconf < result.
size(); iconf++)
668 xmlNodePtr mc_ptr = result[iconf];
677 a.
add(fname,
"fileroot");
678 a.
add(fname,
"href");
680 a.
put(result[result.
size() - 1]);
689 app_log() <<
"QMCMain::executeDebugSection " << std::endl;
690 app_log() <<
" Use this to debug new features with <debug/> in the input file " << std::endl;
697 std::string target(
"e");
698 std::string random_test(
"no");
700 a.
add(target,
"target");
701 a.
add(random_test,
"testrng");
703 if (random_test ==
"yes")
707 bool success =
runQMC(cur, reuse);
715 std::string target(
"ion0");
717 a.
add(target,
"target");
724 app_log() <<
"QMCMain::executeCMCSection moving " << target <<
" by dummy move." << std::endl;
733 std::cout <<
"logpsi1 " << logpsi1 << std::endl;
736 std::cout <<
"Local Energy " << eloc1 << std::endl;
741 for (
int iat = 0; iat < nat; ++iat)
743 ions->
R[iat] += deltaR[iat];
752 std::cout <<
"\nION " << iat <<
" " << ions->
R[iat] << std::endl;
753 std::cout <<
"logpsi " << logpsi2 << std::endl;
754 std::cout <<
"Local Energy " << eloc2 << std::endl;
758 ions->
R[iat] -= deltaR[iat];
768 std::cout <<
"ERROR Energies are different " << std::endl;
RealType evaluateLog(ParticleSet &P)
evalaute the log (internally gradients and laplacian) of the trial wavefunction.
bool runQMC(xmlNodePtr cur, bool reuse)
execute <qmc> element
void print_git_info_if_present(std::ostream &os)
Print git info (commit hash, etc) if project was build from git repository.
static void read(const std::string &fname, Communicate *comm)
read in parallel or serial
std::string getObservableName(int i) const
return the name of the i-th observable
A set of walkers that are to be advanced by Metropolis Monte Carlo.
std::ostream & app_warning()
Base class for any object which needs to know about a MPI communicator.
std::vector< xmlNodePtr > walker_set_
xml mcwalkerset elements for output
helper functions for EinsplineSetBuilder
bool executeQMCSection(xmlNodePtr cur, bool reuse=false)
execute qmc
Declaration of OutputManager class.
DriverAssemblyState readSection(xmlNodePtr cur) const
default constructor
void setCommunicator(Communicate *c)
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
size_t getTotalNum() const
std::optional< EstimatorManagerInput > estimator_manager_input_
Global estimators defined outside of <qmc> nodes.
std::ostream & app_summary()
bool put(xmlNodePtr cur)
assign attributes to the set
static void clearClones()
bool isComplex() const noexcept
std::ostream & app_error()
std::unique_ptr< ParticleSetPool > particle_set_pool_
ParticleSet Pool.
RunTimeManager< ChronoClock > run_time_manager
void advance()
increment a series number and reset project_root_
RealType getObservable(int i) const
return the value of the i-th observable
Collection of Local Energy Operators.
xmlNodePtr traces_xml_
traces xml
std::unique_ptr< SimpleFixedNodeBranch > last_branch_engine_legacy_driver_
last branch engine used by legacy drivers
Timer accumulates time and call counts.
xmlNodePtr last_input_node_
pointer to the last node of the main inputfile
void update(bool skipSK=false)
update the internal data
Attaches a unit to a Vector for IO.
Communicate * Controller
Global Communicator for a process.
void executeLoop(xmlNodePtr cur)
execute loop
void print_mem(const std::string &title, std::ostream &log)
void saveXml()
save the xml document
int size() const
return the number of tasks
std::unique_ptr< WaveFunctionPool > psi_pool_
TrialWaveFunction Pool.
class to handle xmlXPathObject
xmlNodePtr initialize(xmlXPathContextPtr)
Wrapping information on parallelism.
static const DeviceManager & getGlobal()
global instance accessor
omp_int_t omp_get_thread_num()
int getGroupID() const
return the group id
Declaration of QMCDriver.
bool dryrun
true, if it is a dryrun
bool put(std::istream &is)
Declaration of InitMolecularSystem.
Compilation units that construct QMCDriverInput need visibility to the actual input classes types in ...
std::unique_ptr< QMCDriverInterface > createQMCDriver(xmlNodePtr cur, DriverAssemblyState &das, const std::optional< EstimatorManagerInput > &emi, MCWalkerConfiguration &qmc_system, ParticleSetPool &particle_pool, WaveFunctionPool &wave_function_pool, HamiltonianPool &hamiltonian_pool, Communicate *comm) const
create a new QMCDriver
std::vector< std::pair< xmlNodePtr, bool > > qmc_action_
qmc sections
bool processPWH(xmlNodePtr cur)
add unique ParticleSet, TrialWaveFunction and QMCHamiltonian elements to Pool objects ...
Communicate * myComm
pointer to Communicate
Declaration of WaveFunctionPool.
int size() const
return the number of Hamiltonians
class to handle a set of attributes of an xmlNode
bool first_qmc_
flag to indicate that a qmc is the first QMC
std::unique_ptr< HamiltonianPool > ham_pool_
QMCHamiltonian Pool.
ProjectData my_project_
project description
This a subclass for runtime errors that will occur on all ranks.
bool execute() override
execute the main function
Manage a collection of ParticleSet objects.
NewTimer & createGlobalTimer(const std::string &myname, timer_levels mylevel)
Declaration of QMCMain class.
bool pushDocument(const std::string &infile)
open a new document
int sizeOfObservables() const
return the size of observables
int qmc_counter
init for <qmc> section
omp_int_t omp_get_num_threads()
std::string getXMLAttributeValue(const xmlNodePtr cur, const std::string_view name)
get the value string for attribute name if name is unfound in cur you get an empty string back this i...
RandomNumberControl my_random_control_
random number controller
#define GET_MACRO_VAL(arg)
Communicate NodeComm() const
provide a node/shared-memory communicator from current (parent) communicator
int getNumGroups() const
return the number of intra_comms which belong to the same group
Declaration of a TrialWaveFunction.
const std::string & currentMainRoot() const noexcept
returns the projectmain of the project, the series id is incremented at every QMC section <project id...
std::vector< xmlNodePtr > walker_set_in_
xml mcwalkerset read-in elements
bool validateXML() override
validate the main document and (read the walker sets !)
void print_options(std::ostream &os)
print command-line options
std::unique_ptr< QMCDriverInterface > last_driver_
the last driver object. Should be in a loop only.
Declaration of HamiltonianPool.
Class for determining elapsed run time enabling simulations to adjust to time limits.
void flush()
flush stream buffer
Class to represent a many-body trial wave function.
bool setMCWalkers(xmlXPathContextPtr cur)
add <mcwalkerset> elements to continue a run
FullPrecRealType evaluate(ParticleSet &P)
evaluate Local Energy
Manager class to handle multiple threads.
void updateSource(ParticleSet &s)
remove a named Hamiltonian from the list
bool is_manager() const
return true if the rank == 0
bool get(std::ostream &os) const
MCWalkerConfiguration * qmc_system_
current MCWalkerConfiguration
TimerManager< NewTimer > & getGlobalTimerManager()
bool executeCMCSection(xmlNodePtr cur)
execute <cmc> element
void popDocument()
close the current document
QMCState qmc_common
a unique QMCState during a run
void barrier_and_abort(const std::string &msg) const
xmlNodePtr walker_logs_xml_
walkerlogs xml
Base class for QMC applications and utilities.
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
static void initializeGlobalDeviceManager(int local_rank, int local_size)
initialize the global instance of DeviceManager arguments are the same as the constructor ...
int getNumDevices() const
std::stack< Libxml2Document * > xml_doc_stack_
stack of xml document
bool put(std::istream &is) override
read from std::istream
bool executeDebugSection(xmlNodePtr cur)
execute <debug> element
Manage a collection of TrialWaveFunction objects.
Declaration of ParticleSetPool.
Declaration of QMCHamiltonian.
void reset()
Construct the root name with title_ and m_series.
Manage a collection of QMCHamiltonian objects.
bool use_density
true, if density is used, e.g. MPC
void makeGaussRandomWithEngine(ParticleAttrib< TinyVector< T, D >> &a, RG &rng)