Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix mixed precision kpoint sorting #5327

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,21 @@ struct QMCTraits

/** Particle traits to use UniformGridLayout for the ParticleLayout.
*/
struct PtclOnLatticeTraits
template<typename PREC>
struct PtclOnLatticeTraitsT
{
using ParticleLayout = CrystalLattice<OHMMS_PRECISION, OHMMS_DIM>;
using ParticleLayout = CrystalLattice<PREC, OHMMS_DIM>;
using QTFull = QMCTraits::QTFull;

using Index_t = int;
using Scalar_t = QTFull::RealType;
using Complex_t = QTFull::ComplexType;

using SingleParticleIndex = ParticleLayout::SingleParticleIndex;
using SingleParticlePos = ParticleLayout::SingleParticlePos;
using Tensor_t = ParticleLayout::Tensor_t;
using SingleParticleIndex = typename ParticleLayout::SingleParticleIndex;
using SingleParticlePos = typename ParticleLayout::SingleParticlePos;
using SingleParticlePosFull = typename CrystalLattice<OHMMS_PRECISION_FULL, OHMMS_DIM>::SingleParticlePos;

using Tensor_t = typename ParticleLayout::Tensor_t;

using ParticleIndex = ParticleAttrib<Index_t>;
using ParticleScalar = ParticleAttrib<Scalar_t>;
Expand All @@ -97,6 +100,10 @@ struct PtclOnLatticeTraits
using SingleParticleValue = QTFull::ValueType;
};

using PtclOnLatticeTraits = PtclOnLatticeTraitsT<OHMMS_PRECISION>;

template<typename T>
using ParticleLayoutT = typename PtclOnLatticeTraitsT<T>::ParticleLayout;

// For unit tests
// Check if we are compiling with Catch defined. Could use other symbols if needed.
Expand Down
1 change: 1 addition & 0 deletions src/Containers/OhmmsPETE/Tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ class Tensor

//TJW: add these 12/16/97 to help with NegReflectAndZeroFace BC:
// These are the same as operator[] but with () instead:
// \todo remove this redundant and non idiomatic operator
inline Type_t& operator()(unsigned int i) { return X[i]; }

inline Type_t operator()(unsigned int i) const { return X[i]; }
Expand Down
8 changes: 4 additions & 4 deletions src/Estimators/EstimatorManagerNew.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ void EstimatorManagerNew::constructEstimators(EstimatorManagerInput&& emi,
const PSPool& pset_pool)
{
for (auto& est_input : emi.get_estimator_inputs())
if (!(createEstimator<SpinDensityInput>(est_input, pset.getLattice(), pset.getSpeciesSet()) ||
if (!(createEstimator<SpinDensityInput>(est_input, pset.getFullPrecLattice(), pset.getSpeciesSet()) ||
createEstimator<MomentumDistributionInput>(est_input, pset.getTotalNum(), pset.getTwist(),
pset.getLattice()) ||
pset.getFullPrecLattice()) ||
createEstimator<SelfHealingOverlapInput>(est_input, twf) ||
createEstimator<OneBodyDensityMatricesInput>(est_input, pset.getLattice(), pset.getSpeciesSet(),
createEstimator<OneBodyDensityMatricesInput>(est_input, pset.getFullPrecLattice(), pset.getSpeciesSet(),
twf.getSPOMap(), pset) ||
createEstimator<MagnetizationDensityInput>(est_input, pset.getLattice()) ||
createEstimator<MagnetizationDensityInput>(est_input, pset.getFullPrecLattice()) ||
createEstimator<PerParticleHamiltonianLoggerInput>(est_input, my_comm_->rank()) ||
createEstimator<EnergyDensityInput>(est_input, pset_pool)))
throw UniformCommunicateError(std::string(error_tag_) +
Expand Down
2 changes: 1 addition & 1 deletion src/Estimators/MagnetizationDensity.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class MagnetizationDensity : public OperatorEstBase
using Real = RealAlias<Value>;
using FullPrecReal = RealAlias<FullPrecValue>;
using Grad = TinyVector<Value, OHMMS_DIM>;
using Lattice = PtclOnLatticeTraits::ParticleLayout;
using Lattice = CrystalLattice<OHMMS_PRECISION_FULL, OHMMS_DIM>;
using Position = QMCTraits::PosType;
using Integrator = MagnetizationDensityInput::Integrator;
static constexpr int DIM = QMCTraits::DIM;
Expand Down
3 changes: 1 addition & 2 deletions src/Estimators/MagnetizationDensityInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ class MagnetizationDensityInput
{"integrator-montecarlo", Integrator::MONTECARLO}};
// clang-format on
using Real = QMCTraits::FullPrecRealType;
using POLT = PtclOnLatticeTraits;
using Lattice = POLT::ParticleLayout;
using Lattice = CrystalLattice<OHMMS_PRECISION_FULL, OHMMS_DIM>;
using PosType = TinyVector<Real, OHMMS_DIM>;
using Consumer = MagnetizationDensity;
static constexpr int DIM = QMCTraits::DIM;
Expand Down
2 changes: 1 addition & 1 deletion src/Estimators/MomentumDistribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace qmcplusplus
MomentumDistribution::MomentumDistribution(MomentumDistributionInput&& mdi,
size_t np,
const PosType& twist_in,
const LatticeType& lattice,
const FullPrecLattice& lattice,
DataLocality dl)
: OperatorEstBase(dl),
input_(std::move(mdi)),
Expand Down
5 changes: 3 additions & 2 deletions src/Estimators/MomentumDistribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class MomentumDistribution : public OperatorEstBase
{
public:
using LatticeType = PtclOnLatticeTraits::ParticleLayout;
using FullPrecLattice = CrystalLattice<OHMMS_PRECISION_FULL, OHMMS_DIM>;
using RealType = QMCTraits::RealType;
using ComplexType = QMCTraits::ComplexType;
using ValueType = QMCTraits::ValueType;
Expand All @@ -45,7 +46,7 @@ class MomentumDistribution : public OperatorEstBase
///twist angle
const PosType twist;
///lattice vector
const LatticeType Lattice;
const FullPrecLattice Lattice;
///normalization factor for n(k)
const RealType norm_nofK;
///list of k-points in Cartesian Coordinates
Expand Down Expand Up @@ -76,7 +77,7 @@ class MomentumDistribution : public OperatorEstBase
MomentumDistribution(MomentumDistributionInput&& mdi,
size_t np,
const PosType& twist,
const LatticeType& lattice,
const FullPrecLattice& lattice,
DataLocality dl = DataLocality::crowd);

/** Constructor used when spawing crowd clones
Expand Down
2 changes: 1 addition & 1 deletion src/Estimators/OneBodyDensityMatrices.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class OneBodyDensityMatrices : public OperatorEstBase
using Real = RealAlias<Value>;
using FullPrecReal = RealAlias<FullPrecValue>;
using Grad = TinyVector<Value, OHMMS_DIM>;
using Lattice = PtclOnLatticeTraits::ParticleLayout;
using Lattice = CrystalLattice<OHMMS_PRECISION_FULL, OHMMS_DIM>;
using Position = QMCTraits::PosType;

using Evaluator = OneBodyDensityMatricesInput::Evaluator;
Expand Down
3 changes: 1 addition & 2 deletions src/Estimators/SpinDensityInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class SpinDensityInput
{
public:
using Real = QMCTraits::RealType;
using POLT = PtclOnLatticeTraits;
using Lattice = POLT::ParticleLayout;
using Lattice = CrystalLattice<OHMMS_PRECISION_FULL, OHMMS_DIM>;
using PosType = QMCTraits::PosType;
using Consumer = SpinDensityNew;
static constexpr int DIM = QMCTraits::DIM;
Expand Down
2 changes: 1 addition & 1 deletion src/Estimators/SpinDensityNew.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SpinDensityNew : public OperatorEstBase
{
public:
using POLT = PtclOnLatticeTraits;
using Lattice = POLT::ParticleLayout;
using Lattice = CrystalLattice<OHMMS_PRECISION_FULL, OHMMS_DIM>;
using QMCT = QMCTraits;
using FullPrecRealType = QMCT::FullPrecRealType;

Expand Down
3 changes: 1 addition & 2 deletions src/Estimators/tests/EstimatorTesting.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class SpeciesSet;

namespace testing
{
using POLT = PtclOnLatticeTraits;
using Lattice = POLT::ParticleLayout;
using Lattice = CrystalLattice<OHMMS_PRECISION_FULL,OHMMS_DIM>;

enum class SpeciesCases
{
Expand Down
4 changes: 2 additions & 2 deletions src/Estimators/tests/test_MagnetizationDensity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ TEST_CASE("MagnetizationDensity::gridAssignment", "[estimators]")
{6.03341616, 0, 1.77067004}, //bin 6
{2.78496304, 0, 5.31201011}}; //bin 7

ParticleSet::ParticleLayout lattice;
CrystalLattice<OHMMS_PRECISION_FULL, OHMMS_DIM> lattice;
lattice.R(0, 0) = 5.10509515;
lattice.R(0, 1) = -3.23993545;
lattice.R(0, 2) = 0.00000000;
Expand Down Expand Up @@ -295,7 +295,7 @@ TEST_CASE("MagnetizationDensity::IntegrationTest", "[estimators]")
using namespace testing;

// O2 test example from pwscf non-collinear calculation.
ParticleSet::ParticleLayout lattice;
CrystalLattice<OHMMS_PRECISION_FULL, OHMMS_DIM> lattice;
lattice.R(0, 0) = 5.10509515;
lattice.R(0, 1) = -3.23993545;
lattice.R(0, 2) = 0.00000000;
Expand Down
2 changes: 1 addition & 1 deletion src/Estimators/tests/test_MagnetizationDensityInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace qmcplusplus
TEST_CASE("MagnetizationDensityInput::from_xml", "[estimators]")
{
using POLT = PtclOnLatticeTraits;
using Lattice = POLT::ParticleLayout;
using Lattice = CrystalLattice<OHMMS_PRECISION_FULL, OHMMS_DIM>;
using PosType = QMCTraits::PosType;
using namespace testing::magdensity;

Expand Down
8 changes: 4 additions & 4 deletions src/Estimators/tests/test_MomentumDistribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ TEST_CASE("MomentumDistribution::MomentumDistribution", "[estimators]")
DataLocality dl = DataLocality::crowd;

// Build from input
MomentumDistribution md(std::move(mdi), pset.getTotalNum(), pset.getTwist(), pset.getLattice(), dl);
MomentumDistribution md(std::move(mdi), pset.getTotalNum(), pset.getTwist(), pset.getFullPrecLattice(), dl);

CHECK(md.twist[0] == Approx(0.0));
CHECK(md.twist[1] == Approx(0.0));
Expand Down Expand Up @@ -141,7 +141,7 @@ TEST_CASE("MomentumDistribution::accumulate", "[estimators]")
{3.657151589, 4.883870516, 4.201243939}, {2.97317591, 4.245644974, 4.284564732}};

// Build from input
MomentumDistribution md(std::move(mdi), pset.getTotalNum(), pset.getTwist(), pset.getLattice(), dl);
MomentumDistribution md(std::move(mdi), pset.getTotalNum(), pset.getTwist(), pset.getFullPrecLattice(), dl);

// Test accumulate

Expand Down Expand Up @@ -245,7 +245,7 @@ TEST_CASE("MomentumDistribution::spawnCrowdClone", "[estimators]")
DataLocality dl = DataLocality::crowd;

// Build from input
MomentumDistribution md(std::move(mdi), pset.getTotalNum(), pset.getTwist(), pset.getLattice(), dl);
MomentumDistribution md(std::move(mdi), pset.getTotalNum(), pset.getTwist(), pset.getFullPrecLattice(), dl);

auto clone = md.spawnCrowdClone();
REQUIRE(clone != nullptr);
Expand All @@ -256,7 +256,7 @@ TEST_CASE("MomentumDistribution::spawnCrowdClone", "[estimators]")
// for MomentumDistribution. Then checks relevant to that should be added.
MomentumDistributionInput fail_mdi(node);
dl = DataLocality::rank;
MomentumDistribution fail_md(std::move(fail_mdi), pset.getTotalNum(), pset.getTwist(), pset.getLattice(), dl);
MomentumDistribution fail_md(std::move(fail_mdi), pset.getTotalNum(), pset.getTwist(), pset.getFullPrecLattice(), dl);
CHECK_THROWS_AS(clone = fail_md.spawnCrowdClone(), std::runtime_error);
}

Expand Down
12 changes: 6 additions & 6 deletions src/Estimators/tests/test_OneBodyDensityMatrices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ TEST_CASE("OneBodyDensityMatrices::generateSamples", "[estimators]")
xmlNodePtr node = doc.getRoot();
OneBodyDensityMatricesInput obdmi(node);

OneBodyDensityMatrices obDenMat(std::move(obdmi), pset_target.getLattice(), species_set, spo_map, pset_target);
OneBodyDensityMatrices obDenMat(std::move(obdmi), pset_target.getFullPrecLattice(), species_set, spo_map, pset_target);

testing::OneBodyDensityMatricesTests<QMCTraits::FullPrecRealType> obdmt;
//Get control over which rng is used.
Expand Down Expand Up @@ -332,7 +332,7 @@ TEST_CASE("OneBodyDensityMatrices::generateSamplesForSpinor", "[estimators]")
xmlNodePtr node = doc.getRoot();
OneBodyDensityMatricesInput obdmi(node);

OneBodyDensityMatrices obDenMat(std::move(obdmi), pset_target.getLattice(), species_set, spo_map, pset_target);
OneBodyDensityMatrices obDenMat(std::move(obdmi), pset_target.getFullPrecLattice(), species_set, spo_map, pset_target);

testing::OneBodyDensityMatricesTests<QMCTraits::FullPrecRealType> obdmt;
//Get control over which rng is used.
Expand Down Expand Up @@ -368,7 +368,7 @@ TEST_CASE("OneBodyDensityMatrices::spawnCrowdClone()", "[estimators]")
xmlNodePtr node = doc.getRoot();
OneBodyDensityMatricesInput obdmi(node);

OneBodyDensityMatrices original(std::move(obdmi), pset_target.getLattice(), species_set, spomap, pset_target);
OneBodyDensityMatrices original(std::move(obdmi), pset_target.getFullPrecLattice(), species_set, spomap, pset_target);
auto clone = original.spawnCrowdClone();
REQUIRE(clone != nullptr);
REQUIRE(clone.get() != &original);
Expand Down Expand Up @@ -396,7 +396,7 @@ TEST_CASE("OneBodyDensityMatrices::accumulate", "[estimators]")
auto& pset_target = *(particle_pool.getParticleSet("e"));
auto& pset_source = *(particle_pool.getParticleSet("ion"));
auto& species_set = pset_target.getSpeciesSet();
OneBodyDensityMatrices obdm(std::move(obdmi), pset_target.getLattice(), species_set, spomap, pset_target);
OneBodyDensityMatrices obdm(std::move(obdmi), pset_target.getFullPrecLattice(), species_set, spomap, pset_target);

std::vector<MCPWalker> walkers;
int nwalkers = 3;
Expand Down Expand Up @@ -493,7 +493,7 @@ TEST_CASE("OneBodyDensityMatrices::evaluateMatrix", "[estimators]")
auto& spomap = wavefunction_pool.getWaveFunction("wavefunction")->getSPOMap();
auto& pset_target = *(particle_pool.getParticleSet("e"));
auto& species_set = pset_target.getSpeciesSet();
OneBodyDensityMatrices obdm(std::move(obdmi), pset_target.getLattice(), species_set, spomap, pset_target);
OneBodyDensityMatrices obdm(std::move(obdmi), pset_target.getFullPrecLattice(), species_set, spomap, pset_target);
auto& trial_wavefunction = *(wavefunction_pool.getPrimary());

// Because we can't control or consistent know the global random state we must initialize particle positions to known values.
Expand Down Expand Up @@ -545,7 +545,7 @@ TEST_CASE("OneBodyDensityMatrices::registerAndWrite", "[estimators]")
auto& spomap = wavefunction_pool.getWaveFunction("wavefunction")->getSPOMap();
auto& pset_target = *(particle_pool.getParticleSet("e"));
auto& species_set = pset_target.getSpeciesSet();
OneBodyDensityMatrices obdm(std::move(obdmi), pset_target.getLattice(), species_set, spomap, pset_target);
OneBodyDensityMatrices obdm(std::move(obdmi), pset_target.getFullPrecLattice(), species_set, spomap, pset_target);

testing::OneBodyDensityMatricesTests<QMCTraits::FullPrecRealType> obdmt;
obdmt.testRegisterAndWrite(obdm);
Expand Down
3 changes: 1 addition & 2 deletions src/Estimators/tests/test_SpinDensityInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ namespace qmcplusplus
{
TEST_CASE("SpinDensityInput::readXML", "[estimators]")
{
using POLT = PtclOnLatticeTraits;
using Lattice = POLT::ParticleLayout;
using Lattice = CrystalLattice<OHMMS_PRECISION_FULL, OHMMS_DIM>;
using input = testing::ValidSpinDensityInput;
for (auto input_xml : input::xml)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Estimators/tests/test_SpinDensityNew.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ TEST_CASE("SpinDensityNew::SpinDensityNew(SPInput, SpeciesSet)", "[estimators]")
species_set(iattribute, ispecies) = 2;
SpinDensityInput sdi_copy = sdi;
SpinDensityNew(std::move(sdi), species_set);
CrystalLattice<OHMMS_PRECISION, OHMMS_DIM> lattice;
CrystalLattice<OHMMS_PRECISION_FULL, OHMMS_DIM> lattice;
}

TEST_CASE("SpinDensityNew::SpinDensityNew(SPInput, Lattice, SpeciesSet)", "[estimators]")
Expand Down
1 change: 1 addition & 0 deletions src/Particle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ set(PARTICLE
createDistanceTableAA.cpp
createDistanceTableAB.cpp
HDFWalkerInputManager.cpp
Lattice/CrystalLattice.cpp
LongRange/KContainer.cpp
LongRange/StructFact.cpp
LongRange/LPQHIBasis.cpp
Expand Down
Loading
Loading