55 attributes = {
"name",
"samples",
"kmax",
"full",
"width::type"};
56 parameters = {
"label",
"count",
"width",
"rational",
"testenum1",
57 "testenum2",
"sposets",
"center",
"density",
"target"};
59 strings = {
"name",
"label",
"width::type"};
64 reals = {
"kmax",
"width"};
66 bools = {
"full",
"rational"};
67 enums = {
"testenum1",
"testenum2"};
71 {
"rational", bool(
false)}};
96 TEST_CASE(
"InputSection::InputSection",
"[estimators]")
112 TEST_CASE(
"InputSection::assignAnyEnum",
"[estimators]")
126 SECTION(
"minimum required attributes and parameters")
129 const char* xml = R
"( 131 <parameter name="count"> 15 </parameter> 162 CHECK(ti.
get<
bool>(
"full") ==
false);
164 CHECK(ti.
get<std::string>(
"name") ==
"demo");
165 CHECK(ti.
get<
int>(
"samples") == 20);
167 CHECK(ti.
get<
bool>(
"rational") ==
false);
170 SECTION(
"complete attributes and parameters")
173 const char* xml = R
"( 174 <test name="alice" samples="10" kmax="3.0" full="no"> 175 <parameter name="label" > relative </parameter> 176 <parameter name="count" > 15 </parameter> 177 <parameter name="width" type="super"> 2.5 </parameter> 178 <parameter name="rational"> yes </parameter> 179 <parameter name="testenum1"> Value1 </parameter> 180 <parameter name="testenum2"> Value2 </parameter> 181 <parameter name="sposets"> spo1 spo2 </parameter> 182 <density> 10.0 20.0 30.0 </density> 183 <target> 0.0 0.2 0.3 </target> 184 <target> 0.1 0.3 0.5 </target> 185 <parameter name="center"> 0.0 0.0 0.1 </parameter> 213 CHECK(ti.
get<std::string>(
"name") ==
"alice");
214 CHECK(ti.
get<
int>(
"samples") == 10);
216 CHECK(ti.
get<
bool>(
"full") ==
false);
217 CHECK(ti.
get<std::string>(
"label") ==
"relative");
220 CHECK(ti.
get<std::string>(
"width::type") ==
"super");
221 CHECK(ti.
get<
bool>(
"rational") ==
true);
222 CHECK(ti.
get<std::vector<Real>>(
"density") == std::vector<Real>{10.0, 20.0, 30.0});
225 CHECK(ti.
get<std::vector<std::string>>(
"sposets") == std::vector<std::string>{
"spo1",
"spo2"});
229 SECTION(
"invalid inputs")
235 std::map<std::string, std::string_view> invalid_inputs =
236 {{
"missing_attribute", R
"( 238 <parameter name="count"> 15 </parameter> 241 {"missing_parameter", R
"( 244 {"foreign_attribute", R
"( 245 <test full="no" area="51"> 246 <parameter name="count"> 15 </parameter> 249 {"foreign_parameter", R
"( 251 <parameter name="count"> 15 </parameter> 252 <parameter name="area" > 51 </parameter> 255 {"invalid_section_name", R
"(<not_test><parameter name="nothing"></parameter></not_test>)"}}; 257 std::cout << "really going to try bad sections\n" << std::endl;
258 for (
auto& [label, xml] : invalid_inputs)
273 TEST_CASE(
"InputSection::InvalidElement",
"[estimators]")
275 std::string invalid_element{R
"(<test> < </test>)"}; 286 SECTION(
"bad type handling")
291 SECTION(
"minimum required attributes and parameters")
295 ti.init({{
"full", bool(
false)}, {
"count", int(15)}});
297 ti.report(std::cout);
300 CHECK(ti.has(
"full"));
301 CHECK(ti.has(
"count"));
303 CHECK(ti.has(
"name"));
304 CHECK(ti.has(
"samples"));
305 CHECK(ti.has(
"width"));
306 CHECK(ti.has(
"rational"));
308 CHECK(!ti.has(
"kmax"));
309 CHECK(!ti.has(
"label"));
311 CHECK(ti.get<
bool>(
"full") ==
false);
312 CHECK(ti.get<
int>(
"count") == 15);
313 CHECK(ti.get<std::string>(
"name") ==
"demo");
314 CHECK(ti.get<
int>(
"samples") == 20);
315 CHECK(ti.get<
Real>(
"width") == Approx(1.0));
316 CHECK(ti.get<
bool>(
"rational") ==
false);
320 SECTION(
"complete attributes and parameters")
324 ti.init({{
"name", std::string(
"alice")},
325 {
"samples", int(10)},
327 {
"full", bool(
false)},
328 {
"label", std::string(
"relative")},
330 {
"width",
Real(2.5)},
331 {
"rational", bool(
true)},
332 {
"sposets", std::vector<std::string>{
"spo1",
"spo2"}},
335 ti.report(std::cout);
337 CHECK(ti.has(
"name"));
338 CHECK(ti.has(
"samples"));
339 CHECK(ti.has(
"kmax"));
340 CHECK(ti.has(
"full"));
341 CHECK(ti.has(
"label"));
342 CHECK(ti.has(
"count"));
343 CHECK(ti.has(
"width"));
344 CHECK(ti.has(
"rational"));
346 CHECK(ti.get<std::string>(
"name") ==
"alice");
347 CHECK(ti.get<
int>(
"samples") == 10);
348 CHECK(ti.get<
Real>(
"kmax") == Approx(3.0));
349 CHECK(ti.get<
bool>(
"full") ==
false);
350 CHECK(ti.get<std::string>(
"label") ==
"relative");
351 CHECK(ti.get<
int>(
"count") == 15);
352 CHECK(ti.get<
Real>(
"width") == Approx(2.5));
353 CHECK(ti.get<
bool>(
"rational") ==
true);
354 CHECK(ti.get<std::vector<std::string>>(
"sposets") == std::vector<std::string>{
"spo1",
"spo2"});
359 SECTION(
"invalid type assignment")
362 CHECK_THROWS_AS(ti.init({{
"full", bool(false)}, {
"count", Real(15.)}}), UniformCommunicateError);
369 ti.
init({{
"name", std::string(
"alice")},
370 {
"samples", int(10)},
372 {
"full", bool(
false)},
373 {
"label", std::string(
"relative")},
375 {
"width",
Real(2.5)},
376 {
"rational", bool(
true)},
377 {
"sposets", std::vector<std::string>{
"spo1",
"spo2"}},
401 using Repeater = std::vector<std::pair<std::string, std::string>>;
404 section_name =
"Test";
405 attributes = {
"name",
"samples",
"kmax",
"full",
"custom_attribute",
"with_custom::custom_attribute"};
406 parameters = {
"label",
"count",
"width",
"with_custom"};
407 strings = {
"name",
"label",
"with_custom"};
409 integers = {
"samples",
"count"};
411 custom = {
"weird_stuff",
"repeater",
"custom_attribute"};
413 void setFromStreamCustom(
const std::string& ename,
const std::string& name, std::istringstream& svalue)
override 415 if (ename ==
"weird_stuff")
424 else if (ename ==
"repeater")
426 std::string compound;
428 auto split_vstrv =
split(compound,
":");
430 std::any_cast<
Repeater>(&(values_[name]))->emplace_back(split_vstrv[0], split_vstrv[1]);
432 values_[name] =
Repeater{{split_vstrv[0], split_vstrv[1]}};
434 else if (name ==
"custom_attribute" || name ==
"with_custom::custom_attribute")
437 std::getline(svalue, cus_at);
438 values_[name] = cus_at;
441 throw std::runtime_error(
"bad name passed: " + name +
442 " or custom setFromStream not implemented in derived class.");
445 void report(std::ostream& ostr) { InputSection::report(ostr); }
456 using Repeater = std::vector<std::pair<std::string, std::string>>;
459 section_name =
"Test";
460 attributes = {
"name",
"samples",
"kmax",
"full",
"custom_attribute",
"with_custom::custom_attribute"};
461 parameters = {
"label",
"count",
"width",
"with_custom"};
462 strings = {
"name",
"label"};
464 integers = {
"samples",
"count"};
466 custom = {
"weird_stuff",
"repeater",
"custom_attribute"};
472 std::string_view xml = R
"XML( 473 <test name="alice" samples="10" kmax="3.0" full="no" custom_attribute="for the section"> 474 <parameter name="label" > relative </parameter> 475 <parameter name="count" > 15 </parameter> 476 <weird_stuff name="weird"> XQ 10 20 10 </weird_stuff> 477 <Repeater> first:something </Repeater> 478 <Repeater> second:else </Repeater> 479 <parameter name="with_custom" custom_attribute="This is a custom attribute."/> 489 auto ws = cti.
get<decltype(cti)::WeirdStuff>(
"weird");
490 CHECK(ws.letters ==
"XQ");
491 std::array<int, 3> exp_numbers{10, 20, 10};
492 CHECK(ws.numbers == exp_numbers);
495 std::string custom_attribute = cti.
get<std::string>(
"with_custom::custom_attribute");
496 CHECK(custom_attribute ==
"This is a custom attribute.");
497 custom_attribute = cti.
get<std::string>(
"custom_attribute");
498 CHECK(custom_attribute ==
"for the section");
500 auto repeater = cti.
get<decltype(cti)::Repeater>(
"repeater");
501 decltype(cti)::Repeater exp_repeater{{
"first",
"something"}, {
"second",
"else"}};
502 CHECK(repeater == exp_repeater);
505 CHECK_THROWS_AS(fcti.
readXML(cur), std::runtime_error);
524 section_name =
"AnotherInput";
525 section_name_alternates = {
"ainput"};
526 attributes = {
"name",
"optional"};
527 strings = {
"name",
"optional"};
533 input_section_.readXML(cur);
535 setIfInInput(name_,
"name");
536 setIfInInput(optional_,
"optional");
541 const std::string&
get_name()
const {
return name_; };
544 std::string name_ =
"AnotherInputSection";
554 value_label = another_input.
get_name();
555 return another_input;
568 section_name =
"DelegateTest";
569 attributes = {
"name",
"full"};
570 parameters = {
"label",
"count",
"width"};
571 strings = {
"name",
"label"};
572 integers = {
"count"};
574 delegates = {
"anotherinput"};
583 bool has(
const std::string& name)
const {
return dins_.has(name); }
585 T
get(
const std::string& name)
const 587 return dins_.get<T>(name);
591 std::string name_ =
"DelegatingInput";
597 std::string_view xml = R
"XML( 598 <delegatetest name="alice" full="no"> 599 <parameter name="label" > relative </parameter> 600 <parameter name="count" > 15 </parameter> 601 <AnotherInput name="ainput"> XQ 10 20 10 </AnotherInput> 614 std::vector<std::string_view> ref_tokens{
"XQ",
"10",
"20",
"10"};
615 CHECK(ai.getTokens() == ref_tokens);
618 std::string_view xml_duplicate_delegate_name = R
"XML( 619 <test name="alice" full="no"> 620 <parameter name="label" > relative </parameter> 621 <parameter name="count" > 15 </parameter> 622 <AnotherInput name="ainput"> XQ 10 20 10 </AnotherInput> 623 <AnotherInput name="ainput"> XQ 10 20 10 </AnotherInput> std::vector< std::string_view > tokens_
std::any makeAnotherInput(xmlNodePtr cur, std::string &value_label)
std::unordered_set< std::string > strings
std::unordered_set< std::string > reals
class that handles xmlDoc
AnotherInput(xmlNodePtr cur)
helper functions for EinsplineSetBuilder
std::unordered_set< std::string > parameters
std::array< int, 3 > numbers
Generic delgate input class.
std::vector< std::string_view > getTokens() const
TEST_CASE("complex_helper", "[type_traits]")
const std::string & get_name() const
std::unordered_map< std::string, std::any > lookup_input_enum_value
std::any assignAnyEnum(const std::string &name) const override
Derived class overrides this to get proper assignment of scoped enum values.
std::unordered_set< std::string > positions
std::unordered_map< std::string, std::any > default_values
QMCTraits::FullPrecRealType Real
void setFromStreamCustom(const std::string &ename, const std::string &name, std::istringstream &svalue) override
Derived class can overrides this to do custom parsing of the element values for Custom elements These...
Generic input section delegating some inputs to other input classes.
void init(const std::unordered_map< std::string, std::any > &init_values)
bool has(const std::string &name) const
REQUIRE(std::filesystem::exists(filename))
void report(std::ostream &ostr)
T get(const std::string &name) const
#define LAMBDA_setIfInInput
If tag is present in input_secution set its variable.
typename QMCTypes< Real, OHMMS_DIM >::PosType Position
std::unordered_set< std::string > integers
This a subclass for runtime errors that will occur on all ranks.
void readXML(xmlNodePtr cur)
Read variable values (initialize) from XML input, call checkValid.
void report(std::ostream &ostr)
constexpr bool has(const R &this_one)
std::unordered_set< std::string > attributes
TEST_CASE("InputSection::Delegate", "[estimators]")
static std::any lookupAnyEnum(const std::string &enum_name, const std::string &enum_value, const std::unordered_map< std::string, std::any > &enum_map)
Assign any enum helper for InputSection derived class assumes enum lookup table of this form: inline ...
DelegatingInputSection dins_
std::vector< std::pair< std::string, std::string > > Repeater
convert xmlNode contents into a std::string
std::unordered_set< std::string > required
bool parseFromString(const std::string_view data)
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
std::vector< std::string_view > split(const string_view s, const string_view delimiters)
AnotherInputSection input_section_
std::unordered_set< std::string > multi_strings
std::unordered_set< std::string > bools
std::unordered_set< std::string > multi_reals
QTFull::RealType FullPrecRealType
DelegatingInput(xmlNodePtr cur)
std::vector< std::pair< std::string, std::string > > Repeater
std::unordered_set< std::string > multiple
Input section provides basic parsing and a uniform method of access to the raw parsed input...
T get(const std::string &name) const
bool has(const std::string &name) const
std::string section_name
"Name" of the input section, you must define this in the subtype and the ename, name, type, or method must match.
std::array< int, 3 > numbers
std::unordered_set< std::string > enums
list of enum inputs which allow a finite set of strings to map to enum values The enum class types an...