Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
1,746 changes: 1,346 additions & 400 deletions nexus/nexus/qmcpack_input.py

Large diffs are not rendered by default.

252 changes: 251 additions & 1 deletion nexus/nexus/tests/test_qmcpack_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ def test_qixml_class_init():
elements = tuple,
text = str,
parameters = tuple,
parents = tuple,
attribs = tuple,
costs = tuple,
h5tags = tuple,
Expand All @@ -525,14 +526,17 @@ def test_qixml_class_init():
defaults = obj,
collection_id = str,
exp_names = obj,
attribute_aliases = obj,
element_aliases = obj,
unsupported = tuple,
params = tuple,
plurals_inv = obj,
plurals = obj,
expanded_names = obj,
afqmc_order = tuple,
)
optional = set(['expanded_names','afqmc_order'])
assert(len(attr_types)==21)
assert(len(attr_types)==25)

def valid_name(s):
v = True
Expand Down Expand Up @@ -568,11 +572,257 @@ def valid_name(s):
#end if
#end if
#end for
declared_inputs = set(cls.attributes+cls.parameters+cls.elements)
assert(set(cls.unsupported)<=declared_inputs)
#end for

#end def test_qixml_class_init


def test_qixml_live_and_unsupported_parameters(tmp_path):
from ..qmcpack_input import QIxml
from ..qmcpack_input import QmcpackInput
from ..qmcpack_input import atomicbasisset,bspline_builder,checkpoint_element,coefs_mem,determinant,detlist
from ..qmcpack_input import dmc,dmc_batch,group,init
from ..qmcpack_input import force,hamiltonian,harmonic_extpot,hybrid_optimizer
from ..qmcpack_input import linear,linear_batch,mpc,multideterminant,onebodydensitymatrices,optimize
from ..qmcpack_input import mcwalkerset,paircorrelation,particleset,pseudo,pseudopotential
from ..qmcpack_input import qmc_system_selector,qmcsystem,rpa_jastrow,simulation,simulationcell
from ..qmcpack_input import sposet,sposet_builder,sposet_collection,structurefactor,vmc,vmc_batch,walkerlogs

assert(QIxml.unsupported==())
assert(multideterminant.unsupported==('spo_down','fast'))
assert(detlist.unsupported==())
assert('basisset' not in determinant.unsupported)
assert('size' not in determinant.unsupported)
assert('cuspinfo' not in determinant.unsupported)
assert(pseudo.unsupported==('cutoff',))
assert(mpc.unsupported==('ecut','source','target'))
assert(force.unsupported==('addionion','weightexp','lrmethod'))
assert(structurefactor.unsupported==('report','hdf5','writerho','writeionion'))
assert(paircorrelation.unsupported==('debug','sources'))
assert('max_relative_change' in linear.unsupported)
assert('gpu' not in linear.unsupported)
assert('gpu' in vmc.unsupported)
assert('target' not in vmc.unsupported)
assert('trace' not in vmc.unsupported)
assert('trace' in vmc_batch.unsupported)
assert('walkers' not in vmc.unsupported)
assert('walkers' in vmc_batch.unsupported)
assert('walkers' in dmc_batch.unsupported)
assert('l2_diffusion' not in dmc.unsupported)
assert('reconfiguration' not in dmc.unsupported)
assert('reconfiguration' in dmc_batch.unsupported)
assert('l2_diffusion' in dmc_batch.unsupported)
assert(onebodydensitymatrices.unsupported==('reuse','basis_size','warmup'))
assert(mcwalkerset.unsupported==('target','walkers'))
assert(qmcsystem.unsupported==('dim',))
assert(simulationcell.unsupported==('name','tilematrix','reciprocal','uc_grid'))
assert(particleset.unsupported==('charge','source','role','simulationcell'))
assert(group.unsupported==('id','mass'))
assert(simulation.parents==())
assert(group.parents==('particleset',))
assert(force.parents==('hamiltonian',))

obdm = onebodydensitymatrices(
type = 'OneBodyDensityMatrices',
name = 'OneBodyDensityMatrices',
basis = 'spo_ud',
volume_normed = False,
warmup_samples = 17,
)
obdm_xml = obdm.write()
assert('<parameter name="volume_normed"' in obdm_xml)
assert('<parameter name="warmup_samples"' in obdm_xml)
assert('> no' in obdm_xml)

det_xml = determinant(
id = 'updet',
size = 2,
basisset = 'LCAOBSet',
cuspinfo = 'updet.cuspInfo.xml',
).write()
assert('size="2"' in det_xml)
assert('basisset="LCAOBSet"' in det_xml)
assert('cuspInfo="updet.cuspInfo.xml"' in det_xml)

detlist_xml = detlist(
type = 'CSF',
size = 2,
sortby = 'qchem_coeff',
zero_cutoff = 1e-8,
).write()
assert('sortby="qchem_coeff"' in detlist_xml)
assert('zero_cutoff="1e-08"' in detlist_xml)

cell = simulationcell(
vacuum = 1.5,
ewald_grid = 1001,
)
cell_xml = cell.write()
assert('<parameter name="vacuum"' in cell_xml)
assert('<parameter name="ewald_grid"' in cell_xml)

pset = particleset(
id = 'e',
gpu = 'omptarget',
spinor = True,
groups = [group(name='u',size=1,charge=-1)],
)
pset_xml = pset.write()
assert('<particleset id="e"' in pset_xml)
assert('gpu="omptarget"' in pset_xml)
assert('spinor="yes"' in pset_xml)

init_xml = init(source='ion0',target='e',use_volume=True).write()
assert('<init source="ion0" target="e" use_volume="yes"/>' in init_xml)

basis = atomicbasisset(elementtype='C',expm='yes')
assert('elementType="C"' in basis.write())
assert('expM="yes"' in basis.write())

builder = bspline_builder(
type = 'bspline',
skip_checks = True,
check_orb_norm = False,
save_coefs = True,
sposet = sposet(
name = 'spo-u',
size = 4,
coefs_mem = coefs_mem(distributed_ranks=2,shared_ranks=4),
),
)
builder_xml = builder.write()
assert('skip_checks="yes"' in builder_xml)
assert('check_orb_norm="no"' in builder_xml)
assert('save_coefs="yes"' in builder_xml)
assert('<coefs_mem distributed_ranks="2" shared_ranks="4"/>' in builder_xml)

pw_xml = sposet_builder(
type = 'pw',
twistindex = 2,
bufferlayer = 1,
expand = 3,
).write()
assert('<sposet_builder type="pw">' in pw_xml)
assert('<parameter name="twistIndex"' in pw_xml)
assert('<parameter name="bufferLayer"' in pw_xml)

collection_xml = sposet_collection(type='heg',source='ion0').write()
assert(collection_xml.startswith('<sposet_collection type="heg"'))

checkpoint_xml = vmc(
method = 'vmc',
checkpoint = -1,
checkpoint_element = checkpoint_element(stride=20),
).write()
assert('<qmc method="vmc" checkpoint="-1">' in checkpoint_xml)
assert('<checkpoint stride="20"/>' in checkpoint_xml)

rpa = rpa_jastrow(
type = 'rpa',
longrange = True,
shortrange = False,
rs = 2.0,
kc = 1.0,
)
rpa_xml = rpa.write()
assert('longrange="yes"' in rpa_xml)
assert('shortrange="no"' in rpa_xml)
assert('<parameter name="rs"' in rpa_xml)
assert('<parameter name="kc"' in rpa_xml)

pp = pseudopotential(
type = 'pseudo',
pbc = False,
physicalso = True,
spin_integrator = 'exact',
)
pp_xml = pp.write()
assert('pbc="no"' in pp_xml)
assert('physicalSO="yes"' in pp_xml)
assert('spin_integrator="exact"' in pp_xml)

ham = hamiltonian(
name = 'h0',
wavefunction = 'psi0',
extpot = harmonic_extpot(type='harmonic_ext',mass=1.0,frequency=2.0),
estimator = paircorrelation(type='paircorrelation',dr=0.1),
)
ham_xml = ham.write()
assert('wavefunction="psi0"' in ham_xml)
assert('<extpot type="harmonic_ext"' in ham_xml)
assert('<estimator type="PairCorrelation"' in ham_xml)

calc = dmc(
method = 'dmc',
append = 'yes',
drift_unr_a = 1.0,
maxdisplsq = 4.0,
energyupdateinterval = 10,
refenergy = -1.0,
maxcopy = 2,
qmc_system_selector = qmc_system_selector(
wavefunction = 'psi1',
hamiltonian = 'h1',
),
)
calc_xml = calc.write()
assert('append="yes"' in calc_xml)
assert('<parameter name="drift_UNR_a"' in calc_xml)
assert('<parameter name="maxDisplSq"' in calc_xml)
assert('<parameter name="energyUpdateInterval"' in calc_xml)
assert('<parameter name="refEnergy"' in calc_xml)
assert('<parameter name="maxCopy"' in calc_xml)
assert('<qmcsystem wavefunction="psi1" hamiltonian="h1"/>' in calc_xml)

selector_file = tmp_path/'qmc_system_selector.xml'
selector_file.write_text('''<simulation>
<project id="qmc" series="0"/>
<qmc method="dmc">
<qmcsystem wavefunction="psi1" hamiltonian="h1"/>
</qmc>
</simulation>
''')
selector_input = QmcpackInput(selector_file)
selector = selector_input.simulation.qmc.qmc_system_selector
assert(selector.wavefunction=='psi1')
assert(selector.hamiltonian=='h1')

opt = linear(
method = 'linear',
max_relative_cost_change = 5.0,
optimize = optimize(
method = 'gradient_test',
output_param_file = True,
finite_diff_delta = 1e-5,
),
optimizers = [
hybrid_optimizer(num_updates=3,minmethod='adaptive'),
hybrid_optimizer(num_updates=2,minmethod='descent'),
],
)
opt_xml = opt.write()
assert('<parameter name="max_relative_cost_change"' in opt_xml)
assert('<optimize method="gradient_test">' in opt_xml)
assert(opt_xml.count('<optimizer num_updates=')==2)
assert('<parameter name="MinMethod"' in opt_xml)

batched = linear_batch(
method = 'linear_batch',
**{'options_LMY_.targetExcited':'yes'},
)
assert('<parameter name="options_LMY_.targetExcited"' in batched.write())

sim = simulation(
walkerlogs = walkerlogs(step_period=4,particle=True,quantiles=False),
)
sim_xml = sim.write()
assert('<walkerlogs step_period="4" particle="yes" quantiles="no"/>' in sim_xml)

#end def test_qixml_live_and_unsupported_parameters



def test_compose():
import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion src/Estimators/OneBodyDensityMatricesInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ OneBodyDensityMatricesInput::OneBodyDensityMatricesInput(xmlNodePtr cur)
setIfInInput(energy_matrix_, "energy_matrix");
setIfInInput(use_drift_, "use_drift");
setIfInInput(normalized_, "normalized");
setIfInInput(volume_normalized_, "volume_normalized");
setIfInInput(volume_normalized_, "volume_normed");
setIfInInput(check_overlap_, "check_overlap");
setIfInInput(check_derivatives_, "check_derivatives");
setIfInInput(rstats_, "rstats");
Expand Down
2 changes: 1 addition & 1 deletion src/Estimators/OneBodyDensityMatricesInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class OneBodyDensityMatricesInput
parameters = {"basis", "energy_matrix", "integrator", "evaluator", "scale",
"corner", "center", "points", "samples", "warmup", "timestep",
"use_drift", "check_overlap", "check_derivatives", "acceptance_ratio", "rstats",
"normalized", "volumed_normed"};
"normalized", "volume_normed"};
bools = {"energy_matrix", "use_drift", "normalized", "volume_normed",
"check_overlap", "check_derivatives", "rstats", "acceptance_ratio"};
enums = {"integrator", "evaluator"};
Expand Down
17 changes: 17 additions & 0 deletions src/Estimators/tests/test_OneBodyDensityMatricesInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "Message/UniformCommunicateError.h"

#include <iostream>
#include <string_view>

namespace qmcplusplus
{
Expand Down Expand Up @@ -56,4 +57,20 @@ TEST_CASE("OneBodyDensityMatricesInput::copy_construction", "[estimators]")
static_assert(std::is_copy_constructible_v<OneBodyDensityMatricesInput>);
}

TEST_CASE("OneBodyDensityMatricesInput::volume_normed", "[estimators]")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we didn't have coverage that a particular input string really results in the correct native input representation. I think generating more comprehensive tests like this should get on the road map. I will look into doing it. In the meantime "volume_normed" will at least not have a regression.

Unfortunately It doesn't look to me like its actually tested, i.e. volume_normed=no doesn't appear covered by an application or unit level test. So while this isn't "unsupported" we don't protect this functionality from breakage and I can't attest it works as intended. Am I missing something?
If true this should become an issue it's not a defect with the PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think volume_normed is covered. It is not on the updated "unsupported" list and will be kept through the removal process.

{
constexpr std::string_view input_xml = R"XML(
<estimator type="OneBodyDensityMatrices" name="OneBodyDensityMatrices">
<parameter name="basis">spo_ud</parameter>
<parameter name="integrator">uniform</parameter>
<parameter name="volume_normed">no</parameter>
</estimator>
)XML";

Libxml2Document doc;
REQUIRE(doc.parseFromString(input_xml));
OneBodyDensityMatricesInput obdmi(doc.getRoot());
CHECK_FALSE(obdmi.get_volume_normalized());
}

} // namespace qmcplusplus
18 changes: 18 additions & 0 deletions tests/heg/heg_14_gamma/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,15 @@ qmc_run_and_check(
DET_HEG14GSSJB_SCALARS # VMC
)

qmc_run_and_check(
deterministic-heg_14_gamma-sjb-batched
"${qmcpack_SOURCE_DIR}/tests/heg/heg_14_gamma"
det_heg_short_SJB_batched
det_heg-short-SJB_batched.xml
1
1
TRUE)

if(NOT QMC_MIXED_PRECISION)
simple_run_and_check(
deterministic-heg_14_gamma-sjb-opt
Expand Down Expand Up @@ -483,4 +492,13 @@ if(NOT QMC_MIXED_PRECISION)
DET_HEG14GSSJB_OPT_SCALARS # VMC
)

qmc_run_and_check(
deterministic-heg_14_gamma-sjb-opt-batched
"${qmcpack_SOURCE_DIR}/tests/heg/heg_14_gamma"
det_heg_short_SJB_opt_batched
det_heg-short-SJB_opt_batched.xml
1
1
TRUE)

endif()
23 changes: 23 additions & 0 deletions tests/heg/heg_14_gamma/det_heg-short-SJB_batched.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<simulation>
<project id="det_heg_short_SJB_batched" series="0">
<application name="qmcapp" class="serial">
Sample qmc run for Slater-Jastrow-Backflow HEG.
</application>
<parameter name="driver_version">batched</parameter>
</project>
<random seed="93"/>
<include href="heg.ptcl.xml"/>
<include href="heg.sjb.wfs.xml"/>
<include href="heg.H.xml"/>

<qmc method="vmc" move="pbyp">
<estimator name="LocalEnergy" hdf5="no"/>
<parameter name="total_walkers" > 1 </parameter>
<parameter name="blocks" > 3 </parameter>
<parameter name="steps" > 3 </parameter>
<parameter name="subSteps" > 2 </parameter>
<parameter name="timestep" > 0.3 </parameter>
<parameter name="warmupSteps" > 3 </parameter>
</qmc>
</simulation>
Loading