Skip to content

Commit

Permalink
Merge branch 'develop' into matrix_update_engines_direct_inversion
Browse files Browse the repository at this point in the history
  • Loading branch information
PDoakORNL committed Oct 1, 2021
2 parents d6aa22f + a556925 commit 4e8b3f4
Show file tree
Hide file tree
Showing 84 changed files with 1,161 additions and 603 deletions.
2 changes: 1 addition & 1 deletion docs/developing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Class private/protected data members names should follow the convention of varia
(Member) function names
~~~~~~~~~~~~~~~~~~~~~~~

Function names should start with a lowercase character and have a capital letter for each new word.
Function names should start with a lowercase character and have a capital letter for each new word. The exception are the special cases for prefixed multiwalker (``mw_``) and flex (``flex_``) batched API functions. Coding convention should follow after those prefixes.

Template Parameters
~~~~~~~~~~~~~~~~~~~
Expand Down
6 changes: 3 additions & 3 deletions nexus/lib/pwscf_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,14 +924,14 @@ def plot_bandstructure(self, filename=None, filepath=None, max_min_e = None, sho
#end if
#end for
for ln, li in enumerate(labels):
if li is not '':
if li != '':
axvline(x[ln], ymin=-100, ymax=100, linewidth=3, color='k')
if li == 'GAMMA':
labels[ln] = r'$\Gamma$'
elif li is not '':
elif li != '':
labels[ln] = '${0}$'.format(li)
#end if
if labels[ln-1] is not '' and ln > 0:
if labels[ln-1] != '' and ln > 0:
labels[ln] = labels[ln-1]+'|'+labels[ln]
labels[ln-1] = ''
#end if
Expand Down
10 changes: 4 additions & 6 deletions nexus/lib/qmcpack_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,10 +799,8 @@ def get_result(self,result_name,sim):
wfn_file,ptcl_file = self.list_output_files()
if result_name=='orbitals':
result.location = os.path.join(self.locdir,wfn_file)
if self.input.hdf5==True:
orbfile = self.get_prefix()+'.orbs.h5'
result.orbfile = os.path.join(self.locdir,orbfile)
#end if
orbfile = self.get_prefix()+'.orbs.h5'
result.orbfile = os.path.join(self.locdir,orbfile)
elif result_name=='particles':
result.location = os.path.join(self.locdir,ptcl_file)
else:
Expand Down Expand Up @@ -841,15 +839,15 @@ def incorporate_result(self,result_name,result,sim):
self.input_code = 'pyscf'
if result_name=='orbitals':
orbpath = os.path.relpath(result.h5_file,self.locdir)
input.pyscf = orbpath
input.orbitals = orbpath
else:
implemented = False
#end if
elif isinstance(sim,QuantumPackage):
self.input_code = 'qp'
if result_name=='orbitals':
orbpath = os.path.relpath(result.outfile,self.locdir)
input.qp = orbpath
input.orbitals = orbpath
else:
implemented = False
#end if
Expand Down
2 changes: 1 addition & 1 deletion nexus/lib/qmcpack_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -5377,7 +5377,7 @@ def generate_jastrow1(function='bspline',size=8,rcut=None,coeff=None,cusp=0.,ena
corrs = []
for i in range(len(elements)):
element = elements[i]
if cusp is 'Z':
if cusp == 'Z':
QmcpackInput.class_error('need to implement Z cusp','generate_jastrow1')
else:
lcusp = cusp
Expand Down
12 changes: 7 additions & 5 deletions nexus/lib/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -5562,7 +5562,7 @@ def _getseekpath(
structure = structure.folded_structure
#end if
structure = structure.copy()
if structure.units is not 'A':
if structure.units != 'A':
structure.change_units('A')
#end if
axes = structure.axes
Expand Down Expand Up @@ -6783,10 +6783,12 @@ def __init__(self,
pos = []
if basis_vectors is None:
basis_vectors = axes
elif basis_vectors is 'primitive':
basis_vectors = axes_prim
elif basis_vectors is 'conventional':
basis_vectors = axes_conv
elif isinstance(basis_vectors,str):
if basis_vectors=='primitive':
basis_vectors = axes_prim
elif basis_vectors=='conventional':
basis_vectors = axes_conv
#end if
#end if
nbasis = len(atoms)
for point in points:
Expand Down
6 changes: 4 additions & 2 deletions nexus/tests/unit/test_qmcpack_converter_simulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def test_convert4qmc_get_result():

result_ref = obj(
location = './runs/sample.wfj.xml',
orbfile = './runs/sample.orbs.h5',
)

assert(object_eq(result,result_ref))
Expand Down Expand Up @@ -338,7 +339,7 @@ def test_convert4qmc_incorporate_result():
sim.incorporate_result('orbitals',pscf_result,pscf)

assert(sim.input_code=='pyscf')
assert(sim.input.pyscf=='../scf.h5')
assert(sim.input.orbitals=='../scf.h5')

# incorporate orbitals from quantum package
sim = sim_start.copy()
Expand All @@ -349,7 +350,8 @@ def test_convert4qmc_incorporate_result():
sim.incorporate_result('orbitals',qp_result,qp)

assert(sim.input_code=='qp')
assert(sim.input.qp=='../qp_savewf.out')
#assert(sim.input.qp=='../qp_savewf.out')
assert(sim.input.orbitals=='../qp_savewf.out')

clear_all_sims()
#end def test_convert4qmc_incorporate_result
Expand Down
7 changes: 5 additions & 2 deletions nexus/tests/unit/test_qmcpack_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ def test_incorporate_result():

result = c4q_orb.get_result('orbitals',None)

wfn_file = os.path.join(tpath,'c4q_orbitals.wfj.xml')
wfn_file = os.path.join(tpath,'c4q_orbitals.wfj.xml')
wfn_file2 = os.path.join(tpath,'c4q_orbitals.orbs.h5')
input = sim.input.copy()
dset = input.get('determinantset')
dset.href = 'orbs.h5'
Expand All @@ -281,6 +282,8 @@ def test_incorporate_result():
input.qmcsystem = qs
input.write(wfn_file)
assert(os.path.exists(wfn_file))
open(wfn_file2,'w').write('fake')
assert(os.path.exists(wfn_file2))

from qmcpack_input import QmcpackInput
inp = QmcpackInput(wfn_file)
Expand All @@ -291,7 +294,7 @@ def test_incorporate_result():
sim.incorporate_result('orbitals',result,c4q_orb)

dset = sim.input.get('determinantset')
assert(dset.href=='orbs.h5')
assert(dset.href=='c4q_orbitals.orbs.h5')


# incorporate qmcpack jastrow
Expand Down
2 changes: 1 addition & 1 deletion src/Estimators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ set(QMCEST_SRC
OperatorEstBase.cpp
SpinDensityNew.cpp
MomentumDistribution.cpp
)
OneBodyDensityMatricesInput.cpp)

####################################
# create libqmcestimators
Expand Down
6 changes: 2 additions & 4 deletions src/Estimators/InputSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ void InputSection::readXML(xmlNodePtr cur)

// check input validity
check_valid();

//report();
}

Expand All @@ -79,7 +78,6 @@ void InputSection::init(const std::unordered_map<std::string, std::any>& init_va

// check input validity
check_valid();

//report();
}

Expand All @@ -91,7 +89,6 @@ void InputSection::set_defaults()
set_from_value(name, default_value);
}


void InputSection::set_from_stream(const std::string& name, std::istringstream& svalue)
{
if (is_string(name))
Expand Down Expand Up @@ -158,7 +155,8 @@ void InputSection::check_valid()
<< " has not been assigned\n";
throw UniformCommunicateError(error.str());
}
}
this->checkParticularValidity();
};


void InputSection::report() const
Expand Down
9 changes: 8 additions & 1 deletion src/Estimators/InputSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class InputSection
// Enable read-only access to variable values.
// Needs updating to allow copy-less return.
template<typename T>
T get(const std::string& name) const
const T get(const std::string& name) const
{
return std::any_cast<T>(values.at(name));
}
Expand All @@ -74,6 +74,13 @@ class InputSection
// Initialize from unordered_map/initializer list
void init(const std::unordered_map<std::string, std::any>& init_values);

protected:
/** Do validation for a particular subtype of InputSection
* Called by check_valid.
* Default implementation is noop
*/
virtual void checkParticularValidity() {}

private:
// Query functions
bool is_attribute(const std::string& name) const { return attributes.find(name) != attributes.end(); }
Expand Down
2 changes: 1 addition & 1 deletion src/Estimators/MomentumDistribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ void MomentumDistribution::registerOperatorEstimator(hid_t gid)
ng[0] = nofK.size();
h5desc_.emplace_back(std::make_unique<ObservableHelper>("nofk"));
auto& h5o = h5desc_.back();
//h5o.set_dimensions(ng, myIndex);
//h5o.set_dimensions(ng, my_index_);
h5o->set_dimensions(ng, 0); // JTK: doesn't seem right
h5o->open(gid);
h5o->addProperty(const_cast<std::vector<PosType>&>(kPoints), "kpoints");
Expand Down
42 changes: 42 additions & 0 deletions src/Estimators/OneBodyDensityMatricesInput.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//////////////////////////////////////////////////////////////////////////////////////
// This file is distributed under the University of Illinois/NCSA Open Source License.
// See LICENSE file in top directory for details.
//
// Copyright (c) 2021 QMCPACK developers.
//
// File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
//
// Some code refactored from: DensityMatrices1b.cpp
//////////////////////////////////////////////////////////////////////////////////////

#include "string_utils.h"
#include "OneBodyDensityMatricesInput.h"

namespace qmcplusplus
{

OneBodyDensityMatricesInput::OneBodyDensityMatricesInput(){};
OneBodyDensityMatricesInput::OneBodyDensityMatricesInput(xmlNodePtr cur)
{
// This results in checkParticularValidity being called on OneBodyDensityMatrixInputSection
input_section_.readXML(cur);
}

void OneBodyDensityMatricesInput::OneBodyDensityMatrixInputSection::checkParticularValidity()
{
if (has("scale"))
{
Real scale = get<Real>("scale");
std::cout << "SCALE is :" << scale << '\n';
if (scale > 1.0 + 1e-10)
throw UniformCommunicateError("OneBodyDensityMatrices input: scale must be less than one");
else if (scale < 0.0 - 1e-10)
throw UniformCommunicateError("OneBodyDensityMatrices input: scale must be greater than zero");
}
std::string basis_str = get<std::string>("basis");
auto basis_set_names = split(basis_str);
if (basis_set_names.size() == 0 || basis_set_names[0].size() == 0)
throw UniformCommunicateError("OneBodyDensityMatrices input: basis must have at least one sposet");
}

} // namespace qmcplusplus
120 changes: 120 additions & 0 deletions src/Estimators/OneBodyDensityMatricesInput.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
//////////////////////////////////////////////////////////////////////////////////////
// This file is distributed under the University of Illinois/NCSA Open Source License.
// See LICENSE file in top directory for details.
//
// Copyright (c) 2021 QMCPACK developers.
//
// File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
//
// Some code refactored from: DensityMatrices1b.h
//////////////////////////////////////////////////////////////////////////////////////

#ifndef QMCPLUSPLUS_ONE_BODY_DENSITY_MATRICES_INPUT_H
#define QMCPLUSPLUS_ONE_BODY_DENSITY_MATRICES_INPUT_H

#include "Configuration.h"
#include "InputSection.h"

namespace qmcplusplus
{
/** Native representation for DensityMatrices1B Estimator's inputs
*/
class OneBodyDensityMatricesInput
{
public:
enum class Integrators
{
UNIFORM_GRID,
UNIFORM,
DENSITY,
NO_INTEGRATOR
};

enum class Evaluators
{
LOOP,
MATRIX,
NO_EVALUATOR
};

enum class Samplings
{
VOLUME_BASED,
METROPOLIS,
NO_SAMPLING
};

class OneBodyDensityMatrixInputSection : public InputSection
{
public:
/** parse time definition of input parameters */
OneBodyDensityMatrixInputSection()
{
section_name = "OneBodyDensityMatrix";
attributes = {"name", "type"};
parameters = {"basis", "energy_matrix", "integrator", "evaluator", "scale",
"center", "points", "samples", "warmup", "timestep",
"use_drift", "check_overlap", "check_derivatives", "acceptance_ratio", "rstats",
"normalized", "volumed_normed"};
bools = {"energy_matrix", "use_drift", "normalized", "volume_normed",
"check_overlap", "check_derivatives", "rstats", "acceptance_ratio"};
strings = {"name", "type", "basis", "integrator", "evaluator"};
integers = {"points", "samples"};
reals = {"scale", "timestep"};
required = {"name", "basis"};
// I'd much rather see the default defined in simple native c++ as below
}

/** do parse time checks of input */
void checkParticularValidity() override;
};

using Position = QMCTraits::PosType;
using Real = QMCTraits::FullPrecRealType;

OneBodyDensityMatricesInput();
OneBodyDensityMatricesInput(xmlNodePtr cur);

private:
OneBodyDensityMatrixInputSection input_section_;

bool energy_matrix_ = false;
bool use_drift_ = false;
bool normalized_ = true;
bool volume_normalized_ = true;
bool check_overlap_ = false;
bool check_derivatives_ = false;
bool rstats_ = false;
bool acceptance_ratio_ = false;
Integrators integrator_ = Integrators::UNIFORM_GRID;
Samplings sampling_ = Samplings::VOLUME_BASED;
Evaluators evaluator_ = Evaluators::LOOP;
Real scale_ = 1.0;
Position center_ = 0.0;
Real timestep_ = 0.5;
int points_ = 10;
int samples_ = 10;
int warmup_samples_ = 30;
public:
bool get_energy_matrix() const { return energy_matrix_; }
bool get_use_drift() const { return use_drift_; }
bool get_normalized() const { return normalized_; }
bool get_volume_normalized() const { return volume_normalized_; }
bool get_check_overlap() const { return check_overlap_; }
bool get_check_derivatives() const { return check_derivatives_; }
bool get_rstats() const { return rstats_; }
bool get_acceptance_ratio() const { return acceptance_ratio_; }
Integrators get_integrator() const { return integrator_; }
Samplings get_sampling() const { return sampling_; }
Evaluators get_evaluator() const { return evaluator_; }
Real get_scale() const { return scale_; }
Position get_center() const { return center_; }
Real get_timestep() const { return timestep_; }
int get_points() const { return points_; }
int get_samples() const { return samples_; }
int get_warmup_samples() const { return warmup_samples_; }
};

} // namespace qmcplusplus

#endif
3 changes: 2 additions & 1 deletion src/Estimators/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ set(SRCS
test_manager.cpp
test_EstimatorManagerNew.cpp
test_trace_manager.cpp
SpinDensityTesting.cpp
EstimatorTesting.cpp
test_SpinDensityInput.cpp
test_SpinDensityNew.cpp
test_InputSection.cpp
test_OneBodyDensityMatricesInput.cpp
)

add_executable(${UTEST_EXE} ${SRCS})
Expand Down
Loading

0 comments on commit 4e8b3f4

Please sign in to comment.