From 03a8651b5cc23773f651c39bfed4690bd8dcbd83 Mon Sep 17 00:00:00 2001 From: Peter Doak Date: Wed, 25 Oct 2023 15:20:56 -0400 Subject: [PATCH 01/11] Add ported References points --- src/Estimators/NEReferencePoints.cpp | 138 +++++++++++++++ src/Estimators/NEReferencePoints.h | 67 +++++++ .../tests/ValidReferencePointsInput.h | 74 ++++++++ src/Estimators/tests/test_ReferencePoints.cpp | 164 ++++++++++++++++++ .../tests/test_ReferencePointsInput.cpp | 53 ++++++ 5 files changed, 496 insertions(+) create mode 100644 src/Estimators/NEReferencePoints.cpp create mode 100644 src/Estimators/NEReferencePoints.h create mode 100644 src/Estimators/tests/ValidReferencePointsInput.h create mode 100644 src/Estimators/tests/test_ReferencePoints.cpp create mode 100644 src/Estimators/tests/test_ReferencePointsInput.cpp diff --git a/src/Estimators/NEReferencePoints.cpp b/src/Estimators/NEReferencePoints.cpp new file mode 100644 index 0000000000..2e15bcc596 --- /dev/null +++ b/src/Estimators/NEReferencePoints.cpp @@ -0,0 +1,138 @@ +////////////////////////////////////////////////////////////////////////////////////// +// This file is distributed under the University of Illinois/NCSA Open Source License. +// See LICENSE file in top directory for details. +// +// Copyright (c) 2022 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 +// Peter W. Doak. doakpw@ornl.gov, Oak Ridge National Laboratory +// +// File refactored from: QMCHamiltonian/ReferencePoints.cpp +////////////////////////////////////////////////////////////////////////////////////// + + +#include "NEReferencePoints.h" +#include "Utilities/string_utils.h" +#include "OhmmsData/AttributeSet.h" +#include "QMCHamiltonians/ObservableHelper.h" + +namespace qmcplusplus +{ +NEReferencePoints::NEReferencePoints(const ReferencePointsInput& rp_input, + ParticleSet& pset, + RefVector& ref_psets) + : input_(rp_input) +{ + processParticleSets(pset, ref_psets); + for (int i = 0; i < OHMMS_DIM; i++) + for (int d = 0; d < OHMMS_DIM; d++) + axes(d, i) = pset.getLattice().a(i)[d]; + Axes crd; + // no need to handle error here rp_input will have a valid value for coord_form + switch (input_.get_coord_form()) + { + case Coord::CELL: + crd = axes; + break; + case Coord::CARTESIAN: + for (int i = 0; i < OHMMS_DIM; i++) + for (int d = 0; d < OHMMS_DIM; d++) + if (d == i) + crd(i, i) = 1.0; + else + crd(d, i) = 0.0; + break; + } + + for (const auto& [key, value] : input_.get_points()) + points_[key] = dot(crd, value); +} + +void NEReferencePoints::processParticleSets(ParticleSet& P, RefVector& Psets) +{ + //get axes and origin information from the ParticleSet + points_["zero"] = 0 * P.getLattice().a(0); + points_["a1"] = P.getLattice().a(0); + points_["a2"] = P.getLattice().a(1); + points_["a3"] = P.getLattice().a(2); + //points_["center"]= .5*(P.getLattice().a(0)+P.getLattice().a(1)+P.Lattice.a(2)) + //set points_ on face centers + points_["f1p"] = points_["zero"] + .5 * points_["a1"]; + points_["f1m"] = points_["zero"] - .5 * points_["a1"]; + points_["f2p"] = points_["zero"] + .5 * points_["a2"]; + points_["f2m"] = points_["zero"] - .5 * points_["a2"]; + points_["f3p"] = points_["zero"] + .5 * points_["a3"]; + points_["f3m"] = points_["zero"] - .5 * points_["a3"]; + //set points_ on cell corners + points_["cmmm"] = points_["zero"] + .5 * (-1 * points_["a1"] - points_["a2"] - points_["a3"]); + points_["cpmm"] = points_["zero"] + .5 * (points_["a1"] - points_["a2"] - points_["a3"]); + points_["cmpm"] = points_["zero"] + .5 * (-1 * points_["a1"] + points_["a2"] - points_["a3"]); + points_["cmmp"] = points_["zero"] + .5 * (-1 * points_["a1"] - points_["a2"] + points_["a3"]); + points_["cmpp"] = points_["zero"] + .5 * (-1 * points_["a1"] + points_["a2"] + points_["a3"]); + points_["cpmp"] = points_["zero"] + .5 * (points_["a1"] - points_["a2"] + points_["a3"]); + points_["cppm"] = points_["zero"] + .5 * (points_["a1"] + points_["a2"] - points_["a3"]); + points_["cppp"] = points_["zero"] + .5 * (points_["a1"] + points_["a2"] + points_["a3"]); + //get points from requested particle sets + int cshift = 1; + for (ParticleSet& pset : Psets) + { + for (int p = 0; p < pset.getTotalNum(); p++) + { + std::stringstream ss; + ss << p + cshift; + points_[pset.getName() + ss.str()] = pset.R[p]; + } + } +} + +void NEReferencePoints::write_description(std::ostream& os, const std::string& indent) const +{ + os << indent + "reference_points" << std::endl; + std::map::const_iterator it, end = points_.end(); + for (it = points_.begin(); it != end; ++it) + { + os << indent + " " << it->first << ": " << it->second << std::endl; + } + os << indent + "end reference_points" << std::endl; + return; +} + +void NEReferencePoints::write(hdf_archive& file) const +{ + file.push(std::string_view("reference_points")); + for (auto it = points_.cbegin(); it != points_.cend(); ++it) + file.write(const_cast(it->second), it->first); + file.pop(); +} + +std::ostream& operator<<(std::ostream& out, const NEReferencePoints& rhs) +{ + rhs.write_description(out, ""); + return out; +} + +namespace testing +{ +void TestableNEReferencePoints::write_testable_description(std::ostream& os) const +{ + os << "{" << '\n'; + std::map::const_iterator it, end = points_.end(); + for (it = points_.begin(); it != end; ++it) + { + os << " {\"" << it->first << "\", {" << std::setw(16) << std::setprecision(16) << it->second[0] << "," << it->second[1] << "," << it->second[2] + << "}}," << '\n'; + } + os << "};" << '\n'; + return; +} +} // namespace testing + +std::ostream& operator<<(std::ostream& out, const testing::TestableNEReferencePoints& rhs) +{ + rhs.write_testable_description(out); + return out; +} + + +} // namespace qmcplusplus diff --git a/src/Estimators/NEReferencePoints.h b/src/Estimators/NEReferencePoints.h new file mode 100644 index 0000000000..f10c3df31f --- /dev/null +++ b/src/Estimators/NEReferencePoints.h @@ -0,0 +1,67 @@ +////////////////////////////////////////////////////////////////////////////////////// +// This file is distributed under the University of Illinois/NCSA Open Source License. +// See LICENSE file in top directory for details. +// +// Copyright (c) 2022 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 +// Peter W. Doak. doakpw@ornl.gov, Oak Ridge National Laboratory +// +// File refactored from: QMCHamiltonian/ReferencePoints.h +////////////////////////////////////////////////////////////////////////////////////// + + +#ifndef QMCPLUSPLUS_NEREFERENCE_POINTS_H +#define QMCPLUSPLUS_NEREFERENCE_POINTS_H + +#include +#include "OhmmsData/OhmmsElementBase.h" +#include "Particle/ParticleSet.h" +#include "QMCHamiltonians/ObservableHelper.h" +#include "OhmmsPETE/Tensor.h" +#include "ReferencePointsInput.h" + +namespace qmcplusplus +{ +class NEReferencePoints +{ +public: + using Real = QMCTraits::RealType; + using Axes = Tensor; + using Point = TinyVector; + using Points = std::map; + using Coord = typename ReferencePointsInput::Coord; + NEReferencePoints(const ReferencePointsInput& rp_input, ParticleSet& pset, RefVector& ref_psets); + NEReferencePoints(const NEReferencePoints& nerp) = default; + + void processParticleSets(ParticleSet& P, RefVector& Pref); + void write_description(std::ostream& os, const std::string& indent) const; + void write(hdf_archive& file) const; + const Points& get_points() const { return points_; } + +protected: + Points points_; + +private: + Axes axes; + ReferencePointsInput input_; +}; + +std::ostream& operator<<(std::ostream& out, const NEReferencePoints& rhs); + +namespace testing +{ +class TestableNEReferencePoints : public NEReferencePoints +{ +public: + TestableNEReferencePoints(const NEReferencePoints& nerp) : NEReferencePoints(nerp) {} + void write_testable_description(std::ostream& os) const; +}; +} // namespace testing + +std::ostream& operator<<(std::ostream& out, const testing::TestableNEReferencePoints& rhs); +} // namespace qmcplusplus + + +#endif diff --git a/src/Estimators/tests/ValidReferencePointsInput.h b/src/Estimators/tests/ValidReferencePointsInput.h new file mode 100644 index 0000000000..f500c16905 --- /dev/null +++ b/src/Estimators/tests/ValidReferencePointsInput.h @@ -0,0 +1,74 @@ +////////////////////////////////////////////////////////////////////////////////////// +// This file is distributed under the University of Illinois/NCSA Open Source License. +// See LICENSE file in top directory for details. +// +// Copyright (c) 2023 QMCPACK developers. +// +// File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Lab +// +// File created by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Lab +////////////////////////////////////////////////////////////////////////////////////// + +#ifndef QMCPLUSPLUS_VALID_REFERENCEPOINTS_INPUT_H +#define QMCPLUSPLUS_VALID_REFERENCEPOINTS_INPUT_H + +#include +#include + +namespace qmcplusplus +{ +namespace testing +{ + +struct ValidReferencePointsInputs +{ + static constexpr std::array xml{ + R"XML( + + r1 1 0 0 + r2 0 1 0 + r3 0 0 1 + +)XML", + R"XML( + + r1 1 0 0 + r2 0 1 0 + r3 0 0 1 + +)XML"}; + + enum valid + { + CELL = 0, + CARTESIAN + }; +}; + +struct InvalidReferencePointsInputs +{ + static constexpr std::array xml{ + R"XML( + + r1 1 0 0 + r2 0 1 + r3 0 0 1 + +)XML", + R"XML( + + r1 1 0 0 + r2 0 1 ab + +)XML"}; + enum invalid + { + PARAM = 0, + NUM + }; +}; + +} // namespace testing +} // namespace qmcplusplus + +#endif diff --git a/src/Estimators/tests/test_ReferencePoints.cpp b/src/Estimators/tests/test_ReferencePoints.cpp new file mode 100644 index 0000000000..e1890a7faf --- /dev/null +++ b/src/Estimators/tests/test_ReferencePoints.cpp @@ -0,0 +1,164 @@ +////////////////////////////////////////////////////////////////////////////////////// +// This file is distributed under the University of Illinois/NCSA Open Source License. +// See LICENSE file in top directory for details. +// +// Copyright (c) 2023 QMCPACK developers. +// +// File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Lab +////////////////////////////////////////////////////////////////////////////////////// + +#include "catch.hpp" + +#include "NEReferencePoints.h" +#include "ReferencePointsInput.h" +#include "ValidReferencePointsInput.h" +#include "OhmmsData/Libxml2Doc.h" +#include "EstimatorTesting.h" +#include "Particle/tests/MinimalParticlePool.h" + +/** \file + * This is a postfacto unit testing written for reference points during porting of EnergyDensity + * to the batched version of the estimators. + */ + +namespace qmcplusplus +{ +constexpr bool generate_test_data = false; + +template +bool approxEquality(const TinyVector& val_a, const TinyVector& val_b) +{ + for (int i = 0; i < D; ++i) + if (val_a[i] != Approx(val_b[i])) + return false; + return true; +} + +TEST_CASE("ReferencePoints::DefaultConstruction", "[estimators]") +{ + using Input = testing::ValidReferencePointsInputs; + Libxml2Document doc; + bool okay = doc.parseFromString(Input::xml[Input::valid::CELL]); + xmlNodePtr node = doc.getRoot(); + ReferencePointsInput rpi(node); + + auto lattice = testing::makeTestLattice(); + Communicate* comm; + comm = OHMMS::Controller; + auto particle_pool = MinimalParticlePool::make_diamondC_1x1x1(comm); + auto& pset = *(particle_pool.getParticleSet("e")); + auto& pset_ions = *(particle_pool.getParticleSet("ion")); + + // Setup particleset + pset.R = ParticleSet::ParticlePos{{1.751870349, 4.381521229, 2.865202269}, {3.244515371, 4.382273176, 4.21105285}, + {3.000459944, 3.329603408, 4.265030556}, {3.748660329, 3.63420622, 5.393637791}, + {3.033228526, 3.391869137, 4.654413566}, {3.114198787, 2.654334594, 5.231075822}, + {3.657151589, 4.883870516, 4.201243939}, {2.97317591, 4.245644974, 4.284564732}}; + + RefVector ref_psets; + ref_psets.push_back(pset_ions); + NEReferencePoints ref_points(rpi, pset, ref_psets); + + if (generate_test_data) + { + testing::TestableNEReferencePoints tref_points(ref_points); + std::cout << "expected_reference_points" << tref_points; + } + typename NEReferencePoints::Points expected_reference_points{ + {"a1", {3.37316107749939, 3.37316107749939, 0}}, + {"a2", {0, 3.37316107749939, 3.37316107749939}}, + {"a3", {3.37316107749939, 0, 3.37316107749939}}, + {"cmmm", {-3.37316107749939, -3.37316107749939, -3.37316107749939}}, + {"cmmp", {0, -3.37316107749939, 0}}, + {"cmpm", {-3.37316107749939, 0, 0}}, + {"cmpp", {0, 0, 3.37316107749939}}, + {"cpmm", {0, 0, -3.37316107749939}}, + {"cpmp", {3.37316107749939, 0, 0}}, + {"cppm", {0, 3.37316107749939, 0}}, + {"cppp", {3.37316107749939, 3.37316107749939, 3.37316107749939}}, + {"f1m", {-1.686580538749695, -1.686580538749695, 0}}, + {"f1p", {1.686580538749695, 1.686580538749695, 0}}, + {"f2m", {0, -1.686580538749695, -1.686580538749695}}, + {"f2p", {0, 1.686580538749695, 1.686580538749695}}, + {"f3m", {-1.686580538749695, 0, -1.686580538749695}}, + {"f3p", {1.686580538749695, 0, 1.686580538749695}}, + {"ion1", {0, 0, 0}}, + {"ion2", {1.686580538749695, 1.686580538749695, 1.686580538749695}}, + {"r1", {3.37316107749939, 3.37316107749939, 0}}, + {"r2", {0, 3.37316107749939, 3.37316107749939}}, + {"r3", {3.37316107749939, 0, 3.37316107749939}}, + {"zero", {0, 0, 0}}, + }; + + for (auto& [key, value] : ref_points.get_points()) + { + bool coords_match = approxEquality(expected_reference_points[key], value); + CHECK(coords_match); + } +} + +TEST_CASE("ReferencePoints::Construction", "[estimators]") +{ + using Input = testing::ValidReferencePointsInputs; + Libxml2Document doc; + bool okay = doc.parseFromString(Input::xml[Input::valid::CELL]); + xmlNodePtr node = doc.getRoot(); + ReferencePointsInput rpi(node); + + auto lattice = testing::makeTestLattice(); + Communicate* comm; + comm = OHMMS::Controller; + auto particle_pool = MinimalParticlePool::make_diamondC_1x1x1(comm); + auto& pset = *(particle_pool.getParticleSet("e")); + auto& pset_ions = *(particle_pool.getParticleSet("ion")); + + // Setup particleset + pset.R = ParticleSet::ParticlePos{{1.751870349, 4.381521229, 2.865202269}, {3.244515371, 4.382273176, 4.21105285}, + {3.000459944, 3.329603408, 4.265030556}, {3.748660329, 3.63420622, 5.393637791}, + {3.033228526, 3.391869137, 4.654413566}, {3.114198787, 2.654334594, 5.231075822}, + {3.657151589, 4.883870516, 4.201243939}, {2.97317591, 4.245644974, 4.284564732}}; + + RefVector ref_psets; + ref_psets.push_back(pset_ions); + NEReferencePoints ref_points(std::move(rpi), pset, ref_psets); + + if (generate_test_data) + { + testing::TestableNEReferencePoints tref_points(ref_points); + std::cout << "expected_reference_points" << tref_points; + } + typename NEReferencePoints::Points expected_reference_points{ + {"a1", {3.37316107749939, 3.37316107749939, 0}}, + {"a2", {0, 3.37316107749939, 3.37316107749939}}, + {"a3", {3.37316107749939, 0, 3.37316107749939}}, + {"cmmm", {-3.37316107749939, -3.37316107749939, -3.37316107749939}}, + {"cmmp", {0, -3.37316107749939, 0}}, + {"cmpm", {-3.37316107749939, 0, 0}}, + {"cmpp", {0, 0, 3.37316107749939}}, + {"cpmm", {0, 0, -3.37316107749939}}, + {"cpmp", {3.37316107749939, 0, 0}}, + {"cppm", {0, 3.37316107749939, 0}}, + {"cppp", {3.37316107749939, 3.37316107749939, 3.37316107749939}}, + {"f1m", {-1.686580538749695, -1.686580538749695, 0}}, + {"f1p", {1.686580538749695, 1.686580538749695, 0}}, + {"f2m", {0, -1.686580538749695, -1.686580538749695}}, + {"f2p", {0, 1.686580538749695, 1.686580538749695}}, + {"f3m", {-1.686580538749695, 0, -1.686580538749695}}, + {"f3p", {1.686580538749695, 0, 1.686580538749695}}, + {"ion1", {0, 0, 0}}, + {"ion2", {1.686580538749695, 1.686580538749695, 1.686580538749695}}, + {"r1", {3.37316107749939, 3.37316107749939, 0}}, + {"r2", {0, 3.37316107749939, 3.37316107749939}}, + {"r3", {3.37316107749939, 0, 3.37316107749939}}, + {"zero", {0, 0, 0}}, + }; + + for (auto& [key, value] : ref_points.get_points()) + { + bool coords_match = approxEquality(expected_reference_points[key], value); + CHECK(coords_match); + } +} + + +} // namespace qmcplusplus diff --git a/src/Estimators/tests/test_ReferencePointsInput.cpp b/src/Estimators/tests/test_ReferencePointsInput.cpp new file mode 100644 index 0000000000..c03c434313 --- /dev/null +++ b/src/Estimators/tests/test_ReferencePointsInput.cpp @@ -0,0 +1,53 @@ +////////////////////////////////////////////////////////////////////////////////////// +// This file is distributed under the University of Illinois/NCSA Open Source License. +// See LICENSE file in top directory for details. +// +// Copyright (c) 2023 QMCPACK developers. +// +// File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Lab +// +// File created by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Lab +////////////////////////////////////////////////////////////////////////////////////// + + +#include "catch.hpp" + +#include +#include + +#include "ReferencePointsInput.h" +#include "ValidReferencePointsInput.h" +#include "OhmmsData/Libxml2Doc.h" + +namespace qmcplusplus +{ + +TEST_CASE("ReferencePointsInput::parseXML::valid", "[estimators]") +{ + using Input = testing::ValidReferencePointsInputs; + for (auto input_xml : Input::xml) + { + Libxml2Document doc; + bool okay = doc.parseFromString(input_xml); + xmlNodePtr node = doc.getRoot(); + + // Will throw if input is invalid. + ReferencePointsInput rpi(node); + } +} + +TEST_CASE("ReferencePointsInput::parseXML::invalid", "[estimators]") +{ + using Input = testing::InvalidReferencePointsInputs; + for (auto input_xml : Input::xml) + { + Libxml2Document doc; + bool okay = doc.parseFromString(input_xml); + REQUIRE(okay); + xmlNodePtr node = doc.getRoot(); + + auto constructBadRefPoints = [](xmlNodePtr cur) { ReferencePointsInput rpi(cur); }; + CHECK_THROWS_AS(constructBadRefPoints(node), UniformCommunicateError); + } +} +} // namespace qmcplusplus From 2ff9b4c5bd6a561c3475514245ac62e4425854e6 Mon Sep 17 00:00:00 2001 From: Peter Doak Date: Wed, 25 Oct 2023 15:29:41 -0400 Subject: [PATCH 02/11] cmake updates to support better testing and NEReferencePoints --- src/Estimators/CMakeLists.txt | 21 ++++- src/Estimators/ReferencePointsInput.cpp | 88 +++++++++++++++++++++ src/Estimators/ReferencePointsInput.h | 101 ++++++++++++++++++++++++ src/Estimators/tests/CMakeLists.txt | 15 +++- 4 files changed, 222 insertions(+), 3 deletions(-) create mode 100644 src/Estimators/ReferencePointsInput.cpp create mode 100644 src/Estimators/ReferencePointsInput.h diff --git a/src/Estimators/CMakeLists.txt b/src/Estimators/CMakeLists.txt index 8e30d88811..b2e7b0417b 100644 --- a/src/Estimators/CMakeLists.txt +++ b/src/Estimators/CMakeLists.txt @@ -11,6 +11,23 @@ # Estimators which accumulate observables #################################### +set(QMCEST_INPUT_SRC + InputSection.cpp + EstimatorInput.cpp + OneBodyDensityMatricesInput.cpp + ReferencePointsInput.cpp + NEReferencePoints.cpp) + +if(USE_OBJECT_TARGET) + add_library(qmcestimators_input OBJECT ${QMCEST_INPUT_SRC}) +else() + add_library(qmcestimators_input ${QMCEST_INPUT_SRC}) +endif() + +target_include_directories(qmcestimators_input PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") +target_link_libraries(qmcestimators_input PUBLIC containers qmcham qmcparticle qmcutil) + + set(QMCEST_SRC InputSection.cpp CSEnergyEstimator.cpp @@ -33,7 +50,9 @@ set(QMCEST_SRC MagnetizationDensity.cpp MagnetizationDensityInput.cpp PerParticleHamiltonianLoggerInput.cpp - PerParticleHamiltonianLogger.cpp) + PerParticleHamiltonianLogger.cpp + ReferencePointsInput.cpp + NEReferencePoints.cpp) #################################### # create libqmcestimators diff --git a/src/Estimators/ReferencePointsInput.cpp b/src/Estimators/ReferencePointsInput.cpp new file mode 100644 index 0000000000..b169836c6c --- /dev/null +++ b/src/Estimators/ReferencePointsInput.cpp @@ -0,0 +1,88 @@ +////////////////////////////////////////////////////////////////////////////////////// +// This file is distributed under the University of Illinois/NCSA Open Source License. +// See LICENSE file in top directory for details. +// +// Copyright (c) 2022 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 +// Peter W. Doak, doakpw@ornl.gov, Oak Ridge National Laboratory +// +// Some code refactored from: QMCHamiltonians/ReferencePoints.cpp +////////////////////////////////////////////////////////////////////////////////////// + +#include "ReferencePointsInput.h" + +#include + +#include "EstimatorInput.h" +#include "ModernStringUtils.hpp" + +namespace qmcplusplus +{ + +ReferencePointsInput::ReferencePointsInput(xmlNodePtr cur) +{ + input_section_.readXML(cur); + auto setIfInInput = LAMBDA_setIfInInput; + setIfInInput(coord_form_, "coord"); + readRefPointsXML(cur); +} + +// ReferencePointsInput::ReferencePointsInput(const Points& points, const CoordForm coord_form) +// : points_(points), coord_form_(coord_form) +// {} + +void ReferencePointsInput::readRefPointsXML(xmlNodePtr cur) +{ + using modernstrutil::split; + using modernstrutil::strip; + + // read refpoints values they are some sequence of value nodes + std::string node_str{XMLNodeString{cur}}; + std::vector lines = split(strip(node_str), "\n"); + for (int i = 0; i < lines.size(); i++) + { + auto stripped_line = strip(lines[i]); + std::vector tokens = split(stripped_line, " "); + if (tokens.size() != OHMMS_DIM + 1) + { + std::ostringstream error; + error << error_tag << "reference point has 4 entries, given " << tokens.size() << ": " << lines[i]; + throw UniformCommunicateError(error.str()); + } + else + { + Point rp; + for (int d = 0; d < OHMMS_DIM; d++) + { + try + { + rp[d] = std::stod(std::string(tokens[d + 1].begin(), tokens[d + 1].size())); + } + catch (const std::invalid_argument& ia) + { + throw UniformCommunicateError(ia.what()); + } + } + + // This must be done in constructor of ReferencePoints + // rp = dot(crd, rp); + points_[std::string(tokens[0].begin(), tokens[0].size())] = rp; + } + } +} + +std::any ReferencePointsInput::ReferencePointsInputSection::assignAnyEnum(const std::string& name) const +{ + return lookupAnyEnum(name, get(name), lookup_input_enum_value); +} + +std::any makeReferencePointsInput(xmlNodePtr cur, std::string& value_label) +{ + ReferencePointsInput rpi{cur}; + value_label = "referencepoints"; + return rpi; +} + +} // namespace qmcplusplus diff --git a/src/Estimators/ReferencePointsInput.h b/src/Estimators/ReferencePointsInput.h new file mode 100644 index 0000000000..a61c4a59b2 --- /dev/null +++ b/src/Estimators/ReferencePointsInput.h @@ -0,0 +1,101 @@ +////////////////////////////////////////////////////////////////////////////////////// +// This file is distributed under the University of Illinois/NCSA Open Source License. +// See LICENSE file in top directory for details. +// +// Copyright (c) 2022 QMCPACK developers. +// +// File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory +// +// Some code refactored from: ReferencePoints.h & ReferencePoints.cpp +////////////////////////////////////////////////////////////////////////////////////// + +#ifndef QMCPLUSPLUS_REFERNCE_POINTS_INPUT_H +#define QMCPLUSPLUS_REFERNCE_POINTS_INPUT_H + +#include +#include +#include + +#include +#include +#include +#include "InputSection.h" + +namespace qmcplusplus +{ +namespace testing +{ +template +class EnergyDensityTests; +} + +class SpaceGrid; + +class ReferencePointsInput +{ +public: + using Real = double; + using Consumer = SpaceGrid; + using Point = TinyVector; + using Points = std::map; + enum class Coord + { + CELL, + CARTESIAN + }; + + /** mapping for enumerated options of ReferencePointsInput + * This data object is the basis of input enum string values + * translation to native C++ scoped enums. This boiler plate is + * generated by utils/code_tools/qmcpack-elisp-generators.el + * qmcp-add-enum-string-map + * + * This plus the virtual assignAnyEnum method are needed by InputSection to + * validate and assign enum values from input. + * + * In testing code we assume this map is bidirectional. + */ + inline static const std::unordered_map lookup_input_enum_value{ + {"coord-cell", Coord::CELL}, + {"coord-cartesian", Coord::CARTESIAN}, + }; + + class ReferencePointsInputSection : public InputSection + { + public: + ReferencePointsInputSection() + { + section_name = "reference_points"; + enums = {"coord"}; + attributes = {"coord"}; + required = {"coord"}; + } + std::any assignAnyEnum(const std::string& name) const override; + ReferencePointsInputSection(const ReferencePointsInputSection&) = default; + }; + + /** Unlike many input classes ReferencePointInputs needs a way to be constructured even if there is no input node. + * The ReferencePoints for a space grid are assumed to just be a default ReferencePoints with + * the same CoordType. + */ + ReferencePointsInput() = default; + + ReferencePointsInput(xmlNodePtr cur); + ReferencePointsInput(const ReferencePointsInput& rpi) = default; + + Coord get_coord_form() const { return coord_form_; } + const Points& get_points() const { return points_; } +private: + void readRefPointsXML(xmlNodePtr cur); + // As far as I can tell if not specified in input this is what is happening in legacy. + Coord coord_form_ = Coord::CELL; + Points points_; + ReferencePointsInputSection input_section_; + static constexpr std::string_view error_tag{"ReferencePointsInput input: "}; +}; + +std::any makeReferencePointsInput(xmlNodePtr, std::string& value_label); + +} // namespace qmcplusplus + +#endif diff --git a/src/Estimators/tests/CMakeLists.txt b/src/Estimators/tests/CMakeLists.txt index 4bce933e32..dfe576fe42 100644 --- a/src/Estimators/tests/CMakeLists.txt +++ b/src/Estimators/tests/CMakeLists.txt @@ -40,7 +40,17 @@ set(SRCS test_PerParticleHamiltonianLogger.cpp test_EstimatorManagerCrowd.cpp test_MagnetizationDensityInput.cpp - test_MagnetizationDensity.cpp) + test_MagnetizationDensity.cpp + test_PerParticleHamiltonianLogger.cpp + test_ReferencePointsInput.cpp + test_ReferencePoints.cpp + ) + +# Tests incompatible with DiracDeterminantCUDA +# DiracDeterminantsCUDA cannot be copied +if(NOT QMC_CUDA) + set(SRCS ${SRCS} test_MomentumDistribution.cpp test_OneBodyDensityMatricesInput.cpp test_OneBodyDensityMatrices.cpp test_PerParticleHamiltonianLogger.cpp test_EstimatorManagerCrowd.cpp) +endif() add_executable(${UTEST_EXE} ${SRCS}) target_link_libraries(${UTEST_EXE} catch_main qmcutil qmcestimators utilities_for_test sposets_for_testing) @@ -71,6 +81,7 @@ if(HAVE_MPI) if(USE_OBJECT_TARGET) target_link_libraries( ${UTEST_EXE} + qmcutil qmcestimators qmcham qmcdriver @@ -82,7 +93,7 @@ if(HAVE_MPI) platform_omptarget_LA utilities_for_test) endif() - target_link_libraries(${UTEST_EXE} catch_main qmcestimators) + target_link_libraries(${UTEST_EXE} catch_main qmcestimators qmcwfs qmcparticle qmcham qmcwfs_omptarget qmcutil utilities_for_test) # Right now the unified driver mpi tests are hard coded for 3 MPI ranks add_unit_test(${UTEST_NAME} 3 1 $) endif() From 1d26932512e2ece4c40d76e580e62883eeb9da39 Mon Sep 17 00:00:00 2001 From: Peter Doak Date: Wed, 25 Oct 2023 17:57:26 -0400 Subject: [PATCH 03/11] cover NEReferencePoints description output --- src/Estimators/tests/test_ReferencePoints.cpp | 98 ++++++++++++++++++- 1 file changed, 95 insertions(+), 3 deletions(-) diff --git a/src/Estimators/tests/test_ReferencePoints.cpp b/src/Estimators/tests/test_ReferencePoints.cpp index e1890a7faf..d066c243e0 100644 --- a/src/Estimators/tests/test_ReferencePoints.cpp +++ b/src/Estimators/tests/test_ReferencePoints.cpp @@ -33,7 +33,7 @@ bool approxEquality(const TinyVector& val_a, const TinyVector& val return false; return true; } - + TEST_CASE("ReferencePoints::DefaultConstruction", "[estimators]") { using Input = testing::ValidReferencePointsInputs; @@ -44,7 +44,7 @@ TEST_CASE("ReferencePoints::DefaultConstruction", "[estimators]") auto lattice = testing::makeTestLattice(); Communicate* comm; - comm = OHMMS::Controller; + comm = OHMMS::Controller; auto particle_pool = MinimalParticlePool::make_diamondC_1x1x1(comm); auto& pset = *(particle_pool.getParticleSet("e")); auto& pset_ions = *(particle_pool.getParticleSet("ion")); @@ -107,7 +107,7 @@ TEST_CASE("ReferencePoints::Construction", "[estimators]") auto lattice = testing::makeTestLattice(); Communicate* comm; - comm = OHMMS::Controller; + comm = OHMMS::Controller; auto particle_pool = MinimalParticlePool::make_diamondC_1x1x1(comm); auto& pset = *(particle_pool.getParticleSet("e")); auto& pset_ions = *(particle_pool.getParticleSet("ion")); @@ -118,6 +118,7 @@ TEST_CASE("ReferencePoints::Construction", "[estimators]") {3.033228526, 3.391869137, 4.654413566}, {3.114198787, 2.654334594, 5.231075822}, {3.657151589, 4.883870516, 4.201243939}, {2.97317591, 4.245644974, 4.284564732}}; + RefVector ref_psets; ref_psets.push_back(pset_ions); NEReferencePoints ref_points(std::move(rpi), pset, ref_psets); @@ -160,5 +161,96 @@ TEST_CASE("ReferencePoints::Construction", "[estimators]") } } +TEST_CASE("ReferencePoints::Description", "[estimators]") +{ + using Input = testing::ValidReferencePointsInputs; + Libxml2Document doc; + bool okay = doc.parseFromString(Input::xml[Input::valid::CELL]); + xmlNodePtr node = doc.getRoot(); + ReferencePointsInput rpi(node); + + auto lattice = testing::makeTestLattice(); + Communicate* comm; + comm = OHMMS::Controller; + auto particle_pool = MinimalParticlePool::make_diamondC_1x1x1(comm); + auto& pset = *(particle_pool.getParticleSet("e")); + auto& pset_ions = *(particle_pool.getParticleSet("ion")); + + // Setup particleset + pset.R = ParticleSet::ParticlePos{{1.751870349, 4.381521229, 2.865202269}, {3.244515371, 4.382273176, 4.21105285}, + {3.000459944, 3.329603408, 4.265030556}, {3.748660329, 3.63420622, 5.393637791}, + {3.033228526, 3.391869137, 4.654413566}, {3.114198787, 2.654334594, 5.231075822}, + {3.657151589, 4.883870516, 4.201243939}, {2.97317591, 4.245644974, 4.284564732}}; + + + RefVector ref_psets; + ref_psets.push_back(pset_ions); + NEReferencePoints ref_points(std::move(rpi), pset, ref_psets); + + std::ostringstream ostr_stream; + ref_points.write_description(ostr_stream, " "); + + std::string expected_description{ + R"( reference_points + a1: 3.37316115 3.37316115 0 + a2: 0 3.37316115 3.37316115 + a3: 3.37316115 0 3.37316115 + cmmm: -3.37316115 -3.37316115 -3.37316115 + cmmp: 0 -3.37316115 0 + cmpm: -3.37316115 0 0 + cmpp: 0 0 3.37316115 + cpmm: 0 0 -3.37316115 + cpmp: 3.37316115 0 0 + cppm: 0 3.37316115 0 + cppp: 3.37316115 3.37316115 3.37316115 + f1m: -1.686580575 -1.686580575 0 + f1p: 1.686580575 1.686580575 0 + f2m: 0 -1.686580575 -1.686580575 + f2p: 0 1.686580575 1.686580575 + f3m: -1.686580575 0 -1.686580575 + f3p: 1.686580575 0 1.686580575 + ion1: 0 0 0 + ion2: 1.68658058 1.68658058 1.68658058 + r1: 3.37316115 3.37316115 0 + r2: 0 3.37316115 3.37316115 + r3: 3.37316115 0 3.37316115 + zero: 0 0 0 + end reference_points +)"}; + CHECK(ostr_stream.str() == expected_description); + + // This subclass and function are used to generate the test data and may be useful for further test cases in future. + testing::TestableNEReferencePoints test_ref_points(ref_points); + std::ostringstream ostr_testing_stream; + test_ref_points.write_testable_description(ostr_testing_stream); + std::string expected_testable_description{R"({ + {"a1", { 3.37316115,3.37316115,0}}, + {"a2", { 0,3.37316115,3.37316115}}, + {"a3", { 3.37316115,0,3.37316115}}, + {"cmmm", { -3.37316115,-3.37316115,-3.37316115}}, + {"cmmp", { 0,-3.37316115,0}}, + {"cmpm", { -3.37316115,0,0}}, + {"cmpp", { 0,0,3.37316115}}, + {"cpmm", { 0,0,-3.37316115}}, + {"cpmp", { 3.37316115,0,0}}, + {"cppm", { 0,3.37316115,0}}, + {"cppp", { 3.37316115,3.37316115,3.37316115}}, + {"f1m", { -1.686580575,-1.686580575,0}}, + {"f1p", { 1.686580575,1.686580575,0}}, + {"f2m", { 0,-1.686580575,-1.686580575}}, + {"f2p", { 0,1.686580575,1.686580575}}, + {"f3m", { -1.686580575,0,-1.686580575}}, + {"f3p", { 1.686580575,0,1.686580575}}, + {"ion1", { 0,0,0}}, + {"ion2", { 1.68658058,1.68658058,1.68658058}}, + {"r1", { 3.37316115,3.37316115,0}}, + {"r2", { 0,3.37316115,3.37316115}}, + {"r3", { 3.37316115,0,3.37316115}}, + {"zero", { 0,0,0}}, +}; +)"}; + CHECK(ostr_testing_stream.str() == expected_testable_description); +} + } // namespace qmcplusplus From 7feb5822ff2a25e67261233418acdeaf50dd776c Mon Sep 17 00:00:00 2001 From: Peter Doak Date: Wed, 25 Oct 2023 18:27:37 -0400 Subject: [PATCH 04/11] coverage of NEReferencePoints factory function --- src/Estimators/ReferencePointsInput.h | 5 ++++- src/Estimators/tests/test_ReferencePointsInput.cpp | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Estimators/ReferencePointsInput.h b/src/Estimators/ReferencePointsInput.h index a61c4a59b2..becd1e16fd 100644 --- a/src/Estimators/ReferencePointsInput.h +++ b/src/Estimators/ReferencePointsInput.h @@ -94,7 +94,10 @@ class ReferencePointsInput static constexpr std::string_view error_tag{"ReferencePointsInput input: "}; }; -std::any makeReferencePointsInput(xmlNodePtr, std::string& value_label); + /** factory function used by InputSection to make reference points Input + * \param[out] value_label key value in delegating InputSection for storing the constructed Input from processed node. + */ + std::any makeReferencePointsInput(xmlNodePtr, std::string& value_label); } // namespace qmcplusplus diff --git a/src/Estimators/tests/test_ReferencePointsInput.cpp b/src/Estimators/tests/test_ReferencePointsInput.cpp index c03c434313..6ba5206564 100644 --- a/src/Estimators/tests/test_ReferencePointsInput.cpp +++ b/src/Estimators/tests/test_ReferencePointsInput.cpp @@ -50,4 +50,15 @@ TEST_CASE("ReferencePointsInput::parseXML::invalid", "[estimators]") CHECK_THROWS_AS(constructBadRefPoints(node), UniformCommunicateError); } } + +TEST_CASE("ReferencePointsInput::makeReferencePointsInput", "[estimators]") +{ + using Input = testing::ValidReferencePointsInputs; + std::string value_label; + Libxml2Document doc; + bool okay = doc.parseFromString(Input::xml[0]); + xmlNodePtr node = doc.getRoot(); + makeReferencePointsInput(node, value_label); + CHECK(value_label == "referencepoints"); +} } // namespace qmcplusplus From 487e37c59cf46767afe0b2d2555bfff796cab19d Mon Sep 17 00:00:00 2001 From: Peter Doak Date: Thu, 26 Oct 2023 15:27:02 -0400 Subject: [PATCH 05/11] more coverage --- src/Estimators/tests/test_ReferencePoints.cpp | 77 ++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/src/Estimators/tests/test_ReferencePoints.cpp b/src/Estimators/tests/test_ReferencePoints.cpp index d066c243e0..8c16b92845 100644 --- a/src/Estimators/tests/test_ReferencePoints.cpp +++ b/src/Estimators/tests/test_ReferencePoints.cpp @@ -222,7 +222,7 @@ TEST_CASE("ReferencePoints::Description", "[estimators]") // This subclass and function are used to generate the test data and may be useful for further test cases in future. testing::TestableNEReferencePoints test_ref_points(ref_points); std::ostringstream ostr_testing_stream; - test_ref_points.write_testable_description(ostr_testing_stream); + ostr_testing_stream << test_ref_points; std::string expected_testable_description{R"({ {"a1", { 3.37316115,3.37316115,0}}, {"a2", { 0,3.37316115,3.37316115}}, @@ -252,5 +252,80 @@ TEST_CASE("ReferencePoints::Description", "[estimators]") CHECK(ostr_testing_stream.str() == expected_testable_description); } +TEST_CASE("ReferencePoints::HDF5", "[estimators]") +{ + using Input = testing::ValidReferencePointsInputs; + Libxml2Document doc; + bool okay = doc.parseFromString(Input::xml[Input::valid::CELL]); + xmlNodePtr node = doc.getRoot(); + ReferencePointsInput rpi(node); + + auto lattice = testing::makeTestLattice(); + Communicate* comm; + comm = OHMMS::Controller; + auto particle_pool = MinimalParticlePool::make_diamondC_1x1x1(comm); + auto& pset = *(particle_pool.getParticleSet("e")); + auto& pset_ions = *(particle_pool.getParticleSet("ion")); + + // Setup particleset + pset.R = ParticleSet::ParticlePos{{1.751870349, 4.381521229, 2.865202269}, {3.244515371, 4.382273176, 4.21105285}, + {3.000459944, 3.329603408, 4.265030556}, {3.748660329, 3.63420622, 5.393637791}, + {3.033228526, 3.391869137, 4.654413566}, {3.114198787, 2.654334594, 5.231075822}, + {3.657151589, 4.883870516, 4.201243939}, {2.97317591, 4.245644974, 4.284564732}}; + + + RefVector ref_psets; + ref_psets.push_back(pset_ions); + NEReferencePoints ref_points(std::move(rpi), pset, ref_psets); + + hdf_archive hd; + std::string test_file{"reference_points_test.hdf"}; + okay = hd.create(test_file); + REQUIRE(okay); + + ref_points.write(hd); + + hd.close(); + + hdf_archive hd_read; + bool okay_read = hd.open(test_file); + + hd.push("reference_points"); + + typename NEReferencePoints::Points expected_reference_points{ + {"a1", {3.37316107749939, 3.37316107749939, 0}}, + {"a2", {0, 3.37316107749939, 3.37316107749939}}, + {"a3", {3.37316107749939, 0, 3.37316107749939}}, + {"cmmm", {-3.37316107749939, -3.37316107749939, -3.37316107749939}}, + {"cmmp", {0, -3.37316107749939, 0}}, + {"cmpm", {-3.37316107749939, 0, 0}}, + {"cmpp", {0, 0, 3.37316107749939}}, + {"cpmm", {0, 0, -3.37316107749939}}, + {"cpmp", {3.37316107749939, 0, 0}}, + {"cppm", {0, 3.37316107749939, 0}}, + {"cppp", {3.37316107749939, 3.37316107749939, 3.37316107749939}}, + {"f1m", {-1.686580538749695, -1.686580538749695, 0}}, + {"f1p", {1.686580538749695, 1.686580538749695, 0}}, + {"f2m", {0, -1.686580538749695, -1.686580538749695}}, + {"f2p", {0, 1.686580538749695, 1.686580538749695}}, + {"f3m", {-1.686580538749695, 0, -1.686580538749695}}, + {"f3p", {1.686580538749695, 0, 1.686580538749695}}, + {"ion1", {0, 0, 0}}, + {"ion2", {1.686580538749695, 1.686580538749695, 1.686580538749695}}, + {"r1", {3.37316107749939, 3.37316107749939, 0}}, + {"r2", {0, 3.37316107749939, 3.37316107749939}}, + {"r3", {3.37316107749939, 0, 3.37316107749939}}, + {"zero", {0, 0, 0}}, + }; + + for (auto& map_entry : expected_reference_points) + { + std::string key{map_entry.first}; + NEReferencePoints::Point point; + hd.readEntry(point, key); + CHECK(approxEquality(point, map_entry.second)); + } + hd.close(); +} } // namespace qmcplusplus From 2706b6d3bb493ecf5243ec7e0ed1c6b05e84abc1 Mon Sep 17 00:00:00 2001 From: Peter Doak Date: Fri, 27 Oct 2023 12:59:23 -0400 Subject: [PATCH 06/11] works for both mixed and full precision --- src/Estimators/tests/test_ReferencePoints.cpp | 197 ++++++++++++------ 1 file changed, 137 insertions(+), 60 deletions(-) diff --git a/src/Estimators/tests/test_ReferencePoints.cpp b/src/Estimators/tests/test_ReferencePoints.cpp index 8c16b92845..30b06e1f11 100644 --- a/src/Estimators/tests/test_ReferencePoints.cpp +++ b/src/Estimators/tests/test_ReferencePoints.cpp @@ -34,6 +34,65 @@ bool approxEquality(const TinyVector& val_a, const TinyVector& val return true; } +auto expectedReferencePoints() +{ + typename NEReferencePoints::Points expected_reference_points; + if constexpr (std::is_same_v) + expected_reference_points = { + {"a1", {3.37316107749939, 3.37316107749939, 0}}, + {"a2", {0, 3.37316107749939, 3.37316107749939}}, + {"a3", {3.37316107749939, 0, 3.37316107749939}}, + {"cmmm", {-3.37316107749939, -3.37316107749939, -3.37316107749939}}, + {"cmmp", {0, -3.37316107749939, 0}}, + {"cmpm", {-3.37316107749939, 0, 0}}, + {"cmpp", {0, 0, 3.37316107749939}}, + {"cpmm", {0, 0, -3.37316107749939}}, + {"cpmp", {3.37316107749939, 0, 0}}, + {"cppm", {0, 3.37316107749939, 0}}, + {"cppp", {3.37316107749939, 3.37316107749939, 3.37316107749939}}, + {"f1m", {-1.686580538749695, -1.686580538749695, 0}}, + {"f1p", {1.686580538749695, 1.686580538749695, 0}}, + {"f2m", {0, -1.686580538749695, -1.686580538749695}}, + {"f2p", {0, 1.686580538749695, 1.686580538749695}}, + {"f3m", {-1.686580538749695, 0, -1.686580538749695}}, + {"f3p", {1.686580538749695, 0, 1.686580538749695}}, + {"ion1", {0, 0, 0}}, + {"ion2", {1.686580538749695, 1.686580538749695, 1.686580538749695}}, + {"r1", {3.37316107749939, 3.37316107749939, 0}}, + {"r2", {0, 3.37316107749939, 3.37316107749939}}, + {"r3", {3.37316107749939, 0, 3.37316107749939}}, + {"zero", {0, 0, 0}}, + }; + else + expected_reference_points = { + {"a1", {3.37316115, 3.37316115, 0}}, + {"a2", {0, 3.37316115, 3.37316115}}, + {"a3", {3.37316115, 0, 3.37316115}}, + {"cmmm", {-3.37316115, -3.37316115, -3.37316115}}, + {"cmmp", {0, -3.37316115, 0}}, + {"cmpm", {-3.37316115, 0, 0}}, + {"cmpp", {0, 0, 3.37316115}}, + {"cpmm", {0, 0, -3.37316115}}, + {"cpmp", {3.37316115, 0, 0}}, + {"cppm", {0, 3.37316115, 0}}, + {"cppp", {3.37316115, 3.37316115, 3.37316115}}, + {"f1m", {-1.686580575, -1.686580575, 0}}, + {"f1p", {1.686580575, 1.686580575, 0}}, + {"f2m", {0, -1.686580575, -1.686580575}}, + {"f2p", {0, 1.686580575, 1.686580575}}, + {"f3m", {-1.686580575, 0, -1.686580575}}, + {"f3p", {1.686580575, 0, 1.686580575}}, + {"ion1", {0, 0, 0}}, + {"ion2", {1.68658058, 1.68658058, 1.68658058}}, + {"r1", {3.37316115, 3.37316115, 0}}, + {"r2", {0, 3.37316115, 3.37316115}}, + {"r3", {3.37316115, 0, 3.37316115}}, + {"zero", {0, 0, 0}}, + }; + return expected_reference_points; +} + + TEST_CASE("ReferencePoints::DefaultConstruction", "[estimators]") { using Input = testing::ValidReferencePointsInputs; @@ -64,31 +123,9 @@ TEST_CASE("ReferencePoints::DefaultConstruction", "[estimators]") testing::TestableNEReferencePoints tref_points(ref_points); std::cout << "expected_reference_points" << tref_points; } - typename NEReferencePoints::Points expected_reference_points{ - {"a1", {3.37316107749939, 3.37316107749939, 0}}, - {"a2", {0, 3.37316107749939, 3.37316107749939}}, - {"a3", {3.37316107749939, 0, 3.37316107749939}}, - {"cmmm", {-3.37316107749939, -3.37316107749939, -3.37316107749939}}, - {"cmmp", {0, -3.37316107749939, 0}}, - {"cmpm", {-3.37316107749939, 0, 0}}, - {"cmpp", {0, 0, 3.37316107749939}}, - {"cpmm", {0, 0, -3.37316107749939}}, - {"cpmp", {3.37316107749939, 0, 0}}, - {"cppm", {0, 3.37316107749939, 0}}, - {"cppp", {3.37316107749939, 3.37316107749939, 3.37316107749939}}, - {"f1m", {-1.686580538749695, -1.686580538749695, 0}}, - {"f1p", {1.686580538749695, 1.686580538749695, 0}}, - {"f2m", {0, -1.686580538749695, -1.686580538749695}}, - {"f2p", {0, 1.686580538749695, 1.686580538749695}}, - {"f3m", {-1.686580538749695, 0, -1.686580538749695}}, - {"f3p", {1.686580538749695, 0, 1.686580538749695}}, - {"ion1", {0, 0, 0}}, - {"ion2", {1.686580538749695, 1.686580538749695, 1.686580538749695}}, - {"r1", {3.37316107749939, 3.37316107749939, 0}}, - {"r2", {0, 3.37316107749939, 3.37316107749939}}, - {"r3", {3.37316107749939, 0, 3.37316107749939}}, - {"zero", {0, 0, 0}}, - }; + + typename NEReferencePoints::Points expected_reference_points; + expected_reference_points = expectedReferencePoints(); for (auto& [key, value] : ref_points.get_points()) { @@ -128,31 +165,9 @@ TEST_CASE("ReferencePoints::Construction", "[estimators]") testing::TestableNEReferencePoints tref_points(ref_points); std::cout << "expected_reference_points" << tref_points; } - typename NEReferencePoints::Points expected_reference_points{ - {"a1", {3.37316107749939, 3.37316107749939, 0}}, - {"a2", {0, 3.37316107749939, 3.37316107749939}}, - {"a3", {3.37316107749939, 0, 3.37316107749939}}, - {"cmmm", {-3.37316107749939, -3.37316107749939, -3.37316107749939}}, - {"cmmp", {0, -3.37316107749939, 0}}, - {"cmpm", {-3.37316107749939, 0, 0}}, - {"cmpp", {0, 0, 3.37316107749939}}, - {"cpmm", {0, 0, -3.37316107749939}}, - {"cpmp", {3.37316107749939, 0, 0}}, - {"cppm", {0, 3.37316107749939, 0}}, - {"cppp", {3.37316107749939, 3.37316107749939, 3.37316107749939}}, - {"f1m", {-1.686580538749695, -1.686580538749695, 0}}, - {"f1p", {1.686580538749695, 1.686580538749695, 0}}, - {"f2m", {0, -1.686580538749695, -1.686580538749695}}, - {"f2p", {0, 1.686580538749695, 1.686580538749695}}, - {"f3m", {-1.686580538749695, 0, -1.686580538749695}}, - {"f3p", {1.686580538749695, 0, 1.686580538749695}}, - {"ion1", {0, 0, 0}}, - {"ion2", {1.686580538749695, 1.686580538749695, 1.686580538749695}}, - {"r1", {3.37316107749939, 3.37316107749939, 0}}, - {"r2", {0, 3.37316107749939, 3.37316107749939}}, - {"r3", {3.37316107749939, 0, 3.37316107749939}}, - {"zero", {0, 0, 0}}, - }; + + typename NEReferencePoints::Points expected_reference_points; + expected_reference_points = expectedReferencePoints(); for (auto& [key, value] : ref_points.get_points()) { @@ -190,8 +205,9 @@ TEST_CASE("ReferencePoints::Description", "[estimators]") std::ostringstream ostr_stream; ref_points.write_description(ostr_stream, " "); - std::string expected_description{ - R"( reference_points + std::string expected_description; + if constexpr (std::is_same_v) + expected_description = R"( reference_points a1: 3.37316115 3.37316115 0 a2: 0 3.37316115 3.37316115 a3: 3.37316115 0 3.37316115 @@ -216,14 +232,44 @@ TEST_CASE("ReferencePoints::Description", "[estimators]") r3: 3.37316115 0 3.37316115 zero: 0 0 0 end reference_points -)"}; +)"; + else + expected_description = R"( reference_points + a1: 3.373161077 3.373161077 0 + a2: 0 3.373161077 3.373161077 + a3: 3.373161077 0 3.373161077 + cmmm: -3.373161077 -3.373161077 -3.373161077 + cmmp: 0 -3.373161077 0 + cmpm: -3.373161077 0 0 + cmpp: 0 0 3.373161077 + cpmm: 0 0 -3.373161077 + cpmp: 3.373161077 0 0 + cppm: 0 3.373161077 0 + cppp: 3.373161077 3.373161077 3.373161077 + f1m: -1.686580539 -1.686580539 0 + f1p: 1.686580539 1.686580539 0 + f2m: 0 -1.686580539 -1.686580539 + f2p: 0 1.686580539 1.686580539 + f3m: -1.686580539 0 -1.686580539 + f3p: 1.686580539 0 1.686580539 + ion1: 0 0 0 + ion2: 1.686580539 1.686580539 1.686580539 + r1: 3.373161077 3.373161077 0 + r2: 0 3.373161077 3.373161077 + r3: 3.373161077 0 3.373161077 + zero: 0 0 0 + end reference_points +)"; CHECK(ostr_stream.str() == expected_description); - // This subclass and function are used to generate the test data and may be useful for further test cases in future. testing::TestableNEReferencePoints test_ref_points(ref_points); std::ostringstream ostr_testing_stream; ostr_testing_stream << test_ref_points; - std::string expected_testable_description{R"({ + std::string expected_testable_description; + if constexpr (std::is_same_v) + { + std::cout << "NEReferencePoints::Real == double\n"; + expected_testable_description = R"({ {"a1", { 3.37316115,3.37316115,0}}, {"a2", { 0,3.37316115,3.37316115}}, {"a3", { 3.37316115,0,3.37316115}}, @@ -248,7 +294,38 @@ TEST_CASE("ReferencePoints::Description", "[estimators]") {"r3", { 3.37316115,0,3.37316115}}, {"zero", { 0,0,0}}, }; -)"}; +)"; + } + else + { + std::cout << "NEReferencePoints::Real == float\n"; + expected_testable_description = R"({ + {"a1", {3.37316107749939,3.37316107749939,0}}, + {"a2", { 0,3.37316107749939,3.37316107749939}}, + {"a3", {3.37316107749939,0,3.37316107749939}}, + {"cmmm", {-3.37316107749939,-3.37316107749939,-3.37316107749939}}, + {"cmmp", { 0,-3.37316107749939,0}}, + {"cmpm", {-3.37316107749939,0,0}}, + {"cmpp", { 0,0,3.37316107749939}}, + {"cpmm", { 0,0,-3.37316107749939}}, + {"cpmp", {3.37316107749939,0,0}}, + {"cppm", { 0,3.37316107749939,0}}, + {"cppp", {3.37316107749939,3.37316107749939,3.37316107749939}}, + {"f1m", {-1.686580538749695,-1.686580538749695,0}}, + {"f1p", {1.686580538749695,1.686580538749695,0}}, + {"f2m", { 0,-1.686580538749695,-1.686580538749695}}, + {"f2p", { 0,1.686580538749695,1.686580538749695}}, + {"f3m", {-1.686580538749695,0,-1.686580538749695}}, + {"f3p", {1.686580538749695,0,1.686580538749695}}, + {"ion1", { 0,0,0}}, + {"ion2", {1.686580538749695,1.686580538749695,1.686580538749695}}, + {"r1", {3.37316107749939,3.37316107749939,0}}, + {"r2", { 0,3.37316107749939,3.37316107749939}}, + {"r3", {3.37316107749939,0,3.37316107749939}}, + {"zero", { 0,0,0}}, +}; +)"; + } CHECK(ostr_testing_stream.str() == expected_testable_description); } @@ -282,7 +359,7 @@ TEST_CASE("ReferencePoints::HDF5", "[estimators]") std::string test_file{"reference_points_test.hdf"}; okay = hd.create(test_file); REQUIRE(okay); - + ref_points.write(hd); hd.close(); @@ -291,7 +368,7 @@ TEST_CASE("ReferencePoints::HDF5", "[estimators]") bool okay_read = hd.open(test_file); hd.push("reference_points"); - + typename NEReferencePoints::Points expected_reference_points{ {"a1", {3.37316107749939, 3.37316107749939, 0}}, {"a2", {0, 3.37316107749939, 3.37316107749939}}, @@ -319,12 +396,12 @@ TEST_CASE("ReferencePoints::HDF5", "[estimators]") }; for (auto& map_entry : expected_reference_points) - { + { std::string key{map_entry.first}; NEReferencePoints::Point point; hd.readEntry(point, key); CHECK(approxEquality(point, map_entry.second)); - } + } hd.close(); } From f9ac9cbc26411a56c895a9be1c5d6f95bf50131d Mon Sep 17 00:00:00 2001 From: Peter Doak Date: Fri, 27 Oct 2023 13:26:54 -0400 Subject: [PATCH 07/11] remove a bunch of repetition from test --- src/Estimators/tests/test_ReferencePoints.cpp | 170 ++++++------------ 1 file changed, 52 insertions(+), 118 deletions(-) diff --git a/src/Estimators/tests/test_ReferencePoints.cpp b/src/Estimators/tests/test_ReferencePoints.cpp index 30b06e1f11..445c58a5b2 100644 --- a/src/Estimators/tests/test_ReferencePoints.cpp +++ b/src/Estimators/tests/test_ReferencePoints.cpp @@ -34,6 +34,43 @@ bool approxEquality(const TinyVector& val_a, const TinyVector& val return true; } +ReferencePointsInput makeTestRPI() +{ + using Input = testing::ValidReferencePointsInputs; + Libxml2Document doc; + bool okay = doc.parseFromString(Input::xml[Input::valid::CELL]); + xmlNodePtr node = doc.getRoot(); + return {node}; +} + +struct PSetsAndRefList +{ + ParticleSetPool ppool; + ParticleSet pset; + ParticleSet pset_ions; + RefVector ref_psets; +}; + +PSetsAndRefList makePsets() +{ + auto lattice = testing::makeTestLattice(); + Communicate* comm; + comm = OHMMS::Controller; + auto particle_pool = MinimalParticlePool::make_diamondC_1x1x1(comm); + auto& pset = *(particle_pool.getParticleSet("e")); + auto& pset_ions = *(particle_pool.getParticleSet("ion")); + + // Setup particleset + pset.R = ParticleSet::ParticlePos{{1.751870349, 4.381521229, 2.865202269}, {3.244515371, 4.382273176, 4.21105285}, + {3.000459944, 3.329603408, 4.265030556}, {3.748660329, 3.63420622, 5.393637791}, + {3.033228526, 3.391869137, 4.654413566}, {3.114198787, 2.654334594, 5.231075822}, + {3.657151589, 4.883870516, 4.201243939}, {2.97317591, 4.245644974, 4.284564732}}; + + RefVector ref_psets; + ref_psets.push_back(pset_ions); + return {std::move(particle_pool), pset, pset_ions, ref_psets}; +} + auto expectedReferencePoints() { typename NEReferencePoints::Points expected_reference_points; @@ -92,31 +129,11 @@ auto expectedReferencePoints() return expected_reference_points; } - TEST_CASE("ReferencePoints::DefaultConstruction", "[estimators]") { - using Input = testing::ValidReferencePointsInputs; - Libxml2Document doc; - bool okay = doc.parseFromString(Input::xml[Input::valid::CELL]); - xmlNodePtr node = doc.getRoot(); - ReferencePointsInput rpi(node); - - auto lattice = testing::makeTestLattice(); - Communicate* comm; - comm = OHMMS::Controller; - auto particle_pool = MinimalParticlePool::make_diamondC_1x1x1(comm); - auto& pset = *(particle_pool.getParticleSet("e")); - auto& pset_ions = *(particle_pool.getParticleSet("ion")); - - // Setup particleset - pset.R = ParticleSet::ParticlePos{{1.751870349, 4.381521229, 2.865202269}, {3.244515371, 4.382273176, 4.21105285}, - {3.000459944, 3.329603408, 4.265030556}, {3.748660329, 3.63420622, 5.393637791}, - {3.033228526, 3.391869137, 4.654413566}, {3.114198787, 2.654334594, 5.231075822}, - {3.657151589, 4.883870516, 4.201243939}, {2.97317591, 4.245644974, 4.284564732}}; - - RefVector ref_psets; - ref_psets.push_back(pset_ions); - NEReferencePoints ref_points(rpi, pset, ref_psets); + auto rpi = makeTestRPI(); + auto ppr = makePsets(); + NEReferencePoints ref_points(rpi, ppr.pset, ppr.ref_psets); if (generate_test_data) { @@ -136,29 +153,9 @@ TEST_CASE("ReferencePoints::DefaultConstruction", "[estimators]") TEST_CASE("ReferencePoints::Construction", "[estimators]") { - using Input = testing::ValidReferencePointsInputs; - Libxml2Document doc; - bool okay = doc.parseFromString(Input::xml[Input::valid::CELL]); - xmlNodePtr node = doc.getRoot(); - ReferencePointsInput rpi(node); - - auto lattice = testing::makeTestLattice(); - Communicate* comm; - comm = OHMMS::Controller; - auto particle_pool = MinimalParticlePool::make_diamondC_1x1x1(comm); - auto& pset = *(particle_pool.getParticleSet("e")); - auto& pset_ions = *(particle_pool.getParticleSet("ion")); - - // Setup particleset - pset.R = ParticleSet::ParticlePos{{1.751870349, 4.381521229, 2.865202269}, {3.244515371, 4.382273176, 4.21105285}, - {3.000459944, 3.329603408, 4.265030556}, {3.748660329, 3.63420622, 5.393637791}, - {3.033228526, 3.391869137, 4.654413566}, {3.114198787, 2.654334594, 5.231075822}, - {3.657151589, 4.883870516, 4.201243939}, {2.97317591, 4.245644974, 4.284564732}}; - - - RefVector ref_psets; - ref_psets.push_back(pset_ions); - NEReferencePoints ref_points(std::move(rpi), pset, ref_psets); + auto rpi = makeTestRPI(); + auto ppr = makePsets(); + NEReferencePoints ref_points(rpi, ppr.pset, ppr.ref_psets); if (generate_test_data) { @@ -178,29 +175,9 @@ TEST_CASE("ReferencePoints::Construction", "[estimators]") TEST_CASE("ReferencePoints::Description", "[estimators]") { - using Input = testing::ValidReferencePointsInputs; - Libxml2Document doc; - bool okay = doc.parseFromString(Input::xml[Input::valid::CELL]); - xmlNodePtr node = doc.getRoot(); - ReferencePointsInput rpi(node); - - auto lattice = testing::makeTestLattice(); - Communicate* comm; - comm = OHMMS::Controller; - auto particle_pool = MinimalParticlePool::make_diamondC_1x1x1(comm); - auto& pset = *(particle_pool.getParticleSet("e")); - auto& pset_ions = *(particle_pool.getParticleSet("ion")); - - // Setup particleset - pset.R = ParticleSet::ParticlePos{{1.751870349, 4.381521229, 2.865202269}, {3.244515371, 4.382273176, 4.21105285}, - {3.000459944, 3.329603408, 4.265030556}, {3.748660329, 3.63420622, 5.393637791}, - {3.033228526, 3.391869137, 4.654413566}, {3.114198787, 2.654334594, 5.231075822}, - {3.657151589, 4.883870516, 4.201243939}, {2.97317591, 4.245644974, 4.284564732}}; - - - RefVector ref_psets; - ref_psets.push_back(pset_ions); - NEReferencePoints ref_points(std::move(rpi), pset, ref_psets); + auto rpi = makeTestRPI(); + auto ppr = makePsets(); + NEReferencePoints ref_points(rpi, ppr.pset, ppr.ref_psets); std::ostringstream ostr_stream; ref_points.write_description(ostr_stream, " "); @@ -331,33 +308,13 @@ TEST_CASE("ReferencePoints::Description", "[estimators]") TEST_CASE("ReferencePoints::HDF5", "[estimators]") { - using Input = testing::ValidReferencePointsInputs; - Libxml2Document doc; - bool okay = doc.parseFromString(Input::xml[Input::valid::CELL]); - xmlNodePtr node = doc.getRoot(); - ReferencePointsInput rpi(node); - - auto lattice = testing::makeTestLattice(); - Communicate* comm; - comm = OHMMS::Controller; - auto particle_pool = MinimalParticlePool::make_diamondC_1x1x1(comm); - auto& pset = *(particle_pool.getParticleSet("e")); - auto& pset_ions = *(particle_pool.getParticleSet("ion")); - - // Setup particleset - pset.R = ParticleSet::ParticlePos{{1.751870349, 4.381521229, 2.865202269}, {3.244515371, 4.382273176, 4.21105285}, - {3.000459944, 3.329603408, 4.265030556}, {3.748660329, 3.63420622, 5.393637791}, - {3.033228526, 3.391869137, 4.654413566}, {3.114198787, 2.654334594, 5.231075822}, - {3.657151589, 4.883870516, 4.201243939}, {2.97317591, 4.245644974, 4.284564732}}; - - - RefVector ref_psets; - ref_psets.push_back(pset_ions); - NEReferencePoints ref_points(std::move(rpi), pset, ref_psets); + auto rpi = makeTestRPI(); + auto ppr = makePsets(); + NEReferencePoints ref_points(rpi, ppr.pset, ppr.ref_psets); hdf_archive hd; std::string test_file{"reference_points_test.hdf"}; - okay = hd.create(test_file); + bool okay = hd.create(test_file); REQUIRE(okay); ref_points.write(hd); @@ -369,31 +326,8 @@ TEST_CASE("ReferencePoints::HDF5", "[estimators]") hd.push("reference_points"); - typename NEReferencePoints::Points expected_reference_points{ - {"a1", {3.37316107749939, 3.37316107749939, 0}}, - {"a2", {0, 3.37316107749939, 3.37316107749939}}, - {"a3", {3.37316107749939, 0, 3.37316107749939}}, - {"cmmm", {-3.37316107749939, -3.37316107749939, -3.37316107749939}}, - {"cmmp", {0, -3.37316107749939, 0}}, - {"cmpm", {-3.37316107749939, 0, 0}}, - {"cmpp", {0, 0, 3.37316107749939}}, - {"cpmm", {0, 0, -3.37316107749939}}, - {"cpmp", {3.37316107749939, 0, 0}}, - {"cppm", {0, 3.37316107749939, 0}}, - {"cppp", {3.37316107749939, 3.37316107749939, 3.37316107749939}}, - {"f1m", {-1.686580538749695, -1.686580538749695, 0}}, - {"f1p", {1.686580538749695, 1.686580538749695, 0}}, - {"f2m", {0, -1.686580538749695, -1.686580538749695}}, - {"f2p", {0, 1.686580538749695, 1.686580538749695}}, - {"f3m", {-1.686580538749695, 0, -1.686580538749695}}, - {"f3p", {1.686580538749695, 0, 1.686580538749695}}, - {"ion1", {0, 0, 0}}, - {"ion2", {1.686580538749695, 1.686580538749695, 1.686580538749695}}, - {"r1", {3.37316107749939, 3.37316107749939, 0}}, - {"r2", {0, 3.37316107749939, 3.37316107749939}}, - {"r3", {3.37316107749939, 0, 3.37316107749939}}, - {"zero", {0, 0, 0}}, - }; + typename NEReferencePoints::Points expected_reference_points; + expected_reference_points = expectedReferencePoints(); for (auto& map_entry : expected_reference_points) { From a91ab62766b8d59cc396b680a2acc424b88b8c63 Mon Sep 17 00:00:00 2001 From: Peter Doak Date: Fri, 27 Oct 2023 13:49:07 -0400 Subject: [PATCH 08/11] cleanup some cmake used for debugging. --- src/Estimators/CMakeLists.txt | 17 ----------------- src/Estimators/tests/CMakeLists.txt | 1 - 2 files changed, 18 deletions(-) diff --git a/src/Estimators/CMakeLists.txt b/src/Estimators/CMakeLists.txt index b2e7b0417b..c8b580d708 100644 --- a/src/Estimators/CMakeLists.txt +++ b/src/Estimators/CMakeLists.txt @@ -11,23 +11,6 @@ # Estimators which accumulate observables #################################### -set(QMCEST_INPUT_SRC - InputSection.cpp - EstimatorInput.cpp - OneBodyDensityMatricesInput.cpp - ReferencePointsInput.cpp - NEReferencePoints.cpp) - -if(USE_OBJECT_TARGET) - add_library(qmcestimators_input OBJECT ${QMCEST_INPUT_SRC}) -else() - add_library(qmcestimators_input ${QMCEST_INPUT_SRC}) -endif() - -target_include_directories(qmcestimators_input PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") -target_link_libraries(qmcestimators_input PUBLIC containers qmcham qmcparticle qmcutil) - - set(QMCEST_SRC InputSection.cpp CSEnergyEstimator.cpp diff --git a/src/Estimators/tests/CMakeLists.txt b/src/Estimators/tests/CMakeLists.txt index dfe576fe42..e069b6cc54 100644 --- a/src/Estimators/tests/CMakeLists.txt +++ b/src/Estimators/tests/CMakeLists.txt @@ -37,7 +37,6 @@ set(SRCS test_MomentumDistribution.cpp test_OneBodyDensityMatricesInput.cpp test_OneBodyDensityMatrices.cpp - test_PerParticleHamiltonianLogger.cpp test_EstimatorManagerCrowd.cpp test_MagnetizationDensityInput.cpp test_MagnetizationDensity.cpp From a37ad11c40d68963794be32af17466847b3a738a Mon Sep 17 00:00:00 2001 From: Peter Doak Date: Wed, 1 Nov 2023 10:59:31 -0400 Subject: [PATCH 09/11] cleanup/refactors suggested by @ye-lou review --- src/Estimators/NEReferencePoints.cpp | 28 ++--------- src/Estimators/NEReferencePoints.h | 46 ++++++++++++------- src/Estimators/tests/CMakeLists.txt | 15 +++--- src/Estimators/tests/test_ReferencePoints.cpp | 33 +++++++++++++ 4 files changed, 72 insertions(+), 50 deletions(-) diff --git a/src/Estimators/NEReferencePoints.cpp b/src/Estimators/NEReferencePoints.cpp index 2e15bcc596..a47f0855d4 100644 --- a/src/Estimators/NEReferencePoints.cpp +++ b/src/Estimators/NEReferencePoints.cpp @@ -19,8 +19,9 @@ namespace qmcplusplus { + NEReferencePoints::NEReferencePoints(const ReferencePointsInput& rp_input, - ParticleSet& pset, + const ParticleSet& pset, RefVector& ref_psets) : input_(rp_input) { @@ -49,7 +50,7 @@ NEReferencePoints::NEReferencePoints(const ReferencePointsInput& rp_input, points_[key] = dot(crd, value); } -void NEReferencePoints::processParticleSets(ParticleSet& P, RefVector& Psets) +void NEReferencePoints::processParticleSets(const ParticleSet& P, RefVector& Psets) { //get axes and origin information from the ParticleSet points_["zero"] = 0 * P.getLattice().a(0); @@ -112,27 +113,4 @@ std::ostream& operator<<(std::ostream& out, const NEReferencePoints& rhs) return out; } -namespace testing -{ -void TestableNEReferencePoints::write_testable_description(std::ostream& os) const -{ - os << "{" << '\n'; - std::map::const_iterator it, end = points_.end(); - for (it = points_.begin(); it != end; ++it) - { - os << " {\"" << it->first << "\", {" << std::setw(16) << std::setprecision(16) << it->second[0] << "," << it->second[1] << "," << it->second[2] - << "}}," << '\n'; - } - os << "};" << '\n'; - return; -} -} // namespace testing - -std::ostream& operator<<(std::ostream& out, const testing::TestableNEReferencePoints& rhs) -{ - rhs.write_testable_description(out); - return out; -} - - } // namespace qmcplusplus diff --git a/src/Estimators/NEReferencePoints.h b/src/Estimators/NEReferencePoints.h index f10c3df31f..89263a61ee 100644 --- a/src/Estimators/NEReferencePoints.h +++ b/src/Estimators/NEReferencePoints.h @@ -24,6 +24,13 @@ namespace qmcplusplus { + +/** This class creates, contains, and writes both user and machine readable referencepoints. + * they are derived from the lattice of the pset passed and the particle positions in the ref_psets + * an arbitrary number of additional points can be defined in the input that ReferencePointsInput + * presents as native input. + * It is a dependency of Estimators/NESpaceGrid and Estimatorss/EnergyDensityEstimator + */ class NEReferencePoints { public: @@ -32,36 +39,41 @@ class NEReferencePoints using Point = TinyVector; using Points = std::map; using Coord = typename ReferencePointsInput::Coord; - NEReferencePoints(const ReferencePointsInput& rp_input, ParticleSet& pset, RefVector& ref_psets); + /** Usual constructor + * \param[in] rp_input Input object for reference points which can contain and arbitrary set of points beyond + * those take from the pset, and ref_psets + * \param[in] pset pset that supplies the lattice information for reference points + * \param[in] ref_psets pset reference vector the particle points in this/these psets are reference points + */ + NEReferencePoints(const ReferencePointsInput& rp_input, const ParticleSet& pset, RefVector& ref_psets); NEReferencePoints(const NEReferencePoints& nerp) = default; - void processParticleSets(ParticleSet& P, RefVector& Pref); + /** writes a human readable representation of the reference points. + * \param[inout] os ostream to write description to + * \param[in] indent spaces or other text to preface each line of output with. needed to preserve + * legacy output format. + */ void write_description(std::ostream& os, const std::string& indent) const; + + /** machine readable output + * \param[inout] file hdf5 file to write to. Respects current state of file. + */ void write(hdf_archive& file) const; + + /** return const ref to map of reference points. + * labeling scheme unchanged from legacy + */ const Points& get_points() const { return points_; } protected: Points points_; - private: + void processParticleSets(const ParticleSet& P, RefVector& Pref); Axes axes; ReferencePointsInput input_; }; std::ostream& operator<<(std::ostream& out, const NEReferencePoints& rhs); -namespace testing -{ -class TestableNEReferencePoints : public NEReferencePoints -{ -public: - TestableNEReferencePoints(const NEReferencePoints& nerp) : NEReferencePoints(nerp) {} - void write_testable_description(std::ostream& os) const; -}; -} // namespace testing - -std::ostream& operator<<(std::ostream& out, const testing::TestableNEReferencePoints& rhs); -} // namespace qmcplusplus - - +} #endif diff --git a/src/Estimators/tests/CMakeLists.txt b/src/Estimators/tests/CMakeLists.txt index e069b6cc54..0e7f87d81d 100644 --- a/src/Estimators/tests/CMakeLists.txt +++ b/src/Estimators/tests/CMakeLists.txt @@ -43,16 +43,15 @@ set(SRCS test_PerParticleHamiltonianLogger.cpp test_ReferencePointsInput.cpp test_ReferencePoints.cpp + test_MomentumDistribution.cpp + test_OneBodyDensityMatricesInput.cpp + test_OneBodyDensityMatrices.cpp + test_PerParticleHamiltonianLogger.cpp + test_EstimatorManagerCrowd.cpp ) -# Tests incompatible with DiracDeterminantCUDA -# DiracDeterminantsCUDA cannot be copied -if(NOT QMC_CUDA) - set(SRCS ${SRCS} test_MomentumDistribution.cpp test_OneBodyDensityMatricesInput.cpp test_OneBodyDensityMatrices.cpp test_PerParticleHamiltonianLogger.cpp test_EstimatorManagerCrowd.cpp) -endif() - add_executable(${UTEST_EXE} ${SRCS}) -target_link_libraries(${UTEST_EXE} catch_main qmcutil qmcestimators utilities_for_test sposets_for_testing) +target_link_libraries(${UTEST_EXE} catch_main qmcutil qmcestimators utilities_for_test) if(USE_OBJECT_TARGET) target_link_libraries( ${UTEST_EXE} @@ -92,7 +91,7 @@ if(HAVE_MPI) platform_omptarget_LA utilities_for_test) endif() - target_link_libraries(${UTEST_EXE} catch_main qmcestimators qmcwfs qmcparticle qmcham qmcwfs_omptarget qmcutil utilities_for_test) + 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 $) endif() diff --git a/src/Estimators/tests/test_ReferencePoints.cpp b/src/Estimators/tests/test_ReferencePoints.cpp index 445c58a5b2..f780ae1078 100644 --- a/src/Estimators/tests/test_ReferencePoints.cpp +++ b/src/Estimators/tests/test_ReferencePoints.cpp @@ -23,6 +23,39 @@ namespace qmcplusplus { + +namespace testing +{ +class TestableNEReferencePoints : public NEReferencePoints +{ +public: + TestableNEReferencePoints(const NEReferencePoints& nerp) : NEReferencePoints(nerp) {} + void write_testable_description(std::ostream& os) const; +}; + +void TestableNEReferencePoints::write_testable_description(std::ostream& os) const +{ + os << "{" << '\n'; + std::map::const_iterator it, end = points_.end(); + for (it = points_.begin(); it != end; ++it) + { + os << " {\"" << it->first << "\", {" << std::setw(16) << std::setprecision(16) << it->second[0] << "," + << it->second[1] << "," << it->second[2] << "}}," << '\n'; + } + os << "};" << '\n'; + return; +} +} // namespace testing + +std::ostream& operator<<(std::ostream& out, const testing::TestableNEReferencePoints& rhs) +{ + rhs.write_testable_description(out); + return out; +} + + +std::ostream& operator<<(std::ostream& out, const testing::TestableNEReferencePoints& rhs); + constexpr bool generate_test_data = false; template From a1ad310fb11ebf46beec33bf1e0bfcb6fa417420 Mon Sep 17 00:00:00 2001 From: Peter Doak Date: Wed, 1 Nov 2023 13:44:02 -0400 Subject: [PATCH 10/11] surprising missing library. rebase damage maybe --- src/Estimators/tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Estimators/tests/CMakeLists.txt b/src/Estimators/tests/CMakeLists.txt index 0e7f87d81d..0d97d93a27 100644 --- a/src/Estimators/tests/CMakeLists.txt +++ b/src/Estimators/tests/CMakeLists.txt @@ -51,7 +51,7 @@ set(SRCS ) add_executable(${UTEST_EXE} ${SRCS}) -target_link_libraries(${UTEST_EXE} catch_main qmcutil qmcestimators utilities_for_test) +target_link_libraries(${UTEST_EXE} catch_main qmcutil qmcestimators utilities_for_test sposets_for_testing) if(USE_OBJECT_TARGET) target_link_libraries( ${UTEST_EXE} From 4f99340588c074d234acbe3e751ae55b49e56a8d Mon Sep 17 00:00:00 2001 From: Peter Doak Date: Mon, 6 Nov 2023 10:32:40 -0500 Subject: [PATCH 11/11] add to do for renaming NEReferencePoints --- src/Estimators/NEReferencePoints.cpp | 2 +- src/Estimators/NEReferencePoints.h | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Estimators/NEReferencePoints.cpp b/src/Estimators/NEReferencePoints.cpp index a47f0855d4..309ecb736e 100644 --- a/src/Estimators/NEReferencePoints.cpp +++ b/src/Estimators/NEReferencePoints.cpp @@ -2,7 +2,7 @@ // This file is distributed under the University of Illinois/NCSA Open Source License. // See LICENSE file in top directory for details. // -// Copyright (c) 2022 QMCPACK developers. +// Copyright (c) 2023 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 diff --git a/src/Estimators/NEReferencePoints.h b/src/Estimators/NEReferencePoints.h index 89263a61ee..d76d5aafca 100644 --- a/src/Estimators/NEReferencePoints.h +++ b/src/Estimators/NEReferencePoints.h @@ -2,7 +2,7 @@ // This file is distributed under the University of Illinois/NCSA Open Source License. // See LICENSE file in top directory for details. // -// Copyright (c) 2022 QMCPACK developers. +// Copyright (c) 2023 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 @@ -11,10 +11,13 @@ // File refactored from: QMCHamiltonian/ReferencePoints.h ////////////////////////////////////////////////////////////////////////////////////// - #ifndef QMCPLUSPLUS_NEREFERENCE_POINTS_H #define QMCPLUSPLUS_NEREFERENCE_POINTS_H +/** @file + * \todo When QMCHamiltonian/ReferencePoints is removed rename this class to ReferencePoints + */ + #include #include "OhmmsData/OhmmsElementBase.h" #include "Particle/ParticleSet.h"