Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
52 changes: 27 additions & 25 deletions src/Estimators/InputSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
namespace qmcplusplus
{

template<typename T>
Comment thread
prckent marked this conversation as resolved.
Outdated
const T& anyCastOrThrow(const std::string& section_name, const std::string& name, const std::any& value)
Comment thread
prckent marked this conversation as resolved.
Outdated
{
if (const auto* typed_value = std::any_cast<T>(&value))
return *typed_value;

throw UniformCommunicateError("std::any_cast failed in setFromValue for name:" + name + " in " + section_name);
}

[[noreturn]] std::any InputSection::assignAnyEnum(const std::string& tag) const
{
throw UniformCommunicateError("derived class must provide assignAnyEnum method if enum parameters are used");
Expand Down Expand Up @@ -275,32 +284,25 @@ void InputSection::assignValue(const std::string& name, const T& value)

void InputSection::setFromValue(const std::string& name, const std::any& value)
{
try
{
if (isString(name) || isEnumString(name))
assignValue(name, std::any_cast<std::string>(value));
else if (isMultiString(name))
assignValue(name, std::any_cast<std::vector<std::string>>(value));
else if (isMultiReal(name))
assignValue(name, std::any_cast<std::vector<std::string>>(value));
Comment thread
prckent marked this conversation as resolved.
else if (isBool(name))
assignValue(name, std::any_cast<bool>(value));
else if (isInteger(name))
assignValue(name, std::any_cast<int>(value));
else if (isReal(name))
assignValue(name, std::any_cast<Real>(value));
else if (isPosition(name))
assignValue(name, std::any_cast<Position>(value));
else
{
std::stringstream error;
error << "InputSection::set_from_value name " << name << " in " << section_name << " does not have a type\n";
throw UniformCommunicateError(error.str());
}
}
catch (const std::bad_cast& exc)
if (isString(name) || isEnumString(name))
assignValue(name, anyCastOrThrow<std::string>(section_name, name, value));
else if (isMultiString(name))
assignValue(name, anyCastOrThrow<std::vector<std::string>>(section_name, name, value));
else if (isMultiReal(name))
assignValue(name, anyCastOrThrow<std::vector<Real>>(section_name, name, value));
Comment thread
prckent marked this conversation as resolved.
Outdated
else if (isBool(name))
assignValue(name, anyCastOrThrow<bool>(section_name, name, value));
else if (isInteger(name))
assignValue(name, anyCastOrThrow<int>(section_name, name, value));
else if (isReal(name))
assignValue(name, anyCastOrThrow<Real>(section_name, name, value));
else if (isPosition(name))
assignValue(name, anyCastOrThrow<Position>(section_name, name, value));
else
{
std::throw_with_nested(UniformCommunicateError("std::any_cast failed in setFromValue for name:" + name));
std::stringstream error;
error << "InputSection::set_from_value name " << name << " in " << section_name << " does not have a type\n";
throw UniformCommunicateError(error.str());
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/Estimators/tests/test_InputSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ TEST_CASE("InputSection::init", "[estimators]")
{"width", Real(2.5)},
{"rational", bool(true)},
{"sposets", std::vector<std::string>{"spo1", "spo2"}},
{"density", std::vector<Real>{10.0, 20.0, 30.0}},
{"center", InputSection::Position(0.0, 0.0, 0.1)}});

ti.report(std::cout);
Expand All @@ -338,6 +339,7 @@ TEST_CASE("InputSection::init", "[estimators]")
CHECK(ti.has("count"));
CHECK(ti.has("width"));
CHECK(ti.has("rational"));
CHECK(ti.has("density"));
// check value correctness
CHECK(ti.get<std::string>("name") == "alice");
CHECK(ti.get<int>("samples") == 10);
Expand All @@ -348,6 +350,7 @@ TEST_CASE("InputSection::init", "[estimators]")
CHECK(ti.get<Real>("width") == Approx(2.5));
CHECK(ti.get<bool>("rational") == true);
CHECK(ti.get<std::vector<std::string>>("sposets") == std::vector<std::string>{"spo1", "spo2"});
CHECK(ti.get<std::vector<Real>>("density") == std::vector<Real>{10.0, 20.0, 30.0});
CHECK(ti.get<InputSection::Position>("center") == InputSection::Position(0.0, 0.0, 0.1));
}

Expand Down
10 changes: 1 addition & 9 deletions tests/test_automation/github-actions/ci/run_step.sh
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,7 @@ case "$1" in
test)

# Run only deterministic tests (reasonable for CI) by default
case "${GH_JOBNAME}" in
*"macOS-GCC16"*"-Real"*)
TEST_LABEL="-L deterministic -E deterministic-unit_test_estimators"
# estimator test bus error on mac only
;;
*)
TEST_LABEL="-L deterministic"
;;
esac
TEST_LABEL="-L deterministic"

cd ${GITHUB_WORKSPACE}/../qmcpack-build

Expand Down
Loading