From a1b5edc672bfd20286b8d19267d593f365071190 Mon Sep 17 00:00:00 2001 From: "Yubo \"Paul\" Yang" Date: Wed, 13 Mar 2024 18:01:12 -0400 Subject: [PATCH 1/6] update instead of rewrite config.h5 --- src/Particle/HDFWalkerOutput.cpp | 21 +++++++++++++++++---- src/Particle/HDFWalkerOutput.h | 4 ++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Particle/HDFWalkerOutput.cpp b/src/Particle/HDFWalkerOutput.cpp index 6ecbfebb63..54e5e84d57 100644 --- a/src/Particle/HDFWalkerOutput.cpp +++ b/src/Particle/HDFWalkerOutput.cpp @@ -79,7 +79,7 @@ HDFWalkerOutput::~HDFWalkerOutput() = default; * - walker_partition (int array) * - walkers (nw,np,3) */ -bool HDFWalkerOutput::dump(const WalkerConfigurations& W, int nblock) +bool HDFWalkerOutput::dump(const WalkerConfigurations& W, int nblock, const bool identify_block) { std::filesystem::path FileName = myComm->getName(); FileName.concat(hdf::config_ext); @@ -93,13 +93,16 @@ bool HDFWalkerOutput::dump(const WalkerConfigurations& W, int nblock) //try to use collective hdf_archive dump_file(myComm, true); - dump_file.create(FileName); + bool exists = dump_file.open(FileName); + if (!exists) // create new config.h5 + dump_file.create(FileName); + HDFVersion cur_version; dump_file.write(cur_version.version, hdf::version); dump_file.push(hdf::main_state); dump_file.write(nblock, "block"); - write_configuration(W, dump_file, nblock); + write_configuration(W, dump_file, nblock, identify_block); dump_file.close(); currentConfigNumber++; @@ -107,8 +110,18 @@ bool HDFWalkerOutput::dump(const WalkerConfigurations& W, int nblock) return true; } -void HDFWalkerOutput::write_configuration(const WalkerConfigurations& W, hdf_archive& hout, int nblock) +void HDFWalkerOutput::write_configuration(const WalkerConfigurations& W, hdf_archive& hout, int nblock, const bool identify_block) { + if (identify_block) + { // change h5 slab name to record more than one block + } else { // remove previous checkpoint + std::vector names = {"block", hdf::num_walkers, "walker_partition", hdf::walkers}; + for (auto aname : names) + { + if (hout.is_dataset(aname)) hout.unlink(aname); + } + } + const int wb = OHMMS_DIM * number_of_particles_; if (nblock > block) { diff --git a/src/Particle/HDFWalkerOutput.h b/src/Particle/HDFWalkerOutput.h index d44d2593a9..3d4548862d 100644 --- a/src/Particle/HDFWalkerOutput.h +++ b/src/Particle/HDFWalkerOutput.h @@ -52,7 +52,7 @@ class HDFWalkerOutput /** dump configurations * @param w walkers */ - bool dump(const WalkerConfigurations& w, int block); + bool dump(const WalkerConfigurations& w, int block, const bool identify_block=false); // bool dump(ForwardWalkingHistoryObject& FWO); private: @@ -62,7 +62,7 @@ class HDFWalkerOutput std::array RemoteData; std::array, 2> RemoteDataW; int block; - void write_configuration(const WalkerConfigurations& W, hdf_archive& hout, int block); + void write_configuration(const WalkerConfigurations& W, hdf_archive& hout, int block, const bool identify_block); }; } // namespace qmcplusplus From 106569ea7215ec05e4166ad10360bd374109a44a Mon Sep 17 00:00:00 2001 From: "Yubo \"Paul\" Yang" Date: Thu, 14 Mar 2024 08:00:59 -0400 Subject: [PATCH 2/6] more thorough cleanup of previous checkpoint --- src/Particle/HDFWalkerOutput.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Particle/HDFWalkerOutput.cpp b/src/Particle/HDFWalkerOutput.cpp index 54e5e84d57..c0bf4f8316 100644 --- a/src/Particle/HDFWalkerOutput.cpp +++ b/src/Particle/HDFWalkerOutput.cpp @@ -95,12 +95,12 @@ bool HDFWalkerOutput::dump(const WalkerConfigurations& W, int nblock, const bool hdf_archive dump_file(myComm, true); bool exists = dump_file.open(FileName); if (!exists) // create new config.h5 + { dump_file.create(FileName); - - HDFVersion cur_version; - dump_file.write(cur_version.version, hdf::version); + HDFVersion cur_version; + dump_file.write(cur_version.version, hdf::version); + } dump_file.push(hdf::main_state); - dump_file.write(nblock, "block"); write_configuration(W, dump_file, nblock, identify_block); dump_file.close(); @@ -115,11 +115,10 @@ void HDFWalkerOutput::write_configuration(const WalkerConfigurations& W, hdf_arc if (identify_block) { // change h5 slab name to record more than one block } else { // remove previous checkpoint - std::vector names = {"block", hdf::num_walkers, "walker_partition", hdf::walkers}; + std::vector names = {"block", hdf::num_walkers, "walker_partition", hdf::walkers, hdf::walker_weights}; for (auto aname : names) - { if (hout.is_dataset(aname)) hout.unlink(aname); - } + hout.write(nblock, "block"); } const int wb = OHMMS_DIM * number_of_particles_; From 3c74d97c0af818bbc2f253ee27ab7067f4b45c25 Mon Sep 17 00:00:00 2001 From: "Yubo \"Paul\" Yang" Date: Thu, 14 Mar 2024 08:06:35 -0400 Subject: [PATCH 3/6] implement identify_block append block index after walkers --- src/Particle/HDFWalkerOutput.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Particle/HDFWalkerOutput.cpp b/src/Particle/HDFWalkerOutput.cpp index c0bf4f8316..98f8b61a9f 100644 --- a/src/Particle/HDFWalkerOutput.cpp +++ b/src/Particle/HDFWalkerOutput.cpp @@ -112,13 +112,16 @@ bool HDFWalkerOutput::dump(const WalkerConfigurations& W, int nblock, const bool void HDFWalkerOutput::write_configuration(const WalkerConfigurations& W, hdf_archive& hout, int nblock, const bool identify_block) { + std::string dataset_name = hdf::walkers; if (identify_block) { // change h5 slab name to record more than one block + std::stringstream block_str; + block_str << nblock; + dataset_name += block_str.str(); } else { // remove previous checkpoint - std::vector names = {"block", hdf::num_walkers, "walker_partition", hdf::walkers, hdf::walker_weights}; + std::vector names = {"block", hdf::num_walkers, "walker_partition", dataset_name, hdf::walker_weights}; for (auto aname : names) if (hout.is_dataset(aname)) hout.unlink(aname); - hout.write(nblock, "block"); } const int wb = OHMMS_DIM * number_of_particles_; @@ -132,7 +135,11 @@ void HDFWalkerOutput::write_configuration(const WalkerConfigurations& W, hdf_arc auto& walker_offsets = W.getWalkerOffsets(); number_of_walkers_ = walker_offsets[myComm->size()]; - hout.write(number_of_walkers_, hdf::num_walkers); + if (!identify_block) + { + hout.write(nblock, "block"); + hout.write(number_of_walkers_, hdf::num_walkers); + } if (hout.is_parallel()) { @@ -161,7 +168,7 @@ void HDFWalkerOutput::write_configuration(const WalkerConfigurations& W, hdf_arc std::array counts{W.getActiveWalkers(), number_of_particles_, OHMMS_DIM}; std::array offsets{static_cast(walker_offsets[myComm->rank()]), 0, 0}; hyperslab_proxy slab(RemoteData[0], gcounts, counts, offsets); - hout.write(slab, hdf::walkers); + hout.write(slab, dataset_name); } { std::array gcounts{number_of_walkers_}; @@ -198,7 +205,7 @@ void HDFWalkerOutput::write_configuration(const WalkerConfigurations& W, hdf_arc int buffer_id = (myComm->size() > 1) ? 1 : 0; { std::array gcounts{number_of_walkers_, number_of_particles_, OHMMS_DIM}; - hout.writeSlabReshaped(RemoteData[buffer_id], gcounts, hdf::walkers); + hout.writeSlabReshaped(RemoteData[buffer_id], gcounts, dataset_name); } { std::array gcounts{number_of_walkers_}; From bd6bd542c386dbba93e632e7cd439bbb714f5752 Mon Sep 17 00:00:00 2001 From: "Yubo \"Paul\" Yang" Date: Thu, 14 Mar 2024 08:14:34 -0400 Subject: [PATCH 4/6] rename walker_weights and walker_partition in addition to walkers --- src/Particle/HDFWalkerOutput.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Particle/HDFWalkerOutput.cpp b/src/Particle/HDFWalkerOutput.cpp index 98f8b61a9f..42e25a633f 100644 --- a/src/Particle/HDFWalkerOutput.cpp +++ b/src/Particle/HDFWalkerOutput.cpp @@ -112,14 +112,18 @@ bool HDFWalkerOutput::dump(const WalkerConfigurations& W, int nblock, const bool void HDFWalkerOutput::write_configuration(const WalkerConfigurations& W, hdf_archive& hout, int nblock, const bool identify_block) { + std::string partition_name = "walker_partition"; std::string dataset_name = hdf::walkers; + std::string weights_name = hdf::walker_weights; if (identify_block) { // change h5 slab name to record more than one block std::stringstream block_str; block_str << nblock; + partition_name += block_str.str(); dataset_name += block_str.str(); + weights_name += block_str.str(); } else { // remove previous checkpoint - std::vector names = {"block", hdf::num_walkers, "walker_partition", dataset_name, hdf::walker_weights}; + std::vector names = {"block", hdf::num_walkers, partition_name, dataset_name, weights_name}; for (auto aname : names) if (hout.is_dataset(aname)) hout.unlink(aname); } @@ -161,7 +165,7 @@ void HDFWalkerOutput::write_configuration(const WalkerConfigurations& W, hdf_arc myWalkerOffset.push_back(walker_offsets[myComm->rank()]); } hyperslab_proxy, 1> slab(myWalkerOffset, gcounts, counts, offsets); - hout.write(slab, "walker_partition"); + hout.write(slab, partition_name); } { // write walker configuration std::array gcounts{number_of_walkers_, number_of_particles_, OHMMS_DIM}; @@ -175,12 +179,12 @@ void HDFWalkerOutput::write_configuration(const WalkerConfigurations& W, hdf_arc std::array counts{W.getActiveWalkers()}; std::array offsets{static_cast(walker_offsets[myComm->rank()])}; hyperslab_proxy, 1> slab(RemoteDataW[0], gcounts, counts, offsets); - hout.write(slab, hdf::walker_weights); + hout.write(slab, weights_name); } } else { //gaterv to the master and master writes it, could use isend/irecv - hout.write(walker_offsets, "walker_partition"); + hout.write(walker_offsets, partition_name); if (myComm->size() > 1) { std::vector displ(myComm->size()), counts(myComm->size()); @@ -209,7 +213,7 @@ void HDFWalkerOutput::write_configuration(const WalkerConfigurations& W, hdf_arc } { std::array gcounts{number_of_walkers_}; - hout.writeSlabReshaped(RemoteDataW[buffer_id], gcounts, hdf::walker_weights); + hout.writeSlabReshaped(RemoteDataW[buffer_id], gcounts, weights_name); } } } From 42b10ed0edfc82e348b26698033c29cd3be9349c Mon Sep 17 00:00:00 2001 From: "Yubo \"Paul\" Yang" Date: Thu, 14 Mar 2024 08:15:13 -0400 Subject: [PATCH 5/6] use dump with identify_block --- src/QMCDrivers/QMCDriver.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/QMCDrivers/QMCDriver.cpp b/src/QMCDrivers/QMCDriver.cpp index 32981d1927..594449b6b7 100644 --- a/src/QMCDrivers/QMCDriver.cpp +++ b/src/QMCDrivers/QMCDriver.cpp @@ -306,6 +306,11 @@ void QMCDriver::recordBlock(int block) branchEngine->write(RootName, true); //save energy_history RandomNumberControl::write(RootName, myComm); } + if (Period4ConfigDump!=0 && block%Period4ConfigDump == 0) + { // append current walkers to config.h5 + const bool identify_block = true; + wOut->dump(W, block, identify_block); + } } bool QMCDriver::finalize(int block, bool dumpwalkers) From e8594ebe0aa7bbf57942028824dfe1ce6ad365f0 Mon Sep 17 00:00:00 2001 From: "Yubo \"Paul\" Yang" Date: Thu, 11 Apr 2024 14:14:42 -0400 Subject: [PATCH 6/6] comment on identify_block --- src/Particle/HDFWalkerOutput.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Particle/HDFWalkerOutput.h b/src/Particle/HDFWalkerOutput.h index 3d4548862d..57f2ded732 100644 --- a/src/Particle/HDFWalkerOutput.h +++ b/src/Particle/HDFWalkerOutput.h @@ -50,7 +50,12 @@ class HDFWalkerOutput ~HDFWalkerOutput(); /** dump configurations - * @param w walkers + * Write walkers into hdf file. + * The "walkers" dataset typically resides at "state_0/walkers", which + * contains no information about when it was written (at which block). + * The identify_block flag appends the block index to uniquely identify + * each walker dump, e.g., "state_0/walkers10" is from block 10. + * */ bool dump(const WalkerConfigurations& w, int block, const bool identify_block=false); // bool dump(ForwardWalkingHistoryObject& FWO);