Skip to content

Commit

Permalink
Implemented WalkerConfigurationsT and dealt with the ensuing mess
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipFackler committed Sep 29, 2023
1 parent 538bfcd commit 4c73f01
Show file tree
Hide file tree
Showing 36 changed files with 668 additions and 1,329 deletions.
2 changes: 1 addition & 1 deletion src/Estimators/EstimatorManagerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class EstimatorManagerBase

using EstimatorType = ScalarEstimatorBase;
using BufferType = std::vector<RealType>;
using MCPWalker = Walker<QMCTraits, PtclOnLatticeTraits>;
using MCPWalker = MCWalkerConfiguration::Walker_t;

///default constructor
EstimatorManagerBase(Communicate* c = 0);
Expand Down
3 changes: 2 additions & 1 deletion src/Estimators/EstimatorManagerCrowd.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Estimators/EstimatorManagerNew.h"
#include "Particle/Walker.h"
#include "OhmmsPETE/OhmmsVector.h"
#include "Particle/MCWalkerConfiguration.h"

namespace qmcplusplus
{
Expand All @@ -38,7 +39,7 @@ class QMCHamiltonian;
class EstimatorManagerCrowd
{
public:
using MCPWalker = Walker<QMCTraits, PtclOnLatticeTraits>;
using MCPWalker = MCWalkerConfiguration::Walker_t;
using RealType = EstimatorManagerNew::RealType;
using FullPrecRealType = EstimatorManagerNew::FullPrecRealType;

Expand Down
3 changes: 2 additions & 1 deletion src/Estimators/OperatorEstBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "QMCWaveFunctions/OrbitalSetTraits.h"
#include "type_traits/DataLocality.h"
#include "hdf/hdf_archive.h"
#include "Particle/MCWalkerConfiguration.h"
#include <bitset>

namespace qmcplusplus
Expand All @@ -41,7 +42,7 @@ class OperatorEstBase
public:
using QMCT = QMCTraits;
using FullPrecRealType = QMCT::FullPrecRealType;
using MCPWalker = Walker<QMCTraits, PtclOnLatticeTraits>;
using MCPWalker = MCWalkerConfiguration::Walker_t;

using Data = std::vector<QMCT::RealType>;

Expand Down
2 changes: 1 addition & 1 deletion src/Estimators/ScalarEstimatorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct ScalarEstimatorBase
using RealType = QMCTraits::FullPrecRealType;
using accumulator_type = accumulator_set<RealType>;
using Walker_t = MCWalkerConfiguration::Walker_t;
using MCPWalker = Walker<QMCTraits, PtclOnLatticeTraits>;
using MCPWalker = Walker_t;
using WalkerIterator = MCWalkerConfiguration::const_iterator;
using RecordListType = RecordNamedProperty<RealType>;

Expand Down
2 changes: 1 addition & 1 deletion src/Estimators/tests/test_EstimatorManagerCrowd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ TEST_CASE("EstimatorManagerCrowd PerParticleHamiltonianLogger integration", "[es

EstimatorManagerCrowd emc(emn);

using MCPWalker = Walker<QMCTraits, PtclOnLatticeTraits>;
using MCPWalker = EstimatorManagerCrowd::MCPWalker;

std::vector<MCPWalker> walkers(num_walkers, MCPWalker(pset.getTotalNum()));

Expand Down
2 changes: 1 addition & 1 deletion src/Particle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ set(PARTICLE
DynamicCoordinatesT.cpp
MCCoordsT.cpp
MCWalkerConfigurationT.cpp
WalkerConfigurations.cpp
WalkerConfigurationsT.cpp
SpeciesSet.cpp
SampleStackT.cpp
createDistanceTableAA.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/Particle/InitMolecularSystemT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ InitMolecularSystemT<T>::reset()

#ifndef QMC_COMPLEX
template class InitMolecularSystemT<double>;
template class InitMolecularSystemT<float>;
// template class InitMolecularSystemT<float>;
#else
template class InitMolecularSystemT<std::complex<double>>;
template class InitMolecularSystemT<std::complex<float>>;
Expand Down
48 changes: 24 additions & 24 deletions src/Particle/MCWalkerConfigurationT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ MCWalkerConfigurationT<T>::MCWalkerConfigurationT(
{
samples.clearEnsemble();
samples.setMaxSamples(mcw.getMaxSamples());
setWalkerOffsets(mcw.getWalkerOffsets());
this->setWalkerOffsets(mcw.getWalkerOffsets());
this->Properties = mcw.Properties;
}

Expand All @@ -70,11 +70,11 @@ template <typename T>
void
MCWalkerConfigurationT<T>::createWalkers(int n)
{
const int old_nw = getActiveWalkers();
WalkerConfigurations::createWalkers(n, this->TotalNum);
const int old_nw = this->getActiveWalkers();
WalkerConfigurationsT<T>::createWalkers(n, this->TotalNum);
// no pre-existing walkers, need to initialized based on particleset.
if (old_nw == 0)
for (auto& awalker : walker_list_) {
for (auto& awalker : this->walker_list_) {
awalker->R = this->R;
awalker->spins = this->spins;
}
Expand All @@ -85,16 +85,16 @@ template <typename T>
void
MCWalkerConfigurationT<T>::resize(int numWalkers, int numPtcls)
{
if (this->TotalNum && walker_list_.size())
if (this->TotalNum && this->walker_list_.size())
app_warning()
<< "MCWalkerConfiguration::resize cleans up the walker list."
<< std::endl;
const int old_nw = getActiveWalkers();
const int old_nw = this->getActiveWalkers();
ParticleSetT<T>::resize(unsigned(numPtcls));
WalkerConfigurations::resize(numWalkers, this->TotalNum);
WalkerConfigurationsT<T>::resize(numWalkers, this->TotalNum);
// no pre-existing walkers, need to initialized based on particleset.
if (old_nw == 0)
for (auto& awalker : walker_list_) {
for (auto& awalker : this->walker_list_) {
awalker->R = this->R;
awalker->spins = this->spins;
}
Expand Down Expand Up @@ -139,7 +139,7 @@ MCWalkerConfigurationT<T>::resetWalkerProperty(int ncopy)
APP_ABORT("Fatal Exception");
}

for (auto& walker : walker_list_) {
for (auto& walker : this->walker_list_) {
walker->resizeProperty(ncopy, m);
walker->Weight = 1.0;
}
Expand All @@ -153,12 +153,12 @@ MCWalkerConfigurationT<T>::resizeWalkerHistories()
// using std::vector<std::vector<RealType> > is too costly.
int np = this->PropertyHistory.size();
if (np)
for (int iw = 0; iw < walker_list_.size(); ++iw)
walker_list_[iw]->PropertyHistory = this->PropertyHistory;
for (int iw = 0; iw < this->walker_list_.size(); ++iw)
this->walker_list_[iw]->PropertyHistory = this->PropertyHistory;
np = this->PHindex.size();
if (np)
for (int iw = 0; iw < walker_list_.size(); ++iw)
walker_list_[iw]->PHindex = this->PHindex;
for (int iw = 0; iw < this->walker_list_.size(); ++iw)
this->walker_list_[iw]->PHindex = this->PHindex;
;
}

Expand All @@ -179,7 +179,7 @@ template <typename T>
void
MCWalkerConfigurationT<T>::saveEnsemble()
{
saveEnsemble(walker_list_.begin(), walker_list_.end());
saveEnsemble(this->walker_list_.begin(), this->walker_list_.end());
}

/** save the [first,last) walkers to SampleStack
Expand Down Expand Up @@ -211,14 +211,14 @@ MCWalkerConfigurationT<T>::loadEnsemble()
int nsamples = std::min(samples.getMaxSamples(), samples.getNumSamples());
if (samples.empty() || nsamples == 0)
return;
Walker_t::PropertyContainer_t prop(
typename Walker_t::PropertyContainer_t prop(
1, this->PropertyList.size(), 1, WP::MAXPROPERTIES);
walker_list_.resize(nsamples);
this->walker_list_.resize(nsamples);
for (int i = 0; i < nsamples; ++i) {
auto awalker = std::make_unique<Walker_t>(this->TotalNum);
awalker->Properties.copy(prop);
samples.getSample(i).convertToWalker(*awalker);
walker_list_[i] = std::move(awalker);
this->walker_list_[i] = std::move(awalker);
}
resizeWalkerHistories();
samples.clearEnsemble();
Expand All @@ -230,7 +230,7 @@ MCWalkerConfigurationT<T>::dumpEnsemble(
std::vector<MCWalkerConfigurationT<T>*>& others, HDFWalkerOutput& out,
int np, int nBlock)
{
WalkerConfigurations wctemp;
WalkerConfigurationsT<T> wctemp;
for (auto* mcwc : others) {
const auto& astack(mcwc->getSampleStack());
const size_t sample_size =
Expand Down Expand Up @@ -277,18 +277,18 @@ MCWalkerConfigurationT<T>::loadEnsemble(
}
int nw_tot = off.back();
if (nw_tot) {
Walker_t::PropertyContainer_t prop(
typename Walker_t::PropertyContainer_t prop(
1, this->PropertyList.size(), 1, WP::MAXPROPERTIES);
while (walker_list_.size())
pop_back();
walker_list_.resize(nw_tot);
while (this->walker_list_.size())
this->pop_back();
this->walker_list_.resize(nw_tot);
for (int i = 0; i < others.size(); ++i) {
SampleStackT<T>& astack(others[i]->getSampleStack());
for (int j = 0, iw = off[i]; iw < off[i + 1]; ++j, ++iw) {
auto awalker = std::make_unique<Walker_t>(this->TotalNum);
awalker->Properties.copy(prop);
astack.getSample(j).convertToWalker(*awalker);
walker_list_[iw] = std::move(awalker);
this->walker_list_[iw] = std::move(awalker);
}
if (doclean)
others[i]->clearEnsemble();
Expand All @@ -307,7 +307,7 @@ MCWalkerConfigurationT<T>::clearEnsemble()

#ifndef QMC_COMPLEX
template class MCWalkerConfigurationT<double>;
template class MCWalkerConfigurationT<float>;
// template class MCWalkerConfigurationT<float>;
#else
template class MCWalkerConfigurationT<std::complex<double>>;
template class MCWalkerConfigurationT<std::complex<float>>;
Expand Down
14 changes: 7 additions & 7 deletions src/Particle/MCWalkerConfigurationT.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "Particle/ParticleSetT.h"
#include "Particle/SampleStackT.h"
#include "Particle/Walker.h"
#include "Particle/WalkerConfigurations.h"
#include "Particle/WalkerConfigurationsT.h"
#include "Utilities/IteratorUtility.h"

namespace qmcplusplus
Expand Down Expand Up @@ -60,7 +60,7 @@ class ReptileT;
template <typename T>
class MCWalkerConfigurationT :
public ParticleSetT<T>,
public WalkerConfigurations
public WalkerConfigurationsT<T>
{
public:
/**enumeration for update*/
Expand All @@ -71,16 +71,16 @@ class MCWalkerConfigurationT :
Update_Particle /// move a particle by particle
};

using Walker_t = WalkerConfigurations::Walker_t;
using Walker_t = typename WalkerConfigurationsT<T>::Walker_t;
/// container type of the Properties of a Walker
using PropertyContainer_t = Walker_t::PropertyContainer_t;
using PropertyContainer_t = typename Walker_t::PropertyContainer_t;
/// container type of Walkers
using WalkerList_t = std::vector<std::unique_ptr<Walker_t>>;
/// FIX: a type alias of iterator for an object should not be for just one
/// of many objects it holds.
using iterator = WalkerList_t::iterator;
using iterator = typename WalkerList_t::iterator;
/// const_iterator of Walker container
using const_iterator = WalkerList_t::const_iterator;
using const_iterator = typename WalkerList_t::const_iterator;

using ReptileList_t = UPtrVector<ReptileT<T>>;

Expand All @@ -104,7 +104,7 @@ class MCWalkerConfigurationT :
resize(int numWalkers, int numPtcls);

/// clean up the walker list
using WalkerConfigurations::clear;
using WalkerConfigurationsT<T>::clear;
/// resize Walker::PropertyHistory and Walker::PHindex:
void
resizeWalkerHistories();
Expand Down
2 changes: 1 addition & 1 deletion src/Particle/ParticleSetPoolT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ ParticleSetPoolT<T>::reset()
// explicit instantiations
#ifndef QMC_COMPLEX
template class ParticleSetPoolT<double>;
template class ParticleSetPoolT<float>;
// template class ParticleSetPoolT<float>;
#else
template class ParticleSetPoolT<std::complex<double>>;
template class ParticleSetPoolT<std::complex<float>>;
Expand Down
3 changes: 3 additions & 0 deletions src/Particle/VirtualParticleSetT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,11 @@ VirtualParticleSetT<T>::mw_makeMovesWithSpin(
ParticleSetT<T>::mw_update(p_list);
}

#ifndef QMC_COMPLEX
template class VirtualParticleSetT<double>;
template class VirtualParticleSetT<float>;
#else
template class VirtualParticleSetT<std::complex<double>>;
template class VirtualParticleSetT<std::complex<float>>;
#endif
} // namespace qmcplusplus
Loading

0 comments on commit 4c73f01

Please sign in to comment.