From e36d329ac58ecabe2502d1fb35ae3dde3e7f3f26 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Mon, 20 May 2024 16:08:57 -0400 Subject: [PATCH 01/55] first working impl of TraceManager copy --- src/QMCApp/QMCMain.cpp | 9 +- src/QMCApp/QMCMain.h | 3 + src/QMCDrivers/CloneManager.cpp | 3 + src/QMCDrivers/CloneManager.h | 2 + src/QMCDrivers/DMC/DMC.cpp | 17 +- src/QMCDrivers/QMCDriver.cpp | 10 + src/QMCDrivers/QMCDriver.h | 16 ++ src/QMCDrivers/QMCDriverFactory.cpp | 6 + src/QMCDrivers/QMCDriverFactory.h | 1 + src/QMCDrivers/QMCDriverInterface.h | 2 + src/QMCDrivers/QMCDriverNew.h | 4 + src/QMCDrivers/QMCUpdateBase.cpp | 29 ++ src/QMCDrivers/QMCUpdateBase.h | 8 + src/QMCDrivers/VMC/VMC.cpp | 11 +- src/QMCDrivers/VMC/VMCUpdatePbyP.cpp | 1 + src/QMCHamiltonians/CMakeLists.txt | 2 +- src/QMCHamiltonians/OperatorBase.cpp | 59 ++++ src/QMCHamiltonians/OperatorBase.h | 27 ++ src/QMCHamiltonians/QMCHamiltonian.cpp | 255 +++++++++++++++++- src/QMCHamiltonians/QMCHamiltonian.h | 22 ++ tests/solids/diamondC_1x1x1_pp/CMakeLists.txt | 37 +++ 21 files changed, 517 insertions(+), 7 deletions(-) diff --git a/src/QMCApp/QMCMain.cpp b/src/QMCApp/QMCMain.cpp index 3469a38876..e3e398dc78 100644 --- a/src/QMCApp/QMCMain.cpp +++ b/src/QMCApp/QMCMain.cpp @@ -65,7 +65,8 @@ QMCMain::QMCMain(Communicate* c) first_qmc_(true) #if !defined(REMOVE_TRACEMANAGER) , - traces_xml_(NULL) + traces_xml_(NULL), + traces_xml_new_(NULL) #endif { Communicate node_comm{OHMMS::Controller->NodeComm()}; @@ -482,6 +483,11 @@ bool QMCMain::validateXML() { traces_xml_ = cur; } + else if (cname == "walkertraces") + { + app_log()<<"JTK: got walkertraces xml input"<putWalkers(walker_set_in_); #if !defined(REMOVE_TRACEMANAGER) qmc_driver->putTraces(traces_xml_); + qmc_driver->putTracesNew(traces_xml_new_); #endif { ScopedTimer qmc_run_timer(createGlobalTimer(qmc_driver->getEngineName(), timer_level_coarse)); diff --git a/src/QMCApp/QMCMain.h b/src/QMCApp/QMCMain.h index b32d09c5d3..b3f36c2471 100644 --- a/src/QMCApp/QMCMain.h +++ b/src/QMCApp/QMCMain.h @@ -82,6 +82,9 @@ class QMCMain : public MPIObjectBase, public QMCAppBase ///traces xml xmlNodePtr traces_xml_; + ///traces xml + xmlNodePtr traces_xml_new_; + ///qmc sections std::vector> qmc_action_; diff --git a/src/QMCDrivers/CloneManager.cpp b/src/QMCDrivers/CloneManager.cpp index 9f5e283638..e2f670b990 100644 --- a/src/QMCDrivers/CloneManager.cpp +++ b/src/QMCDrivers/CloneManager.cpp @@ -24,8 +24,10 @@ #include "Utilities/qmc_common.h" #if !defined(REMOVE_TRACEMANAGER) #include "Estimators/TraceManager.h" +#include "Estimators/TraceManagerNew.h" #else using TraceManager = int; +using TraceManagerNew = int; #endif //comment this out to use only method to clone @@ -85,6 +87,7 @@ CloneManager::~CloneManager() #if !defined(REMOVE_TRACEMANAGER) delete_iter(traceClones.begin(), traceClones.end()); + delete_iter(traceClonesNew.begin(), traceClonesNew.end()); #endif } diff --git a/src/QMCDrivers/CloneManager.h b/src/QMCDrivers/CloneManager.h index 0d3c86d15a..1b5853eb63 100644 --- a/src/QMCDrivers/CloneManager.h +++ b/src/QMCDrivers/CloneManager.h @@ -75,6 +75,8 @@ class CloneManager : public QMCTraits std::vector estimatorClones; ///trace managers std::vector traceClones; + ///trace managers + std::vector traceClonesNew; //for correlated sampling. static std::vector> WPoolClones_uptr; diff --git a/src/QMCDrivers/DMC/DMC.cpp b/src/QMCDrivers/DMC/DMC.cpp index 8592e073a6..9cafd67a04 100644 --- a/src/QMCDrivers/DMC/DMC.cpp +++ b/src/QMCDrivers/DMC/DMC.cpp @@ -33,8 +33,10 @@ #include "Utilities/FairDivide.h" #if !defined(REMOVE_TRACEMANAGER) #include "Estimators/TraceManager.h" +#include "Estimators/TraceManagerNew.h" #else using TraceManager = int; +using TraceManagerNew = int; #endif namespace qmcplusplus @@ -93,6 +95,7 @@ void DMC::resetUpdateEngines() Rng.resize(NumThreads); estimatorClones.resize(NumThreads, nullptr); traceClones.resize(NumThreads, nullptr); + traceClonesNew.resize(NumThreads, nullptr); FairDivideLow(W.getActiveWalkers(), NumThreads, wPerRank); { @@ -129,6 +132,7 @@ void DMC::resetUpdateEngines() estimatorClones[ip]->setCollectionMode(false); #if !defined(REMOVE_TRACEMANAGER) traceClones[ip] = Traces->makeClone(); + traceClonesNew[ip] = Traces_new->makeClone(); #endif Rng[ip] = rngs_[ip]->makeClone(); hClones[ip]->setRandomGenerator(Rng[ip].get()); @@ -140,7 +144,8 @@ void DMC::resetUpdateEngines() Movers[ip] = new SODMCUpdatePbyPWithRejectionFast(*wClones[ip], *psiClones[ip], *hClones[ip], *Rng[ip]); Movers[ip]->setSpinMass(SpinMass); Movers[ip]->put(qmcNode); - Movers[ip]->resetRun(branchEngine.get(), estimatorClones[ip], traceClones[ip], DriftModifier); + //Movers[ip]->resetRun(branchEngine.get(), estimatorClones[ip], traceClones[ip], DriftModifier); + Movers[ip]->resetRunNew(branchEngine.get(), estimatorClones[ip], traceClones[ip], traceClonesNew[ip], DriftModifier); Movers[ip]->initWalkersForPbyP(W.begin() + wPerRank[ip], W.begin() + wPerRank[ip + 1]); } else @@ -158,7 +163,8 @@ void DMC::resetUpdateEngines() Movers[ip] = new DMCUpdatePbyPWithRejectionFast(*wClones[ip], *psiClones[ip], *hClones[ip], *Rng[ip]); Movers[ip]->put(qmcNode); - Movers[ip]->resetRun(branchEngine.get(), estimatorClones[ip], traceClones[ip], DriftModifier); + //Movers[ip]->resetRun(branchEngine.get(), estimatorClones[ip], traceClones[ip], DriftModifier); + Movers[ip]->resetRunNew(branchEngine.get(), estimatorClones[ip], traceClones[ip], traceClonesNew[ip], DriftModifier); Movers[ip]->initWalkersForPbyP(W.begin() + wPerRank[ip], W.begin() + wPerRank[ip + 1]); } else @@ -168,7 +174,8 @@ void DMC::resetUpdateEngines() else Movers[ip] = new DMCUpdateAllWithRejection(*wClones[ip], *psiClones[ip], *hClones[ip], *Rng[ip]); Movers[ip]->put(qmcNode); - Movers[ip]->resetRun(branchEngine.get(), estimatorClones[ip], traceClones[ip], DriftModifier); + //Movers[ip]->resetRun(branchEngine.get(), estimatorClones[ip], traceClones[ip], DriftModifier); + Movers[ip]->resetRunNew(branchEngine.get(), estimatorClones[ip], traceClones[ip], traceClonesNew[ip], DriftModifier); Movers[ip]->initWalkers(W.begin() + wPerRank[ip], W.begin() + wPerRank[ip + 1]); } } @@ -181,6 +188,7 @@ void DMC::resetUpdateEngines() for (int ip = 0; ip < NumThreads; ++ip) { traceClones[ip]->transfer_state_from(*Traces); + traceClonesNew[ip]->transfer_state_from(*Traces_new); } } #endif @@ -235,6 +243,7 @@ bool DMC::run() Movers[ip]->startRun(nBlocks, false); #if !defined(REMOVE_TRACEMANAGER) Traces->startRun(nBlocks, traceClones); + Traces_new->startRun(nBlocks, traceClonesNew); #endif IndexType block = 0; IndexType updatePeriod = (qmc_driver_mode[QMC_UPDATE_MODE]) ? Period4CheckProperties : (nBlocks + 1) * nSteps; @@ -292,6 +301,7 @@ bool DMC::run() Estimators->stopBlock(acceptRatio()); #if !defined(REMOVE_TRACEMANAGER) Traces->write_buffers(traceClones, block); + Traces_new->write_buffers(traceClonesNew, block); #endif block++; if (DumpConfig && block % Period4CheckPoint == 0) @@ -325,6 +335,7 @@ bool DMC::run() Movers[ip]->stopRun2(); #if !defined(REMOVE_TRACEMANAGER) Traces->stopRun(); + Traces_new->stopRun(); #endif return finalize(nBlocks); } diff --git a/src/QMCDrivers/QMCDriver.cpp b/src/QMCDrivers/QMCDriver.cpp index b60bc2d063..9587240db0 100644 --- a/src/QMCDrivers/QMCDriver.cpp +++ b/src/QMCDrivers/QMCDriver.cpp @@ -33,8 +33,10 @@ #include "QMCDrivers/GreenFunctionModifiers/DriftModifierBuilder.h" #if !defined(REMOVE_TRACEMANAGER) #include "Estimators/TraceManager.h" +#include "Estimators/TraceManagerNew.h" #else using TraceManager = int; +using TraceManagerNew = int; #endif namespace qmcplusplus @@ -62,6 +64,7 @@ QMCDriver::QMCDriver(const ProjectData& project_data, DumpConfig = false; IsQMCDriver = true; allow_traces = false; + allow_traces_new = false; MyCounter = 0; // value //accept multiple names for the same value @@ -202,6 +205,13 @@ void QMCDriver::process(xmlNodePtr cur) Traces = std::make_unique(myComm); } Traces->put(traces_xml, allow_traces, RootName); + + //create and initialize traces + if (!Traces_new) + { + Traces_new = std::make_unique(myComm); + } + Traces_new->put(traces_xml_new, allow_traces_new, RootName); #endif branchEngine->put(cur); Estimators->put(H, cur); diff --git a/src/QMCDrivers/QMCDriver.h b/src/QMCDrivers/QMCDriver.h index 571fa3d858..3fd6398c18 100644 --- a/src/QMCDrivers/QMCDriver.h +++ b/src/QMCDrivers/QMCDriver.h @@ -62,6 +62,7 @@ namespace qmcplusplus class MCWalkerConfiguration; class HDFWalkerOutput; class TraceManager; +class TraceManagerNew; /** @ingroup QMCDrivers * @{ @@ -96,6 +97,11 @@ class QMCDriver : public QMCDriverInterface, public QMCTraits, public MPIObjectB /// traces xml xmlNodePtr traces_xml; + /// whether to allow traces + bool allow_traces_new; + /// traces xml + xmlNodePtr traces_xml_new; + /// Constructor. QMCDriver(const ProjectData& project_data, MCWalkerConfiguration& w, @@ -149,6 +155,13 @@ class QMCDriver : public QMCDriverInterface, public QMCTraits, public MPIObjectB inline void requestTraces(bool traces) override { allow_traces = traces; } + inline void putTracesNew(xmlNodePtr txml) override { + app_log()<<"JTK: putTracesNew"< @@ -184,6 +197,9 @@ class QMCDriver : public QMCDriverInterface, public QMCTraits, public MPIObjectB ///Traces manager std::unique_ptr Traces; + ///Traces manager + std::unique_ptr Traces_new; + ///return the random generators inline RefVector> getRngRefs() const { diff --git a/src/QMCDrivers/QMCDriverFactory.cpp b/src/QMCDrivers/QMCDriverFactory.cpp index 00d3abd629..f4651a5ad6 100644 --- a/src/QMCDrivers/QMCDriverFactory.cpp +++ b/src/QMCDrivers/QMCDriverFactory.cpp @@ -76,6 +76,7 @@ QMCDriverFactory::DriverAssemblyState QMCDriverFactory::readSection(xmlNodePtr c aAttrib.add(append_tag, "append"); aAttrib.add(profiling_tag, "profiling"); aAttrib.add(das.traces_tag, "trace"); + aAttrib.add(das.walkertraces_tag, "walkertrace"); aAttrib.put(cur); das.append_run = (append_tag == "yes"); das.enable_profiling = (profiling_tag == "yes"); @@ -294,6 +295,11 @@ std::unique_ptr QMCDriverFactory::createQMCDriver(xmlNodePtr (das.traces_tag == "none" && (das.new_run_type == QMCRunType::VMC || das.new_run_type == QMCRunType::DMC)); new_driver->requestTraces(allow_traces); + //add trace information + bool allow_traces_new = das.walkertraces_tag == "yes" || + (das.walkertraces_tag == "none" && (das.new_run_type == QMCRunType::VMC || das.new_run_type == QMCRunType::DMC)); + new_driver->requestTracesNew(allow_traces_new); + return new_driver; } } // namespace qmcplusplus diff --git a/src/QMCDrivers/QMCDriverFactory.h b/src/QMCDrivers/QMCDriverFactory.h index c1dd191b8f..fc8800719f 100644 --- a/src/QMCDrivers/QMCDriverFactory.h +++ b/src/QMCDrivers/QMCDriverFactory.h @@ -47,6 +47,7 @@ class QMCDriverFactory bool append_run = false; bool enable_profiling = false; std::string traces_tag = "none"; + std::string walkertraces_tag = "none"; QMCRunType new_run_type = QMCRunType::DUMMY; }; diff --git a/src/QMCDrivers/QMCDriverInterface.h b/src/QMCDrivers/QMCDriverInterface.h index 7e20915583..59168f9ed5 100644 --- a/src/QMCDrivers/QMCDriverInterface.h +++ b/src/QMCDrivers/QMCDriverInterface.h @@ -49,6 +49,8 @@ class QMCDriverInterface virtual void putWalkers(std::vector& wset) = 0; virtual void putTraces(xmlNodePtr txml) = 0; virtual void requestTraces(bool allow_traces) = 0; + virtual void putTracesNew(xmlNodePtr txml) = 0; + virtual void requestTracesNew(bool allow_traces) = 0; virtual void process(xmlNodePtr cur) = 0; virtual QMCRunType getRunType() = 0; virtual std::string getEngineName() = 0; diff --git a/src/QMCDrivers/QMCDriverNew.h b/src/QMCDrivers/QMCDriverNew.h index 079850cf3a..2318ea0436 100644 --- a/src/QMCDrivers/QMCDriverNew.h +++ b/src/QMCDrivers/QMCDriverNew.h @@ -51,6 +51,7 @@ namespace qmcplusplus { //forward declarations: Do not include headers if not needed class TraceManager; +class TraceManagerNew; class EstimatorManagerNew; class TrialWaveFunction; class QMCHamiltonian; @@ -241,6 +242,9 @@ class QMCDriverNew : public QMCDriverInterface, public MPIObjectBase void putTraces(xmlNodePtr txml) override {} void requestTraces(bool allow_traces) override {} + void putTracesNew(xmlNodePtr txml) override {} + void requestTracesNew(bool allow_traces) override {} + // scales a MCCoords by sqrtTau. Chooses appropriate taus by CT template static void scaleBySqrtTau(const TauParams& taus, MCCoords& coords) diff --git a/src/QMCDrivers/QMCUpdateBase.cpp b/src/QMCDrivers/QMCUpdateBase.cpp index 215bd37695..0904e0b646 100644 --- a/src/QMCDrivers/QMCUpdateBase.cpp +++ b/src/QMCDrivers/QMCUpdateBase.cpp @@ -23,8 +23,10 @@ #include "Concurrency/OpenMP.h" #if !defined(REMOVE_TRACEMANAGER) #include "Estimators/TraceManager.h" +#include "Estimators/TraceManagerNew.h" #else using TraceManager = int; +using TraceManagerNew = int; #endif namespace qmcplusplus @@ -37,6 +39,7 @@ QMCUpdateBase::QMCUpdateBase(MCWalkerConfiguration& w, RandomBase& rg) : csoffset(0), Traces(0), + Traces_new(0), W(w), Psi(psi), Guide(guide), @@ -57,6 +60,7 @@ QMCUpdateBase::QMCUpdateBase(MCWalkerConfiguration& w, RandomBase& rg) : csoffset(0), Traces(0), + Traces_new(0), W(w), Psi(psi), Guide(psi), @@ -114,6 +118,16 @@ bool QMCUpdateBase::put(xmlNodePtr cur) return s; } +void QMCUpdateBase::resetRunNew(BranchEngineType* brancher, + EstimatorManagerBase* est, + TraceManager* traces, + TraceManagerNew* traces_new, + const DriftModifierBase* driftmodifer) +{ + Traces_new = traces_new; + resetRun(brancher,est,traces,driftmodifer); +} + void QMCUpdateBase::resetRun(BranchEngineType* brancher, EstimatorManagerBase* est, TraceManager* traces, @@ -163,6 +177,16 @@ void QMCUpdateBase::startRun(int blocks, bool record) } H.initialize_traces(*Traces, W); Traces->initialize_traces(); + + if (!Traces_new) + { + APP_ABORT( + "QMCUpdateBase::startRun\n derived QMCDriver class has not setup (new!) trace clones properly\n null TraceManagerNew " + "pointer encountered in derived QMCUpdateBase class\n see VMCLinearOptOMP.cpp for a correct minimal interface " + "(search on 'trace')\n refer to changes made in SVN revision 6597 for further guidance"); + } + H.initialize_traces_new(*Traces_new, W); + Traces_new->initialize_traces(); #endif } @@ -175,6 +199,9 @@ void QMCUpdateBase::stopRun2() #if !defined(REMOVE_TRACEMANAGER) H.finalize_traces(); Traces->finalize_traces(); + + H.finalize_traces_new(); + Traces_new->finalize_traces(); #endif } @@ -183,6 +210,7 @@ void QMCUpdateBase::startBlock(int steps) Estimators->startBlock(steps); #if !defined(REMOVE_TRACEMANAGER) Traces->startBlock(steps); + Traces_new->startBlock(steps); #endif nAccept = 0; nReject = 0; @@ -196,6 +224,7 @@ void QMCUpdateBase::stopBlock(bool collectall) Estimators->stopBlock(acceptRatio(), collectall); #if !defined(REMOVE_TRACEMANAGER) Traces->stopBlock(); + Traces_new->stopBlock(); #endif } diff --git a/src/QMCDrivers/QMCUpdateBase.h b/src/QMCDrivers/QMCUpdateBase.h index 48d8a9315b..725e2a702b 100644 --- a/src/QMCDrivers/QMCUpdateBase.h +++ b/src/QMCDrivers/QMCUpdateBase.h @@ -31,6 +31,7 @@ namespace qmcplusplus { class TraceManager; +class TraceManagerNew; /** @ingroup QMC * @brief Base class for update methods for each step * @@ -101,6 +102,12 @@ class QMCUpdateBase : public QMCTraits TraceManager* traces, const DriftModifierBase* driftmodifer); + void resetRunNew(BranchEngineType* brancher, + EstimatorManagerBase* est, + TraceManager* traces, + TraceManagerNew* traces_new, + const DriftModifierBase* driftmodifer); + inline RealType getTau() { //SpeciesSet tspecies(W.getSpeciesSet()); @@ -238,6 +245,7 @@ class QMCUpdateBase : public QMCTraits public: ///traces TraceManager* Traces; + TraceManagerNew* Traces_new; protected: ///update particle-by-particle diff --git a/src/QMCDrivers/VMC/VMC.cpp b/src/QMCDrivers/VMC/VMC.cpp index bc97b82a66..6967913575 100644 --- a/src/QMCDrivers/VMC/VMC.cpp +++ b/src/QMCDrivers/VMC/VMC.cpp @@ -29,8 +29,10 @@ #include "Utilities/FairDivide.h" #if !defined(REMOVE_TRACEMANAGER) #include "Estimators/TraceManager.h" +#include "Estimators/TraceManagerNew.h" #else using TraceManager = int; +using TraceManagerNew = int; #endif namespace qmcplusplus @@ -65,6 +67,7 @@ bool VMC::run() Movers[ip]->startRun(nBlocks, false); #if !defined(REMOVE_TRACEMANAGER) Traces->startRun(nBlocks, traceClones); + Traces_new->startRun(nBlocks, traceClonesNew); #endif LoopTimer<> vmc_loop; @@ -108,6 +111,7 @@ bool VMC::run() Estimators->stopBlock(estimatorClones); #if !defined(REMOVE_TRACEMANAGER) Traces->write_buffers(traceClones, block); + Traces_new->write_buffers(traceClonesNew, block); #endif recordBlock(block); vmc_loop.stop(); @@ -130,6 +134,7 @@ bool VMC::run() Movers[ip]->stopRun2(); #if !defined(REMOVE_TRACEMANAGER) Traces->stopRun(); + Traces_new->stopRun(); #endif //copy back the random states for (int ip = 0; ip < NumThreads; ++ip) @@ -165,6 +170,7 @@ void VMC::resetRun() Movers.resize(NumThreads, nullptr); estimatorClones.resize(NumThreads, nullptr); traceClones.resize(NumThreads, nullptr); + traceClonesNew.resize(NumThreads, nullptr); Rng.resize(NumThreads); // hdf_archive::hdf_archive() is not thread-safe @@ -179,6 +185,7 @@ void VMC::resetRun() estimatorClones[ip]->setCollectionMode(false); #if !defined(REMOVE_TRACEMANAGER) traceClones[ip] = Traces->makeClone(); + traceClonesNew[ip] = Traces_new->makeClone(); #endif Rng[ip] = rngs_[ip]->makeClone(); hClones[ip]->setRandomGenerator(Rng[ip].get()); @@ -217,6 +224,7 @@ void VMC::resetRun() for (int ip = 0; ip < NumThreads; ++ip) { traceClones[ip]->transfer_state_from(*Traces); + traceClonesNew[ip]->transfer_state_from(*Traces_new); } } #endif @@ -262,7 +270,8 @@ void VMC::resetRun() { //int ip=omp_get_thread_num(); Movers[ip]->put(qmcNode); - Movers[ip]->resetRun(branchEngine.get(), estimatorClones[ip], traceClones[ip], DriftModifier); + //Movers[ip]->resetRun(branchEngine.get(), estimatorClones[ip], traceClones[ip], DriftModifier); + Movers[ip]->resetRunNew(branchEngine.get(), estimatorClones[ip], traceClones[ip], traceClonesNew[ip], DriftModifier); if (qmc_driver_mode[QMC_UPDATE_MODE]) Movers[ip]->initWalkersForPbyP(W.begin() + wPerRank[ip], W.begin() + wPerRank[ip + 1]); else diff --git a/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp b/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp index fbce39d2ea..cfd08ee7f6 100644 --- a/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp +++ b/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp @@ -133,6 +133,7 @@ void VMCUpdatePbyP::advanceWalker(Walker_t& thisWalker, bool recompute) collectables_timer_.stop(); #if !defined(REMOVE_TRACEMANAGER) Traces->buffer_sample(W.current_step); + Traces_new->buffer_sample(W.current_step); #endif if (!moved) ++nAllRejected; diff --git a/src/QMCHamiltonians/CMakeLists.txt b/src/QMCHamiltonians/CMakeLists.txt index 92ba055e04..8f7d6b3a52 100644 --- a/src/QMCHamiltonians/CMakeLists.txt +++ b/src/QMCHamiltonians/CMakeLists.txt @@ -70,7 +70,7 @@ if(OHMMS_DIM MATCHES 3) ECPComponentBuilder_L2.cpp) if(NOT REMOVE_TRACEMANAGER) - set(HAMSRCS ${HAMSRCS} ../Estimators/TraceManager.cpp ReferencePoints.cpp SpaceGrid.cpp EnergyDensityEstimator.cpp + set(HAMSRCS ${HAMSRCS} ../Estimators/TraceManager.cpp ../Estimators/TraceManagerNew.cpp ReferencePoints.cpp SpaceGrid.cpp EnergyDensityEstimator.cpp DensityMatrices1B.cpp) endif() diff --git a/src/QMCHamiltonians/OperatorBase.cpp b/src/QMCHamiltonians/OperatorBase.cpp index 8f7dc68d38..3ac3f03f5b 100644 --- a/src/QMCHamiltonians/OperatorBase.cpp +++ b/src/QMCHamiltonians/OperatorBase.cpp @@ -33,6 +33,10 @@ OperatorBase::OperatorBase() streaming_particles_(false), have_required_traces_(false), streaming_scalars_(false), + + streaming_particles_new_(false), + have_required_traces_new_(false), + streaming_scalars_new_(false), #endif quantum_domain_(NO_QUANTUM_DOMAIN), energy_domain_(NO_ENERGY_DOMAIN) @@ -50,6 +54,7 @@ void OperatorBase::setName(const std::string name) noexcept { name_ = name; } #if !defined(REMOVE_TRACEMANAGER) TraceRequest& OperatorBase::getRequest() noexcept { return request_; } +TraceRequestNew& OperatorBase::getRequestNew() noexcept { return request_new_; } #endif //////// FUNCTIONS //////////////// @@ -223,6 +228,7 @@ void OperatorBase::add2Hamiltonian(ParticleSet& qp, TrialWaveFunction& psi, QMCH #if !defined(REMOVE_TRACEMANAGER) void OperatorBase::getRequiredTraces(TraceManager& tm){}; +void OperatorBase::getRequiredTracesNew(TraceManagerNew& tm){}; #endif // END FUNCTIONS // @@ -269,6 +275,32 @@ void OperatorBase::deleteTraceQuantities() request_.reset(); } + + +void OperatorBase::contributeTraceQuantitiesNew() +{ + contributeScalarQuantitiesNew(); + contributeParticleQuantitiesNew(); +} + +void OperatorBase::checkoutTraceQuantitiesNew(TraceManagerNew& tm) +{ + checkoutScalarQuantitiesNew(tm); + checkoutParticleQuantitiesNew(tm); +} + +void OperatorBase::collectScalarTracesNew() { collectScalarQuantitiesNew(); } + +void OperatorBase::deleteTraceQuantitiesNew() +{ + deleteScalarQuantitiesNew(); + deleteParticleQuantitiesNew(); + streaming_scalars_new_ = false; + streaming_particles_new_ = false; + have_required_traces_new_ = false; + request_new_.reset(); +} + #endif ////// PROTECTED FUNCTIONS @@ -297,6 +329,33 @@ void OperatorBase::deleteScalarQuantities() void OperatorBase::contributeParticleQuantities(){}; void OperatorBase::checkoutParticleQuantities(TraceManager& tm){}; void OperatorBase::deleteParticleQuantities(){}; + + + +void OperatorBase::contributeScalarQuantitiesNew() { request_new_.contribute_scalar(name_); } + +void OperatorBase::checkoutScalarQuantitiesNew(TraceManagerNew& tm) +{ + streaming_scalars_new_ = request_new_.streaming_scalar(name_); + if (streaming_scalars_new_) + value_sample_new_ = tm.checkout_real<1>(name_); +} + +void OperatorBase::collectScalarQuantitiesNew() +{ + if (streaming_scalars_new_) + (*value_sample_new_)(0) = value_; +} + +void OperatorBase::deleteScalarQuantitiesNew() +{ + if (streaming_scalars_new_) + delete value_sample_new_; +} + +void OperatorBase::contributeParticleQuantitiesNew(){}; +void OperatorBase::checkoutParticleQuantitiesNew(TraceManagerNew& tm){}; +void OperatorBase::deleteParticleQuantitiesNew(){}; #endif void OperatorBase::setComputeForces(bool compute) {} diff --git a/src/QMCHamiltonians/OperatorBase.h b/src/QMCHamiltonians/OperatorBase.h index cd4641dd01..8eef25e7ce 100644 --- a/src/QMCHamiltonians/OperatorBase.h +++ b/src/QMCHamiltonians/OperatorBase.h @@ -31,6 +31,7 @@ #include "QMCWaveFunctions/TWFFastDerivWrapper.h" #if !defined(REMOVE_TRACEMANAGER) #include "Estimators/TraceManager.h" +#include "Estimators/TraceManagerNew.h" #endif #include "QMCHamiltonians/Listener.hpp" #include "QMCWaveFunctions/OrbitalSetTraits.h" @@ -163,6 +164,7 @@ class OperatorBase : public QMCTraits * @return TraceRequest& reference to request_ */ TraceRequest& getRequest() noexcept; + TraceRequestNew& getRequestNew() noexcept; #endif //////// PURELY VIRTUAL FUNCTIONS //////////////// @@ -464,6 +466,7 @@ class OperatorBase : public QMCTraits * @param tm */ virtual void getRequiredTraces(TraceManager& tm); + virtual void getRequiredTracesNew(TraceManagerNew& tm); #endif // TODO: add docs @@ -514,6 +517,12 @@ class OperatorBase : public QMCTraits * @brief delete trace arrays */ void deleteTraceQuantities(); + + + void contributeTraceQuantitiesNew(); + void checkoutTraceQuantitiesNew(TraceManagerNew& tm); + void collectScalarTracesNew(); + void deleteTraceQuantitiesNew(); #endif protected: @@ -529,6 +538,7 @@ class OperatorBase : public QMCTraits #if !defined(REMOVE_TRACEMANAGER) ///whether traces are being collected TraceRequest request_; + TraceRequestNew request_new_; #endif ///starting index of this object @@ -543,6 +553,8 @@ class OperatorBase : public QMCTraits #if !defined(REMOVE_TRACEMANAGER) bool streaming_particles_; bool have_required_traces_; + bool streaming_particles_new_; + bool have_required_traces_new_; #endif /////PURELY VIRTUAL FUNCTIONS @@ -567,6 +579,15 @@ class OperatorBase : public QMCTraits virtual void contributeParticleQuantities(); virtual void checkoutParticleQuantities(TraceManager& tm); virtual void deleteParticleQuantities(); + + + virtual void contributeScalarQuantitiesNew(); + virtual void checkoutScalarQuantitiesNew(TraceManagerNew& tm); + virtual void collectScalarQuantitiesNew(); + virtual void deleteScalarQuantitiesNew(); + virtual void contributeParticleQuantitiesNew(); + virtual void checkoutParticleQuantitiesNew(TraceManagerNew& tm); + virtual void deleteParticleQuantitiesNew(); #endif virtual void setComputeForces(bool compute); @@ -604,6 +625,12 @@ class OperatorBase : public QMCTraits ///array to store sample value Array* value_sample_; + + + bool streaming_scalars_new_; + + ///array to store sample value + Array* value_sample_new_; #endif /** Is there a per particle listener diff --git a/src/QMCHamiltonians/QMCHamiltonian.cpp b/src/QMCHamiltonians/QMCHamiltonian.cpp index 8056e050bf..a4cfda87cc 100644 --- a/src/QMCHamiltonians/QMCHamiltonian.cpp +++ b/src/QMCHamiltonians/QMCHamiltonian.cpp @@ -65,7 +65,17 @@ QMCHamiltonian::QMCHamiltonian(const std::string& aname) age_sample(nullptr), mult_sample(nullptr), weight_sample(nullptr), - position_sample(nullptr) + position_sample(nullptr), + + streaming_position_new(false), + id_sample_new(nullptr), + pid_sample_new(nullptr), + step_sample_new(nullptr), + gen_sample_new(nullptr), + age_sample_new(nullptr), + mult_sample_new(nullptr), + weight_sample_new(nullptr), + position_sample_new(nullptr) #endif {} @@ -530,6 +540,240 @@ void QMCHamiltonian::finalize_traces() streaming_position = false; request.reset(); } + + + + + + + +void QMCHamiltonian::initialize_traces_new(TraceManagerNew& tm, ParticleSet& P) +{ + static bool first_init_new = true; + bool trace_log = first_init_new && tm.verbose && omp_get_thread_num() == 0; + if (trace_log) + app_log() << "\n Hamiltonian is initializing traces" << std::endl; + + //fill std::string vectors for combined trace quantities + std::vector Eloc; + std::vector Vloc; + std::vector Vq, Vc, Vqq, Vqc, Vcc; + for (int i = 0; i < H.size(); ++i) + Eloc.push_back(H[i]->getName()); + for (int i = 1; i < H.size(); ++i) + Vloc.push_back(H[i]->getName()); + + // These contributions are based on the potential energy components. + // Loop starts at one to skip the kinetic energy component. + for (int i = 1; i < H.size(); ++i) + { + OperatorBase& h = *H[i]; + if (h.isQuantum()) + Vq.push_back(h.getName()); + else if (h.isClassical()) + Vc.push_back(h.getName()); + else if (h.isQuantumQuantum()) + Vqq.push_back(h.getName()); + else if (h.isQuantumClassical()) + Vqc.push_back(h.getName()); + else if (h.isClassicalClassical()) + Vcc.push_back(h.getName()); + else if (omp_get_thread_num() == 0) + app_log() << " warning: potential named " << h.getName() + << " has not been classified according to its quantum domain (q,c,qq,qc,cc)\n estimators depending " + "on this classification may not function properly" + << std::endl; + } + + + //make trace quantities available + request_new.contribute_scalar("id", true); //default trace quantity + request_new.contribute_scalar("parent_id", true); //default trace quantity + request_new.contribute_scalar("step", true); //default trace quantity + request_new.contribute_scalar("generation", true); //default trace quantity + request_new.contribute_scalar("age", true); //default trace quantity + request_new.contribute_scalar("multiplicity", true); //default trace quantity + request_new.contribute_scalar("weight", true); //default trace quantity + request_new.contribute_array("position"); + for (int i = 0; i < H.size(); ++i) + H[i]->contributeTraceQuantitiesNew(); + //for (int i = 0; i < auxH.size(); ++i) + // auxH[i]->contributeTraceQuantitiesNew(); + + + //note availability of combined quantities + request_new.contribute_combined("LocalEnergy", Eloc, true); + request_new.contribute_combined("LocalPotential", Vloc, true, true); + if (Vq.size() > 0) + request_new.contribute_combined("Vq", Vq, true, true); + if (Vc.size() > 0) + request_new.contribute_combined("Vc", Vc, true, true); + if (Vqq.size() > 0) + request_new.contribute_combined("Vqq", Vqq, true, true); + if (Vqc.size() > 0) + request_new.contribute_combined("Vqc", Vqc, true, true); + if (Vcc.size() > 0) + request_new.contribute_combined("Vcc", Vcc, true, true); + + + ////collect trace requests + std::vector requests; + // Hamiltonian request (id, step, weight, positions) + requests.push_back(&request_new); + //// requests from Hamiltonian components + for (int i = 0; i < H.size(); ++i) + requests.push_back(&H[i]->getRequestNew()); + //// requests from other observables + //for (int i = 0; i < auxH.size(); ++i) + // requests.push_back(&auxH[i]->getRequest()); + // + //collect trace quantity availability/requests from contributors/requestors + for (int i = 0; i < requests.size(); ++i) + tm.request.incorporate(*requests[i]); + + //balance requests with availability, mark quantities as streaming/writing + tm.request.determine_stream_write(); + + //relay updated streaming information to all contributors/requestors + for (int i = 0; i < requests.size(); ++i) + tm.request.relay_stream_info(*requests[i]); + + //set streaming/writing traces in general + tm.update_status(); + + // setup traces, if any quantities should be streaming + + // tracing + bool tracing = request_new.streaming(); + if (tracing != tm.streaming_traces) + APP_ABORT("QMCHamiltonian::initialize_traces_new trace request failed to initialize properly"); + if (!tracing) + { + // Empty. Do not log if nothing will be done + + if (trace_log) + app_log() << " no walker traces streaming" << std::endl; + } + else + { + if (trace_log) + app_log() << " walker traces streaming" << std::endl; + //checkout trace quantities + //(requested sources checkout arrays to place samples in for streaming) + // checkout walker trace quantities + streaming_position_new = request_new.streaming_array("position"); + if (request_new.streaming_default_scalars) + { + id_sample_new = tm.checkout_int<1>("id"); + pid_sample_new = tm.checkout_int<1>("parent_id"); + step_sample_new = tm.checkout_int<1>("step"); + gen_sample_new = tm.checkout_int<1>("generation"); + age_sample_new = tm.checkout_int<1>("age"); + mult_sample_new = tm.checkout_int<1>("multiplicity"); + weight_sample_new = tm.checkout_real<1>("weight"); + } + if (streaming_position_new) + position_sample_new = tm.checkout_real<2>("position", P, DIM); + // checkout observable trace quantities + for (int i = 0; i < H.size(); ++i) + { + if (trace_log) + app_log() << " OperatorBase::checkoutTraceQuantitiesNew " << H[i]->getName() << std::endl; + H[i]->checkoutTraceQuantitiesNew(tm); + } + //for (int i = 0; i < auxH.size(); ++i) + //{ + // if (trace_log) + // app_log() << " OperatorBase::checkoutTraceQuantities " << auxH[i]->getName() << std::endl; + // auxH[i]->checkoutTraceQuantities(tm); + //} + //setup combined traces that depend on H information + // LocalEnergy, LocalPotential, Vq, Vc, Vqq, Vqc, Vcc + if (Vloc.size() > 0 && request.streaming("LocalPotential")) + tm.make_combined_trace("LocalPotential", Vloc); + if (Eloc.size() > 0 && request.streaming("LocalEnergy")) + tm.make_combined_trace("LocalEnergy", Eloc); + if (Vq.size() > 0 && request.streaming("Vq")) + tm.make_combined_trace("Vq", Eloc); + if (Vc.size() > 0 && request.streaming("Vc")) + tm.make_combined_trace("Vc", Eloc); + if (Vqq.size() > 0 && request.streaming("Vqq")) + tm.make_combined_trace("Vqq", Eloc); + if (Vqc.size() > 0 && request.streaming("Vqc")) + tm.make_combined_trace("Vqc", Eloc); + if (Vcc.size() > 0 && request.streaming("Vcc")) + tm.make_combined_trace("Vcc", Eloc); + + //all trace samples have been created ( streaming instances) + // mark the ones that will be writing also + tm.screen_writes(); + + ////observables that depend on traces check them out + //if (trace_log) + // app_log() << "\n Hamiltonian is fulfilling trace requests from observables" << std::endl; + //for (int i = 0; i < auxH.size(); ++i) + //{ + // if (trace_log) + // app_log() << " OperatorBase::getRequiredTraces " << auxH[i]->getName() << std::endl; + // auxH[i]->getRequiredTraces(tm); + //} + //report + + //write traces status to the log + if (trace_log) + tm.user_report(); + + first_init_new = false; + } +} + + +void QMCHamiltonian::collect_walker_traces_new(Walker_t& walker, int step) +{ + if (request_new.streaming_default_scalars) + { + (*id_sample_new)(0) = walker.getWalkerID(); + (*pid_sample_new)(0) = walker.getParentID(); + (*step_sample_new)(0) = step; + (*gen_sample_new)(0) = walker.Generation; + (*age_sample_new)(0) = walker.Age; + (*mult_sample_new)(0) = walker.Multiplicity; + (*weight_sample_new)(0) = walker.Weight; + } + if (streaming_position_new) + for (int i = 0; i < walker.R.size(); ++i) + for (int d = 0; d < DIM; ++d) + (*position_sample_new)(i, d) = walker.R[i][d]; +} + + +void QMCHamiltonian::finalize_traces_new() +{ + if (request_new.streaming_default_scalars) + { + delete id_sample_new; + delete pid_sample_new; + delete step_sample_new; + delete gen_sample_new; + delete age_sample_new; + delete mult_sample_new; + delete weight_sample_new; + } + if (streaming_position_new) + delete position_sample_new; + if (request_new.streaming()) + { + for (int i = 0; i < H.size(); ++i) + H[i]->deleteTraceQuantitiesNew(); + //for (int i = 0; i < auxH.size(); ++i) + // auxH[i]->deleteTraceQuantities(); + } + streaming_position_new = false; + request_new.reset(); +} + + + #endif /** Evaluate all the Hamiltonians for the N-particle configuration @@ -547,6 +791,7 @@ QMCHamiltonian::FullPrecRealType QMCHamiltonian::evaluate(ParticleSet& P) updateComponent(*H[i], *this, P); #if !defined(REMOVE_TRACEMANAGER) H[i]->collectScalarTraces(); + H[i]->collectScalarTracesNew(); #endif } updateKinetic(*this, P); @@ -564,6 +809,7 @@ QMCHamiltonian::FullPrecRealType QMCHamiltonian::evaluateDeterministic(ParticleS updateComponent(*H[i], *this, P); #if !defined(REMOVE_TRACEMANAGER) H[i]->collectScalarTraces(); + H[i]->collectScalarTracesNew(); #endif } updateKinetic(*this, P); @@ -727,6 +973,7 @@ void QMCHamiltonian::auxHevaluate(ParticleSet& P) auxH[i]->setObservables(Observables); #if !defined(REMOVE_TRACEMANAGER) auxH[i]->collectScalarTraces(); + auxH[i]->collectScalarTracesNew(); #endif auxH[i]->setParticlePropertyList(P.PropertyList, myIndex); //H[i]->setParticlePropertyList(P.PropertyList,myIndex); @@ -738,6 +985,7 @@ void QMCHamiltonian::auxHevaluate(ParticleSet& P, Walker_t& ThisWalker) { #if !defined(REMOVE_TRACEMANAGER) collect_walker_traces(ThisWalker, P.current_step); + collect_walker_traces_new(ThisWalker, P.current_step); #endif for (int i = 0; i < auxH.size(); ++i) { @@ -746,6 +994,7 @@ void QMCHamiltonian::auxHevaluate(ParticleSet& P, Walker_t& ThisWalker) auxH[i]->setObservables(Observables); #if !defined(REMOVE_TRACEMANAGER) auxH[i]->collectScalarTraces(); + auxH[i]->collectScalarTracesNew(); #endif auxH[i]->setParticlePropertyList(P.PropertyList, myIndex); } @@ -755,6 +1004,7 @@ void QMCHamiltonian::auxHevaluate(ParticleSet& P, Walker_t& ThisWalker, bool do_ { #if !defined(REMOVE_TRACEMANAGER) collect_walker_traces(ThisWalker, P.current_step); + collect_walker_traces_new(ThisWalker, P.current_step); #endif for (int i = 0; i < auxH.size(); ++i) { @@ -767,6 +1017,7 @@ void QMCHamiltonian::auxHevaluate(ParticleSet& P, Walker_t& ThisWalker, bool do_ auxH[i]->setObservables(Observables); #if !defined(REMOVE_TRACEMANAGER) auxH[i]->collectScalarTraces(); + auxH[i]->collectScalarTracesNew(); #endif auxH[i]->setParticlePropertyList(P.PropertyList, myIndex); } @@ -783,6 +1034,7 @@ void QMCHamiltonian::rejectedMove(ParticleSet& P, Walker_t& ThisWalker) // (they will be from the walker moved before this one) #if !defined(REMOVE_TRACEMANAGER) collect_walker_traces(ThisWalker, P.current_step); + collect_walker_traces_new(ThisWalker, P.current_step); #endif // ThisWalker.rejectedMove(); for (int i = 0; i < auxH.size(); ++i) @@ -803,6 +1055,7 @@ QMCHamiltonian::FullPrecRealType QMCHamiltonian::evaluateWithToperator(ParticleS updateComponent(*H[i], *this, P); #if !defined(REMOVE_TRACEMANAGER) H[i]->collectScalarTraces(); + H[i]->collectScalarTracesNew(); #endif } updateKinetic(*this, P); diff --git a/src/QMCHamiltonians/QMCHamiltonian.h b/src/QMCHamiltonians/QMCHamiltonian.h index 11dda4ac9c..08e6271425 100644 --- a/src/QMCHamiltonians/QMCHamiltonian.h +++ b/src/QMCHamiltonians/QMCHamiltonian.h @@ -33,6 +33,7 @@ #include "Utilities/Resource.h" #if !defined(REMOVE_TRACEMANAGER) #include "Estimators/TraceManager.h" +#include "Estimators/TraceManagerNew.h" #endif #include "QMCWaveFunctions/OrbitalSetTraits.h" @@ -113,6 +114,15 @@ class QMCHamiltonian ///finalize trace data void finalize_traces(); + + ///initialize trace data + void initialize_traces_new(TraceManagerNew& tm, ParticleSet& P); + + ///collect walker trace data + void collect_walker_traces_new(Walker_t& walker, int step); + + ///finalize trace data + void finalize_traces_new(); #endif /** @@ -486,6 +496,18 @@ class QMCHamiltonian Array* mult_sample; Array* weight_sample; Array* position_sample; + + ///traces variables + TraceRequestNew request_new; + bool streaming_position_new; + Array* id_sample_new; + Array* pid_sample_new; + Array* step_sample_new; + Array* gen_sample_new; + Array* age_sample_new; + Array* mult_sample_new; + Array* weight_sample_new; + Array* position_sample_new; #endif /// multiwalker shared resource diff --git a/tests/solids/diamondC_1x1x1_pp/CMakeLists.txt b/tests/solids/diamondC_1x1x1_pp/CMakeLists.txt index 598d460206..9b7a9791a2 100644 --- a/tests/solids/diamondC_1x1x1_pp/CMakeLists.txt +++ b/tests/solids/diamondC_1x1x1_pp/CMakeLists.txt @@ -1874,6 +1874,43 @@ if(add_traces_tests) -m 'vmc,dmc' --dmc_steps_exclude=1) + + simple_run_and_check( + deterministic-diamondC_1x1x1_pp-vmc-dmc-walkertrace_scalars + "${qmcpack_SOURCE_DIR}/tests/solids/diamondC_1x1x1_pp" + qmc_walkertrace_scalars.in.xml + 1 + 1 + check_traces.py + -p + qmc_trace_scalars + -s + 0 + -m + vmc + -q + 'Kinetic,ElecElec,IonIon,LocalECP,NonLocalECP' + --dmc_steps_exclude=1) + + simple_run_and_check( + deterministic-diamondC_1x1x1_pp-vmc-dmc-walkertrace_scalars + "${qmcpack_SOURCE_DIR}/tests/solids/diamondC_1x1x1_pp" + qmc_walkertrace_scalars.in.xml + 4 + 4 + check_traces.py + -p + qmc_trace_scalars + -n + 4 + -s + 0 + -m + vmc + -q + 'Kinetic,ElecElec,IonIon,LocalECP,NonLocalECP' + --dmc_steps_exclude=1) + endif() if(QMC_MIXED_PRECISION) From abf1634c000bc2ffc23d18fc0c7d97b927a5cab8 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Tue, 21 May 2024 04:02:18 -0400 Subject: [PATCH 02/55] remove unused functions --- src/Estimators/TraceManagerNew.cpp | 27 + src/Estimators/TraceManagerNew.h | 2076 +++++++++++++++++ src/QMCDrivers/QMCUpdateBase.cpp | 1 - .../qmc_walkertrace_scalars.in.xml | 103 + 4 files changed, 2206 insertions(+), 1 deletion(-) create mode 100644 src/Estimators/TraceManagerNew.cpp create mode 100644 src/Estimators/TraceManagerNew.h create mode 100644 tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_scalars.in.xml diff --git a/src/Estimators/TraceManagerNew.cpp b/src/Estimators/TraceManagerNew.cpp new file mode 100644 index 0000000000..45ac8c4fae --- /dev/null +++ b/src/Estimators/TraceManagerNew.cpp @@ -0,0 +1,27 @@ +////////////////////////////////////////////////////////////////////////////////////// +// 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. +// +// File developed by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory +// Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory +// +// File created by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory +////////////////////////////////////////////////////////////////////////////////////// + + +#if !defined(DISABLE_TRACEMANAGER) + + +#include "TraceManagerNew.h" + + +namespace qmcplusplus +{ +double TraceManagerNew::trace_tol = 1e-8; + +} + + +#endif diff --git a/src/Estimators/TraceManagerNew.h b/src/Estimators/TraceManagerNew.h new file mode 100644 index 0000000000..f2d328ac83 --- /dev/null +++ b/src/Estimators/TraceManagerNew.h @@ -0,0 +1,2076 @@ +////////////////////////////////////////////////////////////////////////////////////// +// This file is distributed under the University of Illinois/NCSA Open Source License. +// See LICENSE file in top directory for details. +// +// Copyright (c) 2024 QMCPACK developers. +// +// File developed by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory +// +// File created by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory +////////////////////////////////////////////////////////////////////////////////////// + + +#ifndef QMCPLUSPLUS_TRACEMANAGERNEW_H +#define QMCPLUSPLUS_TRACEMANAGERNEW_H + + +#if !defined(DISABLE_TRACEMANAGER) + + +#include +#include "OhmmsData/OhmmsElementBase.h" +#include "OhmmsData/AttributeSet.h" +#include "OhmmsPETE/OhmmsArray.h" +#include "Particle/ParticleSet.h" +#include "Utilities/IteratorUtility.h" +#include "ModernStringUtils.hpp" +#include "Message/Communicate.h" +#include "hdf/hdf_archive.h" +#include "Concurrency/OpenMP.h" + +#include +#include +#include +#include +#include + +namespace qmcplusplus +{ +//#define TRACE_CHECK + +const unsigned int DMAXNEW = 4; +using TraceIntNew = long; +using TraceRealNew = OHMMS_PRECISION; +using TraceCompNew = std::complex; + + +struct TraceQuantityNew +{ + std::string name; + bool default_quantity; + bool combined_quantity; + bool scalar_available; + bool array_available; + bool scalar_stream_requested; + bool array_stream_requested; + bool scalar_write_requested; + bool array_write_requested; + bool stream_scalar; + bool stream_array; + bool write_scalar; + bool write_array; + + inline TraceQuantityNew() + { + default_quantity = false; + combined_quantity = false; + scalar_available = false; + array_available = false; + scalar_stream_requested = false; + array_stream_requested = false; + scalar_write_requested = false; + array_write_requested = false; + stream_scalar = false; + stream_array = false; + write_scalar = false; + write_array = false; + } + + inline void incorporate(const TraceQuantityNew& other) + { + if (name != other.name) + { + APP_ABORT("TraceQuantityNew::incorporate\n cannot merge quantities with differing names\n names: " + name + " " + + other.name); + } + default_quantity |= other.default_quantity; + combined_quantity |= other.combined_quantity; + scalar_available |= other.scalar_available; + array_available |= other.array_available; + scalar_stream_requested |= other.scalar_stream_requested; + array_stream_requested |= other.array_stream_requested; + } +}; + + +//means of control of traces +// which quantities are available, streaming, writing, etc +// handles global (user + all observable) trace request +//medium of exchange of trace information between trace manager and observables +// handles individual trace requests from observables +struct TraceRequestNew +{ + //switch to allow or disallow streams/writes of requested quantities + bool allow_streams; + bool allow_writes; + + //switch to allow or disallow scalar/array streaming/writing + bool scalars_on; + bool arrays_on; + + //all scalar/array quantities should be provided for streaming + bool stream_all_scalars; + bool stream_all_arrays; + + //all scalar/array quantities should be provided for writing + bool write_all_scalars; + bool write_all_arrays; + + //records whether default scalars/arrays should stream/write + bool streaming_default_scalars; + bool streaming_default_arrays; + bool writing_default_scalars; + bool writing_default_arrays; + + + //quantities made available or requested for streaming or writing + std::map quantities; + + //dependency lists for combined quantities + std::map> combined_dependencies; + + //used to screen checked out quantities for writing + std::string scalar_domain; + + inline TraceRequestNew() { reset(); } + + inline void reset() + { + allow_streams = false; + allow_writes = false; + scalars_on = false; + arrays_on = false; + stream_all_scalars = false; + stream_all_arrays = false; + write_all_scalars = false; + write_all_arrays = false; + streaming_default_scalars = false; + streaming_default_arrays = false; + writing_default_scalars = false; + writing_default_arrays = false; + + quantities.clear(); + combined_dependencies.clear(); + } + + inline void set_scalar_domain(const std::string& domain) { scalar_domain = domain; } + + inline bool screen_sample(const std::string& domain, const std::string& name, bool& write) + { + bool scalar = domain == scalar_domain; + bool present = quantities.find(name) != quantities.end(); + bool stream = false; + write = false; + if (present) + { + TraceQuantityNew& q = quantities[name]; + if (scalar) + { + stream = q.stream_scalar; + write = q.write_scalar; + } + else + { + stream = q.stream_array; + write = q.write_array; + } + } + app_log()<<"JTK: TraceRequestNew::screen_sample "<& deps, + bool scalar = false, + bool array = false, + bool default_quantity = false) + { + app_log()<<"JTK: TraceRequestNew::contribute_combined (op)"<& names, bool write = false) + { + app_log()<<"JTK: TraceRequestNew::request_scalar (tm)"<::iterator name; + for (name = names.begin(); name != names.end(); ++name) + request_scalar(*name, write); + } + + //declare that array quantities are desired for streaming + inline void request_array(const std::set& names, bool write = false) + { + app_log()<<"JTK: TraceRequestNew::request_array (tm)"<::iterator name; + for (name = names.begin(); name != names.end(); ++name) + request_array(*name, write); + } + + //merge in all quantities from a contributor request + inline void incorporate(TraceRequestNew& other) + { + std::map::iterator it; + for (it = other.quantities.begin(); it != other.quantities.end(); ++it) + { + const TraceQuantityNew& q = it->second; + if (quantity_present(q.name)) + quantities[q.name].incorporate(q); + else + quantities[q.name] = q; + } + std::map>::iterator d; + for (d = other.combined_dependencies.begin(); d != other.combined_dependencies.end(); ++d) + { + const std::string& name = d->first; + std::set& deps = d->second; + if (combined_dependencies.find(name) != combined_dependencies.end()) + combined_dependencies[name].insert(deps.begin(), deps.end()); + else + combined_dependencies[name] = deps; + } + } + + //balance requests with availability and turn streaming/writing on/off + inline void determine_stream_write() + { + std::map::iterator it; + for (it = quantities.begin(); it != quantities.end(); ++it) + { + TraceQuantityNew& q = it->second; + + q.stream_scalar = + allow_streams && scalars_on && q.scalar_available && (q.scalar_stream_requested || stream_all_scalars); + + q.write_scalar = q.stream_scalar && (q.scalar_write_requested || write_all_scalars); + + q.stream_array = + allow_streams && arrays_on && q.array_available && (q.array_stream_requested || stream_all_arrays); + + q.write_array = q.stream_array && (q.array_write_requested || write_all_arrays); + } + // default quantities stream and write if any others do + streaming_default_scalars = false; + writing_default_scalars = false; + streaming_default_arrays = false; + writing_default_arrays = false; + for (it = quantities.begin(); it != quantities.end(); ++it) + { + TraceQuantityNew& q = it->second; + streaming_default_scalars |= q.stream_scalar; + writing_default_scalars |= q.write_scalar; + streaming_default_arrays |= q.stream_array; + writing_default_arrays |= q.write_array; + } + for (it = quantities.begin(); it != quantities.end(); ++it) + { + TraceQuantityNew& q = it->second; + if (q.default_quantity) + { + q.stream_scalar = streaming_default_scalars; + q.write_scalar = writing_default_scalars; + q.stream_array = streaming_default_arrays; + q.write_array = writing_default_arrays; + } + } + // if any combined quantities are streaming, their dependencies must also + for (it = quantities.begin(); it != quantities.end(); ++it) + { + TraceQuantityNew& q = it->second; + if (q.combined_quantity) + { + std::set& deps = combined_dependencies[q.name]; + std::set::iterator name; + if (q.stream_scalar || q.stream_array) + { + for (name = deps.begin(); name != deps.end(); ++name) + { + check_presence(*name); + TraceQuantityNew& qd = quantities[*name]; + qd.stream_scalar |= (qd.scalar_available && q.stream_scalar); + qd.stream_array |= (qd.array_available && q.stream_array); + } + } + } + } + combined_dependencies.clear(); + } + + //relay updated streaming information to contributor + inline void relay_stream_info(TraceRequestNew& other) + { + other.allow_streams = allow_streams; + other.allow_writes = allow_writes; + other.scalars_on = scalars_on; + other.arrays_on = arrays_on; + other.stream_all_scalars = stream_all_scalars; + other.stream_all_arrays = stream_all_arrays; + other.write_all_scalars = write_all_scalars; + other.write_all_arrays = write_all_arrays; + other.streaming_default_scalars = streaming_default_scalars; + other.streaming_default_arrays = streaming_default_arrays; + other.writing_default_scalars = writing_default_scalars; + other.writing_default_arrays = writing_default_arrays; + std::map::iterator it; + for (it = other.quantities.begin(); it != other.quantities.end(); ++it) + { + TraceQuantityNew& q = it->second; + check_presence(q.name); + q = quantities[q.name]; + } + other.combined_dependencies.clear(); + } + + inline void report() + { + //app_log()<<"\n TraceRequestNew"<< std::endl; + app_log() << " allow_streams = " << allow_streams << std::endl; + app_log() << " allow_writes = " << allow_writes << std::endl; + app_log() << " scalars_on = " << scalars_on << std::endl; + app_log() << " arrays_on = " << arrays_on << std::endl; + app_log() << " stream_all_scalars = " << stream_all_scalars << std::endl; + app_log() << " stream_all_arrays = " << stream_all_arrays << std::endl; + app_log() << " write_all_scalars = " << write_all_scalars << std::endl; + app_log() << " write_all_arrays = " << write_all_arrays << std::endl; + app_log() << " streaming_default_scalars = " << streaming_default_scalars << std::endl; + app_log() << " streaming_default_arrays = " << streaming_default_arrays << std::endl; + app_log() << " writing_default_scalars = " << writing_default_scalars << std::endl; + app_log() << " writing_default_arrays = " << writing_default_arrays << std::endl; + + write_selected("scalars available", "scalar_available"); + write_selected("arrays available", "array_available"); + + write_selected("scalar streams requested", "scalar_stream_requested"); + write_selected("array streams requested", "array_stream_requested"); + + write_selected("scalar writes requested", "scalar_write_requested"); + write_selected("array writes requested", "array_write_requested"); + + write_selected("scalar streams occurring", "stream_scalar"); + write_selected("array streams occurring", "stream_array"); + + write_selected("scalar writes occurring", "write_scalar"); + write_selected("array writes occurring", "write_array"); + } + + inline void write_selected(const std::string& header, const std::string& selector) + { + app_log() << " " << header << ":"; + int n = 0; + std::map::iterator it; + for (it = quantities.begin(); it != quantities.end(); ++it) + { + TraceQuantityNew& q = it->second; + bool selected = false; + if (selector == "scalar_available") + selected = q.scalar_available; + else if (selector == "array_available") + selected = q.array_available; + else if (selector == "scalar_stream_requested") + selected = q.scalar_stream_requested; + else if (selector == "array_stream_requested") + selected = q.array_stream_requested; + else if (selector == "scalar_write_requested") + selected = q.scalar_write_requested; + else if (selector == "array_write_requested") + selected = q.array_write_requested; + else if (selector == "stream_scalar") + selected = q.stream_scalar; + else if (selector == "stream_array") + selected = q.stream_array; + else if (selector == "write_scalar") + selected = q.write_scalar; + else if (selector == "write_array") + selected = q.write_array; + else + APP_ABORT("TraceRequestNew::write_selected unrecognized selector: " + selector); + if (selected) + { + if (n % 5 == 0) + app_log() << std::endl << " "; + n++; + app_log() << " " << q.name; + } + } + app_log() << std::endl; + } + + + //private (internal) API + //query whether a quantity is present + inline bool quantity_present(const std::string& name) { return quantities.find(name) != quantities.end(); } + + //create a quantity if it is not present + inline void guarantee_presence(const std::string& name, bool combined = false) + { + if (!quantity_present(name)) + { + TraceQuantityNew q; + q.name = name; + quantities[name] = q; + } + if (combined) + if (combined_dependencies.find(name) == combined_dependencies.end()) + { + std::set stmp; + combined_dependencies[name] = stmp; + } + } + + //abort if a quantity is not present + inline void check_presence(const std::string& name) + { + if (!quantity_present(name)) + { + APP_ABORT("TraceRequestNew::check_presence quantity " + name + " is not present"); + } + } + + //query whether any quantities are streaming + inline bool streaming() { return streaming_default_scalars || streaming_default_arrays; } + + //query whether any quantities are writing + inline bool writing() { return writing_default_scalars || writing_default_arrays; } + + //query whether any scalar quantities are streaming + inline bool streaming_scalars() { return streaming_default_scalars; } + + //query whether any array quantities are streaming + inline bool streaming_arrays() { return streaming_default_arrays; } +}; + + +template +struct TraceSampleNew +{ + std::string domain; + std::string name; + int index; + bool array_trace; + int dimension; + int size; + int unit_size; + int data_size; + TinyVector shape; + Vector& sample; + bool write; + int buffer_start, buffer_end; + std::map meta_int; + std::map meta_real; + std::map meta_string; + bool verbose; + + inline TraceSampleNew(const std::string& sdomain, const std::string& sname, int sindex, int sdim, Vector& ssample) + : sample(ssample), verbose(false) + { + initialize(sdomain, sname, sindex, sdim); + } + + + inline TraceSampleNew(const std::string& sdomain, + const std::string& sname, + int sindex, + int sdim, + TinyVector sshape, + Vector& ssample) + : sample(ssample), verbose(false) + { + initialize(sdomain, sname, sindex, sdim); + shape = sshape; + size = sample.size(); + check_shape(); + } + + inline virtual ~TraceSampleNew() = default; + + inline void initialize(const std::string& sdomain, const std::string& sname, int sindex, int sdim) + { + domain = sdomain, name = sname; + dimension = sdim; + index = sindex; + array_trace = false; + write = false; + buffer_start = -1; + buffer_end = -1; + } + + + inline void set_unit_size(int usize) { unit_size = usize; } + + + inline void set_data_size() { data_size = size * unit_size; } + + + inline void check_shape() + { + bool correct_shape = true; + bool correct_dimension = dimension <= DMAXNEW; + if (correct_dimension) + { + int tsize = 1; + for (int d = 0; d < dimension; ++d) + { + tsize *= shape[d]; + correct_dimension = correct_dimension && shape[d] > 0; + } + correct_shape = tsize == size; + } + if (!correct_dimension) + APP_ABORT("TraceSampleNew::check_shape dimension of sample array is incorrect"); + if (!correct_shape) + APP_ABORT("TraceSampleNew::check_shape shape and size of sample array do not match"); + } + + + inline bool same_shape(TraceSampleNew* other) + { + bool same = dimension == other->dimension && size == other->size; + if (same) + for (int d = 0; d < dimension; ++d) + same = same && shape[d] == other->shape[d]; + return same; + } + + virtual bool is_combined() { return false; } + + inline void set_buffer_range(int& bstart) + { + set_data_size(); + if (write) + { + buffer_start = bstart; + buffer_end = bstart + data_size; + bstart = buffer_end; + } + } + + + inline T sum() + { + T s(0); + for (int i = 0; i < sample.size(); ++i) + s += sample[i]; + return s; + } + + inline void write_summary(int ind = -1, std::string pad = " ") + { + std::string pad2 = pad + " "; + if (ind == -1) + app_log() << pad << " TraceSampleNew " << name << std::endl; + else + app_log() << pad << ind << " TraceSampleNew " << name << std::endl; + app_log() << pad2 << "domain = " << domain << std::endl; + app_log() << pad2 << "name = " << name << std::endl; + app_log() << pad2 << "index = " << index << std::endl; + app_log() << pad2 << "array_trace = " << array_trace << std::endl; + app_log() << pad2 << "dimension = " << dimension << std::endl; + app_log() << pad2 << "size = " << size << std::endl; + app_log() << pad2 << "unit_size = " << unit_size << std::endl; + app_log() << pad2 << "data_size = " << data_size << std::endl; + app_log() << pad2 << "shape = " << shape << std::endl; + app_log() << pad2 << "write = " << write << std::endl; + app_log() << pad2 << "buffer range = [" << buffer_start << "," << buffer_end << ")" << std::endl; + } +}; + + +template +struct CombinedTraceSampleNew : public TraceSampleNew +{ + bool combined; + std::vector weights; + std::vector*> components; + + + inline CombinedTraceSampleNew(const std::string& sdomain, + const std::string& sname, + int sindex, + int sdim, + Vector& ssample) + : TraceSampleNew(sdomain, sname, sindex, sdim, ssample) + { + reset(); + } + + + inline CombinedTraceSampleNew(const std::string& sdomain, + const std::string& sname, + int sindex, + int sdim, + TinyVector sshape, + Vector& ssample) + : TraceSampleNew(sdomain, sname, sindex, sdim, sshape, ssample) + { + reset(); + } + + bool is_combined() override { return true; } + + inline void reset() { combined = false; } + + + inline void add_component(TraceSampleNew* component, TraceRealNew weight) + { + if (components.size() == 0) + { + this->dimension = component->dimension; + this->size = component->size; + this->shape = component->shape; + this->data_size = component->data_size; + this->array_trace = component->array_trace; + this->sample.resize(component->size); + } + else if (!this->same_shape(component)) + { + APP_ABORT("CombinedTraceSampleNew::add_component attempted to add a different shape component\n my domain: " + + this->domain + "\n my name: " + this->name + "\n component domain: " + component->domain + + "\n component name: " + component->name); + } + else if (this->domain != component->domain) + APP_ABORT("CombinedTraceSampleNew::add_component attempted to add a different domain component\n my domain: " + + this->domain + "\n my name: " + this->name + "\n component domain: " + component->domain + + "\n component name: " + component->name); + weights.push_back(weight); + components.push_back(component); + } + + + inline void combine() + { + std::fill(this->sample.begin(), this->sample.end(), T(0)); + for (int i = 0; i < components.size(); ++i) + { + T weight = weights[i]; + auto& component = components[i]->sample; + for (int j = 0; j < this->sample.size(); ++j) + this->sample[j] += weight * component[j]; + } + combined = true; + } + + + inline void write_summary_combined(int ind, std::string pad = " ") + { + std::string pad2 = pad + " "; + std::string pad3 = pad2 + " "; + app_log() << pad << ind << " CombinedTraceSampleNew " << this->name << std::endl; + app_log() << pad2 << "domain = " << this->domain << std::endl; + app_log() << pad2 << "ncomponents = " << components.size() << std::endl; + app_log() << pad2 << "components" << std::endl; + for (int i = 0; i < components.size(); ++i) + { + TraceSampleNew& c = *components[i]; + app_log() << pad3 << c.name << " " << c.index << " " << weights[i] << std::endl; + } + app_log() << pad2 << "end components" << std::endl; + app_log() << pad2 << "vector address = " << (size_t) & this->sample << std::endl; + } +}; + + +template +bool TraceSampleNew_comp(TraceSampleNew* left, TraceSampleNew* right) +{ + return left->data_size < right->data_size; +} + + +template +struct TraceSampleNews +{ + std::vector*> samples; + std::map> sample_indices; + std::vector*> ordered_samples; + std::vector*> combined_samples; + std::vector*> combined_sample_vectors; + bool verbose; + + inline TraceSampleNews() : verbose(false) {} + + inline ~TraceSampleNews() { finalize(); } + + + inline void set_verbose(bool v) { verbose = v; } + + + inline int size() { return samples.size(); } + + + inline void assign_sample_index(const std::string& domain, const std::string& name, int index, std::string label = "") + { + if (sample_indices.count(domain) > 0 && sample_indices[domain].count(name) > 0) + { + APP_ABORT("TraceSampleNews::checkout " + label + " variable " + name + " already exists in domain " + domain); + } + else + { + sample_indices[domain][name] = index; + } + } + + template + inline Array* checkout_array(const std::string& domain, const std::string& name, TinyVector shape) + { + int index = samples.size(); + assign_sample_index(domain, name, index, "array"); + std::array subshape; + for (int idim = 0; idim < D; idim++) + subshape[idim] = shape[idim]; + Array* a = new Array(subshape); + TraceSampleNew* s = new TraceSampleNew(domain, name, index, D, shape, a->storage()); + samples.push_back(s); + if (verbose) + app_log() << "TraceSampleNews::checkout_array " << domain << " " << name << " " << index << std::endl; + return a; + } + + + template + inline Array* checkout_array(const ParticleSet& P, const std::string& name, TinyVector shape) + { + const std::string& domain = P.parentName(); + int index = samples.size(); + assign_sample_index(domain, name, index, "array"); + std::array subshape; + for (int idim = 0; idim < D; idim++) + subshape[idim] = shape[idim]; + Array* a = new Array(subshape); + TraceSampleNew* s = new TraceSampleNew(domain, name, index, D, shape, a->storage()); + samples.push_back(s); + s->array_trace = true; + if (verbose) + app_log() << "TraceSampleNews::checkout_array " << domain << " " << name << " " << index << std::endl; + return a; + } + + + inline TraceSampleNew* get_trace(const std::string& domain, const std::string& name) + { + TraceSampleNew* ts = NULL; + for (int i = 0; i < samples.size(); ++i) + { + TraceSampleNew& tsc = *samples[i]; + if (tsc.domain == domain && tsc.name == name) + { + ts = &tsc; + break; + } + } + if (ts == NULL) + APP_ABORT("TraceSampleNews::get_trace failed to get trace for quantity " + name + " in domain " + domain); + return ts; + } + + + inline CombinedTraceSampleNew* get_combined_trace(const std::string& domain, const std::string& name) + { + CombinedTraceSampleNew* ts = NULL; + for (int i = 0; i < combined_samples.size(); ++i) + { + CombinedTraceSampleNew& tsc = *combined_samples[i]; + if (tsc.domain == domain && tsc.name == name) + { + ts = &tsc; + break; + } + } + return ts; + } + + + inline bool make_combined_trace(const std::string& name, + std::vector& names, + std::vector& weights) + { + bool created = false; + if (names.size() != weights.size()) + APP_ABORT("TraceSampleNews::make_combined_trace names and weights must be the same size"); + std::map>::iterator it; + for (it = sample_indices.begin(); it != sample_indices.end(); it++) + { + std::string domain = it->first; + std::map& indices = it->second; + bool any_present = false; + for (int i = 0; i < names.size(); ++i) + any_present = any_present || indices.count(names[i]) > 0; + if (any_present) + { + int index = samples.size(); + auto* sample = new Vector; + CombinedTraceSampleNew* combined = new CombinedTraceSampleNew(domain, name, index, 0, *sample); + for (int i = 0; i < names.size(); ++i) + { + if (indices.count(names[i]) > 0) + { + TraceSampleNew* component = samples[indices[names[i]]]; + combined->add_component(component, weights[i]); + } + } + assign_sample_index(domain, name, index); + samples.push_back(combined); + combined_samples.push_back(combined); + combined_sample_vectors.push_back(sample); + created = true; + } + } + return created; + } + + + inline void set_unit_size(int usize) + { + for (int i = 0; i < samples.size(); i++) + samples[i]->set_unit_size(usize); + } + + + inline void screen_writes(TraceRequestNew& request) + { + for (int i = 0; i < samples.size(); i++) + { + TraceSampleNew& s = *samples[i]; + bool stream = request.screen_sample(s.domain, s.name, s.write); + if (verbose) + app_log() << "TraceRequestNew screening " << s.name << " in domain " << s.domain << ". stream: " << stream + << " write: " << s.write << std::endl; + if (!stream && !s.is_combined()) + app_log() << "warning: quantity " + s.name + " in domain " + s.domain + + " was not requested but is streaming anyway" + << std::endl; + } + } + + + inline void order_by_size() + { + for (int i = 0; i < samples.size(); i++) + samples[i]->set_data_size(); + ordered_samples.resize(samples.size()); + copy(samples.begin(), samples.end(), ordered_samples.begin()); + sort(ordered_samples.begin(), ordered_samples.end(), TraceSampleNew_comp); + } + + + inline void set_buffer_ranges(int& starting_index) + { + for (int i = 0; i < ordered_samples.size(); i++) + { + TraceSampleNew& sample = *ordered_samples[i]; + sample.set_buffer_range(starting_index); + } + } + + + inline int total_size() + { + int s = 0; + for (int i = 0; i < samples.size(); i++) + s += samples[i]->sample.size() * samples[i]->unit_size; + return s; + } + + + inline int min_buffer_index() + { + int min_index = 2000000000; + for (int i = 0; i < samples.size(); i++) + min_index = std::min(min_index, samples[i]->buffer_start); + return min_index; + } + + + inline int max_buffer_index() + { + int max_index = -1; + for (int i = 0; i < samples.size(); i++) + max_index = std::max(max_index, samples[i]->buffer_end); + return max_index; + } + + + inline void combine_samples() + { + for (int i = 0; i < combined_samples.size(); ++i) + combined_samples[i]->combine(); + } + + + inline void reset_combined_samples() + { + for (int i = 0; i < combined_samples.size(); ++i) + combined_samples[i]->reset(); + } + + + inline void finalize() + { + //note combined_samples pointers are a subset of those in samples + // and so only samples needs to be deleted + delete_iter(samples.begin(), samples.end()); + delete_iter(combined_sample_vectors.begin(), combined_sample_vectors.end()); + samples.resize(0); + ordered_samples.resize(0); + combined_samples.resize(0); + combined_sample_vectors.resize(0); + sample_indices.clear(); + } + + + inline void register_hdf_data(hdf_archive& f) + { + std::map>::iterator it; + std::map::iterator it2; + for (it = sample_indices.begin(); it != sample_indices.end(); it++) + { + const std::string& domain = it->first; + std::map& indices = it->second; + f.push(domain); + for (it2 = indices.begin(); it2 != indices.end(); ++it2) + { + const std::string& quantity = it2->first; + TraceSampleNew& sample = *samples[it2->second]; + if (sample.write) + { + f.push(quantity); + f.write(sample.dimension, "dimension"); + f.write(sample.shape, "shape"); + f.write(sample.size, "size"); + f.write(sample.unit_size, "unit_size"); + f.write(sample.buffer_start, "row_start"); + f.write(sample.buffer_end, "row_end"); + f.pop(); + } + } + f.pop(); + } + } + + + inline void write_summary(std::string type, std::string pad = " ") + { + std::string pad2 = pad + " "; + std::string pad3 = pad2 + " "; + std::string pad4 = pad3 + " "; + app_log() << pad << "TraceSampleNews<" << type << ">" << std::endl; + app_log() << pad2 << "nsamples = " << samples.size() << std::endl; + app_log() << pad2 << "ncombined_samples = " << combined_samples.size() << std::endl; + app_log() << pad2 << "sample_indices" << std::endl; + std::map>::iterator it; + std::map::iterator it2; + for (it = sample_indices.begin(); it != sample_indices.end(); it++) + { + const std::string& domain = it->first; + std::map& indices = it->second; + app_log() << pad3 << domain << std::endl; + for (it2 = indices.begin(); it2 != indices.end(); ++it2) + app_log() << pad4 << it2->first << " = " << it2->second << std::endl; + } + app_log() << pad2 << "end sample_indices" << std::endl; + app_log() << pad2 << "combined_sample_vectors = "; + for (int i = 0; i < combined_sample_vectors.size(); ++i) + app_log() << (size_t)combined_sample_vectors[i] << " "; + app_log() << std::endl; + app_log() << pad2 << "combined_samples" << std::endl; + for (int i = 0; i < combined_samples.size(); ++i) + combined_samples[i]->write_summary_combined(i, pad3); + app_log() << pad2 << "end combined_samples" << std::endl; + app_log() << pad2 << "samples" << std::endl; + for (int i = 0; i < ordered_samples.size(); ++i) + ordered_samples[i]->write_summary(i, pad3); + //for(int i=0; iwrite_summary(i,pad3); + app_log() << pad2 << "end samples" << std::endl; + app_log() << pad << "end TraceSampleNews<" << type << ">" << std::endl; + } + + + inline void user_report(const std::string& type, const std::string& pad = " ") + { + std::string pad2 = pad + " "; + app_log() << pad << type << " traces provided by estimators" << std::endl; + std::map>::iterator it; + std::map::iterator it2; + for (it = sample_indices.begin(); it != sample_indices.end(); it++) + { + const std::string& domain = it->first; + std::map& indices = it->second; + app_log() << pad2 << "domain " << domain << ": "; + int n = 0; + for (it2 = indices.begin(); it2 != indices.end(); ++it2) + { + if (n % 5 == 0) + app_log() << std::endl << pad2 << " "; + n++; + const std::string& quantity = it2->first; + app_log() << quantity << " "; + } + app_log() << std::endl; + } + } +}; + + +template +struct TraceBufferNew +{ + bool has_complex; + TraceSampleNews* samples; + TraceSampleNews>* complex_samples; + std::string type; + Array buffer; + bool verbose; + + //hdf variables + std::string top; + hsize_t dims[2]; + hsize_t hdf_file_pointer; + + + TraceBufferNew() : samples(0), complex_samples(0), verbose(false) + { + type = "?"; + has_complex = false; + reset(); + } + + + inline void set_verbose(bool v) { verbose = v; } + + + inline void set_type(std::string stype) + { + type = stype; + top = type + "_data"; + } + + + inline void reset() { buffer.resize(0, buffer.size(1)); } + + + inline void set_samples(TraceSampleNews& s) { samples = &s; } + + + inline void set_samples(TraceSampleNews>& s) + { + complex_samples = &s; + has_complex = true; + } + + + inline void make_combined_trace(const std::string& name, + std::vector& names, + std::vector& weights) + { + bool created_real = samples->make_combined_trace(name, names, weights); + if (has_complex) + { + bool created_complex = complex_samples->make_combined_trace(name, names, weights); + if (created_real && created_complex) + APP_ABORT("TraceBufferNew<" + type + + ">::make_combined_trace\n cannot create real and complex combined traces for the same quantity\n " + "attempted for quantity " + + name); + } + } + + + inline void order_and_resize() + { + //put the sample data in size order + samples->set_unit_size(1); + samples->order_by_size(); + if (has_complex) + { + complex_samples->set_unit_size(2); + complex_samples->order_by_size(); + } + //assign buffer ranges to each sample + int sample_size = 0; + samples->set_buffer_ranges(sample_size); + if (has_complex) + complex_samples->set_buffer_ranges(sample_size); +#if defined(TRACE_CHECK) + test_buffer_write(sample_size); +#endif + //resize the buffer + int nsamples_init = 1; + buffer.resize(nsamples_init, sample_size); + } + + + inline bool same_as(TraceBufferNew& ref) { return buffer.size(1) == ref.buffer.size(1); } + + + inline void collect_sample() + { + if (verbose) + app_log() << " TraceBufferNew<" << type << ">::collect_sample()" << std::endl; + //make more room, if necessary + int nrows = buffer.size(0); + int row_size = buffer.size(1); + if (row_size > 0) + { + //make space for the row, if necessary + int current_row = nrows; + nrows++; + // resizing buffer(type Array) doesn't preserve data. Thus keep old data and copy over + auto buffer_old(buffer); + buffer.resize(nrows, row_size); + std::copy_n(buffer_old.data(), buffer_old.size(), buffer.data()); + if (verbose) + app_log() << " increasing # of rows to " << nrows << std::endl; + //combine samples + samples->combine_samples(); + if (has_complex) + complex_samples->combine_samples(); + //collect data from all samples into the buffer row + { + std::vector*>& ordered_samples = samples->ordered_samples; + for (int s = 0; s < ordered_samples.size(); s++) + { + TraceSampleNew& tsample = *ordered_samples[s]; + if (tsample.write) + { + auto& sample = tsample.sample; + for (int i = 0; i < sample.size(); ++i) + buffer(current_row, tsample.buffer_start + i) = sample[i]; + } + } + } + if (has_complex) + { + std::vector>*>& ordered_samples = complex_samples->ordered_samples; + for (int s = 0; s < ordered_samples.size(); s++) + { + TraceSampleNew>& tsample = *ordered_samples[s]; + if (tsample.write) + { + auto& sample = tsample.sample; + for (int i = 0, ib = 0; i < sample.size(); ++i, ib += 2) + { + buffer(current_row, tsample.buffer_start + ib) = sample[i].real(); + buffer(current_row, tsample.buffer_start + ib + 1) = sample[i].imag(); + } + } + } + } + //reset combined samples so they can be recombined on the next step + samples->reset_combined_samples(); + if (has_complex) + complex_samples->reset_combined_samples(); +#if defined(TRACE_CHECK) + test_buffer_collect(current_row); +#endif + } + } + + + inline void write() { APP_ABORT("TraceBufferNew::write has not yet been implemented"); } + + + inline void write_summary(std::string pad = " ") + { + std::string pad2 = pad + " "; + app_log() << pad << "TraceBufferNew<" << type << ">" << std::endl; + app_log() << pad2 << "nrows = " << buffer.size(0) << std::endl; + app_log() << pad2 << "row_size = " << buffer.size(1) << std::endl; + app_log() << pad2 << "has_complex = " << has_complex << std::endl; + samples->write_summary(type, pad2); + if (has_complex) + complex_samples->write_summary("complex " + type, pad2); + app_log() << pad << "end TraceBufferNew<" << type << ">" << std::endl; + } + + + inline void user_report(const std::string& pad = " ") + { + samples->user_report(type, pad); + if (has_complex) + complex_samples->user_report("complex " + type, pad); + } + + inline void register_hdf_data(hdf_archive& f) + { + f.push(top); + f.push("layout"); + samples->register_hdf_data(f); + if (has_complex) + complex_samples->register_hdf_data(f); + f.pop(); + f.pop(); + if (!f.open_groups()) + APP_ABORT("TraceBufferNew<" + type + + ">::register_hdf_data() some hdf groups are still open at the end of registration"); + hdf_file_pointer = 0; + } + + + inline void write_hdf(hdf_archive& f) { write_hdf(f, hdf_file_pointer); } + + + inline void write_hdf(hdf_archive& f, hsize_t& file_pointer) + { + if (verbose) + app_log() << "TraceBufferNew<" << type << ">::write_hdf() " << file_pointer << " " << buffer.size(0) << " " + << buffer.size(1) << std::endl; + dims[0] = buffer.size(0); + dims[1] = buffer.size(1); + if (dims[0] > 0) + { + f.push(top); + h5d_append(f.top(), "traces", file_pointer, buffer.dim(), dims, buffer.data()); + f.pop(); + } + f.flush(); + } + + + inline void test_buffer_write(int sample_size) + { + //check that the size is correct + int ssize = samples->total_size(); + if (has_complex) + ssize += complex_samples->total_size(); + if (sample_size != ssize) + { + app_log() << "sample_size = " << sample_size << "\ntotal_size = " << ssize << std::endl; + APP_ABORT("TraceBufferNew::test_buffer_write sample_size and total_size do not match"); + } + //check that buffer indices fall in the expected range + int nsamples = samples->size(); + int min_index = samples->min_buffer_index(); + int max_index = samples->max_buffer_index(); + if (has_complex) + { + nsamples += complex_samples->size(); + min_index = std::min(min_index, complex_samples->min_buffer_index()); + max_index = std::max(max_index, complex_samples->max_buffer_index()); + } + if (nsamples > 0) + { + if (min_index != 0) + APP_ABORT("TraceBufferNew::test_buffer_write min_index!=0\n min_index=" << min_index); + if (max_index != sample_size) + APP_ABORT("TraceBufferNew::test_buffer_write max_index!=sample_size"); + //check that no overlap exists in writes to buffer + Array test_buffer; + test_buffer.resize(1, sample_size); + std::fill(test_buffer.begin(), test_buffer.end(), 0); + int row = 0; + int row_size = test_buffer.size(1); + int offset = row * row_size; + int* loc1 = &test_buffer(offset); + int* loc2 = &test_buffer(row, 0); + if (loc1 != loc2) + APP_ABORT("TraceBufferNew::test_buffer_write serialized buffer offset improperly computed"); + { + int boffset; + std::vector*>& ordered_samples = samples->ordered_samples; + for (int s = 0; s < ordered_samples.size(); s++) + { + TraceSampleNew& tsample = *ordered_samples[s]; + std::vector& sample = tsample.sample; + boffset = offset + tsample.buffer_start; + for (int i = 0; i < sample.size(); ++i) + test_buffer(boffset + i) = 1; + } + } + if (has_complex) + { + int boffset; + std::vector>*>& ordered_samples = complex_samples->ordered_samples; + for (int s = 0; s < ordered_samples.size(); s++) + { + TraceSampleNew>& tsample = *ordered_samples[s]; + std::vector>& sample = tsample.sample; + boffset = offset + tsample.buffer_start; + for (int i = 0, ib = 0; i < sample.size(); ++i, ib += tsample.unit_size) + { + test_buffer(boffset + ib) = 1; + test_buffer(boffset + ib + 1) = 1; + } + } + } + //app_log()<<"test_buffer:"<< std::endl; + //for(int i=0;i>::iterator dom; + std::map::iterator var; + std::map>& domains = samples->sample_indices; + std::vector*>& tsamples = samples->samples; + std::map& scalar_vars = domains[scalars]; + for (var = scalar_vars.begin(); var != scalar_vars.end(); var++) + { + const std::string& name = var->first; + TraceSampleNew& sample = *tsamples[var->second]; + T value = buffer(current_row, sample.buffer_start); + T svalue = 0; + bool any_present = false; + for (dom = domains.begin(); dom != domains.end(); dom++) + { + const std::string& domain = dom->first; + if (domain != scalars) + { + std::map& vars = dom->second; + if (vars.count(name) > 0) + { + any_present = true; + TraceSampleNew& ssample = *tsamples[vars[name]]; + int start = ssample.buffer_start; + int end = ssample.buffer_end; + for (int i = start; i < end; i++) + svalue += buffer(current_row, i); + } + } + } + if (any_present) + { + if (verbose) + app_log() << " " << name << " " << value << " " << svalue << std::endl; + } + } + } +}; + + +class TraceManagerNew +{ +private: + //collections of samples for a single walker step + // the associated arrays will be updated following evaluate + TraceSampleNews int_samples; + TraceSampleNews real_samples; + TraceSampleNews comp_samples; + + //buffers for storing samples + // single row of buffer is a single sample from one walker + // number of rows adjusts to accommodate walker samples + TraceBufferNew int_buffer; + TraceBufferNew real_buffer; + +public: + static double trace_tol; + + TraceRequestNew request; + + bool master_copy; + std::string default_domain; + bool method_allows_traces; + bool streaming_traces; + bool writing_traces; + int throttle; + bool verbose; + std::string format; + bool hdf_format; + std::string file_root; + Communicate* communicator; + std::unique_ptr hdf_file; + + TraceManagerNew(Communicate* comm = 0) : verbose(false) + { + reset_permissions(); + master_copy = true; + communicator = comm; + throttle = 1; + format = "hdf"; + default_domain = "scalars"; + request.set_scalar_domain(default_domain); + int_buffer.set_type("int"); + real_buffer.set_type("real"); + int_buffer.set_samples(int_samples); + real_buffer.set_samples(real_samples); + real_buffer.set_samples(comp_samples); + } + + + inline TraceManagerNew* makeClone() + { + app_log()<<"JTK: TraceManagernew::makeClone"<master_copy = false; + tm->transfer_state_from(*this); + tm->distribute(); + return tm; + } + + + inline void transfer_state_from(const TraceManagerNew& tm) + { + method_allows_traces = tm.method_allows_traces; + request = tm.request; + streaming_traces = tm.streaming_traces; + writing_traces = tm.writing_traces; + throttle = tm.throttle; + verbose = tm.verbose; + format = tm.format; + hdf_format = tm.hdf_format; + default_domain = tm.default_domain; + } + + + inline void distribute() + { + int_samples.set_verbose(verbose); + real_samples.set_verbose(verbose); + comp_samples.set_verbose(verbose); + int_buffer.set_verbose(verbose); + real_buffer.set_verbose(verbose); + } + + + inline void reset_permissions() + { + method_allows_traces = false; + streaming_traces = false; + writing_traces = false; + verbose = false; + hdf_format = false; + request.reset(); + } + + + inline void put(xmlNodePtr cur, bool allow_traces, std::string series_root) + { + app_log()<<"JTK: TraceManagerNew::put"< scalar_requests; + std::set array_requests; + xmlNodePtr element = cur->children; + while (element != NULL) + { + std::string name((const char*)element->name); + if (name == "scalar_traces") + { + std::string defaults = "no"; + OhmmsAttributeSet eattrib; + eattrib.add(defaults, "defaults"); + eattrib.put(element); + use_scalar_defaults = use_scalar_defaults && defaults == "yes"; + if (!use_scalar_defaults) + { + std::vector scalar_list; + putContent(scalar_list, element); + scalar_requests.insert(scalar_list.begin(), scalar_list.end()); + } + } + else if (name == "array_traces" || name == "particle_traces") + { + std::string defaults = "no"; + OhmmsAttributeSet eattrib; + eattrib.add(defaults, "defaults"); + eattrib.put(element); + use_array_defaults = use_array_defaults && defaults == "yes"; + if (!use_array_defaults) + { + std::vector array_list; + putContent(array_list, element); + array_requests.insert(array_list.begin(), array_list.end()); + } + } + else if (name != "text") + { + APP_ABORT("TraceManagerNew::put " + name + + " is not a valid sub-element of \n valid options are: scalar_traces, array_traces"); + } + element = element->next; + } + + writing_traces &= method_allows_traces; + + //input user quantity requests into the traces request + request.allow_streams = method_allows_traces; + request.allow_writes = writing_traces; + request.scalars_on = scalars_on; + request.arrays_on = arrays_on; + request.stream_all_scalars = use_scalar_defaults; + request.stream_all_arrays = use_array_defaults; + request.write_all_scalars = request.stream_all_scalars && writing_traces; + request.write_all_arrays = request.stream_all_arrays && writing_traces; + request.request_scalar(scalar_requests, writing_traces); + request.request_array(array_requests, writing_traces); + + //distribute verbosity level to buffer and sample objects + distribute(); + + } + + //streaming_traces = false; + //writing_traces = false; + } + + + inline void update_status() + { + streaming_traces = request.streaming(); + writing_traces = request.writing(); + } + + + inline void screen_writes() + { + int_samples.screen_writes(request); + real_samples.screen_writes(request); + comp_samples.screen_writes(request); + } + + inline void initialize_traces() + { + app_log()<<"JTK: TraceManagerNew::initialize_traces "< + inline Array* checkout_int(const std::string& name, int n1 = 1, int n2 = 0, int n3 = 0, int n4 = 0) + { + app_log()<<"JTK: TraceManagerNew::checkout_int"<(default_domain, name, n1, n2, n3, n4); + } + template + inline Array* checkout_int(const std::string& domain, + const std::string& name, + int n1 = 1, + int n2 = 0, + int n3 = 0, + int n4 = 0) + { + app_log()<<"JTK: TraceManagerNew::checkout_int"< shape(n1, n2, n3, n4); + return int_samples.checkout_array(domain, name, shape); + } + template + inline Array* checkout_int(const std::string& name, + const ParticleSet& P, + int n2 = 0, + int n3 = 0, + int n4 = 0) + { + app_log()<<"JTK: TraceManagerNew::checkout_int"< shape(P.getTotalNum(), n2, n3, n4); + return int_samples.checkout_array(P, name, shape); + } + + + // checkout real arrays + template + inline Array* checkout_real(const std::string& name, int n1 = 1, int n2 = 0, int n3 = 0, int n4 = 0) + { + app_log()<<"JTK: TraceManagerNew::checkout_real"<(default_domain, name, n1, n2, n3, n4); + } + template + inline Array* checkout_real(const std::string& domain, + const std::string& name, + int n1 = 1, + int n2 = 0, + int n3 = 0, + int n4 = 0) + { + app_log()<<"JTK: TraceManagerNew::checkout_real"< shape(n1, n2, n3, n4); + return real_samples.checkout_array(domain, name, shape); + } + template + inline Array* checkout_real(const std::string& name, + const ParticleSet& P, + int n2 = 0, + int n3 = 0, + int n4 = 0) + { + app_log()<<"JTK: TraceManagerNew::checkout_real"< shape(P.getTotalNum(), n2, n3, n4); + return real_samples.checkout_array(P, name, shape); + } + + + // checkout complex arrays + template + inline Array* checkout_complex(const std::string& name, int n1 = 1, int n2 = 0, int n3 = 0, int n4 = 0) + { + app_log()<<"JTK: TraceManagerNew::checkout_complex"<(default_domain, name, n1, n2, n3, n4); + } + template + inline Array* checkout_complex(const std::string& domain, + const std::string& name, + int n1 = 1, + int n2 = 0, + int n3 = 0, + int n4 = 0) + { + app_log()<<"JTK: TraceManagerNew::checkout_complex"< shape(n1, n2, n3, n4); + return comp_samples.checkout_array(domain, name, shape); + } + template + inline Array* checkout_complex(const std::string& name, + const ParticleSet& P, + int n2 = 0, + int n3 = 0, + int n4 = 0) + { + app_log()<<"JTK: TraceManagerNew::checkout_complex"< shape(P.getTotalNum(), n2, n3, n4); + return comp_samples.checkout_array(P, name, shape); + } + + + + //create combined trace out of existing traces + inline void make_combined_trace(const std::string& name, std::vector& names) + { + std::vector weights; + weights.resize(names.size()); + std::fill(weights.begin(), weights.end(), 1.0); + make_combined_trace(name, names, weights); + } + + inline void make_combined_trace(const std::string& name, + std::vector& names, + std::vector& weights) + { + if (streaming_traces) + { + if (verbose) + app_log() << "TraceManagerNew::make_combined_trace " << master_copy << " " << name << std::endl; + real_buffer.make_combined_trace(name, names, weights); + } + } + + + inline void check_clones(std::vector& clones) + { + app_log() << "JTK: TraceManagerNew::check_clones "< 0) + { + if (verbose) + app_log() << "TraceManagerNew::check_clones" << std::endl; + bool all_same = true; + bool int_same; + bool real_same; + TraceManagerNew& ref = *clones[0]; + for (int i = 0; i < clones.size(); ++i) + { + TraceManagerNew& tm = *clones[i]; + int_same = tm.int_buffer.same_as(ref.int_buffer); + real_same = tm.real_buffer.same_as(ref.real_buffer); + all_same = all_same && int_same && real_same; + } + if (!all_same) + { + for (int i = 0; i < clones.size(); ++i) + clones[i]->write_summary(); + APP_ABORT("TraceManagerNew::check_clones trace buffer widths of clones do not match\n contiguous write is " + "impossible\n this was first caused by clones contributing array traces from identical, but " + "differently named, particlesets such as e, e2, e3 ... (fixed)\n please check the TraceManagerNew " + "summaries printed above"); + } + } + } + + + inline void reset_buffers() + { + app_log() << "JTK: TraceManagerNew::reset_buffers"<& clones, int block) + { + app_log() << "JTK: TraceManagerNew::write_buffers "<< writing_traces<& clones) + { + app_log() << "JTK: TraceManagerNew::open_file "<< writing_traces<write_summary(); + if (hdf_format) + { + open_hdf_file(clones); + } + } + } + else + APP_ABORT("TraceManagerNew::open_file should not be called from non-master copy"); + } + + + inline void close_file() + { + app_log() << "JTK: TraceManagerNew::close_file "<< writing_traces<& clones) + { + app_log() << "JTK: TraceManagerNew::startRun " << master_copy << std::endl; + if (verbose) + app_log() << "TraceManagerNew::startRun " << master_copy << std::endl; + if (master_copy) + { + initialize_traces(); + check_clones(clones); + open_file(clones); + } + else + APP_ABORT("TraceManagerNew::startRun should not be called from non-master copy"); + } + + + inline void stopRun() + { + app_log() << "JTK: TraceManagerNew::stopRun " << master_copy << std::endl; + if (verbose) + app_log() << "TraceManagerNew::stopRun " << master_copy << std::endl; + if (master_copy) + { + close_file(); + finalize_traces(); + } + else + APP_ABORT("TraceManagerNew::stopRun should not be called from non-master copy"); + } + + + inline void startBlock(int nsteps) + { + app_log() << "JTK: TraceManagerNew::startBlock " << master_copy << std::endl; + if (verbose) + app_log() << "TraceManagerNew::startBlock " << master_copy << std::endl; + reset_buffers(); + } + + + inline void write_summary(std::string pad = " ") + { + std::string pad2 = pad + " "; + app_log() << std::endl; + app_log() << pad << "TraceManagerNew (detailed summary)" << std::endl; + app_log() << pad2 << "master_copy = " << master_copy << std::endl; + app_log() << pad2 << "method_allows_traces = " << method_allows_traces << std::endl; + app_log() << pad2 << "streaming_traces = " << streaming_traces << std::endl; + app_log() << pad2 << "writing_traces = " << writing_traces << std::endl; + app_log() << pad2 << "format = " << format << std::endl; + app_log() << pad2 << "hdf format = " << hdf_format << std::endl; + app_log() << pad2 << "default_domain = " << default_domain << std::endl; + int_buffer.write_summary(pad2); + real_buffer.write_summary(pad2); + app_log() << pad << "end TraceManagerNew" << std::endl; + } + + + inline void user_report(std::string pad = " ") + { + std::string pad2 = pad + " "; + std::string pad3 = pad2 + " "; + app_log() << std::endl; + app_log() << pad << "Traces report" << std::endl; + request.report(); + app_log() << pad2 << "Type and domain breakdown of streaming quantities:" << std::endl; + std::set::iterator req; + int_buffer.user_report(pad3); + real_buffer.user_report(pad3); + app_log() << std::endl; + //if(verbose) + // write_summary(pad); + } + + //hdf file operations + inline void open_hdf_file(std::vector& clones) + { + app_log() << "JTK: TraceManagerNew::open_hdf_file " << master_copy << std::endl; + if (clones.size() == 0) + APP_ABORT("TraceManagerNew::open_hdf_file no trace clones exist, cannot open file"); + int nprocs = communicator->size(); + int rank = communicator->rank(); + std::array ptoken; + std::string file_name = file_root; + if (nprocs > 1) + { + int length{0}; + if (nprocs > 10000) + length = std::snprintf(ptoken.data(), ptoken.size(), ".p%05d", rank); + else if (nprocs > 1000) + length = std::snprintf(ptoken.data(), ptoken.size(), ".p%04d", rank); + else + length = std::snprintf(ptoken.data(), ptoken.size(), ".p%03d", rank); + if (length < 0) + throw std::runtime_error("Error generating filename"); + file_name.append(ptoken.data(), length); + } + file_name += ".traces.h5"; + if (verbose) + app_log() << "TraceManagerNew::open_hdf_file opening traces hdf file " << file_name << std::endl; + hdf_file = std::make_unique(); + bool successful = hdf_file->create(file_name); + if (!successful) + APP_ABORT("TraceManagerNew::open_hdf_file failed to open hdf file " + file_name); + // only clones have active buffers and associated data + TraceManagerNew& tm = *clones[0]; + //tm.write_summary(); + tm.int_buffer.register_hdf_data(*hdf_file); + tm.real_buffer.register_hdf_data(*hdf_file); + } + + + inline void write_buffers_hdf(std::vector& clones) + { + app_log() << "JTK: TraceManagerNew::write_buffers_hdf " << master_copy << std::endl; + if (verbose) + app_log() << "TraceManagerNew::write_buffers_hdf " << master_copy << std::endl; + for (int ip = 0; ip < clones.size(); ++ip) + { + TraceManagerNew& tm = *clones[ip]; + tm.int_buffer.write_hdf(*hdf_file, int_buffer.hdf_file_pointer); + tm.real_buffer.write_hdf(*hdf_file, real_buffer.hdf_file_pointer); + } + } + + inline void close_hdf_file() { + app_log() << "JTK: TraceManagerNew::close_hdf_file " << master_copy << std::endl; + hdf_file.reset(); + } +}; + + +} // namespace qmcplusplus + + +#else + +// no vacuous class: new tracemanager always supported + +#endif + + +#endif diff --git a/src/QMCDrivers/QMCUpdateBase.cpp b/src/QMCDrivers/QMCUpdateBase.cpp index 0904e0b646..d12896418a 100644 --- a/src/QMCDrivers/QMCUpdateBase.cpp +++ b/src/QMCDrivers/QMCUpdateBase.cpp @@ -224,7 +224,6 @@ void QMCUpdateBase::stopBlock(bool collectall) Estimators->stopBlock(acceptRatio(), collectall); #if !defined(REMOVE_TRACEMANAGER) Traces->stopBlock(); - Traces_new->stopBlock(); #endif } diff --git a/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_scalars.in.xml b/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_scalars.in.xml new file mode 100644 index 0000000000..2b08a869a2 --- /dev/null +++ b/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_scalars.in.xml @@ -0,0 +1,103 @@ + + + + + + + + + + 3.37316115 3.37316115 0.00000000 + 0.00000000 3.37316115 3.37316115 + 3.37316115 0.00000000 3.37316115 + + + p p p + + 15 + + + + -1 + 1.0 + + + -1 + 1.0 + + + + + 4 + 4 + 6 + 21894.7135906 + + 0.00000000 0.00000000 0.00000000 + 1.68658058 1.68658058 1.68658058 + + + + + + + + + + + + + + + + +-0.2032153051 -0.1625595974 -0.143124599 -0.1216434956 -0.09919771951 -0.07111729038 +-0.04445345869 -0.02135082917 + + + + + + +0.2797730287 0.2172604155 0.1656172964 0.1216984261 0.083995349 0.05302065936 +0.02915953995 0.0122402581 + + + + +0.4631099906 0.356399124 0.2587895287 0.1829298509 0.1233653291 0.07714708174 +0.04145899033 0.01690645936 + + + + + + + + + + + + + + + + 2 + 2 + 4 + 2 + 1 + 0.3 + + + + From 8a885a1e77a9a4d50d24fbd73280a02cc6a32840 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Tue, 21 May 2024 04:06:19 -0400 Subject: [PATCH 03/55] remove combined trace use --- src/QMCHamiltonians/QMCHamiltonian.cpp | 89 -------------------------- 1 file changed, 89 deletions(-) diff --git a/src/QMCHamiltonians/QMCHamiltonian.cpp b/src/QMCHamiltonians/QMCHamiltonian.cpp index a4cfda87cc..fcf02f0f2d 100644 --- a/src/QMCHamiltonians/QMCHamiltonian.cpp +++ b/src/QMCHamiltonians/QMCHamiltonian.cpp @@ -554,38 +554,6 @@ void QMCHamiltonian::initialize_traces_new(TraceManagerNew& tm, ParticleSet& P) if (trace_log) app_log() << "\n Hamiltonian is initializing traces" << std::endl; - //fill std::string vectors for combined trace quantities - std::vector Eloc; - std::vector Vloc; - std::vector Vq, Vc, Vqq, Vqc, Vcc; - for (int i = 0; i < H.size(); ++i) - Eloc.push_back(H[i]->getName()); - for (int i = 1; i < H.size(); ++i) - Vloc.push_back(H[i]->getName()); - - // These contributions are based on the potential energy components. - // Loop starts at one to skip the kinetic energy component. - for (int i = 1; i < H.size(); ++i) - { - OperatorBase& h = *H[i]; - if (h.isQuantum()) - Vq.push_back(h.getName()); - else if (h.isClassical()) - Vc.push_back(h.getName()); - else if (h.isQuantumQuantum()) - Vqq.push_back(h.getName()); - else if (h.isQuantumClassical()) - Vqc.push_back(h.getName()); - else if (h.isClassicalClassical()) - Vcc.push_back(h.getName()); - else if (omp_get_thread_num() == 0) - app_log() << " warning: potential named " << h.getName() - << " has not been classified according to its quantum domain (q,c,qq,qc,cc)\n estimators depending " - "on this classification may not function properly" - << std::endl; - } - - //make trace quantities available request_new.contribute_scalar("id", true); //default trace quantity request_new.contribute_scalar("parent_id", true); //default trace quantity @@ -597,24 +565,6 @@ void QMCHamiltonian::initialize_traces_new(TraceManagerNew& tm, ParticleSet& P) request_new.contribute_array("position"); for (int i = 0; i < H.size(); ++i) H[i]->contributeTraceQuantitiesNew(); - //for (int i = 0; i < auxH.size(); ++i) - // auxH[i]->contributeTraceQuantitiesNew(); - - - //note availability of combined quantities - request_new.contribute_combined("LocalEnergy", Eloc, true); - request_new.contribute_combined("LocalPotential", Vloc, true, true); - if (Vq.size() > 0) - request_new.contribute_combined("Vq", Vq, true, true); - if (Vc.size() > 0) - request_new.contribute_combined("Vc", Vc, true, true); - if (Vqq.size() > 0) - request_new.contribute_combined("Vqq", Vqq, true, true); - if (Vqc.size() > 0) - request_new.contribute_combined("Vqc", Vqc, true, true); - if (Vcc.size() > 0) - request_new.contribute_combined("Vcc", Vcc, true, true); - ////collect trace requests std::vector requests; @@ -623,10 +573,6 @@ void QMCHamiltonian::initialize_traces_new(TraceManagerNew& tm, ParticleSet& P) //// requests from Hamiltonian components for (int i = 0; i < H.size(); ++i) requests.push_back(&H[i]->getRequestNew()); - //// requests from other observables - //for (int i = 0; i < auxH.size(); ++i) - // requests.push_back(&auxH[i]->getRequest()); - // //collect trace quantity availability/requests from contributors/requestors for (int i = 0; i < requests.size(); ++i) tm.request.incorporate(*requests[i]); @@ -681,44 +627,11 @@ void QMCHamiltonian::initialize_traces_new(TraceManagerNew& tm, ParticleSet& P) app_log() << " OperatorBase::checkoutTraceQuantitiesNew " << H[i]->getName() << std::endl; H[i]->checkoutTraceQuantitiesNew(tm); } - //for (int i = 0; i < auxH.size(); ++i) - //{ - // if (trace_log) - // app_log() << " OperatorBase::checkoutTraceQuantities " << auxH[i]->getName() << std::endl; - // auxH[i]->checkoutTraceQuantities(tm); - //} - //setup combined traces that depend on H information - // LocalEnergy, LocalPotential, Vq, Vc, Vqq, Vqc, Vcc - if (Vloc.size() > 0 && request.streaming("LocalPotential")) - tm.make_combined_trace("LocalPotential", Vloc); - if (Eloc.size() > 0 && request.streaming("LocalEnergy")) - tm.make_combined_trace("LocalEnergy", Eloc); - if (Vq.size() > 0 && request.streaming("Vq")) - tm.make_combined_trace("Vq", Eloc); - if (Vc.size() > 0 && request.streaming("Vc")) - tm.make_combined_trace("Vc", Eloc); - if (Vqq.size() > 0 && request.streaming("Vqq")) - tm.make_combined_trace("Vqq", Eloc); - if (Vqc.size() > 0 && request.streaming("Vqc")) - tm.make_combined_trace("Vqc", Eloc); - if (Vcc.size() > 0 && request.streaming("Vcc")) - tm.make_combined_trace("Vcc", Eloc); //all trace samples have been created ( streaming instances) // mark the ones that will be writing also tm.screen_writes(); - ////observables that depend on traces check them out - //if (trace_log) - // app_log() << "\n Hamiltonian is fulfilling trace requests from observables" << std::endl; - //for (int i = 0; i < auxH.size(); ++i) - //{ - // if (trace_log) - // app_log() << " OperatorBase::getRequiredTraces " << auxH[i]->getName() << std::endl; - // auxH[i]->getRequiredTraces(tm); - //} - //report - //write traces status to the log if (trace_log) tm.user_report(); @@ -765,8 +678,6 @@ void QMCHamiltonian::finalize_traces_new() { for (int i = 0; i < H.size(); ++i) H[i]->deleteTraceQuantitiesNew(); - //for (int i = 0; i < auxH.size(); ++i) - // auxH[i]->deleteTraceQuantities(); } streaming_position_new = false; request_new.reset(); From ca70bc8ffa1b4166c44b1d2d1316d6500d527542 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Tue, 21 May 2024 04:24:30 -0400 Subject: [PATCH 04/55] remove combined traces entirely --- src/Estimators/TraceManagerNew.h | 294 +------------------------------ 1 file changed, 1 insertion(+), 293 deletions(-) diff --git a/src/Estimators/TraceManagerNew.h b/src/Estimators/TraceManagerNew.h index f2d328ac83..7d5880607a 100644 --- a/src/Estimators/TraceManagerNew.h +++ b/src/Estimators/TraceManagerNew.h @@ -48,7 +48,6 @@ struct TraceQuantityNew { std::string name; bool default_quantity; - bool combined_quantity; bool scalar_available; bool array_available; bool scalar_stream_requested; @@ -63,7 +62,6 @@ struct TraceQuantityNew inline TraceQuantityNew() { default_quantity = false; - combined_quantity = false; scalar_available = false; array_available = false; scalar_stream_requested = false; @@ -84,7 +82,6 @@ struct TraceQuantityNew other.name); } default_quantity |= other.default_quantity; - combined_quantity |= other.combined_quantity; scalar_available |= other.scalar_available; array_available |= other.array_available; scalar_stream_requested |= other.scalar_stream_requested; @@ -126,9 +123,6 @@ struct TraceRequestNew //quantities made available or requested for streaming or writing std::map quantities; - //dependency lists for combined quantities - std::map> combined_dependencies; - //used to screen checked out quantities for writing std::string scalar_domain; @@ -150,7 +144,6 @@ struct TraceRequestNew writing_default_arrays = false; quantities.clear(); - combined_dependencies.clear(); } inline void set_scalar_domain(const std::string& domain) { scalar_domain = domain; } @@ -200,24 +193,6 @@ struct TraceRequestNew quantities[name].default_quantity = true; } - //declare that a combined quantity could be made available - inline void contribute_combined(const std::string& name, - std::vector& deps, - bool scalar = false, - bool array = false, - bool default_quantity = false) - { - app_log()<<"JTK: TraceRequestNew::contribute_combined (op)"<>::iterator d; - for (d = other.combined_dependencies.begin(); d != other.combined_dependencies.end(); ++d) - { - const std::string& name = d->first; - std::set& deps = d->second; - if (combined_dependencies.find(name) != combined_dependencies.end()) - combined_dependencies[name].insert(deps.begin(), deps.end()); - else - combined_dependencies[name] = deps; - } } //balance requests with availability and turn streaming/writing on/off @@ -346,27 +311,6 @@ struct TraceRequestNew q.write_array = writing_default_arrays; } } - // if any combined quantities are streaming, their dependencies must also - for (it = quantities.begin(); it != quantities.end(); ++it) - { - TraceQuantityNew& q = it->second; - if (q.combined_quantity) - { - std::set& deps = combined_dependencies[q.name]; - std::set::iterator name; - if (q.stream_scalar || q.stream_array) - { - for (name = deps.begin(); name != deps.end(); ++name) - { - check_presence(*name); - TraceQuantityNew& qd = quantities[*name]; - qd.stream_scalar |= (qd.scalar_available && q.stream_scalar); - qd.stream_array |= (qd.array_available && q.stream_array); - } - } - } - } - combined_dependencies.clear(); } //relay updated streaming information to contributor @@ -391,7 +335,6 @@ struct TraceRequestNew check_presence(q.name); q = quantities[q.name]; } - other.combined_dependencies.clear(); } inline void report() @@ -482,12 +425,6 @@ struct TraceRequestNew q.name = name; quantities[name] = q; } - if (combined) - if (combined_dependencies.find(name) == combined_dependencies.end()) - { - std::set stmp; - combined_dependencies[name] = stmp; - } } //abort if a quantity is not present @@ -604,8 +541,6 @@ struct TraceSampleNew return same; } - virtual bool is_combined() { return false; } - inline void set_buffer_range(int& bstart) { set_data_size(); @@ -648,99 +583,6 @@ struct TraceSampleNew }; -template -struct CombinedTraceSampleNew : public TraceSampleNew -{ - bool combined; - std::vector weights; - std::vector*> components; - - - inline CombinedTraceSampleNew(const std::string& sdomain, - const std::string& sname, - int sindex, - int sdim, - Vector& ssample) - : TraceSampleNew(sdomain, sname, sindex, sdim, ssample) - { - reset(); - } - - - inline CombinedTraceSampleNew(const std::string& sdomain, - const std::string& sname, - int sindex, - int sdim, - TinyVector sshape, - Vector& ssample) - : TraceSampleNew(sdomain, sname, sindex, sdim, sshape, ssample) - { - reset(); - } - - bool is_combined() override { return true; } - - inline void reset() { combined = false; } - - - inline void add_component(TraceSampleNew* component, TraceRealNew weight) - { - if (components.size() == 0) - { - this->dimension = component->dimension; - this->size = component->size; - this->shape = component->shape; - this->data_size = component->data_size; - this->array_trace = component->array_trace; - this->sample.resize(component->size); - } - else if (!this->same_shape(component)) - { - APP_ABORT("CombinedTraceSampleNew::add_component attempted to add a different shape component\n my domain: " + - this->domain + "\n my name: " + this->name + "\n component domain: " + component->domain + - "\n component name: " + component->name); - } - else if (this->domain != component->domain) - APP_ABORT("CombinedTraceSampleNew::add_component attempted to add a different domain component\n my domain: " + - this->domain + "\n my name: " + this->name + "\n component domain: " + component->domain + - "\n component name: " + component->name); - weights.push_back(weight); - components.push_back(component); - } - - - inline void combine() - { - std::fill(this->sample.begin(), this->sample.end(), T(0)); - for (int i = 0; i < components.size(); ++i) - { - T weight = weights[i]; - auto& component = components[i]->sample; - for (int j = 0; j < this->sample.size(); ++j) - this->sample[j] += weight * component[j]; - } - combined = true; - } - - - inline void write_summary_combined(int ind, std::string pad = " ") - { - std::string pad2 = pad + " "; - std::string pad3 = pad2 + " "; - app_log() << pad << ind << " CombinedTraceSampleNew " << this->name << std::endl; - app_log() << pad2 << "domain = " << this->domain << std::endl; - app_log() << pad2 << "ncomponents = " << components.size() << std::endl; - app_log() << pad2 << "components" << std::endl; - for (int i = 0; i < components.size(); ++i) - { - TraceSampleNew& c = *components[i]; - app_log() << pad3 << c.name << " " << c.index << " " << weights[i] << std::endl; - } - app_log() << pad2 << "end components" << std::endl; - app_log() << pad2 << "vector address = " << (size_t) & this->sample << std::endl; - } -}; - template bool TraceSampleNew_comp(TraceSampleNew* left, TraceSampleNew* right) @@ -755,8 +597,6 @@ struct TraceSampleNews std::vector*> samples; std::map> sample_indices; std::vector*> ordered_samples; - std::vector*> combined_samples; - std::vector*> combined_sample_vectors; bool verbose; inline TraceSampleNews() : verbose(false) {} @@ -836,60 +676,6 @@ struct TraceSampleNews } - inline CombinedTraceSampleNew* get_combined_trace(const std::string& domain, const std::string& name) - { - CombinedTraceSampleNew* ts = NULL; - for (int i = 0; i < combined_samples.size(); ++i) - { - CombinedTraceSampleNew& tsc = *combined_samples[i]; - if (tsc.domain == domain && tsc.name == name) - { - ts = &tsc; - break; - } - } - return ts; - } - - - inline bool make_combined_trace(const std::string& name, - std::vector& names, - std::vector& weights) - { - bool created = false; - if (names.size() != weights.size()) - APP_ABORT("TraceSampleNews::make_combined_trace names and weights must be the same size"); - std::map>::iterator it; - for (it = sample_indices.begin(); it != sample_indices.end(); it++) - { - std::string domain = it->first; - std::map& indices = it->second; - bool any_present = false; - for (int i = 0; i < names.size(); ++i) - any_present = any_present || indices.count(names[i]) > 0; - if (any_present) - { - int index = samples.size(); - auto* sample = new Vector; - CombinedTraceSampleNew* combined = new CombinedTraceSampleNew(domain, name, index, 0, *sample); - for (int i = 0; i < names.size(); ++i) - { - if (indices.count(names[i]) > 0) - { - TraceSampleNew* component = samples[indices[names[i]]]; - combined->add_component(component, weights[i]); - } - } - assign_sample_index(domain, name, index); - samples.push_back(combined); - combined_samples.push_back(combined); - combined_sample_vectors.push_back(sample); - created = true; - } - } - return created; - } - inline void set_unit_size(int usize) { @@ -907,7 +693,7 @@ struct TraceSampleNews if (verbose) app_log() << "TraceRequestNew screening " << s.name << " in domain " << s.domain << ". stream: " << stream << " write: " << s.write << std::endl; - if (!stream && !s.is_combined()) + if (!stream) app_log() << "warning: quantity " + s.name + " in domain " + s.domain + " was not requested but is streaming anyway" << std::endl; @@ -962,30 +748,11 @@ struct TraceSampleNews } - inline void combine_samples() - { - for (int i = 0; i < combined_samples.size(); ++i) - combined_samples[i]->combine(); - } - - - inline void reset_combined_samples() - { - for (int i = 0; i < combined_samples.size(); ++i) - combined_samples[i]->reset(); - } - - inline void finalize() { - //note combined_samples pointers are a subset of those in samples - // and so only samples needs to be deleted delete_iter(samples.begin(), samples.end()); - delete_iter(combined_sample_vectors.begin(), combined_sample_vectors.end()); samples.resize(0); ordered_samples.resize(0); - combined_samples.resize(0); - combined_sample_vectors.resize(0); sample_indices.clear(); } @@ -1027,7 +794,6 @@ struct TraceSampleNews std::string pad4 = pad3 + " "; app_log() << pad << "TraceSampleNews<" << type << ">" << std::endl; app_log() << pad2 << "nsamples = " << samples.size() << std::endl; - app_log() << pad2 << "ncombined_samples = " << combined_samples.size() << std::endl; app_log() << pad2 << "sample_indices" << std::endl; std::map>::iterator it; std::map::iterator it2; @@ -1040,19 +806,9 @@ struct TraceSampleNews app_log() << pad4 << it2->first << " = " << it2->second << std::endl; } app_log() << pad2 << "end sample_indices" << std::endl; - app_log() << pad2 << "combined_sample_vectors = "; - for (int i = 0; i < combined_sample_vectors.size(); ++i) - app_log() << (size_t)combined_sample_vectors[i] << " "; - app_log() << std::endl; - app_log() << pad2 << "combined_samples" << std::endl; - for (int i = 0; i < combined_samples.size(); ++i) - combined_samples[i]->write_summary_combined(i, pad3); - app_log() << pad2 << "end combined_samples" << std::endl; app_log() << pad2 << "samples" << std::endl; for (int i = 0; i < ordered_samples.size(); ++i) ordered_samples[i]->write_summary(i, pad3); - //for(int i=0; iwrite_summary(i,pad3); app_log() << pad2 << "end samples" << std::endl; app_log() << pad << "end TraceSampleNews<" << type << ">" << std::endl; } @@ -1131,23 +887,6 @@ struct TraceBufferNew } - inline void make_combined_trace(const std::string& name, - std::vector& names, - std::vector& weights) - { - bool created_real = samples->make_combined_trace(name, names, weights); - if (has_complex) - { - bool created_complex = complex_samples->make_combined_trace(name, names, weights); - if (created_real && created_complex) - APP_ABORT("TraceBufferNew<" + type + - ">::make_combined_trace\n cannot create real and complex combined traces for the same quantity\n " - "attempted for quantity " + - name); - } - } - - inline void order_and_resize() { //put the sample data in size order @@ -1193,10 +932,6 @@ struct TraceBufferNew std::copy_n(buffer_old.data(), buffer_old.size(), buffer.data()); if (verbose) app_log() << " increasing # of rows to " << nrows << std::endl; - //combine samples - samples->combine_samples(); - if (has_complex) - complex_samples->combine_samples(); //collect data from all samples into the buffer row { std::vector*>& ordered_samples = samples->ordered_samples; @@ -1228,10 +963,6 @@ struct TraceBufferNew } } } - //reset combined samples so they can be recombined on the next step - samples->reset_combined_samples(); - if (has_complex) - complex_samples->reset_combined_samples(); #if defined(TRACE_CHECK) test_buffer_collect(current_row); #endif @@ -1786,29 +1517,6 @@ class TraceManagerNew } - - //create combined trace out of existing traces - inline void make_combined_trace(const std::string& name, std::vector& names) - { - std::vector weights; - weights.resize(names.size()); - std::fill(weights.begin(), weights.end(), 1.0); - make_combined_trace(name, names, weights); - } - - inline void make_combined_trace(const std::string& name, - std::vector& names, - std::vector& weights) - { - if (streaming_traces) - { - if (verbose) - app_log() << "TraceManagerNew::make_combined_trace " << master_copy << " " << name << std::endl; - real_buffer.make_combined_trace(name, names, weights); - } - } - - inline void check_clones(std::vector& clones) { app_log() << "JTK: TraceManagerNew::check_clones "< Date: Tue, 21 May 2024 04:45:02 -0400 Subject: [PATCH 05/55] start trace collector --- src/Estimators/TraceManagerNew.h | 439 +++++++++++++++++++++++++++++++ 1 file changed, 439 insertions(+) diff --git a/src/Estimators/TraceManagerNew.h b/src/Estimators/TraceManagerNew.h index 7d5880607a..f7480397d1 100644 --- a/src/Estimators/TraceManagerNew.h +++ b/src/Estimators/TraceManagerNew.h @@ -1150,6 +1150,443 @@ struct TraceBufferNew }; + + +struct TraceManagerState +{ + bool method_allows_traces; + TraceRequestNew request; + bool streaming_traces; + bool writing_traces; + int throttle; + bool verbose; + std::string format; + bool hdf_format; + std::string default_domain; +}; + + + +class TraceCollector +{ +private: + //collections of samples for a single walker step + // the associated arrays will be updated following evaluate + TraceSampleNews int_samples; + TraceSampleNews real_samples; + TraceSampleNews comp_samples; + + //buffers for storing samples + // single row of buffer is a single sample from one walker + // number of rows adjusts to accommodate walker samples + TraceBufferNew int_buffer; + TraceBufferNew real_buffer; + +public: + static double trace_tol; + + TraceRequestNew request; + + std::string default_domain; + bool method_allows_traces; + bool streaming_traces; + bool writing_traces; + int throttle; + bool verbose; + std::string format; + bool hdf_format; + std::string file_root; + Communicate* communicator; + + TraceCollector(Communicate* comm = 0) : verbose(false) + { + reset_permissions(); + communicator = comm; + throttle = 1; + format = "hdf"; + default_domain = "scalars"; + request.set_scalar_domain(default_domain); + int_buffer.set_type("int"); + real_buffer.set_type("real"); + int_buffer.set_samples(int_samples); + real_buffer.set_samples(real_samples); + real_buffer.set_samples(comp_samples); + } + + + inline void transfer_state_from(const TraceManagerState& tms) + { + method_allows_traces = tms.method_allows_traces; + request = tms.request; + streaming_traces = tms.streaming_traces; + writing_traces = tms.writing_traces; + throttle = tms.throttle; + verbose = tms.verbose; + format = tms.format; + hdf_format = tms.hdf_format; + default_domain = tms.default_domain; + } + + + inline void distribute() + { + int_samples.set_verbose(verbose); + real_samples.set_verbose(verbose); + comp_samples.set_verbose(verbose); + int_buffer.set_verbose(verbose); + real_buffer.set_verbose(verbose); + } + + + inline void reset_permissions() + { + method_allows_traces = false; + streaming_traces = false; + writing_traces = false; + verbose = false; + hdf_format = false; + request.reset(); + } + + + inline void put(xmlNodePtr cur, bool allow_traces, std::string series_root) + { + app_log()<<"JTK: TraceCollector::put"< scalar_requests; + std::set array_requests; + xmlNodePtr element = cur->children; + while (element != NULL) + { + std::string name((const char*)element->name); + if (name == "scalar_traces") + { + std::string defaults = "no"; + OhmmsAttributeSet eattrib; + eattrib.add(defaults, "defaults"); + eattrib.put(element); + use_scalar_defaults = use_scalar_defaults && defaults == "yes"; + if (!use_scalar_defaults) + { + std::vector scalar_list; + putContent(scalar_list, element); + scalar_requests.insert(scalar_list.begin(), scalar_list.end()); + } + } + else if (name == "array_traces" || name == "particle_traces") + { + std::string defaults = "no"; + OhmmsAttributeSet eattrib; + eattrib.add(defaults, "defaults"); + eattrib.put(element); + use_array_defaults = use_array_defaults && defaults == "yes"; + if (!use_array_defaults) + { + std::vector array_list; + putContent(array_list, element); + array_requests.insert(array_list.begin(), array_list.end()); + } + } + else if (name != "text") + { + APP_ABORT("TraceCollector::put " + name + + " is not a valid sub-element of \n valid options are: scalar_traces, array_traces"); + } + element = element->next; + } + + writing_traces &= method_allows_traces; + + //input user quantity requests into the traces request + request.allow_streams = method_allows_traces; + request.allow_writes = writing_traces; + request.scalars_on = scalars_on; + request.arrays_on = arrays_on; + request.stream_all_scalars = use_scalar_defaults; + request.stream_all_arrays = use_array_defaults; + request.write_all_scalars = request.stream_all_scalars && writing_traces; + request.write_all_arrays = request.stream_all_arrays && writing_traces; + request.request_scalar(scalar_requests, writing_traces); + request.request_array(array_requests, writing_traces); + + //distribute verbosity level to buffer and sample objects + distribute(); + + } + } + + + inline void update_status() + { + streaming_traces = request.streaming(); + writing_traces = request.writing(); + } + + + inline void screen_writes() + { + int_samples.screen_writes(request); + real_samples.screen_writes(request); + comp_samples.screen_writes(request); + } + + inline void initialize_traces() + { + app_log()<<"JTK: TraceCollector::initialize_traces "< + inline Array* checkout_int(const std::string& name, int n1 = 1, int n2 = 0, int n3 = 0, int n4 = 0) + { + app_log()<<"JTK: TraceCollector::checkout_int"<(default_domain, name, n1, n2, n3, n4); + } + template + inline Array* checkout_int(const std::string& domain, + const std::string& name, + int n1 = 1, + int n2 = 0, + int n3 = 0, + int n4 = 0) + { + app_log()<<"JTK: TraceCollector::checkout_int"< shape(n1, n2, n3, n4); + return int_samples.checkout_array(domain, name, shape); + } + template + inline Array* checkout_int(const std::string& name, + const ParticleSet& P, + int n2 = 0, + int n3 = 0, + int n4 = 0) + { + app_log()<<"JTK: TraceCollector::checkout_int"< shape(P.getTotalNum(), n2, n3, n4); + return int_samples.checkout_array(P, name, shape); + } + + + // checkout real arrays + template + inline Array* checkout_real(const std::string& name, int n1 = 1, int n2 = 0, int n3 = 0, int n4 = 0) + { + app_log()<<"JTK: TraceCollector::checkout_real"<(default_domain, name, n1, n2, n3, n4); + } + template + inline Array* checkout_real(const std::string& domain, + const std::string& name, + int n1 = 1, + int n2 = 0, + int n3 = 0, + int n4 = 0) + { + app_log()<<"JTK: TraceCollector::checkout_real"< shape(n1, n2, n3, n4); + return real_samples.checkout_array(domain, name, shape); + } + template + inline Array* checkout_real(const std::string& name, + const ParticleSet& P, + int n2 = 0, + int n3 = 0, + int n4 = 0) + { + app_log()<<"JTK: TraceCollector::checkout_real"< shape(P.getTotalNum(), n2, n3, n4); + return real_samples.checkout_array(P, name, shape); + } + + + // checkout complex arrays + template + inline Array* checkout_complex(const std::string& name, int n1 = 1, int n2 = 0, int n3 = 0, int n4 = 0) + { + app_log()<<"JTK: TraceCollector::checkout_complex"<(default_domain, name, n1, n2, n3, n4); + } + template + inline Array* checkout_complex(const std::string& domain, + const std::string& name, + int n1 = 1, + int n2 = 0, + int n3 = 0, + int n4 = 0) + { + app_log()<<"JTK: TraceCollector::checkout_complex"< shape(n1, n2, n3, n4); + return comp_samples.checkout_array(domain, name, shape); + } + template + inline Array* checkout_complex(const std::string& name, + const ParticleSet& P, + int n2 = 0, + int n3 = 0, + int n4 = 0) + { + app_log()<<"JTK: TraceCollector::checkout_complex"< shape(P.getTotalNum(), n2, n3, n4); + return comp_samples.checkout_array(P, name, shape); + } + + + inline void reset_buffers() + { + app_log() << "JTK: TraceCollector::reset_buffers"<::iterator req; + int_buffer.user_report(pad3); + real_buffer.user_report(pad3); + app_log() << std::endl; + } + +}; + + + + + + class TraceManagerNew { private: @@ -1771,6 +2208,8 @@ class TraceManagerNew }; + + } // namespace qmcplusplus From d21b2ce539e6cc40b9fb0fc7bb7fdc83bf7782c4 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Tue, 21 May 2024 05:31:50 -0400 Subject: [PATCH 06/55] hot swap trace collector for trace manager --- src/Estimators/TraceManagerNew.h | 52 ++++++++++++++++++++------ src/QMCDrivers/CloneManager.h | 4 +- src/QMCDrivers/DMC/DMC.cpp | 4 +- src/QMCDrivers/QMCUpdateBase.cpp | 2 +- src/QMCDrivers/QMCUpdateBase.h | 4 +- src/QMCDrivers/VMC/VMC.cpp | 4 +- src/QMCHamiltonians/OperatorBase.cpp | 8 ++-- src/QMCHamiltonians/OperatorBase.h | 8 ++-- src/QMCHamiltonians/QMCHamiltonian.cpp | 2 +- src/QMCHamiltonians/QMCHamiltonian.h | 2 +- 10 files changed, 59 insertions(+), 31 deletions(-) diff --git a/src/Estimators/TraceManagerNew.h b/src/Estimators/TraceManagerNew.h index f7480397d1..5337d9c9b9 100644 --- a/src/Estimators/TraceManagerNew.h +++ b/src/Estimators/TraceManagerNew.h @@ -1169,7 +1169,7 @@ struct TraceManagerState class TraceCollector { -private: +public: //collections of samples for a single walker step // the associated arrays will be updated following evaluate TraceSampleNews int_samples; @@ -1182,7 +1182,6 @@ class TraceCollector TraceBufferNew int_buffer; TraceBufferNew real_buffer; -public: static double trace_tol; TraceRequestNew request; @@ -1637,6 +1636,35 @@ class TraceManagerNew } + inline TraceManagerState getState() + { + TraceManagerState tms; + tms.method_allows_traces = method_allows_traces; + tms.request = request; + tms.streaming_traces = streaming_traces; + tms.writing_traces = writing_traces; + tms.throttle = throttle; + tms.verbose = verbose; + tms.format = format; + tms.hdf_format = hdf_format; + tms.default_domain = default_domain; + return tms; + } + + inline TraceCollector* makeCollector() + { + app_log()<<"JTK: TraceManagernew::makeCollector"<transfer_state_from(getState()); + tc->distribute(); + return tc; + } + + inline TraceManagerNew* makeClone() { app_log()<<"JTK: TraceManagernew::makeClone"<& clones) + inline void check_clones(std::vector& clones) { app_log() << "JTK: TraceManagerNew::check_clones "< 0) @@ -1964,10 +1992,10 @@ class TraceManagerNew bool all_same = true; bool int_same; bool real_same; - TraceManagerNew& ref = *clones[0]; + TraceCollector& ref = *clones[0]; for (int i = 0; i < clones.size(); ++i) { - TraceManagerNew& tm = *clones[i]; + TraceCollector& tm = *clones[i]; int_same = tm.int_buffer.same_as(ref.int_buffer); real_same = tm.real_buffer.same_as(ref.real_buffer); all_same = all_same && int_same && real_same; @@ -2013,7 +2041,7 @@ class TraceManagerNew //write buffered trace data to file - inline void write_buffers(std::vector& clones, int block) + inline void write_buffers(std::vector& clones, int block) { app_log() << "JTK: TraceManagerNew::write_buffers "<< writing_traces<& clones) + inline void open_file(std::vector& clones) { app_log() << "JTK: TraceManagerNew::open_file "<< writing_traces<& clones) + inline void startRun(int blocks, std::vector& clones) { app_log() << "JTK: TraceManagerNew::startRun " << master_copy << std::endl; if (verbose) @@ -2151,7 +2179,7 @@ class TraceManagerNew } //hdf file operations - inline void open_hdf_file(std::vector& clones) + inline void open_hdf_file(std::vector& clones) { app_log() << "JTK: TraceManagerNew::open_hdf_file " << master_copy << std::endl; if (clones.size() == 0) @@ -2181,21 +2209,21 @@ class TraceManagerNew if (!successful) APP_ABORT("TraceManagerNew::open_hdf_file failed to open hdf file " + file_name); // only clones have active buffers and associated data - TraceManagerNew& tm = *clones[0]; + TraceCollector& tm = *clones[0]; //tm.write_summary(); tm.int_buffer.register_hdf_data(*hdf_file); tm.real_buffer.register_hdf_data(*hdf_file); } - inline void write_buffers_hdf(std::vector& clones) + inline void write_buffers_hdf(std::vector& clones) { app_log() << "JTK: TraceManagerNew::write_buffers_hdf " << master_copy << std::endl; if (verbose) app_log() << "TraceManagerNew::write_buffers_hdf " << master_copy << std::endl; for (int ip = 0; ip < clones.size(); ++ip) { - TraceManagerNew& tm = *clones[ip]; + TraceCollector& tm = *clones[ip]; tm.int_buffer.write_hdf(*hdf_file, int_buffer.hdf_file_pointer); tm.real_buffer.write_hdf(*hdf_file, real_buffer.hdf_file_pointer); } diff --git a/src/QMCDrivers/CloneManager.h b/src/QMCDrivers/CloneManager.h index 1b5853eb63..3fdd4cf9a2 100644 --- a/src/QMCDrivers/CloneManager.h +++ b/src/QMCDrivers/CloneManager.h @@ -75,8 +75,8 @@ class CloneManager : public QMCTraits std::vector estimatorClones; ///trace managers std::vector traceClones; - ///trace managers - std::vector traceClonesNew; + ///trace collectors + std::vector traceClonesNew; //for correlated sampling. static std::vector> WPoolClones_uptr; diff --git a/src/QMCDrivers/DMC/DMC.cpp b/src/QMCDrivers/DMC/DMC.cpp index 9cafd67a04..893e943141 100644 --- a/src/QMCDrivers/DMC/DMC.cpp +++ b/src/QMCDrivers/DMC/DMC.cpp @@ -132,7 +132,7 @@ void DMC::resetUpdateEngines() estimatorClones[ip]->setCollectionMode(false); #if !defined(REMOVE_TRACEMANAGER) traceClones[ip] = Traces->makeClone(); - traceClonesNew[ip] = Traces_new->makeClone(); + traceClonesNew[ip] = Traces_new->makeCollector(); #endif Rng[ip] = rngs_[ip]->makeClone(); hClones[ip]->setRandomGenerator(Rng[ip].get()); @@ -188,7 +188,7 @@ void DMC::resetUpdateEngines() for (int ip = 0; ip < NumThreads; ++ip) { traceClones[ip]->transfer_state_from(*Traces); - traceClonesNew[ip]->transfer_state_from(*Traces_new); + traceClonesNew[ip]->transfer_state_from(Traces_new->getState()); } } #endif diff --git a/src/QMCDrivers/QMCUpdateBase.cpp b/src/QMCDrivers/QMCUpdateBase.cpp index d12896418a..28ec298d28 100644 --- a/src/QMCDrivers/QMCUpdateBase.cpp +++ b/src/QMCDrivers/QMCUpdateBase.cpp @@ -121,7 +121,7 @@ bool QMCUpdateBase::put(xmlNodePtr cur) void QMCUpdateBase::resetRunNew(BranchEngineType* brancher, EstimatorManagerBase* est, TraceManager* traces, - TraceManagerNew* traces_new, + TraceCollector* traces_new, const DriftModifierBase* driftmodifer) { Traces_new = traces_new; diff --git a/src/QMCDrivers/QMCUpdateBase.h b/src/QMCDrivers/QMCUpdateBase.h index 725e2a702b..7ce5b60365 100644 --- a/src/QMCDrivers/QMCUpdateBase.h +++ b/src/QMCDrivers/QMCUpdateBase.h @@ -105,7 +105,7 @@ class QMCUpdateBase : public QMCTraits void resetRunNew(BranchEngineType* brancher, EstimatorManagerBase* est, TraceManager* traces, - TraceManagerNew* traces_new, + TraceCollector* traces_new, const DriftModifierBase* driftmodifer); inline RealType getTau() @@ -245,7 +245,7 @@ class QMCUpdateBase : public QMCTraits public: ///traces TraceManager* Traces; - TraceManagerNew* Traces_new; + TraceCollector* Traces_new; protected: ///update particle-by-particle diff --git a/src/QMCDrivers/VMC/VMC.cpp b/src/QMCDrivers/VMC/VMC.cpp index 6967913575..245df45fbf 100644 --- a/src/QMCDrivers/VMC/VMC.cpp +++ b/src/QMCDrivers/VMC/VMC.cpp @@ -185,7 +185,7 @@ void VMC::resetRun() estimatorClones[ip]->setCollectionMode(false); #if !defined(REMOVE_TRACEMANAGER) traceClones[ip] = Traces->makeClone(); - traceClonesNew[ip] = Traces_new->makeClone(); + traceClonesNew[ip] = Traces_new->makeCollector(); #endif Rng[ip] = rngs_[ip]->makeClone(); hClones[ip]->setRandomGenerator(Rng[ip].get()); @@ -224,7 +224,7 @@ void VMC::resetRun() for (int ip = 0; ip < NumThreads; ++ip) { traceClones[ip]->transfer_state_from(*Traces); - traceClonesNew[ip]->transfer_state_from(*Traces_new); + traceClonesNew[ip]->transfer_state_from(Traces_new->getState()); } } #endif diff --git a/src/QMCHamiltonians/OperatorBase.cpp b/src/QMCHamiltonians/OperatorBase.cpp index 3ac3f03f5b..99d2dac4e4 100644 --- a/src/QMCHamiltonians/OperatorBase.cpp +++ b/src/QMCHamiltonians/OperatorBase.cpp @@ -228,7 +228,7 @@ void OperatorBase::add2Hamiltonian(ParticleSet& qp, TrialWaveFunction& psi, QMCH #if !defined(REMOVE_TRACEMANAGER) void OperatorBase::getRequiredTraces(TraceManager& tm){}; -void OperatorBase::getRequiredTracesNew(TraceManagerNew& tm){}; +void OperatorBase::getRequiredTracesNew(TraceCollector& tm){}; #endif // END FUNCTIONS // @@ -283,7 +283,7 @@ void OperatorBase::contributeTraceQuantitiesNew() contributeParticleQuantitiesNew(); } -void OperatorBase::checkoutTraceQuantitiesNew(TraceManagerNew& tm) +void OperatorBase::checkoutTraceQuantitiesNew(TraceCollector& tm) { checkoutScalarQuantitiesNew(tm); checkoutParticleQuantitiesNew(tm); @@ -334,7 +334,7 @@ void OperatorBase::deleteParticleQuantities(){}; void OperatorBase::contributeScalarQuantitiesNew() { request_new_.contribute_scalar(name_); } -void OperatorBase::checkoutScalarQuantitiesNew(TraceManagerNew& tm) +void OperatorBase::checkoutScalarQuantitiesNew(TraceCollector& tm) { streaming_scalars_new_ = request_new_.streaming_scalar(name_); if (streaming_scalars_new_) @@ -354,7 +354,7 @@ void OperatorBase::deleteScalarQuantitiesNew() } void OperatorBase::contributeParticleQuantitiesNew(){}; -void OperatorBase::checkoutParticleQuantitiesNew(TraceManagerNew& tm){}; +void OperatorBase::checkoutParticleQuantitiesNew(TraceCollector& tm){}; void OperatorBase::deleteParticleQuantitiesNew(){}; #endif diff --git a/src/QMCHamiltonians/OperatorBase.h b/src/QMCHamiltonians/OperatorBase.h index 8eef25e7ce..02b119da4c 100644 --- a/src/QMCHamiltonians/OperatorBase.h +++ b/src/QMCHamiltonians/OperatorBase.h @@ -466,7 +466,7 @@ class OperatorBase : public QMCTraits * @param tm */ virtual void getRequiredTraces(TraceManager& tm); - virtual void getRequiredTracesNew(TraceManagerNew& tm); + virtual void getRequiredTracesNew(TraceCollector& tm); #endif // TODO: add docs @@ -520,7 +520,7 @@ class OperatorBase : public QMCTraits void contributeTraceQuantitiesNew(); - void checkoutTraceQuantitiesNew(TraceManagerNew& tm); + void checkoutTraceQuantitiesNew(TraceCollector& tm); void collectScalarTracesNew(); void deleteTraceQuantitiesNew(); #endif @@ -582,11 +582,11 @@ class OperatorBase : public QMCTraits virtual void contributeScalarQuantitiesNew(); - virtual void checkoutScalarQuantitiesNew(TraceManagerNew& tm); + virtual void checkoutScalarQuantitiesNew(TraceCollector& tm); virtual void collectScalarQuantitiesNew(); virtual void deleteScalarQuantitiesNew(); virtual void contributeParticleQuantitiesNew(); - virtual void checkoutParticleQuantitiesNew(TraceManagerNew& tm); + virtual void checkoutParticleQuantitiesNew(TraceCollector& tm); virtual void deleteParticleQuantitiesNew(); #endif diff --git a/src/QMCHamiltonians/QMCHamiltonian.cpp b/src/QMCHamiltonians/QMCHamiltonian.cpp index fcf02f0f2d..055a042ea5 100644 --- a/src/QMCHamiltonians/QMCHamiltonian.cpp +++ b/src/QMCHamiltonians/QMCHamiltonian.cpp @@ -547,7 +547,7 @@ void QMCHamiltonian::finalize_traces() -void QMCHamiltonian::initialize_traces_new(TraceManagerNew& tm, ParticleSet& P) +void QMCHamiltonian::initialize_traces_new(TraceCollector& tm, ParticleSet& P) { static bool first_init_new = true; bool trace_log = first_init_new && tm.verbose && omp_get_thread_num() == 0; diff --git a/src/QMCHamiltonians/QMCHamiltonian.h b/src/QMCHamiltonians/QMCHamiltonian.h index 08e6271425..825578ff27 100644 --- a/src/QMCHamiltonians/QMCHamiltonian.h +++ b/src/QMCHamiltonians/QMCHamiltonian.h @@ -116,7 +116,7 @@ class QMCHamiltonian void finalize_traces(); ///initialize trace data - void initialize_traces_new(TraceManagerNew& tm, ParticleSet& P); + void initialize_traces_new(TraceCollector& tm, ParticleSet& P); ///collect walker trace data void collect_walker_traces_new(Walker_t& walker, int step); From 1545230e2a808e727c73da59d6eb5c1cfaebacb6 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Tue, 21 May 2024 09:21:04 -0400 Subject: [PATCH 07/55] remove unused code --- src/Estimators/TraceManagerNew.h | 370 +------------------------------ 1 file changed, 10 insertions(+), 360 deletions(-) diff --git a/src/Estimators/TraceManagerNew.h b/src/Estimators/TraceManagerNew.h index 5337d9c9b9..c8acddadcd 100644 --- a/src/Estimators/TraceManagerNew.h +++ b/src/Estimators/TraceManagerNew.h @@ -1229,6 +1229,7 @@ class TraceCollector inline void distribute() { + app_log()<<"JTK: TraceCollector::distribute"< scalar_requests; - std::set array_requests; - xmlNodePtr element = cur->children; - while (element != NULL) - { - std::string name((const char*)element->name); - if (name == "scalar_traces") - { - std::string defaults = "no"; - OhmmsAttributeSet eattrib; - eattrib.add(defaults, "defaults"); - eattrib.put(element); - use_scalar_defaults = use_scalar_defaults && defaults == "yes"; - if (!use_scalar_defaults) - { - std::vector scalar_list; - putContent(scalar_list, element); - scalar_requests.insert(scalar_list.begin(), scalar_list.end()); - } - } - else if (name == "array_traces" || name == "particle_traces") - { - std::string defaults = "no"; - OhmmsAttributeSet eattrib; - eattrib.add(defaults, "defaults"); - eattrib.put(element); - use_array_defaults = use_array_defaults && defaults == "yes"; - if (!use_array_defaults) - { - std::vector array_list; - putContent(array_list, element); - array_requests.insert(array_list.begin(), array_list.end()); - } - } - else if (name != "text") - { - APP_ABORT("TraceCollector::put " + name + - " is not a valid sub-element of \n valid options are: scalar_traces, array_traces"); - } - element = element->next; - } - - writing_traces &= method_allows_traces; - - //input user quantity requests into the traces request - request.allow_streams = method_allows_traces; - request.allow_writes = writing_traces; - request.scalars_on = scalars_on; - request.arrays_on = arrays_on; - request.stream_all_scalars = use_scalar_defaults; - request.stream_all_arrays = use_array_defaults; - request.write_all_scalars = request.stream_all_scalars && writing_traces; - request.write_all_arrays = request.stream_all_arrays && writing_traces; - request.request_scalar(scalar_requests, writing_traces); - request.request_array(array_requests, writing_traces); - - //distribute verbosity level to buffer and sample objects - distribute(); - - } - } - - inline void update_status() { + app_log()<<"JTK: TraceCollector::update_status"<::iterator req; @@ -1653,7 +1535,7 @@ class TraceManagerNew inline TraceCollector* makeCollector() { - app_log()<<"JTK: TraceManagernew::makeCollector"<master_copy = false; - tm->transfer_state_from(*this); - tm->distribute(); - return tm; - } - - - inline void transfer_state_from(const TraceManagerNew& tm) - { - method_allows_traces = tm.method_allows_traces; - request = tm.request; - streaming_traces = tm.streaming_traces; - writing_traces = tm.writing_traces; - throttle = tm.throttle; - verbose = tm.verbose; - format = tm.format; - hdf_format = tm.hdf_format; - default_domain = tm.default_domain; - } - - inline void distribute() { + app_log()<<"JTK: TraceManagerNew::distribute"< - inline Array* checkout_int(const std::string& name, int n1 = 1, int n2 = 0, int n3 = 0, int n4 = 0) - { - app_log()<<"JTK: TraceManagerNew::checkout_int"<(default_domain, name, n1, n2, n3, n4); - } - template - inline Array* checkout_int(const std::string& domain, - const std::string& name, - int n1 = 1, - int n2 = 0, - int n3 = 0, - int n4 = 0) - { - app_log()<<"JTK: TraceManagerNew::checkout_int"< shape(n1, n2, n3, n4); - return int_samples.checkout_array(domain, name, shape); - } - template - inline Array* checkout_int(const std::string& name, - const ParticleSet& P, - int n2 = 0, - int n3 = 0, - int n4 = 0) - { - app_log()<<"JTK: TraceManagerNew::checkout_int"< shape(P.getTotalNum(), n2, n3, n4); - return int_samples.checkout_array(P, name, shape); - } - - - // checkout real arrays - template - inline Array* checkout_real(const std::string& name, int n1 = 1, int n2 = 0, int n3 = 0, int n4 = 0) - { - app_log()<<"JTK: TraceManagerNew::checkout_real"<(default_domain, name, n1, n2, n3, n4); - } - template - inline Array* checkout_real(const std::string& domain, - const std::string& name, - int n1 = 1, - int n2 = 0, - int n3 = 0, - int n4 = 0) - { - app_log()<<"JTK: TraceManagerNew::checkout_real"< shape(n1, n2, n3, n4); - return real_samples.checkout_array(domain, name, shape); - } - template - inline Array* checkout_real(const std::string& name, - const ParticleSet& P, - int n2 = 0, - int n3 = 0, - int n4 = 0) - { - app_log()<<"JTK: TraceManagerNew::checkout_real"< shape(P.getTotalNum(), n2, n3, n4); - return real_samples.checkout_array(P, name, shape); - } - - - // checkout complex arrays - template - inline Array* checkout_complex(const std::string& name, int n1 = 1, int n2 = 0, int n3 = 0, int n4 = 0) - { - app_log()<<"JTK: TraceManagerNew::checkout_complex"<(default_domain, name, n1, n2, n3, n4); - } - template - inline Array* checkout_complex(const std::string& domain, - const std::string& name, - int n1 = 1, - int n2 = 0, - int n3 = 0, - int n4 = 0) - { - app_log()<<"JTK: TraceManagerNew::checkout_complex"< shape(n1, n2, n3, n4); - return comp_samples.checkout_array(domain, name, shape); - } - template - inline Array* checkout_complex(const std::string& name, - const ParticleSet& P, - int n2 = 0, - int n3 = 0, - int n4 = 0) - { - app_log()<<"JTK: TraceManagerNew::checkout_complex"< shape(P.getTotalNum(), n2, n3, n4); - return comp_samples.checkout_array(P, name, shape); + app_log()<<"JTK: TraceManagerNew::finalize_traces (no-op) "<& clones, int block) { @@ -2134,50 +1828,6 @@ class TraceManagerNew APP_ABORT("TraceManagerNew::stopRun should not be called from non-master copy"); } - - inline void startBlock(int nsteps) - { - app_log() << "JTK: TraceManagerNew::startBlock " << master_copy << std::endl; - if (verbose) - app_log() << "TraceManagerNew::startBlock " << master_copy << std::endl; - reset_buffers(); - } - - - inline void write_summary(std::string pad = " ") - { - std::string pad2 = pad + " "; - app_log() << std::endl; - app_log() << pad << "TraceManagerNew (detailed summary)" << std::endl; - app_log() << pad2 << "master_copy = " << master_copy << std::endl; - app_log() << pad2 << "method_allows_traces = " << method_allows_traces << std::endl; - app_log() << pad2 << "streaming_traces = " << streaming_traces << std::endl; - app_log() << pad2 << "writing_traces = " << writing_traces << std::endl; - app_log() << pad2 << "format = " << format << std::endl; - app_log() << pad2 << "hdf format = " << hdf_format << std::endl; - app_log() << pad2 << "default_domain = " << default_domain << std::endl; - int_buffer.write_summary(pad2); - real_buffer.write_summary(pad2); - app_log() << pad << "end TraceManagerNew" << std::endl; - } - - - inline void user_report(std::string pad = " ") - { - std::string pad2 = pad + " "; - std::string pad3 = pad2 + " "; - app_log() << std::endl; - app_log() << pad << "Traces report" << std::endl; - request.report(); - app_log() << pad2 << "Type and domain breakdown of streaming quantities:" << std::endl; - std::set::iterator req; - int_buffer.user_report(pad3); - real_buffer.user_report(pad3); - app_log() << std::endl; - //if(verbose) - // write_summary(pad); - } - //hdf file operations inline void open_hdf_file(std::vector& clones) { From 875ee62ab928b1bcc08a46d783dc2dad76dedcbd Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Tue, 21 May 2024 10:36:40 -0400 Subject: [PATCH 08/55] remove buffers from master --- src/Estimators/TraceManagerNew.h | 147 +++++++------------------------ 1 file changed, 34 insertions(+), 113 deletions(-) diff --git a/src/Estimators/TraceManagerNew.h b/src/Estimators/TraceManagerNew.h index c8acddadcd..051db5e41d 100644 --- a/src/Estimators/TraceManagerNew.h +++ b/src/Estimators/TraceManagerNew.h @@ -1470,25 +1470,11 @@ class TraceCollector class TraceManagerNew { -private: - //collections of samples for a single walker step - // the associated arrays will be updated following evaluate - TraceSampleNews int_samples; - TraceSampleNews real_samples; - TraceSampleNews comp_samples; - - //buffers for storing samples - // single row of buffer is a single sample from one walker - // number of rows adjusts to accommodate walker samples - TraceBufferNew int_buffer; - TraceBufferNew real_buffer; - public: static double trace_tol; TraceRequestNew request; - bool master_copy; std::string default_domain; bool method_allows_traces; bool streaming_traces; @@ -1504,17 +1490,11 @@ class TraceManagerNew TraceManagerNew(Communicate* comm = 0) : verbose(false) { reset_permissions(); - master_copy = true; communicator = comm; throttle = 1; format = "hdf"; default_domain = "scalars"; request.set_scalar_domain(default_domain); - int_buffer.set_type("int"); - real_buffer.set_type("real"); - int_buffer.set_samples(int_samples); - real_buffer.set_samples(real_samples); - real_buffer.set_samples(comp_samples); } @@ -1537,9 +1517,7 @@ class TraceManagerNew { app_log()<<"JTK: TraceManagerNew::makeCollector"<transfer_state_from(getState()); tc->distribute(); @@ -1547,17 +1525,6 @@ class TraceManagerNew } - inline void distribute() - { - app_log()<<"JTK: TraceManagerNew::distribute"<& clones) { @@ -1738,100 +1691,67 @@ class TraceManagerNew inline void write_buffers(std::vector& clones, int block) { app_log() << "JTK: TraceManagerNew::write_buffers "<< writing_traces<& clones) { app_log() << "JTK: TraceManagerNew::open_file "<< writing_traces<write_summary(); - if (hdf_format) - { - open_hdf_file(clones); - } - } + if (verbose) + app_log() << "TraceManagerNew::open_file " << std::endl; + if (verbose) + clones[0]->write_summary(); + if (hdf_format) + open_hdf_file(clones); } - else - APP_ABORT("TraceManagerNew::open_file should not be called from non-master copy"); } inline void close_file() { app_log() << "JTK: TraceManagerNew::close_file "<< writing_traces<& clones) { - app_log() << "JTK: TraceManagerNew::startRun " << master_copy << std::endl; + app_log() << "JTK: TraceManagerNew::startRun " << std::endl; if (verbose) - app_log() << "TraceManagerNew::startRun " << master_copy << std::endl; - if (master_copy) - { - initialize_traces(); - check_clones(clones); - open_file(clones); - } - else - APP_ABORT("TraceManagerNew::startRun should not be called from non-master copy"); + app_log() << "TraceManagerNew::startRun " << std::endl; + check_clones(clones); + open_file(clones); } inline void stopRun() { - app_log() << "JTK: TraceManagerNew::stopRun " << master_copy << std::endl; + app_log() << "JTK: TraceManagerNew::stopRun " << std::endl; if (verbose) - app_log() << "TraceManagerNew::stopRun " << master_copy << std::endl; - if (master_copy) - { - close_file(); - finalize_traces(); - } - else - APP_ABORT("TraceManagerNew::stopRun should not be called from non-master copy"); + app_log() << "TraceManagerNew::stopRun " << std::endl; + close_file(); } //hdf file operations inline void open_hdf_file(std::vector& clones) { - app_log() << "JTK: TraceManagerNew::open_hdf_file " << master_copy << std::endl; + app_log() << "JTK: TraceManagerNew::open_hdf_file " << std::endl; if (clones.size() == 0) APP_ABORT("TraceManagerNew::open_hdf_file no trace clones exist, cannot open file"); int nprocs = communicator->size(); @@ -1868,19 +1788,20 @@ class TraceManagerNew inline void write_buffers_hdf(std::vector& clones) { - app_log() << "JTK: TraceManagerNew::write_buffers_hdf " << master_copy << std::endl; + app_log() << "JTK: TraceManagerNew::write_buffers_hdf " << std::endl; if (verbose) - app_log() << "TraceManagerNew::write_buffers_hdf " << master_copy << std::endl; + app_log() << "TraceManagerNew::write_buffers_hdf " << std::endl; + TraceCollector& tm_lead = *clones[0]; for (int ip = 0; ip < clones.size(); ++ip) { TraceCollector& tm = *clones[ip]; - tm.int_buffer.write_hdf(*hdf_file, int_buffer.hdf_file_pointer); - tm.real_buffer.write_hdf(*hdf_file, real_buffer.hdf_file_pointer); + tm.int_buffer.write_hdf(*hdf_file, tm_lead.int_buffer.hdf_file_pointer); + tm.real_buffer.write_hdf(*hdf_file, tm_lead.real_buffer.hdf_file_pointer); } } inline void close_hdf_file() { - app_log() << "JTK: TraceManagerNew::close_hdf_file " << master_copy << std::endl; + app_log() << "JTK: TraceManagerNew::close_hdf_file " << std::endl; hdf_file.reset(); } }; From e0fcd9b9938f1271df3e4e084faa2ee9b1c3ce38 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Tue, 21 May 2024 10:55:14 -0400 Subject: [PATCH 09/55] remove unused data members --- src/Estimators/TraceManagerNew.h | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/src/Estimators/TraceManagerNew.h b/src/Estimators/TraceManagerNew.h index 051db5e41d..0485f6ddea 100644 --- a/src/Estimators/TraceManagerNew.h +++ b/src/Estimators/TraceManagerNew.h @@ -1160,8 +1160,6 @@ struct TraceManagerState bool writing_traces; int throttle; bool verbose; - std::string format; - bool hdf_format; std::string default_domain; }; @@ -1182,8 +1180,6 @@ class TraceCollector TraceBufferNew int_buffer; TraceBufferNew real_buffer; - static double trace_tol; - TraceRequestNew request; std::string default_domain; @@ -1192,17 +1188,11 @@ class TraceCollector bool writing_traces; int throttle; bool verbose; - std::string format; - bool hdf_format; - std::string file_root; - Communicate* communicator; - TraceCollector(Communicate* comm = 0) : verbose(false) + TraceCollector() : verbose(false) { reset_permissions(); - communicator = comm; throttle = 1; - format = "hdf"; default_domain = "scalars"; request.set_scalar_domain(default_domain); int_buffer.set_type("int"); @@ -1221,8 +1211,6 @@ class TraceCollector writing_traces = tms.writing_traces; throttle = tms.throttle; verbose = tms.verbose; - format = tms.format; - hdf_format = tms.hdf_format; default_domain = tms.default_domain; } @@ -1245,7 +1233,6 @@ class TraceCollector streaming_traces = false; writing_traces = false; verbose = false; - hdf_format = false; request.reset(); } @@ -1438,8 +1425,6 @@ class TraceCollector app_log() << pad2 << "method_allows_traces = " << method_allows_traces << std::endl; app_log() << pad2 << "streaming_traces = " << streaming_traces << std::endl; app_log() << pad2 << "writing_traces = " << writing_traces << std::endl; - app_log() << pad2 << "format = " << format << std::endl; - app_log() << pad2 << "hdf format = " << hdf_format << std::endl; app_log() << pad2 << "default_domain = " << default_domain << std::endl; int_buffer.write_summary(pad2); real_buffer.write_summary(pad2); @@ -1471,7 +1456,7 @@ class TraceCollector class TraceManagerNew { public: - static double trace_tol; + static double trace_tol; // remove this TraceRequestNew request; @@ -1507,8 +1492,6 @@ class TraceManagerNew tms.writing_traces = writing_traces; tms.throttle = throttle; tms.verbose = verbose; - tms.format = format; - tms.hdf_format = hdf_format; tms.default_domain = default_domain; return tms; } From 6e1ad00fc6da7a51531ba6a512cc494a264c27c5 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Tue, 21 May 2024 11:56:14 -0400 Subject: [PATCH 10/55] fix dmc walker traces --- src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp | 3 + tests/solids/diamondC_1x1x1_pp/CMakeLists.txt | 33 +++++-- ...xml => qmc_walkertrace_dmc_scalars.in.xml} | 5 +- .../qmc_walkertrace_vmc_scalars.in.xml | 92 +++++++++++++++++++ 4 files changed, 122 insertions(+), 11 deletions(-) rename tests/solids/diamondC_1x1x1_pp/{qmc_walkertrace_scalars.in.xml => qmc_walkertrace_dmc_scalars.in.xml} (98%) create mode 100644 tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_vmc_scalars.in.xml diff --git a/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp b/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp index 5fb7d657a1..39f1714f99 100644 --- a/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp +++ b/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp @@ -21,8 +21,10 @@ #include "QMCDrivers/DriftOperators.h" #if !defined(REMOVE_TRACEMANAGER) #include "Estimators/TraceManager.h" +#include "Estimators/TraceManagerNew.h" #else using TraceManager = int; +using TraceManagerNew = int; #endif //#define TEST_INNERBRANCH @@ -169,6 +171,7 @@ void DMCUpdatePbyPWithRejectionFast::advanceWalker(Walker_t& thisWalker, bool re } #if !defined(REMOVE_TRACEMANAGER) Traces->buffer_sample(W.current_step); + Traces_new->buffer_sample(W.current_step); #endif { ScopedTimer local_timer(myTimers[DMC_tmoves]); diff --git a/tests/solids/diamondC_1x1x1_pp/CMakeLists.txt b/tests/solids/diamondC_1x1x1_pp/CMakeLists.txt index 9b7a9791a2..d9a6ef5fe9 100644 --- a/tests/solids/diamondC_1x1x1_pp/CMakeLists.txt +++ b/tests/solids/diamondC_1x1x1_pp/CMakeLists.txt @@ -1876,14 +1876,14 @@ if(add_traces_tests) --dmc_steps_exclude=1) simple_run_and_check( - deterministic-diamondC_1x1x1_pp-vmc-dmc-walkertrace_scalars + deterministic-diamondC_1x1x1_pp-vmc-walkertrace_scalars "${qmcpack_SOURCE_DIR}/tests/solids/diamondC_1x1x1_pp" - qmc_walkertrace_scalars.in.xml + qmc_walkertrace_vmc_scalars.in.xml 1 1 check_traces.py -p - qmc_trace_scalars + qmc_trace_vmc_scalars -s 0 -m @@ -1891,16 +1891,16 @@ if(add_traces_tests) -q 'Kinetic,ElecElec,IonIon,LocalECP,NonLocalECP' --dmc_steps_exclude=1) - + simple_run_and_check( - deterministic-diamondC_1x1x1_pp-vmc-dmc-walkertrace_scalars + deterministic-diamondC_1x1x1_pp-vmc-walkertrace_scalars "${qmcpack_SOURCE_DIR}/tests/solids/diamondC_1x1x1_pp" - qmc_walkertrace_scalars.in.xml + qmc_walkertrace_vmc_scalars.in.xml 4 4 check_traces.py -p - qmc_trace_scalars + qmc_trace_vmc_scalars -n 4 -s @@ -1911,6 +1911,25 @@ if(add_traces_tests) 'Kinetic,ElecElec,IonIon,LocalECP,NonLocalECP' --dmc_steps_exclude=1) + simple_run_and_check( + deterministic-diamondC_1x1x1_pp-dmc-walkertrace_scalars + "${qmcpack_SOURCE_DIR}/tests/solids/diamondC_1x1x1_pp" + qmc_walkertrace_dmc_scalars.in.xml + 4 + 4 + check_traces.py + -p + qmc_trace_dmc_scalars + -n + 4 + -s + 1 + -m + dmc + -q + 'Kinetic,ElecElec,IonIon,LocalECP,NonLocalECP' + --dmc_steps_exclude=1) + endif() if(QMC_MIXED_PRECISION) diff --git a/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_scalars.in.xml b/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_dmc_scalars.in.xml similarity index 98% rename from tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_scalars.in.xml rename to tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_dmc_scalars.in.xml index 2b08a869a2..835ce8bf7d 100644 --- a/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_scalars.in.xml +++ b/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_dmc_scalars.in.xml @@ -1,6 +1,6 @@ - + @@ -89,7 +89,6 @@ 1 0.3 - - diff --git a/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_vmc_scalars.in.xml b/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_vmc_scalars.in.xml new file mode 100644 index 0000000000..0858ecfdf2 --- /dev/null +++ b/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_vmc_scalars.in.xml @@ -0,0 +1,92 @@ + + + + + + + + + + 3.37316115 3.37316115 0.00000000 + 0.00000000 3.37316115 3.37316115 + 3.37316115 0.00000000 3.37316115 + + + p p p + + 15 + + + + -1 + 1.0 + + + -1 + 1.0 + + + + + 4 + 4 + 6 + 21894.7135906 + + 0.00000000 0.00000000 0.00000000 + 1.68658058 1.68658058 1.68658058 + + + + + + + + + + + + + + + + +-0.2032153051 -0.1625595974 -0.143124599 -0.1216434956 -0.09919771951 -0.07111729038 +-0.04445345869 -0.02135082917 + + + + + + +0.2797730287 0.2172604155 0.1656172964 0.1216984261 0.083995349 0.05302065936 +0.02915953995 0.0122402581 + + + + +0.4631099906 0.356399124 0.2587895287 0.1829298509 0.1233653291 0.07714708174 +0.04145899033 0.01690645936 + + + + + + + + + + + + + + + + 2 + 2 + 4 + 2 + 1 + 0.3 + + From d4edf7211128d9e2bb5d50d7a1c0574909ffb30c Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Tue, 21 May 2024 12:42:59 -0400 Subject: [PATCH 11/55] consolidate state --- src/Estimators/TraceManagerNew.h | 265 ++++++++++--------------- src/QMCHamiltonians/QMCHamiltonian.cpp | 15 +- 2 files changed, 112 insertions(+), 168 deletions(-) diff --git a/src/Estimators/TraceManagerNew.h b/src/Estimators/TraceManagerNew.h index 0485f6ddea..a313c1c0e4 100644 --- a/src/Estimators/TraceManagerNew.h +++ b/src/Estimators/TraceManagerNew.h @@ -970,9 +970,6 @@ struct TraceBufferNew } - inline void write() { APP_ABORT("TraceBufferNew::write has not yet been implemented"); } - - inline void write_summary(std::string pad = " ") { std::string pad2 = pad + " "; @@ -1010,9 +1007,6 @@ struct TraceBufferNew } - inline void write_hdf(hdf_archive& f) { write_hdf(f, hdf_file_pointer); } - - inline void write_hdf(hdf_archive& f, hsize_t& file_pointer) { if (verbose) @@ -1154,13 +1148,38 @@ struct TraceBufferNew struct TraceManagerState { - bool method_allows_traces; TraceRequestNew request; + bool method_allows_traces; bool streaming_traces; bool writing_traces; int throttle; bool verbose; std::string default_domain; + + TraceManagerState() + { + reset_permissions(); + throttle = 1; + verbose = false; + default_domain = "scalars"; + request.set_scalar_domain(default_domain); + } + + inline void reset_permissions() + { + method_allows_traces = false; + streaming_traces = false; + writing_traces = false; + verbose = false; + request.reset(); + } + + inline void update_status() + { + streaming_traces = request.streaming(); + writing_traces = request.writing(); + } + }; @@ -1180,21 +1199,12 @@ class TraceCollector TraceBufferNew int_buffer; TraceBufferNew real_buffer; - TraceRequestNew request; + TraceManagerState state; - std::string default_domain; - bool method_allows_traces; - bool streaming_traces; - bool writing_traces; - int throttle; - bool verbose; - - TraceCollector() : verbose(false) + TraceCollector() { - reset_permissions(); - throttle = 1; - default_domain = "scalars"; - request.set_scalar_domain(default_domain); + state.reset_permissions(); + int_buffer.set_type("int"); real_buffer.set_type("real"); int_buffer.set_samples(int_samples); @@ -1205,63 +1215,38 @@ class TraceCollector inline void transfer_state_from(const TraceManagerState& tms) { - method_allows_traces = tms.method_allows_traces; - request = tms.request; - streaming_traces = tms.streaming_traces; - writing_traces = tms.writing_traces; - throttle = tms.throttle; - verbose = tms.verbose; - default_domain = tms.default_domain; + state = tms; } inline void distribute() { app_log()<<"JTK: TraceCollector::distribute"<* checkout_int(const std::string& name, int n1 = 1, int n2 = 0, int n3 = 0, int n4 = 0) { app_log()<<"JTK: TraceCollector::checkout_int"<(default_domain, name, n1, n2, n3, n4); + return checkout_int(state.default_domain, name, n1, n2, n3, n4); } template inline Array* checkout_int(const std::string& domain, @@ -1322,7 +1307,7 @@ class TraceCollector inline Array* checkout_real(const std::string& name, int n1 = 1, int n2 = 0, int n3 = 0, int n4 = 0) { app_log()<<"JTK: TraceCollector::checkout_real"<(default_domain, name, n1, n2, n3, n4); + return checkout_real(state.default_domain, name, n1, n2, n3, n4); } template inline Array* checkout_real(const std::string& domain, @@ -1354,7 +1339,7 @@ class TraceCollector inline Array* checkout_complex(const std::string& name, int n1 = 1, int n2 = 0, int n3 = 0, int n4 = 0) { app_log()<<"JTK: TraceCollector::checkout_complex"<(default_domain, name, n1, n2, n3, n4); + return checkout_complex(state.default_domain, name, n1, n2, n3, n4); } template inline Array* checkout_complex(const std::string& domain, @@ -1384,9 +1369,9 @@ class TraceCollector inline void reset_buffers() { app_log() << "JTK: TraceCollector::reset_buffers"<::iterator req; int_buffer.user_report(pad3); @@ -1458,48 +1443,28 @@ class TraceManagerNew public: static double trace_tol; // remove this - TraceRequestNew request; - - std::string default_domain; - bool method_allows_traces; - bool streaming_traces; - bool writing_traces; - int throttle; - bool verbose; - std::string format; - bool hdf_format; std::string file_root; Communicate* communicator; std::unique_ptr hdf_file; - TraceManagerNew(Communicate* comm = 0) : verbose(false) + TraceManagerState state; + + TraceManagerNew(Communicate* comm = 0) { - reset_permissions(); + state.reset_permissions(); communicator = comm; - throttle = 1; - format = "hdf"; - default_domain = "scalars"; - request.set_scalar_domain(default_domain); } inline TraceManagerState getState() { - TraceManagerState tms; - tms.method_allows_traces = method_allows_traces; - tms.request = request; - tms.streaming_traces = streaming_traces; - tms.writing_traces = writing_traces; - tms.throttle = throttle; - tms.verbose = verbose; - tms.default_domain = default_domain; - return tms; + return state; } inline TraceCollector* makeCollector() { app_log()<<"JTK: TraceManagerNew::makeCollector"<transfer_state_from(getState()); @@ -1508,37 +1473,25 @@ class TraceManagerNew } - inline void reset_permissions() - { - app_log()<<"JTK: TraceManagerNew::reset_permissions"<next; } - writing_traces &= method_allows_traces; + state.writing_traces &= state.method_allows_traces; //input user quantity requests into the traces request - request.allow_streams = method_allows_traces; - request.allow_writes = writing_traces; + TraceRequestNew& request = state.request; + request.allow_streams = state.method_allows_traces; + request.allow_writes = state.writing_traces; request.scalars_on = scalars_on; request.arrays_on = arrays_on; request.stream_all_scalars = use_scalar_defaults; request.stream_all_arrays = use_array_defaults; - request.write_all_scalars = request.stream_all_scalars && writing_traces; - request.write_all_arrays = request.stream_all_arrays && writing_traces; - request.request_scalar(scalar_requests, writing_traces); - request.request_array(array_requests, writing_traces); + request.write_all_scalars = request.stream_all_scalars && state.writing_traces; + request.write_all_arrays = request.stream_all_arrays && state.writing_traces; + request.request_scalar(scalar_requests, state.writing_traces); + request.request_array(array_requests, state.writing_traces); } } @@ -1641,10 +1585,10 @@ class TraceManagerNew inline void check_clones(std::vector& clones) { - app_log() << "JTK: TraceManagerNew::check_clones "< 0) + app_log() << "JTK: TraceManagerNew::check_clones "< 0) { - if (verbose) + if (state.verbose) app_log() << "TraceManagerNew::check_clones" << std::endl; bool all_same = true; bool int_same; @@ -1673,42 +1617,39 @@ class TraceManagerNew //write buffered trace data to file inline void write_buffers(std::vector& clones, int block) { - app_log() << "JTK: TraceManagerNew::write_buffers "<< writing_traces<& clones) { - app_log() << "JTK: TraceManagerNew::open_file "<< writing_traces<write_summary(); - if (hdf_format) - open_hdf_file(clones); + open_hdf_file(clones); } } inline void close_file() { - app_log() << "JTK: TraceManagerNew::close_file "<< writing_traces<& clones) { app_log() << "JTK: TraceManagerNew::startRun " << std::endl; - if (verbose) + if (state.verbose) app_log() << "TraceManagerNew::startRun " << std::endl; check_clones(clones); open_file(clones); @@ -1726,7 +1667,7 @@ class TraceManagerNew inline void stopRun() { app_log() << "JTK: TraceManagerNew::stopRun " << std::endl; - if (verbose) + if (state.verbose) app_log() << "TraceManagerNew::stopRun " << std::endl; close_file(); } @@ -1755,7 +1696,7 @@ class TraceManagerNew file_name.append(ptoken.data(), length); } file_name += ".traces.h5"; - if (verbose) + if (state.verbose) app_log() << "TraceManagerNew::open_hdf_file opening traces hdf file " << file_name << std::endl; hdf_file = std::make_unique(); bool successful = hdf_file->create(file_name); @@ -1772,7 +1713,7 @@ class TraceManagerNew inline void write_buffers_hdf(std::vector& clones) { app_log() << "JTK: TraceManagerNew::write_buffers_hdf " << std::endl; - if (verbose) + if (state.verbose) app_log() << "TraceManagerNew::write_buffers_hdf " << std::endl; TraceCollector& tm_lead = *clones[0]; for (int ip = 0; ip < clones.size(); ++ip) diff --git a/src/QMCHamiltonians/QMCHamiltonian.cpp b/src/QMCHamiltonians/QMCHamiltonian.cpp index 055a042ea5..9f1bfe1efd 100644 --- a/src/QMCHamiltonians/QMCHamiltonian.cpp +++ b/src/QMCHamiltonians/QMCHamiltonian.cpp @@ -550,7 +550,10 @@ void QMCHamiltonian::finalize_traces() void QMCHamiltonian::initialize_traces_new(TraceCollector& tm, ParticleSet& P) { static bool first_init_new = true; - bool trace_log = first_init_new && tm.verbose && omp_get_thread_num() == 0; + + TraceRequestNew& tm_request = tm.state.request; + TraceManagerState& tms = tm.state; + bool trace_log = first_init_new && tms.verbose && omp_get_thread_num() == 0; if (trace_log) app_log() << "\n Hamiltonian is initializing traces" << std::endl; @@ -575,23 +578,23 @@ void QMCHamiltonian::initialize_traces_new(TraceCollector& tm, ParticleSet& P) requests.push_back(&H[i]->getRequestNew()); //collect trace quantity availability/requests from contributors/requestors for (int i = 0; i < requests.size(); ++i) - tm.request.incorporate(*requests[i]); + tm_request.incorporate(*requests[i]); //balance requests with availability, mark quantities as streaming/writing - tm.request.determine_stream_write(); + tm_request.determine_stream_write(); //relay updated streaming information to all contributors/requestors for (int i = 0; i < requests.size(); ++i) - tm.request.relay_stream_info(*requests[i]); + tm_request.relay_stream_info(*requests[i]); //set streaming/writing traces in general - tm.update_status(); + tms.update_status(); // setup traces, if any quantities should be streaming // tracing bool tracing = request_new.streaming(); - if (tracing != tm.streaming_traces) + if (tracing != tms.streaming_traces) APP_ABORT("QMCHamiltonian::initialize_traces_new trace request failed to initialize properly"); if (!tracing) { From 6aeb13cda473e2b22656745e6d5b262e7b265b21 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Fri, 24 May 2024 12:53:27 -0400 Subject: [PATCH 12/55] operable buffers --- src/Estimators/TraceManagerNew.cpp | 204 +++++++++- src/Estimators/TraceManagerNew.h | 459 +++++++++++++++++++++-- src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp | 1 + src/QMCDrivers/VMC/VMCUpdatePbyP.cpp | 1 + 4 files changed, 621 insertions(+), 44 deletions(-) diff --git a/src/Estimators/TraceManagerNew.cpp b/src/Estimators/TraceManagerNew.cpp index 45ac8c4fae..19f4bdc72a 100644 --- a/src/Estimators/TraceManagerNew.cpp +++ b/src/Estimators/TraceManagerNew.cpp @@ -11,17 +11,215 @@ ////////////////////////////////////////////////////////////////////////////////////// -#if !defined(DISABLE_TRACEMANAGER) +#include "TraceManagerNew.h" +#include "Particle/Walker.h" +//#include "Particle/ParticleSet.h" +#include "QMCWaveFunctions/TrialWaveFunction.h" +#include "QMCHamiltonians/QMCHamiltonian.h" -#include "TraceManagerNew.h" namespace qmcplusplus { + +using MCPWalker = Walker; + + double TraceManagerNew::trace_tol = 1e-8; + + +template +void report_row(T& b) +{ + auto& buf = b.buffer; + auto irow = buf.size(0)-1; + for(size_t n=0;n; + //Configuration.h: using ParticleScalar = ParticleAttrib; + //Configuration.h: using ParticleGradient = ParticleAttrib; + //Configuration.h: using ParticleLaplacian = ParticleAttrib; + + app_log()<<"pset step: "< #include "OhmmsData/OhmmsElementBase.h" #include "OhmmsData/AttributeSet.h" @@ -33,16 +30,31 @@ #include #include #include +#include + + namespace qmcplusplus { //#define TRACE_CHECK + + const unsigned int DMAXNEW = 4; using TraceIntNew = long; using TraceRealNew = OHMMS_PRECISION; using TraceCompNew = std::complex; +const unsigned int WDMAX = 4; +using WTraceInt = long; +using WTraceReal = OHMMS_PRECISION_FULL; +using WTraceComp = std::complex; +#ifndef QMC_COMPLEX +using WTracePsiVal = WTraceReal; +#else +using WTracePsiVal = WTraceComp; +#endif + struct TraceQuantityNew { @@ -1145,6 +1157,298 @@ struct TraceBufferNew +struct WalkerQuantityInfo +{ + std::string name; + size_t dimension; + size_t size; + size_t unit_size; + TinyVector shape; + size_t buffer_start; + size_t buffer_end; + + WalkerQuantityInfo(const std::string& name_,size_t unit_size_,size_t buffer_start_,size_t n1=1,size_t n2=0,size_t n3=0,size_t n4=0) + { + name = name_; + unit_size = unit_size_; + buffer_start = buffer_start_; + shape[0] = n1; + shape[1] = n2; + shape[2] = n3; + shape[3] = n4; + + dimension = 0; + size = 1; + for (size_t d=0;d0) + { + dimension++; + size *= shape[d]; + } + buffer_end = buffer_start + size*unit_size; + } +}; + + + +template +struct WalkerTraceBuffer +{ + Array buffer; + bool verbose; + + size_t walker_data_size; + std::vector quantity_info; + + bool first_collect; + size_t quantity_pointer; + size_t row_start_pointer; + size_t row_end_pointer; + + //hdf variables + std::string label; + hsize_t dims[2]; + hsize_t hdf_file_pointer; + + WalkerTraceBuffer() + { + label = "?"; + verbose = false; + first_collect = true; + walker_data_size = 0; + quantity_pointer = 0; + reset_buffer(); + } + + + inline void reset_buffer() + { + buffer.resize(0, buffer.size(1)); + row_start_pointer = 0; + row_end_pointer = 0; + } + + + inline void reset_collect() + { + if(quantity_pointer!=quantity_info.size()) + {/*throw exception*/} + first_collect = false; + quantity_pointer = 0; + } + + inline void reset_step() + { + row_start_pointer = row_end_pointer; + } + + inline void reset_block() + { + reset_buffer(); + } + + + inline bool same_as(WalkerTraceBuffer& ref) + { + return buffer.size(1) == ref.buffer.size(1); + } + + + inline void reset_rowsize(size_t row_size) + { + auto nrows = buffer.size(0); + if(nrows==0) + nrows++; + if(nrows!=1) + {/*throw exception*/} + auto buffer_old(buffer); + buffer.resize(nrows,row_size); + std::copy_n(buffer_old.data(), buffer_old.size(), buffer.data()); + if(buffer.size(0)!=1) + {/*throw exception*/} + if(buffer.size(1)!=row_size) + {/*throw exception*/} + } + + + inline void make_new_row() + { + size_t nrows = buffer.size(0); + size_t row_size = buffer.size(1); + if (row_size==0) + { + // throw an exception + } + nrows++; + // resizing buffer(type Array) doesn't preserve data. Thus keep old data and copy over + auto buffer_old(buffer); + buffer.resize(nrows, row_size); + std::copy_n(buffer_old.data(), buffer_old.size(), buffer.data()); + } + + + inline void collect(const std::string& name, const T& value) + { + if (verbose) + app_log() << "WalkerTraceBuffer(" << label << ")::collect_sample()" << std::endl; + size_t irow=0; + if( first_collect ) + { + WalkerQuantityInfo wqi_(name,1,walker_data_size); + quantity_info.push_back(wqi_); + walker_data_size = wqi_.buffer_end; + reset_rowsize(walker_data_size); + } + else + { + if(quantity_pointer==0) + make_new_row(); + irow = buffer.size(0)-1; + } + auto& wqi = quantity_info[quantity_pointer]; + buffer(irow,wqi.buffer_start) = value; + quantity_pointer++; + } + + + template + inline void collect(const std::string& name, Array arr) + { + size_t n1 = arr.size(0); + size_t n2,n3,n4; + n2=n3=n4=0; + if (D>4) + {/*throw exception*/} + if (D>1) n2 = arr.size(1); + if (D>2) n3 = arr.size(2); + if (D>3) n4 = arr.size(3); + size_t irow=0; + if( first_collect ) + { + WalkerQuantityInfo wqi_(name,1,walker_data_size,n1,n2,n3,n4); + quantity_info.push_back(wqi_); + walker_data_size = wqi_.buffer_end; + reset_rowsize(walker_data_size); + } + else + { + if(quantity_pointer==0) + make_new_row(); + irow = buffer.size(0)-1; + } + auto& wqi = quantity_info[quantity_pointer]; + auto& arr1d = arr.storage(); + for (size_t n=0;n + inline void collect(const std::string& name, Array,D> arr) + { + size_t n1 = arr.size(0); + size_t n2,n3,n4; + n2=n3=n4=0; + if (D>4) + {/*throw exception*/} + if (D>1) n2 = arr.size(1); + if (D>2) n3 = arr.size(2); + if (D>3) n4 = arr.size(3); + size_t irow=0; + if( first_collect ) + { + WalkerQuantityInfo wqi_(name,2,walker_data_size,n1,n2,n3,n4); + quantity_info.push_back(wqi_); + walker_data_size = wqi_.buffer_end; + reset_rowsize(walker_data_size); + } + else + { + if(quantity_pointer==0) + make_new_row(); + irow = buffer.size(0)-1; + } + auto& wqi = quantity_info[quantity_pointer]; + auto& arr1d = arr.storage(); + size_t n = 0; + for (size_t i=0;i other_buffer, size_t i) + { + if(buffer.size(1)!=other_buffer.size(1)) + { + // throw an exception + } + make_new_row(); + size_t ib = buffer.size(0)-1; + for(size_t j=0;jregister_hdf_data(f); + //if (has_complex) + // complex_samples->register_hdf_data(f); + f.pop(); + f.pop(); + if (!f.open_groups()) + APP_ABORT("WalkerTraceBuffer(" + label + + ")::register_hdf_data() some hdf groups are still open at the end of registration"); + hdf_file_pointer = 0; + } + + + inline void write_hdf(hdf_archive& f, hsize_t& file_pointer) + { + if (verbose) + app_log() << "WalkerTraceBuffer(" << label << ")::write_hdf() " << file_pointer << " " << buffer.size(0) << " " + << buffer.size(1) << std::endl; + dims[0] = buffer.size(0); + dims[1] = buffer.size(1); + if (dims[0] > 0) + { + f.push(label); + h5d_append(f.top(), "data", file_pointer, buffer.dim(), dims, buffer.data()); + f.pop(); + } + f.flush(); + } +}; + +//template class WalkerTraceBuffer; +//template class WalkerTraceBuffer; + + + + struct TraceManagerState { @@ -1184,6 +1488,14 @@ struct TraceManagerState +template class Walker; +//class ParticleSet; +class TrialWaveFunction; +class QMCHamiltonian; +using MCPWalker = Walker; + + + class TraceCollector { public: @@ -1193,15 +1505,34 @@ class TraceCollector TraceSampleNews real_samples; TraceSampleNews comp_samples; + + TraceManagerState state; + //buffers for storing samples // single row of buffer is a single sample from one walker // number of rows adjusts to accommodate walker samples TraceBufferNew int_buffer; TraceBufferNew real_buffer; - TraceManagerState state; + // new walker buffers + std::unordered_set properties_include; + std::vector property_indices; + int energy_index; + + std::vector energies; + WalkerTraceBuffer walker_property_int_buffer; + WalkerTraceBuffer walker_property_real_buffer; + WalkerTraceBuffer walker_particle_real_buffer; + + // temporary (contiguous) storage for awful ParticleAttrib<> quantities + Array Rtmp; + Array Stmp; + Array Gtmp; + Array Ltmp; + TraceCollector() + : properties_include{"R2Accepted","R2Proposed","LocalEnergy","LocalPotential","Kinetic","ElecElec","ElecIon","LocalECP","NonLocalECP"} { state.reset_permissions(); @@ -1210,18 +1541,32 @@ class TraceCollector int_buffer.set_samples(int_samples); real_buffer.set_samples(real_samples); real_buffer.set_samples(comp_samples); + + // new walker buffers, etc + energy_index = -1; + energies.resize(0); + walker_property_int_buffer.label = "walker_property_int"; + walker_property_real_buffer.label = "walker_property_real"; + walker_particle_real_buffer.label = "walker_particle_real"; } inline void transfer_state_from(const TraceManagerState& tms) { + // JTK: rename this function as "setState" state = tms; } + inline void reset_step() + { + energies.resize(0); + } + inline void distribute() { - app_log()<<"JTK: TraceCollector::distribute"< wmin_property_int_buffer; + WalkerTraceBuffer wmin_property_real_buffer; + WalkerTraceBuffer wmin_particle_real_buffer; + + WalkerTraceBuffer wmax_property_int_buffer; + WalkerTraceBuffer wmax_property_real_buffer; + WalkerTraceBuffer wmax_particle_real_buffer; + + WalkerTraceBuffer wmed_property_int_buffer; + WalkerTraceBuffer wmed_property_real_buffer; + WalkerTraceBuffer wmed_particle_real_buffer; + + TraceManagerNew(Communicate* comm = 0) { state.reset_permissions(); communicator = comm; + + // new walker buffers, etc + write_particle_data = false; + write_min_data = true; + write_max_data = true; + write_med_data = true; + + wmin_property_int_buffer.label = "wmin_property_int"; + wmin_property_real_buffer.label = "wmin_property_real"; + wmin_particle_real_buffer.label = "wmin_particle_real"; + + wmax_property_int_buffer.label = "wmax_property_int"; + wmax_property_real_buffer.label = "wmax_property_real"; + wmax_particle_real_buffer.label = "wmax_particle_real"; + + wmed_property_int_buffer.label = "wmed_property_int"; + wmed_property_real_buffer.label = "wmed_property_real"; + wmed_particle_real_buffer.label = "wmed_particle_real"; } @@ -1463,7 +1853,6 @@ class TraceManagerNew inline TraceCollector* makeCollector() { - app_log()<<"JTK: TraceManagerNew::makeCollector"<& clones) { - app_log() << "JTK: TraceManagerNew::check_clones "< 0) { - if (state.verbose) - app_log() << "TraceManagerNew::check_clones" << std::endl; bool all_same = true; bool int_same; bool real_same; @@ -1617,7 +2003,8 @@ class TraceManagerNew //write buffered trace data to file inline void write_buffers(std::vector& clones, int block) { - app_log() << "JTK: TraceManagerNew::write_buffers "<< state.writing_traces<& clones) { - app_log() << "JTK: TraceManagerNew::open_file "<< state.writing_traces<write_summary(); open_hdf_file(clones); @@ -1644,19 +2030,15 @@ class TraceManagerNew inline void close_file() { - app_log() << "JTK: TraceManagerNew::close_file "<< state.writing_traces<& clones) { - app_log() << "JTK: TraceManagerNew::startRun " << std::endl; if (state.verbose) app_log() << "TraceManagerNew::startRun " << std::endl; check_clones(clones); @@ -1666,7 +2048,6 @@ class TraceManagerNew inline void stopRun() { - app_log() << "JTK: TraceManagerNew::stopRun " << std::endl; if (state.verbose) app_log() << "TraceManagerNew::stopRun " << std::endl; close_file(); @@ -1675,7 +2056,8 @@ class TraceManagerNew //hdf file operations inline void open_hdf_file(std::vector& clones) { - app_log() << "JTK: TraceManagerNew::open_hdf_file " << std::endl; + if (state.verbose) + app_log() << "TraceManagerNew::open_hdf_file " << std::endl; if (clones.size() == 0) APP_ABORT("TraceManagerNew::open_hdf_file no trace clones exist, cannot open file"); int nprocs = communicator->size(); @@ -1712,7 +2094,6 @@ class TraceManagerNew inline void write_buffers_hdf(std::vector& clones) { - app_log() << "JTK: TraceManagerNew::write_buffers_hdf " << std::endl; if (state.verbose) app_log() << "TraceManagerNew::write_buffers_hdf " << std::endl; TraceCollector& tm_lead = *clones[0]; @@ -1725,9 +2106,11 @@ class TraceManagerNew } inline void close_hdf_file() { - app_log() << "JTK: TraceManagerNew::close_hdf_file " << std::endl; + if (state.verbose) + app_log() << "TraceManagerNew::close_hdf_file " << std::endl; hdf_file.reset(); } + }; @@ -1736,11 +2119,5 @@ class TraceManagerNew } // namespace qmcplusplus -#else - -// no vacuous class: new tracemanager always supported - -#endif - #endif diff --git a/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp b/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp index 39f1714f99..0fd416afff 100644 --- a/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp +++ b/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp @@ -172,6 +172,7 @@ void DMCUpdatePbyPWithRejectionFast::advanceWalker(Walker_t& thisWalker, bool re #if !defined(REMOVE_TRACEMANAGER) Traces->buffer_sample(W.current_step); Traces_new->buffer_sample(W.current_step); + Traces_new->collect(thisWalker,W,Psi,H); #endif { ScopedTimer local_timer(myTimers[DMC_tmoves]); diff --git a/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp b/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp index cfd08ee7f6..5d05f7f996 100644 --- a/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp +++ b/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp @@ -134,6 +134,7 @@ void VMCUpdatePbyP::advanceWalker(Walker_t& thisWalker, bool recompute) #if !defined(REMOVE_TRACEMANAGER) Traces->buffer_sample(W.current_step); Traces_new->buffer_sample(W.current_step); + Traces_new->collect(thisWalker,W,Psi,H); #endif if (!moved) ++nAllRejected; From b0b9175394812b995c77fd16cb91f08d37c94afe Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Fri, 24 May 2024 17:16:10 -0400 Subject: [PATCH 13/55] wtrace buffers work --- src/Estimators/TraceManagerNew.cpp | 127 ++++++------------------- src/Estimators/TraceManagerNew.h | 111 +++++++++++++-------- src/QMCHamiltonians/QMCHamiltonian.cpp | 4 +- 3 files changed, 103 insertions(+), 139 deletions(-) diff --git a/src/Estimators/TraceManagerNew.cpp b/src/Estimators/TraceManagerNew.cpp index 19f4bdc72a..f992c9fa36 100644 --- a/src/Estimators/TraceManagerNew.cpp +++ b/src/Estimators/TraceManagerNew.cpp @@ -43,10 +43,27 @@ void report_row(T& b) } } +template +void report_buffer(WalkerTraceBuffer& wtb) +{ + auto& b = wtb.buffer; + for (size_t r=0;r; - //Configuration.h: using ParticleScalar = ParticleAttrib; - //Configuration.h: using ParticleGradient = ParticleAttrib; - //Configuration.h: using ParticleLaplacian = ParticleAttrib; - - app_log()<<"pset step: "< 0) { f.push(top); @@ -1033,6 +1034,7 @@ struct TraceBufferNew f.pop(); } f.flush(); + app_log()<<" "< other_buffer, size_t i) { + app_log()<<"WalkerTraceBuffer("<register_hdf_data(f); - //if (has_complex) - // complex_samples->register_hdf_data(f); + for(auto& wqi: quantity_info) + { + f.push(wqi.name); + f.write(wqi.dimension, "dimension" ); + f.write(wqi.shape, "shape" ); + f.write(wqi.size, "size" ); + f.write(wqi.unit_size, "unit_size" ); + f.write(wqi.buffer_start, "index_start"); + f.write(wqi.buffer_end, "index_end" ); + f.pop(); + } f.pop(); f.pop(); if (!f.open_groups()) @@ -1428,18 +1446,22 @@ struct WalkerTraceBuffer inline void write_hdf(hdf_archive& f, hsize_t& file_pointer) { - if (verbose) - app_log() << "WalkerTraceBuffer(" << label << ")::write_hdf() " << file_pointer << " " << buffer.size(0) << " " - << buffer.size(1) << std::endl; + app_log()<<"WalkerTraceBuffer("< 0) { - f.push(label); + f.push(top); h5d_append(f.top(), "data", file_pointer, buffer.dim(), dims, buffer.data()); f.pop(); } f.flush(); + app_log()<<" "< int_samples; + TraceSampleNews int_samples; TraceSampleNews real_samples; TraceSampleNews comp_samples; @@ -1511,12 +1533,12 @@ class TraceCollector //buffers for storing samples // single row of buffer is a single sample from one walker // number of rows adjusts to accommodate walker samples - TraceBufferNew int_buffer; + TraceBufferNew int_buffer; TraceBufferNew real_buffer; // new walker buffers std::unordered_set properties_include; - std::vector property_indices; + std::vector property_indices; int energy_index; std::vector energies; @@ -1712,14 +1734,17 @@ class TraceCollector inline void reset_buffers() { - app_log() << "JTK: TraceCollector::reset_buffers"<::iterator req; - int_buffer.user_report(pad3); - real_buffer.user_report(pad3); - app_log() << std::endl; - } - - //void collect(MCPWalker& walker, ParticleSet& pset, TrialWaveFunction& wfn); void collect(MCPWalker& walker, ParticleSet& pset, TrialWaveFunction& wfn, QMCHamiltonian& ham); @@ -1799,6 +1807,7 @@ class TraceManagerNew std::string file_root; Communicate* communicator; std::unique_ptr hdf_file; + bool registered_hdf; TraceManagerState state; @@ -1826,6 +1835,8 @@ class TraceManagerNew state.reset_permissions(); communicator = comm; + registered_hdf = false; + // new walker buffers, etc write_particle_data = false; write_min_data = true; @@ -2008,8 +2019,6 @@ class TraceManagerNew if (state.writing_traces) { //double tstart = MPI_Wtime(); - if (state.verbose) - app_log() << "TraceManagerNew::write_buffers " << std::endl; write_buffers_hdf(clones); } } @@ -2077,7 +2086,7 @@ class TraceManagerNew throw std::runtime_error("Error generating filename"); file_name.append(ptoken.data(), length); } - file_name += ".traces.h5"; + file_name += ".wtraces.h5"; if (state.verbose) app_log() << "TraceManagerNew::open_hdf_file opening traces hdf file " << file_name << std::endl; hdf_file = std::make_unique(); @@ -2087,8 +2096,13 @@ class TraceManagerNew // only clones have active buffers and associated data TraceCollector& tm = *clones[0]; //tm.write_summary(); - tm.int_buffer.register_hdf_data(*hdf_file); - tm.real_buffer.register_hdf_data(*hdf_file); + + //tm.int_buffer.register_hdf_data(*hdf_file); + //tm.real_buffer.register_hdf_data(*hdf_file); + // + //tm.walker_property_int_buffer.register_hdf_data(*hdf_file); + //tm.walker_property_real_buffer.register_hdf_data(*hdf_file); + //tm.walker_particle_real_buffer.register_hdf_data(*hdf_file); } @@ -2097,11 +2111,26 @@ class TraceManagerNew if (state.verbose) app_log() << "TraceManagerNew::write_buffers_hdf " << std::endl; TraceCollector& tm_lead = *clones[0]; + if(!registered_hdf) + { + //tm_lead.int_buffer.register_hdf_data(*hdf_file); + //tm_lead.real_buffer.register_hdf_data(*hdf_file); + + tm_lead.walker_property_int_buffer.register_hdf_data(*hdf_file); + tm_lead.walker_property_real_buffer.register_hdf_data(*hdf_file); + tm_lead.walker_particle_real_buffer.register_hdf_data(*hdf_file); + + registered_hdf = true; + } for (int ip = 0; ip < clones.size(); ++ip) { TraceCollector& tm = *clones[ip]; - tm.int_buffer.write_hdf(*hdf_file, tm_lead.int_buffer.hdf_file_pointer); - tm.real_buffer.write_hdf(*hdf_file, tm_lead.real_buffer.hdf_file_pointer); + //tm.int_buffer.write_hdf(*hdf_file, tm_lead.int_buffer.hdf_file_pointer); + //tm.real_buffer.write_hdf(*hdf_file, tm_lead.real_buffer.hdf_file_pointer); + + tm.walker_property_int_buffer.write_hdf(*hdf_file, tm_lead.walker_property_int_buffer.hdf_file_pointer); + tm.walker_property_real_buffer.write_hdf(*hdf_file, tm_lead.walker_property_real_buffer.hdf_file_pointer); + tm.walker_particle_real_buffer.write_hdf(*hdf_file, tm_lead.walker_particle_real_buffer.hdf_file_pointer); } } diff --git a/src/QMCHamiltonians/QMCHamiltonian.cpp b/src/QMCHamiltonians/QMCHamiltonian.cpp index 9f1bfe1efd..c955f9828e 100644 --- a/src/QMCHamiltonians/QMCHamiltonian.cpp +++ b/src/QMCHamiltonians/QMCHamiltonian.cpp @@ -636,8 +636,8 @@ void QMCHamiltonian::initialize_traces_new(TraceCollector& tm, ParticleSet& P) tm.screen_writes(); //write traces status to the log - if (trace_log) - tm.user_report(); + //if (trace_log) + // tm.user_report(); first_init_new = false; } From a1b48c272176d32c2807ea978a482b882562a071 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Mon, 27 May 2024 23:37:21 -0400 Subject: [PATCH 14/55] roll tests over to walker traces --- tests/scripts/check_wtraces.py | 1411 +++++++++++++++++ tests/solids/diamondC_1x1x1_pp/CMakeLists.txt | 12 +- 2 files changed, 1414 insertions(+), 9 deletions(-) create mode 100755 tests/scripts/check_wtraces.py diff --git a/tests/scripts/check_wtraces.py b/tests/scripts/check_wtraces.py new file mode 100755 index 0000000000..45ead77251 --- /dev/null +++ b/tests/scripts/check_wtraces.py @@ -0,0 +1,1411 @@ +#! /usr/bin/env python3 + +# Performs consistency checks between traces.h5 and scalar.dat/stat.h5/dmc.dat files +# Jaron Krogel/ORNL + +# Type the following to view documentation for command line inputs: +# >check_wtraces.py -h + +# For usage examples, type: +# >check_wtraces.py -x + +# check_traces.py packages obj and HDFreader classes from Nexus. +# Note that h5py is required (which depends on numpy). +# This script is compatible with both Python 2 and 3. + +import os +import sys +from copy import deepcopy +import numpy as np +import h5py +from optparse import OptionParser + +# Returns failure error code to OS. +# Explicitly prints 'fail' after an optional message. +def test_fail(): + print('\n\nTest status: fail') + sys.exit(1) +#end def test_fail + + +# Returns success error code to OS. +# Explicitly prints 'pass' after an optional message. +def test_pass(): + print('\n\nTest status: pass') + sys.exit(0) +#end def test_pass + + + +###################################################################### +# from generic.py +###################################################################### + +logfile = sys.stdout + +def log(msg,n=0,indent=' '): + if not isinstance(msg,str): + msg = str(msg) + #end if + if n>0: + indent = n*indent + msg=indent+msg.replace('\n','\n'+indent) + #end if + logfile.write(msg+'\n') +#end def log + + +def error(msg,header=None,n=0): + post_header=' error:' + if header is None: + header = post_header.lstrip() + else: + header += post_header + #end if + log('\n '+header,n=n) + log(msg.rstrip(),n=n) + log(' exiting.\n') + test_fail() +#end def error + + + +class object_interface(object): + _logfile = sys.stdout + + def __len__(self): + return len(self.__dict__) + #end def __len__ + + def __contains__(self,name): + return name in self.__dict__ + #end def + + def __getitem__(self,name): + return self.__dict__[name] + #end def __getitem__ + + def __setitem__(self,name,value): + self.__dict__[name]=value + #end def __setitem__ + + def __delitem__(self,name): + del self.__dict__[name] + #end def __delitem__ + + def __iter__(self): + for item in self.__dict__: + yield self.__dict__[item] + #end for + #end def __iter__ + + def __repr__(self): + s='' + for k in sorted(self.keys()): + if not isinstance(k,str) or k[0]!='_': + v=self.__dict__[k] + if hasattr(v,'__class__'): + s+=' {0:<20} {1:<20}\n'.format(str(k),v.__class__.__name__) + else: + s+=' {0:<20} {1:<20}\n'.format(str(k),type(v)) + #end if + #end if + #end for + return s + #end def __repr__ + + def __str__(self,nindent=1): + pad = ' ' + npad = nindent*pad + s='' + normal = [] + qable = [] + for k,v in self.items(): + if not isinstance(k,str) or k[0]!='_': + if isinstance(v,object_interface): + qable.append(k) + else: + normal.append(k) + #end if + #end if + #end for + normal = sorted(normal) + qable = sorted(qable) + indent = npad+18*' ' + for k in normal: + v = self[k] + vstr = str(v).replace('\n','\n'+indent) + s+=npad+'{0:<15} = '.format(str(k))+vstr+'\n' + #end for + for k in qable: + v = self[k] + s+=npad+str(k)+'\n' + s+=v.__str__(nindent+1) + if isinstance(k,str): + s+=npad+'end '+k+'\n' + #end if + #end for + return s + #end def __str__ + + def keys(self): + return self.__dict__.keys() + #end def keys + + def values(self): + return self.__dict__.values() + #end def values + + def items(self): + return self.__dict__.items() + #end def items + + def copy(self): + return deepcopy(self) + #end def copy + + def clear(self): + self.__dict__.clear() + #end def clear + + def log(self,*items,**kwargs): + log(*items,**kwargs) + #end def log + + def error(self,message,header=None,n=0): + if header is None: + header = self.__class__.__name__ + #end if + error(message,header,n=n) + #end def error +#end class object_interface + + + +class obj(object_interface): + def __init__(self,*vars,**kwargs): + for var in vars: + if isinstance(var,(dict,object_interface)): + for k,v in var.items(): + self[k] = v + #end for + else: + self[var] = None + #end if + #end for + for k,v in kwargs.items(): + self[k] = v + #end for + #end def __init__ + + def append(self,value): + self[len(self)] = value + #end def append + + def first(self): + return self[min(self.keys())] + #end def first +#end class obj + +###################################################################### +# end from generic.py +###################################################################### + + + +###################################################################### +# from developer.py +###################################################################### + +class DevBase(obj): + None +#end class DevBase + +###################################################################### +# end from developer.py +###################################################################### + + + + +###################################################################### +# from hdfreader.py +###################################################################### +import keyword +from inspect import getmembers + +class HDFglobals(DevBase): + view = False +#end class HDFglobals + + +class HDFgroup(DevBase): + def _escape_name(self,name): + if name in self._escape_names: + name=name+'_' + #end if + return name + #end def escape_name + + def _set_parent(self,parent): + self._parent=parent + return + #end def set_parent + + def _add_dataset(self,name,dataset): + self._datasets[name]=dataset + return + #end def add_dataset + + def _add_group(self,name,group): + group._name=name + self._groups[name]=group + return + #end def add_group + + def _contains_group(self,name): + return name in self._groups.keys() + #end def _contains_group + + def _contains_dataset(self,name): + return name in self._datasets.keys() + #end def _contains_dataset + + + def __init__(self): + self._name='' + self._parent=None + self._groups={}; + self._datasets={}; + self._group_counts={} + + self._escape_names=None + self._escape_names=set(dict(getmembers(self)).keys()) | set(keyword.kwlist) + return + #end def __init__ + + + def _remove_hidden(self,deep=True): + if '_parent' in self: + del self._parent + #end if + if deep: + for name,value in self.items(): + if isinstance(value,HDFgroup): + value._remove_hidden() + #end if + #end for + #end if + for name in list(self.keys()): + if name[0]=='_': + del self[name] + #end if + #end for + #end def _remove_hidden + + + # read in all data views (h5py datasets) into arrays + # useful for converting a single group read in view form to full arrays + def read_arrays(self): + self._remove_hidden() + for k,v in self.items(): + if isinstance(v,HDFgroup): + v.read_arrays() + else: + self[k] = np.array(v) + #end if + #end for + #end def read_arrays + + + def get_keys(self): + if '_groups' in self: + keys = list(self._groups.keys()) + else: + keys = list(self.keys()) + #end if + return keys + #end def get_keys +#end class HDFgroup + + + + +class HDFreader(DevBase): + + def __init__(self,fpath,verbose=False,view=False): + + HDFglobals.view = view + + if verbose: + print(' Initializing HDFreader') + #end if + + self.fpath=fpath + if verbose: + print(' loading h5 file') + #end if + + try: + self.hdf = h5py.File(fpath,'r') + except IOError: + self._success = False + self.hdf = obj(obj=obj()) + else: + self._success = True + #end if + + if verbose: + print(' converting h5 file to dynamic object') + #end if + + #convert the hdf 'dict' into a dynamic object + self.nlevels=1 + self.ilevel=0 + # Set the current hdf group + self.obj = HDFgroup() + self.cur=[self.obj] + self.hcur=[self.hdf] + + if self._success: + cur = self.cur[self.ilevel] + hcur = self.hcur[self.ilevel] + for kr,v in hcur.items(): + k=cur._escape_name(kr) + if isinstance(v, h5py.Dataset): + self.add_dataset(cur,k,v) + elif isinstance(v, h5py.Group): + self.add_group(hcur,cur,k,v) + else: + self.error('encountered invalid type: '+str(type(v))) + #end if + #end for + #end if + + if verbose: + print(' end HDFreader Initialization') + #end if + + return + #end def __init__ + + + def increment_level(self): + self.ilevel+=1 + self.nlevels = max(self.ilevel+1,self.nlevels) + if self.ilevel+1==self.nlevels: + self.cur.append(None) + self.hcur.append(None) + #end if + self.pad = self.ilevel*' ' + return + #end def increment_level + + def decrement_level(self): + self.ilevel-=1 + self.pad = self.ilevel*' ' + return + #end def decrement_level + + def add_dataset(self,cur,k,v): + if not HDFglobals.view: + cur[k] = np.array(v) + else: + cur[k] = v + #end if + cur._add_dataset(k,cur[k]) + return + #end def add_dataset + + def add_group(self,hcur,cur,k,v): + cur[k] = HDFgroup() + cur._add_group(k,cur[k]) + cur._groups[k]._parent = cur + self.increment_level() + self.cur[self.ilevel] = cur._groups[k] + self.hcur[self.ilevel] = hcur[k] + + cur = self.cur[self.ilevel] + hcur = self.hcur[self.ilevel] + for kr,v in hcur.items(): + k=cur._escape_name(kr) + if isinstance(v, h5py.Dataset): + self.add_dataset(cur,k,v) + elif isinstance(v, h5py.Group): + self.add_group(hcur,cur,k,v) + #end if + #end for + #end def add_group +#end class HDFreader + +###################################################################### +# end from hdfreader.py +###################################################################### + + + +# Represents QMCPACK data file. +# Used to read scalar.dat, stat.h5, dmc.dat, traces.h5 +class DataFile(DevBase): + + aliases = None + + def __init__(self,filepath=None,quantities=None): + self.data = None + self.filepath = filepath + self.quantities = None + if quantities is not None: + self.quantities = list(quantities) + #end if + if filepath is not None: + self.read(filepath) + if self.aliases is not None: + for name,alias in self.aliases.items(): + if name in self.data: + self.data[alias] = self.data[name] + del self.data[name] + #end if + #end for + #end if + if quantities is not None: + missing = set(quantities)-set(self.data.keys()) + if len(missing)>0: + self.error('some quantities are missing from file "{}"\nquantities present: {}\nquantities missing: {}'.format(self.filepath,sorted(self.data.keys()),sorted(missing))) + #end if + #end if + #end if + #end def __init__ + + def read(self,filepath): + None + #end def read +#end class DataFile + + +# Used to parse scalar.dat and dmc.dat files +class DatFile(DataFile): + def read(self,filepath): + lt = np.loadtxt(filepath) + if len(lt.shape)==1: + lt.shape = (1,len(lt)) + #end if + + data = lt[:,1:].transpose() + + fobj = open(filepath,'r') + variables = fobj.readline().split()[2:] + fobj.close() + + self.data = obj() + for i,vname in enumerate(variables): + self.data[vname]=data[i,:] + #end for + #end def read +#end class DatFile + + +# Parses scalar.dat +class ScalarDatFile(DatFile): + aliases = obj(BlockWeight='Weight') +#end class ScalarDat + + +# Parses dmc.dat +class DmcDatFile(DatFile): + None +#end class DmcDatFile + + + +# Parses scalar data from stat.h5 +class ScalarHDFFile(DataFile): + def read(self,filepath): + hr = HDFreader(filepath) + if not hr._success: + self.error('hdf file read failed\nfile path: '+filepath) + #end if + data = hr.obj + data._remove_hidden() + + self.data = obj() + for name,value in data.items(): + if 'value' in value: + self.data[name] = value.value.flatten() + #end if + #end for + #end def read +#end class ScalarHDFFile + + + +# Parses and organizes data from traces.h5. +# QMCPACK writes one traces.h5 for each MPI task. +# At every MC step, data from each walker is written to this file. +class TracesFileHDF(DataFile): + def __init__(self,filepath=None,blocks=None): + self.info = obj( + blocks = blocks, + particle_sums_valid = None, + ) + DataFile.__init__(self,filepath) + #end def __init__ + + + def read(self,filepath=None): + # Open the wtraces.h5 file + hr = HDFreader(filepath) + if not hr._success: + self.error('hdf file read failed\nfile path: '+filepath) + #end if + hdf = hr.obj + hdf._remove_hidden() + + # Translate from flat table structure to nested data structure. + # Do this for top level "int_data" and "real_data" HDF groups + for name,buffer in hdf.items(): + self.init_trace(name,buffer) + #end for + + # Sum trace data over walkers into per-step and per-block totals + self.accumulate_scalars() + #end def read + + + # Translate from serialized traces table format to fully dimensioned + # data resolved by physical quantity. + def init_trace(self,name,fbuffer): + aliases = obj( + walker_property_int = 'int_traces', + walker_property_real = 'real_traces', + ) + dname = 'scalars' + if name not in aliases.keys(): + return + #end if + trace = obj() + if 'data' in fbuffer: + # Wide data table + # Each row corresponds to a single step of a single walker. + # Each row contains serialized scalar (e.g. LocalEnergy) + # and array (e.g. electron coordinates) data. + ftrace = fbuffer.data + + # Number of rows (walkers*steps for single mpi task) + nrows = len(ftrace) + + # Serialization layout of each row is stored in "layout". + # Layout is separated into a few potential domains: + # scalar domain : scalar quantities such as LocalEnergy + # domain name is "scalars" + # electron domain: array quantities dimensioned like number of electrons (e.g. electron positions) + # domain name follows particleset (often "e") + # ion domain : array quantities dimensioned like number of ions + # domain name follows particleset (often "ion0") + # Get start and end row indices for each quantity + domain = obj() + for qname,fquantity in fbuffer.data_layout.items(): + q = obj() + for vname,value in fquantity.items(): + q[vname] = value + #end for + + # extract per quantity data across all walkers and steps + quantity = ftrace[:,q.index_start:q.index_end] + + # reshape from serialized to multidimensional data for the quantity + if q.unit_size==1: + shape = [nrows]+list(fquantity.shape[0:q.dimension]) + else: + shape = [nrows]+list(fquantity.shape[0:q.dimension])+[q.unit_size] + #end if + quantity.shape = tuple(shape) + #if len(fquantity.shape)==q.dimension: + # quantity.shape = tuple([nrows]+list(fquantity.shape)) + ##end if + domain[qname] = quantity + #end for + trace[dname] = domain + else: + self.error('traces are missing in file "{}"'.format(self.filepath)) + #end if + # rename "int_data" and "real_data" as "int_traces" and "real_traces" + self[aliases[name]] = trace + #end def init_trace + + + # Perform internal consistency check between per-walker single + # particle energies and per-walker total energies. + def check_particle_sums(self,tol): + t = self.real_traces + + # Determine quantities present as "scalars" (total values) and also per-particle + scalar_names = set(t.scalars.keys()) + other_names = [] + for dname,domain in t.items(): + if dname!='scalars': + other_names.extend(domain.keys()) + #end if + #end for + other_names = set(other_names) + sum_names = scalar_names & other_names + + # For each quantity, determine if the sum over particles matches the total + same = True + for qname in sum_names: + # Get total value for each quantity + q = t.scalars[qname] + + # Perform the sum over particles + qs = 0*q + for dname,domain in t.items(): + if dname!='scalars' and qname in domain: + tqs = domain[qname].sum(1) + if len(tqs.shape)==1: + qs[:,0] += tqs + else: + qs[:,0] += tqs[:,0] + #end if + #end if + #end for + + # Compare total and summed quantities + qsame = (abs(q-qs)0: + self.error('{} file check failed for series {}\ntraces file is missing some quantities\nquantities present: {}\nquantities missing: {}'.format(file_type,self.options.series,sorted(trace_names),sorted(missing))) + #end if + + scalars_valid = True + scalars = scalar_file.data + + # Sum traces data for each quantity across all traces.h5 files + summed_scalars = obj() + for qname in qnames: + summed_scalars[qname] = np.zeros(scalars[qname].shape) + #end for + wtot = np.zeros(summed_scalars.first().shape) + for trace_file in self.data: + # scalar.dat/stat.h5 are resolved per block + w = trace_file.scalars_by_block.Weight + wtot += w + for qname in qnames: + q = trace_file.scalars_by_block[qname] + if qname!='Weight': + summed_scalars[qname] += w*q + else: + summed_scalars[qname] += w + #end if + #end for + #end for + + # Compare summed trace data against scalar.dat/stat.h5 values + for qname in qnames: + qscalar = scalars[qname] + if qname!='Weight': + qb = summed_scalars[qname]/wtot + else: + qb = summed_scalars[qname] + #end if + match = abs(qb-qscalar)3} {: 16.12f} {: 16.12f} {: 16.12f}'.format(b,qfile,qtrace,qfile-qtrace),n=3) + #end if + #end for + #end if + scalars_valid &= all_match + #end for + + self.failed |= not scalars_valid + + return scalars_valid + #end def check_scalar_file + + + # Check aggregated traces data against dmc.dat + def check_dmc_dat(self,tol): + + # Some DMC steps are excluded due to a known bug in QMCPACK weights + dmc_steps_exclude = self.options.dmc_steps_exclude + + # Check that expected quantities are present + dmc_file = self.dmc_dat + qnames = dmc_file.quantities + trace_names = set(self.data[0].scalars_by_step.keys()) + missing = set(qnames)-trace_names + if len(missing)>0: + self.error('dmc.dat check failed for series {}\ntraces file is missing some quantities\nquantities present: {}\nquantities missing: {}'.format(self.options.series,sorted(trace_names),sorted(missing))) + #end if + weighted = set(['LocalEnergy']) + + dmc_valid = True + dmc = dmc_file.data + + # Sum traces data for each quantity across all traces.h5 files + summed_scalars = obj() + for qname in qnames: + summed_scalars[qname] = np.zeros(dmc[qname].shape) + #end for + wtot = np.zeros(summed_scalars.first().shape) + for trace_file in self.data: + # dmc.dat is resolved per step + w = trace_file.scalars_by_step.Weight + wtot += w + for qname in qnames: + q = trace_file.scalars_by_step[qname] + if qname in weighted: + summed_scalars[qname] += w*q + else: + summed_scalars[qname] += q + #end if + #end for + #end for + + # Compare summed trace data against dmc.dat values + for qname in qnames: + qdmc = dmc[qname] + if qname in weighted: + qb = summed_scalars[qname]/wtot + else: + qb = summed_scalars[qname] + #end if + match = abs(qb-qdmc)3} {: 16.12f} {: 16.12f} {: 16.12f}'.format(s,qfile,qtrace,qfile-qtrace),n=3) + #end if + #end for + #end if + if dmc_steps_exclude>0: + all_match = match[dmc_steps_exclude:].all() + #end if + dmc_valid &= all_match + #end for + + if dmc_steps_exclude>0: + log('\nExcluding first {} DMC steps from match check.'.format(dmc_steps_exclude),n=2) + #end if + + self.dmc_dat_valid = dmc_valid + self.pass_fail(dmc_valid,n=2) + + self.failed |= not dmc_valid + + return dmc_valid + #end def check_dmc_dat + + + # Print a brief message about pass/fail status of a subtest + def pass_fail(self,passed,n): + if passed: + self.log('\nCheck passed!',n=n) + else: + self.log('\nCheck failed!',n=n) + #end if + #end def pass_fail +#end class TracesAnalyzer + + + +examples = ''' + +=================================================================== +Example 1: QMCPACK VMC/DMC with scalar-only traces, single mpi task +=================================================================== + +Contents of QMCPACK input file (qmc.in.xml): +-------------------------------------------- + + + ... + + + + ... + + + # write traces files w/o array info (scalars only) + + + # vmc run, scalars written to stat.h5 + + + ... + + + # dmc run, scalars written to stat.h5 + + + ... + + + + +QMCPACK execution: +------------------ +export OMP_NUM_THREADS=1 +mpirun -np qmcpack qmc.in.xml + +QMCPACK output files: +--------------------- +qmc.s000.qmc.xml +qmc.s000.scalar.dat +qmc.s000.stat.h5 +qmc.s000.traces.h5 +qmc.s001.cont.xml +qmc.s001.dmc.dat +qmc.s001.qmc.xml +qmc.s001.scalar.dat +qmc.s001.stat.h5 +qmc.s001.traces.h5 + +check_traces.py usage: +---------------------- +check_traces.py -p qmc -s '0,1' -m 'vmc,dmc' --dmc_steps_exclude=1 + +Either execute check_traces.py in /your/path/to/qmcpack/output as above, or do: + +check_traces.py -p qmc -s '0,1' -m 'vmc,dmc' --dmc_steps_exclude=1 /your/path/to/qmcpack/output + + +==================================================================== +Example 2: QMCPACK VMC/DMC, selective scalar traces, single mpi task +==================================================================== + +Contents of QMCPACK input file (qmc.in.xml): +-------------------------------------------- + + + ... + + + + ... + + + # write traces files w/o array info (scalars only) + + + Kinetic ElecElec # only write traces of Kinetic and ElecElec + + + + # vmc run, scalars written to stat.h5 + + + ... + + + # dmc run, scalars written to stat.h5 + + + ... + + + + +QMCPACK execution: +------------------ +export OMP_NUM_THREADS=1 +mpirun -np qmcpack qmc.in.xml + +QMCPACK output files: +--------------------- +qmc.s000.qmc.xml +qmc.s000.scalar.dat +qmc.s000.stat.h5 +qmc.s000.traces.h5 +qmc.s001.cont.xml +qmc.s001.dmc.dat +qmc.s001.qmc.xml +qmc.s001.scalar.dat +qmc.s001.stat.h5 +qmc.s001.traces.h5 + +check_traces.py usage: +---------------------- +check_traces.py -p qmc -s '0,1' -m 'vmc,dmc' -q 'Kinetic,ElecElec' --dmc_steps_exclude=1 + + +=================================================================== +Example 3: QMCPACK VMC/DMC, selective array traces, single mpi task +=================================================================== + +Contents of QMCPACK input file (qmc.in.xml): +-------------------------------------------- + + + ... + + + + ... + + + # write traces files w/ all scalar info and select array info + + + position Kinetic # write per-electron positions and kinetic energies + + + + # vmc run, scalars written to stat.h5 + + + ... + + + # dmc run, scalars written to stat.h5 + + + ... + + + + +QMCPACK execution: +------------------ +export OMP_NUM_THREADS=1 +mpirun -np qmcpack qmc.in.xml + +QMCPACK output files: +--------------------- +qmc.s000.qmc.xml +qmc.s000.scalar.dat +qmc.s000.stat.h5 +qmc.s000.traces.h5 +qmc.s001.cont.xml +qmc.s001.dmc.dat +qmc.s001.qmc.xml +qmc.s001.scalar.dat +qmc.s001.stat.h5 +qmc.s001.traces.h5 + +check_traces.py usage: +---------------------- +check_traces.py -p qmc -s '0,1' -m 'vmc,dmc' --psum --dmc_steps_exclude=1 + +''' + + + +if __name__=='__main__': + + # Define command line options + usage = '''usage: %prog [options] [path]''' + parser = OptionParser(usage=usage,add_help_option=False,version='%prog 0.1') + + parser.add_option('-h','--help',dest='help', + action='store_true',default=False, + help='Print help information and exit (default=%default).' + ) + parser.add_option('-x','--examples',dest='examples', + action='store_true',default=False, + help='Print usage examples and exit (default=%default).' + ) + parser.add_option('-p','--prefix',dest='prefix', + default='qmc', + help='Series number(s) to check (default=%default).' + ) + parser.add_option('-s','--series',dest='series', + default='None', + help='Series number(s) to check (default=%default).' + ) + parser.add_option('-m','--methods',dest='methods', + default='None', + help='QMC method for each series. Can be "vmc" or "dmc" for each series (default=%default).' + ) + parser.add_option('-q','--quantities',dest='quantities', + default='default', + help='QMC method for each series. Can be "vmc" or "dmc" for each series (default=%default).' + ) + parser.add_option('-n','--mpi',dest='mpi', + default='1', + help='Number of MPI tasks in the original QMCPACK run. This is also the number of traces.h5 files produced by a single VMC or DMC section (default=%default).' + ) + parser.add_option('--psum',dest='particle_sum', + action='store_true',default=False, + help='Check sums of single particle energies (default=%default).' + ) + parser.add_option('--pseudo',dest='pseudo', + action='store_true',default=True, + help='QMC calculation used pseudopotentials (default=%default).' + ) + parser.add_option('--dmc_steps_exclude',dest='dmc_steps_exclude', + default='0', + help='Exclude a number of DMC steps from being checked. This option is temporary and will be removed once a bug in the DMC weights for the first step is fixed (default=%default).' + ) + parser.add_option('--tol',dest='tolerance', + default='1e-8', + help='Tolerance to check (default=%default).' + ) + + opt,paths = parser.parse_args() + + options = obj(**opt.__dict__) + + # Process command line options + if options.help: + log('\n'+parser.format_help().strip()+'\n') + sys.exit(0) + #end if + + if options.examples: + log(examples) + sys.exit(0) + #end if + + tol = float(options.tolerance) + + if len(paths)==0: + options.path = './' + elif len(paths)==1: + options.path = paths[0] + else: + error('Only a single path is accepted as input.\nPaths provided:\n{}'.format(paths)) + #end if + if not os.path.exists(options.path): + error('Path to QMCPACK run does not exist.\nPath provided: {}'.format(options.path)) + elif os.path.isfile(options.path): + error('Path to QMCPACK run is actually a file.\nOnly directory paths are accepted.\nPath provided: {}'.format(options.path)) + #end if + + def process_list(slist,type=lambda x: x): + tokens = slist.strip('"').strip("'").replace(',',' ').split() + lst = [type(t) for t in tokens] + return lst + #end def process_list + + options.series = process_list(options.series,int) + options.methods = process_list(options.methods) + options.mpi = int(options.mpi) + options.dmc_steps_exclude = int(options.dmc_steps_exclude) + if options.quantities=='default': + options.quantities = None + else: + options.quantities = process_list(options.quantities) + #end if + + if len(options.series)!=len(options.methods): + error('"series" and "methods" must match in length.') + #end if + valid_methods = ['vmc','dmc'] + invalid = set(options.methods)-set(valid_methods) + if len(invalid)>0: + error('Invalid entries given for "methods".\nValid options are: {}\nYou provided: {}'.format(valid_methods,sorted(invalid))) + #end if + + valid_quantities = ''' + LocalEnergy Kinetic LocalPotential ElecElec ElecIon LocalECP NonLocalECP + '''.split() + if options.quantities is not None: + invalid = set(options.quantities)-set(valid_quantities) + if len(invalid)>0: + error('Invalid entries given for "quantities".\nValid options are: {}\nYou provided: {}'.format(valid_quantities,sorted(invalid))) + #end if + #end if + + + # Parse all files across all requested series and compare traces vs scalar/stat/dmc + + log('\nChecking match between traces and scalar/stat/dmc files\n') + + log('\nOptions provided:\n'+str(options).rstrip()) + + failed = False + + series_in = options.series + methods_in = options.methods + + del options.series + del options.methods + + # Loop over vmc/dmc series + for series,method in zip(series_in,methods_in): + + options.series = series + options.method = method + + log('\n\nChecking series {} method={}'.format(series,method)) + + # Read scalar.dat, stat.h5, dmc.dat, and *wtraces.h5 for the series + ta = TracesAnalyzer(options) + + # Check traces data against scalar/stat/dmc files + if method=='vmc': + log('\nChecking scalar.dat',n=1) + ta.check_scalar_dat(tol) + + log('\nChecking stat.h5',n=1) + ta.check_stat_h5(tol) + + elif method=='dmc': + log('\nSkipping checks of scalar.dat and stat.h5',n=1) + log('Statistics for these files are currently computed\n' + 'after branching. Since traces are written before \n' + 'branching, these files cannot be reconstructed \n' + 'from the traces.',n=2) + + log('\nChecking dmc.dat',n=1) + ta.check_dmc_dat(tol) + #end if + + failed |= ta.failed + #end for + + # Print final pass/fail message + if failed: + test_fail() + else: + test_pass() + #end if +#end if diff --git a/tests/solids/diamondC_1x1x1_pp/CMakeLists.txt b/tests/solids/diamondC_1x1x1_pp/CMakeLists.txt index d9a6ef5fe9..f644ddd261 100644 --- a/tests/solids/diamondC_1x1x1_pp/CMakeLists.txt +++ b/tests/solids/diamondC_1x1x1_pp/CMakeLists.txt @@ -1881,15 +1881,13 @@ if(add_traces_tests) qmc_walkertrace_vmc_scalars.in.xml 1 1 - check_traces.py + check_wtraces.py -p qmc_trace_vmc_scalars -s 0 -m vmc - -q - 'Kinetic,ElecElec,IonIon,LocalECP,NonLocalECP' --dmc_steps_exclude=1) simple_run_and_check( @@ -1898,7 +1896,7 @@ if(add_traces_tests) qmc_walkertrace_vmc_scalars.in.xml 4 4 - check_traces.py + check_wtraces.py -p qmc_trace_vmc_scalars -n @@ -1907,8 +1905,6 @@ if(add_traces_tests) 0 -m vmc - -q - 'Kinetic,ElecElec,IonIon,LocalECP,NonLocalECP' --dmc_steps_exclude=1) simple_run_and_check( @@ -1917,7 +1913,7 @@ if(add_traces_tests) qmc_walkertrace_dmc_scalars.in.xml 4 4 - check_traces.py + check_wtraces.py -p qmc_trace_dmc_scalars -n @@ -1926,8 +1922,6 @@ if(add_traces_tests) 1 -m dmc - -q - 'Kinetic,ElecElec,IonIon,LocalECP,NonLocalECP' --dmc_steps_exclude=1) endif() From 586c7db517dade8c32cff50933c075d677b6fc2c Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Tue, 28 May 2024 00:36:40 -0400 Subject: [PATCH 15/55] remove old scaffolding --- src/Estimators/TraceManagerNew.h | 1435 +--------------------- src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp | 1 - src/QMCDrivers/QMCDriver.h | 1 + src/QMCDrivers/QMCUpdateBase.cpp | 14 - src/QMCDrivers/QMCUpdateBase.h | 1 + src/QMCDrivers/VMC/VMCUpdatePbyP.cpp | 1 - src/QMCHamiltonians/OperatorBase.cpp | 60 - src/QMCHamiltonians/OperatorBase.h | 27 - src/QMCHamiltonians/QMCHamiltonian.cpp | 169 +-- src/QMCHamiltonians/QMCHamiltonian.h | 22 - 10 files changed, 21 insertions(+), 1710 deletions(-) diff --git a/src/Estimators/TraceManagerNew.h b/src/Estimators/TraceManagerNew.h index 72f2aed76c..a30e4905f5 100644 --- a/src/Estimators/TraceManagerNew.h +++ b/src/Estimators/TraceManagerNew.h @@ -36,14 +36,6 @@ namespace qmcplusplus { -//#define TRACE_CHECK - - - -const unsigned int DMAXNEW = 4; -using TraceIntNew = long; -using TraceRealNew = OHMMS_PRECISION; -using TraceCompNew = std::complex; const unsigned int WDMAX = 4; using WTraceInt = long; @@ -56,1107 +48,6 @@ using WTracePsiVal = WTraceComp; #endif -struct TraceQuantityNew -{ - std::string name; - bool default_quantity; - bool scalar_available; - bool array_available; - bool scalar_stream_requested; - bool array_stream_requested; - bool scalar_write_requested; - bool array_write_requested; - bool stream_scalar; - bool stream_array; - bool write_scalar; - bool write_array; - - inline TraceQuantityNew() - { - default_quantity = false; - scalar_available = false; - array_available = false; - scalar_stream_requested = false; - array_stream_requested = false; - scalar_write_requested = false; - array_write_requested = false; - stream_scalar = false; - stream_array = false; - write_scalar = false; - write_array = false; - } - - inline void incorporate(const TraceQuantityNew& other) - { - if (name != other.name) - { - APP_ABORT("TraceQuantityNew::incorporate\n cannot merge quantities with differing names\n names: " + name + " " + - other.name); - } - default_quantity |= other.default_quantity; - scalar_available |= other.scalar_available; - array_available |= other.array_available; - scalar_stream_requested |= other.scalar_stream_requested; - array_stream_requested |= other.array_stream_requested; - } -}; - - -//means of control of traces -// which quantities are available, streaming, writing, etc -// handles global (user + all observable) trace request -//medium of exchange of trace information between trace manager and observables -// handles individual trace requests from observables -struct TraceRequestNew -{ - //switch to allow or disallow streams/writes of requested quantities - bool allow_streams; - bool allow_writes; - - //switch to allow or disallow scalar/array streaming/writing - bool scalars_on; - bool arrays_on; - - //all scalar/array quantities should be provided for streaming - bool stream_all_scalars; - bool stream_all_arrays; - - //all scalar/array quantities should be provided for writing - bool write_all_scalars; - bool write_all_arrays; - - //records whether default scalars/arrays should stream/write - bool streaming_default_scalars; - bool streaming_default_arrays; - bool writing_default_scalars; - bool writing_default_arrays; - - - //quantities made available or requested for streaming or writing - std::map quantities; - - //used to screen checked out quantities for writing - std::string scalar_domain; - - inline TraceRequestNew() { reset(); } - - inline void reset() - { - allow_streams = false; - allow_writes = false; - scalars_on = false; - arrays_on = false; - stream_all_scalars = false; - stream_all_arrays = false; - write_all_scalars = false; - write_all_arrays = false; - streaming_default_scalars = false; - streaming_default_arrays = false; - writing_default_scalars = false; - writing_default_arrays = false; - - quantities.clear(); - } - - inline void set_scalar_domain(const std::string& domain) { scalar_domain = domain; } - - inline bool screen_sample(const std::string& domain, const std::string& name, bool& write) - { - bool scalar = domain == scalar_domain; - bool present = quantities.find(name) != quantities.end(); - bool stream = false; - write = false; - if (present) - { - TraceQuantityNew& q = quantities[name]; - if (scalar) - { - stream = q.stream_scalar; - write = q.write_scalar; - } - else - { - stream = q.stream_array; - write = q.write_array; - } - } - app_log()<<"JTK: TraceRequestNew::screen_sample "<& names, bool write = false) - { - app_log()<<"JTK: TraceRequestNew::request_scalar (tm)"<::iterator name; - for (name = names.begin(); name != names.end(); ++name) - request_scalar(*name, write); - } - - //declare that array quantities are desired for streaming - inline void request_array(const std::set& names, bool write = false) - { - app_log()<<"JTK: TraceRequestNew::request_array (tm)"<::iterator name; - for (name = names.begin(); name != names.end(); ++name) - request_array(*name, write); - } - - //merge in all quantities from a contributor request - inline void incorporate(TraceRequestNew& other) - { - std::map::iterator it; - for (it = other.quantities.begin(); it != other.quantities.end(); ++it) - { - const TraceQuantityNew& q = it->second; - if (quantity_present(q.name)) - quantities[q.name].incorporate(q); - else - quantities[q.name] = q; - } - } - - //balance requests with availability and turn streaming/writing on/off - inline void determine_stream_write() - { - std::map::iterator it; - for (it = quantities.begin(); it != quantities.end(); ++it) - { - TraceQuantityNew& q = it->second; - - q.stream_scalar = - allow_streams && scalars_on && q.scalar_available && (q.scalar_stream_requested || stream_all_scalars); - - q.write_scalar = q.stream_scalar && (q.scalar_write_requested || write_all_scalars); - - q.stream_array = - allow_streams && arrays_on && q.array_available && (q.array_stream_requested || stream_all_arrays); - - q.write_array = q.stream_array && (q.array_write_requested || write_all_arrays); - } - // default quantities stream and write if any others do - streaming_default_scalars = false; - writing_default_scalars = false; - streaming_default_arrays = false; - writing_default_arrays = false; - for (it = quantities.begin(); it != quantities.end(); ++it) - { - TraceQuantityNew& q = it->second; - streaming_default_scalars |= q.stream_scalar; - writing_default_scalars |= q.write_scalar; - streaming_default_arrays |= q.stream_array; - writing_default_arrays |= q.write_array; - } - for (it = quantities.begin(); it != quantities.end(); ++it) - { - TraceQuantityNew& q = it->second; - if (q.default_quantity) - { - q.stream_scalar = streaming_default_scalars; - q.write_scalar = writing_default_scalars; - q.stream_array = streaming_default_arrays; - q.write_array = writing_default_arrays; - } - } - } - - //relay updated streaming information to contributor - inline void relay_stream_info(TraceRequestNew& other) - { - other.allow_streams = allow_streams; - other.allow_writes = allow_writes; - other.scalars_on = scalars_on; - other.arrays_on = arrays_on; - other.stream_all_scalars = stream_all_scalars; - other.stream_all_arrays = stream_all_arrays; - other.write_all_scalars = write_all_scalars; - other.write_all_arrays = write_all_arrays; - other.streaming_default_scalars = streaming_default_scalars; - other.streaming_default_arrays = streaming_default_arrays; - other.writing_default_scalars = writing_default_scalars; - other.writing_default_arrays = writing_default_arrays; - std::map::iterator it; - for (it = other.quantities.begin(); it != other.quantities.end(); ++it) - { - TraceQuantityNew& q = it->second; - check_presence(q.name); - q = quantities[q.name]; - } - } - - inline void report() - { - //app_log()<<"\n TraceRequestNew"<< std::endl; - app_log() << " allow_streams = " << allow_streams << std::endl; - app_log() << " allow_writes = " << allow_writes << std::endl; - app_log() << " scalars_on = " << scalars_on << std::endl; - app_log() << " arrays_on = " << arrays_on << std::endl; - app_log() << " stream_all_scalars = " << stream_all_scalars << std::endl; - app_log() << " stream_all_arrays = " << stream_all_arrays << std::endl; - app_log() << " write_all_scalars = " << write_all_scalars << std::endl; - app_log() << " write_all_arrays = " << write_all_arrays << std::endl; - app_log() << " streaming_default_scalars = " << streaming_default_scalars << std::endl; - app_log() << " streaming_default_arrays = " << streaming_default_arrays << std::endl; - app_log() << " writing_default_scalars = " << writing_default_scalars << std::endl; - app_log() << " writing_default_arrays = " << writing_default_arrays << std::endl; - - write_selected("scalars available", "scalar_available"); - write_selected("arrays available", "array_available"); - - write_selected("scalar streams requested", "scalar_stream_requested"); - write_selected("array streams requested", "array_stream_requested"); - - write_selected("scalar writes requested", "scalar_write_requested"); - write_selected("array writes requested", "array_write_requested"); - - write_selected("scalar streams occurring", "stream_scalar"); - write_selected("array streams occurring", "stream_array"); - - write_selected("scalar writes occurring", "write_scalar"); - write_selected("array writes occurring", "write_array"); - } - - inline void write_selected(const std::string& header, const std::string& selector) - { - app_log() << " " << header << ":"; - int n = 0; - std::map::iterator it; - for (it = quantities.begin(); it != quantities.end(); ++it) - { - TraceQuantityNew& q = it->second; - bool selected = false; - if (selector == "scalar_available") - selected = q.scalar_available; - else if (selector == "array_available") - selected = q.array_available; - else if (selector == "scalar_stream_requested") - selected = q.scalar_stream_requested; - else if (selector == "array_stream_requested") - selected = q.array_stream_requested; - else if (selector == "scalar_write_requested") - selected = q.scalar_write_requested; - else if (selector == "array_write_requested") - selected = q.array_write_requested; - else if (selector == "stream_scalar") - selected = q.stream_scalar; - else if (selector == "stream_array") - selected = q.stream_array; - else if (selector == "write_scalar") - selected = q.write_scalar; - else if (selector == "write_array") - selected = q.write_array; - else - APP_ABORT("TraceRequestNew::write_selected unrecognized selector: " + selector); - if (selected) - { - if (n % 5 == 0) - app_log() << std::endl << " "; - n++; - app_log() << " " << q.name; - } - } - app_log() << std::endl; - } - - - //private (internal) API - //query whether a quantity is present - inline bool quantity_present(const std::string& name) { return quantities.find(name) != quantities.end(); } - - //create a quantity if it is not present - inline void guarantee_presence(const std::string& name, bool combined = false) - { - if (!quantity_present(name)) - { - TraceQuantityNew q; - q.name = name; - quantities[name] = q; - } - } - - //abort if a quantity is not present - inline void check_presence(const std::string& name) - { - if (!quantity_present(name)) - { - APP_ABORT("TraceRequestNew::check_presence quantity " + name + " is not present"); - } - } - - //query whether any quantities are streaming - inline bool streaming() { return streaming_default_scalars || streaming_default_arrays; } - - //query whether any quantities are writing - inline bool writing() { return writing_default_scalars || writing_default_arrays; } - - //query whether any scalar quantities are streaming - inline bool streaming_scalars() { return streaming_default_scalars; } - - //query whether any array quantities are streaming - inline bool streaming_arrays() { return streaming_default_arrays; } -}; - - -template -struct TraceSampleNew -{ - std::string domain; - std::string name; - int index; - bool array_trace; - int dimension; - int size; - int unit_size; - int data_size; - TinyVector shape; - Vector& sample; - bool write; - int buffer_start, buffer_end; - std::map meta_int; - std::map meta_real; - std::map meta_string; - bool verbose; - - inline TraceSampleNew(const std::string& sdomain, const std::string& sname, int sindex, int sdim, Vector& ssample) - : sample(ssample), verbose(false) - { - initialize(sdomain, sname, sindex, sdim); - } - - - inline TraceSampleNew(const std::string& sdomain, - const std::string& sname, - int sindex, - int sdim, - TinyVector sshape, - Vector& ssample) - : sample(ssample), verbose(false) - { - initialize(sdomain, sname, sindex, sdim); - shape = sshape; - size = sample.size(); - check_shape(); - } - - inline virtual ~TraceSampleNew() = default; - - inline void initialize(const std::string& sdomain, const std::string& sname, int sindex, int sdim) - { - domain = sdomain, name = sname; - dimension = sdim; - index = sindex; - array_trace = false; - write = false; - buffer_start = -1; - buffer_end = -1; - } - - - inline void set_unit_size(int usize) { unit_size = usize; } - - - inline void set_data_size() { data_size = size * unit_size; } - - - inline void check_shape() - { - bool correct_shape = true; - bool correct_dimension = dimension <= DMAXNEW; - if (correct_dimension) - { - int tsize = 1; - for (int d = 0; d < dimension; ++d) - { - tsize *= shape[d]; - correct_dimension = correct_dimension && shape[d] > 0; - } - correct_shape = tsize == size; - } - if (!correct_dimension) - APP_ABORT("TraceSampleNew::check_shape dimension of sample array is incorrect"); - if (!correct_shape) - APP_ABORT("TraceSampleNew::check_shape shape and size of sample array do not match"); - } - - - inline bool same_shape(TraceSampleNew* other) - { - bool same = dimension == other->dimension && size == other->size; - if (same) - for (int d = 0; d < dimension; ++d) - same = same && shape[d] == other->shape[d]; - return same; - } - - inline void set_buffer_range(int& bstart) - { - set_data_size(); - if (write) - { - buffer_start = bstart; - buffer_end = bstart + data_size; - bstart = buffer_end; - } - } - - - inline T sum() - { - T s(0); - for (int i = 0; i < sample.size(); ++i) - s += sample[i]; - return s; - } - - inline void write_summary(int ind = -1, std::string pad = " ") - { - std::string pad2 = pad + " "; - if (ind == -1) - app_log() << pad << " TraceSampleNew " << name << std::endl; - else - app_log() << pad << ind << " TraceSampleNew " << name << std::endl; - app_log() << pad2 << "domain = " << domain << std::endl; - app_log() << pad2 << "name = " << name << std::endl; - app_log() << pad2 << "index = " << index << std::endl; - app_log() << pad2 << "array_trace = " << array_trace << std::endl; - app_log() << pad2 << "dimension = " << dimension << std::endl; - app_log() << pad2 << "size = " << size << std::endl; - app_log() << pad2 << "unit_size = " << unit_size << std::endl; - app_log() << pad2 << "data_size = " << data_size << std::endl; - app_log() << pad2 << "shape = " << shape << std::endl; - app_log() << pad2 << "write = " << write << std::endl; - app_log() << pad2 << "buffer range = [" << buffer_start << "," << buffer_end << ")" << std::endl; - } -}; - - - -template -bool TraceSampleNew_comp(TraceSampleNew* left, TraceSampleNew* right) -{ - return left->data_size < right->data_size; -} - - -template -struct TraceSampleNews -{ - std::vector*> samples; - std::map> sample_indices; - std::vector*> ordered_samples; - bool verbose; - - inline TraceSampleNews() : verbose(false) {} - - inline ~TraceSampleNews() { finalize(); } - - - inline void set_verbose(bool v) { verbose = v; } - - - inline int size() { return samples.size(); } - - - inline void assign_sample_index(const std::string& domain, const std::string& name, int index, std::string label = "") - { - if (sample_indices.count(domain) > 0 && sample_indices[domain].count(name) > 0) - { - APP_ABORT("TraceSampleNews::checkout " + label + " variable " + name + " already exists in domain " + domain); - } - else - { - sample_indices[domain][name] = index; - } - } - - template - inline Array* checkout_array(const std::string& domain, const std::string& name, TinyVector shape) - { - int index = samples.size(); - assign_sample_index(domain, name, index, "array"); - std::array subshape; - for (int idim = 0; idim < D; idim++) - subshape[idim] = shape[idim]; - Array* a = new Array(subshape); - TraceSampleNew* s = new TraceSampleNew(domain, name, index, D, shape, a->storage()); - samples.push_back(s); - if (verbose) - app_log() << "TraceSampleNews::checkout_array " << domain << " " << name << " " << index << std::endl; - return a; - } - - - template - inline Array* checkout_array(const ParticleSet& P, const std::string& name, TinyVector shape) - { - const std::string& domain = P.parentName(); - int index = samples.size(); - assign_sample_index(domain, name, index, "array"); - std::array subshape; - for (int idim = 0; idim < D; idim++) - subshape[idim] = shape[idim]; - Array* a = new Array(subshape); - TraceSampleNew* s = new TraceSampleNew(domain, name, index, D, shape, a->storage()); - samples.push_back(s); - s->array_trace = true; - if (verbose) - app_log() << "TraceSampleNews::checkout_array " << domain << " " << name << " " << index << std::endl; - return a; - } - - - inline TraceSampleNew* get_trace(const std::string& domain, const std::string& name) - { - TraceSampleNew* ts = NULL; - for (int i = 0; i < samples.size(); ++i) - { - TraceSampleNew& tsc = *samples[i]; - if (tsc.domain == domain && tsc.name == name) - { - ts = &tsc; - break; - } - } - if (ts == NULL) - APP_ABORT("TraceSampleNews::get_trace failed to get trace for quantity " + name + " in domain " + domain); - return ts; - } - - - - inline void set_unit_size(int usize) - { - for (int i = 0; i < samples.size(); i++) - samples[i]->set_unit_size(usize); - } - - - inline void screen_writes(TraceRequestNew& request) - { - for (int i = 0; i < samples.size(); i++) - { - TraceSampleNew& s = *samples[i]; - bool stream = request.screen_sample(s.domain, s.name, s.write); - if (verbose) - app_log() << "TraceRequestNew screening " << s.name << " in domain " << s.domain << ". stream: " << stream - << " write: " << s.write << std::endl; - if (!stream) - app_log() << "warning: quantity " + s.name + " in domain " + s.domain + - " was not requested but is streaming anyway" - << std::endl; - } - } - - - inline void order_by_size() - { - for (int i = 0; i < samples.size(); i++) - samples[i]->set_data_size(); - ordered_samples.resize(samples.size()); - copy(samples.begin(), samples.end(), ordered_samples.begin()); - sort(ordered_samples.begin(), ordered_samples.end(), TraceSampleNew_comp); - } - - - inline void set_buffer_ranges(int& starting_index) - { - for (int i = 0; i < ordered_samples.size(); i++) - { - TraceSampleNew& sample = *ordered_samples[i]; - sample.set_buffer_range(starting_index); - } - } - - - inline int total_size() - { - int s = 0; - for (int i = 0; i < samples.size(); i++) - s += samples[i]->sample.size() * samples[i]->unit_size; - return s; - } - - - inline int min_buffer_index() - { - int min_index = 2000000000; - for (int i = 0; i < samples.size(); i++) - min_index = std::min(min_index, samples[i]->buffer_start); - return min_index; - } - - - inline int max_buffer_index() - { - int max_index = -1; - for (int i = 0; i < samples.size(); i++) - max_index = std::max(max_index, samples[i]->buffer_end); - return max_index; - } - - - inline void finalize() - { - delete_iter(samples.begin(), samples.end()); - samples.resize(0); - ordered_samples.resize(0); - sample_indices.clear(); - } - - - inline void register_hdf_data(hdf_archive& f) - { - std::map>::iterator it; - std::map::iterator it2; - for (it = sample_indices.begin(); it != sample_indices.end(); it++) - { - const std::string& domain = it->first; - std::map& indices = it->second; - f.push(domain); - for (it2 = indices.begin(); it2 != indices.end(); ++it2) - { - const std::string& quantity = it2->first; - TraceSampleNew& sample = *samples[it2->second]; - if (sample.write) - { - f.push(quantity); - f.write(sample.dimension, "dimension"); - f.write(sample.shape, "shape"); - f.write(sample.size, "size"); - f.write(sample.unit_size, "unit_size"); - f.write(sample.buffer_start, "row_start"); - f.write(sample.buffer_end, "row_end"); - f.pop(); - } - } - f.pop(); - } - } - - - inline void write_summary(std::string type, std::string pad = " ") - { - std::string pad2 = pad + " "; - std::string pad3 = pad2 + " "; - std::string pad4 = pad3 + " "; - app_log() << pad << "TraceSampleNews<" << type << ">" << std::endl; - app_log() << pad2 << "nsamples = " << samples.size() << std::endl; - app_log() << pad2 << "sample_indices" << std::endl; - std::map>::iterator it; - std::map::iterator it2; - for (it = sample_indices.begin(); it != sample_indices.end(); it++) - { - const std::string& domain = it->first; - std::map& indices = it->second; - app_log() << pad3 << domain << std::endl; - for (it2 = indices.begin(); it2 != indices.end(); ++it2) - app_log() << pad4 << it2->first << " = " << it2->second << std::endl; - } - app_log() << pad2 << "end sample_indices" << std::endl; - app_log() << pad2 << "samples" << std::endl; - for (int i = 0; i < ordered_samples.size(); ++i) - ordered_samples[i]->write_summary(i, pad3); - app_log() << pad2 << "end samples" << std::endl; - app_log() << pad << "end TraceSampleNews<" << type << ">" << std::endl; - } - - - inline void user_report(const std::string& type, const std::string& pad = " ") - { - std::string pad2 = pad + " "; - app_log() << pad << type << " traces provided by estimators" << std::endl; - std::map>::iterator it; - std::map::iterator it2; - for (it = sample_indices.begin(); it != sample_indices.end(); it++) - { - const std::string& domain = it->first; - std::map& indices = it->second; - app_log() << pad2 << "domain " << domain << ": "; - int n = 0; - for (it2 = indices.begin(); it2 != indices.end(); ++it2) - { - if (n % 5 == 0) - app_log() << std::endl << pad2 << " "; - n++; - const std::string& quantity = it2->first; - app_log() << quantity << " "; - } - app_log() << std::endl; - } - } -}; - - -template -struct TraceBufferNew -{ - bool has_complex; - TraceSampleNews* samples; - TraceSampleNews>* complex_samples; - std::string type; - Array buffer; - bool verbose; - - //hdf variables - std::string top; - hsize_t dims[2]; - hsize_t hdf_file_pointer; - - - TraceBufferNew() : samples(0), complex_samples(0), verbose(false) - { - type = "?"; - has_complex = false; - reset(); - } - - - inline void set_verbose(bool v) { verbose = v; } - - - inline void set_type(std::string stype) - { - type = stype; - top = type + "_data"; - } - - - inline void reset() { buffer.resize(0, buffer.size(1)); } - - - inline void set_samples(TraceSampleNews& s) { samples = &s; } - - - inline void set_samples(TraceSampleNews>& s) - { - complex_samples = &s; - has_complex = true; - } - - - inline void order_and_resize() - { - //put the sample data in size order - samples->set_unit_size(1); - samples->order_by_size(); - if (has_complex) - { - complex_samples->set_unit_size(2); - complex_samples->order_by_size(); - } - //assign buffer ranges to each sample - int sample_size = 0; - samples->set_buffer_ranges(sample_size); - if (has_complex) - complex_samples->set_buffer_ranges(sample_size); -#if defined(TRACE_CHECK) - test_buffer_write(sample_size); -#endif - //resize the buffer - int nsamples_init = 1; - buffer.resize(nsamples_init, sample_size); - } - - - inline bool same_as(TraceBufferNew& ref) { return buffer.size(1) == ref.buffer.size(1); } - - - inline void collect_sample() - { - if (verbose) - app_log() << " TraceBufferNew<" << type << ">::collect_sample()" << std::endl; - //make more room, if necessary - int nrows = buffer.size(0); - int row_size = buffer.size(1); - if (row_size > 0) - { - //make space for the row, if necessary - int current_row = nrows; - nrows++; - // resizing buffer(type Array) doesn't preserve data. Thus keep old data and copy over - auto buffer_old(buffer); - buffer.resize(nrows, row_size); - std::copy_n(buffer_old.data(), buffer_old.size(), buffer.data()); - if (verbose) - app_log() << " increasing # of rows to " << nrows << std::endl; - //collect data from all samples into the buffer row - { - std::vector*>& ordered_samples = samples->ordered_samples; - for (int s = 0; s < ordered_samples.size(); s++) - { - TraceSampleNew& tsample = *ordered_samples[s]; - if (tsample.write) - { - auto& sample = tsample.sample; - for (int i = 0; i < sample.size(); ++i) - buffer(current_row, tsample.buffer_start + i) = sample[i]; - } - } - } - if (has_complex) - { - std::vector>*>& ordered_samples = complex_samples->ordered_samples; - for (int s = 0; s < ordered_samples.size(); s++) - { - TraceSampleNew>& tsample = *ordered_samples[s]; - if (tsample.write) - { - auto& sample = tsample.sample; - for (int i = 0, ib = 0; i < sample.size(); ++i, ib += 2) - { - buffer(current_row, tsample.buffer_start + ib) = sample[i].real(); - buffer(current_row, tsample.buffer_start + ib + 1) = sample[i].imag(); - } - } - } - } -#if defined(TRACE_CHECK) - test_buffer_collect(current_row); -#endif - } - } - - - inline void write_summary(std::string pad = " ") - { - std::string pad2 = pad + " "; - app_log() << pad << "TraceBufferNew<" << type << ">" << std::endl; - app_log() << pad2 << "nrows = " << buffer.size(0) << std::endl; - app_log() << pad2 << "row_size = " << buffer.size(1) << std::endl; - app_log() << pad2 << "has_complex = " << has_complex << std::endl; - samples->write_summary(type, pad2); - if (has_complex) - complex_samples->write_summary("complex " + type, pad2); - app_log() << pad << "end TraceBufferNew<" << type << ">" << std::endl; - } - - - inline void user_report(const std::string& pad = " ") - { - samples->user_report(type, pad); - if (has_complex) - complex_samples->user_report("complex " + type, pad); - } - - inline void register_hdf_data(hdf_archive& f) - { - f.push(top); - f.push("layout"); - samples->register_hdf_data(f); - if (has_complex) - complex_samples->register_hdf_data(f); - f.pop(); - f.pop(); - if (!f.open_groups()) - APP_ABORT("TraceBufferNew<" + type + - ">::register_hdf_data() some hdf groups are still open at the end of registration"); - hdf_file_pointer = 0; - } - - - inline void write_hdf(hdf_archive& f, hsize_t& file_pointer) - { - if (verbose) - app_log() << "TraceBufferNew<" << type << ">::write_hdf() " << file_pointer << " " << buffer.size(0) << " " - << buffer.size(1) << std::endl; - dims[0] = buffer.size(0); - dims[1] = buffer.size(1); - app_log()<<" "< 0) - { - f.push(top); - h5d_append(f.top(), "traces", file_pointer, buffer.dim(), dims, buffer.data()); - f.pop(); - } - f.flush(); - app_log()<<" "<total_size(); - if (has_complex) - ssize += complex_samples->total_size(); - if (sample_size != ssize) - { - app_log() << "sample_size = " << sample_size << "\ntotal_size = " << ssize << std::endl; - APP_ABORT("TraceBufferNew::test_buffer_write sample_size and total_size do not match"); - } - //check that buffer indices fall in the expected range - int nsamples = samples->size(); - int min_index = samples->min_buffer_index(); - int max_index = samples->max_buffer_index(); - if (has_complex) - { - nsamples += complex_samples->size(); - min_index = std::min(min_index, complex_samples->min_buffer_index()); - max_index = std::max(max_index, complex_samples->max_buffer_index()); - } - if (nsamples > 0) - { - if (min_index != 0) - APP_ABORT("TraceBufferNew::test_buffer_write min_index!=0\n min_index=" << min_index); - if (max_index != sample_size) - APP_ABORT("TraceBufferNew::test_buffer_write max_index!=sample_size"); - //check that no overlap exists in writes to buffer - Array test_buffer; - test_buffer.resize(1, sample_size); - std::fill(test_buffer.begin(), test_buffer.end(), 0); - int row = 0; - int row_size = test_buffer.size(1); - int offset = row * row_size; - int* loc1 = &test_buffer(offset); - int* loc2 = &test_buffer(row, 0); - if (loc1 != loc2) - APP_ABORT("TraceBufferNew::test_buffer_write serialized buffer offset improperly computed"); - { - int boffset; - std::vector*>& ordered_samples = samples->ordered_samples; - for (int s = 0; s < ordered_samples.size(); s++) - { - TraceSampleNew& tsample = *ordered_samples[s]; - std::vector& sample = tsample.sample; - boffset = offset + tsample.buffer_start; - for (int i = 0; i < sample.size(); ++i) - test_buffer(boffset + i) = 1; - } - } - if (has_complex) - { - int boffset; - std::vector>*>& ordered_samples = complex_samples->ordered_samples; - for (int s = 0; s < ordered_samples.size(); s++) - { - TraceSampleNew>& tsample = *ordered_samples[s]; - std::vector>& sample = tsample.sample; - boffset = offset + tsample.buffer_start; - for (int i = 0, ib = 0; i < sample.size(); ++i, ib += tsample.unit_size) - { - test_buffer(boffset + ib) = 1; - test_buffer(boffset + ib + 1) = 1; - } - } - } - //app_log()<<"test_buffer:"<< std::endl; - //for(int i=0;i>::iterator dom; - std::map::iterator var; - std::map>& domains = samples->sample_indices; - std::vector*>& tsamples = samples->samples; - std::map& scalar_vars = domains[scalars]; - for (var = scalar_vars.begin(); var != scalar_vars.end(); var++) - { - const std::string& name = var->first; - TraceSampleNew& sample = *tsamples[var->second]; - T value = buffer(current_row, sample.buffer_start); - T svalue = 0; - bool any_present = false; - for (dom = domains.begin(); dom != domains.end(); dom++) - { - const std::string& domain = dom->first; - if (domain != scalars) - { - std::map& vars = dom->second; - if (vars.count(name) > 0) - { - any_present = true; - TraceSampleNew& ssample = *tsamples[vars[name]]; - int start = ssample.buffer_start; - int end = ssample.buffer_end; - for (int i = start; i < end; i++) - svalue += buffer(current_row, i); - } - } - } - if (any_present) - { - if (verbose) - app_log() << " " << name << " " << value << " " << svalue << std::endl; - } - } - } -}; - struct WalkerQuantityInfo @@ -1234,7 +125,6 @@ struct WalkerTraceBuffer inline void reset_collect() { - //app_log()<<"WalkerTraceBuffer("<; -//template class WalkerTraceBuffer; - struct TraceManagerState { - TraceRequestNew request; bool method_allows_traces; bool streaming_traces; bool writing_traces; @@ -1488,7 +371,6 @@ struct TraceManagerState throttle = 1; verbose = false; default_domain = "scalars"; - request.set_scalar_domain(default_domain); } inline void reset_permissions() @@ -1497,21 +379,12 @@ struct TraceManagerState streaming_traces = false; writing_traces = false; verbose = false; - request.reset(); } - - inline void update_status() - { - streaming_traces = request.streaming(); - writing_traces = request.writing(); - } - }; template class Walker; -//class ParticleSet; class TrialWaveFunction; class QMCHamiltonian; using MCPWalker = Walker; @@ -1521,30 +394,18 @@ using MCPWalker = Walker; class TraceCollector { public: - //collections of samples for a single walker step - // the associated arrays will be updated following evaluate - TraceSampleNews int_samples; - TraceSampleNews real_samples; - TraceSampleNews comp_samples; - TraceManagerState state; - //buffers for storing samples - // single row of buffer is a single sample from one walker - // number of rows adjusts to accommodate walker samples - TraceBufferNew int_buffer; - TraceBufferNew real_buffer; - // new walker buffers std::unordered_set properties_include; std::vector property_indices; int energy_index; - std::vector energies; - WalkerTraceBuffer walker_property_int_buffer; - WalkerTraceBuffer walker_property_real_buffer; - WalkerTraceBuffer walker_particle_real_buffer; + std::vector energies; + WalkerTraceBuffer walker_property_int_buffer; + WalkerTraceBuffer walker_property_real_buffer; + WalkerTraceBuffer walker_particle_real_buffer; // temporary (contiguous) storage for awful ParticleAttrib<> quantities Array Rtmp; @@ -1558,12 +419,6 @@ class TraceCollector { state.reset_permissions(); - int_buffer.set_type("int"); - real_buffer.set_type("real"); - int_buffer.set_samples(int_samples); - real_buffer.set_samples(real_samples); - real_buffer.set_samples(comp_samples); - // new walker buffers, etc energy_index = -1; energies.resize(0); @@ -1589,146 +444,6 @@ class TraceCollector { if (state.verbose) app_log()<<"TraceCollector::distribute"< - inline Array* checkout_int(const std::string& name, int n1 = 1, int n2 = 0, int n3 = 0, int n4 = 0) - { - app_log()<<"JTK: TraceCollector::checkout_int"<(state.default_domain, name, n1, n2, n3, n4); - } - template - inline Array* checkout_int(const std::string& domain, - const std::string& name, - int n1 = 1, - int n2 = 0, - int n3 = 0, - int n4 = 0) - { - app_log()<<"JTK: TraceCollector::checkout_int"< shape(n1, n2, n3, n4); - return int_samples.checkout_array(domain, name, shape); - } - template - inline Array* checkout_int(const std::string& name, - const ParticleSet& P, - int n2 = 0, - int n3 = 0, - int n4 = 0) - { - app_log()<<"JTK: TraceCollector::checkout_int"< shape(P.getTotalNum(), n2, n3, n4); - return int_samples.checkout_array(P, name, shape); - } - - - // checkout real arrays - template - inline Array* checkout_real(const std::string& name, int n1 = 1, int n2 = 0, int n3 = 0, int n4 = 0) - { - app_log()<<"JTK: TraceCollector::checkout_real"<(state.default_domain, name, n1, n2, n3, n4); - } - template - inline Array* checkout_real(const std::string& domain, - const std::string& name, - int n1 = 1, - int n2 = 0, - int n3 = 0, - int n4 = 0) - { - app_log()<<"JTK: TraceCollector::checkout_real"< shape(n1, n2, n3, n4); - return real_samples.checkout_array(domain, name, shape); - } - template - inline Array* checkout_real(const std::string& name, - const ParticleSet& P, - int n2 = 0, - int n3 = 0, - int n4 = 0) - { - app_log()<<"JTK: TraceCollector::checkout_real"< shape(P.getTotalNum(), n2, n3, n4); - return real_samples.checkout_array(P, name, shape); - } - - - // checkout complex arrays - template - inline Array* checkout_complex(const std::string& name, int n1 = 1, int n2 = 0, int n3 = 0, int n4 = 0) - { - app_log()<<"JTK: TraceCollector::checkout_complex"<(state.default_domain, name, n1, n2, n3, n4); - } - template - inline Array* checkout_complex(const std::string& domain, - const std::string& name, - int n1 = 1, - int n2 = 0, - int n3 = 0, - int n4 = 0) - { - app_log()<<"JTK: TraceCollector::checkout_complex"< shape(n1, n2, n3, n4); - return comp_samples.checkout_array(domain, name, shape); - } - template - inline Array* checkout_complex(const std::string& name, - const ParticleSet& P, - int n2 = 0, - int n3 = 0, - int n4 = 0) - { - app_log()<<"JTK: TraceCollector::checkout_complex"< shape(P.getTotalNum(), n2, n3, n4); - return comp_samples.checkout_array(P, name, shape); } @@ -1736,31 +451,12 @@ class TraceCollector { if (state.verbose) app_log() << "TraceCollector::reset_buffers"< wmin_property_int_buffer; - WalkerTraceBuffer wmin_property_real_buffer; - WalkerTraceBuffer wmin_particle_real_buffer; + WalkerTraceBuffer wmin_property_int_buffer; + WalkerTraceBuffer wmin_property_real_buffer; + WalkerTraceBuffer wmin_particle_real_buffer; - WalkerTraceBuffer wmax_property_int_buffer; - WalkerTraceBuffer wmax_property_real_buffer; - WalkerTraceBuffer wmax_particle_real_buffer; + WalkerTraceBuffer wmax_property_int_buffer; + WalkerTraceBuffer wmax_property_real_buffer; + WalkerTraceBuffer wmax_particle_real_buffer; - WalkerTraceBuffer wmed_property_int_buffer; - WalkerTraceBuffer wmed_property_real_buffer; - WalkerTraceBuffer wmed_particle_real_buffer; + WalkerTraceBuffer wmed_property_int_buffer; + WalkerTraceBuffer wmed_property_real_buffer; + WalkerTraceBuffer wmed_particle_real_buffer; TraceManagerNew(Communicate* comm = 0) @@ -1892,91 +585,13 @@ class TraceManagerNew app_log() << " streaming traces : " << state.streaming_traces << std::endl; app_log() << std::endl; } - app_log()<<"JTK: reading xml attributes "< scalar_requests; - std::set array_requests; - xmlNodePtr element = cur->children; - while (element != NULL) - { - std::string name((const char*)element->name); - if (name == "scalar_traces") - { - std::string defaults = "no"; - OhmmsAttributeSet eattrib; - eattrib.add(defaults, "defaults"); - eattrib.put(element); - use_scalar_defaults = use_scalar_defaults && defaults == "yes"; - if (!use_scalar_defaults) - { - std::vector scalar_list; - putContent(scalar_list, element); - scalar_requests.insert(scalar_list.begin(), scalar_list.end()); - } - } - else if (name == "array_traces" || name == "particle_traces") - { - std::string defaults = "no"; - OhmmsAttributeSet eattrib; - eattrib.add(defaults, "defaults"); - eattrib.put(element); - use_array_defaults = use_array_defaults && defaults == "yes"; - if (!use_array_defaults) - { - std::vector array_list; - putContent(array_list, element); - array_requests.insert(array_list.begin(), array_list.end()); - } - } - else if (name != "text") - { - APP_ABORT("TraceManagerNew::put " + name + - " is not a valid sub-element of \n valid options are: scalar_traces, array_traces"); - } - element = element->next; - } - - state.writing_traces &= state.method_allows_traces; - - //input user quantity requests into the traces request - TraceRequestNew& request = state.request; - request.allow_streams = state.method_allows_traces; - request.allow_writes = state.writing_traces; - request.scalars_on = scalars_on; - request.arrays_on = arrays_on; - request.stream_all_scalars = use_scalar_defaults; - request.stream_all_arrays = use_array_defaults; - request.write_all_scalars = request.stream_all_scalars && state.writing_traces; - request.write_all_arrays = request.stream_all_arrays && state.writing_traces; - request.request_scalar(scalar_requests, state.writing_traces); - request.request_array(array_requests, state.writing_traces); - } } @@ -1994,9 +609,9 @@ class TraceManagerNew for (int i = 0; i < clones.size(); ++i) { TraceCollector& tm = *clones[i]; - int_same = tm.int_buffer.same_as(ref.int_buffer); - real_same = tm.real_buffer.same_as(ref.real_buffer); - all_same = all_same && int_same && real_same; + all_same &= tm.walker_property_int_buffer.same_as(ref.walker_property_int_buffer); + all_same &= tm.walker_property_real_buffer.same_as(ref.walker_property_real_buffer); + all_same &= tm.walker_particle_real_buffer.same_as(ref.walker_particle_real_buffer); } if (!all_same) { @@ -2095,14 +710,6 @@ class TraceManagerNew APP_ABORT("TraceManagerNew::open_hdf_file failed to open hdf file " + file_name); // only clones have active buffers and associated data TraceCollector& tm = *clones[0]; - //tm.write_summary(); - - //tm.int_buffer.register_hdf_data(*hdf_file); - //tm.real_buffer.register_hdf_data(*hdf_file); - // - //tm.walker_property_int_buffer.register_hdf_data(*hdf_file); - //tm.walker_property_real_buffer.register_hdf_data(*hdf_file); - //tm.walker_particle_real_buffer.register_hdf_data(*hdf_file); } @@ -2113,9 +720,6 @@ class TraceManagerNew TraceCollector& tm_lead = *clones[0]; if(!registered_hdf) { - //tm_lead.int_buffer.register_hdf_data(*hdf_file); - //tm_lead.real_buffer.register_hdf_data(*hdf_file); - tm_lead.walker_property_int_buffer.register_hdf_data(*hdf_file); tm_lead.walker_property_real_buffer.register_hdf_data(*hdf_file); tm_lead.walker_particle_real_buffer.register_hdf_data(*hdf_file); @@ -2125,9 +729,6 @@ class TraceManagerNew for (int ip = 0; ip < clones.size(); ++ip) { TraceCollector& tm = *clones[ip]; - //tm.int_buffer.write_hdf(*hdf_file, tm_lead.int_buffer.hdf_file_pointer); - //tm.real_buffer.write_hdf(*hdf_file, tm_lead.real_buffer.hdf_file_pointer); - tm.walker_property_int_buffer.write_hdf(*hdf_file, tm_lead.walker_property_int_buffer.hdf_file_pointer); tm.walker_property_real_buffer.write_hdf(*hdf_file, tm_lead.walker_property_real_buffer.hdf_file_pointer); tm.walker_particle_real_buffer.write_hdf(*hdf_file, tm_lead.walker_particle_real_buffer.hdf_file_pointer); diff --git a/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp b/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp index 0fd416afff..42d5e6a371 100644 --- a/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp +++ b/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp @@ -171,7 +171,6 @@ void DMCUpdatePbyPWithRejectionFast::advanceWalker(Walker_t& thisWalker, bool re } #if !defined(REMOVE_TRACEMANAGER) Traces->buffer_sample(W.current_step); - Traces_new->buffer_sample(W.current_step); Traces_new->collect(thisWalker,W,Psi,H); #endif { diff --git a/src/QMCDrivers/QMCDriver.h b/src/QMCDrivers/QMCDriver.h index 3fd6398c18..4848cc7e27 100644 --- a/src/QMCDrivers/QMCDriver.h +++ b/src/QMCDrivers/QMCDriver.h @@ -31,6 +31,7 @@ #include "QMCWaveFunctions/WaveFunctionPool.h" #include "QMCHamiltonians/QMCHamiltonian.h" #include "Estimators/EstimatorManagerBase.h" +#include "Estimators/TraceManagerNew.h" #include "QMCDrivers/DriverTraits.h" #include "QMCDrivers/QMCDriverInterface.h" #include "QMCDrivers/GreenFunctionModifiers/DriftModifierBase.h" diff --git a/src/QMCDrivers/QMCUpdateBase.cpp b/src/QMCDrivers/QMCUpdateBase.cpp index 28ec298d28..7feae00c9c 100644 --- a/src/QMCDrivers/QMCUpdateBase.cpp +++ b/src/QMCDrivers/QMCUpdateBase.cpp @@ -26,7 +26,6 @@ #include "Estimators/TraceManagerNew.h" #else using TraceManager = int; -using TraceManagerNew = int; #endif namespace qmcplusplus @@ -177,16 +176,6 @@ void QMCUpdateBase::startRun(int blocks, bool record) } H.initialize_traces(*Traces, W); Traces->initialize_traces(); - - if (!Traces_new) - { - APP_ABORT( - "QMCUpdateBase::startRun\n derived QMCDriver class has not setup (new!) trace clones properly\n null TraceManagerNew " - "pointer encountered in derived QMCUpdateBase class\n see VMCLinearOptOMP.cpp for a correct minimal interface " - "(search on 'trace')\n refer to changes made in SVN revision 6597 for further guidance"); - } - H.initialize_traces_new(*Traces_new, W); - Traces_new->initialize_traces(); #endif } @@ -199,9 +188,6 @@ void QMCUpdateBase::stopRun2() #if !defined(REMOVE_TRACEMANAGER) H.finalize_traces(); Traces->finalize_traces(); - - H.finalize_traces_new(); - Traces_new->finalize_traces(); #endif } diff --git a/src/QMCDrivers/QMCUpdateBase.h b/src/QMCDrivers/QMCUpdateBase.h index 7ce5b60365..d4f92839cb 100644 --- a/src/QMCDrivers/QMCUpdateBase.h +++ b/src/QMCDrivers/QMCUpdateBase.h @@ -23,6 +23,7 @@ #include "QMCWaveFunctions/TrialWaveFunction.h" #include "QMCHamiltonians/QMCHamiltonian.h" #include "QMCHamiltonians/NonLocalTOperator.h" +#include "Estimators/TraceManagerNew.h" #include "GreenFunctionModifiers/DriftModifierBase.h" #include "SimpleFixedNodeBranch.h" #include "DriverDebugChecks.h" diff --git a/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp b/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp index 5d05f7f996..a7e4e363ae 100644 --- a/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp +++ b/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp @@ -133,7 +133,6 @@ void VMCUpdatePbyP::advanceWalker(Walker_t& thisWalker, bool recompute) collectables_timer_.stop(); #if !defined(REMOVE_TRACEMANAGER) Traces->buffer_sample(W.current_step); - Traces_new->buffer_sample(W.current_step); Traces_new->collect(thisWalker,W,Psi,H); #endif if (!moved) diff --git a/src/QMCHamiltonians/OperatorBase.cpp b/src/QMCHamiltonians/OperatorBase.cpp index 99d2dac4e4..a7701abefc 100644 --- a/src/QMCHamiltonians/OperatorBase.cpp +++ b/src/QMCHamiltonians/OperatorBase.cpp @@ -33,10 +33,6 @@ OperatorBase::OperatorBase() streaming_particles_(false), have_required_traces_(false), streaming_scalars_(false), - - streaming_particles_new_(false), - have_required_traces_new_(false), - streaming_scalars_new_(false), #endif quantum_domain_(NO_QUANTUM_DOMAIN), energy_domain_(NO_ENERGY_DOMAIN) @@ -54,7 +50,6 @@ void OperatorBase::setName(const std::string name) noexcept { name_ = name; } #if !defined(REMOVE_TRACEMANAGER) TraceRequest& OperatorBase::getRequest() noexcept { return request_; } -TraceRequestNew& OperatorBase::getRequestNew() noexcept { return request_new_; } #endif //////// FUNCTIONS //////////////// @@ -228,7 +223,6 @@ void OperatorBase::add2Hamiltonian(ParticleSet& qp, TrialWaveFunction& psi, QMCH #if !defined(REMOVE_TRACEMANAGER) void OperatorBase::getRequiredTraces(TraceManager& tm){}; -void OperatorBase::getRequiredTracesNew(TraceCollector& tm){}; #endif // END FUNCTIONS // @@ -274,33 +268,6 @@ void OperatorBase::deleteTraceQuantities() have_required_traces_ = false; request_.reset(); } - - - -void OperatorBase::contributeTraceQuantitiesNew() -{ - contributeScalarQuantitiesNew(); - contributeParticleQuantitiesNew(); -} - -void OperatorBase::checkoutTraceQuantitiesNew(TraceCollector& tm) -{ - checkoutScalarQuantitiesNew(tm); - checkoutParticleQuantitiesNew(tm); -} - -void OperatorBase::collectScalarTracesNew() { collectScalarQuantitiesNew(); } - -void OperatorBase::deleteTraceQuantitiesNew() -{ - deleteScalarQuantitiesNew(); - deleteParticleQuantitiesNew(); - streaming_scalars_new_ = false; - streaming_particles_new_ = false; - have_required_traces_new_ = false; - request_new_.reset(); -} - #endif ////// PROTECTED FUNCTIONS @@ -329,33 +296,6 @@ void OperatorBase::deleteScalarQuantities() void OperatorBase::contributeParticleQuantities(){}; void OperatorBase::checkoutParticleQuantities(TraceManager& tm){}; void OperatorBase::deleteParticleQuantities(){}; - - - -void OperatorBase::contributeScalarQuantitiesNew() { request_new_.contribute_scalar(name_); } - -void OperatorBase::checkoutScalarQuantitiesNew(TraceCollector& tm) -{ - streaming_scalars_new_ = request_new_.streaming_scalar(name_); - if (streaming_scalars_new_) - value_sample_new_ = tm.checkout_real<1>(name_); -} - -void OperatorBase::collectScalarQuantitiesNew() -{ - if (streaming_scalars_new_) - (*value_sample_new_)(0) = value_; -} - -void OperatorBase::deleteScalarQuantitiesNew() -{ - if (streaming_scalars_new_) - delete value_sample_new_; -} - -void OperatorBase::contributeParticleQuantitiesNew(){}; -void OperatorBase::checkoutParticleQuantitiesNew(TraceCollector& tm){}; -void OperatorBase::deleteParticleQuantitiesNew(){}; #endif void OperatorBase::setComputeForces(bool compute) {} diff --git a/src/QMCHamiltonians/OperatorBase.h b/src/QMCHamiltonians/OperatorBase.h index 02b119da4c..cd4641dd01 100644 --- a/src/QMCHamiltonians/OperatorBase.h +++ b/src/QMCHamiltonians/OperatorBase.h @@ -31,7 +31,6 @@ #include "QMCWaveFunctions/TWFFastDerivWrapper.h" #if !defined(REMOVE_TRACEMANAGER) #include "Estimators/TraceManager.h" -#include "Estimators/TraceManagerNew.h" #endif #include "QMCHamiltonians/Listener.hpp" #include "QMCWaveFunctions/OrbitalSetTraits.h" @@ -164,7 +163,6 @@ class OperatorBase : public QMCTraits * @return TraceRequest& reference to request_ */ TraceRequest& getRequest() noexcept; - TraceRequestNew& getRequestNew() noexcept; #endif //////// PURELY VIRTUAL FUNCTIONS //////////////// @@ -466,7 +464,6 @@ class OperatorBase : public QMCTraits * @param tm */ virtual void getRequiredTraces(TraceManager& tm); - virtual void getRequiredTracesNew(TraceCollector& tm); #endif // TODO: add docs @@ -517,12 +514,6 @@ class OperatorBase : public QMCTraits * @brief delete trace arrays */ void deleteTraceQuantities(); - - - void contributeTraceQuantitiesNew(); - void checkoutTraceQuantitiesNew(TraceCollector& tm); - void collectScalarTracesNew(); - void deleteTraceQuantitiesNew(); #endif protected: @@ -538,7 +529,6 @@ class OperatorBase : public QMCTraits #if !defined(REMOVE_TRACEMANAGER) ///whether traces are being collected TraceRequest request_; - TraceRequestNew request_new_; #endif ///starting index of this object @@ -553,8 +543,6 @@ class OperatorBase : public QMCTraits #if !defined(REMOVE_TRACEMANAGER) bool streaming_particles_; bool have_required_traces_; - bool streaming_particles_new_; - bool have_required_traces_new_; #endif /////PURELY VIRTUAL FUNCTIONS @@ -579,15 +567,6 @@ class OperatorBase : public QMCTraits virtual void contributeParticleQuantities(); virtual void checkoutParticleQuantities(TraceManager& tm); virtual void deleteParticleQuantities(); - - - virtual void contributeScalarQuantitiesNew(); - virtual void checkoutScalarQuantitiesNew(TraceCollector& tm); - virtual void collectScalarQuantitiesNew(); - virtual void deleteScalarQuantitiesNew(); - virtual void contributeParticleQuantitiesNew(); - virtual void checkoutParticleQuantitiesNew(TraceCollector& tm); - virtual void deleteParticleQuantitiesNew(); #endif virtual void setComputeForces(bool compute); @@ -625,12 +604,6 @@ class OperatorBase : public QMCTraits ///array to store sample value Array* value_sample_; - - - bool streaming_scalars_new_; - - ///array to store sample value - Array* value_sample_new_; #endif /** Is there a per particle listener diff --git a/src/QMCHamiltonians/QMCHamiltonian.cpp b/src/QMCHamiltonians/QMCHamiltonian.cpp index c955f9828e..8056e050bf 100644 --- a/src/QMCHamiltonians/QMCHamiltonian.cpp +++ b/src/QMCHamiltonians/QMCHamiltonian.cpp @@ -65,17 +65,7 @@ QMCHamiltonian::QMCHamiltonian(const std::string& aname) age_sample(nullptr), mult_sample(nullptr), weight_sample(nullptr), - position_sample(nullptr), - - streaming_position_new(false), - id_sample_new(nullptr), - pid_sample_new(nullptr), - step_sample_new(nullptr), - gen_sample_new(nullptr), - age_sample_new(nullptr), - mult_sample_new(nullptr), - weight_sample_new(nullptr), - position_sample_new(nullptr) + position_sample(nullptr) #endif {} @@ -540,154 +530,6 @@ void QMCHamiltonian::finalize_traces() streaming_position = false; request.reset(); } - - - - - - - -void QMCHamiltonian::initialize_traces_new(TraceCollector& tm, ParticleSet& P) -{ - static bool first_init_new = true; - - TraceRequestNew& tm_request = tm.state.request; - TraceManagerState& tms = tm.state; - bool trace_log = first_init_new && tms.verbose && omp_get_thread_num() == 0; - if (trace_log) - app_log() << "\n Hamiltonian is initializing traces" << std::endl; - - //make trace quantities available - request_new.contribute_scalar("id", true); //default trace quantity - request_new.contribute_scalar("parent_id", true); //default trace quantity - request_new.contribute_scalar("step", true); //default trace quantity - request_new.contribute_scalar("generation", true); //default trace quantity - request_new.contribute_scalar("age", true); //default trace quantity - request_new.contribute_scalar("multiplicity", true); //default trace quantity - request_new.contribute_scalar("weight", true); //default trace quantity - request_new.contribute_array("position"); - for (int i = 0; i < H.size(); ++i) - H[i]->contributeTraceQuantitiesNew(); - - ////collect trace requests - std::vector requests; - // Hamiltonian request (id, step, weight, positions) - requests.push_back(&request_new); - //// requests from Hamiltonian components - for (int i = 0; i < H.size(); ++i) - requests.push_back(&H[i]->getRequestNew()); - //collect trace quantity availability/requests from contributors/requestors - for (int i = 0; i < requests.size(); ++i) - tm_request.incorporate(*requests[i]); - - //balance requests with availability, mark quantities as streaming/writing - tm_request.determine_stream_write(); - - //relay updated streaming information to all contributors/requestors - for (int i = 0; i < requests.size(); ++i) - tm_request.relay_stream_info(*requests[i]); - - //set streaming/writing traces in general - tms.update_status(); - - // setup traces, if any quantities should be streaming - - // tracing - bool tracing = request_new.streaming(); - if (tracing != tms.streaming_traces) - APP_ABORT("QMCHamiltonian::initialize_traces_new trace request failed to initialize properly"); - if (!tracing) - { - // Empty. Do not log if nothing will be done - - if (trace_log) - app_log() << " no walker traces streaming" << std::endl; - } - else - { - if (trace_log) - app_log() << " walker traces streaming" << std::endl; - //checkout trace quantities - //(requested sources checkout arrays to place samples in for streaming) - // checkout walker trace quantities - streaming_position_new = request_new.streaming_array("position"); - if (request_new.streaming_default_scalars) - { - id_sample_new = tm.checkout_int<1>("id"); - pid_sample_new = tm.checkout_int<1>("parent_id"); - step_sample_new = tm.checkout_int<1>("step"); - gen_sample_new = tm.checkout_int<1>("generation"); - age_sample_new = tm.checkout_int<1>("age"); - mult_sample_new = tm.checkout_int<1>("multiplicity"); - weight_sample_new = tm.checkout_real<1>("weight"); - } - if (streaming_position_new) - position_sample_new = tm.checkout_real<2>("position", P, DIM); - // checkout observable trace quantities - for (int i = 0; i < H.size(); ++i) - { - if (trace_log) - app_log() << " OperatorBase::checkoutTraceQuantitiesNew " << H[i]->getName() << std::endl; - H[i]->checkoutTraceQuantitiesNew(tm); - } - - //all trace samples have been created ( streaming instances) - // mark the ones that will be writing also - tm.screen_writes(); - - //write traces status to the log - //if (trace_log) - // tm.user_report(); - - first_init_new = false; - } -} - - -void QMCHamiltonian::collect_walker_traces_new(Walker_t& walker, int step) -{ - if (request_new.streaming_default_scalars) - { - (*id_sample_new)(0) = walker.getWalkerID(); - (*pid_sample_new)(0) = walker.getParentID(); - (*step_sample_new)(0) = step; - (*gen_sample_new)(0) = walker.Generation; - (*age_sample_new)(0) = walker.Age; - (*mult_sample_new)(0) = walker.Multiplicity; - (*weight_sample_new)(0) = walker.Weight; - } - if (streaming_position_new) - for (int i = 0; i < walker.R.size(); ++i) - for (int d = 0; d < DIM; ++d) - (*position_sample_new)(i, d) = walker.R[i][d]; -} - - -void QMCHamiltonian::finalize_traces_new() -{ - if (request_new.streaming_default_scalars) - { - delete id_sample_new; - delete pid_sample_new; - delete step_sample_new; - delete gen_sample_new; - delete age_sample_new; - delete mult_sample_new; - delete weight_sample_new; - } - if (streaming_position_new) - delete position_sample_new; - if (request_new.streaming()) - { - for (int i = 0; i < H.size(); ++i) - H[i]->deleteTraceQuantitiesNew(); - } - streaming_position_new = false; - request_new.reset(); -} - - - #endif /** Evaluate all the Hamiltonians for the N-particle configuration @@ -705,7 +547,6 @@ QMCHamiltonian::FullPrecRealType QMCHamiltonian::evaluate(ParticleSet& P) updateComponent(*H[i], *this, P); #if !defined(REMOVE_TRACEMANAGER) H[i]->collectScalarTraces(); - H[i]->collectScalarTracesNew(); #endif } updateKinetic(*this, P); @@ -723,7 +564,6 @@ QMCHamiltonian::FullPrecRealType QMCHamiltonian::evaluateDeterministic(ParticleS updateComponent(*H[i], *this, P); #if !defined(REMOVE_TRACEMANAGER) H[i]->collectScalarTraces(); - H[i]->collectScalarTracesNew(); #endif } updateKinetic(*this, P); @@ -887,7 +727,6 @@ void QMCHamiltonian::auxHevaluate(ParticleSet& P) auxH[i]->setObservables(Observables); #if !defined(REMOVE_TRACEMANAGER) auxH[i]->collectScalarTraces(); - auxH[i]->collectScalarTracesNew(); #endif auxH[i]->setParticlePropertyList(P.PropertyList, myIndex); //H[i]->setParticlePropertyList(P.PropertyList,myIndex); @@ -899,7 +738,6 @@ void QMCHamiltonian::auxHevaluate(ParticleSet& P, Walker_t& ThisWalker) { #if !defined(REMOVE_TRACEMANAGER) collect_walker_traces(ThisWalker, P.current_step); - collect_walker_traces_new(ThisWalker, P.current_step); #endif for (int i = 0; i < auxH.size(); ++i) { @@ -908,7 +746,6 @@ void QMCHamiltonian::auxHevaluate(ParticleSet& P, Walker_t& ThisWalker) auxH[i]->setObservables(Observables); #if !defined(REMOVE_TRACEMANAGER) auxH[i]->collectScalarTraces(); - auxH[i]->collectScalarTracesNew(); #endif auxH[i]->setParticlePropertyList(P.PropertyList, myIndex); } @@ -918,7 +755,6 @@ void QMCHamiltonian::auxHevaluate(ParticleSet& P, Walker_t& ThisWalker, bool do_ { #if !defined(REMOVE_TRACEMANAGER) collect_walker_traces(ThisWalker, P.current_step); - collect_walker_traces_new(ThisWalker, P.current_step); #endif for (int i = 0; i < auxH.size(); ++i) { @@ -931,7 +767,6 @@ void QMCHamiltonian::auxHevaluate(ParticleSet& P, Walker_t& ThisWalker, bool do_ auxH[i]->setObservables(Observables); #if !defined(REMOVE_TRACEMANAGER) auxH[i]->collectScalarTraces(); - auxH[i]->collectScalarTracesNew(); #endif auxH[i]->setParticlePropertyList(P.PropertyList, myIndex); } @@ -948,7 +783,6 @@ void QMCHamiltonian::rejectedMove(ParticleSet& P, Walker_t& ThisWalker) // (they will be from the walker moved before this one) #if !defined(REMOVE_TRACEMANAGER) collect_walker_traces(ThisWalker, P.current_step); - collect_walker_traces_new(ThisWalker, P.current_step); #endif // ThisWalker.rejectedMove(); for (int i = 0; i < auxH.size(); ++i) @@ -969,7 +803,6 @@ QMCHamiltonian::FullPrecRealType QMCHamiltonian::evaluateWithToperator(ParticleS updateComponent(*H[i], *this, P); #if !defined(REMOVE_TRACEMANAGER) H[i]->collectScalarTraces(); - H[i]->collectScalarTracesNew(); #endif } updateKinetic(*this, P); diff --git a/src/QMCHamiltonians/QMCHamiltonian.h b/src/QMCHamiltonians/QMCHamiltonian.h index 825578ff27..11dda4ac9c 100644 --- a/src/QMCHamiltonians/QMCHamiltonian.h +++ b/src/QMCHamiltonians/QMCHamiltonian.h @@ -33,7 +33,6 @@ #include "Utilities/Resource.h" #if !defined(REMOVE_TRACEMANAGER) #include "Estimators/TraceManager.h" -#include "Estimators/TraceManagerNew.h" #endif #include "QMCWaveFunctions/OrbitalSetTraits.h" @@ -114,15 +113,6 @@ class QMCHamiltonian ///finalize trace data void finalize_traces(); - - ///initialize trace data - void initialize_traces_new(TraceCollector& tm, ParticleSet& P); - - ///collect walker trace data - void collect_walker_traces_new(Walker_t& walker, int step); - - ///finalize trace data - void finalize_traces_new(); #endif /** @@ -496,18 +486,6 @@ class QMCHamiltonian Array* mult_sample; Array* weight_sample; Array* position_sample; - - ///traces variables - TraceRequestNew request_new; - bool streaming_position_new; - Array* id_sample_new; - Array* pid_sample_new; - Array* step_sample_new; - Array* gen_sample_new; - Array* age_sample_new; - Array* mult_sample_new; - Array* weight_sample_new; - Array* position_sample_new; #endif /// multiwalker shared resource From 6fdcae6bc005d7f912863f507b9e5ba700c59c0d Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Tue, 28 May 2024 01:06:17 -0400 Subject: [PATCH 16/55] cleaning --- src/Estimators/TraceManagerNew.cpp | 8 +--- src/Estimators/TraceManagerNew.h | 64 +++++++++++++----------------- 2 files changed, 29 insertions(+), 43 deletions(-) diff --git a/src/Estimators/TraceManagerNew.cpp b/src/Estimators/TraceManagerNew.cpp index f992c9fa36..5db2e67f1e 100644 --- a/src/Estimators/TraceManagerNew.cpp +++ b/src/Estimators/TraceManagerNew.cpp @@ -26,9 +26,6 @@ namespace qmcplusplus using MCPWalker = Walker; -double TraceManagerNew::trace_tol = 1e-8; - - template void report_row(T& b) @@ -60,10 +57,9 @@ void report_buffer(WalkerTraceBuffer& wtb) -//void TraceCollector::collect(MCPWalker& walker, ParticleSet& pset, TrialWaveFunction& wfn) void TraceCollector::collect(MCPWalker& walker, ParticleSet& pset, TrialWaveFunction& wfn, QMCHamiltonian& ham) { - app_log()<<"TraceCollector::collect (step "< inline void collect(const std::string& name, Array arr) { + //if (verbose) + // app_log()<<"WalkerTraceBuffer("<4) - {/*throw exception*/} + throw std::runtime_error("WalkerTraceBuffer::collect Only arrays up to dimension 4 are currently supported."); if (D>1) n2 = arr.size(1); if (D>2) n3 = arr.size(2); if (D>3) n4 = arr.size(3); @@ -247,7 +249,7 @@ struct WalkerTraceBuffer size_t n2,n3,n4; n2=n3=n4=0; if (D>4) - {/*throw exception*/} + throw std::runtime_error("WalkerTraceBuffer::collect Only arrays up to dimension 4 are currently supported."); if (D>1) n2 = arr.size(1); if (D>2) n3 = arr.size(2); if (D>3) n4 = arr.size(3); @@ -281,9 +283,7 @@ struct WalkerTraceBuffer { app_log()<<"WalkerTraceBuffer("<transfer_state_from(getState()); - tc->distribute(); return tc; } @@ -586,12 +579,12 @@ class TraceManagerNew app_log() << std::endl; } //read trace attributes - std::string verbose_write = "no"; + std::string verbose_write = "no"; OhmmsAttributeSet attrib; attrib.add(state.throttle, "throttle"); attrib.add(verbose_write, "verbose"); attrib.put(cur); - state.verbose = verbose_write == "yes"; + state.verbose = verbose_write == "yes"; } } @@ -603,8 +596,6 @@ class TraceManagerNew if (state.writing_traces && clones.size() > 0) { bool all_same = true; - bool int_same; - bool real_same; TraceCollector& ref = *clones[0]; for (int i = 0; i < clones.size(); ++i) { @@ -617,7 +608,7 @@ class TraceManagerNew { for (int i = 0; i < clones.size(); ++i) clones[i]->write_summary(); - APP_ABORT("TraceManagerNew::check_clones trace buffer widths of clones do not match\n contiguous write is " + throw std::runtime_error("TraceManagerNew::check_clones trace buffer widths of clones do not match\n contiguous write is " "impossible\n this was first caused by clones contributing array traces from identical, but " "differently named, particlesets such as e, e2, e3 ... (fixed)\n please check the TraceManagerNew " "summaries printed above"); @@ -633,7 +624,6 @@ class TraceManagerNew app_log() << "TraceManagerNew::write_buffers "<size(); int rank = communicator->rank(); std::array ptoken; @@ -707,7 +697,7 @@ class TraceManagerNew hdf_file = std::make_unique(); bool successful = hdf_file->create(file_name); if (!successful) - APP_ABORT("TraceManagerNew::open_hdf_file failed to open hdf file " + file_name); + throw std::runtime_error("TraceManagerNew::open_hdf_file failed to open hdf file " + file_name); // only clones have active buffers and associated data TraceCollector& tm = *clones[0]; } From 77bfcbda2c36e716e96679d204babf805d688749 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Tue, 28 May 2024 13:49:13 -0400 Subject: [PATCH 17/55] update trace collector names --- src/Estimators/TraceManagerNew.cpp | 2 +- src/Estimators/TraceManagerNew.h | 34 ++++++++++++------------ src/QMCDrivers/CloneManager.cpp | 3 +-- src/QMCDrivers/CloneManager.h | 2 +- src/QMCDrivers/DMC/DMC.cpp | 17 ++++++------ src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp | 3 +-- src/QMCDrivers/QMCUpdateBase.cpp | 18 ++++++------- src/QMCDrivers/QMCUpdateBase.h | 6 ++--- src/QMCDrivers/VMC/VMC.cpp | 12 ++++----- src/QMCDrivers/VMC/VMCUpdatePbyP.cpp | 2 +- 10 files changed, 48 insertions(+), 51 deletions(-) diff --git a/src/Estimators/TraceManagerNew.cpp b/src/Estimators/TraceManagerNew.cpp index 5db2e67f1e..e4b016f84b 100644 --- a/src/Estimators/TraceManagerNew.cpp +++ b/src/Estimators/TraceManagerNew.cpp @@ -57,7 +57,7 @@ void report_buffer(WalkerTraceBuffer& wtb) -void TraceCollector::collect(MCPWalker& walker, ParticleSet& pset, TrialWaveFunction& wfn, QMCHamiltonian& ham) +void WalkerTraceCollector::collect(MCPWalker& walker, ParticleSet& pset, TrialWaveFunction& wfn, QMCHamiltonian& ham) { //app_log()<<"TraceCollector::collect (step "<; -class TraceCollector +class WalkerTraceCollector { public: @@ -413,7 +413,7 @@ class TraceCollector Array Ltmp; - TraceCollector() + WalkerTraceCollector() : properties_include{"R2Accepted","R2Proposed","LocalEnergy","LocalPotential","Kinetic","ElecElec","ElecIon","LocalECP","NonLocalECP"} { state.reset_permissions(); @@ -446,7 +446,7 @@ class TraceCollector inline void reset_buffers() { if (state.verbose) - app_log() << "TraceCollector::reset_buffers"<transfer_state_from(getState()); return tc; } @@ -589,17 +589,17 @@ class TraceManagerNew } - inline void check_clones(std::vector& clones) + inline void check_clones(std::vector& clones) { if (state.verbose) app_log() << "TraceManagerNew::check_clones" << std::endl; if (state.writing_traces && clones.size() > 0) { bool all_same = true; - TraceCollector& ref = *clones[0]; + WalkerTraceCollector& ref = *clones[0]; for (int i = 0; i < clones.size(); ++i) { - TraceCollector& tm = *clones[i]; + WalkerTraceCollector& tm = *clones[i]; all_same &= tm.walker_property_int_buffer.same_as(ref.walker_property_int_buffer); all_same &= tm.walker_property_real_buffer.same_as(ref.walker_property_real_buffer); all_same &= tm.walker_particle_real_buffer.same_as(ref.walker_particle_real_buffer); @@ -618,7 +618,7 @@ class TraceManagerNew //write buffered trace data to file - inline void write_buffers(std::vector& clones, int block) + inline void write_buffers(std::vector& clones, int block) { if (state.verbose) app_log() << "TraceManagerNew::write_buffers "<& clones) + inline void open_file(std::vector& clones) { if (state.verbose) app_log() << "TraceManagerNew::open_file "<& clones) + inline void startRun(int blocks, std::vector& clones) { if (state.verbose) app_log() << "TraceManagerNew::startRun " << std::endl; @@ -668,7 +668,7 @@ class TraceManagerNew } //hdf file operations - inline void open_hdf_file(std::vector& clones) + inline void open_hdf_file(std::vector& clones) { if (state.verbose) app_log() << "TraceManagerNew::open_hdf_file " << std::endl; @@ -699,15 +699,15 @@ class TraceManagerNew if (!successful) throw std::runtime_error("TraceManagerNew::open_hdf_file failed to open hdf file " + file_name); // only clones have active buffers and associated data - TraceCollector& tm = *clones[0]; + WalkerTraceCollector& tm = *clones[0]; } - inline void write_buffers_hdf(std::vector& clones) + inline void write_buffers_hdf(std::vector& clones) { if (state.verbose) app_log() << "TraceManagerNew::write_buffers_hdf " << std::endl; - TraceCollector& tm_lead = *clones[0]; + WalkerTraceCollector& tm_lead = *clones[0]; if(!registered_hdf) { tm_lead.walker_property_int_buffer.register_hdf_data(*hdf_file); @@ -718,7 +718,7 @@ class TraceManagerNew } for (int ip = 0; ip < clones.size(); ++ip) { - TraceCollector& tm = *clones[ip]; + WalkerTraceCollector& tm = *clones[ip]; tm.walker_property_int_buffer.write_hdf(*hdf_file, tm_lead.walker_property_int_buffer.hdf_file_pointer); tm.walker_property_real_buffer.write_hdf(*hdf_file, tm_lead.walker_property_real_buffer.hdf_file_pointer); tm.walker_particle_real_buffer.write_hdf(*hdf_file, tm_lead.walker_particle_real_buffer.hdf_file_pointer); diff --git a/src/QMCDrivers/CloneManager.cpp b/src/QMCDrivers/CloneManager.cpp index e2f670b990..05a9903864 100644 --- a/src/QMCDrivers/CloneManager.cpp +++ b/src/QMCDrivers/CloneManager.cpp @@ -27,7 +27,6 @@ #include "Estimators/TraceManagerNew.h" #else using TraceManager = int; -using TraceManagerNew = int; #endif //comment this out to use only method to clone @@ -87,7 +86,7 @@ CloneManager::~CloneManager() #if !defined(REMOVE_TRACEMANAGER) delete_iter(traceClones.begin(), traceClones.end()); - delete_iter(traceClonesNew.begin(), traceClonesNew.end()); + delete_iter(wtrace_collectors.begin(), wtrace_collectors.end()); #endif } diff --git a/src/QMCDrivers/CloneManager.h b/src/QMCDrivers/CloneManager.h index 3fdd4cf9a2..ab874ecadd 100644 --- a/src/QMCDrivers/CloneManager.h +++ b/src/QMCDrivers/CloneManager.h @@ -76,7 +76,7 @@ class CloneManager : public QMCTraits ///trace managers std::vector traceClones; ///trace collectors - std::vector traceClonesNew; + std::vector wtrace_collectors; //for correlated sampling. static std::vector> WPoolClones_uptr; diff --git a/src/QMCDrivers/DMC/DMC.cpp b/src/QMCDrivers/DMC/DMC.cpp index 893e943141..da2e1b06bc 100644 --- a/src/QMCDrivers/DMC/DMC.cpp +++ b/src/QMCDrivers/DMC/DMC.cpp @@ -36,7 +36,6 @@ #include "Estimators/TraceManagerNew.h" #else using TraceManager = int; -using TraceManagerNew = int; #endif namespace qmcplusplus @@ -95,7 +94,7 @@ void DMC::resetUpdateEngines() Rng.resize(NumThreads); estimatorClones.resize(NumThreads, nullptr); traceClones.resize(NumThreads, nullptr); - traceClonesNew.resize(NumThreads, nullptr); + wtrace_collectors.resize(NumThreads, nullptr); FairDivideLow(W.getActiveWalkers(), NumThreads, wPerRank); { @@ -132,7 +131,7 @@ void DMC::resetUpdateEngines() estimatorClones[ip]->setCollectionMode(false); #if !defined(REMOVE_TRACEMANAGER) traceClones[ip] = Traces->makeClone(); - traceClonesNew[ip] = Traces_new->makeCollector(); + wtrace_collectors[ip] = Traces_new->makeCollector(); #endif Rng[ip] = rngs_[ip]->makeClone(); hClones[ip]->setRandomGenerator(Rng[ip].get()); @@ -145,7 +144,7 @@ void DMC::resetUpdateEngines() Movers[ip]->setSpinMass(SpinMass); Movers[ip]->put(qmcNode); //Movers[ip]->resetRun(branchEngine.get(), estimatorClones[ip], traceClones[ip], DriftModifier); - Movers[ip]->resetRunNew(branchEngine.get(), estimatorClones[ip], traceClones[ip], traceClonesNew[ip], DriftModifier); + Movers[ip]->resetRun2(branchEngine.get(), estimatorClones[ip], traceClones[ip], wtrace_collectors[ip], DriftModifier); Movers[ip]->initWalkersForPbyP(W.begin() + wPerRank[ip], W.begin() + wPerRank[ip + 1]); } else @@ -164,7 +163,7 @@ void DMC::resetUpdateEngines() Movers[ip]->put(qmcNode); //Movers[ip]->resetRun(branchEngine.get(), estimatorClones[ip], traceClones[ip], DriftModifier); - Movers[ip]->resetRunNew(branchEngine.get(), estimatorClones[ip], traceClones[ip], traceClonesNew[ip], DriftModifier); + Movers[ip]->resetRun2(branchEngine.get(), estimatorClones[ip], traceClones[ip], wtrace_collectors[ip], DriftModifier); Movers[ip]->initWalkersForPbyP(W.begin() + wPerRank[ip], W.begin() + wPerRank[ip + 1]); } else @@ -175,7 +174,7 @@ void DMC::resetUpdateEngines() Movers[ip] = new DMCUpdateAllWithRejection(*wClones[ip], *psiClones[ip], *hClones[ip], *Rng[ip]); Movers[ip]->put(qmcNode); //Movers[ip]->resetRun(branchEngine.get(), estimatorClones[ip], traceClones[ip], DriftModifier); - Movers[ip]->resetRunNew(branchEngine.get(), estimatorClones[ip], traceClones[ip], traceClonesNew[ip], DriftModifier); + Movers[ip]->resetRun2(branchEngine.get(), estimatorClones[ip], traceClones[ip], wtrace_collectors[ip], DriftModifier); Movers[ip]->initWalkers(W.begin() + wPerRank[ip], W.begin() + wPerRank[ip + 1]); } } @@ -188,7 +187,7 @@ void DMC::resetUpdateEngines() for (int ip = 0; ip < NumThreads; ++ip) { traceClones[ip]->transfer_state_from(*Traces); - traceClonesNew[ip]->transfer_state_from(Traces_new->getState()); + wtrace_collectors[ip]->transfer_state_from(Traces_new->getState()); } } #endif @@ -243,7 +242,7 @@ bool DMC::run() Movers[ip]->startRun(nBlocks, false); #if !defined(REMOVE_TRACEMANAGER) Traces->startRun(nBlocks, traceClones); - Traces_new->startRun(nBlocks, traceClonesNew); + Traces_new->startRun(nBlocks, wtrace_collectors); #endif IndexType block = 0; IndexType updatePeriod = (qmc_driver_mode[QMC_UPDATE_MODE]) ? Period4CheckProperties : (nBlocks + 1) * nSteps; @@ -301,7 +300,7 @@ bool DMC::run() Estimators->stopBlock(acceptRatio()); #if !defined(REMOVE_TRACEMANAGER) Traces->write_buffers(traceClones, block); - Traces_new->write_buffers(traceClonesNew, block); + Traces_new->write_buffers(wtrace_collectors, block); #endif block++; if (DumpConfig && block % Period4CheckPoint == 0) diff --git a/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp b/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp index 42d5e6a371..a1f498381e 100644 --- a/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp +++ b/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp @@ -24,7 +24,6 @@ #include "Estimators/TraceManagerNew.h" #else using TraceManager = int; -using TraceManagerNew = int; #endif //#define TEST_INNERBRANCH @@ -171,8 +170,8 @@ void DMCUpdatePbyPWithRejectionFast::advanceWalker(Walker_t& thisWalker, bool re } #if !defined(REMOVE_TRACEMANAGER) Traces->buffer_sample(W.current_step); - Traces_new->collect(thisWalker,W,Psi,H); #endif + wtrace_collector->collect(thisWalker,W,Psi,H); { ScopedTimer local_timer(myTimers[DMC_tmoves]); const int NonLocalMoveAcceptedTemp = H.makeNonLocalMoves(W); diff --git a/src/QMCDrivers/QMCUpdateBase.cpp b/src/QMCDrivers/QMCUpdateBase.cpp index 7feae00c9c..e3f4ad8928 100644 --- a/src/QMCDrivers/QMCUpdateBase.cpp +++ b/src/QMCDrivers/QMCUpdateBase.cpp @@ -38,7 +38,7 @@ QMCUpdateBase::QMCUpdateBase(MCWalkerConfiguration& w, RandomBase& rg) : csoffset(0), Traces(0), - Traces_new(0), + wtrace_collector(0), W(w), Psi(psi), Guide(guide), @@ -59,7 +59,7 @@ QMCUpdateBase::QMCUpdateBase(MCWalkerConfiguration& w, RandomBase& rg) : csoffset(0), Traces(0), - Traces_new(0), + wtrace_collector(0), W(w), Psi(psi), Guide(psi), @@ -117,13 +117,13 @@ bool QMCUpdateBase::put(xmlNodePtr cur) return s; } -void QMCUpdateBase::resetRunNew(BranchEngineType* brancher, - EstimatorManagerBase* est, - TraceManager* traces, - TraceCollector* traces_new, - const DriftModifierBase* driftmodifer) +void QMCUpdateBase::resetRun2(BranchEngineType* brancher, + EstimatorManagerBase* est, + TraceManager* traces, + WalkerTraceCollector* wtrace_collector_, + const DriftModifierBase* driftmodifer) { - Traces_new = traces_new; + wtrace_collector = wtrace_collector_; resetRun(brancher,est,traces,driftmodifer); } @@ -196,8 +196,8 @@ void QMCUpdateBase::startBlock(int steps) Estimators->startBlock(steps); #if !defined(REMOVE_TRACEMANAGER) Traces->startBlock(steps); - Traces_new->startBlock(steps); #endif + wtrace_collector->startBlock(steps); nAccept = 0; nReject = 0; nAllRejected = 0; diff --git a/src/QMCDrivers/QMCUpdateBase.h b/src/QMCDrivers/QMCUpdateBase.h index d4f92839cb..d27d9d9011 100644 --- a/src/QMCDrivers/QMCUpdateBase.h +++ b/src/QMCDrivers/QMCUpdateBase.h @@ -103,10 +103,10 @@ class QMCUpdateBase : public QMCTraits TraceManager* traces, const DriftModifierBase* driftmodifer); - void resetRunNew(BranchEngineType* brancher, + void resetRun2(BranchEngineType* brancher, EstimatorManagerBase* est, TraceManager* traces, - TraceCollector* traces_new, + WalkerTraceCollector* wtrace_collector_, const DriftModifierBase* driftmodifer); inline RealType getTau() @@ -246,7 +246,7 @@ class QMCUpdateBase : public QMCTraits public: ///traces TraceManager* Traces; - TraceCollector* Traces_new; + WalkerTraceCollector* wtrace_collector; protected: ///update particle-by-particle diff --git a/src/QMCDrivers/VMC/VMC.cpp b/src/QMCDrivers/VMC/VMC.cpp index 245df45fbf..191e498c76 100644 --- a/src/QMCDrivers/VMC/VMC.cpp +++ b/src/QMCDrivers/VMC/VMC.cpp @@ -67,7 +67,7 @@ bool VMC::run() Movers[ip]->startRun(nBlocks, false); #if !defined(REMOVE_TRACEMANAGER) Traces->startRun(nBlocks, traceClones); - Traces_new->startRun(nBlocks, traceClonesNew); + Traces_new->startRun(nBlocks, wtrace_collectors); #endif LoopTimer<> vmc_loop; @@ -111,7 +111,7 @@ bool VMC::run() Estimators->stopBlock(estimatorClones); #if !defined(REMOVE_TRACEMANAGER) Traces->write_buffers(traceClones, block); - Traces_new->write_buffers(traceClonesNew, block); + Traces_new->write_buffers(wtrace_collectors, block); #endif recordBlock(block); vmc_loop.stop(); @@ -170,7 +170,7 @@ void VMC::resetRun() Movers.resize(NumThreads, nullptr); estimatorClones.resize(NumThreads, nullptr); traceClones.resize(NumThreads, nullptr); - traceClonesNew.resize(NumThreads, nullptr); + wtrace_collectors.resize(NumThreads, nullptr); Rng.resize(NumThreads); // hdf_archive::hdf_archive() is not thread-safe @@ -185,7 +185,7 @@ void VMC::resetRun() estimatorClones[ip]->setCollectionMode(false); #if !defined(REMOVE_TRACEMANAGER) traceClones[ip] = Traces->makeClone(); - traceClonesNew[ip] = Traces_new->makeCollector(); + wtrace_collectors[ip] = Traces_new->makeCollector(); #endif Rng[ip] = rngs_[ip]->makeClone(); hClones[ip]->setRandomGenerator(Rng[ip].get()); @@ -224,7 +224,7 @@ void VMC::resetRun() for (int ip = 0; ip < NumThreads; ++ip) { traceClones[ip]->transfer_state_from(*Traces); - traceClonesNew[ip]->transfer_state_from(Traces_new->getState()); + wtrace_collectors[ip]->transfer_state_from(Traces_new->getState()); } } #endif @@ -271,7 +271,7 @@ void VMC::resetRun() //int ip=omp_get_thread_num(); Movers[ip]->put(qmcNode); //Movers[ip]->resetRun(branchEngine.get(), estimatorClones[ip], traceClones[ip], DriftModifier); - Movers[ip]->resetRunNew(branchEngine.get(), estimatorClones[ip], traceClones[ip], traceClonesNew[ip], DriftModifier); + Movers[ip]->resetRun2(branchEngine.get(), estimatorClones[ip], traceClones[ip], wtrace_collectors[ip], DriftModifier); if (qmc_driver_mode[QMC_UPDATE_MODE]) Movers[ip]->initWalkersForPbyP(W.begin() + wPerRank[ip], W.begin() + wPerRank[ip + 1]); else diff --git a/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp b/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp index a7e4e363ae..0130f51a1f 100644 --- a/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp +++ b/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp @@ -133,8 +133,8 @@ void VMCUpdatePbyP::advanceWalker(Walker_t& thisWalker, bool recompute) collectables_timer_.stop(); #if !defined(REMOVE_TRACEMANAGER) Traces->buffer_sample(W.current_step); - Traces_new->collect(thisWalker,W,Psi,H); #endif + wtrace_collector->collect(thisWalker,W,Psi,H); if (!moved) ++nAllRejected; } From c50cbfcfd2df1b14d5091b1b0d9069558054424d Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Tue, 28 May 2024 15:42:46 -0400 Subject: [PATCH 18/55] walker trace manager names --- ...eManagerNew.cpp => WalkerTraceManager.cpp} | 2 +- ...TraceManagerNew.h => WalkerTraceManager.h} | 38 +++++++++---------- src/QMCDrivers/CloneManager.cpp | 2 +- src/QMCDrivers/DMC/DMC.cpp | 2 +- src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp | 2 +- src/QMCDrivers/QMCDriver.cpp | 6 +-- src/QMCDrivers/QMCDriver.h | 6 +-- src/QMCDrivers/QMCDriverNew.h | 2 +- src/QMCDrivers/QMCUpdateBase.cpp | 2 +- src/QMCDrivers/QMCUpdateBase.h | 4 +- src/QMCDrivers/VMC/VMC.cpp | 4 +- src/QMCHamiltonians/CMakeLists.txt | 2 +- 12 files changed, 36 insertions(+), 36 deletions(-) rename src/Estimators/{TraceManagerNew.cpp => WalkerTraceManager.cpp} (99%) rename src/Estimators/{TraceManagerNew.h => WalkerTraceManager.h} (93%) diff --git a/src/Estimators/TraceManagerNew.cpp b/src/Estimators/WalkerTraceManager.cpp similarity index 99% rename from src/Estimators/TraceManagerNew.cpp rename to src/Estimators/WalkerTraceManager.cpp index e4b016f84b..4ccca6355d 100644 --- a/src/Estimators/TraceManagerNew.cpp +++ b/src/Estimators/WalkerTraceManager.cpp @@ -11,7 +11,7 @@ ////////////////////////////////////////////////////////////////////////////////////// -#include "TraceManagerNew.h" +#include "WalkerTraceManager.h" #include "Particle/Walker.h" //#include "Particle/ParticleSet.h" diff --git a/src/Estimators/TraceManagerNew.h b/src/Estimators/WalkerTraceManager.h similarity index 93% rename from src/Estimators/TraceManagerNew.h rename to src/Estimators/WalkerTraceManager.h index b77372f632..81d1717fd8 100644 --- a/src/Estimators/TraceManagerNew.h +++ b/src/Estimators/WalkerTraceManager.h @@ -487,7 +487,7 @@ class WalkerTraceCollector -class TraceManagerNew +class WalkerTraceManager { public: @@ -517,7 +517,7 @@ class TraceManagerNew WalkerTraceBuffer wmed_particle_real_buffer; - TraceManagerNew(Communicate* comm = 0) + WalkerTraceManager(Communicate* comm = 0) { state.reset_permissions(); communicator = comm; @@ -552,7 +552,7 @@ class TraceManagerNew inline WalkerTraceCollector* makeCollector() { if (state.verbose) - app_log() << "TraceManagerNew::makeCollector " << std::endl; + app_log() << "WalkerTraceManager::makeCollector " << std::endl; WalkerTraceCollector* tc = new WalkerTraceCollector(); tc->transfer_state_from(getState()); return tc; @@ -562,7 +562,7 @@ class TraceManagerNew inline void put(xmlNodePtr cur, bool allow_traces, std::string series_root) { if (state.verbose) - app_log()<<"TraceManagerNew::put"<& clones) { if (state.verbose) - app_log() << "TraceManagerNew::check_clones" << std::endl; + app_log() << "WalkerTraceManager::check_clones" << std::endl; if (state.writing_traces && clones.size() > 0) { bool all_same = true; @@ -608,9 +608,9 @@ class TraceManagerNew { for (int i = 0; i < clones.size(); ++i) clones[i]->write_summary(); - throw std::runtime_error("TraceManagerNew::check_clones trace buffer widths of clones do not match\n contiguous write is " + throw std::runtime_error("WalkerTraceManager::check_clones trace buffer widths of clones do not match\n contiguous write is " "impossible\n this was first caused by clones contributing array traces from identical, but " - "differently named, particlesets such as e, e2, e3 ... (fixed)\n please check the TraceManagerNew " + "differently named, particlesets such as e, e2, e3 ... (fixed)\n please check the WalkerTraceManager " "summaries printed above"); } } @@ -621,7 +621,7 @@ class TraceManagerNew inline void write_buffers(std::vector& clones, int block) { if (state.verbose) - app_log() << "TraceManagerNew::write_buffers "<& clones) { if (state.verbose) - app_log() << "TraceManagerNew::open_file "<& clones) { if (state.verbose) - app_log() << "TraceManagerNew::startRun " << std::endl; + app_log() << "WalkerTraceManager::startRun " << std::endl; check_clones(clones); open_file(clones); } @@ -663,7 +663,7 @@ class TraceManagerNew inline void stopRun() { if (state.verbose) - app_log() << "TraceManagerNew::stopRun " << std::endl; + app_log() << "WalkerTraceManager::stopRun " << std::endl; close_file(); } @@ -671,9 +671,9 @@ class TraceManagerNew inline void open_hdf_file(std::vector& clones) { if (state.verbose) - app_log() << "TraceManagerNew::open_hdf_file " << std::endl; + app_log() << "WalkerTraceManager::open_hdf_file " << std::endl; if (clones.size() == 0) - throw std::runtime_error("TraceManagerNew::open_hdf_file no trace clones exist, cannot open file"); + throw std::runtime_error("WalkerTraceManager::open_hdf_file no trace clones exist, cannot open file"); int nprocs = communicator->size(); int rank = communicator->rank(); std::array ptoken; @@ -693,11 +693,11 @@ class TraceManagerNew } file_name += ".wtraces.h5"; if (state.verbose) - app_log() << "TraceManagerNew::open_hdf_file opening traces hdf file " << file_name << std::endl; + app_log() << "WalkerTraceManager::open_hdf_file opening traces hdf file " << file_name << std::endl; hdf_file = std::make_unique(); bool successful = hdf_file->create(file_name); if (!successful) - throw std::runtime_error("TraceManagerNew::open_hdf_file failed to open hdf file " + file_name); + throw std::runtime_error("WalkerTraceManager::open_hdf_file failed to open hdf file " + file_name); // only clones have active buffers and associated data WalkerTraceCollector& tm = *clones[0]; } @@ -706,7 +706,7 @@ class TraceManagerNew inline void write_buffers_hdf(std::vector& clones) { if (state.verbose) - app_log() << "TraceManagerNew::write_buffers_hdf " << std::endl; + app_log() << "WalkerTraceManager::write_buffers_hdf " << std::endl; WalkerTraceCollector& tm_lead = *clones[0]; if(!registered_hdf) { @@ -727,7 +727,7 @@ class TraceManagerNew inline void close_hdf_file() { if (state.verbose) - app_log() << "TraceManagerNew::close_hdf_file " << std::endl; + app_log() << "WalkerTraceManager::close_hdf_file " << std::endl; hdf_file.reset(); } diff --git a/src/QMCDrivers/CloneManager.cpp b/src/QMCDrivers/CloneManager.cpp index 05a9903864..6c3421f65c 100644 --- a/src/QMCDrivers/CloneManager.cpp +++ b/src/QMCDrivers/CloneManager.cpp @@ -24,7 +24,7 @@ #include "Utilities/qmc_common.h" #if !defined(REMOVE_TRACEMANAGER) #include "Estimators/TraceManager.h" -#include "Estimators/TraceManagerNew.h" +#include "Estimators/WalkerTraceManager.h" #else using TraceManager = int; #endif diff --git a/src/QMCDrivers/DMC/DMC.cpp b/src/QMCDrivers/DMC/DMC.cpp index da2e1b06bc..42eb03148d 100644 --- a/src/QMCDrivers/DMC/DMC.cpp +++ b/src/QMCDrivers/DMC/DMC.cpp @@ -33,7 +33,7 @@ #include "Utilities/FairDivide.h" #if !defined(REMOVE_TRACEMANAGER) #include "Estimators/TraceManager.h" -#include "Estimators/TraceManagerNew.h" +#include "Estimators/WalkerTraceManager.h" #else using TraceManager = int; #endif diff --git a/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp b/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp index a1f498381e..5a3723ebc1 100644 --- a/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp +++ b/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp @@ -21,7 +21,7 @@ #include "QMCDrivers/DriftOperators.h" #if !defined(REMOVE_TRACEMANAGER) #include "Estimators/TraceManager.h" -#include "Estimators/TraceManagerNew.h" +#include "Estimators/WalkerTraceManager.h" #else using TraceManager = int; #endif diff --git a/src/QMCDrivers/QMCDriver.cpp b/src/QMCDrivers/QMCDriver.cpp index 9587240db0..724689bd88 100644 --- a/src/QMCDrivers/QMCDriver.cpp +++ b/src/QMCDrivers/QMCDriver.cpp @@ -33,10 +33,10 @@ #include "QMCDrivers/GreenFunctionModifiers/DriftModifierBuilder.h" #if !defined(REMOVE_TRACEMANAGER) #include "Estimators/TraceManager.h" -#include "Estimators/TraceManagerNew.h" +#include "Estimators/WalkerTraceManager.h" #else using TraceManager = int; -using TraceManagerNew = int; +using WalkerTraceManager = int; #endif namespace qmcplusplus @@ -209,7 +209,7 @@ void QMCDriver::process(xmlNodePtr cur) //create and initialize traces if (!Traces_new) { - Traces_new = std::make_unique(myComm); + Traces_new = std::make_unique(myComm); } Traces_new->put(traces_xml_new, allow_traces_new, RootName); #endif diff --git a/src/QMCDrivers/QMCDriver.h b/src/QMCDrivers/QMCDriver.h index 4848cc7e27..6f64fa5c13 100644 --- a/src/QMCDrivers/QMCDriver.h +++ b/src/QMCDrivers/QMCDriver.h @@ -31,7 +31,7 @@ #include "QMCWaveFunctions/WaveFunctionPool.h" #include "QMCHamiltonians/QMCHamiltonian.h" #include "Estimators/EstimatorManagerBase.h" -#include "Estimators/TraceManagerNew.h" +#include "Estimators/WalkerTraceManager.h" #include "QMCDrivers/DriverTraits.h" #include "QMCDrivers/QMCDriverInterface.h" #include "QMCDrivers/GreenFunctionModifiers/DriftModifierBase.h" @@ -63,7 +63,7 @@ namespace qmcplusplus class MCWalkerConfiguration; class HDFWalkerOutput; class TraceManager; -class TraceManagerNew; +class WalkerTraceManager; /** @ingroup QMCDrivers * @{ @@ -199,7 +199,7 @@ class QMCDriver : public QMCDriverInterface, public QMCTraits, public MPIObjectB std::unique_ptr Traces; ///Traces manager - std::unique_ptr Traces_new; + std::unique_ptr Traces_new; ///return the random generators inline RefVector> getRngRefs() const diff --git a/src/QMCDrivers/QMCDriverNew.h b/src/QMCDrivers/QMCDriverNew.h index 2318ea0436..dab1eb4a4b 100644 --- a/src/QMCDrivers/QMCDriverNew.h +++ b/src/QMCDrivers/QMCDriverNew.h @@ -51,7 +51,7 @@ namespace qmcplusplus { //forward declarations: Do not include headers if not needed class TraceManager; -class TraceManagerNew; +class WalkerTraceManager; class EstimatorManagerNew; class TrialWaveFunction; class QMCHamiltonian; diff --git a/src/QMCDrivers/QMCUpdateBase.cpp b/src/QMCDrivers/QMCUpdateBase.cpp index e3f4ad8928..4cb61bb42d 100644 --- a/src/QMCDrivers/QMCUpdateBase.cpp +++ b/src/QMCDrivers/QMCUpdateBase.cpp @@ -23,7 +23,7 @@ #include "Concurrency/OpenMP.h" #if !defined(REMOVE_TRACEMANAGER) #include "Estimators/TraceManager.h" -#include "Estimators/TraceManagerNew.h" +#include "Estimators/WalkerTraceManager.h" #else using TraceManager = int; #endif diff --git a/src/QMCDrivers/QMCUpdateBase.h b/src/QMCDrivers/QMCUpdateBase.h index d27d9d9011..c37d5fcc3b 100644 --- a/src/QMCDrivers/QMCUpdateBase.h +++ b/src/QMCDrivers/QMCUpdateBase.h @@ -23,7 +23,7 @@ #include "QMCWaveFunctions/TrialWaveFunction.h" #include "QMCHamiltonians/QMCHamiltonian.h" #include "QMCHamiltonians/NonLocalTOperator.h" -#include "Estimators/TraceManagerNew.h" +#include "Estimators/WalkerTraceManager.h" #include "GreenFunctionModifiers/DriftModifierBase.h" #include "SimpleFixedNodeBranch.h" #include "DriverDebugChecks.h" @@ -32,7 +32,7 @@ namespace qmcplusplus { class TraceManager; -class TraceManagerNew; +class WalkerTraceManager; /** @ingroup QMC * @brief Base class for update methods for each step * diff --git a/src/QMCDrivers/VMC/VMC.cpp b/src/QMCDrivers/VMC/VMC.cpp index 191e498c76..68855ca20d 100644 --- a/src/QMCDrivers/VMC/VMC.cpp +++ b/src/QMCDrivers/VMC/VMC.cpp @@ -29,10 +29,10 @@ #include "Utilities/FairDivide.h" #if !defined(REMOVE_TRACEMANAGER) #include "Estimators/TraceManager.h" -#include "Estimators/TraceManagerNew.h" +#include "Estimators/WalkerTraceManager.h" #else using TraceManager = int; -using TraceManagerNew = int; +using WalkerTraceManager = int; #endif namespace qmcplusplus diff --git a/src/QMCHamiltonians/CMakeLists.txt b/src/QMCHamiltonians/CMakeLists.txt index 8f7d6b3a52..4f30e3793f 100644 --- a/src/QMCHamiltonians/CMakeLists.txt +++ b/src/QMCHamiltonians/CMakeLists.txt @@ -70,7 +70,7 @@ if(OHMMS_DIM MATCHES 3) ECPComponentBuilder_L2.cpp) if(NOT REMOVE_TRACEMANAGER) - set(HAMSRCS ${HAMSRCS} ../Estimators/TraceManager.cpp ../Estimators/TraceManagerNew.cpp ReferencePoints.cpp SpaceGrid.cpp EnergyDensityEstimator.cpp + set(HAMSRCS ${HAMSRCS} ../Estimators/TraceManager.cpp ../Estimators/WalkerTraceManager.cpp ReferencePoints.cpp SpaceGrid.cpp EnergyDensityEstimator.cpp DensityMatrices1B.cpp) endif() From 4c881ef2837a592308a568cc05ba58c80f6ed5cd Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Tue, 28 May 2024 16:02:56 -0400 Subject: [PATCH 19/55] walker trace manager names, continued --- src/QMCApp/QMCMain.cpp | 7 +++---- src/QMCApp/QMCMain.h | 2 +- src/QMCDrivers/DMC/DMC.cpp | 10 +++++----- src/QMCDrivers/QMCDriver.cpp | 8 ++++---- src/QMCDrivers/QMCDriver.h | 13 +++++-------- src/QMCDrivers/QMCDriverFactory.cpp | 4 ++-- src/QMCDrivers/QMCDriverInterface.h | 4 ++-- src/QMCDrivers/QMCDriverNew.h | 4 ++-- src/QMCDrivers/VMC/VMC.cpp | 10 +++++----- 9 files changed, 29 insertions(+), 33 deletions(-) diff --git a/src/QMCApp/QMCMain.cpp b/src/QMCApp/QMCMain.cpp index e3e398dc78..0db92b1142 100644 --- a/src/QMCApp/QMCMain.cpp +++ b/src/QMCApp/QMCMain.cpp @@ -66,7 +66,7 @@ QMCMain::QMCMain(Communicate* c) #if !defined(REMOVE_TRACEMANAGER) , traces_xml_(NULL), - traces_xml_new_(NULL) + walker_traces_xml_(NULL) #endif { Communicate node_comm{OHMMS::Controller->NodeComm()}; @@ -485,8 +485,7 @@ bool QMCMain::validateXML() } else if (cname == "walkertraces") { - app_log()<<"JTK: got walkertraces xml input"<putWalkers(walker_set_in_); #if !defined(REMOVE_TRACEMANAGER) qmc_driver->putTraces(traces_xml_); - qmc_driver->putTracesNew(traces_xml_new_); + qmc_driver->putWalkerTraces(walker_traces_xml_); #endif { ScopedTimer qmc_run_timer(createGlobalTimer(qmc_driver->getEngineName(), timer_level_coarse)); diff --git a/src/QMCApp/QMCMain.h b/src/QMCApp/QMCMain.h index b3f36c2471..fbc13e1506 100644 --- a/src/QMCApp/QMCMain.h +++ b/src/QMCApp/QMCMain.h @@ -83,7 +83,7 @@ class QMCMain : public MPIObjectBase, public QMCAppBase xmlNodePtr traces_xml_; ///traces xml - xmlNodePtr traces_xml_new_; + xmlNodePtr walker_traces_xml_; ///qmc sections std::vector> qmc_action_; diff --git a/src/QMCDrivers/DMC/DMC.cpp b/src/QMCDrivers/DMC/DMC.cpp index 42eb03148d..7a9cb79737 100644 --- a/src/QMCDrivers/DMC/DMC.cpp +++ b/src/QMCDrivers/DMC/DMC.cpp @@ -131,7 +131,7 @@ void DMC::resetUpdateEngines() estimatorClones[ip]->setCollectionMode(false); #if !defined(REMOVE_TRACEMANAGER) traceClones[ip] = Traces->makeClone(); - wtrace_collectors[ip] = Traces_new->makeCollector(); + wtrace_collectors[ip] = wtrace_manager->makeCollector(); #endif Rng[ip] = rngs_[ip]->makeClone(); hClones[ip]->setRandomGenerator(Rng[ip].get()); @@ -187,7 +187,7 @@ void DMC::resetUpdateEngines() for (int ip = 0; ip < NumThreads; ++ip) { traceClones[ip]->transfer_state_from(*Traces); - wtrace_collectors[ip]->transfer_state_from(Traces_new->getState()); + wtrace_collectors[ip]->transfer_state_from(wtrace_manager->getState()); } } #endif @@ -242,7 +242,7 @@ bool DMC::run() Movers[ip]->startRun(nBlocks, false); #if !defined(REMOVE_TRACEMANAGER) Traces->startRun(nBlocks, traceClones); - Traces_new->startRun(nBlocks, wtrace_collectors); + wtrace_manager->startRun(nBlocks, wtrace_collectors); #endif IndexType block = 0; IndexType updatePeriod = (qmc_driver_mode[QMC_UPDATE_MODE]) ? Period4CheckProperties : (nBlocks + 1) * nSteps; @@ -300,7 +300,7 @@ bool DMC::run() Estimators->stopBlock(acceptRatio()); #if !defined(REMOVE_TRACEMANAGER) Traces->write_buffers(traceClones, block); - Traces_new->write_buffers(wtrace_collectors, block); + wtrace_manager->write_buffers(wtrace_collectors, block); #endif block++; if (DumpConfig && block % Period4CheckPoint == 0) @@ -334,7 +334,7 @@ bool DMC::run() Movers[ip]->stopRun2(); #if !defined(REMOVE_TRACEMANAGER) Traces->stopRun(); - Traces_new->stopRun(); + wtrace_manager->stopRun(); #endif return finalize(nBlocks); } diff --git a/src/QMCDrivers/QMCDriver.cpp b/src/QMCDrivers/QMCDriver.cpp index 724689bd88..18704fb321 100644 --- a/src/QMCDrivers/QMCDriver.cpp +++ b/src/QMCDrivers/QMCDriver.cpp @@ -64,7 +64,7 @@ QMCDriver::QMCDriver(const ProjectData& project_data, DumpConfig = false; IsQMCDriver = true; allow_traces = false; - allow_traces_new = false; + allow_walker_traces = false; MyCounter = 0; // value //accept multiple names for the same value @@ -207,11 +207,11 @@ void QMCDriver::process(xmlNodePtr cur) Traces->put(traces_xml, allow_traces, RootName); //create and initialize traces - if (!Traces_new) + if (!wtrace_manager) { - Traces_new = std::make_unique(myComm); + wtrace_manager = std::make_unique(myComm); } - Traces_new->put(traces_xml_new, allow_traces_new, RootName); + wtrace_manager->put(walker_traces_xml, allow_walker_traces, RootName); #endif branchEngine->put(cur); Estimators->put(H, cur); diff --git a/src/QMCDrivers/QMCDriver.h b/src/QMCDrivers/QMCDriver.h index 6f64fa5c13..873b7f79ec 100644 --- a/src/QMCDrivers/QMCDriver.h +++ b/src/QMCDrivers/QMCDriver.h @@ -99,9 +99,9 @@ class QMCDriver : public QMCDriverInterface, public QMCTraits, public MPIObjectB xmlNodePtr traces_xml; /// whether to allow traces - bool allow_traces_new; + bool allow_walker_traces; /// traces xml - xmlNodePtr traces_xml_new; + xmlNodePtr walker_traces_xml; /// Constructor. QMCDriver(const ProjectData& project_data, @@ -156,12 +156,9 @@ class QMCDriver : public QMCDriverInterface, public QMCTraits, public MPIObjectB inline void requestTraces(bool traces) override { allow_traces = traces; } - inline void putTracesNew(xmlNodePtr txml) override { - app_log()<<"JTK: putTracesNew"< Traces; ///Traces manager - std::unique_ptr Traces_new; + std::unique_ptr wtrace_manager; ///return the random generators inline RefVector> getRngRefs() const diff --git a/src/QMCDrivers/QMCDriverFactory.cpp b/src/QMCDrivers/QMCDriverFactory.cpp index f4651a5ad6..bbcab9e5c2 100644 --- a/src/QMCDrivers/QMCDriverFactory.cpp +++ b/src/QMCDrivers/QMCDriverFactory.cpp @@ -296,9 +296,9 @@ std::unique_ptr QMCDriverFactory::createQMCDriver(xmlNodePtr new_driver->requestTraces(allow_traces); //add trace information - bool allow_traces_new = das.walkertraces_tag == "yes" || + bool allow_walker_traces = das.walkertraces_tag == "yes" || (das.walkertraces_tag == "none" && (das.new_run_type == QMCRunType::VMC || das.new_run_type == QMCRunType::DMC)); - new_driver->requestTracesNew(allow_traces_new); + new_driver->requestWalkerTraces(allow_walker_traces); return new_driver; } diff --git a/src/QMCDrivers/QMCDriverInterface.h b/src/QMCDrivers/QMCDriverInterface.h index 59168f9ed5..9781dad82b 100644 --- a/src/QMCDrivers/QMCDriverInterface.h +++ b/src/QMCDrivers/QMCDriverInterface.h @@ -49,8 +49,8 @@ class QMCDriverInterface virtual void putWalkers(std::vector& wset) = 0; virtual void putTraces(xmlNodePtr txml) = 0; virtual void requestTraces(bool allow_traces) = 0; - virtual void putTracesNew(xmlNodePtr txml) = 0; - virtual void requestTracesNew(bool allow_traces) = 0; + virtual void putWalkerTraces(xmlNodePtr txml) = 0; + virtual void requestWalkerTraces(bool allow_traces) = 0; virtual void process(xmlNodePtr cur) = 0; virtual QMCRunType getRunType() = 0; virtual std::string getEngineName() = 0; diff --git a/src/QMCDrivers/QMCDriverNew.h b/src/QMCDrivers/QMCDriverNew.h index dab1eb4a4b..7306ebaef2 100644 --- a/src/QMCDrivers/QMCDriverNew.h +++ b/src/QMCDrivers/QMCDriverNew.h @@ -242,8 +242,8 @@ class QMCDriverNew : public QMCDriverInterface, public MPIObjectBase void putTraces(xmlNodePtr txml) override {} void requestTraces(bool allow_traces) override {} - void putTracesNew(xmlNodePtr txml) override {} - void requestTracesNew(bool allow_traces) override {} + void putWalkerTraces(xmlNodePtr txml) override {} + void requestWalkerTraces(bool allow_traces) override {} // scales a MCCoords by sqrtTau. Chooses appropriate taus by CT template diff --git a/src/QMCDrivers/VMC/VMC.cpp b/src/QMCDrivers/VMC/VMC.cpp index 68855ca20d..0cd1923e5e 100644 --- a/src/QMCDrivers/VMC/VMC.cpp +++ b/src/QMCDrivers/VMC/VMC.cpp @@ -67,7 +67,7 @@ bool VMC::run() Movers[ip]->startRun(nBlocks, false); #if !defined(REMOVE_TRACEMANAGER) Traces->startRun(nBlocks, traceClones); - Traces_new->startRun(nBlocks, wtrace_collectors); + wtrace_manager->startRun(nBlocks, wtrace_collectors); #endif LoopTimer<> vmc_loop; @@ -111,7 +111,7 @@ bool VMC::run() Estimators->stopBlock(estimatorClones); #if !defined(REMOVE_TRACEMANAGER) Traces->write_buffers(traceClones, block); - Traces_new->write_buffers(wtrace_collectors, block); + wtrace_manager->write_buffers(wtrace_collectors, block); #endif recordBlock(block); vmc_loop.stop(); @@ -134,7 +134,7 @@ bool VMC::run() Movers[ip]->stopRun2(); #if !defined(REMOVE_TRACEMANAGER) Traces->stopRun(); - Traces_new->stopRun(); + wtrace_manager->stopRun(); #endif //copy back the random states for (int ip = 0; ip < NumThreads; ++ip) @@ -185,7 +185,7 @@ void VMC::resetRun() estimatorClones[ip]->setCollectionMode(false); #if !defined(REMOVE_TRACEMANAGER) traceClones[ip] = Traces->makeClone(); - wtrace_collectors[ip] = Traces_new->makeCollector(); + wtrace_collectors[ip] = wtrace_manager->makeCollector(); #endif Rng[ip] = rngs_[ip]->makeClone(); hClones[ip]->setRandomGenerator(Rng[ip].get()); @@ -224,7 +224,7 @@ void VMC::resetRun() for (int ip = 0; ip < NumThreads; ++ip) { traceClones[ip]->transfer_state_from(*Traces); - wtrace_collectors[ip]->transfer_state_from(Traces_new->getState()); + wtrace_collectors[ip]->transfer_state_from(wtrace_manager->getState()); } } #endif From dceab3ac10600e6eecf2f7c5e211b9e87e69fa4e Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Tue, 28 May 2024 16:26:24 -0400 Subject: [PATCH 20/55] revoke prejudice --- src/Estimators/WalkerTraceManager.h | 6 +++--- src/QMCApp/QMCMain.cpp | 10 +++++----- src/QMCApp/QMCMain.h | 6 +++--- src/QMCDrivers/CloneManager.cpp | 4 ++-- src/QMCDrivers/DMC/DMC.cpp | 14 +++++++------- src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp | 2 +- src/QMCDrivers/QMCDriver.cpp | 8 ++------ src/QMCDrivers/QMCUpdateBase.cpp | 2 +- src/QMCDrivers/VMC/VMC.cpp | 21 ++++++++++----------- 9 files changed, 34 insertions(+), 39 deletions(-) diff --git a/src/Estimators/WalkerTraceManager.h b/src/Estimators/WalkerTraceManager.h index 81d1717fd8..e6ac0a7916 100644 --- a/src/Estimators/WalkerTraceManager.h +++ b/src/Estimators/WalkerTraceManager.h @@ -427,7 +427,7 @@ class WalkerTraceCollector } - inline void transfer_state_from(const TraceManagerState& tms) + inline void set_state(const TraceManagerState& tms) { // JTK: rename this function as "setState" state = tms; @@ -544,7 +544,7 @@ class WalkerTraceManager } - inline TraceManagerState getState() + inline TraceManagerState get_state() { return state; } @@ -554,7 +554,7 @@ class WalkerTraceManager if (state.verbose) app_log() << "WalkerTraceManager::makeCollector " << std::endl; WalkerTraceCollector* tc = new WalkerTraceCollector(); - tc->transfer_state_from(getState()); + tc->set_state(get_state()); return tc; } diff --git a/src/QMCApp/QMCMain.cpp b/src/QMCApp/QMCMain.cpp index 0db92b1142..e8514f5e5b 100644 --- a/src/QMCApp/QMCMain.cpp +++ b/src/QMCApp/QMCMain.cpp @@ -62,11 +62,11 @@ QMCMain::QMCMain(Communicate* c) psi_pool_(std::make_unique(my_project_.getRuntimeOptions(), *particle_set_pool_, myComm)), ham_pool_(std::make_unique(*particle_set_pool_, *psi_pool_, myComm)), qmc_system_(nullptr), - first_qmc_(true) + first_qmc_(true), + walker_traces_xml_(NULL) #if !defined(REMOVE_TRACEMANAGER) , - traces_xml_(NULL), - walker_traces_xml_(NULL) + traces_xml_(NULL) #endif { Communicate node_comm{OHMMS::Controller->NodeComm()}; @@ -483,11 +483,11 @@ bool QMCMain::validateXML() { traces_xml_ = cur; } +#endif else if (cname == "walkertraces") { walker_traces_xml_ = cur; } -#endif else { //everything else goes to m_qmcaction @@ -632,8 +632,8 @@ bool QMCMain::runQMC(xmlNodePtr cur, bool reuse) qmc_driver->putWalkers(walker_set_in_); #if !defined(REMOVE_TRACEMANAGER) qmc_driver->putTraces(traces_xml_); - qmc_driver->putWalkerTraces(walker_traces_xml_); #endif + qmc_driver->putWalkerTraces(walker_traces_xml_); { ScopedTimer qmc_run_timer(createGlobalTimer(qmc_driver->getEngineName(), timer_level_coarse)); Timer process_and_run; diff --git a/src/QMCApp/QMCMain.h b/src/QMCApp/QMCMain.h index fbc13e1506..b56c88e168 100644 --- a/src/QMCApp/QMCMain.h +++ b/src/QMCApp/QMCMain.h @@ -79,11 +79,11 @@ class QMCMain : public MPIObjectBase, public QMCAppBase ///xml mcwalkerset read-in elements std::vector walker_set_in_; - ///traces xml - xmlNodePtr traces_xml_; + ///walkertraces xml + xmlNodePtr walker_traces_xml_; ///traces xml - xmlNodePtr walker_traces_xml_; + xmlNodePtr traces_xml_; ///qmc sections std::vector> qmc_action_; diff --git a/src/QMCDrivers/CloneManager.cpp b/src/QMCDrivers/CloneManager.cpp index 6c3421f65c..5703741294 100644 --- a/src/QMCDrivers/CloneManager.cpp +++ b/src/QMCDrivers/CloneManager.cpp @@ -24,10 +24,10 @@ #include "Utilities/qmc_common.h" #if !defined(REMOVE_TRACEMANAGER) #include "Estimators/TraceManager.h" -#include "Estimators/WalkerTraceManager.h" #else using TraceManager = int; #endif +#include "Estimators/WalkerTraceManager.h" //comment this out to use only method to clone #define ENABLE_CLONE_PSI_AND_H @@ -86,8 +86,8 @@ CloneManager::~CloneManager() #if !defined(REMOVE_TRACEMANAGER) delete_iter(traceClones.begin(), traceClones.end()); - delete_iter(wtrace_collectors.begin(), wtrace_collectors.end()); #endif + delete_iter(wtrace_collectors.begin(), wtrace_collectors.end()); } void CloneManager::makeClones(MCWalkerConfiguration& w, TrialWaveFunction& psi, QMCHamiltonian& ham) diff --git a/src/QMCDrivers/DMC/DMC.cpp b/src/QMCDrivers/DMC/DMC.cpp index 7a9cb79737..ba7e5c66c4 100644 --- a/src/QMCDrivers/DMC/DMC.cpp +++ b/src/QMCDrivers/DMC/DMC.cpp @@ -33,10 +33,10 @@ #include "Utilities/FairDivide.h" #if !defined(REMOVE_TRACEMANAGER) #include "Estimators/TraceManager.h" -#include "Estimators/WalkerTraceManager.h" #else using TraceManager = int; #endif +#include "Estimators/WalkerTraceManager.h" namespace qmcplusplus { @@ -131,8 +131,8 @@ void DMC::resetUpdateEngines() estimatorClones[ip]->setCollectionMode(false); #if !defined(REMOVE_TRACEMANAGER) traceClones[ip] = Traces->makeClone(); - wtrace_collectors[ip] = wtrace_manager->makeCollector(); #endif + wtrace_collectors[ip] = wtrace_manager->makeCollector(); Rng[ip] = rngs_[ip]->makeClone(); hClones[ip]->setRandomGenerator(Rng[ip].get()); if (W.isSpinor()) @@ -180,17 +180,17 @@ void DMC::resetUpdateEngines() } } } -#if !defined(REMOVE_TRACEMANAGER) else { +#if !defined(REMOVE_TRACEMANAGER) #pragma omp parallel for for (int ip = 0; ip < NumThreads; ++ip) - { traceClones[ip]->transfer_state_from(*Traces); - wtrace_collectors[ip]->transfer_state_from(wtrace_manager->getState()); - } - } #endif +#pragma omp parallel for + for (int ip = 0; ip < NumThreads; ++ip) + wtrace_collectors[ip]->set_state(wtrace_manager->get_state()); + } if (spinor) app_log() << " Spins treated as dynamic variable with SpinMass: " << SpinMass << std::endl; diff --git a/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp b/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp index 5a3723ebc1..f8d09f94ca 100644 --- a/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp +++ b/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp @@ -21,10 +21,10 @@ #include "QMCDrivers/DriftOperators.h" #if !defined(REMOVE_TRACEMANAGER) #include "Estimators/TraceManager.h" -#include "Estimators/WalkerTraceManager.h" #else using TraceManager = int; #endif +#include "Estimators/WalkerTraceManager.h" //#define TEST_INNERBRANCH diff --git a/src/QMCDrivers/QMCDriver.cpp b/src/QMCDrivers/QMCDriver.cpp index 18704fb321..56cf0429dd 100644 --- a/src/QMCDrivers/QMCDriver.cpp +++ b/src/QMCDrivers/QMCDriver.cpp @@ -33,11 +33,10 @@ #include "QMCDrivers/GreenFunctionModifiers/DriftModifierBuilder.h" #if !defined(REMOVE_TRACEMANAGER) #include "Estimators/TraceManager.h" -#include "Estimators/WalkerTraceManager.h" #else using TraceManager = int; -using WalkerTraceManager = int; #endif +#include "Estimators/WalkerTraceManager.h" namespace qmcplusplus { @@ -205,14 +204,11 @@ void QMCDriver::process(xmlNodePtr cur) Traces = std::make_unique(myComm); } Traces->put(traces_xml, allow_traces, RootName); - +#endif //create and initialize traces if (!wtrace_manager) - { wtrace_manager = std::make_unique(myComm); - } wtrace_manager->put(walker_traces_xml, allow_walker_traces, RootName); -#endif branchEngine->put(cur); Estimators->put(H, cur); if (!wOut) diff --git a/src/QMCDrivers/QMCUpdateBase.cpp b/src/QMCDrivers/QMCUpdateBase.cpp index 4cb61bb42d..10498fecbd 100644 --- a/src/QMCDrivers/QMCUpdateBase.cpp +++ b/src/QMCDrivers/QMCUpdateBase.cpp @@ -23,10 +23,10 @@ #include "Concurrency/OpenMP.h" #if !defined(REMOVE_TRACEMANAGER) #include "Estimators/TraceManager.h" -#include "Estimators/WalkerTraceManager.h" #else using TraceManager = int; #endif +#include "Estimators/WalkerTraceManager.h" namespace qmcplusplus { diff --git a/src/QMCDrivers/VMC/VMC.cpp b/src/QMCDrivers/VMC/VMC.cpp index 0cd1923e5e..3c2e74a91e 100644 --- a/src/QMCDrivers/VMC/VMC.cpp +++ b/src/QMCDrivers/VMC/VMC.cpp @@ -29,11 +29,10 @@ #include "Utilities/FairDivide.h" #if !defined(REMOVE_TRACEMANAGER) #include "Estimators/TraceManager.h" -#include "Estimators/WalkerTraceManager.h" #else using TraceManager = int; -using WalkerTraceManager = int; #endif +#include "Estimators/WalkerTraceManager.h" namespace qmcplusplus { @@ -67,8 +66,8 @@ bool VMC::run() Movers[ip]->startRun(nBlocks, false); #if !defined(REMOVE_TRACEMANAGER) Traces->startRun(nBlocks, traceClones); - wtrace_manager->startRun(nBlocks, wtrace_collectors); #endif + wtrace_manager->startRun(nBlocks, wtrace_collectors); LoopTimer<> vmc_loop; RunTimeControl<> runtimeControl(run_time_manager, MaxCPUSecs, myComm->getName(), myComm->rank() == 0); @@ -111,8 +110,8 @@ bool VMC::run() Estimators->stopBlock(estimatorClones); #if !defined(REMOVE_TRACEMANAGER) Traces->write_buffers(traceClones, block); - wtrace_manager->write_buffers(wtrace_collectors, block); #endif + wtrace_manager->write_buffers(wtrace_collectors, block); recordBlock(block); vmc_loop.stop(); @@ -134,8 +133,8 @@ bool VMC::run() Movers[ip]->stopRun2(); #if !defined(REMOVE_TRACEMANAGER) Traces->stopRun(); - wtrace_manager->stopRun(); #endif + wtrace_manager->stopRun(); //copy back the random states for (int ip = 0; ip < NumThreads; ++ip) rngs_[ip] = Rng[ip]->makeClone(); @@ -185,8 +184,8 @@ void VMC::resetRun() estimatorClones[ip]->setCollectionMode(false); #if !defined(REMOVE_TRACEMANAGER) traceClones[ip] = Traces->makeClone(); - wtrace_collectors[ip] = wtrace_manager->makeCollector(); #endif + wtrace_collectors[ip] = wtrace_manager->makeCollector(); Rng[ip] = rngs_[ip]->makeClone(); hClones[ip]->setRandomGenerator(Rng[ip].get()); if (W.isSpinor()) @@ -217,17 +216,17 @@ void VMC::resetRun() app_log() << os.str() << std::endl; } } -#if !defined(REMOVE_TRACEMANAGER) else { +#if !defined(REMOVE_TRACEMANAGER) #pragma omp parallel for for (int ip = 0; ip < NumThreads; ++ip) - { traceClones[ip]->transfer_state_from(*Traces); - wtrace_collectors[ip]->transfer_state_from(wtrace_manager->getState()); - } - } #endif +#pragma omp parallel for + for (int ip = 0; ip < NumThreads; ++ip) + wtrace_collectors[ip]->set_state(wtrace_manager->get_state()); + } if (qmc_driver_mode[QMC_UPDATE_MODE]) { app_log() << " Using Particle by Particle moves" << std::endl; From e7544be5809326ba894e6d4d99824795c66dc448 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Wed, 29 May 2024 09:15:10 -0400 Subject: [PATCH 21/55] migrate to cpp, cleanup includes --- src/Estimators/WalkerTraceManager.cpp | 268 +++++++++++++++++++- src/Estimators/WalkerTraceManager.h | 349 ++++---------------------- 2 files changed, 305 insertions(+), 312 deletions(-) diff --git a/src/Estimators/WalkerTraceManager.cpp b/src/Estimators/WalkerTraceManager.cpp index 4ccca6355d..c91091f06f 100644 --- a/src/Estimators/WalkerTraceManager.cpp +++ b/src/Estimators/WalkerTraceManager.cpp @@ -13,8 +13,11 @@ #include "WalkerTraceManager.h" +#include "OhmmsData/OhmmsElementBase.h" +#include "OhmmsData/AttributeSet.h" + #include "Particle/Walker.h" -//#include "Particle/ParticleSet.h" +#include "Particle/ParticleSet.h" #include "QMCWaveFunctions/TrialWaveFunction.h" #include "QMCHamiltonians/QMCHamiltonian.h" @@ -47,18 +50,51 @@ void report_buffer(WalkerTraceBuffer& wtb) for (size_t r=0;rset_state(get_state()); + return tc; +} + + +void WalkerTraceManager::startRun(int blocks, std::vector& collectors) +{ + if (!state.traces_active) return; + if (state.verbose) app_log() << "WalkerTraceManager::startRun " << std::endl; + check_collectors(collectors); + open_file(collectors); +} + + +void WalkerTraceManager::stopRun() +{ + if (!state.traces_active) return; + if (state.verbose) app_log() << "WalkerTraceManager::stopRun " << std::endl; + close_file(); +} + + +void WalkerTraceManager::stopStep() +{ + if(!state.traces_active) return; + // find min/max/median walker and collect in buffers +} + + +void WalkerTraceManager::write_buffers(std::vector& collectors, int block) +{ + if (!state.traces_active) return; + if (state.verbose) app_log() << "WalkerTraceManager::write_buffers "<& collectors) +{ + if (!state.traces_active) return; + if (state.verbose) app_log() << "WalkerTraceManager::check_collectors" << std::endl; + if (collectors.size() > 0) + { + bool all_same = true; + WalkerTraceCollector& ref = *collectors[0]; + for (int i = 0; i < collectors.size(); ++i) + { + WalkerTraceCollector& tm = *collectors[i]; + all_same &= tm.walker_property_int_buffer.same_as(ref.walker_property_int_buffer); + all_same &= tm.walker_property_real_buffer.same_as(ref.walker_property_real_buffer); + all_same &= tm.walker_particle_real_buffer.same_as(ref.walker_particle_real_buffer); + } + if (!all_same) + { + throw std::runtime_error("WalkerTraceManager::check_collectors trace buffer widths of collectors do not match\n contiguous write is " + "impossible\n this was first caused by collectors contributing array traces from identical, but " + "differently named, particlesets such as e, e2, e3 ... (fixed)\n please check the WalkerTraceManager " + "summaries printed above"); + } + } } + + +void WalkerTraceManager::open_file(std::vector& collectors) +{ + if (!state.traces_active) return; + if (state.verbose) app_log() << "WalkerTraceManager::open_file "<& collectors) +{ + if (!state.traces_active) return; + if (state.verbose) app_log() << "WalkerTraceManager::open_hdf_file " << std::endl; + if (collectors.size() == 0) + throw std::runtime_error("WalkerTraceManager::open_hdf_file no trace collectors exist, cannot open file"); + int nprocs = communicator->size(); + int rank = communicator->rank(); + std::array ptoken; + std::string file_name = file_root; + if (nprocs > 1) + { + int length{0}; + if (nprocs > 10000) + length = std::snprintf(ptoken.data(), ptoken.size(), ".p%05d", rank); + else if (nprocs > 1000) + length = std::snprintf(ptoken.data(), ptoken.size(), ".p%04d", rank); + else + length = std::snprintf(ptoken.data(), ptoken.size(), ".p%03d", rank); + if (length < 0) + throw std::runtime_error("Error generating filename"); + file_name.append(ptoken.data(), length); + } + file_name += ".wtraces.h5"; + if (state.verbose) app_log() << "WalkerTraceManager::open_hdf_file opening traces hdf file " << file_name << std::endl; + hdf_file = std::make_unique(); + bool successful = hdf_file->create(file_name); + if (!successful) + throw std::runtime_error("WalkerTraceManager::open_hdf_file failed to open hdf file " + file_name); +} + + +void WalkerTraceManager::write_buffers_hdf(std::vector& collectors) +{ + if (!state.traces_active) return; + if (state.verbose) app_log() << "WalkerTraceManager::write_buffers_hdf " << std::endl; + WalkerTraceCollector& tc_lead = *collectors[0]; + if(!registered_hdf) + { + tc_lead.walker_property_int_buffer.register_hdf_data(*hdf_file); + tc_lead.walker_property_real_buffer.register_hdf_data(*hdf_file); + tc_lead.walker_particle_real_buffer.register_hdf_data(*hdf_file); + registered_hdf = true; + } + for (int ip = 0; ip < collectors.size(); ++ip) + { + WalkerTraceCollector& tc = *collectors[ip]; + tc.walker_property_int_buffer.write_hdf(*hdf_file, tc_lead.walker_property_int_buffer.hdf_file_pointer); + tc.walker_property_real_buffer.write_hdf(*hdf_file, tc_lead.walker_property_real_buffer.hdf_file_pointer); + tc.walker_particle_real_buffer.write_hdf(*hdf_file, tc_lead.walker_particle_real_buffer.hdf_file_pointer); + } +} + + +void WalkerTraceManager::close_hdf_file() +{ + if (!state.traces_active) return; + if (state.verbose) app_log() << "WalkerTraceManager::close_hdf_file " << std::endl; + hdf_file.reset(); +} + + + +} // namespace qmcplusplus diff --git a/src/Estimators/WalkerTraceManager.h b/src/Estimators/WalkerTraceManager.h index e6ac0a7916..961bbb0b3c 100644 --- a/src/Estimators/WalkerTraceManager.h +++ b/src/Estimators/WalkerTraceManager.h @@ -10,26 +10,14 @@ ////////////////////////////////////////////////////////////////////////////////////// -#ifndef QMCPLUSPLUS_TRACEMANAGERNEW_H -#define QMCPLUSPLUS_TRACEMANAGERNEW_H +#ifndef QMCPLUSPLUS_WALKERTRACEMANAGER_H +#define QMCPLUSPLUS_WALKERTRACEMANAGER_H #include -#include "OhmmsData/OhmmsElementBase.h" -#include "OhmmsData/AttributeSet.h" #include "OhmmsPETE/OhmmsArray.h" -#include "Particle/ParticleSet.h" -#include "Utilities/IteratorUtility.h" -#include "ModernStringUtils.hpp" #include "Message/Communicate.h" #include "hdf/hdf_archive.h" -#include "Concurrency/OpenMP.h" - -#include -#include -#include -#include -#include #include @@ -49,7 +37,6 @@ using WTracePsiVal = WTraceComp; - struct WalkerQuantityInfo { std::string name; @@ -355,35 +342,30 @@ struct WalkerTraceBuffer - - -struct TraceManagerState +struct WalkerTraceState { - bool method_allows_traces; - bool streaming_traces; - bool writing_traces; - int throttle; + bool traces_active; + int step_period; bool verbose; - TraceManagerState() + WalkerTraceState() { reset_permissions(); - throttle = 1; - verbose = false; + step_period = 1; + verbose = false; } inline void reset_permissions() { - method_allows_traces = false; - streaming_traces = false; - writing_traces = false; - verbose = false; + traces_active = false; + verbose = false; } }; template class Walker; +class ParticleSet; class TrialWaveFunction; class QMCHamiltonian; using MCPWalker = Walker; @@ -393,18 +375,17 @@ using MCPWalker = Walker; class WalkerTraceCollector { public: + std::vector energies; + WalkerTraceBuffer walker_property_int_buffer; + WalkerTraceBuffer walker_property_real_buffer; + WalkerTraceBuffer walker_particle_real_buffer; - TraceManagerState state; - - // new walker buffers std::unordered_set properties_include; std::vector property_indices; int energy_index; - std::vector energies; - WalkerTraceBuffer walker_property_int_buffer; - WalkerTraceBuffer walker_property_real_buffer; - WalkerTraceBuffer walker_particle_real_buffer; +private: + WalkerTraceState state; // temporary (contiguous) storage for awful ParticleAttrib<> quantities Array Rtmp; @@ -412,91 +393,32 @@ class WalkerTraceCollector Array Gtmp; Array Ltmp; +public: + WalkerTraceCollector(); - WalkerTraceCollector() - : properties_include{"R2Accepted","R2Proposed","LocalEnergy","LocalPotential","Kinetic","ElecElec","ElecIon","LocalECP","NonLocalECP"} - { - state.reset_permissions(); - - // new walker buffers, etc - energy_index = -1; - energies.resize(0); - walker_property_int_buffer.label = "walker_property_int"; - walker_property_real_buffer.label = "walker_property_real"; - walker_particle_real_buffer.label = "walker_particle_real"; - } - - - inline void set_state(const TraceManagerState& tms) - { - // JTK: rename this function as "setState" - state = tms; - walker_property_int_buffer.verbose = state.verbose; - walker_property_real_buffer.verbose = state.verbose; - walker_particle_real_buffer.verbose = state.verbose; - } - - - inline void reset_step() - { - energies.resize(0); - } - - - inline void reset_buffers() - { - if (state.verbose) - app_log() << "WalkerTraceCollector::reset_buffers"< hdf_file; bool registered_hdf; - TraceManagerState state; + WalkerTraceState state; // new walker buffers bool write_particle_data; @@ -516,228 +438,41 @@ class WalkerTraceManager WalkerTraceBuffer wmed_property_real_buffer; WalkerTraceBuffer wmed_particle_real_buffer; +public: + WalkerTraceManager(Communicate* comm = 0); - WalkerTraceManager(Communicate* comm = 0) - { - state.reset_permissions(); - communicator = comm; - - registered_hdf = false; - - // new walker buffers, etc - write_particle_data = false; - write_min_data = true; - write_max_data = true; - write_med_data = true; - - wmin_property_int_buffer.label = "wmin_property_int"; - wmin_property_real_buffer.label = "wmin_property_real"; - wmin_particle_real_buffer.label = "wmin_particle_real"; - - wmax_property_int_buffer.label = "wmax_property_int"; - wmax_property_real_buffer.label = "wmax_property_real"; - wmax_particle_real_buffer.label = "wmax_particle_real"; - - wmed_property_int_buffer.label = "wmed_property_int"; - wmed_property_real_buffer.label = "wmed_property_real"; - wmed_particle_real_buffer.label = "wmed_particle_real"; - } - - - inline TraceManagerState get_state() - { - return state; - } - - inline WalkerTraceCollector* makeCollector() - { - if (state.verbose) - app_log() << "WalkerTraceManager::makeCollector " << std::endl; - WalkerTraceCollector* tc = new WalkerTraceCollector(); - tc->set_state(get_state()); - return tc; - } + void put(xmlNodePtr cur, bool allow_traces, std::string series_root); + inline WalkerTraceState get_state() { return state; } - inline void put(xmlNodePtr cur, bool allow_traces, std::string series_root) - { - if (state.verbose) - app_log()<<"WalkerTraceManager::put"<& collectors); - inline void check_clones(std::vector& clones) - { - if (state.verbose) - app_log() << "WalkerTraceManager::check_clones" << std::endl; - if (state.writing_traces && clones.size() > 0) - { - bool all_same = true; - WalkerTraceCollector& ref = *clones[0]; - for (int i = 0; i < clones.size(); ++i) - { - WalkerTraceCollector& tm = *clones[i]; - all_same &= tm.walker_property_int_buffer.same_as(ref.walker_property_int_buffer); - all_same &= tm.walker_property_real_buffer.same_as(ref.walker_property_real_buffer); - all_same &= tm.walker_particle_real_buffer.same_as(ref.walker_particle_real_buffer); - } - if (!all_same) - { - for (int i = 0; i < clones.size(); ++i) - clones[i]->write_summary(); - throw std::runtime_error("WalkerTraceManager::check_clones trace buffer widths of clones do not match\n contiguous write is " - "impossible\n this was first caused by clones contributing array traces from identical, but " - "differently named, particlesets such as e, e2, e3 ... (fixed)\n please check the WalkerTraceManager " - "summaries printed above"); - } - } - } + void stopRun(); + void stopStep(); //write buffered trace data to file - inline void write_buffers(std::vector& clones, int block) - { - if (state.verbose) - app_log() << "WalkerTraceManager::write_buffers "<& clones) - { - if (state.verbose) - app_log() << "WalkerTraceManager::open_file "<write_summary(); - open_hdf_file(clones); - } - } - - - inline void close_file() - { - if (state.verbose) - app_log() << "WalkerTraceManager::close_file " << std::endl; - if (state.writing_traces) - close_hdf_file(); - } - + void write_buffers(std::vector& collectors, int block); - inline void startRun(int blocks, std::vector& clones) - { - if (state.verbose) - app_log() << "WalkerTraceManager::startRun " << std::endl; - check_clones(clones); - open_file(clones); - } +private: + void check_collectors(std::vector& collectors); + void open_file(std::vector& collectors); - inline void stopRun() - { - if (state.verbose) - app_log() << "WalkerTraceManager::stopRun " << std::endl; - close_file(); - } + void close_file(); //hdf file operations - inline void open_hdf_file(std::vector& clones) - { - if (state.verbose) - app_log() << "WalkerTraceManager::open_hdf_file " << std::endl; - if (clones.size() == 0) - throw std::runtime_error("WalkerTraceManager::open_hdf_file no trace clones exist, cannot open file"); - int nprocs = communicator->size(); - int rank = communicator->rank(); - std::array ptoken; - std::string file_name = file_root; - if (nprocs > 1) - { - int length{0}; - if (nprocs > 10000) - length = std::snprintf(ptoken.data(), ptoken.size(), ".p%05d", rank); - else if (nprocs > 1000) - length = std::snprintf(ptoken.data(), ptoken.size(), ".p%04d", rank); - else - length = std::snprintf(ptoken.data(), ptoken.size(), ".p%03d", rank); - if (length < 0) - throw std::runtime_error("Error generating filename"); - file_name.append(ptoken.data(), length); - } - file_name += ".wtraces.h5"; - if (state.verbose) - app_log() << "WalkerTraceManager::open_hdf_file opening traces hdf file " << file_name << std::endl; - hdf_file = std::make_unique(); - bool successful = hdf_file->create(file_name); - if (!successful) - throw std::runtime_error("WalkerTraceManager::open_hdf_file failed to open hdf file " + file_name); - // only clones have active buffers and associated data - WalkerTraceCollector& tm = *clones[0]; - } - - - inline void write_buffers_hdf(std::vector& clones) - { - if (state.verbose) - app_log() << "WalkerTraceManager::write_buffers_hdf " << std::endl; - WalkerTraceCollector& tm_lead = *clones[0]; - if(!registered_hdf) - { - tm_lead.walker_property_int_buffer.register_hdf_data(*hdf_file); - tm_lead.walker_property_real_buffer.register_hdf_data(*hdf_file); - tm_lead.walker_particle_real_buffer.register_hdf_data(*hdf_file); - - registered_hdf = true; - } - for (int ip = 0; ip < clones.size(); ++ip) - { - WalkerTraceCollector& tm = *clones[ip]; - tm.walker_property_int_buffer.write_hdf(*hdf_file, tm_lead.walker_property_int_buffer.hdf_file_pointer); - tm.walker_property_real_buffer.write_hdf(*hdf_file, tm_lead.walker_property_real_buffer.hdf_file_pointer); - tm.walker_particle_real_buffer.write_hdf(*hdf_file, tm_lead.walker_particle_real_buffer.hdf_file_pointer); - } - } + void open_hdf_file(std::vector& collectors); - inline void close_hdf_file() { - if (state.verbose) - app_log() << "WalkerTraceManager::close_hdf_file " << std::endl; - hdf_file.reset(); - } + void write_buffers_hdf(std::vector& collectors); + void close_hdf_file(); }; - } // namespace qmcplusplus - - #endif From 75f2aa1c8e519caf7187be923423fd1db5a9a52e Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Wed, 29 May 2024 12:35:45 -0400 Subject: [PATCH 22/55] implementation of min/max/median energy walker data buffering --- src/Estimators/WalkerTraceManager.cpp | 144 +++++++++++++++++++++++--- src/Estimators/WalkerTraceManager.h | 65 ++++++------ 2 files changed, 159 insertions(+), 50 deletions(-) diff --git a/src/Estimators/WalkerTraceManager.cpp b/src/Estimators/WalkerTraceManager.cpp index c91091f06f..620b032f64 100644 --- a/src/Estimators/WalkerTraceManager.cpp +++ b/src/Estimators/WalkerTraceManager.cpp @@ -57,15 +57,16 @@ void report_buffer(WalkerTraceBuffer& wtb) -/////////////////////////////////// -// WalkerTraceCollector methods // -/////////////////////////////////// +////////////////////////////////// +// WalkerTraceCollector methods // +////////////////////////////////// WalkerTraceCollector::WalkerTraceCollector() : properties_include{"R2Accepted","R2Proposed","LocalEnergy","LocalPotential","Kinetic","ElecElec","ElecIon","LocalECP","NonLocalECP"} { state.reset_permissions(); energy_index = -1; + steps.resize(0); energies.resize(0); walker_property_int_buffer.label = "walker_property_int"; walker_property_real_buffer.label = "walker_property_real"; @@ -73,7 +74,6 @@ WalkerTraceCollector::WalkerTraceCollector() } - void WalkerTraceCollector::set_state(const WalkerTraceState& tms) { state = tms; @@ -170,6 +170,7 @@ void WalkerTraceCollector::collect(MCPWalker& walker, ParticleSet& pset, TrialWa bar.reset_collect(); // save the energy of this walker + steps.push_back((size_t)pset.current_step); energies.push_back((WTraceReal)walker.Properties(0,energy_index)); //app_log()<<" walker_property_int buffer contents:\n"; @@ -188,26 +189,41 @@ void WalkerTraceCollector::collect(MCPWalker& walker, ParticleSet& pset, TrialWa } -void WalkerTraceCollector::reset_step() -{ - energies.resize(0); -} - - void WalkerTraceCollector::reset_buffers() { if (state.verbose) app_log() << "WalkerTraceCollector::reset_buffers"<& colle { if (!state.traces_active) return; if (state.verbose) app_log() << "WalkerTraceManager::write_buffers "<(v); + if (n==0) + { + n1 = n; + prev_step = step; + } + if (step!=prev_step || n==energy_order.size()-1) + { + // for a given step, find data for min/max/median energy walkers + // n1/n2 are indices of the first/last data in energy_order for this step + if (step!=prev_step) n2 = n-1; + if (n==energy_order.size()-1) n2 = n; + auto nmin = n1; // index of minimum energy walker for this step + auto nmax = n2; // index of maximum energy walker for this step + auto nmed = (n1+n2)/2; // index of median energy walker for this step + //app_log()<<" "<(energy_order[nmin]); + r = std::get<3>(energy_order[nmin]); + wmin_property_int_buffer.add_row(collectors[c]->walker_property_int_buffer,r); + wmin_property_real_buffer.add_row(collectors[c]->walker_property_real_buffer,r); + wmin_particle_real_buffer.add_row(collectors[c]->walker_particle_real_buffer,r); + // cache data for maximum energy walker + c = std::get<2>(energy_order[nmax]); + r = std::get<3>(energy_order[nmax]); + wmax_property_int_buffer.add_row(collectors[c]->walker_property_int_buffer,r); + wmax_property_real_buffer.add_row(collectors[c]->walker_property_real_buffer,r); + wmax_particle_real_buffer.add_row(collectors[c]->walker_particle_real_buffer,r); + // cache data for median energy walker + c = std::get<2>(energy_order[nmed]); + r = std::get<3>(energy_order[nmed]); + wmed_property_int_buffer.add_row(collectors[c]->walker_property_int_buffer,r); + wmed_property_real_buffer.add_row(collectors[c]->walker_property_real_buffer,r); + wmed_particle_real_buffer.add_row(collectors[c]->walker_particle_real_buffer,r); + // reset pointers + n1 = n; + prev_step = step; + } + n++; + } + //app_log()<(v) << " " << std::get<1>(v) << " " << std::get<2>(v) << " " << std::get<3>(v) << std::endl; + // n++; + //} + energy_order.resize(0); + + // write buffer data to file write_buffers_hdf(collectors); } @@ -316,10 +408,10 @@ void WalkerTraceManager::check_collectors(std::vector& co WalkerTraceCollector& ref = *collectors[0]; for (int i = 0; i < collectors.size(); ++i) { - WalkerTraceCollector& tm = *collectors[i]; - all_same &= tm.walker_property_int_buffer.same_as(ref.walker_property_int_buffer); - all_same &= tm.walker_property_real_buffer.same_as(ref.walker_property_real_buffer); - all_same &= tm.walker_particle_real_buffer.same_as(ref.walker_particle_real_buffer); + WalkerTraceCollector& tc = *collectors[i]; + all_same &= tc.walker_property_int_buffer.same_as(ref.walker_property_int_buffer); + all_same &= tc.walker_property_real_buffer.same_as(ref.walker_property_real_buffer); + all_same &= tc.walker_particle_real_buffer.same_as(ref.walker_particle_real_buffer); } if (!all_same) { @@ -390,6 +482,15 @@ void WalkerTraceManager::write_buffers_hdf(std::vector& c tc_lead.walker_property_int_buffer.register_hdf_data(*hdf_file); tc_lead.walker_property_real_buffer.register_hdf_data(*hdf_file); tc_lead.walker_particle_real_buffer.register_hdf_data(*hdf_file); + wmin_property_int_buffer.register_hdf_data(*hdf_file); + wmin_property_real_buffer.register_hdf_data(*hdf_file); + wmin_particle_real_buffer.register_hdf_data(*hdf_file); + wmax_property_int_buffer.register_hdf_data(*hdf_file); + wmax_property_real_buffer.register_hdf_data(*hdf_file); + wmax_particle_real_buffer.register_hdf_data(*hdf_file); + wmed_property_int_buffer.register_hdf_data(*hdf_file); + wmed_property_real_buffer.register_hdf_data(*hdf_file); + wmed_particle_real_buffer.register_hdf_data(*hdf_file); registered_hdf = true; } for (int ip = 0; ip < collectors.size(); ++ip) @@ -399,6 +500,15 @@ void WalkerTraceManager::write_buffers_hdf(std::vector& c tc.walker_property_real_buffer.write_hdf(*hdf_file, tc_lead.walker_property_real_buffer.hdf_file_pointer); tc.walker_particle_real_buffer.write_hdf(*hdf_file, tc_lead.walker_particle_real_buffer.hdf_file_pointer); } + wmin_property_int_buffer.write_hdf(*hdf_file); + wmin_property_real_buffer.write_hdf(*hdf_file); + wmin_particle_real_buffer.write_hdf(*hdf_file); + wmax_property_int_buffer.write_hdf(*hdf_file); + wmax_property_real_buffer.write_hdf(*hdf_file); + wmax_particle_real_buffer.write_hdf(*hdf_file); + wmed_property_int_buffer.write_hdf(*hdf_file); + wmed_property_real_buffer.write_hdf(*hdf_file); + wmed_particle_real_buffer.write_hdf(*hdf_file); } diff --git a/src/Estimators/WalkerTraceManager.h b/src/Estimators/WalkerTraceManager.h index 961bbb0b3c..e0f58aabb6 100644 --- a/src/Estimators/WalkerTraceManager.h +++ b/src/Estimators/WalkerTraceManager.h @@ -71,6 +71,7 @@ struct WalkerQuantityInfo + template struct WalkerTraceBuffer { @@ -82,8 +83,6 @@ struct WalkerTraceBuffer bool first_collect; size_t quantity_pointer; - size_t row_start_pointer; - size_t row_end_pointer; //hdf variables std::string label; @@ -105,8 +104,6 @@ struct WalkerTraceBuffer { app_log()<<"WalkerTraceBuffer("<& ref) { @@ -266,15 +249,24 @@ struct WalkerTraceBuffer } - inline void add_row(Array other_buffer, size_t i) + inline void add_row(WalkerTraceBuffer other, size_t i) { - app_log()<<"WalkerTraceBuffer("< 0) { f.push(top); @@ -336,7 +332,7 @@ struct WalkerTraceBuffer f.pop(); } f.flush(); - app_log()<<" "<; class WalkerTraceCollector { public: + std::vector steps; std::vector energies; WalkerTraceBuffer walker_property_int_buffer; WalkerTraceBuffer walker_property_real_buffer; @@ -402,7 +399,7 @@ class WalkerTraceCollector void collect(MCPWalker& walker, ParticleSet& pset, TrialWaveFunction& wfn, QMCHamiltonian& ham); - void reset_step(); + void check_buffers(); private: void reset_buffers(); @@ -426,6 +423,8 @@ class WalkerTraceManager bool write_max_data; bool write_med_data; + std::vector> energy_order; + WalkerTraceBuffer wmin_property_int_buffer; WalkerTraceBuffer wmin_property_real_buffer; WalkerTraceBuffer wmin_particle_real_buffer; From ecfdca892001a5a63bafc6d1a9fda393d8a4d830 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Thu, 30 May 2024 00:07:56 -0400 Subject: [PATCH 23/55] fix min/max/med buffering, works now --- src/Estimators/WalkerTraceManager.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Estimators/WalkerTraceManager.h b/src/Estimators/WalkerTraceManager.h index e0f58aabb6..9288545335 100644 --- a/src/Estimators/WalkerTraceManager.h +++ b/src/Estimators/WalkerTraceManager.h @@ -256,6 +256,7 @@ struct WalkerTraceBuffer if (first_collect) { reset_rowsize(other_buffer.size(1)); + quantity_info = other.quantity_info; first_collect = false; } else @@ -263,10 +264,10 @@ struct WalkerTraceBuffer if(buffer.size(1)!=other_buffer.size(1)) throw std::runtime_error("WalkerTraceBuffer::add_row Row sizes must match."); make_new_row(); - size_t ib = buffer.size(0)-1; - for(size_t j=0;j Date: Thu, 30 May 2024 00:30:25 -0400 Subject: [PATCH 24/55] cleanup api --- src/Estimators/WalkerTraceManager.cpp | 17 ++--------------- src/Estimators/WalkerTraceManager.h | 17 +++-------------- src/QMCDrivers/DMC/DMC.cpp | 6 +++--- src/QMCDrivers/VMC/VMC.cpp | 4 ++-- 4 files changed, 10 insertions(+), 34 deletions(-) diff --git a/src/Estimators/WalkerTraceManager.cpp b/src/Estimators/WalkerTraceManager.cpp index 620b032f64..090e6d7789 100644 --- a/src/Estimators/WalkerTraceManager.cpp +++ b/src/Estimators/WalkerTraceManager.cpp @@ -290,7 +290,7 @@ WalkerTraceCollector* WalkerTraceManager::makeCollector() } -void WalkerTraceManager::startRun(int blocks, std::vector& collectors) +void WalkerTraceManager::startRun(std::vector& collectors) { if (!state.traces_active) return; if (state.verbose) app_log() << "WalkerTraceManager::startRun " << std::endl; @@ -307,14 +307,7 @@ void WalkerTraceManager::stopRun() } -void WalkerTraceManager::stopStep() -{ - if(!state.traces_active) return; - // find min/max/median walker and collect in buffers -} - - -void WalkerTraceManager::write_buffers(std::vector& collectors, int block) +void WalkerTraceManager::write_buffers(std::vector& collectors) { if (!state.traces_active) return; if (state.verbose) app_log() << "WalkerTraceManager::write_buffers "<& colle void WalkerTraceManager::check_collectors(std::vector& collectors) { - if (!state.traces_active) return; if (state.verbose) app_log() << "WalkerTraceManager::check_collectors" << std::endl; if (collectors.size() > 0) { @@ -426,7 +418,6 @@ void WalkerTraceManager::check_collectors(std::vector& co void WalkerTraceManager::open_file(std::vector& collectors) { - if (!state.traces_active) return; if (state.verbose) app_log() << "WalkerTraceManager::open_file "<& collector void WalkerTraceManager::close_file() { - if (!state.traces_active) return; if (state.verbose) app_log() << "WalkerTraceManager::close_file " << std::endl; close_hdf_file(); } @@ -442,7 +432,6 @@ void WalkerTraceManager::close_file() void WalkerTraceManager::open_hdf_file(std::vector& collectors) { - if (!state.traces_active) return; if (state.verbose) app_log() << "WalkerTraceManager::open_hdf_file " << std::endl; if (collectors.size() == 0) throw std::runtime_error("WalkerTraceManager::open_hdf_file no trace collectors exist, cannot open file"); @@ -474,7 +463,6 @@ void WalkerTraceManager::open_hdf_file(std::vector& colle void WalkerTraceManager::write_buffers_hdf(std::vector& collectors) { - if (!state.traces_active) return; if (state.verbose) app_log() << "WalkerTraceManager::write_buffers_hdf " << std::endl; WalkerTraceCollector& tc_lead = *collectors[0]; if(!registered_hdf) @@ -514,7 +502,6 @@ void WalkerTraceManager::write_buffers_hdf(std::vector& c void WalkerTraceManager::close_hdf_file() { - if (!state.traces_active) return; if (state.verbose) app_log() << "WalkerTraceManager::close_hdf_file " << std::endl; hdf_file.reset(); } diff --git a/src/Estimators/WalkerTraceManager.h b/src/Estimators/WalkerTraceManager.h index 9288545335..52874c4de4 100644 --- a/src/Estimators/WalkerTraceManager.h +++ b/src/Estimators/WalkerTraceManager.h @@ -102,7 +102,6 @@ struct WalkerTraceBuffer inline void reset_buffer() { - app_log()<<"WalkerTraceBuffer("< inline void collect(const std::string& name, Array arr) { - //if (verbose) - // app_log()<<"WalkerTraceBuffer("< 0) { f.push(top); @@ -333,7 +325,6 @@ struct WalkerTraceBuffer f.pop(); } f.flush(); - //app_log()<<" "<& collectors); + void startRun(std::vector& collectors); void stopRun(); - void stopStep(); - //write buffered trace data to file - void write_buffers(std::vector& collectors, int block); + void write_buffers(std::vector& collectors); private: void check_collectors(std::vector& collectors); diff --git a/src/QMCDrivers/DMC/DMC.cpp b/src/QMCDrivers/DMC/DMC.cpp index ba7e5c66c4..8fb0128d48 100644 --- a/src/QMCDrivers/DMC/DMC.cpp +++ b/src/QMCDrivers/DMC/DMC.cpp @@ -242,8 +242,8 @@ bool DMC::run() Movers[ip]->startRun(nBlocks, false); #if !defined(REMOVE_TRACEMANAGER) Traces->startRun(nBlocks, traceClones); - wtrace_manager->startRun(nBlocks, wtrace_collectors); #endif + wtrace_manager->startRun(wtrace_collectors); IndexType block = 0; IndexType updatePeriod = (qmc_driver_mode[QMC_UPDATE_MODE]) ? Period4CheckProperties : (nBlocks + 1) * nSteps; int sample = 0; @@ -300,8 +300,8 @@ bool DMC::run() Estimators->stopBlock(acceptRatio()); #if !defined(REMOVE_TRACEMANAGER) Traces->write_buffers(traceClones, block); - wtrace_manager->write_buffers(wtrace_collectors, block); #endif + wtrace_manager->write_buffers(wtrace_collectors); block++; if (DumpConfig && block % Period4CheckPoint == 0) { @@ -334,8 +334,8 @@ bool DMC::run() Movers[ip]->stopRun2(); #if !defined(REMOVE_TRACEMANAGER) Traces->stopRun(); - wtrace_manager->stopRun(); #endif + wtrace_manager->stopRun(); return finalize(nBlocks); } diff --git a/src/QMCDrivers/VMC/VMC.cpp b/src/QMCDrivers/VMC/VMC.cpp index 3c2e74a91e..7950937591 100644 --- a/src/QMCDrivers/VMC/VMC.cpp +++ b/src/QMCDrivers/VMC/VMC.cpp @@ -67,7 +67,7 @@ bool VMC::run() #if !defined(REMOVE_TRACEMANAGER) Traces->startRun(nBlocks, traceClones); #endif - wtrace_manager->startRun(nBlocks, wtrace_collectors); + wtrace_manager->startRun(wtrace_collectors); LoopTimer<> vmc_loop; RunTimeControl<> runtimeControl(run_time_manager, MaxCPUSecs, myComm->getName(), myComm->rank() == 0); @@ -111,7 +111,7 @@ bool VMC::run() #if !defined(REMOVE_TRACEMANAGER) Traces->write_buffers(traceClones, block); #endif - wtrace_manager->write_buffers(wtrace_collectors, block); + wtrace_manager->write_buffers(wtrace_collectors); recordBlock(block); vmc_loop.stop(); From 196a4b45341287d82494326f48f4a65daf0e3f9c Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Thu, 30 May 2024 00:50:58 -0400 Subject: [PATCH 25/55] enable selective data write --- src/Estimators/WalkerTraceManager.cpp | 228 ++++++++++++++++---------- 1 file changed, 140 insertions(+), 88 deletions(-) diff --git a/src/Estimators/WalkerTraceManager.cpp b/src/Estimators/WalkerTraceManager.cpp index 090e6d7789..e5b46bb011 100644 --- a/src/Estimators/WalkerTraceManager.cpp +++ b/src/Estimators/WalkerTraceManager.cpp @@ -271,12 +271,26 @@ void WalkerTraceManager::put(xmlNodePtr cur, bool allow_traces, std::string seri app_log() << std::endl; } //read trace attributes - std::string verbose_write = "no"; + std::string particle_write = "no"; + std::string min_write = "yes"; + std::string max_write = "yes"; + std::string med_write = "yes"; + std::string qtile_write = "yes"; + std::string verbose_log = "no"; OhmmsAttributeSet attrib; attrib.add(state.step_period, "step_period"); - attrib.add(verbose_write, "verbose"); + attrib.add(particle_write , "particle" ); + attrib.add(min_write , "min" ); + attrib.add(max_write , "max" ); + attrib.add(med_write , "median" ); + attrib.add(qtile_write , "qtiles" ); + attrib.add(verbose_log , "verbose" ); attrib.put(cur); - state.verbose = verbose_write == "yes"; + write_particle_data = particle_write == "yes"; + write_min_data = min_write == "yes" && qtile_write == "yes"; + write_max_data = max_write == "yes" && qtile_write == "yes"; + write_med_data = med_write == "yes" && qtile_write == "yes"; + state.verbose = verbose_log == "yes"; } } @@ -312,79 +326,97 @@ void WalkerTraceManager::write_buffers(std::vector& colle if (!state.traces_active) return; if (state.verbose) app_log() << "WalkerTraceManager::write_buffers "<(v); - if (n==0) + for (size_t c=0; c(energy_order[nmin]); - r = std::get<3>(energy_order[nmin]); - wmin_property_int_buffer.add_row(collectors[c]->walker_property_int_buffer,r); - wmin_property_real_buffer.add_row(collectors[c]->walker_property_real_buffer,r); - wmin_particle_real_buffer.add_row(collectors[c]->walker_particle_real_buffer,r); - // cache data for maximum energy walker - c = std::get<2>(energy_order[nmax]); - r = std::get<3>(energy_order[nmax]); - wmax_property_int_buffer.add_row(collectors[c]->walker_property_int_buffer,r); - wmax_property_real_buffer.add_row(collectors[c]->walker_property_real_buffer,r); - wmax_particle_real_buffer.add_row(collectors[c]->walker_particle_real_buffer,r); - // cache data for median energy walker - c = std::get<2>(energy_order[nmed]); - r = std::get<3>(energy_order[nmed]); - wmed_property_int_buffer.add_row(collectors[c]->walker_property_int_buffer,r); - wmed_property_real_buffer.add_row(collectors[c]->walker_property_real_buffer,r); - wmed_particle_real_buffer.add_row(collectors[c]->walker_particle_real_buffer,r); - // reset pointers - n1 = n; - prev_step = step; + auto step = std::get<0>(v); + if (n==0) + { + n1 = n; + prev_step = step; + } + if (step!=prev_step || n==energy_order.size()-1) + { + // for a given step, find data for min/max/median energy walkers + // n1/n2 are indices of the first/last data in energy_order for this step + if (step!=prev_step) n2 = n-1; + if (n==energy_order.size()-1) n2 = n; + auto nmin = n1; // index of minimum energy walker for this step + auto nmax = n2; // index of maximum energy walker for this step + auto nmed = (n1+n2)/2; // index of median energy walker for this step + //app_log()<<" "<(energy_order[nmin]); + r = std::get<3>(energy_order[nmin]); + wmin_property_int_buffer.add_row(collectors[c]->walker_property_int_buffer,r); + wmin_property_real_buffer.add_row(collectors[c]->walker_property_real_buffer,r); + wmin_particle_real_buffer.add_row(collectors[c]->walker_particle_real_buffer,r); + } + if(write_max_data) + {// cache data for maximum energy walker + c = std::get<2>(energy_order[nmax]); + r = std::get<3>(energy_order[nmax]); + wmax_property_int_buffer.add_row(collectors[c]->walker_property_int_buffer,r); + wmax_property_real_buffer.add_row(collectors[c]->walker_property_real_buffer,r); + wmax_particle_real_buffer.add_row(collectors[c]->walker_particle_real_buffer,r); + } + if(write_med_data) + {// cache data for median energy walker + c = std::get<2>(energy_order[nmed]); + r = std::get<3>(energy_order[nmed]); + wmed_property_int_buffer.add_row(collectors[c]->walker_property_int_buffer,r); + wmed_property_real_buffer.add_row(collectors[c]->walker_property_real_buffer,r); + wmed_particle_real_buffer.add_row(collectors[c]->walker_particle_real_buffer,r); + } + // reset pointers + n1 = n; + prev_step = step; + } + n++; } - n++; + //app_log()<(v) << " " << std::get<1>(v) << " " << std::get<2>(v) << " " << std::get<3>(v) << std::endl; + // n++; + //} + energy_order.resize(0); } - //app_log()<(v) << " " << std::get<1>(v) << " " << std::get<2>(v) << " " << std::get<3>(v) << std::endl; - // n++; - //} - energy_order.resize(0); // write buffer data to file write_buffers_hdf(collectors); @@ -469,16 +501,26 @@ void WalkerTraceManager::write_buffers_hdf(std::vector& c { tc_lead.walker_property_int_buffer.register_hdf_data(*hdf_file); tc_lead.walker_property_real_buffer.register_hdf_data(*hdf_file); - tc_lead.walker_particle_real_buffer.register_hdf_data(*hdf_file); - wmin_property_int_buffer.register_hdf_data(*hdf_file); - wmin_property_real_buffer.register_hdf_data(*hdf_file); - wmin_particle_real_buffer.register_hdf_data(*hdf_file); - wmax_property_int_buffer.register_hdf_data(*hdf_file); - wmax_property_real_buffer.register_hdf_data(*hdf_file); - wmax_particle_real_buffer.register_hdf_data(*hdf_file); - wmed_property_int_buffer.register_hdf_data(*hdf_file); - wmed_property_real_buffer.register_hdf_data(*hdf_file); - wmed_particle_real_buffer.register_hdf_data(*hdf_file); + if(write_particle_data) + tc_lead.walker_particle_real_buffer.register_hdf_data(*hdf_file); + if(write_min_data) + { + wmin_property_int_buffer.register_hdf_data(*hdf_file); + wmin_property_real_buffer.register_hdf_data(*hdf_file); + wmin_particle_real_buffer.register_hdf_data(*hdf_file); + } + if(write_max_data) + { + wmax_property_int_buffer.register_hdf_data(*hdf_file); + wmax_property_real_buffer.register_hdf_data(*hdf_file); + wmax_particle_real_buffer.register_hdf_data(*hdf_file); + } + if(write_med_data) + { + wmed_property_int_buffer.register_hdf_data(*hdf_file); + wmed_property_real_buffer.register_hdf_data(*hdf_file); + wmed_particle_real_buffer.register_hdf_data(*hdf_file); + } registered_hdf = true; } for (int ip = 0; ip < collectors.size(); ++ip) @@ -486,17 +528,27 @@ void WalkerTraceManager::write_buffers_hdf(std::vector& c WalkerTraceCollector& tc = *collectors[ip]; tc.walker_property_int_buffer.write_hdf(*hdf_file, tc_lead.walker_property_int_buffer.hdf_file_pointer); tc.walker_property_real_buffer.write_hdf(*hdf_file, tc_lead.walker_property_real_buffer.hdf_file_pointer); - tc.walker_particle_real_buffer.write_hdf(*hdf_file, tc_lead.walker_particle_real_buffer.hdf_file_pointer); + if(write_particle_data) + tc.walker_particle_real_buffer.write_hdf(*hdf_file, tc_lead.walker_particle_real_buffer.hdf_file_pointer); + } + if(write_min_data) + { + wmin_property_int_buffer.write_hdf(*hdf_file); + wmin_property_real_buffer.write_hdf(*hdf_file); + wmin_particle_real_buffer.write_hdf(*hdf_file); + } + if(write_max_data) + { + wmax_property_int_buffer.write_hdf(*hdf_file); + wmax_property_real_buffer.write_hdf(*hdf_file); + wmax_particle_real_buffer.write_hdf(*hdf_file); + } + if(write_med_data) + { + wmed_property_int_buffer.write_hdf(*hdf_file); + wmed_property_real_buffer.write_hdf(*hdf_file); + wmed_particle_real_buffer.write_hdf(*hdf_file); } - wmin_property_int_buffer.write_hdf(*hdf_file); - wmin_property_real_buffer.write_hdf(*hdf_file); - wmin_particle_real_buffer.write_hdf(*hdf_file); - wmax_property_int_buffer.write_hdf(*hdf_file); - wmax_property_real_buffer.write_hdf(*hdf_file); - wmax_particle_real_buffer.write_hdf(*hdf_file); - wmed_property_int_buffer.write_hdf(*hdf_file); - wmed_property_real_buffer.write_hdf(*hdf_file); - wmed_particle_real_buffer.write_hdf(*hdf_file); } From 00986dce1b1de0036cb2b81948ccbd41ae5ee1db Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Thu, 30 May 2024 02:38:06 -0400 Subject: [PATCH 26/55] banish put() --- src/Estimators/WalkerTraceManager.cpp | 108 +++++------------- src/Estimators/WalkerTraceManager.h | 5 +- src/Estimators/WalkerTraceManagerInput.h | 46 ++++++++ src/QMCDrivers/DMC/DMC.cpp | 8 +- src/QMCDrivers/QMCDriver.cpp | 5 +- src/QMCDrivers/VMC/VMC.cpp | 7 +- .../qmc_walkertrace_dmc_scalars.in.xml | 2 +- .../qmc_walkertrace_vmc_scalars.in.xml | 2 +- 8 files changed, 84 insertions(+), 99 deletions(-) create mode 100644 src/Estimators/WalkerTraceManagerInput.h diff --git a/src/Estimators/WalkerTraceManager.cpp b/src/Estimators/WalkerTraceManager.cpp index e5b46bb011..a59cd77c89 100644 --- a/src/Estimators/WalkerTraceManager.cpp +++ b/src/Estimators/WalkerTraceManager.cpp @@ -12,6 +12,7 @@ #include "WalkerTraceManager.h" +#include "WalkerTraceManagerInput.h" #include "OhmmsData/OhmmsElementBase.h" #include "OhmmsData/AttributeSet.h" @@ -29,34 +30,6 @@ namespace qmcplusplus using MCPWalker = Walker; - -template -void report_row(T& b) -{ - auto& buf = b.buffer; - auto irow = buf.size(0)-1; - for(size_t n=0;n("step_period"); + state.verbose = inp.get("verbose"); + bool qtiles = inp.get("qtiles"); + write_particle_data = inp.get("particle"); + write_min_data = inp.get("min") && qtiles; + write_max_data = inp.get("max") && qtiles; + write_med_data = inp.get("median") && qtiles; } + + wmin_property_int_buffer.label = "wmin_property_int"; + wmin_property_real_buffer.label = "wmin_property_real"; + wmin_particle_real_buffer.label = "wmin_particle_real"; + + wmax_property_int_buffer.label = "wmax_property_int"; + wmax_property_real_buffer.label = "wmax_property_real"; + wmax_particle_real_buffer.label = "wmax_particle_real"; + + wmed_property_int_buffer.label = "wmed_property_int"; + wmed_property_real_buffer.label = "wmed_property_real"; + wmed_particle_real_buffer.label = "wmed_particle_real"; + + registered_hdf = false; } diff --git a/src/Estimators/WalkerTraceManager.h b/src/Estimators/WalkerTraceManager.h index 52874c4de4..d6b5c647fc 100644 --- a/src/Estimators/WalkerTraceManager.h +++ b/src/Estimators/WalkerTraceManager.h @@ -18,6 +18,7 @@ #include "OhmmsPETE/OhmmsArray.h" #include "Message/Communicate.h" #include "hdf/hdf_archive.h" + #include @@ -430,9 +431,7 @@ class WalkerTraceManager WalkerTraceBuffer wmed_particle_real_buffer; public: - WalkerTraceManager(Communicate* comm = 0); - - void put(xmlNodePtr cur, bool allow_traces, std::string series_root); + WalkerTraceManager(xmlNodePtr cur, bool allow_traces, std::string series_root, Communicate* comm = 0); inline WalkerTraceState get_state() { return state; } diff --git a/src/Estimators/WalkerTraceManagerInput.h b/src/Estimators/WalkerTraceManagerInput.h new file mode 100644 index 0000000000..697cee46f5 --- /dev/null +++ b/src/Estimators/WalkerTraceManagerInput.h @@ -0,0 +1,46 @@ +////////////////////////////////////////////////////////////////////////////////////// +// This file is distributed under the University of Illinois/NCSA Open Source License. +// See LICENSE file in top directory for details. +// +// Copyright (c) 2024 QMCPACK developers. +// +// File developed by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory +// +////////////////////////////////////////////////////////////////////////////////////// +#ifndef QMCPLUSPLUS_WALKERTRACEMANAGERINPUT_H +#define QMCPLUSPLUS_WALKERTRACEMANAGERINPUT_H + +#include "InputSection.h" + +namespace qmcplusplus +{ + +/** Native representation for WalkerTraceManager input + */ +struct WalkerTraceInput : public InputSection +{ + bool present; + + WalkerTraceInput() : WalkerTraceInput(NULL) {} + + WalkerTraceInput(xmlNodePtr cur) + { + section_name = "walkertraces"; + attributes = {"step_period", "particle", "min", "max", "median", "qtiles", "verbose"}; + integers = {"step_period"}; + bools = {"particle", "min", "max", "median", "qtiles", "verbose"}; + default_values = {{"step_period", int(1)}, + {"particle", bool(false)}, + {"min" , bool(true)}, + {"max" , bool(true)}, + {"median" , bool(true)}, + {"qtiles" , bool(true)}, + {"verbose" , bool(false)}}; + present = cur!=NULL; + if(present) + readXML(cur); + }; +}; + +} // namespace qmcplusplus +#endif /* WALKERTRACEMANAGERINPUT_H */ diff --git a/src/QMCDrivers/DMC/DMC.cpp b/src/QMCDrivers/DMC/DMC.cpp index 8fb0128d48..d9a249b2e9 100644 --- a/src/QMCDrivers/DMC/DMC.cpp +++ b/src/QMCDrivers/DMC/DMC.cpp @@ -180,18 +180,14 @@ void DMC::resetUpdateEngines() } } } +#if !defined(REMOVE_TRACEMANAGER) else { -#if !defined(REMOVE_TRACEMANAGER) #pragma omp parallel for for (int ip = 0; ip < NumThreads; ++ip) traceClones[ip]->transfer_state_from(*Traces); -#endif -#pragma omp parallel for - for (int ip = 0; ip < NumThreads; ++ip) - wtrace_collectors[ip]->set_state(wtrace_manager->get_state()); } - +#endif if (spinor) app_log() << " Spins treated as dynamic variable with SpinMass: " << SpinMass << std::endl; diff --git a/src/QMCDrivers/QMCDriver.cpp b/src/QMCDrivers/QMCDriver.cpp index 56cf0429dd..a8c3b1ea74 100644 --- a/src/QMCDrivers/QMCDriver.cpp +++ b/src/QMCDrivers/QMCDriver.cpp @@ -200,15 +200,12 @@ void QMCDriver::process(xmlNodePtr cur) #if !defined(REMOVE_TRACEMANAGER) //create and initialize traces if (!Traces) - { Traces = std::make_unique(myComm); - } Traces->put(traces_xml, allow_traces, RootName); #endif //create and initialize traces if (!wtrace_manager) - wtrace_manager = std::make_unique(myComm); - wtrace_manager->put(walker_traces_xml, allow_walker_traces, RootName); + wtrace_manager = std::make_unique(walker_traces_xml, allow_walker_traces, RootName, myComm); branchEngine->put(cur); Estimators->put(H, cur); if (!wOut) diff --git a/src/QMCDrivers/VMC/VMC.cpp b/src/QMCDrivers/VMC/VMC.cpp index 7950937591..1c473d9b80 100644 --- a/src/QMCDrivers/VMC/VMC.cpp +++ b/src/QMCDrivers/VMC/VMC.cpp @@ -216,17 +216,14 @@ void VMC::resetRun() app_log() << os.str() << std::endl; } } +#if !defined(REMOVE_TRACEMANAGER) else { -#if !defined(REMOVE_TRACEMANAGER) #pragma omp parallel for for (int ip = 0; ip < NumThreads; ++ip) traceClones[ip]->transfer_state_from(*Traces); -#endif -#pragma omp parallel for - for (int ip = 0; ip < NumThreads; ++ip) - wtrace_collectors[ip]->set_state(wtrace_manager->get_state()); } +#endif if (qmc_driver_mode[QMC_UPDATE_MODE]) { app_log() << " Using Particle by Particle moves" << std::endl; diff --git a/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_dmc_scalars.in.xml b/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_dmc_scalars.in.xml index 835ce8bf7d..c98c34b5a3 100644 --- a/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_dmc_scalars.in.xml +++ b/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_dmc_scalars.in.xml @@ -79,7 +79,7 @@ - + 2 diff --git a/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_vmc_scalars.in.xml b/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_vmc_scalars.in.xml index 0858ecfdf2..018b90d376 100644 --- a/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_vmc_scalars.in.xml +++ b/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_vmc_scalars.in.xml @@ -79,7 +79,7 @@ - + 2 From 4bb52756d7ed7e683c71d7d67a1df615ee38eee4 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Thu, 30 May 2024 02:51:54 -0400 Subject: [PATCH 27/55] cleanup --- src/Estimators/WalkerTraceManager.cpp | 13 ------------- src/Estimators/WalkerTraceManager.h | 1 - 2 files changed, 14 deletions(-) diff --git a/src/Estimators/WalkerTraceManager.cpp b/src/Estimators/WalkerTraceManager.cpp index a59cd77c89..fb5968a590 100644 --- a/src/Estimators/WalkerTraceManager.cpp +++ b/src/Estimators/WalkerTraceManager.cpp @@ -146,19 +146,6 @@ void WalkerTraceCollector::collect(MCPWalker& walker, ParticleSet& pset, TrialWa steps.push_back((size_t)pset.current_step); energies.push_back((WTraceReal)walker.Properties(0,energy_index)); - //app_log()<<" walker_property_int buffer contents:\n"; - //report_buffer(bsi); - - //app_log()<<"\ninteger walker buffer:\n"; - //report_row(bsi); - //app_log()<<"\nreal walker buffer:\n"; - //report_row(bsr); - // - //bsi.write_summary(); - //bsr.write_summary(); - //bar.write_summary(); - ////APP_ABORT("JTK"); - } diff --git a/src/Estimators/WalkerTraceManager.h b/src/Estimators/WalkerTraceManager.h index d6b5c647fc..4973fdc03c 100644 --- a/src/Estimators/WalkerTraceManager.h +++ b/src/Estimators/WalkerTraceManager.h @@ -341,7 +341,6 @@ struct WalkerTraceState { reset_permissions(); step_period = 1; - verbose = false; } inline void reset_permissions() From 3b92dc894bfa47c34e67f77156b504176733faab Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Thu, 30 May 2024 02:58:06 -0400 Subject: [PATCH 28/55] fix header --- src/Estimators/WalkerTraceManager.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Estimators/WalkerTraceManager.cpp b/src/Estimators/WalkerTraceManager.cpp index fb5968a590..25aa6e5a8f 100644 --- a/src/Estimators/WalkerTraceManager.cpp +++ b/src/Estimators/WalkerTraceManager.cpp @@ -2,10 +2,9 @@ // 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) 2024 QMCPACK developers. // // File developed by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory -// Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory // // File created by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory ////////////////////////////////////////////////////////////////////////////////////// From 9d7128add16ce091249c2ae4b1b79557adf807ef Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Thu, 30 May 2024 03:02:37 -0400 Subject: [PATCH 29/55] cleanup api --- src/Estimators/WalkerTraceManager.cpp | 2 +- src/Estimators/WalkerTraceManager.h | 2 +- src/QMCDrivers/QMCUpdateBase.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Estimators/WalkerTraceManager.cpp b/src/Estimators/WalkerTraceManager.cpp index 25aa6e5a8f..c9d1aaa791 100644 --- a/src/Estimators/WalkerTraceManager.cpp +++ b/src/Estimators/WalkerTraceManager.cpp @@ -55,7 +55,7 @@ void WalkerTraceCollector::set_state(const WalkerTraceState& tms) } -void WalkerTraceCollector::startBlock(int nsteps) +void WalkerTraceCollector::startBlock() { if(!state.traces_active) return; if (state.verbose) app_log() << "WalkerTraceCollector::startBlock " << std::endl; diff --git a/src/Estimators/WalkerTraceManager.h b/src/Estimators/WalkerTraceManager.h index 4973fdc03c..b44f455aca 100644 --- a/src/Estimators/WalkerTraceManager.h +++ b/src/Estimators/WalkerTraceManager.h @@ -387,7 +387,7 @@ class WalkerTraceCollector void set_state(const WalkerTraceState& tms); - void startBlock(int nsteps); + void startBlock(); void collect(MCPWalker& walker, ParticleSet& pset, TrialWaveFunction& wfn, QMCHamiltonian& ham); diff --git a/src/QMCDrivers/QMCUpdateBase.cpp b/src/QMCDrivers/QMCUpdateBase.cpp index 10498fecbd..1b62a824dc 100644 --- a/src/QMCDrivers/QMCUpdateBase.cpp +++ b/src/QMCDrivers/QMCUpdateBase.cpp @@ -197,7 +197,7 @@ void QMCUpdateBase::startBlock(int steps) #if !defined(REMOVE_TRACEMANAGER) Traces->startBlock(steps); #endif - wtrace_collector->startBlock(steps); + wtrace_collector->startBlock(); nAccept = 0; nReject = 0; nAllRejected = 0; From 61b0f3c8f164a7821c05cd8bce9ce879362df423 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Thu, 30 May 2024 05:27:27 -0400 Subject: [PATCH 30/55] port to batched drivers --- src/Estimators/WalkerTraceManager.cpp | 16 ++++++++++++---- src/Estimators/WalkerTraceManager.h | 2 +- src/QMCDrivers/Crowd.cpp | 1 + src/QMCDrivers/Crowd.h | 4 ++++ src/QMCDrivers/DMC/DMCBatched.cpp | 20 +++++++++++++++++++- src/QMCDrivers/DMC/DMCBatched.h | 1 + src/QMCDrivers/QMCDriverFactory.cpp | 2 +- src/QMCDrivers/QMCDriverInterface.h | 4 ++-- src/QMCDrivers/QMCDriverNew.cpp | 1 + src/QMCDrivers/QMCDriverNew.h | 13 +++++++++++-- src/QMCDrivers/VMC/VMCBatched.cpp | 20 +++++++++++++++++++- src/QMCDrivers/VMC/VMCBatched.h | 1 + 12 files changed, 73 insertions(+), 12 deletions(-) diff --git a/src/Estimators/WalkerTraceManager.cpp b/src/Estimators/WalkerTraceManager.cpp index c9d1aaa791..c0566aacfd 100644 --- a/src/Estimators/WalkerTraceManager.cpp +++ b/src/Estimators/WalkerTraceManager.cpp @@ -63,9 +63,15 @@ void WalkerTraceCollector::startBlock() } -void WalkerTraceCollector::collect(MCPWalker& walker, ParticleSet& pset, TrialWaveFunction& wfn, QMCHamiltonian& ham) +void WalkerTraceCollector::collect(MCPWalker& walker, ParticleSet& pset, TrialWaveFunction& wfn, QMCHamiltonian& ham, int step) { - if(!state.traces_active || pset.current_step%state.step_period!=0) return; + int current_step; + if (step==-1) + current_step = pset.current_step; + else + current_step = step; + + if(!state.traces_active || current_step%state.step_period!=0) return; //app_log()<<"TraceCollector::collect (step "<& collectors { if (!state.traces_active) return; if (state.verbose) app_log() << "WalkerTraceManager::startRun " << std::endl; + for (auto& tc: collectors) + tc->set_state(state); check_collectors(collectors); open_file(collectors); } diff --git a/src/Estimators/WalkerTraceManager.h b/src/Estimators/WalkerTraceManager.h index b44f455aca..3e5c35baba 100644 --- a/src/Estimators/WalkerTraceManager.h +++ b/src/Estimators/WalkerTraceManager.h @@ -389,7 +389,7 @@ class WalkerTraceCollector void startBlock(); - void collect(MCPWalker& walker, ParticleSet& pset, TrialWaveFunction& wfn, QMCHamiltonian& ham); + void collect(MCPWalker& walker, ParticleSet& pset, TrialWaveFunction& wfn, QMCHamiltonian& ham, int step=-1); void check_buffers(); diff --git a/src/QMCDrivers/Crowd.cpp b/src/QMCDrivers/Crowd.cpp index 2bb3aa7bc8..80fcaaa1d1 100644 --- a/src/QMCDrivers/Crowd.cpp +++ b/src/QMCDrivers/Crowd.cpp @@ -10,6 +10,7 @@ #include "Crowd.h" #include "QMCHamiltonians/QMCHamiltonian.h" + namespace qmcplusplus { Crowd::Crowd(EstimatorManagerNew& emb, diff --git a/src/QMCDrivers/Crowd.h b/src/QMCDrivers/Crowd.h index 6de8b91195..9f734170f2 100644 --- a/src/QMCDrivers/Crowd.h +++ b/src/QMCDrivers/Crowd.h @@ -16,12 +16,14 @@ #include "MultiWalkerDispatchers.h" #include "DriverWalkerTypes.h" #include "Estimators/EstimatorManagerCrowd.h" +#include "Estimators/WalkerTraceManager.h" namespace qmcplusplus { // forward declaration class ResourceCollection; class EstimatorManagerNew; +class WalkerTraceCollector; /** Driver synchronized step context * @@ -139,6 +141,8 @@ class Crowd unsigned long n_accept_ = 0; unsigned long n_nonlocal_accept_ = 0; /** @} */ +public: + WalkerTraceCollector wtrace_collector; }; } // namespace qmcplusplus diff --git a/src/QMCDrivers/DMC/DMCBatched.cpp b/src/QMCDrivers/DMC/DMCBatched.cpp index c59ca331ba..91eff0cf02 100644 --- a/src/QMCDrivers/DMC/DMCBatched.cpp +++ b/src/QMCDrivers/DMC/DMCBatched.cpp @@ -288,6 +288,9 @@ void DMCBatched::advanceWalkers(const StateForThread& sft, crowd.accumulate(step_context.get_random_gen()); } + for (int iw = 0; iw < crowd.size(); ++iw) + crowd.wtrace_collector.collect(walkers[iw], walker_elecs[iw], walker_twfs[iw], walker_hamiltonians[iw], sft.current_step); + { // T-moves ScopedTimer tmove_timer(dmc_timers.tmove_timer); @@ -429,6 +432,14 @@ bool DMCBatched::run() IndexType num_blocks = qmcdriver_input_.get_max_blocks(); estimator_manager_->startDriverRun(); + + //start walker trace manager + wtrace_manager = std::make_unique(walker_traces_xml, allow_walker_traces, get_root_name(), myComm); + std::vector wtrace_collectors; + for (auto& c: crowds_) + wtrace_collectors.push_back(&c->wtrace_collector); + wtrace_manager->startRun(wtrace_collectors); + StateForThread dmc_state(qmcdriver_input_, *drift_modifier_, *branch_engine_, population_, steps_per_block_); LoopTimer<> dmc_loop; @@ -457,6 +468,7 @@ bool DMCBatched::run() ScopedTimer local_timer(timers_.production_timer); ParallelExecutor<> crowd_task; + int current_step = 0; for (int block = 0; block < num_blocks; ++block) { { @@ -471,9 +483,12 @@ bool DMCBatched::run() : false; for (UPtr& crowd : crowds_) + { crowd->startBlock(steps_per_block_); + crowd->wtrace_collector.startBlock(); + } - for (int step = 0; step < steps_per_block_; ++step) + for (int step = 0; step < steps_per_block_; ++step, ++current_step) { ScopedTimer local_timer(timers_.run_steps_timer); @@ -483,6 +498,7 @@ bool DMCBatched::run() setNonLocalMoveHandler(*ham); dmc_state.step = step; + dmc_state.current_step = current_step; crowd_task(crowds_.size(), runDMCStep, dmc_state, timers_, dmc_timers_, std::ref(step_contexts_), std::ref(crowds_)); @@ -500,6 +516,7 @@ bool DMCBatched::run() if (qmcdriver_input_.get_measure_imbalance()) measureImbalance("Block " + std::to_string(block)); endBlock(); + wtrace_manager->write_buffers(wtrace_collectors); recordBlock(block); } @@ -523,6 +540,7 @@ bool DMCBatched::run() print_mem("DMCBatched ends", app_log()); estimator_manager_->stopDriverRun(); + wtrace_manager->stopRun(); return finalize(num_blocks, true); } diff --git a/src/QMCDrivers/DMC/DMCBatched.h b/src/QMCDrivers/DMC/DMCBatched.h index d95ae0c8b6..f521c5b25f 100644 --- a/src/QMCDrivers/DMC/DMCBatched.h +++ b/src/QMCDrivers/DMC/DMCBatched.h @@ -53,6 +53,7 @@ class DMCBatched : public QMCDriverNew IndexType recalculate_properties_period; const size_t steps_per_block; IndexType step = -1; + IndexType current_step = -1; bool is_recomputing_block = false; StateForThread(const QMCDriverInput& qmci, diff --git a/src/QMCDrivers/QMCDriverFactory.cpp b/src/QMCDrivers/QMCDriverFactory.cpp index bbcab9e5c2..413a4b6481 100644 --- a/src/QMCDrivers/QMCDriverFactory.cpp +++ b/src/QMCDrivers/QMCDriverFactory.cpp @@ -297,7 +297,7 @@ std::unique_ptr QMCDriverFactory::createQMCDriver(xmlNodePtr //add trace information bool allow_walker_traces = das.walkertraces_tag == "yes" || - (das.walkertraces_tag == "none" && (das.new_run_type == QMCRunType::VMC || das.new_run_type == QMCRunType::DMC)); + (das.walkertraces_tag == "none" && (das.new_run_type == QMCRunType::VMC || das.new_run_type == QMCRunType::DMC || das.new_run_type == QMCRunType::VMC_BATCH || das.new_run_type == QMCRunType::DMC_BATCH)); new_driver->requestWalkerTraces(allow_walker_traces); return new_driver; diff --git a/src/QMCDrivers/QMCDriverInterface.h b/src/QMCDrivers/QMCDriverInterface.h index 9781dad82b..f425743071 100644 --- a/src/QMCDrivers/QMCDriverInterface.h +++ b/src/QMCDrivers/QMCDriverInterface.h @@ -49,8 +49,8 @@ class QMCDriverInterface virtual void putWalkers(std::vector& wset) = 0; virtual void putTraces(xmlNodePtr txml) = 0; virtual void requestTraces(bool allow_traces) = 0; - virtual void putWalkerTraces(xmlNodePtr txml) = 0; - virtual void requestWalkerTraces(bool allow_traces) = 0; + virtual void putWalkerTraces(xmlNodePtr txml) = 0; + virtual void requestWalkerTraces(bool allow_traces_) = 0; virtual void process(xmlNodePtr cur) = 0; virtual QMCRunType getRunType() = 0; virtual std::string getEngineName() = 0; diff --git a/src/QMCDrivers/QMCDriverNew.cpp b/src/QMCDrivers/QMCDriverNew.cpp index 1ea7106080..1b058e042b 100644 --- a/src/QMCDrivers/QMCDriverNew.cpp +++ b/src/QMCDrivers/QMCDriverNew.cpp @@ -33,6 +33,7 @@ #include "Utilities/Timer.h" #include "Message/UniformCommunicateError.h" #include "EstimatorInputDelegates.h" +#include "Estimators/WalkerTraceManager.h" namespace qmcplusplus diff --git a/src/QMCDrivers/QMCDriverNew.h b/src/QMCDrivers/QMCDriverNew.h index 7306ebaef2..d432f0fb5d 100644 --- a/src/QMCDrivers/QMCDriverNew.h +++ b/src/QMCDrivers/QMCDriverNew.h @@ -102,6 +102,11 @@ class QMCDriverNew : public QMCDriverInterface, public MPIObjectBase */ std::bitset qmc_driver_mode_; + /// whether to allow walker traces + bool allow_walker_traces; + /// walker traces xml + xmlNodePtr walker_traces_xml; + protected: /** This is a data structure strictly for QMCDriver and its derived classes * @@ -242,8 +247,9 @@ class QMCDriverNew : public QMCDriverInterface, public MPIObjectBase void putTraces(xmlNodePtr txml) override {} void requestTraces(bool allow_traces) override {} - void putWalkerTraces(xmlNodePtr txml) override {} - void requestWalkerTraces(bool allow_traces) override {} + void putWalkerTraces(xmlNodePtr txml) override { walker_traces_xml = txml; } + + void requestWalkerTraces(bool allow_traces_) override { allow_walker_traces = allow_traces_; } // scales a MCCoords by sqrtTau. Chooses appropriate taus by CT template @@ -435,6 +441,9 @@ class QMCDriverNew : public QMCDriverInterface, public MPIObjectBase */ std::unique_ptr estimator_manager_; + /// walker trace manager + std::unique_ptr wtrace_manager; + ///record engine for walkers std::unique_ptr wOut; diff --git a/src/QMCDrivers/VMC/VMCBatched.cpp b/src/QMCDrivers/VMC/VMCBatched.cpp index dff6fa1d15..1ab1f8d2ec 100644 --- a/src/QMCDrivers/VMC/VMCBatched.cpp +++ b/src/QMCDrivers/VMC/VMCBatched.cpp @@ -21,6 +21,7 @@ #include "MemoryUsage.h" #include "QMCWaveFunctions/TWFGrads.hpp" #include "TauParams.hpp" +#include "WalkerTraceManager.h" namespace qmcplusplus { @@ -214,6 +215,10 @@ void VMCBatched::advanceWalkers(const StateForThread& sft, ScopedTimer est_timer(timers.estimators_timer); crowd.accumulate(step_context.get_random_gen()); } + + for (int iw = 0; iw < crowd.size(); ++iw) + crowd.wtrace_collector.collect(walkers[iw], walker_elecs[iw], walker_twfs[iw], walker_hamiltonians[iw], sft.current_step); + // TODO: // check if all moves failed } @@ -304,6 +309,12 @@ bool VMCBatched::run() IndexType num_blocks = qmcdriver_input_.get_max_blocks(); //start the main estimator estimator_manager_->startDriverRun(); + //start walker trace manager + wtrace_manager = std::make_unique(walker_traces_xml, allow_walker_traces, get_root_name(), myComm); + std::vector wtrace_collectors; + for (auto& c: crowds_) + wtrace_collectors.push_back(&c->wtrace_collector); + wtrace_manager->startRun(wtrace_collectors); StateForThread vmc_state(qmcdriver_input_, vmcdriver_input_, *drift_modifier_, population_, steps_per_block_); @@ -356,6 +367,7 @@ bool VMCBatched::run() // this barrier fences all previous load imbalance. Avoid block 0 timing pollution. myComm->barrier(); + int current_step = 0; for (int block = 0; block < num_blocks; ++block) { { @@ -369,11 +381,15 @@ bool VMCBatched::run() estimator_manager_->startBlock(steps_per_block_); for (auto& crowd : crowds_) + { crowd->startBlock(steps_per_block_); - for (int step = 0; step < steps_per_block_; ++step) + crowd->wtrace_collector.startBlock(); + } + for (int step = 0; step < steps_per_block_; ++step, ++current_step) { ScopedTimer local_timer(timers_.run_steps_timer); vmc_state.step = step; + vmc_state.current_step = current_step; crowd_task(crowds_.size(), runVMCStep, vmc_state, timers_, std::ref(step_contexts_), std::ref(crowds_)); if (collect_samples_) @@ -389,6 +405,7 @@ bool VMCBatched::run() if (qmcdriver_input_.get_measure_imbalance()) measureImbalance("Block " + std::to_string(block)); endBlock(); + wtrace_manager->write_buffers(wtrace_collectors); recordBlock(block); } @@ -435,6 +452,7 @@ bool VMCBatched::run() print_mem("VMCBatched ends", app_log()); estimator_manager_->stopDriverRun(); + wtrace_manager->stopRun(); return finalize(num_blocks, true); } diff --git a/src/QMCDrivers/VMC/VMCBatched.h b/src/QMCDrivers/VMC/VMCBatched.h index e2ff01111d..752d795fa7 100644 --- a/src/QMCDrivers/VMC/VMCBatched.h +++ b/src/QMCDrivers/VMC/VMCBatched.h @@ -53,6 +53,7 @@ class VMCBatched : public QMCDriverNew IndexType recalculate_properties_period; const size_t steps_per_block; IndexType step = -1; + IndexType current_step = -1; bool is_recomputing_block = false; StateForThread(const QMCDriverInput& qmci, From f5c222498640c8dcdefd737617d7b502f24eb8c1 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Thu, 30 May 2024 09:49:20 -0400 Subject: [PATCH 31/55] add batched tests --- tests/solids/diamondC_1x1x1_pp/CMakeLists.txt | 49 +++++++++ .../qmc_walkertrace_dmcbatch_scalars.in.xml | 100 ++++++++++++++++++ .../qmc_walkertrace_vmcbatch_scalars.in.xml | 92 ++++++++++++++++ 3 files changed, 241 insertions(+) create mode 100644 tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_dmcbatch_scalars.in.xml create mode 100644 tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_vmcbatch_scalars.in.xml diff --git a/tests/solids/diamondC_1x1x1_pp/CMakeLists.txt b/tests/solids/diamondC_1x1x1_pp/CMakeLists.txt index f644ddd261..f9f6c97ade 100644 --- a/tests/solids/diamondC_1x1x1_pp/CMakeLists.txt +++ b/tests/solids/diamondC_1x1x1_pp/CMakeLists.txt @@ -1924,6 +1924,55 @@ if(add_traces_tests) dmc --dmc_steps_exclude=1) + simple_run_and_check( + deterministic-diamondC_1x1x1_pp-vmcbatch-walkertrace_scalars + "${qmcpack_SOURCE_DIR}/tests/solids/diamondC_1x1x1_pp" + qmc_walkertrace_vmcbatch_scalars.in.xml + 1 + 1 + check_wtraces.py + -p + qmc_trace_vmcbatch_scalars + -s + 0 + -m + vmc + --dmc_steps_exclude=1) + + simple_run_and_check( + deterministic-diamondC_1x1x1_pp-vmcbatch-walkertrace_scalars + "${qmcpack_SOURCE_DIR}/tests/solids/diamondC_1x1x1_pp" + qmc_walkertrace_vmcbatch_scalars.in.xml + 4 + 4 + check_wtraces.py + -p + qmc_trace_vmcbatch_scalars + -n + 4 + -s + 0 + -m + vmc + --dmc_steps_exclude=1) + + simple_run_and_check( + deterministic-diamondC_1x1x1_pp-dmcbatch-walkertrace_scalars + "${qmcpack_SOURCE_DIR}/tests/solids/diamondC_1x1x1_pp" + qmc_walkertrace_dmcbatch_scalars.in.xml + 4 + 4 + check_wtraces.py + -p + qmc_trace_dmcbatch_scalars + -n + 4 + -s + 1 + -m + dmc + --dmc_steps_exclude=1) + endif() if(QMC_MIXED_PRECISION) diff --git a/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_dmcbatch_scalars.in.xml b/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_dmcbatch_scalars.in.xml new file mode 100644 index 0000000000..82840dbf9a --- /dev/null +++ b/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_dmcbatch_scalars.in.xml @@ -0,0 +1,100 @@ + + + + + batched + + + + + + 3.37316115 3.37316115 0.00000000 + 0.00000000 3.37316115 3.37316115 + 3.37316115 0.00000000 3.37316115 + + + p p p + + 15 + + + + -1 + 1.0 + + + -1 + 1.0 + + + + + 4 + 4 + 6 + 21894.7135906 + + 0.00000000 0.00000000 0.00000000 + 1.68658058 1.68658058 1.68658058 + + + + + + + + + + + + + + + + +-0.2032153051 -0.1625595974 -0.143124599 -0.1216434956 -0.09919771951 -0.07111729038 +-0.04445345869 -0.02135082917 + + + + + + +0.2797730287 0.2172604155 0.1656172964 0.1216984261 0.083995349 0.05302065936 +0.02915953995 0.0122402581 + + + + +0.4631099906 0.356399124 0.2587895287 0.1829298509 0.1233653291 0.07714708174 +0.04145899033 0.01690645936 + + + + + + + + + + + + + + + 2 + 2 + 4 + 2 + 1 + 0.3 + + + 2 + 2 + 4 + 2 + 0.01 + no + + diff --git a/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_vmcbatch_scalars.in.xml b/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_vmcbatch_scalars.in.xml new file mode 100644 index 0000000000..f6026886ba --- /dev/null +++ b/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_vmcbatch_scalars.in.xml @@ -0,0 +1,92 @@ + + + + + batched + + + + + + 3.37316115 3.37316115 0.00000000 + 0.00000000 3.37316115 3.37316115 + 3.37316115 0.00000000 3.37316115 + + + p p p + + 15 + + + + -1 + 1.0 + + + -1 + 1.0 + + + + + 4 + 4 + 6 + 21894.7135906 + + 0.00000000 0.00000000 0.00000000 + 1.68658058 1.68658058 1.68658058 + + + + + + + + + + + + + + + + +-0.2032153051 -0.1625595974 -0.143124599 -0.1216434956 -0.09919771951 -0.07111729038 +-0.04445345869 -0.02135082917 + + + + + + +0.2797730287 0.2172604155 0.1656172964 0.1216984261 0.083995349 0.05302065936 +0.02915953995 0.0122402581 + + + + +0.4631099906 0.356399124 0.2587895287 0.1829298509 0.1233653291 0.07714708174 +0.04145899033 0.01690645936 + + + + + + + + + + + + + + + 2 + 2 + 4 + 2 + 1 + 0.3 + + From 94a8d1595caf7992d9b0e8094582dc7eaff3e535 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Fri, 31 May 2024 16:14:47 -0400 Subject: [PATCH 32/55] formatting --- src/Estimators/WalkerTraceManager.cpp | 89 +++++++++++++++------------ 1 file changed, 50 insertions(+), 39 deletions(-) diff --git a/src/Estimators/WalkerTraceManager.cpp b/src/Estimators/WalkerTraceManager.cpp index c0566aacfd..d7bea3c38c 100644 --- a/src/Estimators/WalkerTraceManager.cpp +++ b/src/Estimators/WalkerTraceManager.cpp @@ -65,22 +65,47 @@ void WalkerTraceCollector::startBlock() void WalkerTraceCollector::collect(MCPWalker& walker, ParticleSet& pset, TrialWaveFunction& wfn, QMCHamiltonian& ham, int step) { - int current_step; - if (step==-1) - current_step = pset.current_step; - else - current_step = step; - - if(!state.traces_active || current_step%state.step_period!=0) return; + if(!state.traces_active) return; - //app_log()<<"TraceCollector::collect (step "<::max(); + for(size_t n=0; n Date: Fri, 31 May 2024 17:16:21 -0400 Subject: [PATCH 33/55] batched driver member naming convenction --- src/QMCDrivers/Crowd.h | 2 +- src/QMCDrivers/DMC/DMC.cpp | 8 ++++---- src/QMCDrivers/DMC/DMCBatched.cpp | 14 +++++++------- src/QMCDrivers/QMCDriver.cpp | 4 ++-- src/QMCDrivers/QMCDriver.h | 2 +- src/QMCDrivers/QMCDriverNew.h | 2 +- src/QMCDrivers/VMC/VMC.cpp | 8 ++++---- src/QMCDrivers/VMC/VMCBatched.cpp | 14 +++++++------- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/QMCDrivers/Crowd.h b/src/QMCDrivers/Crowd.h index 9f734170f2..0a925e915f 100644 --- a/src/QMCDrivers/Crowd.h +++ b/src/QMCDrivers/Crowd.h @@ -142,7 +142,7 @@ class Crowd unsigned long n_nonlocal_accept_ = 0; /** @} */ public: - WalkerTraceCollector wtrace_collector; + WalkerTraceCollector wtrace_collector_; }; } // namespace qmcplusplus diff --git a/src/QMCDrivers/DMC/DMC.cpp b/src/QMCDrivers/DMC/DMC.cpp index d9a249b2e9..7e057b1707 100644 --- a/src/QMCDrivers/DMC/DMC.cpp +++ b/src/QMCDrivers/DMC/DMC.cpp @@ -132,7 +132,7 @@ void DMC::resetUpdateEngines() #if !defined(REMOVE_TRACEMANAGER) traceClones[ip] = Traces->makeClone(); #endif - wtrace_collectors[ip] = wtrace_manager->makeCollector(); + wtrace_collectors[ip] = wtrace_manager_->makeCollector(); Rng[ip] = rngs_[ip]->makeClone(); hClones[ip]->setRandomGenerator(Rng[ip].get()); if (W.isSpinor()) @@ -239,7 +239,7 @@ bool DMC::run() #if !defined(REMOVE_TRACEMANAGER) Traces->startRun(nBlocks, traceClones); #endif - wtrace_manager->startRun(wtrace_collectors); + wtrace_manager_->startRun(wtrace_collectors); IndexType block = 0; IndexType updatePeriod = (qmc_driver_mode[QMC_UPDATE_MODE]) ? Period4CheckProperties : (nBlocks + 1) * nSteps; int sample = 0; @@ -297,7 +297,7 @@ bool DMC::run() #if !defined(REMOVE_TRACEMANAGER) Traces->write_buffers(traceClones, block); #endif - wtrace_manager->write_buffers(wtrace_collectors); + wtrace_manager_->write_buffers(wtrace_collectors); block++; if (DumpConfig && block % Period4CheckPoint == 0) { @@ -331,7 +331,7 @@ bool DMC::run() #if !defined(REMOVE_TRACEMANAGER) Traces->stopRun(); #endif - wtrace_manager->stopRun(); + wtrace_manager_->stopRun(); return finalize(nBlocks); } diff --git a/src/QMCDrivers/DMC/DMCBatched.cpp b/src/QMCDrivers/DMC/DMCBatched.cpp index 91eff0cf02..c57283b84b 100644 --- a/src/QMCDrivers/DMC/DMCBatched.cpp +++ b/src/QMCDrivers/DMC/DMCBatched.cpp @@ -289,7 +289,7 @@ void DMCBatched::advanceWalkers(const StateForThread& sft, } for (int iw = 0; iw < crowd.size(); ++iw) - crowd.wtrace_collector.collect(walkers[iw], walker_elecs[iw], walker_twfs[iw], walker_hamiltonians[iw], sft.current_step); + crowd.wtrace_collector_.collect(walkers[iw], walker_elecs[iw], walker_twfs[iw], walker_hamiltonians[iw], sft.current_step); { // T-moves ScopedTimer tmove_timer(dmc_timers.tmove_timer); @@ -434,11 +434,11 @@ bool DMCBatched::run() estimator_manager_->startDriverRun(); //start walker trace manager - wtrace_manager = std::make_unique(walker_traces_xml, allow_walker_traces, get_root_name(), myComm); + wtrace_manager_ = std::make_unique(walker_traces_xml, allow_walker_traces, get_root_name(), myComm); std::vector wtrace_collectors; for (auto& c: crowds_) - wtrace_collectors.push_back(&c->wtrace_collector); - wtrace_manager->startRun(wtrace_collectors); + wtrace_collectors.push_back(&c->wtrace_collector_); + wtrace_manager_->startRun(wtrace_collectors); StateForThread dmc_state(qmcdriver_input_, *drift_modifier_, *branch_engine_, population_, steps_per_block_); @@ -485,7 +485,7 @@ bool DMCBatched::run() for (UPtr& crowd : crowds_) { crowd->startBlock(steps_per_block_); - crowd->wtrace_collector.startBlock(); + crowd->wtrace_collector_.startBlock(); } for (int step = 0; step < steps_per_block_; ++step, ++current_step) @@ -516,7 +516,7 @@ bool DMCBatched::run() if (qmcdriver_input_.get_measure_imbalance()) measureImbalance("Block " + std::to_string(block)); endBlock(); - wtrace_manager->write_buffers(wtrace_collectors); + wtrace_manager_->write_buffers(wtrace_collectors); recordBlock(block); } @@ -540,7 +540,7 @@ bool DMCBatched::run() print_mem("DMCBatched ends", app_log()); estimator_manager_->stopDriverRun(); - wtrace_manager->stopRun(); + wtrace_manager_->stopRun(); return finalize(num_blocks, true); } diff --git a/src/QMCDrivers/QMCDriver.cpp b/src/QMCDrivers/QMCDriver.cpp index a8c3b1ea74..aba2d11f05 100644 --- a/src/QMCDrivers/QMCDriver.cpp +++ b/src/QMCDrivers/QMCDriver.cpp @@ -204,8 +204,8 @@ void QMCDriver::process(xmlNodePtr cur) Traces->put(traces_xml, allow_traces, RootName); #endif //create and initialize traces - if (!wtrace_manager) - wtrace_manager = std::make_unique(walker_traces_xml, allow_walker_traces, RootName, myComm); + if (!wtrace_manager_) + wtrace_manager_ = std::make_unique(walker_traces_xml, allow_walker_traces, RootName, myComm); branchEngine->put(cur); Estimators->put(H, cur); if (!wOut) diff --git a/src/QMCDrivers/QMCDriver.h b/src/QMCDrivers/QMCDriver.h index 873b7f79ec..826dce2fbc 100644 --- a/src/QMCDrivers/QMCDriver.h +++ b/src/QMCDrivers/QMCDriver.h @@ -196,7 +196,7 @@ class QMCDriver : public QMCDriverInterface, public QMCTraits, public MPIObjectB std::unique_ptr Traces; ///Traces manager - std::unique_ptr wtrace_manager; + std::unique_ptr wtrace_manager_; ///return the random generators inline RefVector> getRngRefs() const diff --git a/src/QMCDrivers/QMCDriverNew.h b/src/QMCDrivers/QMCDriverNew.h index d432f0fb5d..e5f7e1a84f 100644 --- a/src/QMCDrivers/QMCDriverNew.h +++ b/src/QMCDrivers/QMCDriverNew.h @@ -442,7 +442,7 @@ class QMCDriverNew : public QMCDriverInterface, public MPIObjectBase std::unique_ptr estimator_manager_; /// walker trace manager - std::unique_ptr wtrace_manager; + std::unique_ptr wtrace_manager_; ///record engine for walkers std::unique_ptr wOut; diff --git a/src/QMCDrivers/VMC/VMC.cpp b/src/QMCDrivers/VMC/VMC.cpp index 1c473d9b80..be9c6f2516 100644 --- a/src/QMCDrivers/VMC/VMC.cpp +++ b/src/QMCDrivers/VMC/VMC.cpp @@ -67,7 +67,7 @@ bool VMC::run() #if !defined(REMOVE_TRACEMANAGER) Traces->startRun(nBlocks, traceClones); #endif - wtrace_manager->startRun(wtrace_collectors); + wtrace_manager_->startRun(wtrace_collectors); LoopTimer<> vmc_loop; RunTimeControl<> runtimeControl(run_time_manager, MaxCPUSecs, myComm->getName(), myComm->rank() == 0); @@ -111,7 +111,7 @@ bool VMC::run() #if !defined(REMOVE_TRACEMANAGER) Traces->write_buffers(traceClones, block); #endif - wtrace_manager->write_buffers(wtrace_collectors); + wtrace_manager_->write_buffers(wtrace_collectors); recordBlock(block); vmc_loop.stop(); @@ -134,7 +134,7 @@ bool VMC::run() #if !defined(REMOVE_TRACEMANAGER) Traces->stopRun(); #endif - wtrace_manager->stopRun(); + wtrace_manager_->stopRun(); //copy back the random states for (int ip = 0; ip < NumThreads; ++ip) rngs_[ip] = Rng[ip]->makeClone(); @@ -185,7 +185,7 @@ void VMC::resetRun() #if !defined(REMOVE_TRACEMANAGER) traceClones[ip] = Traces->makeClone(); #endif - wtrace_collectors[ip] = wtrace_manager->makeCollector(); + wtrace_collectors[ip] = wtrace_manager_->makeCollector(); Rng[ip] = rngs_[ip]->makeClone(); hClones[ip]->setRandomGenerator(Rng[ip].get()); if (W.isSpinor()) diff --git a/src/QMCDrivers/VMC/VMCBatched.cpp b/src/QMCDrivers/VMC/VMCBatched.cpp index 1ab1f8d2ec..f02912600a 100644 --- a/src/QMCDrivers/VMC/VMCBatched.cpp +++ b/src/QMCDrivers/VMC/VMCBatched.cpp @@ -217,7 +217,7 @@ void VMCBatched::advanceWalkers(const StateForThread& sft, } for (int iw = 0; iw < crowd.size(); ++iw) - crowd.wtrace_collector.collect(walkers[iw], walker_elecs[iw], walker_twfs[iw], walker_hamiltonians[iw], sft.current_step); + crowd.wtrace_collector_.collect(walkers[iw], walker_elecs[iw], walker_twfs[iw], walker_hamiltonians[iw], sft.current_step); // TODO: // check if all moves failed @@ -310,11 +310,11 @@ bool VMCBatched::run() //start the main estimator estimator_manager_->startDriverRun(); //start walker trace manager - wtrace_manager = std::make_unique(walker_traces_xml, allow_walker_traces, get_root_name(), myComm); + wtrace_manager_ = std::make_unique(walker_traces_xml, allow_walker_traces, get_root_name(), myComm); std::vector wtrace_collectors; for (auto& c: crowds_) - wtrace_collectors.push_back(&c->wtrace_collector); - wtrace_manager->startRun(wtrace_collectors); + wtrace_collectors.push_back(&c->wtrace_collector_); + wtrace_manager_->startRun(wtrace_collectors); StateForThread vmc_state(qmcdriver_input_, vmcdriver_input_, *drift_modifier_, population_, steps_per_block_); @@ -383,7 +383,7 @@ bool VMCBatched::run() for (auto& crowd : crowds_) { crowd->startBlock(steps_per_block_); - crowd->wtrace_collector.startBlock(); + crowd->wtrace_collector_.startBlock(); } for (int step = 0; step < steps_per_block_; ++step, ++current_step) { @@ -405,7 +405,7 @@ bool VMCBatched::run() if (qmcdriver_input_.get_measure_imbalance()) measureImbalance("Block " + std::to_string(block)); endBlock(); - wtrace_manager->write_buffers(wtrace_collectors); + wtrace_manager_->write_buffers(wtrace_collectors); recordBlock(block); } @@ -452,7 +452,7 @@ bool VMCBatched::run() print_mem("VMCBatched ends", app_log()); estimator_manager_->stopDriverRun(); - wtrace_manager->stopRun(); + wtrace_manager_->stopRun(); return finalize(num_blocks, true); } From 23e1c4a3e40ef538ac17b95755151228b216e1e9 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Fri, 31 May 2024 17:26:07 -0400 Subject: [PATCH 34/55] move trace collection to crowd scope --- src/QMCDrivers/Crowd.cpp | 7 +++++++ src/QMCDrivers/Crowd.h | 3 +++ src/QMCDrivers/DMC/DMCBatched.cpp | 6 ++++-- src/QMCDrivers/VMC/VMCBatched.cpp | 6 ++++-- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/QMCDrivers/Crowd.cpp b/src/QMCDrivers/Crowd.cpp index 80fcaaa1d1..1a8cb60686 100644 --- a/src/QMCDrivers/Crowd.cpp +++ b/src/QMCDrivers/Crowd.cpp @@ -86,4 +86,11 @@ void Crowd::startBlock(int num_steps) void Crowd::stopBlock() { estimator_manager_crowd_.stopBlock(); } +void Crowd::collect(int current_step) +{ + for (int iw = 0; iw < size(); ++iw) + wtrace_collector_.collect(mcp_walkers_[iw], walker_elecs_[iw], walker_twfs_[iw], walker_hamiltonians_[iw], current_step); +} + + } // namespace qmcplusplus diff --git a/src/QMCDrivers/Crowd.h b/src/QMCDrivers/Crowd.h index 0a925e915f..e044de3173 100644 --- a/src/QMCDrivers/Crowd.h +++ b/src/QMCDrivers/Crowd.h @@ -85,6 +85,9 @@ class Crowd estimator_manager_crowd_.accumulate(mcp_walkers_, walker_elecs_, walker_twfs_, walker_hamiltonians_, rng); } + /// Collect walker trace data + void collect(int current_step); + void setRNGForHamiltonian(RandomBase& rng); auto beginWalkers() { return mcp_walkers_.begin(); } diff --git a/src/QMCDrivers/DMC/DMCBatched.cpp b/src/QMCDrivers/DMC/DMCBatched.cpp index c57283b84b..e3ed55a292 100644 --- a/src/QMCDrivers/DMC/DMCBatched.cpp +++ b/src/QMCDrivers/DMC/DMCBatched.cpp @@ -288,8 +288,10 @@ void DMCBatched::advanceWalkers(const StateForThread& sft, crowd.accumulate(step_context.get_random_gen()); } - for (int iw = 0; iw < crowd.size(); ++iw) - crowd.wtrace_collector_.collect(walkers[iw], walker_elecs[iw], walker_twfs[iw], walker_hamiltonians[iw], sft.current_step); + // collect walker traces + crowd.collect(sft.current_step); + //for (int iw = 0; iw < crowd.size(); ++iw) + // crowd.wtrace_collector_.collect(walkers[iw], walker_elecs[iw], walker_twfs[iw], walker_hamiltonians[iw], sft.current_step); { // T-moves ScopedTimer tmove_timer(dmc_timers.tmove_timer); diff --git a/src/QMCDrivers/VMC/VMCBatched.cpp b/src/QMCDrivers/VMC/VMCBatched.cpp index f02912600a..b427dc5c15 100644 --- a/src/QMCDrivers/VMC/VMCBatched.cpp +++ b/src/QMCDrivers/VMC/VMCBatched.cpp @@ -216,8 +216,10 @@ void VMCBatched::advanceWalkers(const StateForThread& sft, crowd.accumulate(step_context.get_random_gen()); } - for (int iw = 0; iw < crowd.size(); ++iw) - crowd.wtrace_collector_.collect(walkers[iw], walker_elecs[iw], walker_twfs[iw], walker_hamiltonians[iw], sft.current_step); + // collect walker traces + crowd.collect(sft.current_step); + //for (int iw = 0; iw < crowd.size(); ++iw) + // crowd.wtrace_collector_.collect(walkers[iw], walker_elecs[iw], walker_twfs[iw], walker_hamiltonians[iw], sft.current_step); // TODO: // check if all moves failed From 89fe362a2bfbaebb6d4a4c67462fae290b278b14 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Fri, 31 May 2024 17:30:24 -0400 Subject: [PATCH 35/55] const in collect --- src/Estimators/WalkerTraceManager.cpp | 2 +- src/Estimators/WalkerTraceManager.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Estimators/WalkerTraceManager.cpp b/src/Estimators/WalkerTraceManager.cpp index d7bea3c38c..c717313711 100644 --- a/src/Estimators/WalkerTraceManager.cpp +++ b/src/Estimators/WalkerTraceManager.cpp @@ -63,7 +63,7 @@ void WalkerTraceCollector::startBlock() } -void WalkerTraceCollector::collect(MCPWalker& walker, ParticleSet& pset, TrialWaveFunction& wfn, QMCHamiltonian& ham, int step) +void WalkerTraceCollector::collect(const MCPWalker& walker, const ParticleSet& pset, const TrialWaveFunction& wfn, const QMCHamiltonian& ham, int step) { if(!state.traces_active) return; diff --git a/src/Estimators/WalkerTraceManager.h b/src/Estimators/WalkerTraceManager.h index 3e5c35baba..3903461957 100644 --- a/src/Estimators/WalkerTraceManager.h +++ b/src/Estimators/WalkerTraceManager.h @@ -389,7 +389,7 @@ class WalkerTraceCollector void startBlock(); - void collect(MCPWalker& walker, ParticleSet& pset, TrialWaveFunction& wfn, QMCHamiltonian& ham, int step=-1); + void collect(const MCPWalker& walker, const ParticleSet& pset, const TrialWaveFunction& wfn, const QMCHamiltonian& ham, int step=-1); void check_buffers(); From 085c7b38bf5895594119f920a1081f244c068ac8 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Mon, 3 Jun 2024 08:52:59 -0400 Subject: [PATCH 36/55] input at driver level --- src/Estimators/WalkerTraceManager.cpp | 4 +--- src/Estimators/WalkerTraceManager.h | 5 ++++- src/QMCDrivers/DMC/DMCBatched.cpp | 4 +--- src/QMCDrivers/QMCDriver.cpp | 6 +++++- src/QMCDrivers/QMCDriverNew.cpp | 2 ++ src/QMCDrivers/QMCDriverNew.h | 8 +++++--- src/QMCDrivers/VMC/VMCBatched.cpp | 4 +--- 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Estimators/WalkerTraceManager.cpp b/src/Estimators/WalkerTraceManager.cpp index c717313711..42d7bb5150 100644 --- a/src/Estimators/WalkerTraceManager.cpp +++ b/src/Estimators/WalkerTraceManager.cpp @@ -201,15 +201,13 @@ void WalkerTraceCollector::check_buffers() // WalkerTraceManager methods // //////////////////////////////// -WalkerTraceManager::WalkerTraceManager(xmlNodePtr cur, bool allow_traces, std::string series_root, Communicate* comm) +WalkerTraceManager::WalkerTraceManager(WalkerTraceInput& inp, bool allow_traces, std::string series_root, Communicate* comm) { state.reset_permissions(); communicator = comm; file_root = series_root; bool method_allows_traces = allow_traces; - WalkerTraceInput inp(cur); - bool traces_requested = inp.present; state.traces_active = traces_requested && method_allows_traces; diff --git a/src/Estimators/WalkerTraceManager.h b/src/Estimators/WalkerTraceManager.h index 3903461957..9fb71c4875 100644 --- a/src/Estimators/WalkerTraceManager.h +++ b/src/Estimators/WalkerTraceManager.h @@ -399,6 +399,9 @@ class WalkerTraceCollector +class WalkerTraceInput; + + class WalkerTraceManager { private: @@ -430,7 +433,7 @@ class WalkerTraceManager WalkerTraceBuffer wmed_particle_real_buffer; public: - WalkerTraceManager(xmlNodePtr cur, bool allow_traces, std::string series_root, Communicate* comm = 0); + WalkerTraceManager(WalkerTraceInput& inp, bool allow_traces, std::string series_root, Communicate* comm = 0); inline WalkerTraceState get_state() { return state; } diff --git a/src/QMCDrivers/DMC/DMCBatched.cpp b/src/QMCDrivers/DMC/DMCBatched.cpp index e3ed55a292..0b2860ca23 100644 --- a/src/QMCDrivers/DMC/DMCBatched.cpp +++ b/src/QMCDrivers/DMC/DMCBatched.cpp @@ -290,8 +290,6 @@ void DMCBatched::advanceWalkers(const StateForThread& sft, // collect walker traces crowd.collect(sft.current_step); - //for (int iw = 0; iw < crowd.size(); ++iw) - // crowd.wtrace_collector_.collect(walkers[iw], walker_elecs[iw], walker_twfs[iw], walker_hamiltonians[iw], sft.current_step); { // T-moves ScopedTimer tmove_timer(dmc_timers.tmove_timer); @@ -436,7 +434,7 @@ bool DMCBatched::run() estimator_manager_->startDriverRun(); //start walker trace manager - wtrace_manager_ = std::make_unique(walker_traces_xml, allow_walker_traces, get_root_name(), myComm); + wtrace_manager_ = std::make_unique(walker_traces_input, allow_walker_traces, get_root_name(), myComm); std::vector wtrace_collectors; for (auto& c: crowds_) wtrace_collectors.push_back(&c->wtrace_collector_); diff --git a/src/QMCDrivers/QMCDriver.cpp b/src/QMCDrivers/QMCDriver.cpp index aba2d11f05..fc4eb179cb 100644 --- a/src/QMCDrivers/QMCDriver.cpp +++ b/src/QMCDrivers/QMCDriver.cpp @@ -36,6 +36,7 @@ #else using TraceManager = int; #endif +#include "Estimators/WalkerTraceManagerInput.h" #include "Estimators/WalkerTraceManager.h" namespace qmcplusplus @@ -205,7 +206,10 @@ void QMCDriver::process(xmlNodePtr cur) #endif //create and initialize traces if (!wtrace_manager_) - wtrace_manager_ = std::make_unique(walker_traces_xml, allow_walker_traces, RootName, myComm); + { + WalkerTraceInput walker_traces_input(walker_traces_xml); + wtrace_manager_ = std::make_unique(walker_traces_input, allow_walker_traces, RootName, myComm); + } branchEngine->put(cur); Estimators->put(H, cur); if (!wOut) diff --git a/src/QMCDrivers/QMCDriverNew.cpp b/src/QMCDrivers/QMCDriverNew.cpp index 1b058e042b..4ae992a7ba 100644 --- a/src/QMCDrivers/QMCDriverNew.cpp +++ b/src/QMCDrivers/QMCDriverNew.cpp @@ -33,6 +33,7 @@ #include "Utilities/Timer.h" #include "Message/UniformCommunicateError.h" #include "EstimatorInputDelegates.h" +#include "Estimators/WalkerTraceManagerInput.h" #include "Estimators/WalkerTraceManager.h" @@ -206,6 +207,7 @@ void QMCDriverNew::setStatus(const std::string& aname, const std::string& h5name h5_file_root_ = h5name; } + /** Read walker configurations from *.config.h5 files * @param wset list of xml elements containing mcwalkerset * diff --git a/src/QMCDrivers/QMCDriverNew.h b/src/QMCDrivers/QMCDriverNew.h index e5f7e1a84f..67a339719b 100644 --- a/src/QMCDrivers/QMCDriverNew.h +++ b/src/QMCDrivers/QMCDriverNew.h @@ -43,6 +43,7 @@ #include "DriverWalkerTypes.h" #include "TauParams.hpp" #include "Particle/MCCoords.hpp" +#include "Estimators/WalkerTraceManagerInput.h" #include class Communicate; @@ -104,8 +105,9 @@ class QMCDriverNew : public QMCDriverInterface, public MPIObjectBase /// whether to allow walker traces bool allow_walker_traces; - /// walker traces xml - xmlNodePtr walker_traces_xml; + /// walker traces input + WalkerTraceInput walker_traces_input; + //xmlNodePtr walker_traces_xml; protected: /** This is a data structure strictly for QMCDriver and its derived classes @@ -247,7 +249,7 @@ class QMCDriverNew : public QMCDriverInterface, public MPIObjectBase void putTraces(xmlNodePtr txml) override {} void requestTraces(bool allow_traces) override {} - void putWalkerTraces(xmlNodePtr txml) override { walker_traces_xml = txml; } + void putWalkerTraces(xmlNodePtr txml) override { walker_traces_input.readXML(txml); } void requestWalkerTraces(bool allow_traces_) override { allow_walker_traces = allow_traces_; } diff --git a/src/QMCDrivers/VMC/VMCBatched.cpp b/src/QMCDrivers/VMC/VMCBatched.cpp index b427dc5c15..343732ae2a 100644 --- a/src/QMCDrivers/VMC/VMCBatched.cpp +++ b/src/QMCDrivers/VMC/VMCBatched.cpp @@ -218,8 +218,6 @@ void VMCBatched::advanceWalkers(const StateForThread& sft, // collect walker traces crowd.collect(sft.current_step); - //for (int iw = 0; iw < crowd.size(); ++iw) - // crowd.wtrace_collector_.collect(walkers[iw], walker_elecs[iw], walker_twfs[iw], walker_hamiltonians[iw], sft.current_step); // TODO: // check if all moves failed @@ -312,7 +310,7 @@ bool VMCBatched::run() //start the main estimator estimator_manager_->startDriverRun(); //start walker trace manager - wtrace_manager_ = std::make_unique(walker_traces_xml, allow_walker_traces, get_root_name(), myComm); + wtrace_manager_ = std::make_unique(walker_traces_input, allow_walker_traces, get_root_name(), myComm); std::vector wtrace_collectors; for (auto& c: crowds_) wtrace_collectors.push_back(&c->wtrace_collector_); From b042ff9a672bd46143cb990e7fd5de9cd14ba00c Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Mon, 3 Jun 2024 09:20:37 -0400 Subject: [PATCH 37/55] WalkerTraceBuffer as a class --- src/Estimators/WalkerTraceManager.cpp | 6 +- src/Estimators/WalkerTraceManager.h | 92 +++++++++++++-------------- 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/Estimators/WalkerTraceManager.cpp b/src/Estimators/WalkerTraceManager.cpp index 42d7bb5150..dbab5a269a 100644 --- a/src/Estimators/WalkerTraceManager.cpp +++ b/src/Estimators/WalkerTraceManager.cpp @@ -179,9 +179,9 @@ void WalkerTraceCollector::reset_buffers() void WalkerTraceCollector::check_buffers() { if (state.verbose) app_log() << "WalkerTraceCollector::check_buffers"< -struct WalkerTraceBuffer +class WalkerTraceBuffer { - Array buffer; +public: bool verbose; - size_t walker_data_size; - std::vector quantity_info; - bool first_collect; - size_t quantity_pointer; //hdf variables std::string label; - hsize_t dims[2]; hsize_t hdf_file_pointer; +private: + size_t quantity_pointer; + std::vector quantity_info; + size_t walker_data_size; + Array buffer; + hsize_t dims[2]; + +public: WalkerTraceBuffer() { label = "?"; @@ -100,11 +103,11 @@ struct WalkerTraceBuffer reset_buffer(); } + inline size_t nrows() { return buffer.size(0); } - inline void reset_buffer() - { - buffer.resize(0, buffer.size(1)); - } + inline size_t ncols() { return buffer.size(1); } + + inline void reset_buffer() { buffer.resize(0, buffer.size(1)); } inline void reset_collect() @@ -116,41 +119,7 @@ struct WalkerTraceBuffer } - inline bool same_as(WalkerTraceBuffer& ref) - { - return buffer.size(1) == ref.buffer.size(1); - } - - - inline void reset_rowsize(size_t row_size) - { - auto nrows = buffer.size(0); - if(nrows==0) - nrows++; - if(nrows!=1) - throw std::runtime_error("WalkerTraceBuffer::reset_rowsize row_size (number of columns) should only be changed during growth of the first row."); - auto buffer_old(buffer); - buffer.resize(nrows,row_size); - std::copy_n(buffer_old.data(), buffer_old.size(), buffer.data()); - if(buffer.size(0)!=1) - throw std::runtime_error("WalkerTraceBuffer::reset_rowsize buffer should contain only a single row upon completion."); - if(buffer.size(1)!=row_size) - throw std::runtime_error("WalkerTraceBuffer::reset_rowsize length of buffer row should match the requested row_size following the reset/udpate."); - } - - - inline void make_new_row() - { - size_t nrows = buffer.size(0); - size_t row_size = buffer.size(1); - if (row_size==0) - throw std::runtime_error("WalkerTraceBuffer::make_new_row Cannot make a new row of size zero."); - nrows++; - // resizing buffer(type Array) doesn't preserve data. Thus keep old data and copy over - auto buffer_old(buffer); - buffer.resize(nrows, row_size); - std::copy_n(buffer_old.data(), buffer_old.size(), buffer.data()); - } + inline bool same_as(const WalkerTraceBuffer& ref) { return buffer.size(1) == ref.buffer.size(1); } inline void collect(const std::string& name, const T& value) @@ -327,6 +296,37 @@ struct WalkerTraceBuffer } f.flush(); } + +private: + inline void reset_rowsize(size_t row_size) + { + auto nrows = buffer.size(0); + if(nrows==0) + nrows++; + if(nrows!=1) + throw std::runtime_error("WalkerTraceBuffer::reset_rowsize row_size (number of columns) should only be changed during growth of the first row."); + auto buffer_old(buffer); + buffer.resize(nrows,row_size); + std::copy_n(buffer_old.data(), buffer_old.size(), buffer.data()); + if(buffer.size(0)!=1) + throw std::runtime_error("WalkerTraceBuffer::reset_rowsize buffer should contain only a single row upon completion."); + if(buffer.size(1)!=row_size) + throw std::runtime_error("WalkerTraceBuffer::reset_rowsize length of buffer row should match the requested row_size following the reset/udpate."); + } + + inline void make_new_row() + { + size_t nrows = buffer.size(0); + size_t row_size = buffer.size(1); + if (row_size==0) + throw std::runtime_error("WalkerTraceBuffer::make_new_row Cannot make a new row of size zero."); + nrows++; + // resizing buffer(type Array) doesn't preserve data. Thus keep old data and copy over + auto buffer_old(buffer); + buffer.resize(nrows, row_size); + std::copy_n(buffer_old.data(), buffer_old.size(), buffer.data()); + } + }; From fe47abd995268296bf34cfa16b1420d255393475 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Mon, 3 Jun 2024 11:15:03 -0400 Subject: [PATCH 38/55] camelize --- src/Estimators/WalkerTraceManager.cpp | 195 ++++++++++++-------------- src/Estimators/WalkerTraceManager.h | 85 +++++------ src/QMCDrivers/DMC/DMC.cpp | 2 +- src/QMCDrivers/DMC/DMCBatched.cpp | 2 +- src/QMCDrivers/VMC/VMC.cpp | 2 +- src/QMCDrivers/VMC/VMCBatched.cpp | 2 +- 6 files changed, 130 insertions(+), 158 deletions(-) diff --git a/src/Estimators/WalkerTraceManager.cpp b/src/Estimators/WalkerTraceManager.cpp index dbab5a269a..56279299bf 100644 --- a/src/Estimators/WalkerTraceManager.cpp +++ b/src/Estimators/WalkerTraceManager.cpp @@ -36,7 +36,7 @@ using MCPWalker = Walker; WalkerTraceCollector::WalkerTraceCollector() : properties_include{"R2Accepted","R2Proposed","LocalEnergy","LocalPotential","Kinetic","ElecElec","ElecIon","LocalECP","NonLocalECP"} { - state.reset_permissions(); + state.reset(); energy_index = -1; steps.resize(0); energies.resize(0); @@ -46,20 +46,11 @@ WalkerTraceCollector::WalkerTraceCollector() } -void WalkerTraceCollector::set_state(const WalkerTraceState& tms) -{ - state = tms; - walker_property_int_buffer.verbose = state.verbose; - walker_property_real_buffer.verbose = state.verbose; - walker_particle_real_buffer.verbose = state.verbose; -} - - void WalkerTraceCollector::startBlock() { if(!state.traces_active) return; if (state.verbose) app_log() << "WalkerTraceCollector::startBlock " << std::endl; - reset_buffers(); + resetBuffers(); } @@ -102,14 +93,14 @@ void WalkerTraceCollector::collect(const MCPWalker& walker, const ParticleSet& p for(size_t p=0;pset_state(get_state()); + tc->state = state; return tc; } @@ -260,9 +251,9 @@ void WalkerTraceManager::startRun(std::vector& collectors if (!state.traces_active) return; if (state.verbose) app_log() << "WalkerTraceManager::startRun " << std::endl; for (auto& tc: collectors) - tc->set_state(state); - check_collectors(collectors); - open_file(collectors); + tc->state = state; + checkCollectors(collectors); + openFile(collectors); } @@ -270,32 +261,32 @@ void WalkerTraceManager::stopRun() { if (!state.traces_active) return; if (state.verbose) app_log() << "WalkerTraceManager::stopRun " << std::endl; - close_file(); + closeFile(); } -void WalkerTraceManager::write_buffers(std::vector& collectors) +void WalkerTraceManager::writeBuffers(std::vector& collectors) { if (!state.traces_active) return; - if (state.verbose) app_log() << "WalkerTraceManager::write_buffers "<& colle for (size_t c=0; c& colle auto nmin = n1; // index of minimum energy walker for this step auto nmax = n2; // index of maximum energy walker for this step auto nmed = (n1+n2)/2; // index of median energy walker for this step - //app_log()<<" "<(energy_order[nmin]); r = std::get<3>(energy_order[nmin]); - wmin_property_int_buffer.add_row(collectors[c]->walker_property_int_buffer,r); - wmin_property_real_buffer.add_row(collectors[c]->walker_property_real_buffer,r); - wmin_particle_real_buffer.add_row(collectors[c]->walker_particle_real_buffer,r); + wmin_property_int_buffer.addRow(collectors[c]->walker_property_int_buffer,r); + wmin_property_real_buffer.addRow(collectors[c]->walker_property_real_buffer,r); + wmin_particle_real_buffer.addRow(collectors[c]->walker_particle_real_buffer,r); } if(write_max_data) {// cache data for maximum energy walker c = std::get<2>(energy_order[nmax]); r = std::get<3>(energy_order[nmax]); - wmax_property_int_buffer.add_row(collectors[c]->walker_property_int_buffer,r); - wmax_property_real_buffer.add_row(collectors[c]->walker_property_real_buffer,r); - wmax_particle_real_buffer.add_row(collectors[c]->walker_particle_real_buffer,r); + wmax_property_int_buffer.addRow(collectors[c]->walker_property_int_buffer,r); + wmax_property_real_buffer.addRow(collectors[c]->walker_property_real_buffer,r); + wmax_particle_real_buffer.addRow(collectors[c]->walker_particle_real_buffer,r); } if(write_med_data) {// cache data for median energy walker c = std::get<2>(energy_order[nmed]); r = std::get<3>(energy_order[nmed]); - wmed_property_int_buffer.add_row(collectors[c]->walker_property_int_buffer,r); - wmed_property_real_buffer.add_row(collectors[c]->walker_property_real_buffer,r); - wmed_particle_real_buffer.add_row(collectors[c]->walker_particle_real_buffer,r); + wmed_property_int_buffer.addRow(collectors[c]->walker_property_int_buffer,r); + wmed_property_real_buffer.addRow(collectors[c]->walker_property_real_buffer,r); + wmed_particle_real_buffer.addRow(collectors[c]->walker_particle_real_buffer,r); } // reset pointers n1 = n; @@ -361,24 +351,17 @@ void WalkerTraceManager::write_buffers(std::vector& colle } n++; } - //app_log()<(v) << " " << std::get<1>(v) << " " << std::get<2>(v) << " " << std::get<3>(v) << std::endl; - // n++; - //} energy_order.resize(0); } // write buffer data to file - write_buffers_hdf(collectors); + writeBuffersHDF(collectors); } -void WalkerTraceManager::check_collectors(std::vector& collectors) +void WalkerTraceManager::checkCollectors(std::vector& collectors) { - if (state.verbose) app_log() << "WalkerTraceManager::check_collectors" << std::endl; + if (state.verbose) app_log() << "WalkerTraceManager::checkCollectors" << std::endl; if (collectors.size() > 0) { bool all_same = true; @@ -386,13 +369,13 @@ void WalkerTraceManager::check_collectors(std::vector& co for (int i = 0; i < collectors.size(); ++i) { WalkerTraceCollector& tc = *collectors[i]; - all_same &= tc.walker_property_int_buffer.same_as(ref.walker_property_int_buffer); - all_same &= tc.walker_property_real_buffer.same_as(ref.walker_property_real_buffer); - all_same &= tc.walker_particle_real_buffer.same_as(ref.walker_particle_real_buffer); + all_same &= tc.walker_property_int_buffer.sameAs(ref.walker_property_int_buffer); + all_same &= tc.walker_property_real_buffer.sameAs(ref.walker_property_real_buffer); + all_same &= tc.walker_particle_real_buffer.sameAs(ref.walker_particle_real_buffer); } if (!all_same) { - throw std::runtime_error("WalkerTraceManager::check_collectors trace buffer widths of collectors do not match\n contiguous write is " + throw std::runtime_error("WalkerTraceManager::checkCollectors trace buffer widths of collectors do not match\n contiguous write is " "impossible\n this was first caused by collectors contributing array traces from identical, but " "differently named, particlesets such as e, e2, e3 ... (fixed)\n please check the WalkerTraceManager " "summaries printed above"); @@ -401,25 +384,25 @@ void WalkerTraceManager::check_collectors(std::vector& co } -void WalkerTraceManager::open_file(std::vector& collectors) +void WalkerTraceManager::openFile(std::vector& collectors) { - if (state.verbose) app_log() << "WalkerTraceManager::open_file "<& collectors) +void WalkerTraceManager::openHDFFile(std::vector& collectors) { - if (state.verbose) app_log() << "WalkerTraceManager::open_hdf_file " << std::endl; + if (state.verbose) app_log() << "WalkerTraceManager::openHDFFile " << std::endl; if (collectors.size() == 0) - throw std::runtime_error("WalkerTraceManager::open_hdf_file no trace collectors exist, cannot open file"); + throw std::runtime_error("WalkerTraceManager::openHDFFile no trace collectors exist, cannot open file"); int nprocs = communicator->size(); int rank = communicator->rank(); std::array ptoken; @@ -438,76 +421,76 @@ void WalkerTraceManager::open_hdf_file(std::vector& colle file_name.append(ptoken.data(), length); } file_name += ".wtraces.h5"; - if (state.verbose) app_log() << "WalkerTraceManager::open_hdf_file opening traces hdf file " << file_name << std::endl; + if (state.verbose) app_log() << "WalkerTraceManager::openHDFFile opening traces hdf file " << file_name << std::endl; hdf_file = std::make_unique(); bool successful = hdf_file->create(file_name); if (!successful) - throw std::runtime_error("WalkerTraceManager::open_hdf_file failed to open hdf file " + file_name); + throw std::runtime_error("WalkerTraceManager::openHDFFile failed to open hdf file " + file_name); } -void WalkerTraceManager::write_buffers_hdf(std::vector& collectors) +void WalkerTraceManager::writeBuffersHDF(std::vector& collectors) { - if (state.verbose) app_log() << "WalkerTraceManager::write_buffers_hdf " << std::endl; + if (state.verbose) app_log() << "WalkerTraceManager::writeBuffersHDF " << std::endl; WalkerTraceCollector& tc_lead = *collectors[0]; if(!registered_hdf) { - tc_lead.walker_property_int_buffer.register_hdf_data(*hdf_file); - tc_lead.walker_property_real_buffer.register_hdf_data(*hdf_file); + tc_lead.walker_property_int_buffer.registerHDFData(*hdf_file); + tc_lead.walker_property_real_buffer.registerHDFData(*hdf_file); if(write_particle_data) - tc_lead.walker_particle_real_buffer.register_hdf_data(*hdf_file); + tc_lead.walker_particle_real_buffer.registerHDFData(*hdf_file); if(write_min_data) { - wmin_property_int_buffer.register_hdf_data(*hdf_file); - wmin_property_real_buffer.register_hdf_data(*hdf_file); - wmin_particle_real_buffer.register_hdf_data(*hdf_file); + wmin_property_int_buffer.registerHDFData(*hdf_file); + wmin_property_real_buffer.registerHDFData(*hdf_file); + wmin_particle_real_buffer.registerHDFData(*hdf_file); } if(write_max_data) { - wmax_property_int_buffer.register_hdf_data(*hdf_file); - wmax_property_real_buffer.register_hdf_data(*hdf_file); - wmax_particle_real_buffer.register_hdf_data(*hdf_file); + wmax_property_int_buffer.registerHDFData(*hdf_file); + wmax_property_real_buffer.registerHDFData(*hdf_file); + wmax_particle_real_buffer.registerHDFData(*hdf_file); } if(write_med_data) { - wmed_property_int_buffer.register_hdf_data(*hdf_file); - wmed_property_real_buffer.register_hdf_data(*hdf_file); - wmed_particle_real_buffer.register_hdf_data(*hdf_file); + wmed_property_int_buffer.registerHDFData(*hdf_file); + wmed_property_real_buffer.registerHDFData(*hdf_file); + wmed_particle_real_buffer.registerHDFData(*hdf_file); } registered_hdf = true; } for (int ip = 0; ip < collectors.size(); ++ip) { WalkerTraceCollector& tc = *collectors[ip]; - tc.walker_property_int_buffer.write_hdf(*hdf_file, tc_lead.walker_property_int_buffer.hdf_file_pointer); - tc.walker_property_real_buffer.write_hdf(*hdf_file, tc_lead.walker_property_real_buffer.hdf_file_pointer); + tc.walker_property_int_buffer.writeHDF(*hdf_file, tc_lead.walker_property_int_buffer.hdf_file_pointer); + tc.walker_property_real_buffer.writeHDF(*hdf_file, tc_lead.walker_property_real_buffer.hdf_file_pointer); if(write_particle_data) - tc.walker_particle_real_buffer.write_hdf(*hdf_file, tc_lead.walker_particle_real_buffer.hdf_file_pointer); + tc.walker_particle_real_buffer.writeHDF(*hdf_file, tc_lead.walker_particle_real_buffer.hdf_file_pointer); } if(write_min_data) { - wmin_property_int_buffer.write_hdf(*hdf_file); - wmin_property_real_buffer.write_hdf(*hdf_file); - wmin_particle_real_buffer.write_hdf(*hdf_file); + wmin_property_int_buffer.writeHDF(*hdf_file); + wmin_property_real_buffer.writeHDF(*hdf_file); + wmin_particle_real_buffer.writeHDF(*hdf_file); } if(write_max_data) { - wmax_property_int_buffer.write_hdf(*hdf_file); - wmax_property_real_buffer.write_hdf(*hdf_file); - wmax_particle_real_buffer.write_hdf(*hdf_file); + wmax_property_int_buffer.writeHDF(*hdf_file); + wmax_property_real_buffer.writeHDF(*hdf_file); + wmax_particle_real_buffer.writeHDF(*hdf_file); } if(write_med_data) { - wmed_property_int_buffer.write_hdf(*hdf_file); - wmed_property_real_buffer.write_hdf(*hdf_file); - wmed_particle_real_buffer.write_hdf(*hdf_file); + wmed_property_int_buffer.writeHDF(*hdf_file); + wmed_property_real_buffer.writeHDF(*hdf_file); + wmed_particle_real_buffer.writeHDF(*hdf_file); } } -void WalkerTraceManager::close_hdf_file() +void WalkerTraceManager::closeHDFFile() { - if (state.verbose) app_log() << "WalkerTraceManager::close_hdf_file " << std::endl; + if (state.verbose) app_log() << "WalkerTraceManager::closeHDFFile " << std::endl; hdf_file.reset(); } diff --git a/src/Estimators/WalkerTraceManager.h b/src/Estimators/WalkerTraceManager.h index b61aa03e8f..05d164cdcd 100644 --- a/src/Estimators/WalkerTraceManager.h +++ b/src/Estimators/WalkerTraceManager.h @@ -77,11 +77,7 @@ template class WalkerTraceBuffer { public: - bool verbose; - bool first_collect; - - //hdf variables std::string label; hsize_t hdf_file_pointer; @@ -96,21 +92,19 @@ class WalkerTraceBuffer WalkerTraceBuffer() { label = "?"; - verbose = false; first_collect = true; walker_data_size = 0; quantity_pointer = 0; - reset_buffer(); + resetBuffer(); } inline size_t nrows() { return buffer.size(0); } inline size_t ncols() { return buffer.size(1); } - inline void reset_buffer() { buffer.resize(0, buffer.size(1)); } - + inline void resetBuffer() { buffer.resize(0, buffer.size(1)); } - inline void reset_collect() + inline void resetCollect() { if(quantity_pointer!=quantity_info.size()) throw std::runtime_error("WalkerTraceBuffer quantity_pointer has not been moved through all quantities prior during collect() call."); @@ -119,7 +113,7 @@ class WalkerTraceBuffer } - inline bool same_as(const WalkerTraceBuffer& ref) { return buffer.size(1) == ref.buffer.size(1); } + inline bool sameAs(const WalkerTraceBuffer& ref) { return buffer.size(1) == ref.buffer.size(1); } inline void collect(const std::string& name, const T& value) @@ -130,12 +124,12 @@ class WalkerTraceBuffer WalkerQuantityInfo wqi_(name,1,walker_data_size); quantity_info.push_back(wqi_); walker_data_size = wqi_.buffer_end; - reset_rowsize(walker_data_size); + resetRowSize(walker_data_size); } else { if(quantity_pointer==0) - make_new_row(); + makeNewRow(); irow = buffer.size(0)-1; } auto& wqi = quantity_info[quantity_pointer]; @@ -161,12 +155,12 @@ class WalkerTraceBuffer WalkerQuantityInfo wqi_(name,1,walker_data_size,n1,n2,n3,n4); quantity_info.push_back(wqi_); walker_data_size = wqi_.buffer_end; - reset_rowsize(walker_data_size); + resetRowSize(walker_data_size); } else { if(quantity_pointer==0) - make_new_row(); + makeNewRow(); irow = buffer.size(0)-1; } auto& wqi = quantity_info[quantity_pointer]; @@ -194,12 +188,12 @@ class WalkerTraceBuffer WalkerQuantityInfo wqi_(name,2,walker_data_size,n1,n2,n3,n4); quantity_info.push_back(wqi_); walker_data_size = wqi_.buffer_end; - reset_rowsize(walker_data_size); + resetRowSize(walker_data_size); } else { if(quantity_pointer==0) - make_new_row(); + makeNewRow(); irow = buffer.size(0)-1; } auto& wqi = quantity_info[quantity_pointer]; @@ -214,13 +208,12 @@ class WalkerTraceBuffer } - inline void add_row(WalkerTraceBuffer other, size_t i) + inline void addRow(WalkerTraceBuffer other, size_t i) { - //app_log()<<"WalkerTraceBuffer("< property_indices; int energy_index; -private: WalkerTraceState state; - + +private: // temporary (contiguous) storage for awful ParticleAttrib<> quantities Array Rtmp; Array Stmp; @@ -385,16 +377,14 @@ class WalkerTraceCollector public: WalkerTraceCollector(); - void set_state(const WalkerTraceState& tms); - void startBlock(); void collect(const MCPWalker& walker, const ParticleSet& pset, const TrialWaveFunction& wfn, const QMCHamiltonian& ham, int step=-1); - void check_buffers(); + void checkBuffers(); private: - void reset_buffers(); + void resetBuffers(); }; @@ -404,14 +394,15 @@ class WalkerTraceInput; class WalkerTraceManager { +public: + WalkerTraceState state; + private: std::string file_root; Communicate* communicator; std::unique_ptr hdf_file; bool registered_hdf; - WalkerTraceState state; - // new walker buffers bool write_particle_data; bool write_min_data; @@ -435,8 +426,6 @@ class WalkerTraceManager public: WalkerTraceManager(WalkerTraceInput& inp, bool allow_traces, std::string series_root, Communicate* comm = 0); - inline WalkerTraceState get_state() { return state; } - WalkerTraceCollector* makeCollector(); void startRun(std::vector& collectors); @@ -444,21 +433,21 @@ class WalkerTraceManager void stopRun(); //write buffered trace data to file - void write_buffers(std::vector& collectors); + void writeBuffers(std::vector& collectors); private: - void check_collectors(std::vector& collectors); + void checkCollectors(std::vector& collectors); - void open_file(std::vector& collectors); + void openFile(std::vector& collectors); - void close_file(); + void closeFile(); //hdf file operations - void open_hdf_file(std::vector& collectors); + void openHDFFile(std::vector& collectors); - void write_buffers_hdf(std::vector& collectors); + void writeBuffersHDF(std::vector& collectors); - void close_hdf_file(); + void closeHDFFile(); }; diff --git a/src/QMCDrivers/DMC/DMC.cpp b/src/QMCDrivers/DMC/DMC.cpp index 7e057b1707..ba0dee3ffb 100644 --- a/src/QMCDrivers/DMC/DMC.cpp +++ b/src/QMCDrivers/DMC/DMC.cpp @@ -297,7 +297,7 @@ bool DMC::run() #if !defined(REMOVE_TRACEMANAGER) Traces->write_buffers(traceClones, block); #endif - wtrace_manager_->write_buffers(wtrace_collectors); + wtrace_manager_->writeBuffers(wtrace_collectors); block++; if (DumpConfig && block % Period4CheckPoint == 0) { diff --git a/src/QMCDrivers/DMC/DMCBatched.cpp b/src/QMCDrivers/DMC/DMCBatched.cpp index 0b2860ca23..e1f56dc556 100644 --- a/src/QMCDrivers/DMC/DMCBatched.cpp +++ b/src/QMCDrivers/DMC/DMCBatched.cpp @@ -516,7 +516,7 @@ bool DMCBatched::run() if (qmcdriver_input_.get_measure_imbalance()) measureImbalance("Block " + std::to_string(block)); endBlock(); - wtrace_manager_->write_buffers(wtrace_collectors); + wtrace_manager_->writeBuffers(wtrace_collectors); recordBlock(block); } diff --git a/src/QMCDrivers/VMC/VMC.cpp b/src/QMCDrivers/VMC/VMC.cpp index be9c6f2516..6fe8a31bd9 100644 --- a/src/QMCDrivers/VMC/VMC.cpp +++ b/src/QMCDrivers/VMC/VMC.cpp @@ -111,7 +111,7 @@ bool VMC::run() #if !defined(REMOVE_TRACEMANAGER) Traces->write_buffers(traceClones, block); #endif - wtrace_manager_->write_buffers(wtrace_collectors); + wtrace_manager_->writeBuffers(wtrace_collectors); recordBlock(block); vmc_loop.stop(); diff --git a/src/QMCDrivers/VMC/VMCBatched.cpp b/src/QMCDrivers/VMC/VMCBatched.cpp index 343732ae2a..305d521f1f 100644 --- a/src/QMCDrivers/VMC/VMCBatched.cpp +++ b/src/QMCDrivers/VMC/VMCBatched.cpp @@ -405,7 +405,7 @@ bool VMCBatched::run() if (qmcdriver_input_.get_measure_imbalance()) measureImbalance("Block " + std::to_string(block)); endBlock(); - wtrace_manager_->write_buffers(wtrace_collectors); + wtrace_manager_->writeBuffers(wtrace_collectors); recordBlock(block); } From 921411f04cc0427747c807e2dbab1aeb8be59709 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Mon, 3 Jun 2024 11:56:55 -0400 Subject: [PATCH 39/55] break into multiple files --- src/Estimators/CMakeLists.txt | 2 + src/Estimators/WalkerTraceBuffer.h | 326 +++++++++++++++ src/Estimators/WalkerTraceCollector.cpp | 182 +++++++++ src/Estimators/WalkerTraceCollector.h | 91 +++++ ...TraceManagerInput.h => WalkerTraceInput.h} | 8 +- src/Estimators/WalkerTraceManager.cpp | 178 +-------- src/Estimators/WalkerTraceManager.h | 370 +----------------- src/QMCDrivers/QMCDriver.cpp | 2 +- src/QMCDrivers/QMCDriverNew.cpp | 2 +- src/QMCDrivers/QMCDriverNew.h | 2 +- 10 files changed, 611 insertions(+), 552 deletions(-) create mode 100644 src/Estimators/WalkerTraceBuffer.h create mode 100644 src/Estimators/WalkerTraceCollector.cpp create mode 100644 src/Estimators/WalkerTraceCollector.h rename src/Estimators/{WalkerTraceManagerInput.h => WalkerTraceInput.h} (87%) diff --git a/src/Estimators/CMakeLists.txt b/src/Estimators/CMakeLists.txt index 7f37bc99ff..f49e1a0ffb 100644 --- a/src/Estimators/CMakeLists.txt +++ b/src/Estimators/CMakeLists.txt @@ -26,6 +26,8 @@ set(QMCEST_SRC EstimatorManagerBase.cpp EstimatorManagerNew.cpp EstimatorManagerCrowd.cpp + WalkerTraceCollector.cpp + WalkerTraceManager.cpp CollectablesEstimator.cpp OperatorEstBase.cpp SpinDensityNew.cpp diff --git a/src/Estimators/WalkerTraceBuffer.h b/src/Estimators/WalkerTraceBuffer.h new file mode 100644 index 0000000000..f9e72697cc --- /dev/null +++ b/src/Estimators/WalkerTraceBuffer.h @@ -0,0 +1,326 @@ +////////////////////////////////////////////////////////////////////////////////////// +// This file is distributed under the University of Illinois/NCSA Open Source License. +// See LICENSE file in top directory for details. +// +// Copyright (c) 2024 QMCPACK developers. +// +// File developed by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory +// +// File created by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory +////////////////////////////////////////////////////////////////////////////////////// + + +#ifndef QMCPLUSPLUS_WALKERTRACEBUFFER_H +#define QMCPLUSPLUS_WALKERTRACEBUFFER_H + + +#include +#include "OhmmsPETE/OhmmsArray.h" +#include "hdf/hdf_archive.h" + +#include + + + +namespace qmcplusplus +{ + +const unsigned int WDMAX = 4; +using WTraceInt = long; +using WTraceReal = OHMMS_PRECISION_FULL; +using WTraceComp = std::complex; +#ifndef QMC_COMPLEX +using WTracePsiVal = WTraceReal; +#else +using WTracePsiVal = WTraceComp; +#endif + + + +struct WalkerQuantityInfo +{ + std::string name; + size_t dimension; + size_t size; + size_t unit_size; + TinyVector shape; + size_t buffer_start; + size_t buffer_end; + + WalkerQuantityInfo(const std::string& name_,size_t unit_size_,size_t buffer_start_,size_t n1=1,size_t n2=0,size_t n3=0,size_t n4=0) + { + name = name_; + unit_size = unit_size_; + buffer_start = buffer_start_; + shape[0] = n1; + shape[1] = n2; + shape[2] = n3; + shape[3] = n4; + + dimension = 0; + size = 1; + for (size_t d=0;d0) + { + dimension++; + size *= shape[d]; + } + buffer_end = buffer_start + size*unit_size; + } +}; + + + + +template +class WalkerTraceBuffer +{ +public: + bool first_collect; + std::string label; + hsize_t hdf_file_pointer; + +private: + size_t quantity_pointer; + std::vector quantity_info; + size_t walker_data_size; + Array buffer; + hsize_t dims[2]; + +public: + WalkerTraceBuffer() + { + label = "?"; + first_collect = true; + walker_data_size = 0; + quantity_pointer = 0; + resetBuffer(); + } + + inline size_t nrows() { return buffer.size(0); } + + inline size_t ncols() { return buffer.size(1); } + + inline void resetBuffer() { buffer.resize(0, buffer.size(1)); } + + inline void resetCollect() + { + if(quantity_pointer!=quantity_info.size()) + throw std::runtime_error("WalkerTraceBuffer quantity_pointer has not been moved through all quantities prior during collect() call."); + first_collect = false; + quantity_pointer = 0; + } + + + inline bool sameAs(const WalkerTraceBuffer& ref) { return buffer.size(1) == ref.buffer.size(1); } + + + inline void collect(const std::string& name, const T& value) + { + size_t irow=0; + if( first_collect ) + { + WalkerQuantityInfo wqi_(name,1,walker_data_size); + quantity_info.push_back(wqi_); + walker_data_size = wqi_.buffer_end; + resetRowSize(walker_data_size); + } + else + { + if(quantity_pointer==0) + makeNewRow(); + irow = buffer.size(0)-1; + } + auto& wqi = quantity_info[quantity_pointer]; + buffer(irow,wqi.buffer_start) = value; + quantity_pointer++; + } + + + template + inline void collect(const std::string& name, Array arr) + { + size_t n1 = arr.size(0); + size_t n2,n3,n4; + n2=n3=n4=0; + if (D>4) + throw std::runtime_error("WalkerTraceBuffer::collect Only arrays up to dimension 4 are currently supported."); + if (D>1) n2 = arr.size(1); + if (D>2) n3 = arr.size(2); + if (D>3) n4 = arr.size(3); + size_t irow=0; + if( first_collect ) + { + WalkerQuantityInfo wqi_(name,1,walker_data_size,n1,n2,n3,n4); + quantity_info.push_back(wqi_); + walker_data_size = wqi_.buffer_end; + resetRowSize(walker_data_size); + } + else + { + if(quantity_pointer==0) + makeNewRow(); + irow = buffer.size(0)-1; + } + auto& wqi = quantity_info[quantity_pointer]; + auto& arr1d = arr.storage(); + for (size_t n=0;n + inline void collect(const std::string& name, Array,D> arr) + { + size_t n1 = arr.size(0); + size_t n2,n3,n4; + n2=n3=n4=0; + if (D>4) + throw std::runtime_error("WalkerTraceBuffer::collect Only arrays up to dimension 4 are currently supported."); + if (D>1) n2 = arr.size(1); + if (D>2) n3 = arr.size(2); + if (D>3) n4 = arr.size(3); + size_t irow=0; + if( first_collect ) + { + WalkerQuantityInfo wqi_(name,2,walker_data_size,n1,n2,n3,n4); + quantity_info.push_back(wqi_); + walker_data_size = wqi_.buffer_end; + resetRowSize(walker_data_size); + } + else + { + if(quantity_pointer==0) + makeNewRow(); + irow = buffer.size(0)-1; + } + auto& wqi = quantity_info[quantity_pointer]; + auto& arr1d = arr.storage(); + size_t n = 0; + for (size_t i=0;i other, size_t i) + { + auto& other_buffer = other.buffer; + if (first_collect) + { + resetRowSize(other_buffer.size(1)); + quantity_info = other.quantity_info; + first_collect = false; + } + else + { + if(buffer.size(1)!=other_buffer.size(1)) + throw std::runtime_error("WalkerTraceBuffer::add_row Row sizes must match."); + makeNewRow(); + } + size_t ib = buffer.size(0)-1; + for(size_t j=0;j 0) + { + f.push(top); + h5d_append(f.top(), "data", file_pointer, buffer.dim(), dims, buffer.data()); + f.pop(); + } + f.flush(); + } + +private: + inline void resetRowSize(size_t row_size) + { + auto nrows = buffer.size(0); + if(nrows==0) + nrows++; + if(nrows!=1) + throw std::runtime_error("WalkerTraceBuffer::reset_rowsize row_size (number of columns) should only be changed during growth of the first row."); + auto buffer_old(buffer); + buffer.resize(nrows,row_size); + std::copy_n(buffer_old.data(), buffer_old.size(), buffer.data()); + if(buffer.size(0)!=1) + throw std::runtime_error("WalkerTraceBuffer::reset_rowsize buffer should contain only a single row upon completion."); + if(buffer.size(1)!=row_size) + throw std::runtime_error("WalkerTraceBuffer::reset_rowsize length of buffer row should match the requested row_size following the reset/udpate."); + } + + inline void makeNewRow() + { + size_t nrows = buffer.size(0); + size_t row_size = buffer.size(1); + if (row_size==0) + throw std::runtime_error("WalkerTraceBuffer::makeNewRow Cannot make a new row of size zero."); + nrows++; + // resizing buffer(type Array) doesn't preserve data. Thus keep old data and copy over + auto buffer_old(buffer); + buffer.resize(nrows, row_size); + std::copy_n(buffer_old.data(), buffer_old.size(), buffer.data()); + } + +}; + + +} // namespace qmcplusplus + +#endif diff --git a/src/Estimators/WalkerTraceCollector.cpp b/src/Estimators/WalkerTraceCollector.cpp new file mode 100644 index 0000000000..b019a61671 --- /dev/null +++ b/src/Estimators/WalkerTraceCollector.cpp @@ -0,0 +1,182 @@ +////////////////////////////////////////////////////////////////////////////////////// +// This file is distributed under the University of Illinois/NCSA Open Source License. +// See LICENSE file in top directory for details. +// +// Copyright (c) 2024 QMCPACK developers. +// +// File developed by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory +// +// File created by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory +////////////////////////////////////////////////////////////////////////////////////// + + +#include "WalkerTraceCollector.h" + +#include "Particle/Walker.h" +#include "Particle/ParticleSet.h" +#include "QMCWaveFunctions/TrialWaveFunction.h" +#include "QMCHamiltonians/QMCHamiltonian.h" + + + +namespace qmcplusplus +{ + +using MCPWalker = Walker; + + +WalkerTraceCollector::WalkerTraceCollector() + : properties_include{"R2Accepted","R2Proposed","LocalEnergy","LocalPotential","Kinetic","ElecElec","ElecIon","LocalECP","NonLocalECP"} +{ + state.reset(); + energy_index = -1; + steps.resize(0); + energies.resize(0); + walker_property_int_buffer.label = "walker_property_int"; + walker_property_real_buffer.label = "walker_property_real"; + walker_particle_real_buffer.label = "walker_particle_real"; +} + + +void WalkerTraceCollector::startBlock() +{ + if(!state.traces_active) return; + if (state.verbose) app_log() << "WalkerTraceCollector::startBlock " << std::endl; + resetBuffers(); +} + + +void WalkerTraceCollector::collect(const MCPWalker& walker, const ParticleSet& pset, const TrialWaveFunction& wfn, const QMCHamiltonian& ham, int step) +{ + if(!state.traces_active) return; + + int current_step = (step==-1) ? pset.current_step : step; + if(current_step%state.step_period!=0) return; + + auto& bsi = walker_property_int_buffer; + auto& bsr = walker_property_real_buffer; + auto& bar = walker_particle_real_buffer; + + // collect per-particle walker quantities + size_t nparticles = walker.R.size(); + size_t ndim = walker.R[0].size(); + // per-particle positions (walker.R) + Rtmp.resize(nparticles,ndim); + for(size_t p=0;p::max(); + for(size_t n=0; n class Walker; +class ParticleSet; +class TrialWaveFunction; +class QMCHamiltonian; +using MCPWalker = Walker; + + + +struct WalkerTraceState +{ + bool traces_active; + int step_period; + bool verbose; + + WalkerTraceState() + { + reset(); + step_period = 1; + } + + inline void reset() + { + traces_active = false; + verbose = false; + } +}; + + +class WalkerTraceCollector +{ +public: + std::vector steps; + std::vector energies; + WalkerTraceBuffer walker_property_int_buffer; + WalkerTraceBuffer walker_property_real_buffer; + WalkerTraceBuffer walker_particle_real_buffer; + + std::unordered_set properties_include; + std::vector property_indices; + int energy_index; + + WalkerTraceState state; + +private: + // temporary (contiguous) storage for awful ParticleAttrib<> quantities + Array Rtmp; + Array Stmp; + Array Gtmp; + Array Ltmp; + +public: + WalkerTraceCollector(); + + void startBlock(); + + void collect(const MCPWalker& walker, const ParticleSet& pset, const TrialWaveFunction& wfn, const QMCHamiltonian& ham, int step=-1); + + void checkBuffers(); + +private: + void resetBuffers(); +}; + + + + + +} // namespace qmcplusplus + +#endif diff --git a/src/Estimators/WalkerTraceManagerInput.h b/src/Estimators/WalkerTraceInput.h similarity index 87% rename from src/Estimators/WalkerTraceManagerInput.h rename to src/Estimators/WalkerTraceInput.h index 697cee46f5..4a6c813b01 100644 --- a/src/Estimators/WalkerTraceManagerInput.h +++ b/src/Estimators/WalkerTraceInput.h @@ -7,15 +7,15 @@ // File developed by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory // ////////////////////////////////////////////////////////////////////////////////////// -#ifndef QMCPLUSPLUS_WALKERTRACEMANAGERINPUT_H -#define QMCPLUSPLUS_WALKERTRACEMANAGERINPUT_H +#ifndef QMCPLUSPLUS_WALKERTRACEINPUT_H +#define QMCPLUSPLUS_WALKERTRACEINPUT_H #include "InputSection.h" namespace qmcplusplus { -/** Native representation for WalkerTraceManager input +/** Native representation for walker traces input */ struct WalkerTraceInput : public InputSection { @@ -43,4 +43,4 @@ struct WalkerTraceInput : public InputSection }; } // namespace qmcplusplus -#endif /* WALKERTRACEMANAGERINPUT_H */ +#endif /* WALKERTRACEINPUT_H */ diff --git a/src/Estimators/WalkerTraceManager.cpp b/src/Estimators/WalkerTraceManager.cpp index 56279299bf..f89b22588a 100644 --- a/src/Estimators/WalkerTraceManager.cpp +++ b/src/Estimators/WalkerTraceManager.cpp @@ -9,188 +9,14 @@ // File created by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory ////////////////////////////////////////////////////////////////////////////////////// - #include "WalkerTraceManager.h" -#include "WalkerTraceManagerInput.h" - -#include "OhmmsData/OhmmsElementBase.h" -#include "OhmmsData/AttributeSet.h" - -#include "Particle/Walker.h" -#include "Particle/ParticleSet.h" -#include "QMCWaveFunctions/TrialWaveFunction.h" -#include "QMCHamiltonians/QMCHamiltonian.h" - +#include "WalkerTraceInput.h" +#include "Concurrency/OpenMP.h" namespace qmcplusplus { -using MCPWalker = Walker; - - -////////////////////////////////// -// WalkerTraceCollector methods // -////////////////////////////////// - -WalkerTraceCollector::WalkerTraceCollector() - : properties_include{"R2Accepted","R2Proposed","LocalEnergy","LocalPotential","Kinetic","ElecElec","ElecIon","LocalECP","NonLocalECP"} -{ - state.reset(); - energy_index = -1; - steps.resize(0); - energies.resize(0); - walker_property_int_buffer.label = "walker_property_int"; - walker_property_real_buffer.label = "walker_property_real"; - walker_particle_real_buffer.label = "walker_particle_real"; -} - - -void WalkerTraceCollector::startBlock() -{ - if(!state.traces_active) return; - if (state.verbose) app_log() << "WalkerTraceCollector::startBlock " << std::endl; - resetBuffers(); -} - - -void WalkerTraceCollector::collect(const MCPWalker& walker, const ParticleSet& pset, const TrialWaveFunction& wfn, const QMCHamiltonian& ham, int step) -{ - if(!state.traces_active) return; - - int current_step = (step==-1) ? pset.current_step : step; - if(current_step%state.step_period!=0) return; - - auto& bsi = walker_property_int_buffer; - auto& bsr = walker_property_real_buffer; - auto& bar = walker_particle_real_buffer; - - // collect per-particle walker quantities - size_t nparticles = walker.R.size(); - size_t ndim = walker.R[0].size(); - // per-particle positions (walker.R) - Rtmp.resize(nparticles,ndim); - for(size_t p=0;p::max(); - for(size_t n=0; n -#include "OhmmsPETE/OhmmsArray.h" -#include "Message/Communicate.h" -#include "hdf/hdf_archive.h" - -#include - +#include "WalkerTraceCollector.h" namespace qmcplusplus { -const unsigned int WDMAX = 4; -using WTraceInt = long; -using WTraceReal = OHMMS_PRECISION_FULL; -using WTraceComp = std::complex; -#ifndef QMC_COMPLEX -using WTracePsiVal = WTraceReal; -#else -using WTracePsiVal = WTraceComp; -#endif - - - -struct WalkerQuantityInfo -{ - std::string name; - size_t dimension; - size_t size; - size_t unit_size; - TinyVector shape; - size_t buffer_start; - size_t buffer_end; - - WalkerQuantityInfo(const std::string& name_,size_t unit_size_,size_t buffer_start_,size_t n1=1,size_t n2=0,size_t n3=0,size_t n4=0) - { - name = name_; - unit_size = unit_size_; - buffer_start = buffer_start_; - shape[0] = n1; - shape[1] = n2; - shape[2] = n3; - shape[3] = n4; - - dimension = 0; - size = 1; - for (size_t d=0;d0) - { - dimension++; - size *= shape[d]; - } - buffer_end = buffer_start + size*unit_size; - } -}; - - - - -template -class WalkerTraceBuffer -{ -public: - bool first_collect; - std::string label; - hsize_t hdf_file_pointer; - -private: - size_t quantity_pointer; - std::vector quantity_info; - size_t walker_data_size; - Array buffer; - hsize_t dims[2]; - -public: - WalkerTraceBuffer() - { - label = "?"; - first_collect = true; - walker_data_size = 0; - quantity_pointer = 0; - resetBuffer(); - } - - inline size_t nrows() { return buffer.size(0); } - - inline size_t ncols() { return buffer.size(1); } - - inline void resetBuffer() { buffer.resize(0, buffer.size(1)); } - - inline void resetCollect() - { - if(quantity_pointer!=quantity_info.size()) - throw std::runtime_error("WalkerTraceBuffer quantity_pointer has not been moved through all quantities prior during collect() call."); - first_collect = false; - quantity_pointer = 0; - } - - - inline bool sameAs(const WalkerTraceBuffer& ref) { return buffer.size(1) == ref.buffer.size(1); } - - - inline void collect(const std::string& name, const T& value) - { - size_t irow=0; - if( first_collect ) - { - WalkerQuantityInfo wqi_(name,1,walker_data_size); - quantity_info.push_back(wqi_); - walker_data_size = wqi_.buffer_end; - resetRowSize(walker_data_size); - } - else - { - if(quantity_pointer==0) - makeNewRow(); - irow = buffer.size(0)-1; - } - auto& wqi = quantity_info[quantity_pointer]; - buffer(irow,wqi.buffer_start) = value; - quantity_pointer++; - } - - - template - inline void collect(const std::string& name, Array arr) - { - size_t n1 = arr.size(0); - size_t n2,n3,n4; - n2=n3=n4=0; - if (D>4) - throw std::runtime_error("WalkerTraceBuffer::collect Only arrays up to dimension 4 are currently supported."); - if (D>1) n2 = arr.size(1); - if (D>2) n3 = arr.size(2); - if (D>3) n4 = arr.size(3); - size_t irow=0; - if( first_collect ) - { - WalkerQuantityInfo wqi_(name,1,walker_data_size,n1,n2,n3,n4); - quantity_info.push_back(wqi_); - walker_data_size = wqi_.buffer_end; - resetRowSize(walker_data_size); - } - else - { - if(quantity_pointer==0) - makeNewRow(); - irow = buffer.size(0)-1; - } - auto& wqi = quantity_info[quantity_pointer]; - auto& arr1d = arr.storage(); - for (size_t n=0;n - inline void collect(const std::string& name, Array,D> arr) - { - size_t n1 = arr.size(0); - size_t n2,n3,n4; - n2=n3=n4=0; - if (D>4) - throw std::runtime_error("WalkerTraceBuffer::collect Only arrays up to dimension 4 are currently supported."); - if (D>1) n2 = arr.size(1); - if (D>2) n3 = arr.size(2); - if (D>3) n4 = arr.size(3); - size_t irow=0; - if( first_collect ) - { - WalkerQuantityInfo wqi_(name,2,walker_data_size,n1,n2,n3,n4); - quantity_info.push_back(wqi_); - walker_data_size = wqi_.buffer_end; - resetRowSize(walker_data_size); - } - else - { - if(quantity_pointer==0) - makeNewRow(); - irow = buffer.size(0)-1; - } - auto& wqi = quantity_info[quantity_pointer]; - auto& arr1d = arr.storage(); - size_t n = 0; - for (size_t i=0;i other, size_t i) - { - auto& other_buffer = other.buffer; - if (first_collect) - { - resetRowSize(other_buffer.size(1)); - quantity_info = other.quantity_info; - first_collect = false; - } - else - { - if(buffer.size(1)!=other_buffer.size(1)) - throw std::runtime_error("WalkerTraceBuffer::add_row Row sizes must match."); - makeNewRow(); - } - size_t ib = buffer.size(0)-1; - for(size_t j=0;j 0) - { - f.push(top); - h5d_append(f.top(), "data", file_pointer, buffer.dim(), dims, buffer.data()); - f.pop(); - } - f.flush(); - } - -private: - inline void resetRowSize(size_t row_size) - { - auto nrows = buffer.size(0); - if(nrows==0) - nrows++; - if(nrows!=1) - throw std::runtime_error("WalkerTraceBuffer::reset_rowsize row_size (number of columns) should only be changed during growth of the first row."); - auto buffer_old(buffer); - buffer.resize(nrows,row_size); - std::copy_n(buffer_old.data(), buffer_old.size(), buffer.data()); - if(buffer.size(0)!=1) - throw std::runtime_error("WalkerTraceBuffer::reset_rowsize buffer should contain only a single row upon completion."); - if(buffer.size(1)!=row_size) - throw std::runtime_error("WalkerTraceBuffer::reset_rowsize length of buffer row should match the requested row_size following the reset/udpate."); - } - - inline void makeNewRow() - { - size_t nrows = buffer.size(0); - size_t row_size = buffer.size(1); - if (row_size==0) - throw std::runtime_error("WalkerTraceBuffer::makeNewRow Cannot make a new row of size zero."); - nrows++; - // resizing buffer(type Array) doesn't preserve data. Thus keep old data and copy over - auto buffer_old(buffer); - buffer.resize(nrows, row_size); - std::copy_n(buffer_old.data(), buffer_old.size(), buffer.data()); - } - -}; - - - -struct WalkerTraceState -{ - bool traces_active; - int step_period; - bool verbose; - - WalkerTraceState() - { - reset(); - step_period = 1; - } - - inline void reset() - { - traces_active = false; - verbose = false; - } -}; - - - -template class Walker; -class ParticleSet; -class TrialWaveFunction; -class QMCHamiltonian; -using MCPWalker = Walker; - - - -class WalkerTraceCollector -{ -public: - std::vector steps; - std::vector energies; - WalkerTraceBuffer walker_property_int_buffer; - WalkerTraceBuffer walker_property_real_buffer; - WalkerTraceBuffer walker_particle_real_buffer; - - std::unordered_set properties_include; - std::vector property_indices; - int energy_index; - - WalkerTraceState state; - -private: - // temporary (contiguous) storage for awful ParticleAttrib<> quantities - Array Rtmp; - Array Stmp; - Array Gtmp; - Array Ltmp; - -public: - WalkerTraceCollector(); - - void startBlock(); - - void collect(const MCPWalker& walker, const ParticleSet& pset, const TrialWaveFunction& wfn, const QMCHamiltonian& ham, int step=-1); - - void checkBuffers(); - -private: - void resetBuffers(); -}; - - class WalkerTraceInput; diff --git a/src/QMCDrivers/QMCDriver.cpp b/src/QMCDrivers/QMCDriver.cpp index fc4eb179cb..c0cd542fc9 100644 --- a/src/QMCDrivers/QMCDriver.cpp +++ b/src/QMCDrivers/QMCDriver.cpp @@ -36,7 +36,7 @@ #else using TraceManager = int; #endif -#include "Estimators/WalkerTraceManagerInput.h" +#include "Estimators/WalkerTraceInput.h" #include "Estimators/WalkerTraceManager.h" namespace qmcplusplus diff --git a/src/QMCDrivers/QMCDriverNew.cpp b/src/QMCDrivers/QMCDriverNew.cpp index 4ae992a7ba..ba58b1b1ae 100644 --- a/src/QMCDrivers/QMCDriverNew.cpp +++ b/src/QMCDrivers/QMCDriverNew.cpp @@ -33,7 +33,7 @@ #include "Utilities/Timer.h" #include "Message/UniformCommunicateError.h" #include "EstimatorInputDelegates.h" -#include "Estimators/WalkerTraceManagerInput.h" +#include "Estimators/WalkerTraceInput.h" #include "Estimators/WalkerTraceManager.h" diff --git a/src/QMCDrivers/QMCDriverNew.h b/src/QMCDrivers/QMCDriverNew.h index 67a339719b..d27ee9acbb 100644 --- a/src/QMCDrivers/QMCDriverNew.h +++ b/src/QMCDrivers/QMCDriverNew.h @@ -43,7 +43,7 @@ #include "DriverWalkerTypes.h" #include "TauParams.hpp" #include "Particle/MCCoords.hpp" -#include "Estimators/WalkerTraceManagerInput.h" +#include "Estimators/WalkerTraceInput.h" #include class Communicate; From ea9a8e653851072e90eeae9412f18ddb96019c93 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Mon, 3 Jun 2024 12:13:46 -0400 Subject: [PATCH 40/55] vacuous type class --- src/Estimators/WalkerTraceBuffer.h | 29 +++++++++++--------- src/Estimators/WalkerTraceCollector.cpp | 36 ++++++++++++------------- src/Estimators/WalkerTraceCollector.h | 16 +++++------ src/Estimators/WalkerTraceManager.h | 21 +++++++-------- 4 files changed, 52 insertions(+), 50 deletions(-) diff --git a/src/Estimators/WalkerTraceBuffer.h b/src/Estimators/WalkerTraceBuffer.h index f9e72697cc..ee22b55b2d 100644 --- a/src/Estimators/WalkerTraceBuffer.h +++ b/src/Estimators/WalkerTraceBuffer.h @@ -25,25 +25,28 @@ namespace qmcplusplus { -const unsigned int WDMAX = 4; -using WTraceInt = long; -using WTraceReal = OHMMS_PRECISION_FULL; -using WTraceComp = std::complex; + +struct WTrace +{ + using Int = long; + using Real = OHMMS_PRECISION_FULL; + using Comp = std::complex; #ifndef QMC_COMPLEX -using WTracePsiVal = WTraceReal; + using PsiVal = Real; #else -using WTracePsiVal = WTraceComp; + using PsiVal = Comp; #endif - +}; struct WalkerQuantityInfo { + enum{D0=0,D1,D2,D3,DMAX}; std::string name; size_t dimension; size_t size; size_t unit_size; - TinyVector shape; + TinyVector shape; size_t buffer_start; size_t buffer_end; @@ -52,14 +55,14 @@ struct WalkerQuantityInfo name = name_; unit_size = unit_size_; buffer_start = buffer_start_; - shape[0] = n1; - shape[1] = n2; - shape[2] = n3; - shape[3] = n4; + shape[D0] = n1; + shape[D1] = n2; + shape[D2] = n3; + shape[D3] = n4; dimension = 0; size = 1; - for (size_t d=0;d0) { dimension++; diff --git a/src/Estimators/WalkerTraceCollector.cpp b/src/Estimators/WalkerTraceCollector.cpp index b019a61671..95bef2e6a5 100644 --- a/src/Estimators/WalkerTraceCollector.cpp +++ b/src/Estimators/WalkerTraceCollector.cpp @@ -64,41 +64,41 @@ void WalkerTraceCollector::collect(const MCPWalker& walker, const ParticleSet& p Rtmp.resize(nparticles,ndim); for(size_t p=0;p::max(); + WTrace::Real dr = std::numeric_limits::max(); for(size_t n=0; n steps; - std::vector energies; - WalkerTraceBuffer walker_property_int_buffer; - WalkerTraceBuffer walker_property_real_buffer; - WalkerTraceBuffer walker_particle_real_buffer; + std::vector energies; + WalkerTraceBuffer walker_property_int_buffer; + WalkerTraceBuffer walker_property_real_buffer; + WalkerTraceBuffer walker_particle_real_buffer; std::unordered_set properties_include; std::vector property_indices; @@ -64,10 +64,10 @@ class WalkerTraceCollector private: // temporary (contiguous) storage for awful ParticleAttrib<> quantities - Array Rtmp; - Array Stmp; - Array Gtmp; - Array Ltmp; + Array Rtmp; + Array Stmp; + Array Gtmp; + Array Ltmp; public: WalkerTraceCollector(); diff --git a/src/Estimators/WalkerTraceManager.h b/src/Estimators/WalkerTraceManager.h index fd2a913279..18b8d62f5f 100644 --- a/src/Estimators/WalkerTraceManager.h +++ b/src/Estimators/WalkerTraceManager.h @@ -13,7 +13,6 @@ #ifndef QMCPLUSPLUS_WALKERTRACEMANAGER_H #define QMCPLUSPLUS_WALKERTRACEMANAGER_H -#include #include "WalkerTraceCollector.h" @@ -41,19 +40,19 @@ class WalkerTraceManager bool write_max_data; bool write_med_data; - std::vector> energy_order; + std::vector> energy_order; - WalkerTraceBuffer wmin_property_int_buffer; - WalkerTraceBuffer wmin_property_real_buffer; - WalkerTraceBuffer wmin_particle_real_buffer; + WalkerTraceBuffer wmin_property_int_buffer; + WalkerTraceBuffer wmin_property_real_buffer; + WalkerTraceBuffer wmin_particle_real_buffer; - WalkerTraceBuffer wmax_property_int_buffer; - WalkerTraceBuffer wmax_property_real_buffer; - WalkerTraceBuffer wmax_particle_real_buffer; + WalkerTraceBuffer wmax_property_int_buffer; + WalkerTraceBuffer wmax_property_real_buffer; + WalkerTraceBuffer wmax_particle_real_buffer; - WalkerTraceBuffer wmed_property_int_buffer; - WalkerTraceBuffer wmed_property_real_buffer; - WalkerTraceBuffer wmed_particle_real_buffer; + WalkerTraceBuffer wmed_property_int_buffer; + WalkerTraceBuffer wmed_property_real_buffer; + WalkerTraceBuffer wmed_particle_real_buffer; public: WalkerTraceManager(WalkerTraceInput& inp, bool allow_traces, std::string series_root, Communicate* comm = 0); From 53b43c6ff2609732d62a958925b84b91af288bca Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Mon, 3 Jun 2024 14:32:19 -0400 Subject: [PATCH 41/55] add in-code comments --- src/Estimators/WalkerTraceBuffer.h | 107 +++++++++++++++++------- src/Estimators/WalkerTraceCollector.cpp | 11 ++- src/Estimators/WalkerTraceCollector.h | 32 ++++++- src/Estimators/WalkerTraceManager.cpp | 55 ++++++++---- src/Estimators/WalkerTraceManager.h | 48 ++++++++++- 5 files changed, 198 insertions(+), 55 deletions(-) diff --git a/src/Estimators/WalkerTraceBuffer.h b/src/Estimators/WalkerTraceBuffer.h index ee22b55b2d..c27074f9b5 100644 --- a/src/Estimators/WalkerTraceBuffer.h +++ b/src/Estimators/WalkerTraceBuffer.h @@ -26,39 +26,52 @@ namespace qmcplusplus { +/// Basic data types for walker trace data struct WTrace { - using Int = long; - using Real = OHMMS_PRECISION_FULL; - using Comp = std::complex; + using Int = long; // integer type + using Real = OHMMS_PRECISION_FULL; // real type + using Comp = std::complex; // complex type #ifndef QMC_COMPLEX - using PsiVal = Real; + using PsiVal = Real; // wavefunction type #else - using PsiVal = Comp; + using PsiVal = Comp; // wavefunction type #endif }; +/** Record for an individual walker quantity being traced. + * + * Helper struct for WalkerTraceBuffer. + */ struct WalkerQuantityInfo { - enum{D0=0,D1,D2,D3,DMAX}; - std::string name; - size_t dimension; - size_t size; - size_t unit_size; - TinyVector shape; - size_t buffer_start; - size_t buffer_end; + /// quantity name + std::string name; + /// support up to 4D array quantity + enum{D0=0,D1,D2,D3,DMAX}; + /// array dimension + size_t dimension; + /// total size + size_t size; + /// size of 1 unit of data + size_t unit_size; + /// array shape + TinyVector shape; + /// starting row index in buffer + size_t buffer_start; + /// end range in buffer row + size_t buffer_end; WalkerQuantityInfo(const std::string& name_,size_t unit_size_,size_t buffer_start_,size_t n1=1,size_t n2=0,size_t n3=0,size_t n4=0) { name = name_; unit_size = unit_size_; buffer_start = buffer_start_; - shape[D0] = n1; - shape[D1] = n2; - shape[D2] = n3; - shape[D3] = n4; + shape[D0] = n1; + shape[D1] = n2; + shape[D2] = n3; + shape[D3] = n4; dimension = 0; size = 1; @@ -74,20 +87,38 @@ struct WalkerQuantityInfo - +/** Data buffer for walker trace quantities. + * + * Each row in the buffer contains all quantities for one walker from a single step. + * Rows are added throughout an MC block. + * See WalkerTraceCollector::collect() + * + * Buffer data is written to HDF at the end of each MC block. + * See WalkerTraceManager::writeBuffers() + */ template class WalkerTraceBuffer { public: - bool first_collect; - std::string label; - hsize_t hdf_file_pointer; + /// label for this data in HDF file + std::string label; + /// marks first WalkerTraceCollector::collect() call + bool first_collect; + /// HDF file pointer + hsize_t hdf_file_pointer; private: - size_t quantity_pointer; + /// index of current quantity during WalkerTraceCollector::collect() + size_t quantity_pointer; + /** buffer row location data for each walker quantity + * used to populate "data_layout" field in HDF file + */ std::vector quantity_info; + /// total size of walker data stored in a buffer row size_t walker_data_size; + /// the walker data buffer itself Array buffer; + /// array dimensions used in HDF file write hsize_t dims[2]; public: @@ -100,12 +131,16 @@ class WalkerTraceBuffer resetBuffer(); } + /// current number of rows in the data buffer inline size_t nrows() { return buffer.size(0); } + /// current number of columns in the data buffer (row size) inline size_t ncols() { return buffer.size(1); } + /// resize the buffer to zero inline void resetBuffer() { buffer.resize(0, buffer.size(1)); } + /// reset member variables at end of each WalkerTraceCollector::collect() call inline void resetCollect() { if(quantity_pointer!=quantity_info.size()) @@ -114,32 +149,34 @@ class WalkerTraceBuffer quantity_pointer = 0; } - + /// compare row size of this buffer to another one inline bool sameAs(const WalkerTraceBuffer& ref) { return buffer.size(1) == ref.buffer.size(1); } - + /// collect data for a single walker quantity of scalar type into the current buffer row inline void collect(const std::string& name, const T& value) { size_t irow=0; if( first_collect ) - { + {// cache walker quantity info on first collect WalkerQuantityInfo wqi_(name,1,walker_data_size); quantity_info.push_back(wqi_); walker_data_size = wqi_.buffer_end; resetRowSize(walker_data_size); } else - { + {// make a new buffer row if needed if(quantity_pointer==0) makeNewRow(); irow = buffer.size(0)-1; } + // place the scalar walker quantity into the current buffer row auto& wqi = quantity_info[quantity_pointer]; buffer(irow,wqi.buffer_start) = value; quantity_pointer++; } + /// collect data for a single walker quantity of array type into the current buffer row template inline void collect(const std::string& name, Array arr) { @@ -153,18 +190,19 @@ class WalkerTraceBuffer if (D>3) n4 = arr.size(3); size_t irow=0; if( first_collect ) - { + {// cache walker quantity info on first collect WalkerQuantityInfo wqi_(name,1,walker_data_size,n1,n2,n3,n4); quantity_info.push_back(wqi_); walker_data_size = wqi_.buffer_end; resetRowSize(walker_data_size); } else - { + {// make a new buffer row if needed if(quantity_pointer==0) makeNewRow(); irow = buffer.size(0)-1; } + // place the array walker quantity into the current buffer row auto& wqi = quantity_info[quantity_pointer]; auto& arr1d = arr.storage(); for (size_t n=0;n inline void collect(const std::string& name, Array,D> arr) { @@ -186,18 +225,19 @@ class WalkerTraceBuffer if (D>3) n4 = arr.size(3); size_t irow=0; if( first_collect ) - { + {// cache walker quantity info on first collect WalkerQuantityInfo wqi_(name,2,walker_data_size,n1,n2,n3,n4); quantity_info.push_back(wqi_); walker_data_size = wqi_.buffer_end; resetRowSize(walker_data_size); } else - { + {// make a new buffer row if needed if(quantity_pointer==0) makeNewRow(); irow = buffer.size(0)-1; } + // place the complex array walker quantity into the current buffer row auto& wqi = quantity_info[quantity_pointer]; auto& arr1d = arr.storage(); size_t n = 0; @@ -210,6 +250,7 @@ class WalkerTraceBuffer } + /// add a data row from another buffer to this one inline void addRow(WalkerTraceBuffer other, size_t i) { auto& other_buffer = other.buffer; @@ -231,6 +272,7 @@ class WalkerTraceBuffer } + /// write a summary of quantities in the buffer inline void writeSummary(std::string pad = " ") { std::string pad2 = pad + " "; @@ -247,6 +289,7 @@ class WalkerTraceBuffer app_log() << pad << "end WalkerTraceBuffer(" << label << ")" << std::endl; } + /// write the data_layout for all walker quantities in the HDF file inline void registerHDFData(hdf_archive& f) { auto& top = label; @@ -271,12 +314,14 @@ class WalkerTraceBuffer } + /// write the buffer data into the HDF file inline void writeHDF(hdf_archive& f) { writeHDF(f,hdf_file_pointer); } + /// write the buffer data into the HDF file inline void writeHDF(hdf_archive& f, hsize_t& file_pointer) { auto& top = label; @@ -292,6 +337,7 @@ class WalkerTraceBuffer } private: + /// make space as quantities are added to the buffer for the first time inline void resetRowSize(size_t row_size) { auto nrows = buffer.size(0); @@ -308,6 +354,7 @@ class WalkerTraceBuffer throw std::runtime_error("WalkerTraceBuffer::reset_rowsize length of buffer row should match the requested row_size following the reset/udpate."); } + /// allocate a full new row at the end of the buffer inline void makeNewRow() { size_t nrows = buffer.size(0); diff --git a/src/Estimators/WalkerTraceCollector.cpp b/src/Estimators/WalkerTraceCollector.cpp index 95bef2e6a5..f70e2633cc 100644 --- a/src/Estimators/WalkerTraceCollector.cpp +++ b/src/Estimators/WalkerTraceCollector.cpp @@ -30,8 +30,10 @@ WalkerTraceCollector::WalkerTraceCollector() { state.reset(); energy_index = -1; + // empty walker steps and energy vectors for the MC block steps.resize(0); energies.resize(0); + // label the buffers for HDF file write walker_property_int_buffer.label = "walker_property_int"; walker_property_real_buffer.label = "walker_property_real"; walker_particle_real_buffer.label = "walker_particle_real"; @@ -40,16 +42,17 @@ WalkerTraceCollector::WalkerTraceCollector() void WalkerTraceCollector::startBlock() { - if(!state.traces_active) return; + if(!state.traces_active) return; // no-op for driver if traces are inactive if (state.verbose) app_log() << "WalkerTraceCollector::startBlock " << std::endl; - resetBuffers(); + resetBuffers(); // resize buffers to zero rows } void WalkerTraceCollector::collect(const MCPWalker& walker, const ParticleSet& pset, const TrialWaveFunction& wfn, const QMCHamiltonian& ham, int step) { - if(!state.traces_active) return; + if(!state.traces_active) return; // no-op for driver if traces are inactive + // only collect walker data at steps matching the period (default 1) int current_step = (step==-1) ? pset.current_step : step; if(current_step%state.step_period!=0) return; @@ -151,9 +154,11 @@ void WalkerTraceCollector::collect(const MCPWalker& walker, const ParticleSet& p void WalkerTraceCollector::resetBuffers() { if (state.verbose) app_log() << "WalkerTraceCollector::reset_buffers"<; +/// Helper struct holding data transferred from WalkerTraceManager to WalkerTraceCollector following input read struct WalkerTraceState { + /// whether traces are active in the current driver bool traces_active; + /// period between MC steps for data collection int step_period; + /// controls verbosity of log file writes bool verbose; WalkerTraceState() @@ -47,38 +51,64 @@ struct WalkerTraceState }; +/** Crowd-level resource for walker trace collection. + * + * Contains data buffers for walker properties and walker particle data. + * Data buffers are resized to zero at the start of an MC block. + * Data for all walkers is collected into the buffers each MC step in an MC block. + * This class is not responsible for I/O. + */ class WalkerTraceCollector { public: - std::vector steps; + /// MC step information for each walker throughout the MC block + std::vector steps; + /// LocalEnergy information for each walker throughout the MC block std::vector energies; + /// buffer containing integer walker properties WalkerTraceBuffer walker_property_int_buffer; + /// buffer containing real-valued walker properties WalkerTraceBuffer walker_property_real_buffer; + /// buffer containing per-particle walker data WalkerTraceBuffer walker_particle_real_buffer; + /// ParticleSet::PropertyList quantities to include std::unordered_set properties_include; + /// indices in ParticleSet::PropertyList for included quantities std::vector property_indices; + /// location of LocalEnergy in ParticleSet::PropertyList int energy_index; + /// state data set by WalkerTraceManager WalkerTraceState state; private: // temporary (contiguous) storage for awful ParticleAttrib<> quantities + /// tmp storage for walker positions Array Rtmp; + /// tmp storage for walker spins Array Stmp; + /// tmp storage for walker wavefunction gradients Array Gtmp; + /// tmp storage for walker wavefunciton laplacians Array Ltmp; public: WalkerTraceCollector(); + /// resize buffers to zero rows at beginning of each MC block void startBlock(); + /// collect all data for one walker into the data buffers void collect(const MCPWalker& walker, const ParticleSet& pset, const TrialWaveFunction& wfn, const QMCHamiltonian& ham, int step=-1); + /** Check that all buffers have the same number of rows. + * This ensures that the full data for a given walker can be reconstructed due to enforced data alignment in the buffers. + */ void checkBuffers(); private: + /// resize buffers to zero rows void resetBuffers(); }; diff --git a/src/Estimators/WalkerTraceManager.cpp b/src/Estimators/WalkerTraceManager.cpp index f89b22588a..f5797f19fb 100644 --- a/src/Estimators/WalkerTraceManager.cpp +++ b/src/Estimators/WalkerTraceManager.cpp @@ -23,10 +23,11 @@ WalkerTraceManager::WalkerTraceManager(WalkerTraceInput& inp, bool allow_traces, state.reset(); communicator = comm; file_root = series_root; - bool method_allows_traces = allow_traces; + bool driver_allows_traces = allow_traces; // driver allows traces or not - bool traces_requested = inp.present; - state.traces_active = traces_requested && method_allows_traces; + bool traces_requested = inp.present; // xml input present or not + // determine whether walker traces will be active + state.traces_active = traces_requested && driver_allows_traces; if (state.traces_active) { @@ -34,10 +35,11 @@ WalkerTraceManager::WalkerTraceManager(WalkerTraceInput& inp, bool allow_traces, { app_log() << "\n WalkerTraceManager::put() " << std::endl; app_log() << " traces requested : " << traces_requested << std::endl; - app_log() << " method allows traces : " << method_allows_traces << std::endl; + app_log() << " driver allows traces : " << driver_allows_traces << std::endl; app_log() << " traces active : " << state.traces_active << std::endl; app_log() << std::endl; } + // retrieve input data state.step_period = inp.get("step_period"); state.verbose = inp.get("verbose"); bool qtiles = inp.get("qtiles"); @@ -47,18 +49,22 @@ WalkerTraceManager::WalkerTraceManager(WalkerTraceInput& inp, bool allow_traces, write_med_data = inp.get("median") && qtiles; } + // label min energy walker buffers for HDF file write wmin_property_int_buffer.label = "wmin_property_int"; wmin_property_real_buffer.label = "wmin_property_real"; wmin_particle_real_buffer.label = "wmin_particle_real"; + // label max energy walker buffers for HDF file write wmax_property_int_buffer.label = "wmax_property_int"; wmax_property_real_buffer.label = "wmax_property_real"; wmax_particle_real_buffer.label = "wmax_particle_real"; + // label median energy walker buffers for HDF file write wmed_property_int_buffer.label = "wmed_property_int"; wmed_property_real_buffer.label = "wmed_property_real"; wmed_particle_real_buffer.label = "wmed_particle_real"; + // walker quantity information ("data_layout") has not be put in the HDF file yet registered_hdf = false; } @@ -74,42 +80,46 @@ WalkerTraceCollector* WalkerTraceManager::makeCollector() void WalkerTraceManager::startRun(std::vector& collectors) { - if (!state.traces_active) return; + if (!state.traces_active) return; // no-op for driver if traces are inactive if (state.verbose) app_log() << "WalkerTraceManager::startRun " << std::endl; + // transfer step_period, verbosity, etc settings to trace collectors for (auto& tc: collectors) tc->state = state; + // check data size consistency among the trace collector buffers checkCollectors(collectors); + // open the traces file openFile(collectors); } void WalkerTraceManager::stopRun() { - if (!state.traces_active) return; + if (!state.traces_active) return; // no-op for driver if traces are inactive if (state.verbose) app_log() << "WalkerTraceManager::stopRun " << std::endl; + // close the traces file closeFile(); } void WalkerTraceManager::writeBuffers(std::vector& collectors) { - if (!state.traces_active) return; + if (!state.traces_active) return; // no-op for driver if traces are inactive if (state.verbose) app_log() << "WalkerTraceManager::writeBuffers "<& collec // collect energy information and extract info from min/max/median energy walkers if(write_min_data || write_max_data || write_med_data) { + // gather per energy and step data for all walker throughout the MC block for (size_t c=0; c& collec for (size_t r=0; r& collect if (state.verbose) app_log() << "WalkerTraceManager::openHDFFile " << std::endl; if (collectors.size() == 0) throw std::runtime_error("WalkerTraceManager::openHDFFile no trace collectors exist, cannot open file"); + // each rank opens a wtraces.h5 file int nprocs = communicator->size(); int rank = communicator->rank(); std::array ptoken; std::string file_name = file_root; if (nprocs > 1) - { + {// extend the file name to include processor/rank information int length{0}; if (nprocs > 10000) length = std::snprintf(ptoken.data(), ptoken.size(), ".p%05d", rank); @@ -248,7 +262,9 @@ void WalkerTraceManager::openHDFFile(std::vector& collect } file_name += ".wtraces.h5"; if (state.verbose) app_log() << "WalkerTraceManager::openHDFFile opening traces hdf file " << file_name << std::endl; + // create the hdf archive hdf_file = std::make_unique(); + // open the file bool successful = hdf_file->create(file_name); if (!successful) throw std::runtime_error("WalkerTraceManager::openHDFFile failed to open hdf file " + file_name); @@ -260,31 +276,34 @@ void WalkerTraceManager::writeBuffersHDF(std::vector& col if (state.verbose) app_log() << "WalkerTraceManager::writeBuffersHDF " << std::endl; WalkerTraceCollector& tc_lead = *collectors[0]; if(!registered_hdf) - { + {// write walker quantity information ("data_layout") for each buffer in the HDF file + // create data_layout for all-walker buffers tc_lead.walker_property_int_buffer.registerHDFData(*hdf_file); tc_lead.walker_property_real_buffer.registerHDFData(*hdf_file); if(write_particle_data) tc_lead.walker_particle_real_buffer.registerHDFData(*hdf_file); if(write_min_data) - { + {// create data_layout for min energy walker buffers wmin_property_int_buffer.registerHDFData(*hdf_file); wmin_property_real_buffer.registerHDFData(*hdf_file); wmin_particle_real_buffer.registerHDFData(*hdf_file); } if(write_max_data) - { + {// create data_layout for max energy walker buffers wmax_property_int_buffer.registerHDFData(*hdf_file); wmax_property_real_buffer.registerHDFData(*hdf_file); wmax_particle_real_buffer.registerHDFData(*hdf_file); } if(write_med_data) - { + {// create data_layout for median energy walker buffers wmed_property_int_buffer.registerHDFData(*hdf_file); wmed_property_real_buffer.registerHDFData(*hdf_file); wmed_particle_real_buffer.registerHDFData(*hdf_file); } + // walker quantity information ("data_layout") has now been added to HDF, do not repeat registered_hdf = true; } + // write data for all-walker buffers to HDF for (int ip = 0; ip < collectors.size(); ++ip) { WalkerTraceCollector& tc = *collectors[ip]; @@ -294,19 +313,19 @@ void WalkerTraceManager::writeBuffersHDF(std::vector& col tc.walker_particle_real_buffer.writeHDF(*hdf_file, tc_lead.walker_particle_real_buffer.hdf_file_pointer); } if(write_min_data) - { + {// write data for min energy walker buffers to HDF wmin_property_int_buffer.writeHDF(*hdf_file); wmin_property_real_buffer.writeHDF(*hdf_file); wmin_particle_real_buffer.writeHDF(*hdf_file); } if(write_max_data) - { + {// write data for max energy walker buffers to HDF wmax_property_int_buffer.writeHDF(*hdf_file); wmax_property_real_buffer.writeHDF(*hdf_file); wmax_particle_real_buffer.writeHDF(*hdf_file); } if(write_med_data) - { + {// write data for median energy walker buffers to HDF wmed_property_int_buffer.writeHDF(*hdf_file); wmed_property_real_buffer.writeHDF(*hdf_file); wmed_particle_real_buffer.writeHDF(*hdf_file); diff --git a/src/Estimators/WalkerTraceManager.h b/src/Estimators/WalkerTraceManager.h index 18b8d62f5f..4ae983e8c1 100644 --- a/src/Estimators/WalkerTraceManager.h +++ b/src/Estimators/WalkerTraceManager.h @@ -23,61 +23,103 @@ namespace qmcplusplus class WalkerTraceInput; +/** Driver-level resource for walker trace collection. + * + * This class manages the HDF file (open/close/write). + * Walker buffer data from all crowd-level WalkerTraceCollectors are written + * to the HDF file at the end of each MC block. + * + * Just prior to the write, this class examines the distribution of walker + * energies on its rank for each MC step in the MC block, identifies the + * minimum/maximum/median energy walkers and buffers their full data + * (including per-particle information) for the write. + * This data corresponds to walker information at specific quantiles of the + * energy distribution. + * See WalkerTraceManager::writeBuffers() + * + * Writing per-particle information for all walkers is optional, as is + * writing data for the minimum/maximum/median energy walkers. + * Scalar "property" data for each walker is always written. + */ class WalkerTraceManager { public: WalkerTraceState state; private: + /// file prefix for the current driver std::string file_root; Communicate* communicator; + /// access to HDF file std::unique_ptr hdf_file; + /// whether walker quantity data ("data_layout") has been recorded in HDF bool registered_hdf; - // new walker buffers + /// whether to write per-particle data for all walkers bool write_particle_data; + /// whether to write full data for the minimum energy walker at each step bool write_min_data; + /// whether to write full data for the maximum energy walker at each step bool write_max_data; + /// whether to write full data for the median energy walker at each step bool write_med_data; + /// used to sort energy information for identifying walkers by energy quantile std::vector> energy_order; + /// buffer containing integer properties for the minimum energy walkers WalkerTraceBuffer wmin_property_int_buffer; + /// buffer containing real-valued properties for the minimum energy walkers WalkerTraceBuffer wmin_property_real_buffer; + /// buffer containing per-particle properties for the minimum energy walkers WalkerTraceBuffer wmin_particle_real_buffer; + /// buffer containing integer properties for the maximum energy walkers WalkerTraceBuffer wmax_property_int_buffer; + /// buffer containing real-valued properties for the maximum energy walkers WalkerTraceBuffer wmax_property_real_buffer; + /// buffer containing per-particle properties for the maximum energy walkers WalkerTraceBuffer wmax_particle_real_buffer; + /// buffer containing integer properties for the median energy walkers WalkerTraceBuffer wmed_property_int_buffer; + /// buffer containing real-valued properties for the median energy walkers WalkerTraceBuffer wmed_property_real_buffer; + /// buffer containing per-particle properties for the median energy walkers WalkerTraceBuffer wmed_particle_real_buffer; public: WalkerTraceManager(WalkerTraceInput& inp, bool allow_traces, std::string series_root, Communicate* comm = 0); + /// create a WalkerTraceCollector (legacy drivers only, "cloning" style) WalkerTraceCollector* makeCollector(); + /// open the traces file and check consistency of the collectors at the start of a run void startRun(std::vector& collectors); + /// close the traces file at the end of a run void stopRun(); - //write buffered trace data to file + /// collect min/max/median walker data and write buffered walker trace data to file void writeBuffers(std::vector& collectors); private: + /// check consistency of walker buffer row sizes void checkCollectors(std::vector& collectors); + /// open the traces file void openFile(std::vector& collectors); + /// close the traces file void closeFile(); - //hdf file operations + /// open the traces file (HDF format) void openHDFFile(std::vector& collectors); + /// write data buffers to the traces file (HDF format) void writeBuffersHDF(std::vector& collectors); + /// close the traces file (HDF format) void closeHDFFile(); }; From dc0186315c8a4a19e0e8e0d0289820c0dd3955e1 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Mon, 3 Jun 2024 16:24:05 -0400 Subject: [PATCH 42/55] unit test for WalkerTraceCollector --- src/Estimators/tests/CMakeLists.txt | 1 + .../tests/test_WalkerTraceCollector.cpp | 130 ++++++++++++++++++ src/Estimators/tests/test_trace_manager.cpp | 2 +- 3 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 src/Estimators/tests/test_WalkerTraceCollector.cpp diff --git a/src/Estimators/tests/CMakeLists.txt b/src/Estimators/tests/CMakeLists.txt index 6b411561c4..ec90abd61a 100644 --- a/src/Estimators/tests/CMakeLists.txt +++ b/src/Estimators/tests/CMakeLists.txt @@ -29,6 +29,7 @@ set(SRCS test_manager.cpp test_EstimatorManagerNew.cpp test_trace_manager.cpp + test_WalkerTraceCollector.cpp EstimatorTesting.cpp GenerateRandomParticleSets.cpp test_SpinDensityInput.cpp diff --git a/src/Estimators/tests/test_WalkerTraceCollector.cpp b/src/Estimators/tests/test_WalkerTraceCollector.cpp new file mode 100644 index 0000000000..8090eb7fc5 --- /dev/null +++ b/src/Estimators/tests/test_WalkerTraceCollector.cpp @@ -0,0 +1,130 @@ +////////////////////////////////////////////////////////////////////////////////////// +// This file is distributed under the University of Illinois/NCSA Open Source License. +// See LICENSE file in top directory for details. +// +// Copyright (c) 2024 QMCPACK developers. +// +// File developed by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory +// +// File created by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory +////////////////////////////////////////////////////////////////////////////////////// + + +#include "catch.hpp" + +#include "Message/Communicate.h" +#include "QMCHamiltonians/QMCHamiltonian.h" +#include "Particle/tests/MinimalParticlePool.h" +#include "QMCHamiltonians/tests/MinimalHamiltonianPool.h" +#include "QMCWaveFunctions/tests/MinimalWaveFunctionPool.h" +#include "Utilities/ResourceCollection.h" +#include "Utilities/ProjectData.h" + +#include "Estimators/WalkerTraceCollector.h" + + +namespace qmcplusplus +{ + +TEST_CASE("WalkerTraceCollector::collect", "[estimators]") +{ + std::cout <<"\n\n=======================================================\n"; + std::cout <<"test WalkerTraceCollector::collect\n"; + + ProjectData test_project("test", ProjectData::DriverVersion::BATCH); + Communicate* comm = OHMMS::Controller; + + + auto particle_pool = MinimalParticlePool::make_diamondC_1x1x1(comm); + auto wavefunction_pool = + MinimalWaveFunctionPool::make_diamondC_1x1x1(test_project.getRuntimeOptions(), comm, particle_pool); + auto& pset = *(particle_pool.getParticleSet("e")); + // This is where the pset properties "properies" gain the different hamiltonian operator values. + auto hamiltonian_pool = MinimalHamiltonianPool::make_hamWithEE(comm, particle_pool, wavefunction_pool); + + auto& twf = *(wavefunction_pool.getWaveFunction("wavefunction")); + auto& ham = *(hamiltonian_pool.getPrimary()); + + // setup data structures for multiple walkers + + UPtrVector hams; + UPtrVector twfs; + std::vector psets; + + int num_walkers = 4; + int num_electrons = particle_pool.getParticleSet("e")->getTotalNum(); + int num_ions = particle_pool.getParticleSet("ion")->getTotalNum(); + + for (int iw = 0; iw < num_walkers; ++iw) + { + psets.emplace_back(pset); + psets.back().randomizeFromSource(*particle_pool.getParticleSet("ion")); + twfs.emplace_back(twf.makeClone(psets.back())); + hams.emplace_back(hamiltonian_pool.getPrimary()->makeClone(psets.back(), *twfs.back())); + } + + using MCPWalker = Walker; + + std::vector walkers(num_walkers, MCPWalker(pset.getTotalNum())); + + for (auto& walker : walkers) + { + walker.R = pset.R; + walker.spins = pset.spins; + walker.Properties = pset.Properties; + walker.registerData(); + walker.DataSet.allocate(); + } + + WalkerTraceCollector tc; + tc.state.traces_active = true; + tc.state.step_period = 1; + + auto& bsi = tc.walker_property_int_buffer; + auto& bsr = tc.walker_property_real_buffer; + auto& bpr = tc.walker_particle_real_buffer; + + CHECK(bsi.nrows() == 0); + CHECK(bsr.nrows() == 0); + CHECK(bpr.nrows() == 0); + CHECK(bsi.ncols() == 0); + CHECK(bsr.ncols() == 0); + CHECK(bpr.ncols() == 0); + + int step=0; + tc.collect(walkers[0], psets[0], *(twfs[0]), *(hams[0]), step); + + CHECK(bsi.nrows() == 1); + CHECK(bsr.nrows() == 1); + CHECK(bpr.nrows() == 1); + CHECK(bsi.ncols() == 4); + CHECK(bsr.ncols() == 13); + CHECK(bpr.ncols() == 56); + + for (size_t iw=1; iw Date: Tue, 4 Jun 2024 02:13:33 -0400 Subject: [PATCH 43/55] add manual entry --- docs/methods.rst | 247 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 247 insertions(+) diff --git a/docs/methods.rst b/docs/methods.rst index d54e7e35c2..5660957b93 100644 --- a/docs/methods.rst +++ b/docs/methods.rst @@ -1897,4 +1897,251 @@ declaration to ensure correct sampling: a new all-electron configuration, at which point the action is computed and the move is either accepted or rejected. + + +.. _walker_traces + +Walker Data Traces +================== + +Detailed per-walker information can be written to HDF5 files for VMC or DMC by +including the XML element. This includes the LocalEnergy and +its components for each walker from each MC step. By default, more detailed +particle-level information (e.g. electron coordinates) is also written for the +lowest, highest, and median energy walkers at each MC step (modest disk usage). +Optionally, particle-level information can also be written for all walkers, +potentially requiring a huge amount of disk space. + +**Input specification** + +The default walker data tracing functionality is enabled by including the + XML element (once) just before the QMC driver sections, +for example: + +:: + + + + 256 + 100 + 200 + 10 + 3 + 0.3 + yes + + + 256 + 40 + 800 + 20 + 0.01 + + + + +Optional XML attributes enable finer control over the behavior: + +.. table:: + + +------------------+--------------+--------------+-------------+----------------------------------------------------+ + | **Name** | **Datatype** | **Values** | **Default** | **Description** | + +==================+==============+==============+=============+====================================================+ + | ``step_period`` | integer | :math:`> 0` | 1 | Collect walker data every step_period MC steps | + +------------------+--------------+--------------+-------------+----------------------------------------------------+ + | ``particle`` | text | yes,no | no | Write particle data for all walkers | + +------------------+--------------+--------------+-------------+----------------------------------------------------+ + | ``qtiles`` | text | yes,no | yes | Write full data for min/max/median energy walkers | + +------------------+--------------+--------------+-------------+----------------------------------------------------+ + | ``min`` | text | yes,no | yes | Enable/disable write for min energy walker data | + +------------------+--------------+--------------+-------------+----------------------------------------------------+ + | ``max`` | text | yes,no | yes | Enable/disable write for max energy walker data | + +------------------+--------------+--------------+-------------+----------------------------------------------------+ + | ``median`` | text | yes,no | yes | Enable/disable write for median energy walker data | + +------------------+--------------+--------------+-------------+----------------------------------------------------+ + | ``verbose`` | text | yes,no | no | Write more log file information | + +------------------+--------------+--------------+-------------+----------------------------------------------------+ + + +Additional information: + +- ``step_period``: By default, data for each walker is collected every MC + step, corresponding to step_period=1. A sub-sampling of the walker + data may be obtained instead by setting step_period>1. For example, + with step_period=5, walker data is collected every 5th MC step. + +- ``particle``: This controls whether per-particle data is written to + the traces HDF files along with scalar walker properties. These data + comprise: electron coordinates, spin coordinates (spinor runs only), + per-particle wavefunction gradients, and per-particle wavefunction + laplacian values. + +- ``qtiles``: Write out full (scalar and per-particle) data for walkers + at specific quantiles of the local energy distribution. Currently, + these quantiles are the minimum, maximum, and median. + +- ``min``: Selectively disable writing data for the minimum energy + walkers. Active only if qtiles=yes. + +- ``max``: Selectively disable writing data for the maximum energy + walkers. Active only if qtiles=yes. + +- ``median``: Selectively disable writing data for the median energy + walkers. Active only if qtiles=yes. + +- ``verbose``: If "yes", write function-call information related to + the walker traces functionality. This option is mainly intended + for developers, as it is of little use in practical runs. + + +**Output files** + +The HDF5 files created by the walker traces functionality have the extension \*.wtraces.h5. +For each VMC or DMC section, one of these files is written for every MPI rank in the run. + +For the example XML inputs shown above, QMCPACK run on 6 MPI ranks would produce (at least) +the following output data files: + +:: + + qmc.s000.scalar.dat + qmc.s000.stat.h5 + qmc.s000.p000.wtraces.h5 + qmc.s000.p001.wtraces.h5 + qmc.s000.p002.wtraces.h5 + qmc.s000.p003.wtraces.h5 + qmc.s000.p004.wtraces.h5 + qmc.s000.p005.wtraces.h5 + + qmc.s001.scalar.dat + qmc.s001.dmc.dat + qmc.s001.stat.h5 + qmc.s001.p000.wtraces.h5 + qmc.s001.p001.wtraces.h5 + qmc.s001.p002.wtraces.h5 + qmc.s001.p003.wtraces.h5 + qmc.s001.p004.wtraces.h5 + qmc.s001.p005.wtraces.h5 + + +A single wtraces.h5 file has several walker data buffers (names with underscores below): + +:: + + # scalar (int/real) data for all walkers + walker_property_int walker_property_real + + # scalar and per-particle data for min energy walkers + wmin_property_int wmin_property_real wmin_particle_real + + # scalar and per-particle data for max energy walkers + wmax_property_int wmax_property_real wmax_particle_real + + # scalar and per-particle data for median energy walkers + wmed_property_int wmed_property_real wmed_particle_real + + +Each data buffer contains packed walker data in the form of a large 2D array ("data" below): + +:: + + >h5ls qmc.s000.p000.wtraces.h5/walker_property_int + data Dataset {512000/Inf, 4} + data_layout Group + + >h5ls qmc.s000.p000.wtraces.h5/walker_property_real + data Dataset {512000/Inf, 15} + data_layout Group + + +Each row in the 2D data array/buffer contains data for a single walker at a single MC step. +In this case, 256 walkers were advanced through 200\*10=2000 steps for 512000 row entries total. + +The location of each particular walker quantity in each row is listed in "data_layout": + +:: + + >h5ls qmc.s000.p000.wtraces.h5/walker_property_int/data_layout + id Group # unique walker id + parent_id Group # id of parent (DMC branching) + step Group # MC step number + age Group # walker "age" + + >h5ls qmc.s000.p000.wtraces.h5/walker_property_real/data_layout + weight Group # statistical weight of the walker + LocalEnergy Group # the local (total) energy + Kinetic Group # kinetic energy + LocalPotential Group # full potential energy (all terms) + ElecElec Group # electron-electron energy + LocalECP Group # energy for local channel of ECP + NonLocalECP Group # energy for non-local channels of ECP + logpsi Group # log of wavefunction modulus + phase Group # wavefunction phase + dlogpsi2 Group # squared gradient of wavefunction log-modulus + dphase2 Group # squared gradient of wavefunction phase + dr_node_min Group # estimate of min distance to wfn node along any dimension + multiplicity Group # branching multiplicity (DMC only) + R2Accepted Group # average diffusion of accepted MC moves + R2Proposed Group # average diffusion of proposed MC moves + +From this we can see, e.g., that the value for the MC "step" is stored at column +index 0 in walker_property_int/data and the LocalEnergy is stored at column index 6 +in walker_property_real/data: + +:: + + >h5ls -d qmc.s000.p000.wtraces.h5/walker_property_int/data_layout/step/index_start + index_start Dataset {SCALAR} + Data: + (0) 0 + + >h5ls -d qmc.s000.p000.wtraces.h5/walker_property_real/data_layout/LocalEnergy/index_start + index_start Dataset {SCALAR} + Data: + (0) 6 + + +The per-particle data is arranged similarly: + +:: + + >h5ls -d qmc_trace_dmc_legacy.s000.p000.wtraces.h5/wmin_particle_real/data_layout + R Group # electron coordinates + G Group # wavefunction gradient + L Group # wavefunction laplacian (per-particle) + + +However, more information is required in the data_layout to fully specify the location and +shape of the particle-level array data (simplified view for a run with 8 electrons and a +real-valued wavefunction): + +:: + + >h5ls -d qmc.s000.p000.wtraces.h5/wmin_particle_real/data_layout/R + index_start 0 # data starts at column index 0 + index_end 24 # data ends at column index 24 + dimension 2 # array is 2-dimensional + size 24 # array has 24 elements total + shape 8, 3, 0, 0 # array has shape 8x3 + unit_size 1 # each unit of data stored as 1 real value + + >h5ls -d qmc.s000.p000.wtraces.h5/wmin_particle_real/data_layout/G + index_start 24 # data starts at column index 24 + index_end 48 # data ends at column index 48 + dimension 2 # array is 2-dimensional + size 24 # array has 24 elements total + shape 8, 3, 0, 0 # array has shape 8x3 + unit_size 1 # data stored as single real values (2 if complex) + + >h5ls -d qmc.s000.p000.wtraces.h5/wmin_particle_real/data_layout/L + index_start 48 # data starts at column index 48 + index_end 56 # data ends at column index 56 + dimension 1 # array is 1-dimensional + size 8 # array has 8 elements total + shape 8, 0, 0, 0 # array has linear shape, length 8 + unit_size 1 # data stored as single real values (2 if complex) + + + + .. bibliography:: /bibs/methods.bib From 949193330ad3ac9e477a8fbee78effd0f99d3a18 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Tue, 4 Jun 2024 05:28:20 -0400 Subject: [PATCH 44/55] better guards --- docs/methods.rst | 6 +++--- src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp | 3 ++- src/QMCDrivers/QMCDriver.cpp | 1 + src/QMCDrivers/QMCDriverNew.cpp | 13 +++++++++++++ src/QMCDrivers/QMCDriverNew.h | 2 +- src/QMCDrivers/QMCUpdateBase.cpp | 3 ++- src/QMCDrivers/VMC/VMCUpdatePbyP.cpp | 3 ++- 7 files changed, 24 insertions(+), 7 deletions(-) diff --git a/docs/methods.rst b/docs/methods.rst index 5660957b93..5c7eafdab8 100644 --- a/docs/methods.rst +++ b/docs/methods.rst @@ -1905,7 +1905,7 @@ Walker Data Traces ================== Detailed per-walker information can be written to HDF5 files for VMC or DMC by -including the XML element. This includes the LocalEnergy and +including the XML element. This includes the LocalEnergy and its components for each walker from each MC step. By default, more detailed particle-level information (e.g. electron coordinates) is also written for the lowest, highest, and median energy walkers at each MC step (modest disk usage). @@ -1915,12 +1915,12 @@ potentially requiring a huge amount of disk space. **Input specification** The default walker data tracing functionality is enabled by including the - XML element (once) just before the QMC driver sections, + XML element (once) just before the QMC driver sections, for example: :: - + 256 100 diff --git a/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp b/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp index f8d09f94ca..6d6a8e9c92 100644 --- a/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp +++ b/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp @@ -171,7 +171,8 @@ void DMCUpdatePbyPWithRejectionFast::advanceWalker(Walker_t& thisWalker, bool re #if !defined(REMOVE_TRACEMANAGER) Traces->buffer_sample(W.current_step); #endif - wtrace_collector->collect(thisWalker,W,Psi,H); + if(wtrace_collector) + wtrace_collector->collect(thisWalker,W,Psi,H); { ScopedTimer local_timer(myTimers[DMC_tmoves]); const int NonLocalMoveAcceptedTemp = H.makeNonLocalMoves(W); diff --git a/src/QMCDrivers/QMCDriver.cpp b/src/QMCDrivers/QMCDriver.cpp index c0cd542fc9..d6affeff94 100644 --- a/src/QMCDrivers/QMCDriver.cpp +++ b/src/QMCDrivers/QMCDriver.cpp @@ -65,6 +65,7 @@ QMCDriver::QMCDriver(const ProjectData& project_data, IsQMCDriver = true; allow_traces = false; allow_walker_traces = false; + walker_traces_xml = NULL; MyCounter = 0; // value //accept multiple names for the same value diff --git a/src/QMCDrivers/QMCDriverNew.cpp b/src/QMCDrivers/QMCDriverNew.cpp index ba58b1b1ae..a1349d5f6c 100644 --- a/src/QMCDrivers/QMCDriverNew.cpp +++ b/src/QMCDrivers/QMCDriverNew.cpp @@ -379,6 +379,19 @@ void QMCDriverNew::initialLogEvaluation(int crowd_id, doesDoinTheseLastMatter(walkers[iw]); } + +void QMCDriverNew::putWalkerTraces(xmlNodePtr txml) +{ + walker_traces_input.present = false; + if(txml) + { + walker_traces_input.readXML(txml); + walker_traces_input.present = true; + } + app_log()<<"JTK walker traces present: "< Date: Wed, 5 Jun 2024 16:35:01 -0400 Subject: [PATCH 46/55] fix index error --- src/Estimators/WalkerTraceBuffer.h | 4 ++-- src/Estimators/WalkerTraceManager.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Estimators/WalkerTraceBuffer.h b/src/Estimators/WalkerTraceBuffer.h index c27074f9b5..c221526102 100644 --- a/src/Estimators/WalkerTraceBuffer.h +++ b/src/Estimators/WalkerTraceBuffer.h @@ -243,8 +243,8 @@ class WalkerTraceBuffer size_t n = 0; for (size_t i=0;i Date: Thu, 6 Jun 2024 16:26:41 -0400 Subject: [PATCH 47/55] leave no trace --- docs/methods.rst | 66 +++--- src/Estimators/CMakeLists.txt | 4 +- ...{WalkerTraceBuffer.h => WalkerLogBuffer.h} | 54 ++--- ...ceCollector.cpp => WalkerLogCollector.cpp} | 70 +++---- ...rTraceCollector.h => WalkerLogCollector.h} | 44 ++-- .../{WalkerTraceInput.h => WalkerLogInput.h} | 32 +-- ...rTraceManager.cpp => WalkerLogManager.cpp} | 116 +++++------ ...alkerTraceManager.h => WalkerLogManager.h} | 72 +++---- src/Estimators/tests/CMakeLists.txt | 2 +- ...lector.cpp => test_WalkerLogCollector.cpp} | 26 +-- src/QMCApp/QMCMain.cpp | 8 +- src/QMCApp/QMCMain.h | 4 +- src/QMCDrivers/CloneManager.cpp | 4 +- src/QMCDrivers/CloneManager.h | 2 +- src/QMCDrivers/Crowd.cpp | 2 +- src/QMCDrivers/Crowd.h | 8 +- src/QMCDrivers/DMC/DMC.cpp | 18 +- src/QMCDrivers/DMC/DMCBatched.cpp | 18 +- src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp | 6 +- src/QMCDrivers/QMCDriver.cpp | 14 +- src/QMCDrivers/QMCDriver.h | 14 +- src/QMCDrivers/QMCDriverFactory.cpp | 8 +- src/QMCDrivers/QMCDriverFactory.h | 2 +- src/QMCDrivers/QMCDriverInterface.h | 4 +- src/QMCDrivers/QMCDriverNew.cpp | 15 +- src/QMCDrivers/QMCDriverNew.h | 22 +- src/QMCDrivers/QMCUpdateBase.cpp | 14 +- src/QMCDrivers/QMCUpdateBase.h | 8 +- src/QMCDrivers/VMC/VMC.cpp | 14 +- src/QMCDrivers/VMC/VMCBatched.cpp | 20 +- src/QMCDrivers/VMC/VMCUpdatePbyP.cpp | 4 +- src/QMCHamiltonians/CMakeLists.txt | 2 +- .../{check_wtraces.py => check_wlogs.py} | 188 +----------------- tests/solids/diamondC_1x1x1_pp/CMakeLists.txt | 48 ++--- ...n.xml => qmc_walkerlog_dmc_scalars.in.xml} | 4 +- ... => qmc_walkerlog_dmcbatch_scalars.in.xml} | 4 +- ...n.xml => qmc_walkerlog_vmc_scalars.in.xml} | 4 +- ... => qmc_walkerlog_vmcbatch_scalars.in.xml} | 4 +- 38 files changed, 386 insertions(+), 563 deletions(-) rename src/Estimators/{WalkerTraceBuffer.h => WalkerLogBuffer.h} (82%) rename src/Estimators/{WalkerTraceCollector.cpp => WalkerLogCollector.cpp} (64%) rename src/Estimators/{WalkerTraceCollector.h => WalkerLogCollector.h} (75%) rename src/Estimators/{WalkerTraceInput.h => WalkerLogInput.h} (51%) rename src/Estimators/{WalkerTraceManager.cpp => WalkerLogManager.cpp} (71%) rename src/Estimators/{WalkerTraceManager.h => WalkerLogManager.h} (59%) rename src/Estimators/tests/{test_WalkerTraceCollector.cpp => test_WalkerLogCollector.cpp} (84%) rename tests/scripts/{check_wtraces.py => check_wlogs.py} (89%) rename tests/solids/diamondC_1x1x1_pp/{qmc_walkertrace_dmc_scalars.in.xml => qmc_walkerlog_dmc_scalars.in.xml} (98%) rename tests/solids/diamondC_1x1x1_pp/{qmc_walkertrace_dmcbatch_scalars.in.xml => qmc_walkerlog_dmcbatch_scalars.in.xml} (98%) rename tests/solids/diamondC_1x1x1_pp/{qmc_walkertrace_vmc_scalars.in.xml => qmc_walkerlog_vmc_scalars.in.xml} (98%) rename tests/solids/diamondC_1x1x1_pp/{qmc_walkertrace_vmcbatch_scalars.in.xml => qmc_walkerlog_vmcbatch_scalars.in.xml} (98%) diff --git a/docs/methods.rst b/docs/methods.rst index 5c7eafdab8..8421f801b1 100644 --- a/docs/methods.rst +++ b/docs/methods.rst @@ -1899,13 +1899,13 @@ declaration to ensure correct sampling: -.. _walker_traces +.. _walker_logs -Walker Data Traces +Walker Data Logs ================== Detailed per-walker information can be written to HDF5 files for VMC or DMC by -including the XML element. This includes the LocalEnergy and +including the XML element. This includes the LocalEnergy and its components for each walker from each MC step. By default, more detailed particle-level information (e.g. electron coordinates) is also written for the lowest, highest, and median energy walkers at each MC step (modest disk usage). @@ -1915,12 +1915,12 @@ potentially requiring a huge amount of disk space. **Input specification** The default walker data tracing functionality is enabled by including the - XML element (once) just before the QMC driver sections, + XML element (once) just before the QMC driver sections, for example: :: - + 256 100 @@ -1951,7 +1951,7 @@ Optional XML attributes enable finer control over the behavior: +------------------+--------------+--------------+-------------+----------------------------------------------------+ | ``particle`` | text | yes,no | no | Write particle data for all walkers | +------------------+--------------+--------------+-------------+----------------------------------------------------+ - | ``qtiles`` | text | yes,no | yes | Write full data for min/max/median energy walkers | + | ``quantiles`` | text | yes,no | yes | Write full data for min/max/median energy walkers | +------------------+--------------+--------------+-------------+----------------------------------------------------+ | ``min`` | text | yes,no | yes | Enable/disable write for min energy walker data | +------------------+--------------+--------------+-------------+----------------------------------------------------+ @@ -1971,12 +1971,12 @@ Additional information: with step_period=5, walker data is collected every 5th MC step. - ``particle``: This controls whether per-particle data is written to - the traces HDF files along with scalar walker properties. These data + the walker log HDF files along with scalar walker properties. These data comprise: electron coordinates, spin coordinates (spinor runs only), per-particle wavefunction gradients, and per-particle wavefunction laplacian values. -- ``qtiles``: Write out full (scalar and per-particle) data for walkers +- ``quantiles``: Write out full (scalar and per-particle) data for walkers at specific quantiles of the local energy distribution. Currently, these quantiles are the minimum, maximum, and median. @@ -1990,13 +1990,13 @@ Additional information: walkers. Active only if qtiles=yes. - ``verbose``: If "yes", write function-call information related to - the walker traces functionality. This option is mainly intended + the walker logging functionality. This option is mainly intended for developers, as it is of little use in practical runs. **Output files** -The HDF5 files created by the walker traces functionality have the extension \*.wtraces.h5. +The HDF5 files created by the walker logging functionality have the extension \*.wlogs.h5. For each VMC or DMC section, one of these files is written for every MPI rank in the run. For the example XML inputs shown above, QMCPACK run on 6 MPI ranks would produce (at least) @@ -2006,25 +2006,25 @@ the following output data files: qmc.s000.scalar.dat qmc.s000.stat.h5 - qmc.s000.p000.wtraces.h5 - qmc.s000.p001.wtraces.h5 - qmc.s000.p002.wtraces.h5 - qmc.s000.p003.wtraces.h5 - qmc.s000.p004.wtraces.h5 - qmc.s000.p005.wtraces.h5 + qmc.s000.p000.wlogs.h5 + qmc.s000.p001.wlogs.h5 + qmc.s000.p002.wlogs.h5 + qmc.s000.p003.wlogs.h5 + qmc.s000.p004.wlogs.h5 + qmc.s000.p005.wlogs.h5 qmc.s001.scalar.dat qmc.s001.dmc.dat qmc.s001.stat.h5 - qmc.s001.p000.wtraces.h5 - qmc.s001.p001.wtraces.h5 - qmc.s001.p002.wtraces.h5 - qmc.s001.p003.wtraces.h5 - qmc.s001.p004.wtraces.h5 - qmc.s001.p005.wtraces.h5 + qmc.s001.p000.wlogs.h5 + qmc.s001.p001.wlogs.h5 + qmc.s001.p002.wlogs.h5 + qmc.s001.p003.wlogs.h5 + qmc.s001.p004.wlogs.h5 + qmc.s001.p005.wlogs.h5 -A single wtraces.h5 file has several walker data buffers (names with underscores below): +A single wlogs.h5 file has several walker data buffers (names with underscores below): :: @@ -2045,11 +2045,11 @@ Each data buffer contains packed walker data in the form of a large 2D array ("d :: - >h5ls qmc.s000.p000.wtraces.h5/walker_property_int + >h5ls qmc.s000.p000.wlogs.h5/walker_property_int data Dataset {512000/Inf, 4} data_layout Group - >h5ls qmc.s000.p000.wtraces.h5/walker_property_real + >h5ls qmc.s000.p000.wlogs.h5/walker_property_real data Dataset {512000/Inf, 15} data_layout Group @@ -2061,13 +2061,13 @@ The location of each particular walker quantity in each row is listed in "data_l :: - >h5ls qmc.s000.p000.wtraces.h5/walker_property_int/data_layout + >h5ls qmc.s000.p000.wlogs.h5/walker_property_int/data_layout id Group # unique walker id parent_id Group # id of parent (DMC branching) step Group # MC step number age Group # walker "age" - >h5ls qmc.s000.p000.wtraces.h5/walker_property_real/data_layout + >h5ls qmc.s000.p000.wlogs.h5/walker_property_real/data_layout weight Group # statistical weight of the walker LocalEnergy Group # the local (total) energy Kinetic Group # kinetic energy @@ -2090,12 +2090,12 @@ in walker_property_real/data: :: - >h5ls -d qmc.s000.p000.wtraces.h5/walker_property_int/data_layout/step/index_start + >h5ls -d qmc.s000.p000.wlogs.h5/walker_property_int/data_layout/step/index_start index_start Dataset {SCALAR} Data: (0) 0 - >h5ls -d qmc.s000.p000.wtraces.h5/walker_property_real/data_layout/LocalEnergy/index_start + >h5ls -d qmc.s000.p000.wlogs.h5/walker_property_real/data_layout/LocalEnergy/index_start index_start Dataset {SCALAR} Data: (0) 6 @@ -2105,7 +2105,7 @@ The per-particle data is arranged similarly: :: - >h5ls -d qmc_trace_dmc_legacy.s000.p000.wtraces.h5/wmin_particle_real/data_layout + >h5ls -d qmc_log_dmc_legacy.s000.p000.wlogs.h5/wmin_particle_real/data_layout R Group # electron coordinates G Group # wavefunction gradient L Group # wavefunction laplacian (per-particle) @@ -2117,7 +2117,7 @@ real-valued wavefunction): :: - >h5ls -d qmc.s000.p000.wtraces.h5/wmin_particle_real/data_layout/R + >h5ls -d qmc.s000.p000.wlogs.h5/wmin_particle_real/data_layout/R index_start 0 # data starts at column index 0 index_end 24 # data ends at column index 24 dimension 2 # array is 2-dimensional @@ -2125,7 +2125,7 @@ real-valued wavefunction): shape 8, 3, 0, 0 # array has shape 8x3 unit_size 1 # each unit of data stored as 1 real value - >h5ls -d qmc.s000.p000.wtraces.h5/wmin_particle_real/data_layout/G + >h5ls -d qmc.s000.p000.wlogs.h5/wmin_particle_real/data_layout/G index_start 24 # data starts at column index 24 index_end 48 # data ends at column index 48 dimension 2 # array is 2-dimensional @@ -2133,7 +2133,7 @@ real-valued wavefunction): shape 8, 3, 0, 0 # array has shape 8x3 unit_size 1 # data stored as single real values (2 if complex) - >h5ls -d qmc.s000.p000.wtraces.h5/wmin_particle_real/data_layout/L + >h5ls -d qmc.s000.p000.wlogs.h5/wmin_particle_real/data_layout/L index_start 48 # data starts at column index 48 index_end 56 # data ends at column index 56 dimension 1 # array is 1-dimensional diff --git a/src/Estimators/CMakeLists.txt b/src/Estimators/CMakeLists.txt index f49e1a0ffb..56aa91bee7 100644 --- a/src/Estimators/CMakeLists.txt +++ b/src/Estimators/CMakeLists.txt @@ -26,8 +26,8 @@ set(QMCEST_SRC EstimatorManagerBase.cpp EstimatorManagerNew.cpp EstimatorManagerCrowd.cpp - WalkerTraceCollector.cpp - WalkerTraceManager.cpp + WalkerLogCollector.cpp + WalkerLogManager.cpp CollectablesEstimator.cpp OperatorEstBase.cpp SpinDensityNew.cpp diff --git a/src/Estimators/WalkerTraceBuffer.h b/src/Estimators/WalkerLogBuffer.h similarity index 82% rename from src/Estimators/WalkerTraceBuffer.h rename to src/Estimators/WalkerLogBuffer.h index c221526102..765f9c1f68 100644 --- a/src/Estimators/WalkerTraceBuffer.h +++ b/src/Estimators/WalkerLogBuffer.h @@ -10,8 +10,8 @@ ////////////////////////////////////////////////////////////////////////////////////// -#ifndef QMCPLUSPLUS_WALKERTRACEBUFFER_H -#define QMCPLUSPLUS_WALKERTRACEBUFFER_H +#ifndef QMCPLUSPLUS_WALKERLOGBUFFER_H +#define QMCPLUSPLUS_WALKERLOGBUFFER_H #include @@ -26,8 +26,8 @@ namespace qmcplusplus { -/// Basic data types for walker trace data -struct WTrace +/// Basic data types for walker log data +struct WLog { using Int = long; // integer type using Real = OHMMS_PRECISION_FULL; // real type @@ -40,9 +40,9 @@ struct WTrace }; -/** Record for an individual walker quantity being traced. +/** Record for an individual walker quantity being logd. * - * Helper struct for WalkerTraceBuffer. + * Helper struct for WalkerLogBuffer. */ struct WalkerQuantityInfo { @@ -87,28 +87,28 @@ struct WalkerQuantityInfo -/** Data buffer for walker trace quantities. +/** Data buffer for walker log quantities. * * Each row in the buffer contains all quantities for one walker from a single step. * Rows are added throughout an MC block. - * See WalkerTraceCollector::collect() + * See WalkerLogCollector::collect() * * Buffer data is written to HDF at the end of each MC block. - * See WalkerTraceManager::writeBuffers() + * See WalkerLogManager::writeBuffers() */ template -class WalkerTraceBuffer +class WalkerLogBuffer { public: /// label for this data in HDF file std::string label; - /// marks first WalkerTraceCollector::collect() call + /// marks first WalkerLogCollector::collect() call bool first_collect; /// HDF file pointer hsize_t hdf_file_pointer; private: - /// index of current quantity during WalkerTraceCollector::collect() + /// index of current quantity during WalkerLogCollector::collect() size_t quantity_pointer; /** buffer row location data for each walker quantity * used to populate "data_layout" field in HDF file @@ -122,7 +122,7 @@ class WalkerTraceBuffer hsize_t dims[2]; public: - WalkerTraceBuffer() + WalkerLogBuffer() { label = "?"; first_collect = true; @@ -140,17 +140,17 @@ class WalkerTraceBuffer /// resize the buffer to zero inline void resetBuffer() { buffer.resize(0, buffer.size(1)); } - /// reset member variables at end of each WalkerTraceCollector::collect() call + /// reset member variables at end of each WalkerLogCollector::collect() call inline void resetCollect() { if(quantity_pointer!=quantity_info.size()) - throw std::runtime_error("WalkerTraceBuffer quantity_pointer has not been moved through all quantities prior during collect() call."); + throw std::runtime_error("WalkerLogBuffer quantity_pointer has not been moved through all quantities prior during collect() call."); first_collect = false; quantity_pointer = 0; } /// compare row size of this buffer to another one - inline bool sameAs(const WalkerTraceBuffer& ref) { return buffer.size(1) == ref.buffer.size(1); } + inline bool sameAs(const WalkerLogBuffer& ref) { return buffer.size(1) == ref.buffer.size(1); } /// collect data for a single walker quantity of scalar type into the current buffer row inline void collect(const std::string& name, const T& value) @@ -184,7 +184,7 @@ class WalkerTraceBuffer size_t n2,n3,n4; n2=n3=n4=0; if (D>4) - throw std::runtime_error("WalkerTraceBuffer::collect Only arrays up to dimension 4 are currently supported."); + throw std::runtime_error("WalkerLogBuffer::collect Only arrays up to dimension 4 are currently supported."); if (D>1) n2 = arr.size(1); if (D>2) n3 = arr.size(2); if (D>3) n4 = arr.size(3); @@ -219,7 +219,7 @@ class WalkerTraceBuffer size_t n2,n3,n4; n2=n3=n4=0; if (D>4) - throw std::runtime_error("WalkerTraceBuffer::collect Only arrays up to dimension 4 are currently supported."); + throw std::runtime_error("WalkerLogBuffer::collect Only arrays up to dimension 4 are currently supported."); if (D>1) n2 = arr.size(1); if (D>2) n3 = arr.size(2); if (D>3) n4 = arr.size(3); @@ -251,7 +251,7 @@ class WalkerTraceBuffer /// add a data row from another buffer to this one - inline void addRow(WalkerTraceBuffer other, size_t i) + inline void addRow(WalkerLogBuffer other, size_t i) { auto& other_buffer = other.buffer; if (first_collect) @@ -263,7 +263,7 @@ class WalkerTraceBuffer else { if(buffer.size(1)!=other_buffer.size(1)) - throw std::runtime_error("WalkerTraceBuffer::add_row Row sizes must match."); + throw std::runtime_error("WalkerLogBuffer::add_row Row sizes must match."); makeNewRow(); } size_t ib = buffer.size(0)-1; @@ -278,7 +278,7 @@ class WalkerTraceBuffer std::string pad2 = pad + " "; std::string pad3 = pad2 + " "; app_log() << std::endl; - app_log() << pad << "WalkerTraceBuffer(" << label << ")" << std::endl; + app_log() << pad << "WalkerLogBuffer(" << label << ")" << std::endl; app_log() << pad2 << "nrows = " << buffer.size(0) << std::endl; app_log() << pad2 << "row_size = " << buffer.size(1) << std::endl; for(size_t n=0;n; -WalkerTraceCollector::WalkerTraceCollector() +WalkerLogCollector::WalkerLogCollector() : properties_include{"R2Accepted","R2Proposed","LocalEnergy","LocalPotential","Kinetic","ElecElec","ElecIon","LocalECP","NonLocalECP"} { state.reset(); @@ -40,17 +40,17 @@ WalkerTraceCollector::WalkerTraceCollector() } -void WalkerTraceCollector::startBlock() +void WalkerLogCollector::startBlock() { - if(!state.traces_active) return; // no-op for driver if traces are inactive - if (state.verbose) app_log() << "WalkerTraceCollector::startBlock " << std::endl; + if(!state.logs_active) return; // no-op for driver if logs are inactive + if (state.verbose) app_log() << "WalkerLogCollector::startBlock " << std::endl; resetBuffers(); // resize buffers to zero rows } -void WalkerTraceCollector::collect(const MCPWalker& walker, const ParticleSet& pset, const TrialWaveFunction& wfn, const QMCHamiltonian& ham, int step) +void WalkerLogCollector::collect(const MCPWalker& walker, const ParticleSet& pset, const TrialWaveFunction& wfn, const QMCHamiltonian& ham, int step) { - if(!state.traces_active) return; // no-op for driver if traces are inactive + if(!state.logs_active) return; // no-op for driver if logs are inactive // only collect walker data at steps matching the period (default 1) int current_step = (step==-1) ? pset.current_step : step; @@ -67,41 +67,41 @@ void WalkerTraceCollector::collect(const MCPWalker& walker, const ParticleSet& p Rtmp.resize(nparticles,ndim); for(size_t p=0;p::max(); + WLog::Real dr = std::numeric_limits::max(); for(size_t n=0; n; -/// Helper struct holding data transferred from WalkerTraceManager to WalkerTraceCollector following input read -struct WalkerTraceState +/// Helper struct holding data transferred from WalkerLogManager to WalkerLogCollector following input read +struct WalkerLogState { - /// whether traces are active in the current driver - bool traces_active; + /// whether logs are active in the current driver + bool logs_active; /// period between MC steps for data collection int step_period; /// controls verbosity of log file writes bool verbose; - WalkerTraceState() + WalkerLogState() { reset(); step_period = 1; @@ -45,32 +45,32 @@ struct WalkerTraceState inline void reset() { - traces_active = false; + logs_active = false; verbose = false; } }; -/** Crowd-level resource for walker trace collection. +/** Crowd-level resource for walker log collection. * * Contains data buffers for walker properties and walker particle data. * Data buffers are resized to zero at the start of an MC block. * Data for all walkers is collected into the buffers each MC step in an MC block. * This class is not responsible for I/O. */ -class WalkerTraceCollector +class WalkerLogCollector { public: /// MC step information for each walker throughout the MC block std::vector steps; /// LocalEnergy information for each walker throughout the MC block - std::vector energies; + std::vector energies; /// buffer containing integer walker properties - WalkerTraceBuffer walker_property_int_buffer; + WalkerLogBuffer walker_property_int_buffer; /// buffer containing real-valued walker properties - WalkerTraceBuffer walker_property_real_buffer; + WalkerLogBuffer walker_property_real_buffer; /// buffer containing per-particle walker data - WalkerTraceBuffer walker_particle_real_buffer; + WalkerLogBuffer walker_particle_real_buffer; /// ParticleSet::PropertyList quantities to include std::unordered_set properties_include; @@ -79,22 +79,22 @@ class WalkerTraceCollector /// location of LocalEnergy in ParticleSet::PropertyList int energy_index; - /// state data set by WalkerTraceManager - WalkerTraceState state; + /// state data set by WalkerLogManager + WalkerLogState state; private: // temporary (contiguous) storage for awful ParticleAttrib<> quantities /// tmp storage for walker positions - Array Rtmp; + Array Rtmp; /// tmp storage for walker spins - Array Stmp; + Array Stmp; /// tmp storage for walker wavefunction gradients - Array Gtmp; + Array Gtmp; /// tmp storage for walker wavefunciton laplacians - Array Ltmp; + Array Ltmp; public: - WalkerTraceCollector(); + WalkerLogCollector(); /// resize buffers to zero rows at beginning of each MC block void startBlock(); diff --git a/src/Estimators/WalkerTraceInput.h b/src/Estimators/WalkerLogInput.h similarity index 51% rename from src/Estimators/WalkerTraceInput.h rename to src/Estimators/WalkerLogInput.h index 4a6c813b01..7bff8274af 100644 --- a/src/Estimators/WalkerTraceInput.h +++ b/src/Estimators/WalkerLogInput.h @@ -7,35 +7,35 @@ // File developed by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory // ////////////////////////////////////////////////////////////////////////////////////// -#ifndef QMCPLUSPLUS_WALKERTRACEINPUT_H -#define QMCPLUSPLUS_WALKERTRACEINPUT_H +#ifndef QMCPLUSPLUS_WALKERLOGINPUT_H +#define QMCPLUSPLUS_WALKERLOGINPUT_H #include "InputSection.h" namespace qmcplusplus { -/** Native representation for walker traces input +/** Native representation for walker logs input */ -struct WalkerTraceInput : public InputSection +struct WalkerLogInput : public InputSection { bool present; - WalkerTraceInput() : WalkerTraceInput(NULL) {} + WalkerLogInput() : WalkerLogInput(NULL) {} - WalkerTraceInput(xmlNodePtr cur) + WalkerLogInput(xmlNodePtr cur) { - section_name = "walkertraces"; - attributes = {"step_period", "particle", "min", "max", "median", "qtiles", "verbose"}; + section_name = "walkerlogs"; + attributes = {"step_period", "particle", "min", "max", "median", "quantiles", "verbose"}; integers = {"step_period"}; - bools = {"particle", "min", "max", "median", "qtiles", "verbose"}; + bools = {"particle", "min", "max", "median", "quantiles", "verbose"}; default_values = {{"step_period", int(1)}, - {"particle", bool(false)}, - {"min" , bool(true)}, - {"max" , bool(true)}, - {"median" , bool(true)}, - {"qtiles" , bool(true)}, - {"verbose" , bool(false)}}; + {"particle" , bool(false)}, + {"min" , bool(true)}, + {"max" , bool(true)}, + {"median" , bool(true)}, + {"quantiles" , bool(true)}, + {"verbose" , bool(false)}}; present = cur!=NULL; if(present) readXML(cur); @@ -43,4 +43,4 @@ struct WalkerTraceInput : public InputSection }; } // namespace qmcplusplus -#endif /* WALKERTRACEINPUT_H */ +#endif /* WALKERLOGINPUT_H */ diff --git a/src/Estimators/WalkerTraceManager.cpp b/src/Estimators/WalkerLogManager.cpp similarity index 71% rename from src/Estimators/WalkerTraceManager.cpp rename to src/Estimators/WalkerLogManager.cpp index f5797f19fb..1d9c539270 100644 --- a/src/Estimators/WalkerTraceManager.cpp +++ b/src/Estimators/WalkerLogManager.cpp @@ -9,8 +9,8 @@ // File created by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory ////////////////////////////////////////////////////////////////////////////////////// -#include "WalkerTraceManager.h" -#include "WalkerTraceInput.h" +#include "WalkerLogManager.h" +#include "WalkerLogInput.h" #include "Concurrency/OpenMP.h" @@ -18,35 +18,35 @@ namespace qmcplusplus { -WalkerTraceManager::WalkerTraceManager(WalkerTraceInput& inp, bool allow_traces, std::string series_root, Communicate* comm) +WalkerLogManager::WalkerLogManager(WalkerLogInput& inp, bool allow_logs, std::string series_root, Communicate* comm) { state.reset(); - communicator = comm; - file_root = series_root; - bool driver_allows_traces = allow_traces; // driver allows traces or not + communicator = comm; + file_root = series_root; + bool driver_allows_logs = allow_logs; // driver allows logs or not - bool traces_requested = inp.present; // xml input present or not - // determine whether walker traces will be active - state.traces_active = traces_requested && driver_allows_traces; + bool logs_requested = inp.present; // xml input present or not + // determine whether walker logs will be active + state.logs_active = logs_requested && driver_allows_logs; - if (state.traces_active) + if (state.logs_active) { if (omp_get_thread_num() == 0) { - app_log() << "\n WalkerTraceManager::put() " << std::endl; - app_log() << " traces requested : " << traces_requested << std::endl; - app_log() << " driver allows traces : " << driver_allows_traces << std::endl; - app_log() << " traces active : " << state.traces_active << std::endl; + app_log() << "\n WalkerLogManager::put() " << std::endl; + app_log() << " logs requested : " << logs_requested << std::endl; + app_log() << " driver allows logs : " << driver_allows_logs << std::endl; + app_log() << " logs active : " << state.logs_active << std::endl; app_log() << std::endl; } // retrieve input data state.step_period = inp.get("step_period"); state.verbose = inp.get("verbose"); - bool qtiles = inp.get("qtiles"); + bool quantiles = inp.get("quantiles"); write_particle_data = inp.get("particle"); - write_min_data = inp.get("min") && qtiles; - write_max_data = inp.get("max") && qtiles; - write_med_data = inp.get("median") && qtiles; + write_min_data = inp.get("min") && quantiles; + write_max_data = inp.get("max") && quantiles; + write_med_data = inp.get("median") && quantiles; } // label min energy walker buffers for HDF file write @@ -69,42 +69,42 @@ WalkerTraceManager::WalkerTraceManager(WalkerTraceInput& inp, bool allow_traces, } -WalkerTraceCollector* WalkerTraceManager::makeCollector() +WalkerLogCollector* WalkerLogManager::makeCollector() { - if (state.verbose) app_log() << "WalkerTraceManager::makeCollector " << std::endl; - WalkerTraceCollector* tc = new WalkerTraceCollector(); + if (state.verbose) app_log() << "WalkerLogManager::makeCollector " << std::endl; + WalkerLogCollector* tc = new WalkerLogCollector(); tc->state = state; return tc; } -void WalkerTraceManager::startRun(std::vector& collectors) +void WalkerLogManager::startRun(std::vector& collectors) { - if (!state.traces_active) return; // no-op for driver if traces are inactive - if (state.verbose) app_log() << "WalkerTraceManager::startRun " << std::endl; - // transfer step_period, verbosity, etc settings to trace collectors + if (!state.logs_active) return; // no-op for driver if logs are inactive + if (state.verbose) app_log() << "WalkerLogManager::startRun " << std::endl; + // transfer step_period, verbosity, etc settings to log collectors for (auto& tc: collectors) tc->state = state; - // check data size consistency among the trace collector buffers + // check data size consistency among the log collector buffers checkCollectors(collectors); - // open the traces file + // open the logs file openFile(collectors); } -void WalkerTraceManager::stopRun() +void WalkerLogManager::stopRun() { - if (!state.traces_active) return; // no-op for driver if traces are inactive - if (state.verbose) app_log() << "WalkerTraceManager::stopRun " << std::endl; - // close the traces file + if (!state.logs_active) return; // no-op for driver if logs are inactive + if (state.verbose) app_log() << "WalkerLogManager::stopRun " << std::endl; + // close the logs file closeFile(); } -void WalkerTraceManager::writeBuffers(std::vector& collectors) +void WalkerLogManager::writeBuffers(std::vector& collectors) { - if (!state.traces_active) return; // no-op for driver if traces are inactive - if (state.verbose) app_log() << "WalkerTraceManager::writeBuffers "<& collec } -void WalkerTraceManager::checkCollectors(std::vector& collectors) +void WalkerLogManager::checkCollectors(std::vector& collectors) { - if (state.verbose) app_log() << "WalkerTraceManager::checkCollectors" << std::endl; + if (state.verbose) app_log() << "WalkerLogManager::checkCollectors" << std::endl; if (collectors.size() > 0) { bool all_same = true; - WalkerTraceCollector& ref = *collectors[0]; + WalkerLogCollector& ref = *collectors[0]; for (int i = 0; i < collectors.size(); ++i) { - WalkerTraceCollector& tc = *collectors[i]; + WalkerLogCollector& tc = *collectors[i]; all_same &= tc.walker_property_int_buffer.sameAs(ref.walker_property_int_buffer); all_same &= tc.walker_property_real_buffer.sameAs(ref.walker_property_real_buffer); all_same &= tc.walker_particle_real_buffer.sameAs(ref.walker_particle_real_buffer); } if (!all_same) { - throw std::runtime_error("WalkerTraceManager::checkCollectors trace buffer widths of collectors do not match\n contiguous write is " - "impossible\n this was first caused by collectors contributing array traces from identical, but " - "differently named, particlesets such as e, e2, e3 ... (fixed)\n please check the WalkerTraceManager " + throw std::runtime_error("WalkerLogManager::checkCollectors log buffer widths of collectors do not match\n contiguous write is " + "impossible\n this was first caused by collectors contributing array logs from identical, but " + "differently named, particlesets such as e, e2, e3 ... (fixed)\n please check the WalkerLogManager " "summaries printed above"); } } } -void WalkerTraceManager::openFile(std::vector& collectors) +void WalkerLogManager::openFile(std::vector& collectors) { - if (state.verbose) app_log() << "WalkerTraceManager::openFile "<& collectors) +void WalkerLogManager::openHDFFile(std::vector& collectors) { - if (state.verbose) app_log() << "WalkerTraceManager::openHDFFile " << std::endl; + if (state.verbose) app_log() << "WalkerLogManager::openHDFFile " << std::endl; if (collectors.size() == 0) - throw std::runtime_error("WalkerTraceManager::openHDFFile no trace collectors exist, cannot open file"); - // each rank opens a wtraces.h5 file + throw std::runtime_error("WalkerLogManager::openHDFFile no log collectors exist, cannot open file"); + // each rank opens a wlogs.h5 file int nprocs = communicator->size(); int rank = communicator->rank(); std::array ptoken; @@ -260,21 +260,21 @@ void WalkerTraceManager::openHDFFile(std::vector& collect throw std::runtime_error("Error generating filename"); file_name.append(ptoken.data(), length); } - file_name += ".wtraces.h5"; - if (state.verbose) app_log() << "WalkerTraceManager::openHDFFile opening traces hdf file " << file_name << std::endl; + file_name += ".wlogs.h5"; + if (state.verbose) app_log() << "WalkerLogManager::openHDFFile opening logs hdf file " << file_name << std::endl; // create the hdf archive hdf_file = std::make_unique(); // open the file bool successful = hdf_file->create(file_name); if (!successful) - throw std::runtime_error("WalkerTraceManager::openHDFFile failed to open hdf file " + file_name); + throw std::runtime_error("WalkerLogManager::openHDFFile failed to open hdf file " + file_name); } -void WalkerTraceManager::writeBuffersHDF(std::vector& collectors) +void WalkerLogManager::writeBuffersHDF(std::vector& collectors) { - if (state.verbose) app_log() << "WalkerTraceManager::writeBuffersHDF " << std::endl; - WalkerTraceCollector& tc_lead = *collectors[0]; + if (state.verbose) app_log() << "WalkerLogManager::writeBuffersHDF " << std::endl; + WalkerLogCollector& tc_lead = *collectors[0]; if(!registered_hdf) {// write walker quantity information ("data_layout") for each buffer in the HDF file // create data_layout for all-walker buffers @@ -306,7 +306,7 @@ void WalkerTraceManager::writeBuffersHDF(std::vector& col // write data for all-walker buffers to HDF for (int ip = 0; ip < collectors.size(); ++ip) { - WalkerTraceCollector& tc = *collectors[ip]; + WalkerLogCollector& tc = *collectors[ip]; tc.walker_property_int_buffer.writeHDF(*hdf_file, tc_lead.walker_property_int_buffer.hdf_file_pointer); tc.walker_property_real_buffer.writeHDF(*hdf_file, tc_lead.walker_property_real_buffer.hdf_file_pointer); if(write_particle_data) @@ -333,9 +333,9 @@ void WalkerTraceManager::writeBuffersHDF(std::vector& col } -void WalkerTraceManager::closeHDFFile() +void WalkerLogManager::closeHDFFile() { - if (state.verbose) app_log() << "WalkerTraceManager::closeHDFFile " << std::endl; + if (state.verbose) app_log() << "WalkerLogManager::closeHDFFile " << std::endl; hdf_file.reset(); } diff --git a/src/Estimators/WalkerTraceManager.h b/src/Estimators/WalkerLogManager.h similarity index 59% rename from src/Estimators/WalkerTraceManager.h rename to src/Estimators/WalkerLogManager.h index 39a2976bb6..e17fa7f043 100644 --- a/src/Estimators/WalkerTraceManager.h +++ b/src/Estimators/WalkerLogManager.h @@ -10,23 +10,23 @@ ////////////////////////////////////////////////////////////////////////////////////// -#ifndef QMCPLUSPLUS_WALKERTRACEMANAGER_H -#define QMCPLUSPLUS_WALKERTRACEMANAGER_H +#ifndef QMCPLUSPLUS_WALKERLOGMANAGER_H +#define QMCPLUSPLUS_WALKERLOGMANAGER_H -#include "WalkerTraceCollector.h" +#include "WalkerLogCollector.h" namespace qmcplusplus { -struct WalkerTraceInput; +struct WalkerLogInput; -/** Driver-level resource for walker trace collection. +/** Driver-level resource for walker log collection. * * This class manages the HDF file (open/close/write). - * Walker buffer data from all crowd-level WalkerTraceCollectors are written + * Walker buffer data from all crowd-level WalkerLogCollectors are written * to the HDF file at the end of each MC block. * * Just prior to the write, this class examines the distribution of walker @@ -35,16 +35,16 @@ struct WalkerTraceInput; * (including per-particle information) for the write. * This data corresponds to walker information at specific quantiles of the * energy distribution. - * See WalkerTraceManager::writeBuffers() + * See WalkerLogManager::writeBuffers() * * Writing per-particle information for all walkers is optional, as is * writing data for the minimum/maximum/median energy walkers. * Scalar "property" data for each walker is always written. */ -class WalkerTraceManager +class WalkerLogManager { public: - WalkerTraceState state; + WalkerLogState state; private: /// file prefix for the current driver @@ -65,61 +65,61 @@ class WalkerTraceManager bool write_med_data; /// used to sort energy information for identifying walkers by energy quantile - std::vector> energy_order; + std::vector> energy_order; /// buffer containing integer properties for the minimum energy walkers - WalkerTraceBuffer wmin_property_int_buffer; + WalkerLogBuffer wmin_property_int_buffer; /// buffer containing real-valued properties for the minimum energy walkers - WalkerTraceBuffer wmin_property_real_buffer; + WalkerLogBuffer wmin_property_real_buffer; /// buffer containing per-particle properties for the minimum energy walkers - WalkerTraceBuffer wmin_particle_real_buffer; + WalkerLogBuffer wmin_particle_real_buffer; /// buffer containing integer properties for the maximum energy walkers - WalkerTraceBuffer wmax_property_int_buffer; + WalkerLogBuffer wmax_property_int_buffer; /// buffer containing real-valued properties for the maximum energy walkers - WalkerTraceBuffer wmax_property_real_buffer; + WalkerLogBuffer wmax_property_real_buffer; /// buffer containing per-particle properties for the maximum energy walkers - WalkerTraceBuffer wmax_particle_real_buffer; + WalkerLogBuffer wmax_particle_real_buffer; /// buffer containing integer properties for the median energy walkers - WalkerTraceBuffer wmed_property_int_buffer; + WalkerLogBuffer wmed_property_int_buffer; /// buffer containing real-valued properties for the median energy walkers - WalkerTraceBuffer wmed_property_real_buffer; + WalkerLogBuffer wmed_property_real_buffer; /// buffer containing per-particle properties for the median energy walkers - WalkerTraceBuffer wmed_particle_real_buffer; + WalkerLogBuffer wmed_particle_real_buffer; public: - WalkerTraceManager(WalkerTraceInput& inp, bool allow_traces, std::string series_root, Communicate* comm = 0); + WalkerLogManager(WalkerLogInput& inp, bool allow_logs, std::string series_root, Communicate* comm = 0); - /// create a WalkerTraceCollector (legacy drivers only, "cloning" style) - WalkerTraceCollector* makeCollector(); + /// create a WalkerLogCollector (legacy drivers only, "cloning" style) + WalkerLogCollector* makeCollector(); - /// open the traces file and check consistency of the collectors at the start of a run - void startRun(std::vector& collectors); + /// open the logs file and check consistency of the collectors at the start of a run + void startRun(std::vector& collectors); - /// close the traces file at the end of a run + /// close the logs file at the end of a run void stopRun(); - /// collect min/max/median walker data and write buffered walker trace data to file - void writeBuffers(std::vector& collectors); + /// collect min/max/median walker data and write buffered walker log data to file + void writeBuffers(std::vector& collectors); private: /// check consistency of walker buffer row sizes - void checkCollectors(std::vector& collectors); + void checkCollectors(std::vector& collectors); - /// open the traces file - void openFile(std::vector& collectors); + /// open the logs file + void openFile(std::vector& collectors); - /// close the traces file + /// close the logs file void closeFile(); - /// open the traces file (HDF format) - void openHDFFile(std::vector& collectors); + /// open the logs file (HDF format) + void openHDFFile(std::vector& collectors); - /// write data buffers to the traces file (HDF format) - void writeBuffersHDF(std::vector& collectors); + /// write data buffers to the logs file (HDF format) + void writeBuffersHDF(std::vector& collectors); - /// close the traces file (HDF format) + /// close the logs file (HDF format) void closeHDFFile(); }; diff --git a/src/Estimators/tests/CMakeLists.txt b/src/Estimators/tests/CMakeLists.txt index ec90abd61a..a1fe950771 100644 --- a/src/Estimators/tests/CMakeLists.txt +++ b/src/Estimators/tests/CMakeLists.txt @@ -29,7 +29,7 @@ set(SRCS test_manager.cpp test_EstimatorManagerNew.cpp test_trace_manager.cpp - test_WalkerTraceCollector.cpp + test_WalkerLogCollector.cpp EstimatorTesting.cpp GenerateRandomParticleSets.cpp test_SpinDensityInput.cpp diff --git a/src/Estimators/tests/test_WalkerTraceCollector.cpp b/src/Estimators/tests/test_WalkerLogCollector.cpp similarity index 84% rename from src/Estimators/tests/test_WalkerTraceCollector.cpp rename to src/Estimators/tests/test_WalkerLogCollector.cpp index dff3bb0e4b..444b9574c6 100644 --- a/src/Estimators/tests/test_WalkerTraceCollector.cpp +++ b/src/Estimators/tests/test_WalkerLogCollector.cpp @@ -20,16 +20,16 @@ #include "Utilities/ResourceCollection.h" #include "Utilities/ProjectData.h" -#include "Estimators/WalkerTraceCollector.h" +#include "Estimators/WalkerLogCollector.h" namespace qmcplusplus { -TEST_CASE("WalkerTraceCollector::collect", "[estimators]") +TEST_CASE("WalkerLogCollector::collect", "[estimators]") { std::cout <<"\n\n=======================================================\n"; - std::cout <<"test WalkerTraceCollector::collect\n"; + std::cout <<"test WalkerLogCollector::collect\n"; ProjectData test_project("test", ProjectData::DriverVersion::BATCH); Communicate* comm = OHMMS::Controller; @@ -76,13 +76,13 @@ TEST_CASE("WalkerTraceCollector::collect", "[estimators]") walker.DataSet.allocate(); } - WalkerTraceCollector tc; - tc.state.traces_active = true; - tc.state.step_period = 1; + WalkerLogCollector wlc; + wlc.state.logs_active = true; + wlc.state.step_period = 1; - auto& bsi = tc.walker_property_int_buffer; - auto& bsr = tc.walker_property_real_buffer; - auto& bpr = tc.walker_particle_real_buffer; + auto& bsi = wlc.walker_property_int_buffer; + auto& bsr = wlc.walker_property_real_buffer; + auto& bpr = wlc.walker_particle_real_buffer; CHECK(bsi.nrows() == 0); CHECK(bsr.nrows() == 0); @@ -98,7 +98,7 @@ TEST_CASE("WalkerTraceCollector::collect", "[estimators]") #endif int step=0; - tc.collect(walkers[0], psets[0], *(twfs[0]), *(hams[0]), step); + wlc.collect(walkers[0], psets[0], *(twfs[0]), *(hams[0]), step); CHECK(bsi.nrows() == 1); CHECK(bsr.nrows() == 1); @@ -108,7 +108,7 @@ TEST_CASE("WalkerTraceCollector::collect", "[estimators]") CHECK(bpr.ncols() == npcols); for (size_t iw=1; iw(*particle_set_pool_, *psi_pool_, myComm)), qmc_system_(nullptr), first_qmc_(true), - walker_traces_xml_(NULL) + walker_logs_xml_(NULL) #if !defined(REMOVE_TRACEMANAGER) , traces_xml_(NULL) @@ -484,9 +484,9 @@ bool QMCMain::validateXML() traces_xml_ = cur; } #endif - else if (cname == "walkertraces") + else if (cname == "walkerlogs") { - walker_traces_xml_ = cur; + walker_logs_xml_ = cur; } else { @@ -633,7 +633,7 @@ bool QMCMain::runQMC(xmlNodePtr cur, bool reuse) #if !defined(REMOVE_TRACEMANAGER) qmc_driver->putTraces(traces_xml_); #endif - qmc_driver->putWalkerTraces(walker_traces_xml_); + qmc_driver->putWalkerLogs(walker_logs_xml_); { ScopedTimer qmc_run_timer(createGlobalTimer(qmc_driver->getEngineName(), timer_level_coarse)); Timer process_and_run; diff --git a/src/QMCApp/QMCMain.h b/src/QMCApp/QMCMain.h index b56c88e168..a5209cf909 100644 --- a/src/QMCApp/QMCMain.h +++ b/src/QMCApp/QMCMain.h @@ -79,8 +79,8 @@ class QMCMain : public MPIObjectBase, public QMCAppBase ///xml mcwalkerset read-in elements std::vector walker_set_in_; - ///walkertraces xml - xmlNodePtr walker_traces_xml_; + ///walkerlogs xml + xmlNodePtr walker_logs_xml_; ///traces xml xmlNodePtr traces_xml_; diff --git a/src/QMCDrivers/CloneManager.cpp b/src/QMCDrivers/CloneManager.cpp index 5703741294..63d3e739ba 100644 --- a/src/QMCDrivers/CloneManager.cpp +++ b/src/QMCDrivers/CloneManager.cpp @@ -27,7 +27,7 @@ #else using TraceManager = int; #endif -#include "Estimators/WalkerTraceManager.h" +#include "Estimators/WalkerLogManager.h" //comment this out to use only method to clone #define ENABLE_CLONE_PSI_AND_H @@ -87,7 +87,7 @@ CloneManager::~CloneManager() #if !defined(REMOVE_TRACEMANAGER) delete_iter(traceClones.begin(), traceClones.end()); #endif - delete_iter(wtrace_collectors.begin(), wtrace_collectors.end()); + delete_iter(wlog_collectors.begin(), wlog_collectors.end()); } void CloneManager::makeClones(MCWalkerConfiguration& w, TrialWaveFunction& psi, QMCHamiltonian& ham) diff --git a/src/QMCDrivers/CloneManager.h b/src/QMCDrivers/CloneManager.h index ab874ecadd..d8f41b962a 100644 --- a/src/QMCDrivers/CloneManager.h +++ b/src/QMCDrivers/CloneManager.h @@ -76,7 +76,7 @@ class CloneManager : public QMCTraits ///trace managers std::vector traceClones; ///trace collectors - std::vector wtrace_collectors; + std::vector wlog_collectors; //for correlated sampling. static std::vector> WPoolClones_uptr; diff --git a/src/QMCDrivers/Crowd.cpp b/src/QMCDrivers/Crowd.cpp index 1a8cb60686..58f85753e5 100644 --- a/src/QMCDrivers/Crowd.cpp +++ b/src/QMCDrivers/Crowd.cpp @@ -89,7 +89,7 @@ void Crowd::stopBlock() { estimator_manager_crowd_.stopBlock(); } void Crowd::collect(int current_step) { for (int iw = 0; iw < size(); ++iw) - wtrace_collector_.collect(mcp_walkers_[iw], walker_elecs_[iw], walker_twfs_[iw], walker_hamiltonians_[iw], current_step); + wlog_collector_.collect(mcp_walkers_[iw], walker_elecs_[iw], walker_twfs_[iw], walker_hamiltonians_[iw], current_step); } diff --git a/src/QMCDrivers/Crowd.h b/src/QMCDrivers/Crowd.h index e044de3173..a4b3f32200 100644 --- a/src/QMCDrivers/Crowd.h +++ b/src/QMCDrivers/Crowd.h @@ -16,14 +16,14 @@ #include "MultiWalkerDispatchers.h" #include "DriverWalkerTypes.h" #include "Estimators/EstimatorManagerCrowd.h" -#include "Estimators/WalkerTraceManager.h" +#include "Estimators/WalkerLogManager.h" namespace qmcplusplus { // forward declaration class ResourceCollection; class EstimatorManagerNew; -class WalkerTraceCollector; +class WalkerLogCollector; /** Driver synchronized step context * @@ -85,7 +85,7 @@ class Crowd estimator_manager_crowd_.accumulate(mcp_walkers_, walker_elecs_, walker_twfs_, walker_hamiltonians_, rng); } - /// Collect walker trace data + /// Collect walker log data void collect(int current_step); void setRNGForHamiltonian(RandomBase& rng); @@ -145,7 +145,7 @@ class Crowd unsigned long n_nonlocal_accept_ = 0; /** @} */ public: - WalkerTraceCollector wtrace_collector_; + WalkerLogCollector wlog_collector_; }; } // namespace qmcplusplus diff --git a/src/QMCDrivers/DMC/DMC.cpp b/src/QMCDrivers/DMC/DMC.cpp index ba0dee3ffb..60bf2ec21e 100644 --- a/src/QMCDrivers/DMC/DMC.cpp +++ b/src/QMCDrivers/DMC/DMC.cpp @@ -36,7 +36,7 @@ #else using TraceManager = int; #endif -#include "Estimators/WalkerTraceManager.h" +#include "Estimators/WalkerLogManager.h" namespace qmcplusplus { @@ -94,7 +94,7 @@ void DMC::resetUpdateEngines() Rng.resize(NumThreads); estimatorClones.resize(NumThreads, nullptr); traceClones.resize(NumThreads, nullptr); - wtrace_collectors.resize(NumThreads, nullptr); + wlog_collectors.resize(NumThreads, nullptr); FairDivideLow(W.getActiveWalkers(), NumThreads, wPerRank); { @@ -132,7 +132,7 @@ void DMC::resetUpdateEngines() #if !defined(REMOVE_TRACEMANAGER) traceClones[ip] = Traces->makeClone(); #endif - wtrace_collectors[ip] = wtrace_manager_->makeCollector(); + wlog_collectors[ip] = wlog_manager_->makeCollector(); Rng[ip] = rngs_[ip]->makeClone(); hClones[ip]->setRandomGenerator(Rng[ip].get()); if (W.isSpinor()) @@ -144,7 +144,7 @@ void DMC::resetUpdateEngines() Movers[ip]->setSpinMass(SpinMass); Movers[ip]->put(qmcNode); //Movers[ip]->resetRun(branchEngine.get(), estimatorClones[ip], traceClones[ip], DriftModifier); - Movers[ip]->resetRun2(branchEngine.get(), estimatorClones[ip], traceClones[ip], wtrace_collectors[ip], DriftModifier); + Movers[ip]->resetRun2(branchEngine.get(), estimatorClones[ip], traceClones[ip], wlog_collectors[ip], DriftModifier); Movers[ip]->initWalkersForPbyP(W.begin() + wPerRank[ip], W.begin() + wPerRank[ip + 1]); } else @@ -163,7 +163,7 @@ void DMC::resetUpdateEngines() Movers[ip]->put(qmcNode); //Movers[ip]->resetRun(branchEngine.get(), estimatorClones[ip], traceClones[ip], DriftModifier); - Movers[ip]->resetRun2(branchEngine.get(), estimatorClones[ip], traceClones[ip], wtrace_collectors[ip], DriftModifier); + Movers[ip]->resetRun2(branchEngine.get(), estimatorClones[ip], traceClones[ip], wlog_collectors[ip], DriftModifier); Movers[ip]->initWalkersForPbyP(W.begin() + wPerRank[ip], W.begin() + wPerRank[ip + 1]); } else @@ -174,7 +174,7 @@ void DMC::resetUpdateEngines() Movers[ip] = new DMCUpdateAllWithRejection(*wClones[ip], *psiClones[ip], *hClones[ip], *Rng[ip]); Movers[ip]->put(qmcNode); //Movers[ip]->resetRun(branchEngine.get(), estimatorClones[ip], traceClones[ip], DriftModifier); - Movers[ip]->resetRun2(branchEngine.get(), estimatorClones[ip], traceClones[ip], wtrace_collectors[ip], DriftModifier); + Movers[ip]->resetRun2(branchEngine.get(), estimatorClones[ip], traceClones[ip], wlog_collectors[ip], DriftModifier); Movers[ip]->initWalkers(W.begin() + wPerRank[ip], W.begin() + wPerRank[ip + 1]); } } @@ -239,7 +239,7 @@ bool DMC::run() #if !defined(REMOVE_TRACEMANAGER) Traces->startRun(nBlocks, traceClones); #endif - wtrace_manager_->startRun(wtrace_collectors); + wlog_manager_->startRun(wlog_collectors); IndexType block = 0; IndexType updatePeriod = (qmc_driver_mode[QMC_UPDATE_MODE]) ? Period4CheckProperties : (nBlocks + 1) * nSteps; int sample = 0; @@ -297,7 +297,7 @@ bool DMC::run() #if !defined(REMOVE_TRACEMANAGER) Traces->write_buffers(traceClones, block); #endif - wtrace_manager_->writeBuffers(wtrace_collectors); + wlog_manager_->writeBuffers(wlog_collectors); block++; if (DumpConfig && block % Period4CheckPoint == 0) { @@ -331,7 +331,7 @@ bool DMC::run() #if !defined(REMOVE_TRACEMANAGER) Traces->stopRun(); #endif - wtrace_manager_->stopRun(); + wlog_manager_->stopRun(); return finalize(nBlocks); } diff --git a/src/QMCDrivers/DMC/DMCBatched.cpp b/src/QMCDrivers/DMC/DMCBatched.cpp index e1f56dc556..f07f3c4894 100644 --- a/src/QMCDrivers/DMC/DMCBatched.cpp +++ b/src/QMCDrivers/DMC/DMCBatched.cpp @@ -288,7 +288,7 @@ void DMCBatched::advanceWalkers(const StateForThread& sft, crowd.accumulate(step_context.get_random_gen()); } - // collect walker traces + // collect walker logs crowd.collect(sft.current_step); { // T-moves @@ -433,12 +433,12 @@ bool DMCBatched::run() estimator_manager_->startDriverRun(); - //start walker trace manager - wtrace_manager_ = std::make_unique(walker_traces_input, allow_walker_traces, get_root_name(), myComm); - std::vector wtrace_collectors; + //start walker log manager + wlog_manager_ = std::make_unique(walker_logs_input, allow_walker_logs, get_root_name(), myComm); + std::vector wlog_collectors; for (auto& c: crowds_) - wtrace_collectors.push_back(&c->wtrace_collector_); - wtrace_manager_->startRun(wtrace_collectors); + wlog_collectors.push_back(&c->wlog_collector_); + wlog_manager_->startRun(wlog_collectors); StateForThread dmc_state(qmcdriver_input_, *drift_modifier_, *branch_engine_, population_, steps_per_block_); @@ -485,7 +485,7 @@ bool DMCBatched::run() for (UPtr& crowd : crowds_) { crowd->startBlock(steps_per_block_); - crowd->wtrace_collector_.startBlock(); + crowd->wlog_collector_.startBlock(); } for (int step = 0; step < steps_per_block_; ++step, ++current_step) @@ -516,7 +516,7 @@ bool DMCBatched::run() if (qmcdriver_input_.get_measure_imbalance()) measureImbalance("Block " + std::to_string(block)); endBlock(); - wtrace_manager_->writeBuffers(wtrace_collectors); + wlog_manager_->writeBuffers(wlog_collectors); recordBlock(block); } @@ -540,7 +540,7 @@ bool DMCBatched::run() print_mem("DMCBatched ends", app_log()); estimator_manager_->stopDriverRun(); - wtrace_manager_->stopRun(); + wlog_manager_->stopRun(); return finalize(num_blocks, true); } diff --git a/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp b/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp index 6d6a8e9c92..764612fd5d 100644 --- a/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp +++ b/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp @@ -24,7 +24,7 @@ #else using TraceManager = int; #endif -#include "Estimators/WalkerTraceManager.h" +#include "Estimators/WalkerLogManager.h" //#define TEST_INNERBRANCH @@ -171,8 +171,8 @@ void DMCUpdatePbyPWithRejectionFast::advanceWalker(Walker_t& thisWalker, bool re #if !defined(REMOVE_TRACEMANAGER) Traces->buffer_sample(W.current_step); #endif - if(wtrace_collector) - wtrace_collector->collect(thisWalker,W,Psi,H); + if(wlog_collector) + wlog_collector->collect(thisWalker,W,Psi,H); { ScopedTimer local_timer(myTimers[DMC_tmoves]); const int NonLocalMoveAcceptedTemp = H.makeNonLocalMoves(W); diff --git a/src/QMCDrivers/QMCDriver.cpp b/src/QMCDrivers/QMCDriver.cpp index d6affeff94..c300a4de77 100644 --- a/src/QMCDrivers/QMCDriver.cpp +++ b/src/QMCDrivers/QMCDriver.cpp @@ -36,8 +36,8 @@ #else using TraceManager = int; #endif -#include "Estimators/WalkerTraceInput.h" -#include "Estimators/WalkerTraceManager.h" +#include "Estimators/WalkerLogInput.h" +#include "Estimators/WalkerLogManager.h" namespace qmcplusplus { @@ -64,8 +64,8 @@ QMCDriver::QMCDriver(const ProjectData& project_data, DumpConfig = false; IsQMCDriver = true; allow_traces = false; - allow_walker_traces = false; - walker_traces_xml = NULL; + allow_walker_logs = false; + walker_logs_xml = NULL; MyCounter = 0; // value //accept multiple names for the same value @@ -206,10 +206,10 @@ void QMCDriver::process(xmlNodePtr cur) Traces->put(traces_xml, allow_traces, RootName); #endif //create and initialize traces - if (!wtrace_manager_) + if (!wlog_manager_) { - WalkerTraceInput walker_traces_input(walker_traces_xml); - wtrace_manager_ = std::make_unique(walker_traces_input, allow_walker_traces, RootName, myComm); + WalkerLogInput walker_logs_input(walker_logs_xml); + wlog_manager_ = std::make_unique(walker_logs_input, allow_walker_logs, RootName, myComm); } branchEngine->put(cur); Estimators->put(H, cur); diff --git a/src/QMCDrivers/QMCDriver.h b/src/QMCDrivers/QMCDriver.h index 826dce2fbc..5dec7bd951 100644 --- a/src/QMCDrivers/QMCDriver.h +++ b/src/QMCDrivers/QMCDriver.h @@ -31,7 +31,7 @@ #include "QMCWaveFunctions/WaveFunctionPool.h" #include "QMCHamiltonians/QMCHamiltonian.h" #include "Estimators/EstimatorManagerBase.h" -#include "Estimators/WalkerTraceManager.h" +#include "Estimators/WalkerLogManager.h" #include "QMCDrivers/DriverTraits.h" #include "QMCDrivers/QMCDriverInterface.h" #include "QMCDrivers/GreenFunctionModifiers/DriftModifierBase.h" @@ -63,7 +63,7 @@ namespace qmcplusplus class MCWalkerConfiguration; class HDFWalkerOutput; class TraceManager; -class WalkerTraceManager; +class WalkerLogManager; /** @ingroup QMCDrivers * @{ @@ -99,9 +99,9 @@ class QMCDriver : public QMCDriverInterface, public QMCTraits, public MPIObjectB xmlNodePtr traces_xml; /// whether to allow traces - bool allow_walker_traces; + bool allow_walker_logs; /// traces xml - xmlNodePtr walker_traces_xml; + xmlNodePtr walker_logs_xml; /// Constructor. QMCDriver(const ProjectData& project_data, @@ -156,9 +156,9 @@ class QMCDriver : public QMCDriverInterface, public QMCTraits, public MPIObjectB inline void requestTraces(bool traces) override { allow_traces = traces; } - inline void putWalkerTraces(xmlNodePtr txml) override { walker_traces_xml = txml; } + inline void putWalkerLogs(xmlNodePtr wlxml) override { walker_logs_xml = wlxml; } - inline void requestWalkerTraces(bool traces) override { allow_walker_traces = traces; } + inline void requestWalkerLogs(bool allow_walker_logs_) override { allow_walker_logs = allow_walker_logs_; } std::string getEngineName() override { return QMCType; } @@ -196,7 +196,7 @@ class QMCDriver : public QMCDriverInterface, public QMCTraits, public MPIObjectB std::unique_ptr Traces; ///Traces manager - std::unique_ptr wtrace_manager_; + std::unique_ptr wlog_manager_; ///return the random generators inline RefVector> getRngRefs() const diff --git a/src/QMCDrivers/QMCDriverFactory.cpp b/src/QMCDrivers/QMCDriverFactory.cpp index 413a4b6481..64ddf0bf5d 100644 --- a/src/QMCDrivers/QMCDriverFactory.cpp +++ b/src/QMCDrivers/QMCDriverFactory.cpp @@ -76,7 +76,7 @@ QMCDriverFactory::DriverAssemblyState QMCDriverFactory::readSection(xmlNodePtr c aAttrib.add(append_tag, "append"); aAttrib.add(profiling_tag, "profiling"); aAttrib.add(das.traces_tag, "trace"); - aAttrib.add(das.walkertraces_tag, "walkertrace"); + aAttrib.add(das.walkerlogs_tag, "walkerlog"); aAttrib.put(cur); das.append_run = (append_tag == "yes"); das.enable_profiling = (profiling_tag == "yes"); @@ -296,9 +296,9 @@ std::unique_ptr QMCDriverFactory::createQMCDriver(xmlNodePtr new_driver->requestTraces(allow_traces); //add trace information - bool allow_walker_traces = das.walkertraces_tag == "yes" || - (das.walkertraces_tag == "none" && (das.new_run_type == QMCRunType::VMC || das.new_run_type == QMCRunType::DMC || das.new_run_type == QMCRunType::VMC_BATCH || das.new_run_type == QMCRunType::DMC_BATCH)); - new_driver->requestWalkerTraces(allow_walker_traces); + bool allow_walker_logs = das.walkerlogs_tag == "yes" || + (das.walkerlogs_tag == "none" && (das.new_run_type == QMCRunType::VMC || das.new_run_type == QMCRunType::DMC || das.new_run_type == QMCRunType::VMC_BATCH || das.new_run_type == QMCRunType::DMC_BATCH)); + new_driver->requestWalkerLogs(allow_walker_logs); return new_driver; } diff --git a/src/QMCDrivers/QMCDriverFactory.h b/src/QMCDrivers/QMCDriverFactory.h index fc8800719f..e3397da8ea 100644 --- a/src/QMCDrivers/QMCDriverFactory.h +++ b/src/QMCDrivers/QMCDriverFactory.h @@ -47,7 +47,7 @@ class QMCDriverFactory bool append_run = false; bool enable_profiling = false; std::string traces_tag = "none"; - std::string walkertraces_tag = "none"; + std::string walkerlogs_tag = "none"; QMCRunType new_run_type = QMCRunType::DUMMY; }; diff --git a/src/QMCDrivers/QMCDriverInterface.h b/src/QMCDrivers/QMCDriverInterface.h index f425743071..6209ec31fe 100644 --- a/src/QMCDrivers/QMCDriverInterface.h +++ b/src/QMCDrivers/QMCDriverInterface.h @@ -49,8 +49,8 @@ class QMCDriverInterface virtual void putWalkers(std::vector& wset) = 0; virtual void putTraces(xmlNodePtr txml) = 0; virtual void requestTraces(bool allow_traces) = 0; - virtual void putWalkerTraces(xmlNodePtr txml) = 0; - virtual void requestWalkerTraces(bool allow_traces_) = 0; + virtual void putWalkerLogs(xmlNodePtr wlxml) = 0; + virtual void requestWalkerLogs(bool allow_walker_logs_) = 0; virtual void process(xmlNodePtr cur) = 0; virtual QMCRunType getRunType() = 0; virtual std::string getEngineName() = 0; diff --git a/src/QMCDrivers/QMCDriverNew.cpp b/src/QMCDrivers/QMCDriverNew.cpp index a1349d5f6c..edcab38c47 100644 --- a/src/QMCDrivers/QMCDriverNew.cpp +++ b/src/QMCDrivers/QMCDriverNew.cpp @@ -33,8 +33,8 @@ #include "Utilities/Timer.h" #include "Message/UniformCommunicateError.h" #include "EstimatorInputDelegates.h" -#include "Estimators/WalkerTraceInput.h" -#include "Estimators/WalkerTraceManager.h" +#include "Estimators/WalkerLogInput.h" +#include "Estimators/WalkerLogManager.h" namespace qmcplusplus @@ -380,15 +380,14 @@ void QMCDriverNew::initialLogEvaluation(int crowd_id, } -void QMCDriverNew::putWalkerTraces(xmlNodePtr txml) +void QMCDriverNew::putWalkerLogs(xmlNodePtr wlxml) { - walker_traces_input.present = false; - if(txml) + walker_logs_input.present = false; + if(wlxml) { - walker_traces_input.readXML(txml); - walker_traces_input.present = true; + walker_logs_input.readXML(wlxml); + walker_logs_input.present = true; } - app_log()<<"JTK walker traces present: "< class Communicate; @@ -52,7 +52,7 @@ namespace qmcplusplus { //forward declarations: Do not include headers if not needed class TraceManager; -class WalkerTraceManager; +class WalkerLogManager; class EstimatorManagerNew; class TrialWaveFunction; class QMCHamiltonian; @@ -103,11 +103,11 @@ class QMCDriverNew : public QMCDriverInterface, public MPIObjectBase */ std::bitset qmc_driver_mode_; - /// whether to allow walker traces - bool allow_walker_traces; - /// walker traces input - WalkerTraceInput walker_traces_input; - //xmlNodePtr walker_traces_xml; + /// whether to allow walker logs + bool allow_walker_logs; + /// walker logs input + WalkerLogInput walker_logs_input; + //xmlNodePtr walker_logs_xml; protected: /** This is a data structure strictly for QMCDriver and its derived classes @@ -249,9 +249,9 @@ class QMCDriverNew : public QMCDriverInterface, public MPIObjectBase void putTraces(xmlNodePtr txml) override {} void requestTraces(bool allow_traces) override {} - void putWalkerTraces(xmlNodePtr txml) override; + void putWalkerLogs(xmlNodePtr wlxml) override; - void requestWalkerTraces(bool allow_traces_) override { allow_walker_traces = allow_traces_; } + void requestWalkerLogs(bool allow_walker_logs_) override { allow_walker_logs = allow_walker_logs_; } // scales a MCCoords by sqrtTau. Chooses appropriate taus by CT template @@ -443,8 +443,8 @@ class QMCDriverNew : public QMCDriverInterface, public MPIObjectBase */ std::unique_ptr estimator_manager_; - /// walker trace manager - std::unique_ptr wtrace_manager_; + /// walker log manager + std::unique_ptr wlog_manager_; ///record engine for walkers std::unique_ptr wOut; diff --git a/src/QMCDrivers/QMCUpdateBase.cpp b/src/QMCDrivers/QMCUpdateBase.cpp index 5d42d70400..aefdc25a97 100644 --- a/src/QMCDrivers/QMCUpdateBase.cpp +++ b/src/QMCDrivers/QMCUpdateBase.cpp @@ -26,7 +26,7 @@ #else using TraceManager = int; #endif -#include "Estimators/WalkerTraceManager.h" +#include "Estimators/WalkerLogManager.h" namespace qmcplusplus { @@ -38,7 +38,7 @@ QMCUpdateBase::QMCUpdateBase(MCWalkerConfiguration& w, RandomBase& rg) : csoffset(0), Traces(0), - wtrace_collector(0), + wlog_collector(0), W(w), Psi(psi), Guide(guide), @@ -59,7 +59,7 @@ QMCUpdateBase::QMCUpdateBase(MCWalkerConfiguration& w, RandomBase& rg) : csoffset(0), Traces(0), - wtrace_collector(0), + wlog_collector(0), W(w), Psi(psi), Guide(psi), @@ -120,10 +120,10 @@ bool QMCUpdateBase::put(xmlNodePtr cur) void QMCUpdateBase::resetRun2(BranchEngineType* brancher, EstimatorManagerBase* est, TraceManager* traces, - WalkerTraceCollector* wtrace_collector_, + WalkerLogCollector* wlog_collector_, const DriftModifierBase* driftmodifer) { - wtrace_collector = wtrace_collector_; + wlog_collector = wlog_collector_; resetRun(brancher,est,traces,driftmodifer); } @@ -197,8 +197,8 @@ void QMCUpdateBase::startBlock(int steps) #if !defined(REMOVE_TRACEMANAGER) Traces->startBlock(steps); #endif - if(wtrace_collector) - wtrace_collector->startBlock(); + if(wlog_collector) + wlog_collector->startBlock(); nAccept = 0; nReject = 0; nAllRejected = 0; diff --git a/src/QMCDrivers/QMCUpdateBase.h b/src/QMCDrivers/QMCUpdateBase.h index c37d5fcc3b..4558ab7365 100644 --- a/src/QMCDrivers/QMCUpdateBase.h +++ b/src/QMCDrivers/QMCUpdateBase.h @@ -23,7 +23,7 @@ #include "QMCWaveFunctions/TrialWaveFunction.h" #include "QMCHamiltonians/QMCHamiltonian.h" #include "QMCHamiltonians/NonLocalTOperator.h" -#include "Estimators/WalkerTraceManager.h" +#include "Estimators/WalkerLogManager.h" #include "GreenFunctionModifiers/DriftModifierBase.h" #include "SimpleFixedNodeBranch.h" #include "DriverDebugChecks.h" @@ -32,7 +32,7 @@ namespace qmcplusplus { class TraceManager; -class WalkerTraceManager; +class WalkerLogManager; /** @ingroup QMC * @brief Base class for update methods for each step * @@ -106,7 +106,7 @@ class QMCUpdateBase : public QMCTraits void resetRun2(BranchEngineType* brancher, EstimatorManagerBase* est, TraceManager* traces, - WalkerTraceCollector* wtrace_collector_, + WalkerLogCollector* wlog_collector_, const DriftModifierBase* driftmodifer); inline RealType getTau() @@ -246,7 +246,7 @@ class QMCUpdateBase : public QMCTraits public: ///traces TraceManager* Traces; - WalkerTraceCollector* wtrace_collector; + WalkerLogCollector* wlog_collector; protected: ///update particle-by-particle diff --git a/src/QMCDrivers/VMC/VMC.cpp b/src/QMCDrivers/VMC/VMC.cpp index 6fe8a31bd9..84783e8444 100644 --- a/src/QMCDrivers/VMC/VMC.cpp +++ b/src/QMCDrivers/VMC/VMC.cpp @@ -32,7 +32,7 @@ #else using TraceManager = int; #endif -#include "Estimators/WalkerTraceManager.h" +#include "Estimators/WalkerLogManager.h" namespace qmcplusplus { @@ -67,7 +67,7 @@ bool VMC::run() #if !defined(REMOVE_TRACEMANAGER) Traces->startRun(nBlocks, traceClones); #endif - wtrace_manager_->startRun(wtrace_collectors); + wlog_manager_->startRun(wlog_collectors); LoopTimer<> vmc_loop; RunTimeControl<> runtimeControl(run_time_manager, MaxCPUSecs, myComm->getName(), myComm->rank() == 0); @@ -111,7 +111,7 @@ bool VMC::run() #if !defined(REMOVE_TRACEMANAGER) Traces->write_buffers(traceClones, block); #endif - wtrace_manager_->writeBuffers(wtrace_collectors); + wlog_manager_->writeBuffers(wlog_collectors); recordBlock(block); vmc_loop.stop(); @@ -134,7 +134,7 @@ bool VMC::run() #if !defined(REMOVE_TRACEMANAGER) Traces->stopRun(); #endif - wtrace_manager_->stopRun(); + wlog_manager_->stopRun(); //copy back the random states for (int ip = 0; ip < NumThreads; ++ip) rngs_[ip] = Rng[ip]->makeClone(); @@ -169,7 +169,7 @@ void VMC::resetRun() Movers.resize(NumThreads, nullptr); estimatorClones.resize(NumThreads, nullptr); traceClones.resize(NumThreads, nullptr); - wtrace_collectors.resize(NumThreads, nullptr); + wlog_collectors.resize(NumThreads, nullptr); Rng.resize(NumThreads); // hdf_archive::hdf_archive() is not thread-safe @@ -185,7 +185,7 @@ void VMC::resetRun() #if !defined(REMOVE_TRACEMANAGER) traceClones[ip] = Traces->makeClone(); #endif - wtrace_collectors[ip] = wtrace_manager_->makeCollector(); + wlog_collectors[ip] = wlog_manager_->makeCollector(); Rng[ip] = rngs_[ip]->makeClone(); hClones[ip]->setRandomGenerator(Rng[ip].get()); if (W.isSpinor()) @@ -267,7 +267,7 @@ void VMC::resetRun() //int ip=omp_get_thread_num(); Movers[ip]->put(qmcNode); //Movers[ip]->resetRun(branchEngine.get(), estimatorClones[ip], traceClones[ip], DriftModifier); - Movers[ip]->resetRun2(branchEngine.get(), estimatorClones[ip], traceClones[ip], wtrace_collectors[ip], DriftModifier); + Movers[ip]->resetRun2(branchEngine.get(), estimatorClones[ip], traceClones[ip], wlog_collectors[ip], DriftModifier); if (qmc_driver_mode[QMC_UPDATE_MODE]) Movers[ip]->initWalkersForPbyP(W.begin() + wPerRank[ip], W.begin() + wPerRank[ip + 1]); else diff --git a/src/QMCDrivers/VMC/VMCBatched.cpp b/src/QMCDrivers/VMC/VMCBatched.cpp index 305d521f1f..99950dbb31 100644 --- a/src/QMCDrivers/VMC/VMCBatched.cpp +++ b/src/QMCDrivers/VMC/VMCBatched.cpp @@ -21,7 +21,7 @@ #include "MemoryUsage.h" #include "QMCWaveFunctions/TWFGrads.hpp" #include "TauParams.hpp" -#include "WalkerTraceManager.h" +#include "WalkerLogManager.h" namespace qmcplusplus { @@ -216,7 +216,7 @@ void VMCBatched::advanceWalkers(const StateForThread& sft, crowd.accumulate(step_context.get_random_gen()); } - // collect walker traces + // collect walker logs crowd.collect(sft.current_step); // TODO: @@ -309,12 +309,12 @@ bool VMCBatched::run() IndexType num_blocks = qmcdriver_input_.get_max_blocks(); //start the main estimator estimator_manager_->startDriverRun(); - //start walker trace manager - wtrace_manager_ = std::make_unique(walker_traces_input, allow_walker_traces, get_root_name(), myComm); - std::vector wtrace_collectors; + //start walker log manager + wlog_manager_ = std::make_unique(walker_logs_input, allow_walker_logs, get_root_name(), myComm); + std::vector wlog_collectors; for (auto& c: crowds_) - wtrace_collectors.push_back(&c->wtrace_collector_); - wtrace_manager_->startRun(wtrace_collectors); + wlog_collectors.push_back(&c->wlog_collector_); + wlog_manager_->startRun(wlog_collectors); StateForThread vmc_state(qmcdriver_input_, vmcdriver_input_, *drift_modifier_, population_, steps_per_block_); @@ -383,7 +383,7 @@ bool VMCBatched::run() for (auto& crowd : crowds_) { crowd->startBlock(steps_per_block_); - crowd->wtrace_collector_.startBlock(); + crowd->wlog_collector_.startBlock(); } for (int step = 0; step < steps_per_block_; ++step, ++current_step) { @@ -405,7 +405,7 @@ bool VMCBatched::run() if (qmcdriver_input_.get_measure_imbalance()) measureImbalance("Block " + std::to_string(block)); endBlock(); - wtrace_manager_->writeBuffers(wtrace_collectors); + wlog_manager_->writeBuffers(wlog_collectors); recordBlock(block); } @@ -452,7 +452,7 @@ bool VMCBatched::run() print_mem("VMCBatched ends", app_log()); estimator_manager_->stopDriverRun(); - wtrace_manager_->stopRun(); + wlog_manager_->stopRun(); return finalize(num_blocks, true); } diff --git a/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp b/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp index eb27bb094e..8c3f60fb4e 100644 --- a/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp +++ b/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp @@ -134,8 +134,8 @@ void VMCUpdatePbyP::advanceWalker(Walker_t& thisWalker, bool recompute) #if !defined(REMOVE_TRACEMANAGER) Traces->buffer_sample(W.current_step); #endif - if(wtrace_collector) - wtrace_collector->collect(thisWalker,W,Psi,H); + if(wlog_collector) + wlog_collector->collect(thisWalker,W,Psi,H); if (!moved) ++nAllRejected; } diff --git a/src/QMCHamiltonians/CMakeLists.txt b/src/QMCHamiltonians/CMakeLists.txt index 4f30e3793f..2bd0babd9d 100644 --- a/src/QMCHamiltonians/CMakeLists.txt +++ b/src/QMCHamiltonians/CMakeLists.txt @@ -70,7 +70,7 @@ if(OHMMS_DIM MATCHES 3) ECPComponentBuilder_L2.cpp) if(NOT REMOVE_TRACEMANAGER) - set(HAMSRCS ${HAMSRCS} ../Estimators/TraceManager.cpp ../Estimators/WalkerTraceManager.cpp ReferencePoints.cpp SpaceGrid.cpp EnergyDensityEstimator.cpp + set(HAMSRCS ${HAMSRCS} ../Estimators/TraceManager.cpp ../Estimators/WalkerLogManager.cpp ReferencePoints.cpp SpaceGrid.cpp EnergyDensityEstimator.cpp DensityMatrices1B.cpp) endif() diff --git a/tests/scripts/check_wtraces.py b/tests/scripts/check_wlogs.py similarity index 89% rename from tests/scripts/check_wtraces.py rename to tests/scripts/check_wlogs.py index 45ead77251..bf4401483a 100755 --- a/tests/scripts/check_wtraces.py +++ b/tests/scripts/check_wlogs.py @@ -4,10 +4,10 @@ # Jaron Krogel/ORNL # Type the following to view documentation for command line inputs: -# >check_wtraces.py -h +# >check_wlogs.py -h # For usage examples, type: -# >check_wtraces.py -x +# >check_wlogs.py -x # check_traces.py packages obj and HDFreader classes from Nexus. # Note that h5py is required (which depends on numpy). @@ -552,7 +552,7 @@ def __init__(self,filepath=None,blocks=None): def read(self,filepath=None): - # Open the wtraces.h5 file + # Open the wlogs.h5 file hr = HDFreader(filepath) if not hr._success: self.error('hdf file read failed\nfile path: '+filepath) @@ -827,11 +827,11 @@ def __init__(self,options): trace_files = [] if mpi==1: - tf = os.path.join(path,prefix+'.wtraces.h5') + tf = os.path.join(path,prefix+'.wlogs.h5') trace_files.append(tf) else: for n in range(mpi): - tf = os.path.join(path,prefix+'.p'+str(n).zfill(3)+'.wtraces.h5') + tf = os.path.join(path,prefix+'.p'+str(n).zfill(3)+'.wlogs.h5') trace_files.append(tf) #end for #end if @@ -1058,182 +1058,6 @@ def pass_fail(self,passed,n): examples = ''' -=================================================================== -Example 1: QMCPACK VMC/DMC with scalar-only traces, single mpi task -=================================================================== - -Contents of QMCPACK input file (qmc.in.xml): --------------------------------------------- - - - ... - - - - ... - - - # write traces files w/o array info (scalars only) - - - # vmc run, scalars written to stat.h5 - - - ... - - - # dmc run, scalars written to stat.h5 - - - ... - - - - -QMCPACK execution: ------------------- -export OMP_NUM_THREADS=1 -mpirun -np qmcpack qmc.in.xml - -QMCPACK output files: ---------------------- -qmc.s000.qmc.xml -qmc.s000.scalar.dat -qmc.s000.stat.h5 -qmc.s000.traces.h5 -qmc.s001.cont.xml -qmc.s001.dmc.dat -qmc.s001.qmc.xml -qmc.s001.scalar.dat -qmc.s001.stat.h5 -qmc.s001.traces.h5 - -check_traces.py usage: ----------------------- -check_traces.py -p qmc -s '0,1' -m 'vmc,dmc' --dmc_steps_exclude=1 - -Either execute check_traces.py in /your/path/to/qmcpack/output as above, or do: - -check_traces.py -p qmc -s '0,1' -m 'vmc,dmc' --dmc_steps_exclude=1 /your/path/to/qmcpack/output - - -==================================================================== -Example 2: QMCPACK VMC/DMC, selective scalar traces, single mpi task -==================================================================== - -Contents of QMCPACK input file (qmc.in.xml): --------------------------------------------- - - - ... - - - - ... - - - # write traces files w/o array info (scalars only) - - - Kinetic ElecElec # only write traces of Kinetic and ElecElec - - - - # vmc run, scalars written to stat.h5 - - - ... - - - # dmc run, scalars written to stat.h5 - - - ... - - - - -QMCPACK execution: ------------------- -export OMP_NUM_THREADS=1 -mpirun -np qmcpack qmc.in.xml - -QMCPACK output files: ---------------------- -qmc.s000.qmc.xml -qmc.s000.scalar.dat -qmc.s000.stat.h5 -qmc.s000.traces.h5 -qmc.s001.cont.xml -qmc.s001.dmc.dat -qmc.s001.qmc.xml -qmc.s001.scalar.dat -qmc.s001.stat.h5 -qmc.s001.traces.h5 - -check_traces.py usage: ----------------------- -check_traces.py -p qmc -s '0,1' -m 'vmc,dmc' -q 'Kinetic,ElecElec' --dmc_steps_exclude=1 - - -=================================================================== -Example 3: QMCPACK VMC/DMC, selective array traces, single mpi task -=================================================================== - -Contents of QMCPACK input file (qmc.in.xml): --------------------------------------------- - - - ... - - - - ... - - - # write traces files w/ all scalar info and select array info - - - position Kinetic # write per-electron positions and kinetic energies - - - - # vmc run, scalars written to stat.h5 - - - ... - - - # dmc run, scalars written to stat.h5 - - - ... - - - - -QMCPACK execution: ------------------- -export OMP_NUM_THREADS=1 -mpirun -np qmcpack qmc.in.xml - -QMCPACK output files: ---------------------- -qmc.s000.qmc.xml -qmc.s000.scalar.dat -qmc.s000.stat.h5 -qmc.s000.traces.h5 -qmc.s001.cont.xml -qmc.s001.dmc.dat -qmc.s001.qmc.xml -qmc.s001.scalar.dat -qmc.s001.stat.h5 -qmc.s001.traces.h5 - -check_traces.py usage: ----------------------- -check_traces.py -p qmc -s '0,1' -m 'vmc,dmc' --psum --dmc_steps_exclude=1 - ''' @@ -1377,7 +1201,7 @@ def process_list(slist,type=lambda x: x): log('\n\nChecking series {} method={}'.format(series,method)) - # Read scalar.dat, stat.h5, dmc.dat, and *wtraces.h5 for the series + # Read scalar.dat, stat.h5, dmc.dat, and *wlogs.h5 for the series ta = TracesAnalyzer(options) # Check traces data against scalar/stat/dmc files diff --git a/tests/solids/diamondC_1x1x1_pp/CMakeLists.txt b/tests/solids/diamondC_1x1x1_pp/CMakeLists.txt index f9f6c97ade..16591dd222 100644 --- a/tests/solids/diamondC_1x1x1_pp/CMakeLists.txt +++ b/tests/solids/diamondC_1x1x1_pp/CMakeLists.txt @@ -1876,14 +1876,14 @@ if(add_traces_tests) --dmc_steps_exclude=1) simple_run_and_check( - deterministic-diamondC_1x1x1_pp-vmc-walkertrace_scalars + deterministic-diamondC_1x1x1_pp-vmc-walkerlog_scalars "${qmcpack_SOURCE_DIR}/tests/solids/diamondC_1x1x1_pp" - qmc_walkertrace_vmc_scalars.in.xml + qmc_walkerlog_vmc_scalars.in.xml 1 1 - check_wtraces.py + check_wlogs.py -p - qmc_trace_vmc_scalars + qmc_wlog_vmc_scalars -s 0 -m @@ -1891,14 +1891,14 @@ if(add_traces_tests) --dmc_steps_exclude=1) simple_run_and_check( - deterministic-diamondC_1x1x1_pp-vmc-walkertrace_scalars + deterministic-diamondC_1x1x1_pp-vmc-walkerlog_scalars "${qmcpack_SOURCE_DIR}/tests/solids/diamondC_1x1x1_pp" - qmc_walkertrace_vmc_scalars.in.xml + qmc_walkerlog_vmc_scalars.in.xml 4 4 - check_wtraces.py + check_wlogs.py -p - qmc_trace_vmc_scalars + qmc_wlog_vmc_scalars -n 4 -s @@ -1908,14 +1908,14 @@ if(add_traces_tests) --dmc_steps_exclude=1) simple_run_and_check( - deterministic-diamondC_1x1x1_pp-dmc-walkertrace_scalars + deterministic-diamondC_1x1x1_pp-dmc-walkerlog_scalars "${qmcpack_SOURCE_DIR}/tests/solids/diamondC_1x1x1_pp" - qmc_walkertrace_dmc_scalars.in.xml + qmc_walkerlog_dmc_scalars.in.xml 4 4 - check_wtraces.py + check_wlogs.py -p - qmc_trace_dmc_scalars + qmc_wlog_dmc_scalars -n 4 -s @@ -1925,14 +1925,14 @@ if(add_traces_tests) --dmc_steps_exclude=1) simple_run_and_check( - deterministic-diamondC_1x1x1_pp-vmcbatch-walkertrace_scalars + deterministic-diamondC_1x1x1_pp-vmcbatch-walkerlog_scalars "${qmcpack_SOURCE_DIR}/tests/solids/diamondC_1x1x1_pp" - qmc_walkertrace_vmcbatch_scalars.in.xml + qmc_walkerlog_vmcbatch_scalars.in.xml 1 1 - check_wtraces.py + check_wlogs.py -p - qmc_trace_vmcbatch_scalars + qmc_wlog_vmcbatch_scalars -s 0 -m @@ -1940,14 +1940,14 @@ if(add_traces_tests) --dmc_steps_exclude=1) simple_run_and_check( - deterministic-diamondC_1x1x1_pp-vmcbatch-walkertrace_scalars + deterministic-diamondC_1x1x1_pp-vmcbatch-walkerlog_scalars "${qmcpack_SOURCE_DIR}/tests/solids/diamondC_1x1x1_pp" - qmc_walkertrace_vmcbatch_scalars.in.xml + qmc_walkerlog_vmcbatch_scalars.in.xml 4 4 - check_wtraces.py + check_wlogs.py -p - qmc_trace_vmcbatch_scalars + qmc_wlog_vmcbatch_scalars -n 4 -s @@ -1957,14 +1957,14 @@ if(add_traces_tests) --dmc_steps_exclude=1) simple_run_and_check( - deterministic-diamondC_1x1x1_pp-dmcbatch-walkertrace_scalars + deterministic-diamondC_1x1x1_pp-dmcbatch-walkerlog_scalars "${qmcpack_SOURCE_DIR}/tests/solids/diamondC_1x1x1_pp" - qmc_walkertrace_dmcbatch_scalars.in.xml + qmc_walkerlog_dmcbatch_scalars.in.xml 4 4 - check_wtraces.py + check_wlogs.py -p - qmc_trace_dmcbatch_scalars + qmc_wlog_dmcbatch_scalars -n 4 -s diff --git a/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_dmc_scalars.in.xml b/tests/solids/diamondC_1x1x1_pp/qmc_walkerlog_dmc_scalars.in.xml similarity index 98% rename from tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_dmc_scalars.in.xml rename to tests/solids/diamondC_1x1x1_pp/qmc_walkerlog_dmc_scalars.in.xml index c98c34b5a3..e73b6b8e92 100644 --- a/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_dmc_scalars.in.xml +++ b/tests/solids/diamondC_1x1x1_pp/qmc_walkerlog_dmc_scalars.in.xml @@ -1,6 +1,6 @@ - + @@ -79,7 +79,7 @@ - + 2 diff --git a/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_dmcbatch_scalars.in.xml b/tests/solids/diamondC_1x1x1_pp/qmc_walkerlog_dmcbatch_scalars.in.xml similarity index 98% rename from tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_dmcbatch_scalars.in.xml rename to tests/solids/diamondC_1x1x1_pp/qmc_walkerlog_dmcbatch_scalars.in.xml index 82840dbf9a..f7ea95fcb4 100644 --- a/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_dmcbatch_scalars.in.xml +++ b/tests/solids/diamondC_1x1x1_pp/qmc_walkerlog_dmcbatch_scalars.in.xml @@ -1,6 +1,6 @@ - + batched @@ -80,7 +80,7 @@ - + 2 2 diff --git a/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_vmc_scalars.in.xml b/tests/solids/diamondC_1x1x1_pp/qmc_walkerlog_vmc_scalars.in.xml similarity index 98% rename from tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_vmc_scalars.in.xml rename to tests/solids/diamondC_1x1x1_pp/qmc_walkerlog_vmc_scalars.in.xml index 018b90d376..cccb03e6b9 100644 --- a/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_vmc_scalars.in.xml +++ b/tests/solids/diamondC_1x1x1_pp/qmc_walkerlog_vmc_scalars.in.xml @@ -1,6 +1,6 @@ - + @@ -79,7 +79,7 @@ - + 2 diff --git a/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_vmcbatch_scalars.in.xml b/tests/solids/diamondC_1x1x1_pp/qmc_walkerlog_vmcbatch_scalars.in.xml similarity index 98% rename from tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_vmcbatch_scalars.in.xml rename to tests/solids/diamondC_1x1x1_pp/qmc_walkerlog_vmcbatch_scalars.in.xml index f6026886ba..c6fa42d513 100644 --- a/tests/solids/diamondC_1x1x1_pp/qmc_walkertrace_vmcbatch_scalars.in.xml +++ b/tests/solids/diamondC_1x1x1_pp/qmc_walkerlog_vmcbatch_scalars.in.xml @@ -1,6 +1,6 @@ - + batched @@ -80,7 +80,7 @@ - + 2 2 From 22ea904de8df37f169e8f18f100c1b8b89e18b9f Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Thu, 6 Jun 2024 16:31:43 -0400 Subject: [PATCH 48/55] one more --- docs/methods.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/methods.rst b/docs/methods.rst index 8421f801b1..236f118716 100644 --- a/docs/methods.rst +++ b/docs/methods.rst @@ -1899,10 +1899,10 @@ declaration to ensure correct sampling: -.. _walker_logs +.. _walker_logging -Walker Data Logs -================== +Walker Data Logging +=================== Detailed per-walker information can be written to HDF5 files for VMC or DMC by including the XML element. This includes the LocalEnergy and @@ -1914,7 +1914,7 @@ potentially requiring a huge amount of disk space. **Input specification** -The default walker data tracing functionality is enabled by including the +The default walker data logging functionality is enabled by including the XML element (once) just before the QMC driver sections, for example: From 157dda366eacd4dd7b3254b9edf7bef433200963 Mon Sep 17 00:00:00 2001 From: Ye Luo Date: Mon, 10 Jun 2024 21:46:37 -0500 Subject: [PATCH 49/55] Correct CMake and include. --- src/Estimators/CMakeLists.txt | 2 - src/Estimators/WalkerLogBuffer.h | 376 ------------------ src/Estimators/WalkerLogCollector.cpp | 187 --------- src/Estimators/WalkerLogCollector.h | 121 ------ src/Estimators/WalkerLogInput.h | 46 --- src/Estimators/WalkerLogManager.cpp | 344 ---------------- src/Estimators/WalkerLogManager.h | 130 ------ src/Estimators/tests/CMakeLists.txt | 1 - .../tests/test_WalkerLogCollector.cpp | 136 ------- src/QMCDrivers/CloneManager.cpp | 2 +- src/QMCDrivers/Crowd.h | 2 +- src/QMCDrivers/DMC/DMC.cpp | 2 +- src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp | 2 +- src/QMCDrivers/QMCDriver.cpp | 4 +- src/QMCDrivers/QMCDriver.h | 2 +- src/QMCDrivers/QMCDriverNew.cpp | 4 +- src/QMCDrivers/QMCDriverNew.h | 2 +- src/QMCDrivers/QMCUpdateBase.cpp | 2 +- src/QMCDrivers/QMCUpdateBase.h | 2 +- src/QMCDrivers/VMC/VMC.cpp | 2 +- src/QMCHamiltonians/CMakeLists.txt | 2 +- 21 files changed, 14 insertions(+), 1357 deletions(-) delete mode 100644 src/Estimators/WalkerLogBuffer.h delete mode 100644 src/Estimators/WalkerLogCollector.cpp delete mode 100644 src/Estimators/WalkerLogCollector.h delete mode 100644 src/Estimators/WalkerLogInput.h delete mode 100644 src/Estimators/WalkerLogManager.cpp delete mode 100644 src/Estimators/WalkerLogManager.h delete mode 100644 src/Estimators/tests/test_WalkerLogCollector.cpp diff --git a/src/Estimators/CMakeLists.txt b/src/Estimators/CMakeLists.txt index 56aa91bee7..7f37bc99ff 100644 --- a/src/Estimators/CMakeLists.txt +++ b/src/Estimators/CMakeLists.txt @@ -26,8 +26,6 @@ set(QMCEST_SRC EstimatorManagerBase.cpp EstimatorManagerNew.cpp EstimatorManagerCrowd.cpp - WalkerLogCollector.cpp - WalkerLogManager.cpp CollectablesEstimator.cpp OperatorEstBase.cpp SpinDensityNew.cpp diff --git a/src/Estimators/WalkerLogBuffer.h b/src/Estimators/WalkerLogBuffer.h deleted file mode 100644 index 765f9c1f68..0000000000 --- a/src/Estimators/WalkerLogBuffer.h +++ /dev/null @@ -1,376 +0,0 @@ -////////////////////////////////////////////////////////////////////////////////////// -// This file is distributed under the University of Illinois/NCSA Open Source License. -// See LICENSE file in top directory for details. -// -// Copyright (c) 2024 QMCPACK developers. -// -// File developed by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory -// -// File created by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory -////////////////////////////////////////////////////////////////////////////////////// - - -#ifndef QMCPLUSPLUS_WALKERLOGBUFFER_H -#define QMCPLUSPLUS_WALKERLOGBUFFER_H - - -#include -#include "OhmmsPETE/OhmmsArray.h" -#include "hdf/hdf_archive.h" - -#include - - - -namespace qmcplusplus -{ - - -/// Basic data types for walker log data -struct WLog -{ - using Int = long; // integer type - using Real = OHMMS_PRECISION_FULL; // real type - using Comp = std::complex; // complex type -#ifndef QMC_COMPLEX - using PsiVal = Real; // wavefunction type -#else - using PsiVal = Comp; // wavefunction type -#endif -}; - - -/** Record for an individual walker quantity being logd. - * - * Helper struct for WalkerLogBuffer. - */ -struct WalkerQuantityInfo -{ - /// quantity name - std::string name; - /// support up to 4D array quantity - enum{D0=0,D1,D2,D3,DMAX}; - /// array dimension - size_t dimension; - /// total size - size_t size; - /// size of 1 unit of data - size_t unit_size; - /// array shape - TinyVector shape; - /// starting row index in buffer - size_t buffer_start; - /// end range in buffer row - size_t buffer_end; - - WalkerQuantityInfo(const std::string& name_,size_t unit_size_,size_t buffer_start_,size_t n1=1,size_t n2=0,size_t n3=0,size_t n4=0) - { - name = name_; - unit_size = unit_size_; - buffer_start = buffer_start_; - shape[D0] = n1; - shape[D1] = n2; - shape[D2] = n3; - shape[D3] = n4; - - dimension = 0; - size = 1; - for (size_t d=0;d0) - { - dimension++; - size *= shape[d]; - } - buffer_end = buffer_start + size*unit_size; - } -}; - - - -/** Data buffer for walker log quantities. - * - * Each row in the buffer contains all quantities for one walker from a single step. - * Rows are added throughout an MC block. - * See WalkerLogCollector::collect() - * - * Buffer data is written to HDF at the end of each MC block. - * See WalkerLogManager::writeBuffers() - */ -template -class WalkerLogBuffer -{ -public: - /// label for this data in HDF file - std::string label; - /// marks first WalkerLogCollector::collect() call - bool first_collect; - /// HDF file pointer - hsize_t hdf_file_pointer; - -private: - /// index of current quantity during WalkerLogCollector::collect() - size_t quantity_pointer; - /** buffer row location data for each walker quantity - * used to populate "data_layout" field in HDF file - */ - std::vector quantity_info; - /// total size of walker data stored in a buffer row - size_t walker_data_size; - /// the walker data buffer itself - Array buffer; - /// array dimensions used in HDF file write - hsize_t dims[2]; - -public: - WalkerLogBuffer() - { - label = "?"; - first_collect = true; - walker_data_size = 0; - quantity_pointer = 0; - resetBuffer(); - } - - /// current number of rows in the data buffer - inline size_t nrows() { return buffer.size(0); } - - /// current number of columns in the data buffer (row size) - inline size_t ncols() { return buffer.size(1); } - - /// resize the buffer to zero - inline void resetBuffer() { buffer.resize(0, buffer.size(1)); } - - /// reset member variables at end of each WalkerLogCollector::collect() call - inline void resetCollect() - { - if(quantity_pointer!=quantity_info.size()) - throw std::runtime_error("WalkerLogBuffer quantity_pointer has not been moved through all quantities prior during collect() call."); - first_collect = false; - quantity_pointer = 0; - } - - /// compare row size of this buffer to another one - inline bool sameAs(const WalkerLogBuffer& ref) { return buffer.size(1) == ref.buffer.size(1); } - - /// collect data for a single walker quantity of scalar type into the current buffer row - inline void collect(const std::string& name, const T& value) - { - size_t irow=0; - if( first_collect ) - {// cache walker quantity info on first collect - WalkerQuantityInfo wqi_(name,1,walker_data_size); - quantity_info.push_back(wqi_); - walker_data_size = wqi_.buffer_end; - resetRowSize(walker_data_size); - } - else - {// make a new buffer row if needed - if(quantity_pointer==0) - makeNewRow(); - irow = buffer.size(0)-1; - } - // place the scalar walker quantity into the current buffer row - auto& wqi = quantity_info[quantity_pointer]; - buffer(irow,wqi.buffer_start) = value; - quantity_pointer++; - } - - - /// collect data for a single walker quantity of array type into the current buffer row - template - inline void collect(const std::string& name, Array arr) - { - size_t n1 = arr.size(0); - size_t n2,n3,n4; - n2=n3=n4=0; - if (D>4) - throw std::runtime_error("WalkerLogBuffer::collect Only arrays up to dimension 4 are currently supported."); - if (D>1) n2 = arr.size(1); - if (D>2) n3 = arr.size(2); - if (D>3) n4 = arr.size(3); - size_t irow=0; - if( first_collect ) - {// cache walker quantity info on first collect - WalkerQuantityInfo wqi_(name,1,walker_data_size,n1,n2,n3,n4); - quantity_info.push_back(wqi_); - walker_data_size = wqi_.buffer_end; - resetRowSize(walker_data_size); - } - else - {// make a new buffer row if needed - if(quantity_pointer==0) - makeNewRow(); - irow = buffer.size(0)-1; - } - // place the array walker quantity into the current buffer row - auto& wqi = quantity_info[quantity_pointer]; - auto& arr1d = arr.storage(); - for (size_t n=0;n - inline void collect(const std::string& name, Array,D> arr) - { - size_t n1 = arr.size(0); - size_t n2,n3,n4; - n2=n3=n4=0; - if (D>4) - throw std::runtime_error("WalkerLogBuffer::collect Only arrays up to dimension 4 are currently supported."); - if (D>1) n2 = arr.size(1); - if (D>2) n3 = arr.size(2); - if (D>3) n4 = arr.size(3); - size_t irow=0; - if( first_collect ) - {// cache walker quantity info on first collect - WalkerQuantityInfo wqi_(name,2,walker_data_size,n1,n2,n3,n4); - quantity_info.push_back(wqi_); - walker_data_size = wqi_.buffer_end; - resetRowSize(walker_data_size); - } - else - {// make a new buffer row if needed - if(quantity_pointer==0) - makeNewRow(); - irow = buffer.size(0)-1; - } - // place the complex array walker quantity into the current buffer row - auto& wqi = quantity_info[quantity_pointer]; - auto& arr1d = arr.storage(); - size_t n = 0; - for (size_t i=0;i other, size_t i) - { - auto& other_buffer = other.buffer; - if (first_collect) - { - resetRowSize(other_buffer.size(1)); - quantity_info = other.quantity_info; - first_collect = false; - } - else - { - if(buffer.size(1)!=other_buffer.size(1)) - throw std::runtime_error("WalkerLogBuffer::add_row Row sizes must match."); - makeNewRow(); - } - size_t ib = buffer.size(0)-1; - for(size_t j=0;j 0) - { - f.push(top); - h5d_append(f.top(), "data", file_pointer, buffer.dim(), dims, buffer.data()); - f.pop(); - } - f.flush(); - } - -private: - /// make space as quantities are added to the buffer for the first time - inline void resetRowSize(size_t row_size) - { - auto nrows = buffer.size(0); - if(nrows==0) - nrows++; - if(nrows!=1) - throw std::runtime_error("WalkerLogBuffer::reset_rowsize row_size (number of columns) should only be changed during growth of the first row."); - auto buffer_old(buffer); - buffer.resize(nrows,row_size); - std::copy_n(buffer_old.data(), buffer_old.size(), buffer.data()); - if(buffer.size(0)!=1) - throw std::runtime_error("WalkerLogBuffer::reset_rowsize buffer should contain only a single row upon completion."); - if(buffer.size(1)!=row_size) - throw std::runtime_error("WalkerLogBuffer::reset_rowsize length of buffer row should match the requested row_size following the reset/udpate."); - } - - /// allocate a full new row at the end of the buffer - inline void makeNewRow() - { - size_t nrows = buffer.size(0); - size_t row_size = buffer.size(1); - if (row_size==0) - throw std::runtime_error("WalkerLogBuffer::makeNewRow Cannot make a new row of size zero."); - nrows++; - // resizing buffer(type Array) doesn't preserve data. Thus keep old data and copy over - auto buffer_old(buffer); - buffer.resize(nrows, row_size); - std::copy_n(buffer_old.data(), buffer_old.size(), buffer.data()); - } - -}; - - -} // namespace qmcplusplus - -#endif diff --git a/src/Estimators/WalkerLogCollector.cpp b/src/Estimators/WalkerLogCollector.cpp deleted file mode 100644 index dca5820a68..0000000000 --- a/src/Estimators/WalkerLogCollector.cpp +++ /dev/null @@ -1,187 +0,0 @@ -////////////////////////////////////////////////////////////////////////////////////// -// This file is distributed under the University of Illinois/NCSA Open Source License. -// See LICENSE file in top directory for details. -// -// Copyright (c) 2024 QMCPACK developers. -// -// File developed by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory -// -// File created by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory -////////////////////////////////////////////////////////////////////////////////////// - - -#include "WalkerLogCollector.h" - -#include "Particle/Walker.h" -#include "Particle/ParticleSet.h" -#include "QMCWaveFunctions/TrialWaveFunction.h" -#include "QMCHamiltonians/QMCHamiltonian.h" - - - -namespace qmcplusplus -{ - -using MCPWalker = Walker; - - -WalkerLogCollector::WalkerLogCollector() - : properties_include{"R2Accepted","R2Proposed","LocalEnergy","LocalPotential","Kinetic","ElecElec","ElecIon","LocalECP","NonLocalECP"} -{ - state.reset(); - energy_index = -1; - // empty walker steps and energy vectors for the MC block - steps.resize(0); - energies.resize(0); - // label the buffers for HDF file write - walker_property_int_buffer.label = "walker_property_int"; - walker_property_real_buffer.label = "walker_property_real"; - walker_particle_real_buffer.label = "walker_particle_real"; -} - - -void WalkerLogCollector::startBlock() -{ - if(!state.logs_active) return; // no-op for driver if logs are inactive - if (state.verbose) app_log() << "WalkerLogCollector::startBlock " << std::endl; - resetBuffers(); // resize buffers to zero rows -} - - -void WalkerLogCollector::collect(const MCPWalker& walker, const ParticleSet& pset, const TrialWaveFunction& wfn, const QMCHamiltonian& ham, int step) -{ - if(!state.logs_active) return; // no-op for driver if logs are inactive - - // only collect walker data at steps matching the period (default 1) - int current_step = (step==-1) ? pset.current_step : step; - if(current_step%state.step_period!=0) return; - - auto& bsi = walker_property_int_buffer; - auto& bsr = walker_property_real_buffer; - auto& bar = walker_particle_real_buffer; - - // collect per-particle walker quantities - size_t nparticles = walker.R.size(); - size_t ndim = walker.R[0].size(); - // per-particle positions (walker.R) - Rtmp.resize(nparticles,ndim); - for(size_t p=0;p::max(); - for(size_t n=0; n class Walker; -class ParticleSet; -class TrialWaveFunction; -class QMCHamiltonian; -using MCPWalker = Walker; - - - -/// Helper struct holding data transferred from WalkerLogManager to WalkerLogCollector following input read -struct WalkerLogState -{ - /// whether logs are active in the current driver - bool logs_active; - /// period between MC steps for data collection - int step_period; - /// controls verbosity of log file writes - bool verbose; - - WalkerLogState() - { - reset(); - step_period = 1; - } - - inline void reset() - { - logs_active = false; - verbose = false; - } -}; - - -/** Crowd-level resource for walker log collection. - * - * Contains data buffers for walker properties and walker particle data. - * Data buffers are resized to zero at the start of an MC block. - * Data for all walkers is collected into the buffers each MC step in an MC block. - * This class is not responsible for I/O. - */ -class WalkerLogCollector -{ -public: - /// MC step information for each walker throughout the MC block - std::vector steps; - /// LocalEnergy information for each walker throughout the MC block - std::vector energies; - /// buffer containing integer walker properties - WalkerLogBuffer walker_property_int_buffer; - /// buffer containing real-valued walker properties - WalkerLogBuffer walker_property_real_buffer; - /// buffer containing per-particle walker data - WalkerLogBuffer walker_particle_real_buffer; - - /// ParticleSet::PropertyList quantities to include - std::unordered_set properties_include; - /// indices in ParticleSet::PropertyList for included quantities - std::vector property_indices; - /// location of LocalEnergy in ParticleSet::PropertyList - int energy_index; - - /// state data set by WalkerLogManager - WalkerLogState state; - -private: - // temporary (contiguous) storage for awful ParticleAttrib<> quantities - /// tmp storage for walker positions - Array Rtmp; - /// tmp storage for walker spins - Array Stmp; - /// tmp storage for walker wavefunction gradients - Array Gtmp; - /// tmp storage for walker wavefunciton laplacians - Array Ltmp; - -public: - WalkerLogCollector(); - - /// resize buffers to zero rows at beginning of each MC block - void startBlock(); - - /// collect all data for one walker into the data buffers - void collect(const MCPWalker& walker, const ParticleSet& pset, const TrialWaveFunction& wfn, const QMCHamiltonian& ham, int step=-1); - - /** Check that all buffers have the same number of rows. - * This ensures that the full data for a given walker can be reconstructed due to enforced data alignment in the buffers. - */ - void checkBuffers(); - -private: - /// resize buffers to zero rows - void resetBuffers(); -}; - - - - - -} // namespace qmcplusplus - -#endif diff --git a/src/Estimators/WalkerLogInput.h b/src/Estimators/WalkerLogInput.h deleted file mode 100644 index 7bff8274af..0000000000 --- a/src/Estimators/WalkerLogInput.h +++ /dev/null @@ -1,46 +0,0 @@ -////////////////////////////////////////////////////////////////////////////////////// -// This file is distributed under the University of Illinois/NCSA Open Source License. -// See LICENSE file in top directory for details. -// -// Copyright (c) 2024 QMCPACK developers. -// -// File developed by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory -// -////////////////////////////////////////////////////////////////////////////////////// -#ifndef QMCPLUSPLUS_WALKERLOGINPUT_H -#define QMCPLUSPLUS_WALKERLOGINPUT_H - -#include "InputSection.h" - -namespace qmcplusplus -{ - -/** Native representation for walker logs input - */ -struct WalkerLogInput : public InputSection -{ - bool present; - - WalkerLogInput() : WalkerLogInput(NULL) {} - - WalkerLogInput(xmlNodePtr cur) - { - section_name = "walkerlogs"; - attributes = {"step_period", "particle", "min", "max", "median", "quantiles", "verbose"}; - integers = {"step_period"}; - bools = {"particle", "min", "max", "median", "quantiles", "verbose"}; - default_values = {{"step_period", int(1)}, - {"particle" , bool(false)}, - {"min" , bool(true)}, - {"max" , bool(true)}, - {"median" , bool(true)}, - {"quantiles" , bool(true)}, - {"verbose" , bool(false)}}; - present = cur!=NULL; - if(present) - readXML(cur); - }; -}; - -} // namespace qmcplusplus -#endif /* WALKERLOGINPUT_H */ diff --git a/src/Estimators/WalkerLogManager.cpp b/src/Estimators/WalkerLogManager.cpp deleted file mode 100644 index 1d9c539270..0000000000 --- a/src/Estimators/WalkerLogManager.cpp +++ /dev/null @@ -1,344 +0,0 @@ -////////////////////////////////////////////////////////////////////////////////////// -// This file is distributed under the University of Illinois/NCSA Open Source License. -// See LICENSE file in top directory for details. -// -// Copyright (c) 2024 QMCPACK developers. -// -// File developed by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory -// -// File created by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory -////////////////////////////////////////////////////////////////////////////////////// - -#include "WalkerLogManager.h" -#include "WalkerLogInput.h" -#include "Concurrency/OpenMP.h" - - -namespace qmcplusplus -{ - - -WalkerLogManager::WalkerLogManager(WalkerLogInput& inp, bool allow_logs, std::string series_root, Communicate* comm) -{ - state.reset(); - communicator = comm; - file_root = series_root; - bool driver_allows_logs = allow_logs; // driver allows logs or not - - bool logs_requested = inp.present; // xml input present or not - // determine whether walker logs will be active - state.logs_active = logs_requested && driver_allows_logs; - - if (state.logs_active) - { - if (omp_get_thread_num() == 0) - { - app_log() << "\n WalkerLogManager::put() " << std::endl; - app_log() << " logs requested : " << logs_requested << std::endl; - app_log() << " driver allows logs : " << driver_allows_logs << std::endl; - app_log() << " logs active : " << state.logs_active << std::endl; - app_log() << std::endl; - } - // retrieve input data - state.step_period = inp.get("step_period"); - state.verbose = inp.get("verbose"); - bool quantiles = inp.get("quantiles"); - write_particle_data = inp.get("particle"); - write_min_data = inp.get("min") && quantiles; - write_max_data = inp.get("max") && quantiles; - write_med_data = inp.get("median") && quantiles; - } - - // label min energy walker buffers for HDF file write - wmin_property_int_buffer.label = "wmin_property_int"; - wmin_property_real_buffer.label = "wmin_property_real"; - wmin_particle_real_buffer.label = "wmin_particle_real"; - - // label max energy walker buffers for HDF file write - wmax_property_int_buffer.label = "wmax_property_int"; - wmax_property_real_buffer.label = "wmax_property_real"; - wmax_particle_real_buffer.label = "wmax_particle_real"; - - // label median energy walker buffers for HDF file write - wmed_property_int_buffer.label = "wmed_property_int"; - wmed_property_real_buffer.label = "wmed_property_real"; - wmed_particle_real_buffer.label = "wmed_particle_real"; - - // walker quantity information ("data_layout") has not be put in the HDF file yet - registered_hdf = false; -} - - -WalkerLogCollector* WalkerLogManager::makeCollector() -{ - if (state.verbose) app_log() << "WalkerLogManager::makeCollector " << std::endl; - WalkerLogCollector* tc = new WalkerLogCollector(); - tc->state = state; - return tc; -} - - -void WalkerLogManager::startRun(std::vector& collectors) -{ - if (!state.logs_active) return; // no-op for driver if logs are inactive - if (state.verbose) app_log() << "WalkerLogManager::startRun " << std::endl; - // transfer step_period, verbosity, etc settings to log collectors - for (auto& tc: collectors) - tc->state = state; - // check data size consistency among the log collector buffers - checkCollectors(collectors); - // open the logs file - openFile(collectors); -} - - -void WalkerLogManager::stopRun() -{ - if (!state.logs_active) return; // no-op for driver if logs are inactive - if (state.verbose) app_log() << "WalkerLogManager::stopRun " << std::endl; - // close the logs file - closeFile(); -} - - -void WalkerLogManager::writeBuffers(std::vector& collectors) -{ - if (!state.logs_active) return; // no-op for driver if logs are inactive - if (state.verbose) app_log() << "WalkerLogManager::writeBuffers "<(v); - if (n==0) - { - n1 = n; - prev_step = step; - } - if (step!=prev_step || n==energy_order.size()-1) - { - // for a given step, find data for min/max/median energy walkers - // n1/n2 are indices of the first/last data in energy_order for this step - if (step!=prev_step) n2 = n-1; - if (n==energy_order.size()-1) n2 = n; - auto nmin = n1; // index of minimum energy walker for this step - auto nmax = n2; // index of maximum energy walker for this step - auto nmed = (n1+n2)/2; // index of median energy walker for this step - size_t c,r; - if(write_min_data) - {// cache data for minimum energy walker - c = std::get<2>(energy_order[nmin]); - r = std::get<3>(energy_order[nmin]); - wmin_property_int_buffer.addRow(collectors[c]->walker_property_int_buffer,r); - wmin_property_real_buffer.addRow(collectors[c]->walker_property_real_buffer,r); - wmin_particle_real_buffer.addRow(collectors[c]->walker_particle_real_buffer,r); - } - if(write_max_data) - {// cache data for maximum energy walker - c = std::get<2>(energy_order[nmax]); - r = std::get<3>(energy_order[nmax]); - wmax_property_int_buffer.addRow(collectors[c]->walker_property_int_buffer,r); - wmax_property_real_buffer.addRow(collectors[c]->walker_property_real_buffer,r); - wmax_particle_real_buffer.addRow(collectors[c]->walker_particle_real_buffer,r); - } - if(write_med_data) - {// cache data for median energy walker - c = std::get<2>(energy_order[nmed]); - r = std::get<3>(energy_order[nmed]); - wmed_property_int_buffer.addRow(collectors[c]->walker_property_int_buffer,r); - wmed_property_real_buffer.addRow(collectors[c]->walker_property_real_buffer,r); - wmed_particle_real_buffer.addRow(collectors[c]->walker_particle_real_buffer,r); - } - // reset pointers - n1 = n; - prev_step = step; - } - n++; - } - energy_order.resize(0); - } - - // write buffer data to file - writeBuffersHDF(collectors); -} - - -void WalkerLogManager::checkCollectors(std::vector& collectors) -{ - if (state.verbose) app_log() << "WalkerLogManager::checkCollectors" << std::endl; - if (collectors.size() > 0) - { - bool all_same = true; - WalkerLogCollector& ref = *collectors[0]; - for (int i = 0; i < collectors.size(); ++i) - { - WalkerLogCollector& tc = *collectors[i]; - all_same &= tc.walker_property_int_buffer.sameAs(ref.walker_property_int_buffer); - all_same &= tc.walker_property_real_buffer.sameAs(ref.walker_property_real_buffer); - all_same &= tc.walker_particle_real_buffer.sameAs(ref.walker_particle_real_buffer); - } - if (!all_same) - { - throw std::runtime_error("WalkerLogManager::checkCollectors log buffer widths of collectors do not match\n contiguous write is " - "impossible\n this was first caused by collectors contributing array logs from identical, but " - "differently named, particlesets such as e, e2, e3 ... (fixed)\n please check the WalkerLogManager " - "summaries printed above"); - } - } -} - - -void WalkerLogManager::openFile(std::vector& collectors) -{ - if (state.verbose) app_log() << "WalkerLogManager::openFile "<& collectors) -{ - if (state.verbose) app_log() << "WalkerLogManager::openHDFFile " << std::endl; - if (collectors.size() == 0) - throw std::runtime_error("WalkerLogManager::openHDFFile no log collectors exist, cannot open file"); - // each rank opens a wlogs.h5 file - int nprocs = communicator->size(); - int rank = communicator->rank(); - std::array ptoken; - std::string file_name = file_root; - if (nprocs > 1) - {// extend the file name to include processor/rank information - int length{0}; - if (nprocs > 10000) - length = std::snprintf(ptoken.data(), ptoken.size(), ".p%05d", rank); - else if (nprocs > 1000) - length = std::snprintf(ptoken.data(), ptoken.size(), ".p%04d", rank); - else - length = std::snprintf(ptoken.data(), ptoken.size(), ".p%03d", rank); - if (length < 0) - throw std::runtime_error("Error generating filename"); - file_name.append(ptoken.data(), length); - } - file_name += ".wlogs.h5"; - if (state.verbose) app_log() << "WalkerLogManager::openHDFFile opening logs hdf file " << file_name << std::endl; - // create the hdf archive - hdf_file = std::make_unique(); - // open the file - bool successful = hdf_file->create(file_name); - if (!successful) - throw std::runtime_error("WalkerLogManager::openHDFFile failed to open hdf file " + file_name); -} - - -void WalkerLogManager::writeBuffersHDF(std::vector& collectors) -{ - if (state.verbose) app_log() << "WalkerLogManager::writeBuffersHDF " << std::endl; - WalkerLogCollector& tc_lead = *collectors[0]; - if(!registered_hdf) - {// write walker quantity information ("data_layout") for each buffer in the HDF file - // create data_layout for all-walker buffers - tc_lead.walker_property_int_buffer.registerHDFData(*hdf_file); - tc_lead.walker_property_real_buffer.registerHDFData(*hdf_file); - if(write_particle_data) - tc_lead.walker_particle_real_buffer.registerHDFData(*hdf_file); - if(write_min_data) - {// create data_layout for min energy walker buffers - wmin_property_int_buffer.registerHDFData(*hdf_file); - wmin_property_real_buffer.registerHDFData(*hdf_file); - wmin_particle_real_buffer.registerHDFData(*hdf_file); - } - if(write_max_data) - {// create data_layout for max energy walker buffers - wmax_property_int_buffer.registerHDFData(*hdf_file); - wmax_property_real_buffer.registerHDFData(*hdf_file); - wmax_particle_real_buffer.registerHDFData(*hdf_file); - } - if(write_med_data) - {// create data_layout for median energy walker buffers - wmed_property_int_buffer.registerHDFData(*hdf_file); - wmed_property_real_buffer.registerHDFData(*hdf_file); - wmed_particle_real_buffer.registerHDFData(*hdf_file); - } - // walker quantity information ("data_layout") has now been added to HDF, do not repeat - registered_hdf = true; - } - // write data for all-walker buffers to HDF - for (int ip = 0; ip < collectors.size(); ++ip) - { - WalkerLogCollector& tc = *collectors[ip]; - tc.walker_property_int_buffer.writeHDF(*hdf_file, tc_lead.walker_property_int_buffer.hdf_file_pointer); - tc.walker_property_real_buffer.writeHDF(*hdf_file, tc_lead.walker_property_real_buffer.hdf_file_pointer); - if(write_particle_data) - tc.walker_particle_real_buffer.writeHDF(*hdf_file, tc_lead.walker_particle_real_buffer.hdf_file_pointer); - } - if(write_min_data) - {// write data for min energy walker buffers to HDF - wmin_property_int_buffer.writeHDF(*hdf_file); - wmin_property_real_buffer.writeHDF(*hdf_file); - wmin_particle_real_buffer.writeHDF(*hdf_file); - } - if(write_max_data) - {// write data for max energy walker buffers to HDF - wmax_property_int_buffer.writeHDF(*hdf_file); - wmax_property_real_buffer.writeHDF(*hdf_file); - wmax_particle_real_buffer.writeHDF(*hdf_file); - } - if(write_med_data) - {// write data for median energy walker buffers to HDF - wmed_property_int_buffer.writeHDF(*hdf_file); - wmed_property_real_buffer.writeHDF(*hdf_file); - wmed_particle_real_buffer.writeHDF(*hdf_file); - } -} - - -void WalkerLogManager::closeHDFFile() -{ - if (state.verbose) app_log() << "WalkerLogManager::closeHDFFile " << std::endl; - hdf_file.reset(); -} - - - -} // namespace qmcplusplus diff --git a/src/Estimators/WalkerLogManager.h b/src/Estimators/WalkerLogManager.h deleted file mode 100644 index e17fa7f043..0000000000 --- a/src/Estimators/WalkerLogManager.h +++ /dev/null @@ -1,130 +0,0 @@ -////////////////////////////////////////////////////////////////////////////////////// -// This file is distributed under the University of Illinois/NCSA Open Source License. -// See LICENSE file in top directory for details. -// -// Copyright (c) 2024 QMCPACK developers. -// -// File developed by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory -// -// File created by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory -////////////////////////////////////////////////////////////////////////////////////// - - -#ifndef QMCPLUSPLUS_WALKERLOGMANAGER_H -#define QMCPLUSPLUS_WALKERLOGMANAGER_H - -#include "WalkerLogCollector.h" - - -namespace qmcplusplus -{ - - -struct WalkerLogInput; - - -/** Driver-level resource for walker log collection. - * - * This class manages the HDF file (open/close/write). - * Walker buffer data from all crowd-level WalkerLogCollectors are written - * to the HDF file at the end of each MC block. - * - * Just prior to the write, this class examines the distribution of walker - * energies on its rank for each MC step in the MC block, identifies the - * minimum/maximum/median energy walkers and buffers their full data - * (including per-particle information) for the write. - * This data corresponds to walker information at specific quantiles of the - * energy distribution. - * See WalkerLogManager::writeBuffers() - * - * Writing per-particle information for all walkers is optional, as is - * writing data for the minimum/maximum/median energy walkers. - * Scalar "property" data for each walker is always written. - */ -class WalkerLogManager -{ -public: - WalkerLogState state; - -private: - /// file prefix for the current driver - std::string file_root; - Communicate* communicator; - /// access to HDF file - std::unique_ptr hdf_file; - /// whether walker quantity data ("data_layout") has been recorded in HDF - bool registered_hdf; - - /// whether to write per-particle data for all walkers - bool write_particle_data; - /// whether to write full data for the minimum energy walker at each step - bool write_min_data; - /// whether to write full data for the maximum energy walker at each step - bool write_max_data; - /// whether to write full data for the median energy walker at each step - bool write_med_data; - - /// used to sort energy information for identifying walkers by energy quantile - std::vector> energy_order; - - /// buffer containing integer properties for the minimum energy walkers - WalkerLogBuffer wmin_property_int_buffer; - /// buffer containing real-valued properties for the minimum energy walkers - WalkerLogBuffer wmin_property_real_buffer; - /// buffer containing per-particle properties for the minimum energy walkers - WalkerLogBuffer wmin_particle_real_buffer; - - /// buffer containing integer properties for the maximum energy walkers - WalkerLogBuffer wmax_property_int_buffer; - /// buffer containing real-valued properties for the maximum energy walkers - WalkerLogBuffer wmax_property_real_buffer; - /// buffer containing per-particle properties for the maximum energy walkers - WalkerLogBuffer wmax_particle_real_buffer; - - /// buffer containing integer properties for the median energy walkers - WalkerLogBuffer wmed_property_int_buffer; - /// buffer containing real-valued properties for the median energy walkers - WalkerLogBuffer wmed_property_real_buffer; - /// buffer containing per-particle properties for the median energy walkers - WalkerLogBuffer wmed_particle_real_buffer; - -public: - WalkerLogManager(WalkerLogInput& inp, bool allow_logs, std::string series_root, Communicate* comm = 0); - - /// create a WalkerLogCollector (legacy drivers only, "cloning" style) - WalkerLogCollector* makeCollector(); - - /// open the logs file and check consistency of the collectors at the start of a run - void startRun(std::vector& collectors); - - /// close the logs file at the end of a run - void stopRun(); - - /// collect min/max/median walker data and write buffered walker log data to file - void writeBuffers(std::vector& collectors); - -private: - /// check consistency of walker buffer row sizes - void checkCollectors(std::vector& collectors); - - /// open the logs file - void openFile(std::vector& collectors); - - /// close the logs file - void closeFile(); - - /// open the logs file (HDF format) - void openHDFFile(std::vector& collectors); - - /// write data buffers to the logs file (HDF format) - void writeBuffersHDF(std::vector& collectors); - - /// close the logs file (HDF format) - void closeHDFFile(); -}; - - - -} // namespace qmcplusplus - -#endif diff --git a/src/Estimators/tests/CMakeLists.txt b/src/Estimators/tests/CMakeLists.txt index a1fe950771..6b411561c4 100644 --- a/src/Estimators/tests/CMakeLists.txt +++ b/src/Estimators/tests/CMakeLists.txt @@ -29,7 +29,6 @@ set(SRCS test_manager.cpp test_EstimatorManagerNew.cpp test_trace_manager.cpp - test_WalkerLogCollector.cpp EstimatorTesting.cpp GenerateRandomParticleSets.cpp test_SpinDensityInput.cpp diff --git a/src/Estimators/tests/test_WalkerLogCollector.cpp b/src/Estimators/tests/test_WalkerLogCollector.cpp deleted file mode 100644 index 444b9574c6..0000000000 --- a/src/Estimators/tests/test_WalkerLogCollector.cpp +++ /dev/null @@ -1,136 +0,0 @@ -////////////////////////////////////////////////////////////////////////////////////// -// This file is distributed under the University of Illinois/NCSA Open Source License. -// See LICENSE file in top directory for details. -// -// Copyright (c) 2024 QMCPACK developers. -// -// File developed by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory -// -// File created by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory -////////////////////////////////////////////////////////////////////////////////////// - - -#include "catch.hpp" - -#include "Message/Communicate.h" -#include "QMCHamiltonians/QMCHamiltonian.h" -#include "Particle/tests/MinimalParticlePool.h" -#include "QMCHamiltonians/tests/MinimalHamiltonianPool.h" -#include "QMCWaveFunctions/tests/MinimalWaveFunctionPool.h" -#include "Utilities/ResourceCollection.h" -#include "Utilities/ProjectData.h" - -#include "Estimators/WalkerLogCollector.h" - - -namespace qmcplusplus -{ - -TEST_CASE("WalkerLogCollector::collect", "[estimators]") -{ - std::cout <<"\n\n=======================================================\n"; - std::cout <<"test WalkerLogCollector::collect\n"; - - ProjectData test_project("test", ProjectData::DriverVersion::BATCH); - Communicate* comm = OHMMS::Controller; - - - auto particle_pool = MinimalParticlePool::make_diamondC_1x1x1(comm); - auto wavefunction_pool = - MinimalWaveFunctionPool::make_diamondC_1x1x1(test_project.getRuntimeOptions(), comm, particle_pool); - auto& pset = *(particle_pool.getParticleSet("e")); - // This is where the pset properties "properies" gain the different hamiltonian operator values. - auto hamiltonian_pool = MinimalHamiltonianPool::make_hamWithEE(comm, particle_pool, wavefunction_pool); - - auto& twf = *(wavefunction_pool.getWaveFunction("wavefunction")); - auto& ham = *(hamiltonian_pool.getPrimary()); - - // setup data structures for multiple walkers - - UPtrVector hams; - UPtrVector twfs; - std::vector psets; - - int num_walkers = 4; - int num_electrons = particle_pool.getParticleSet("e")->getTotalNum(); - int num_ions = particle_pool.getParticleSet("ion")->getTotalNum(); - - for (int iw = 0; iw < num_walkers; ++iw) - { - psets.emplace_back(pset); - psets.back().randomizeFromSource(*particle_pool.getParticleSet("ion")); - twfs.emplace_back(twf.makeClone(psets.back())); - hams.emplace_back(hamiltonian_pool.getPrimary()->makeClone(psets.back(), *twfs.back())); - } - - using MCPWalker = Walker; - - std::vector walkers(num_walkers, MCPWalker(pset.getTotalNum())); - - for (auto& walker : walkers) - { - walker.R = pset.R; - walker.spins = pset.spins; - walker.Properties = pset.Properties; - walker.registerData(); - walker.DataSet.allocate(); - } - - WalkerLogCollector wlc; - wlc.state.logs_active = true; - wlc.state.step_period = 1; - - auto& bsi = wlc.walker_property_int_buffer; - auto& bsr = wlc.walker_property_real_buffer; - auto& bpr = wlc.walker_particle_real_buffer; - - CHECK(bsi.nrows() == 0); - CHECK(bsr.nrows() == 0); - CHECK(bpr.nrows() == 0); - CHECK(bsi.ncols() == 0); - CHECK(bsr.ncols() == 0); - CHECK(bpr.ncols() == 0); - -#ifndef QMC_COMPLEX - const size_t npcols = 56; -#else - const size_t npcols = 88; -#endif - - int step=0; - wlc.collect(walkers[0], psets[0], *(twfs[0]), *(hams[0]), step); - - CHECK(bsi.nrows() == 1); - CHECK(bsr.nrows() == 1); - CHECK(bpr.nrows() == 1); - CHECK(bsi.ncols() == 4); - CHECK(bsr.ncols() == 13); - CHECK(bpr.ncols() == npcols); - - for (size_t iw=1; iw class Communicate; diff --git a/src/QMCDrivers/QMCUpdateBase.cpp b/src/QMCDrivers/QMCUpdateBase.cpp index aefdc25a97..f23dd01bba 100644 --- a/src/QMCDrivers/QMCUpdateBase.cpp +++ b/src/QMCDrivers/QMCUpdateBase.cpp @@ -26,7 +26,7 @@ #else using TraceManager = int; #endif -#include "Estimators/WalkerLogManager.h" +#include "WalkerLogManager.h" namespace qmcplusplus { diff --git a/src/QMCDrivers/QMCUpdateBase.h b/src/QMCDrivers/QMCUpdateBase.h index 4558ab7365..237b7048b4 100644 --- a/src/QMCDrivers/QMCUpdateBase.h +++ b/src/QMCDrivers/QMCUpdateBase.h @@ -23,7 +23,7 @@ #include "QMCWaveFunctions/TrialWaveFunction.h" #include "QMCHamiltonians/QMCHamiltonian.h" #include "QMCHamiltonians/NonLocalTOperator.h" -#include "Estimators/WalkerLogManager.h" +#include "WalkerLogManager.h" #include "GreenFunctionModifiers/DriftModifierBase.h" #include "SimpleFixedNodeBranch.h" #include "DriverDebugChecks.h" diff --git a/src/QMCDrivers/VMC/VMC.cpp b/src/QMCDrivers/VMC/VMC.cpp index 84783e8444..508ae66561 100644 --- a/src/QMCDrivers/VMC/VMC.cpp +++ b/src/QMCDrivers/VMC/VMC.cpp @@ -32,7 +32,7 @@ #else using TraceManager = int; #endif -#include "Estimators/WalkerLogManager.h" +#include "WalkerLogManager.h" namespace qmcplusplus { diff --git a/src/QMCHamiltonians/CMakeLists.txt b/src/QMCHamiltonians/CMakeLists.txt index 2bd0babd9d..92ba055e04 100644 --- a/src/QMCHamiltonians/CMakeLists.txt +++ b/src/QMCHamiltonians/CMakeLists.txt @@ -70,7 +70,7 @@ if(OHMMS_DIM MATCHES 3) ECPComponentBuilder_L2.cpp) if(NOT REMOVE_TRACEMANAGER) - set(HAMSRCS ${HAMSRCS} ../Estimators/TraceManager.cpp ../Estimators/WalkerLogManager.cpp ReferencePoints.cpp SpaceGrid.cpp EnergyDensityEstimator.cpp + set(HAMSRCS ${HAMSRCS} ../Estimators/TraceManager.cpp ReferencePoints.cpp SpaceGrid.cpp EnergyDensityEstimator.cpp DensityMatrices1B.cpp) endif() From c792aff89f3cf5b04fb6c830436c8989be37fbb6 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Tue, 11 Jun 2024 09:56:47 -0400 Subject: [PATCH 50/55] rename step counter --- src/QMCDrivers/DMC/DMCBatched.cpp | 8 ++++---- src/QMCDrivers/DMC/DMCBatched.h | 2 +- src/QMCDrivers/VMC/VMCBatched.cpp | 8 ++++---- src/QMCDrivers/VMC/VMCBatched.h | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/QMCDrivers/DMC/DMCBatched.cpp b/src/QMCDrivers/DMC/DMCBatched.cpp index f07f3c4894..fbd10ac9c4 100644 --- a/src/QMCDrivers/DMC/DMCBatched.cpp +++ b/src/QMCDrivers/DMC/DMCBatched.cpp @@ -289,7 +289,7 @@ void DMCBatched::advanceWalkers(const StateForThread& sft, } // collect walker logs - crowd.collect(sft.current_step); + crowd.collect(sft.global_step); { // T-moves ScopedTimer tmove_timer(dmc_timers.tmove_timer); @@ -468,7 +468,7 @@ bool DMCBatched::run() ScopedTimer local_timer(timers_.production_timer); ParallelExecutor<> crowd_task; - int current_step = 0; + int global_step = 0; for (int block = 0; block < num_blocks; ++block) { { @@ -488,7 +488,7 @@ bool DMCBatched::run() crowd->wlog_collector_.startBlock(); } - for (int step = 0; step < steps_per_block_; ++step, ++current_step) + for (int step = 0; step < steps_per_block_; ++step, ++global_step) { ScopedTimer local_timer(timers_.run_steps_timer); @@ -498,7 +498,7 @@ bool DMCBatched::run() setNonLocalMoveHandler(*ham); dmc_state.step = step; - dmc_state.current_step = current_step; + dmc_state.global_step = global_step; crowd_task(crowds_.size(), runDMCStep, dmc_state, timers_, dmc_timers_, std::ref(step_contexts_), std::ref(crowds_)); diff --git a/src/QMCDrivers/DMC/DMCBatched.h b/src/QMCDrivers/DMC/DMCBatched.h index f521c5b25f..fbb318ca7d 100644 --- a/src/QMCDrivers/DMC/DMCBatched.h +++ b/src/QMCDrivers/DMC/DMCBatched.h @@ -53,7 +53,7 @@ class DMCBatched : public QMCDriverNew IndexType recalculate_properties_period; const size_t steps_per_block; IndexType step = -1; - IndexType current_step = -1; + IndexType global_step = -1; bool is_recomputing_block = false; StateForThread(const QMCDriverInput& qmci, diff --git a/src/QMCDrivers/VMC/VMCBatched.cpp b/src/QMCDrivers/VMC/VMCBatched.cpp index 99950dbb31..a2f3c35238 100644 --- a/src/QMCDrivers/VMC/VMCBatched.cpp +++ b/src/QMCDrivers/VMC/VMCBatched.cpp @@ -217,7 +217,7 @@ void VMCBatched::advanceWalkers(const StateForThread& sft, } // collect walker logs - crowd.collect(sft.current_step); + crowd.collect(sft.global_step); // TODO: // check if all moves failed @@ -367,7 +367,7 @@ bool VMCBatched::run() // this barrier fences all previous load imbalance. Avoid block 0 timing pollution. myComm->barrier(); - int current_step = 0; + int global_step = 0; for (int block = 0; block < num_blocks; ++block) { { @@ -385,11 +385,11 @@ bool VMCBatched::run() crowd->startBlock(steps_per_block_); crowd->wlog_collector_.startBlock(); } - for (int step = 0; step < steps_per_block_; ++step, ++current_step) + for (int step = 0; step < steps_per_block_; ++step, ++global_step) { ScopedTimer local_timer(timers_.run_steps_timer); vmc_state.step = step; - vmc_state.current_step = current_step; + vmc_state.global_step = global_step; crowd_task(crowds_.size(), runVMCStep, vmc_state, timers_, std::ref(step_contexts_), std::ref(crowds_)); if (collect_samples_) diff --git a/src/QMCDrivers/VMC/VMCBatched.h b/src/QMCDrivers/VMC/VMCBatched.h index 752d795fa7..8c4cee5882 100644 --- a/src/QMCDrivers/VMC/VMCBatched.h +++ b/src/QMCDrivers/VMC/VMCBatched.h @@ -53,7 +53,7 @@ class VMCBatched : public QMCDriverNew IndexType recalculate_properties_period; const size_t steps_per_block; IndexType step = -1; - IndexType current_step = -1; + IndexType global_step = -1; bool is_recomputing_block = false; StateForThread(const QMCDriverInput& qmci, From 4a7d7700c36507fd60e052f4dbcf083e4bfdc5da Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Tue, 11 Jun 2024 10:02:30 -0400 Subject: [PATCH 51/55] longer name for crowd.collect() --- src/QMCDrivers/Crowd.cpp | 2 +- src/QMCDrivers/Crowd.h | 2 +- src/QMCDrivers/DMC/DMCBatched.cpp | 2 +- src/QMCDrivers/VMC/VMCBatched.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/QMCDrivers/Crowd.cpp b/src/QMCDrivers/Crowd.cpp index 58f85753e5..8eff05c60a 100644 --- a/src/QMCDrivers/Crowd.cpp +++ b/src/QMCDrivers/Crowd.cpp @@ -86,7 +86,7 @@ void Crowd::startBlock(int num_steps) void Crowd::stopBlock() { estimator_manager_crowd_.stopBlock(); } -void Crowd::collect(int current_step) +void Crowd::collectStepWalkerLog(int current_step) { for (int iw = 0; iw < size(); ++iw) wlog_collector_.collect(mcp_walkers_[iw], walker_elecs_[iw], walker_twfs_[iw], walker_hamiltonians_[iw], current_step); diff --git a/src/QMCDrivers/Crowd.h b/src/QMCDrivers/Crowd.h index 63eed00487..b0045b3ef9 100644 --- a/src/QMCDrivers/Crowd.h +++ b/src/QMCDrivers/Crowd.h @@ -86,7 +86,7 @@ class Crowd } /// Collect walker log data - void collect(int current_step); + void collectStepWalkerLog(int current_step); void setRNGForHamiltonian(RandomBase& rng); diff --git a/src/QMCDrivers/DMC/DMCBatched.cpp b/src/QMCDrivers/DMC/DMCBatched.cpp index fbd10ac9c4..47ae30689a 100644 --- a/src/QMCDrivers/DMC/DMCBatched.cpp +++ b/src/QMCDrivers/DMC/DMCBatched.cpp @@ -289,7 +289,7 @@ void DMCBatched::advanceWalkers(const StateForThread& sft, } // collect walker logs - crowd.collect(sft.global_step); + crowd.collectStepWalkerLog(sft.global_step); { // T-moves ScopedTimer tmove_timer(dmc_timers.tmove_timer); diff --git a/src/QMCDrivers/VMC/VMCBatched.cpp b/src/QMCDrivers/VMC/VMCBatched.cpp index a2f3c35238..aa96511bcf 100644 --- a/src/QMCDrivers/VMC/VMCBatched.cpp +++ b/src/QMCDrivers/VMC/VMCBatched.cpp @@ -217,7 +217,7 @@ void VMCBatched::advanceWalkers(const StateForThread& sft, } // collect walker logs - crowd.collect(sft.global_step); + crowd.collectStepWalkerLog(sft.global_step); // TODO: // check if all moves failed From 35871acd2d82f5d856be163850ecb37cd0228cf7 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Tue, 11 Jun 2024 10:11:35 -0400 Subject: [PATCH 52/55] hide data members behind more member functions --- src/QMCDrivers/Crowd.h | 1 + src/QMCDrivers/VMC/VMCBatched.cpp | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/QMCDrivers/Crowd.h b/src/QMCDrivers/Crowd.h index b0045b3ef9..3835899b7c 100644 --- a/src/QMCDrivers/Crowd.h +++ b/src/QMCDrivers/Crowd.h @@ -103,6 +103,7 @@ class Crowd const RefVector& get_walker_hamiltonians() const { return walker_hamiltonians_; } const EstimatorManagerCrowd& get_estimator_manager_crowd() const { return estimator_manager_crowd_; } + WalkerLogCollector& getWalkerLogCollector() { return wlog_collector_; } DriverWalkerResourceCollection& getSharedResource() { return driverwalker_resource_collection_; } diff --git a/src/QMCDrivers/VMC/VMCBatched.cpp b/src/QMCDrivers/VMC/VMCBatched.cpp index aa96511bcf..8b3f227fd9 100644 --- a/src/QMCDrivers/VMC/VMCBatched.cpp +++ b/src/QMCDrivers/VMC/VMCBatched.cpp @@ -313,7 +313,7 @@ bool VMCBatched::run() wlog_manager_ = std::make_unique(walker_logs_input, allow_walker_logs, get_root_name(), myComm); std::vector wlog_collectors; for (auto& c: crowds_) - wlog_collectors.push_back(&c->wlog_collector_); + wlog_collectors.push_back(&c->getWalkerLogCollector()); wlog_manager_->startRun(wlog_collectors); StateForThread vmc_state(qmcdriver_input_, vmcdriver_input_, *drift_modifier_, population_, steps_per_block_); @@ -383,7 +383,8 @@ bool VMCBatched::run() for (auto& crowd : crowds_) { crowd->startBlock(steps_per_block_); - crowd->wlog_collector_.startBlock(); + auto& wlc = crowd->getWalkerLogCollector(); + wlc.startBlock(); } for (int step = 0; step < steps_per_block_; ++step, ++global_step) { From 740cf6bfff928ed1d984252843957a7177164bb7 Mon Sep 17 00:00:00 2001 From: Jaron Krogel Date: Tue, 11 Jun 2024 10:31:21 -0400 Subject: [PATCH 53/55] simplify WalkerLogState --- src/QMCDrivers/WalkerLogCollector.cpp | 1 - src/QMCDrivers/WalkerLogCollector.h | 18 +++--------------- src/QMCDrivers/WalkerLogManager.cpp | 1 - 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/QMCDrivers/WalkerLogCollector.cpp b/src/QMCDrivers/WalkerLogCollector.cpp index 63f41382d3..c0297ded23 100644 --- a/src/QMCDrivers/WalkerLogCollector.cpp +++ b/src/QMCDrivers/WalkerLogCollector.cpp @@ -41,7 +41,6 @@ void WalkerLogCollector::init() { properties_include = {"R2Accepted", "R2Proposed", "LocalEnergy", "LocalPotential", "Kinetic", "ElecElec", "ElecIon", "LocalECP", "NonLocalECP"}; - state.reset(); energy_index = -1; // empty walker steps and energy vectors for the MC block steps.resize(0); diff --git a/src/QMCDrivers/WalkerLogCollector.h b/src/QMCDrivers/WalkerLogCollector.h index 3b63652c56..73d92dbf24 100644 --- a/src/QMCDrivers/WalkerLogCollector.h +++ b/src/QMCDrivers/WalkerLogCollector.h @@ -31,23 +31,11 @@ using MCPWalker = Walker; struct WalkerLogState { /// whether logs are active in the current driver - bool logs_active; + bool logs_active = false; /// period between MC steps for data collection - int step_period; + int step_period = 1; /// controls verbosity of log file writes - bool verbose; - - WalkerLogState() - { - reset(); - step_period = 1; - } - - inline void reset() - { - logs_active = false; - verbose = false; - } + bool verbose = false; }; diff --git a/src/QMCDrivers/WalkerLogManager.cpp b/src/QMCDrivers/WalkerLogManager.cpp index c4583b374b..b78d6eaf7a 100644 --- a/src/QMCDrivers/WalkerLogManager.cpp +++ b/src/QMCDrivers/WalkerLogManager.cpp @@ -20,7 +20,6 @@ namespace qmcplusplus WalkerLogManager::WalkerLogManager(WalkerLogInput& inp, bool allow_logs, std::string series_root, Communicate* comm) { - state.reset(); communicator = comm; file_root = series_root; bool driver_allows_logs = allow_logs; // driver allows logs or not From be01ba4595c432e3d6b28f528bdf0ad8d34f6837 Mon Sep 17 00:00:00 2001 From: Ye Luo Date: Tue, 11 Jun 2024 12:50:25 -0500 Subject: [PATCH 54/55] Relocate wlog_collector_.startBlock --- src/QMCDrivers/Crowd.cpp | 1 + src/QMCDrivers/DMC/DMCBatched.cpp | 3 --- src/QMCDrivers/VMC/VMCBatched.cpp | 5 +---- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/QMCDrivers/Crowd.cpp b/src/QMCDrivers/Crowd.cpp index 8eff05c60a..a00a458fa4 100644 --- a/src/QMCDrivers/Crowd.cpp +++ b/src/QMCDrivers/Crowd.cpp @@ -82,6 +82,7 @@ void Crowd::startBlock(int num_steps) // VMCBatched does no nonlocal moves n_nonlocal_accept_ = 0; estimator_manager_crowd_.startBlock(num_steps); + wlog_collector_.startBlock(); } void Crowd::stopBlock() { estimator_manager_crowd_.stopBlock(); } diff --git a/src/QMCDrivers/DMC/DMCBatched.cpp b/src/QMCDrivers/DMC/DMCBatched.cpp index 47ae30689a..e1a2dc3d8c 100644 --- a/src/QMCDrivers/DMC/DMCBatched.cpp +++ b/src/QMCDrivers/DMC/DMCBatched.cpp @@ -483,10 +483,7 @@ bool DMCBatched::run() : false; for (UPtr& crowd : crowds_) - { crowd->startBlock(steps_per_block_); - crowd->wlog_collector_.startBlock(); - } for (int step = 0; step < steps_per_block_; ++step, ++global_step) { diff --git a/src/QMCDrivers/VMC/VMCBatched.cpp b/src/QMCDrivers/VMC/VMCBatched.cpp index 8b3f227fd9..094a8aca8f 100644 --- a/src/QMCDrivers/VMC/VMCBatched.cpp +++ b/src/QMCDrivers/VMC/VMCBatched.cpp @@ -381,11 +381,8 @@ bool VMCBatched::run() estimator_manager_->startBlock(steps_per_block_); for (auto& crowd : crowds_) - { crowd->startBlock(steps_per_block_); - auto& wlc = crowd->getWalkerLogCollector(); - wlc.startBlock(); - } + for (int step = 0; step < steps_per_block_; ++step, ++global_step) { ScopedTimer local_timer(timers_.run_steps_timer); From a832b7cfc250b2cfd2f12f5752b0f20ab16108d5 Mon Sep 17 00:00:00 2001 From: Ye Luo Date: Tue, 11 Jun 2024 13:12:11 -0500 Subject: [PATCH 55/55] Make wlog_collector_ private in Crowd. --- src/QMCDrivers/Crowd.h | 4 ++-- src/QMCDrivers/DMC/DMCBatched.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/QMCDrivers/Crowd.h b/src/QMCDrivers/Crowd.h index 3835899b7c..ee468ce2b0 100644 --- a/src/QMCDrivers/Crowd.h +++ b/src/QMCDrivers/Crowd.h @@ -135,6 +135,8 @@ class Crowd DriverWalkerResourceCollection driverwalker_resource_collection_; /// per crowd estimator manager EstimatorManagerCrowd estimator_manager_crowd_; + // collector for walker logs + WalkerLogCollector wlog_collector_; /** @name Step State * @@ -145,8 +147,6 @@ class Crowd unsigned long n_accept_ = 0; unsigned long n_nonlocal_accept_ = 0; /** @} */ -public: - WalkerLogCollector wlog_collector_; }; } // namespace qmcplusplus diff --git a/src/QMCDrivers/DMC/DMCBatched.cpp b/src/QMCDrivers/DMC/DMCBatched.cpp index e1a2dc3d8c..4a8d97da6b 100644 --- a/src/QMCDrivers/DMC/DMCBatched.cpp +++ b/src/QMCDrivers/DMC/DMCBatched.cpp @@ -437,7 +437,7 @@ bool DMCBatched::run() wlog_manager_ = std::make_unique(walker_logs_input, allow_walker_logs, get_root_name(), myComm); std::vector wlog_collectors; for (auto& c: crowds_) - wlog_collectors.push_back(&c->wlog_collector_); + wlog_collectors.push_back(&c->getWalkerLogCollector()); wlog_manager_->startRun(wlog_collectors); StateForThread dmc_state(qmcdriver_input_, *drift_modifier_, *branch_engine_, population_, steps_per_block_);