39 vs.
insert(
"first", first_val);
40 std::vector<std::string> names{
"first"};
41 vs.
activate(names.begin(), names.end(),
true);
47 double first_val_real = 1.123456789;
48 CHECK(vs[0] == Approx(first_val_real));
51 vs.
print(o, 0,
false);
53 REQUIRE(o.str() ==
"first 1.123457e+00 0 1 ON 0\n");
55 std::ostringstream o2;
56 vs.
print(o2, 1,
true);
59 char formatted_output[] =
" Name Value Type Recompute Use Index\n" 60 " ----- ---------------------------- ---- --------- --- -----\n" 61 " first 1.123457e+00 0 1 ON 0\n";
64 REQUIRE(o2.str() == formatted_output);
74 vs.
insert(
"second", second_val);
75 vs.
insert(
"really_long_name", third_val);
76 std::vector<std::string> names{
"s",
"second",
"really_long_name"};
77 vs.
activate(names.begin(), names.end(),
true);
83 char formatted_output[] =
" Name Value Type Recompute Use Index\n" 84 "---------------- ---------------------------- ---- --------- --- -----\n" 85 " s 1.123457e+04 0 1 ON 0\n" 86 " second 2.567890e-04 0 1 ON 1\n" 87 "really_long_name -1.200000e+00 0 1 ON 2\n";
89 REQUIRE(o.str() == formatted_output);
92 TEST_CASE(
"VariableSet HDF output and input",
"[optimize]")
99 vs.
insert(
"second", second_val);
100 vs.
insert(
"really_really_really_long_name", third_val);
106 vs2.
insert(
"second", 0.0);
109 CHECK(vs2.
find(
"s")->second == Approx(first_val));
110 CHECK(vs2.
find(
"second")->second == Approx(second_val));
113 CHECK(vs2.
find(
"really_really_really_long_name") == vs2.
end());
iterator find(const std::string &vname)
return the iterator of a named parameter
void writeToHDF(const std::string &filename, qmcplusplus::hdf_archive &hout) const
bool is_optimizable() const
if any of Index value is not zero, return true
const_iterator end() const
return the last const_iterator
void readFromHDF(const std::string &filename, qmcplusplus::hdf_archive &hin)
Read variational parameters from an HDF file.
void activate(ForwardIterator first, ForwardIterator last, bool reindex)
activate variables for optimization
TEST_CASE("VariableSet empty", "[optimize]")
REQUIRE(std::filesystem::exists(filename))
void insert(const std::string &vname, real_type v, bool enable=true, int type=OTHER_P)
class to handle a set of variables that can be modified during optimizations
int size_of_active() const
return the number of active variables
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
std::vector< pair_type > NameAndValue
qmcplusplus::QMCTraits::RealType real_type
const std::string & name(int i) const
return the name of i-th variable
void print(std::ostream &os, int leftPadSpaces=0, bool printHeader=false) const
int getIndex(const std::string &vname) const
return the Index vaule for the named parameter