Skip to content

Commit

Permalink
Merge branch 'develop' into custom-isnan
Browse files Browse the repository at this point in the history
  • Loading branch information
prckent authored Jul 21, 2023
2 parents d012330 + b85264d commit 0bdde7a
Show file tree
Hide file tree
Showing 47 changed files with 152 additions and 337 deletions.
21 changes: 11 additions & 10 deletions src/AFQMC/Walkers/WalkerControl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,10 @@ inline int swapWalkersAsync(WlkBucket& wset,
* Implements Cafarrel's minimum branching algorithm.
* - buff: array of walker info (weight,num).
*/
template<class Random>
inline void min_branch(std::vector<std::pair<double, int>>& buff, Random& rng, double max_c, double min_c)
inline void min_branch(std::vector<std::pair<double, int>>& buff,
RandomBase<QMCTraits::FullPrecRealType>& rng,
double max_c,
double min_c)
{
APP_ABORT(" Error: min_branch not implemented yet. \n\n\n");
}
Expand All @@ -217,8 +219,7 @@ inline void min_branch(std::vector<std::pair<double, int>>& buff, Random& rng, d
* Implements Cafarrel's minimum branching algorithm.
* - buff: array of walker info (weight,num).
*/
template<class Random>
inline void serial_comb(std::vector<std::pair<double, int>>& buff, Random& rng)
inline void serial_comb(std::vector<std::pair<double, int>>& buff, RandomBase<QMCTraits::FullPrecRealType>& rng)
{
APP_ABORT(" Error: serial_comb not implemented yet. \n\n\n");
}
Expand All @@ -229,8 +230,10 @@ inline void serial_comb(std::vector<std::pair<double, int>>& buff, Random& rng)
* and number of times the walker should appear in the new list.
* - buff: array of walker info (weight,num).
*/
template<class Random>
inline void pair_branch(std::vector<std::pair<double, int>>& buff, Random& rng, double max_c, double min_c)
inline void pair_branch(std::vector<std::pair<double, int>>& buff,
RandomBase<QMCTraits::FullPrecRealType>& rng,
double max_c,
double min_c)
{
using tp = std::tuple<double, int, int>;
using tp_it = std::vector<tp>::iterator;
Expand Down Expand Up @@ -299,7 +302,6 @@ inline void pair_branch(std::vector<std::pair<double, int>>& buff, Random& rng,
*/
template<class WalkerSet,
class Mat,
class Random,
typename = typename std::enable_if<(WalkerSet::contiguous_walker)>::type,
typename = typename std::enable_if<(WalkerSet::fixed_population)>::type>
inline void SerialBranching(WalkerSet& wset,
Expand All @@ -308,7 +310,7 @@ inline void SerialBranching(WalkerSet& wset,
double max_,
std::vector<int>& wlk_counts,
Mat& Wexcess,
Random& rng,
RandomBase<QMCTraits::FullPrecRealType>& rng,
communicator& comm)
{
std::vector<std::pair<double, int>> buffer(wset.get_global_target_population());
Expand Down Expand Up @@ -363,14 +365,13 @@ inline void SerialBranching(WalkerSet& wset,
*/
template<class WalkerSet,
class Mat,
class Random,
typename = typename std::enable_if<(WalkerSet::contiguous_walker)>::type,
typename = typename std::enable_if<(WalkerSet::fixed_population)>::type>
inline void CombBranching(WalkerSet& wset,
BRANCHING_ALGORITHM type,
std::vector<int>& wlk_counts,
Mat& Wexcess,
Random& rng,
RandomBase<QMCTraits::FullPrecRealType>& rng,
communicator& comm)
{
APP_ABORT("Error: comb not implemented yet. \n");
Expand Down
5 changes: 0 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ if(IS_GIT_PROJECT)
message("Git commit hash: ${GIT_CONFIG_COMMIT_HASH}")
endif()

# For unit tests, enable use for the fake RNG
function(USE_FAKE_RNG TARGET)
target_compile_definitions(${TARGET} PRIVATE "USE_FAKE_RNG")
endfunction()

add_subdirectory(io)
add_subdirectory(einspline)
add_subdirectory(Containers)
Expand Down
5 changes: 0 additions & 5 deletions src/Estimators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,11 @@ set(QMCEST_SRC
####################################
if(USE_OBJECT_TARGET)
add_library(qmcestimators OBJECT ${QMCEST_SRC})
add_library(qmcestimators_unit OBJECT ${QMCEST_SRC})
else()
add_library(qmcestimators ${QMCEST_SRC})
add_library(qmcestimators_unit ${QMCEST_SRC})
endif()
use_fake_rng(qmcestimators_unit)

target_include_directories(qmcestimators PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
target_include_directories(qmcestimators_unit PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(qmcestimators PUBLIC containers qmcham qmcparticle qmcutil)
target_link_libraries(qmcestimators_unit PUBLIC containers qmcham_unit qmcparticle qmcutil)

add_subdirectory(tests)
4 changes: 2 additions & 2 deletions src/Estimators/EstimatorManagerCrowd.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ class EstimatorManagerCrowd

UPtr<ScalarEstimatorBase> main_estimator_;
///estimators of simple scalars
std::vector<std::unique_ptr<ScalarEstimatorBase>> scalar_estimators_;
UPtrVector<ScalarEstimatorBase> scalar_estimators_;

std::vector<std::unique_ptr<OperatorEstBase>> operator_ests_;
UPtrVector<OperatorEstBase> operator_ests_;
};

} // namespace qmcplusplus
Expand Down
57 changes: 14 additions & 43 deletions src/Estimators/OneBodyDensityMatrices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ size_t OneBodyDensityMatrices::calcFullDataSize(const size_t basis_size, const i

void OneBodyDensityMatrices::startBlock(int steps) {}

template<class RNG_GEN>
void OneBodyDensityMatrices::generateSamples(const Real weight, ParticleSet& pset_target, RNG_GEN& rng, int steps)
void OneBodyDensityMatrices::generateSamples(const Real weight,
ParticleSet& pset_target,
RandomBase<FullPrecReal>& rng,
int steps)
{
ScopedTimer local_timer(timers_.gen_samples_timer);

Expand Down Expand Up @@ -261,8 +263,7 @@ void OneBodyDensityMatrices::generateSamples(const Real weight, ParticleSet& pse
}
}

template<typename RNG_GEN>
inline void OneBodyDensityMatrices::generateUniformGrid(RNG_GEN& rng)
inline void OneBodyDensityMatrices::generateUniformGrid(RandomBase<FullPrecReal>& rng)
{
Position rp;
Position ushift = 0.0;
Expand All @@ -283,8 +284,7 @@ inline void OneBodyDensityMatrices::generateUniformGrid(RNG_GEN& rng)
}
}

template<typename RAN_GEN>
inline void OneBodyDensityMatrices::generateUniformSamples(RAN_GEN& rng)
inline void OneBodyDensityMatrices::generateUniformSamples(RandomBase<FullPrecReal>& rng)
{
Position rp;
for (int s = 0; s < samples_; ++s)
Expand All @@ -295,8 +295,10 @@ inline void OneBodyDensityMatrices::generateUniformSamples(RAN_GEN& rng)
}
}

template<typename RAN_GEN>
inline void OneBodyDensityMatrices::generateDensitySamples(bool save, int steps, RAN_GEN& rng, ParticleSet& pset_target)
inline void OneBodyDensityMatrices::generateDensitySamples(bool save,
int steps,
RandomBase<FullPrecReal>& rng,
ParticleSet& pset_target)
{
const auto timestep = input_.get_timestep();
Real sqt = std::sqrt(timestep);
Expand Down Expand Up @@ -352,8 +354,7 @@ inline void OneBodyDensityMatrices::generateDensitySamples(bool save, int steps,
rhocur_ = rho;
}

template<typename RAN_GEN>
OneBodyDensityMatrices::Position OneBodyDensityMatrices::diffuse(const Real sqt, RAN_GEN& rng)
OneBodyDensityMatrices::Position OneBodyDensityMatrices::diffuse(const Real sqt, RandomBase<FullPrecReal>& rng)
{
Position diff;
assignGaussRand(&diff[0], OHMMS_DIM, rng);
Expand Down Expand Up @@ -401,11 +402,10 @@ void OneBodyDensityMatrices::accumulate(const RefVector<MCPWalker>& walkers,
implAccumulate(walkers, psets, wfns, rng);
}

template<class RNG_GEN>
void OneBodyDensityMatrices::implAccumulate(const RefVector<MCPWalker>& walkers,
const RefVector<ParticleSet>& psets,
const RefVector<TrialWaveFunction>& wfns,
RNG_GEN& rng)
RandomBase<FullPrecReal>& rng)
{
for (int iw = 0; iw < walkers.size(); ++iw)
{
Expand All @@ -414,11 +414,10 @@ void OneBodyDensityMatrices::implAccumulate(const RefVector<MCPWalker>& walkers,
}
}

template<class RNG_GEN>
void OneBodyDensityMatrices::evaluateMatrix(ParticleSet& pset_target,
TrialWaveFunction& psi_target,
const MCPWalker& walker,
RNG_GEN& rng)
RandomBase<FullPrecReal>& rng)
{
//perform warmup sampling the first time
warmupSampling(pset_target, rng);
Expand Down Expand Up @@ -548,8 +547,7 @@ inline void OneBodyDensityMatrices::updateBasisD012(const Position& r, ParticleS
basis_laplacians_[i] *= basis_norms_[i];
}

template<class RAN_GEN>
void OneBodyDensityMatrices::warmupSampling(ParticleSet& pset_target, RAN_GEN& rng)
void OneBodyDensityMatrices::warmupSampling(ParticleSet& pset_target, RandomBase<FullPrecReal>& rng)
{
if (sampling_ == Sampling::METROPOLIS)
{
Expand Down Expand Up @@ -624,31 +622,4 @@ void OneBodyDensityMatrices::registerOperatorEstimator(hdf_archive& file)
}
}

template void OneBodyDensityMatrices::generateSamples<RandomGenerator>(Real weight,
ParticleSet& pset_target,
RandomGenerator& rng,
int steps);
template void OneBodyDensityMatrices::evaluateMatrix<RandomGenerator>(ParticleSet& pset_target,
TrialWaveFunction& psi_target,
const MCPWalker& walker,
RandomGenerator& rng);
template void OneBodyDensityMatrices::implAccumulate<RandomGenerator>(const RefVector<MCPWalker>& walkers,
const RefVector<ParticleSet>& psets,
const RefVector<TrialWaveFunction>& wfns,
RandomGenerator& rng);
#if defined(USE_FAKE_RNG) || defined(QMC_RNG_BOOST)
template void OneBodyDensityMatrices::generateSamples<StdRandom<double>>(Real weight,
ParticleSet& pset_target,
StdRandom<double>& rng,
int steps);
template void OneBodyDensityMatrices::evaluateMatrix<StdRandom<double>>(ParticleSet& pset_target,
TrialWaveFunction& psi_target,
const MCPWalker& walker,
StdRandom<double>& rng);
template void OneBodyDensityMatrices::implAccumulate<StdRandom<double>>(const RefVector<MCPWalker>& walkers,
const RefVector<ParticleSet>& psets,
const RefVector<TrialWaveFunction>& wfns,
StdRandom<double>& rng);
#endif

} // namespace qmcplusplus
56 changes: 12 additions & 44 deletions src/Estimators/OneBodyDensityMatrices.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,21 @@ class OneBodyDensityMatrices : public OperatorEstBase
/** Unfortunate design RandomGenerator type aliasing and
* virtual inheritance requires this for testing.
*/
template<class RNG_GEN>
void implAccumulate(const RefVector<MCPWalker>& walkers,
const RefVector<ParticleSet>& psets,
const RefVector<TrialWaveFunction>& wfns,
RNG_GEN& rng);
RandomBase<FullPrecReal>& rng);

size_t calcFullDataSize(size_t basis_size, int num_species);
//local functions
void normalizeBasis(ParticleSet& pset_target);
// printing
void report(const std::string& pad = "");
template<class RNG_GEN>
void evaluateMatrix(ParticleSet& pset_target, TrialWaveFunction& psi_target, const MCPWalker& walker, RNG_GEN& rng);

void evaluateMatrix(ParticleSet& pset_target,
TrialWaveFunction& psi_target,
const MCPWalker& walker,
RandomBase<FullPrecReal>& rng);
// sample generation
/** Dispatch method to difference methods of generating samples.
* dispatch determined by Integrator.
Expand All @@ -218,12 +220,9 @@ class OneBodyDensityMatrices : public OperatorEstBase
* * update basis_values_, basis_gradients_, basis_laplacians_
*/
// These functions deserve unit tests and likely should be pure functions.
template<class RNG_GEN>
void generateSamples(const Real weight, ParticleSet& pset_target, RNG_GEN& rng, int steps = 0);
template<class RNG_GEN>
void generateUniformGrid(RNG_GEN& rng);
template<class RNG_GEN>
void generateUniformSamples(RNG_GEN& rng);
void generateSamples(const Real weight, ParticleSet& pset_target, RandomBase<FullPrecReal>& rng, int steps = 0);
void generateUniformGrid(RandomBase<FullPrecReal>& rng);
void generateUniformSamples(RandomBase<FullPrecReal>& rng);
/** generate samples for density integration
* \param[in] save if false throw out the samples
* \param[in] steps actually the number of samples which are basically steps.
Expand All @@ -233,14 +232,12 @@ class OneBodyDensityMatrices : public OperatorEstBase
* sideeffects:
* *
*/
template<class RNG_GEN>
void generateDensitySamples(bool save, int steps, RNG_GEN& rng, ParticleSet& pset_target);
void generateDensitySamples(bool save, int steps, RandomBase<FullPrecReal>& rng, ParticleSet& pset_target);
void generateSampleRatios(ParticleSet& pset_target,
TrialWaveFunction& psi_target,
std::vector<Matrix<Value>>& Psi_nm);
/// produce a position difference vector from timestep
template<class RNG_GEN>
Position diffuse(const Real sqt, RNG_GEN& rng);
Position diffuse(const Real sqt, RandomBase<FullPrecReal>& rng);
/** calculate density based on r
* \param[in] r position
* \param[out] dens density
Expand Down Expand Up @@ -290,8 +287,7 @@ class OneBodyDensityMatrices : public OperatorEstBase
* sets initial rhocur_ and dpcur_
* Then calls generateSamples with number of input warmup samples.
*/
template<typename RAN_GEN>
void warmupSampling(ParticleSet& pset_target, RAN_GEN& rng);
void warmupSampling(ParticleSet& pset_target, RandomBase<FullPrecReal>& rng);

struct OneBodyDensityMatrixTimers
{
Expand Down Expand Up @@ -319,34 +315,6 @@ class OneBodyDensityMatrices : public OperatorEstBase
template<typename T>
friend class testing::OneBodyDensityMatricesTests;
};

extern template void OneBodyDensityMatrices::generateSamples<RandomGenerator>(Real weight,
ParticleSet& pset_target,
RandomGenerator& rng,
int steps);
extern template void OneBodyDensityMatrices::evaluateMatrix<RandomGenerator>(ParticleSet& pset_target,
TrialWaveFunction& psi_target,
const MCPWalker& walker,
RandomGenerator& rng);
extern template void OneBodyDensityMatrices::implAccumulate<RandomGenerator>(const RefVector<MCPWalker>& walkers,
const RefVector<ParticleSet>& psets,
const RefVector<TrialWaveFunction>& wfns,
RandomGenerator& rng);
#if defined(USE_FAKE_RNG) || defined(QMC_RNG_BOOST)
extern template void OneBodyDensityMatrices::generateSamples<StdRandom<double>>(Real weight,
ParticleSet& pset_target,
StdRandom<double>& rng,
int steps);
extern template void OneBodyDensityMatrices::evaluateMatrix<StdRandom<double>>(ParticleSet& pset_target,
TrialWaveFunction& psi_target,
const MCPWalker& walker,
StdRandom<double>& rng);
extern template void OneBodyDensityMatrices::implAccumulate<StdRandom<double>>(const RefVector<MCPWalker>& walkers,
const RefVector<ParticleSet>& psets,
const RefVector<TrialWaveFunction>& wfns,
StdRandom<double>& rng);
#endif

} // namespace qmcplusplus

#endif
15 changes: 7 additions & 8 deletions src/Estimators/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ set(SRCS
test_MagnetizationDensity.cpp)

add_executable(${UTEST_EXE} ${SRCS})
use_fake_rng(${UTEST_EXE})
target_link_libraries(${UTEST_EXE} catch_main qmcutil qmcestimators_unit utilities_for_test sposets_for_testing)
target_link_libraries(${UTEST_EXE} catch_main qmcutil qmcestimators utilities_for_test sposets_for_testing)
if(USE_OBJECT_TARGET)
target_link_libraries(
${UTEST_EXE}
qmcutil
qmcestimators_unit
qmcham_unit
qmcestimators
qmcham
qmcwfs
qmcparticle
qmcwfs_omptarget
Expand All @@ -72,9 +71,9 @@ if(HAVE_MPI)
if(USE_OBJECT_TARGET)
target_link_libraries(
${UTEST_EXE}
qmcestimators_unit
qmcham_unit
qmcdriver_unit
qmcestimators
qmcham
qmcdriver
qmcwfs
qmcparticle
qmcwfs_omptarget
Expand All @@ -83,7 +82,7 @@ if(HAVE_MPI)
platform_omptarget_LA
utilities_for_test)
endif()
target_link_libraries(${UTEST_EXE} catch_main qmcestimators_unit)
target_link_libraries(${UTEST_EXE} catch_main qmcestimators)
# Right now the unified driver mpi tests are hard coded for 3 MPI ranks
add_unit_test(${UTEST_NAME} 3 1 $<TARGET_FILE:${UTEST_EXE}>)
endif()
2 changes: 1 addition & 1 deletion src/Estimators/tests/test_EstimatorManagerCrowd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ TEST_CASE("EstimatorManagerCrowd PerParticleHamiltonianLogger integration", "[es
emc.registerListeners(ham_list);

// Setup RNG
RandomGenerator rng;
FakeRandom<OHMMS_PRECISION_FULL> rng;

// Without this QMCHamiltonian::mw_evaluate segfaults
// Because the CoulombPBCAA hamiltonian component has PtclRhoK (StructFact) that is invalid.
Expand Down
2 changes: 1 addition & 1 deletion src/Estimators/tests/test_MomentumDistribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ TEST_CASE("MomentumDistribution::accumulate", "[estimators]")
auto ref_wfns = convertUPtrToRefVector(wfns);

// Setup RNG
RandomGenerator rng;
FakeRandom<OHMMS_PRECISION_FULL> rng;

// Perform accumulate
md.accumulate(ref_walkers, ref_psets, ref_wfns, rng);
Expand Down
Loading

0 comments on commit 0bdde7a

Please sign in to comment.