QMCPACK
VariableSet Struct Reference

class to handle a set of variables that can be modified during optimizations More...

+ Collaboration diagram for VariableSet:

Public Types

using real_type = qmcplusplus::QMCTraits::RealType
 
using pair_type = std::pair< std::string, real_type >
 
using index_pair_type = std::pair< std::string, int >
 
using iterator = std::vector< pair_type >::iterator
 
using const_iterator = std::vector< pair_type >::const_iterator
 
using size_type = std::vector< pair_type >::size_type
 

Public Member Functions

 VariableSet ()
 default constructor More...
 
virtual ~VariableSet ()=default
 viturval destructor for safety More...
 
bool is_optimizable () const
 if any of Index value is not zero, return true More...
 
int size_of_active () const
 return the number of active variables More...
 
const_iterator begin () const
 return the first const_iterator More...
 
const_iterator end () const
 return the last const_iterator More...
 
iterator begin ()
 return the first iterator More...
 
iterator end ()
 return the last iterator More...
 
size_type size () const
 return the size More...
 
int where (int i) const
 return the locator of the i-th Index More...
 
iterator find (const std::string &vname)
 return the iterator of a named parameter More...
 
int getIndex (const std::string &vname) const
 return the Index vaule for the named parameter More...
 
int getLoc (const std::string &vname) const
 
void insert (const std::string &vname, real_type v, bool enable=true, int type=OTHER_P)
 
void setParameterType (int type)
 
void getParameterTypeList (std::vector< int > &types) const
 
real_typeoperator[] (const std::string &vname)
 equivalent to std::map<std::string,T>[string] operator More...
 
const std::string & name (int i) const
 return the name of i-th variable More...
 
real_type operator[] (int i) const
 return the i-th value More...
 
real_typeoperator[] (int i)
 assign the i-th value More...
 
int getType (int i) const
 get the i-th parameter's type More...
 
bool recompute (int i) const
 
int & recompute (int i)
 
void setComputed ()
 
void setRecompute ()
 
void clear ()
 clear the variable set More...
 
void insertFrom (const VariableSet &input)
 insert a VariableSet to the list More...
 
void insertFromSum (const VariableSet &input_1, const VariableSet &input_2)
 sum together the values of the optimizable parameter values in two VariableSet objects, and set this object's values to equal them. More...
 
void insertFromDiff (const VariableSet &input_1, const VariableSet &input_2)
 take the difference (input_1-input_2) of values of the optimizable parameter values in two VariableSet objects, and set this object's values to equal them. More...
 
template<typename ForwardIterator >
void activate (ForwardIterator first, ForwardIterator last, bool reindex)
 activate variables for optimization More...
 
template<typename ForwardIterator >
void disable (ForwardIterator first, ForwardIterator last, bool reindex)
 deactivate variables for optimization More...
 
void resetIndex ()
 reset Index More...
 
void removeInactive ()
 remove inactive variables and trim the internal data More...
 
void getIndex (const VariableSet &selected)
 set the index table of this VariableSet More...
 
void setIndexDefault ()
 set default Indices, namely all the variables are active More...
 
void print (std::ostream &os, int leftPadSpaces=0, bool printHeader=false) const
 
void writeToHDF (const std::string &filename, qmcplusplus::hdf_archive &hout) const
 
void readFromHDF (const std::string &filename, qmcplusplus::hdf_archive &hin)
 Read variational parameters from an HDF file. More...
 

Public Attributes

int num_active_vars
 number of active variables More...
 
std::vector< int > Index
 store locator of the named variable More...
 
std::vector< pair_typeNameAndValue
 
std::vector< index_pair_typeParameterType
 
std::vector< index_pair_typeRecompute
 

Detailed Description

class to handle a set of variables that can be modified during optimizations

A serialized container of named variables.

Definition at line 49 of file VariableSet.h.

Member Typedef Documentation

◆ const_iterator

using const_iterator = std::vector<pair_type>::const_iterator

Definition at line 56 of file VariableSet.h.

◆ index_pair_type

using index_pair_type = std::pair<std::string, int>

Definition at line 54 of file VariableSet.h.

◆ iterator

using iterator = std::vector<pair_type>::iterator

Definition at line 55 of file VariableSet.h.

◆ pair_type

using pair_type = std::pair<std::string, real_type>

Definition at line 53 of file VariableSet.h.

◆ real_type

Definition at line 51 of file VariableSet.h.

◆ size_type

using size_type = std::vector<pair_type>::size_type

Definition at line 57 of file VariableSet.h.

Constructor & Destructor Documentation

◆ VariableSet()

VariableSet ( )
inline

default constructor

Definition at line 71 of file VariableSet.h.

71 : num_active_vars(0) {}
int num_active_vars
number of active variables
Definition: VariableSet.h:60

◆ ~VariableSet()

virtual ~VariableSet ( )
virtualdefault

viturval destructor for safety

Member Function Documentation

◆ activate()

void activate ( ForwardIterator  first,
ForwardIterator  last,
bool  reindex 
)
inline

activate variables for optimization

Parameters
firstiterator of the first name
lastiterator of the last name
reindexif true, Index is updated

The status of a variable that is not included in the [first,last) remains the same.

Definition at line 264 of file VariableSet.h.

References VariableSet::find(), VariableSet::Index, VariableSet::NameAndValue, VariableSet::num_active_vars, VariableSet::removeInactive(), and VariableSet::resetIndex().

Referenced by QMCCostFunctionBase::put(), and optimize::TEST_CASE().

265  {
266  while (first != last)
267  {
268  iterator loc = find(*first++);
269  if (loc != NameAndValue.end())
270  {
271  int i = loc - NameAndValue.begin();
272  if (Index[i] < 0)
273  Index[i] = num_active_vars++;
274  }
275  }
276  if (reindex)
277  {
278  removeInactive();
279  resetIndex();
280  }
281  }
iterator find(const std::string &vname)
return the iterator of a named parameter
Definition: VariableSet.h:98
std::vector< pair_type >::iterator iterator
Definition: VariableSet.h:55
std::vector< int > Index
store locator of the named variable
Definition: VariableSet.h:65
void resetIndex()
reset Index
std::vector< pair_type > NameAndValue
Definition: VariableSet.h:66
void removeInactive()
remove inactive variables and trim the internal data
int num_active_vars
number of active variables
Definition: VariableSet.h:60

◆ begin() [1/2]

const_iterator begin ( ) const
inline

return the first const_iterator

Definition at line 80 of file VariableSet.h.

References VariableSet::NameAndValue.

Referenced by QMCCostFunctionBase::addCJParams(), QMCCostFunctionBase::addCoefficients(), and QMCCostFunctionBase::printCJParams().

80 { return NameAndValue.begin(); }
std::vector< pair_type > NameAndValue
Definition: VariableSet.h:66

◆ begin() [2/2]

iterator begin ( )
inline

return the first iterator

Definition at line 84 of file VariableSet.h.

References VariableSet::NameAndValue.

84 { return NameAndValue.begin(); }
std::vector< pair_type > NameAndValue
Definition: VariableSet.h:66

◆ clear()

◆ disable()

void disable ( ForwardIterator  first,
ForwardIterator  last,
bool  reindex 
)
inline

deactivate variables for optimization

Parameters
firstiterator of the first name
lastiterator of the last name
reindexif true, the variales are removed and Index is updated

Definition at line 289 of file VariableSet.h.

References VariableSet::find(), VariableSet::Index, VariableSet::NameAndValue, VariableSet::removeInactive(), and VariableSet::resetIndex().

Referenced by QMCCostFunctionBase::put().

290  {
291  while (first != last)
292  {
293  int loc = find(*first++) - NameAndValue.begin();
294  if (loc < NameAndValue.size())
295  Index[loc] = -1;
296  }
297  if (reindex)
298  {
299  removeInactive();
300  resetIndex();
301  }
302  }
iterator find(const std::string &vname)
return the iterator of a named parameter
Definition: VariableSet.h:98
std::vector< int > Index
store locator of the named variable
Definition: VariableSet.h:65
void resetIndex()
reset Index
std::vector< pair_type > NameAndValue
Definition: VariableSet.h:66
void removeInactive()
remove inactive variables and trim the internal data

◆ end() [1/2]

◆ end() [2/2]

iterator end ( )
inline

return the last iterator

Definition at line 86 of file VariableSet.h.

References VariableSet::NameAndValue.

86 { return NameAndValue.end(); }
std::vector< pair_type > NameAndValue
Definition: VariableSet.h:66

◆ find()

iterator find ( const std::string &  vname)
inline

return the iterator of a named parameter

Parameters
vnamename of a parameter
Returns
the locator of vname

If vname is not found among the Names, return NameAndValue.end() so that ::end() member function can be used to validate the iterator.

Definition at line 98 of file VariableSet.h.

References VariableSet::NameAndValue.

Referenced by VariableSet::activate(), QMCCostFunctionBase::addCJParams(), VariableSet::disable(), VariableSet::insert(), VariableSet::insertFrom(), VariableSet::insertFromDiff(), VariableSet::insertFromSum(), VariableSet::operator[](), VariableSet::readFromHDF(), optimize::TEST_CASE(), and QMCCostFunctionBase::updateXmlNodes().

99  {
100  return std::find_if(NameAndValue.begin(), NameAndValue.end(),
101  [&vname](const auto& value) { return value.first == vname; });
102  }
std::vector< pair_type > NameAndValue
Definition: VariableSet.h:66

◆ getIndex() [1/2]

int getIndex ( const std::string &  vname) const

return the Index vaule for the named parameter

Parameters
vnamename of the variable

If vname is not found in this variables, return -1;

Definition at line 177 of file VariableSet.cpp.

References VariableSet::Index, and VariableSet::NameAndValue.

Referenced by ExampleHeComponent::checkOutVariables(), SlaterDet::checkOutVariables(), CountingJastrow< RegionType >::checkOutVariables(), CountingGaussian::checkOutVariables(), Backflow_ee_kSpace::checkOutVariables(), kSpaceJastrow::checkOutVariables(), RotatedSPOs::checkOutVariables(), PadeFunctor< T >::checkOutVariables(), UserFunctor< T >::checkOutVariables(), JeeIOrbitalSoA< FT >::checkOutVariables(), J1Spin< FT >::checkOutVariables(), J1OrbitalSoA< FT >::checkOutVariables(), Pade2ndOrderFunctor< T >::checkOutVariables(), ShortRangeCuspFunctor< T >::checkOutVariables(), BsplineFunctor< REAL >::checkOutVariables(), PadeTwo2ndOrderFunctor< T >::checkOutVariables(), ScaledPadeFunctor< T >::checkOutVariables(), PolynomialFunctor3D::checkOutVariables(), CountingJastrow< RegionType >::evaluateDerivatives(), OptimizableFunctorBase::getIndex(), VariableSet::getIndex(), QMCCostFunctionBase::put(), CountingJastrow< RegionType >::resetParametersExclusive(), and optimize::TEST_CASE().

178 {
179  int loc = 0;
180  while (loc != NameAndValue.size())
181  {
182  if (NameAndValue[loc].first == vname)
183  return Index[loc];
184  ++loc;
185  }
186  return -1;
187 }
std::vector< int > Index
store locator of the named variable
Definition: VariableSet.h:65
std::vector< pair_type > NameAndValue
Definition: VariableSet.h:66

◆ getIndex() [2/2]

void getIndex ( const VariableSet selected)

set the index table of this VariableSet

Parameters
selectedinput variables

This VariableSet is a subset of selected.

Definition at line 166 of file VariableSet.cpp.

References VariableSet::getIndex(), VariableSet::Index, VariableSet::NameAndValue, and VariableSet::num_active_vars.

167 {
168  num_active_vars = 0;
169  for (int i = 0; i < NameAndValue.size(); ++i)
170  {
171  Index[i] = selected.getIndex(NameAndValue[i].first);
172  if (Index[i] >= 0)
173  num_active_vars++;
174  }
175 }
std::vector< int > Index
store locator of the named variable
Definition: VariableSet.h:65
std::vector< pair_type > NameAndValue
Definition: VariableSet.h:66
int num_active_vars
number of active variables
Definition: VariableSet.h:60

◆ getLoc()

int getLoc ( const std::string &  vname) const
inline

Definition at line 121 of file VariableSet.h.

References VariableSet::NameAndValue.

Referenced by CountingGaussian::resetParameters(), and CountingJastrow< RegionType >::resetParametersExclusive().

122  {
123  int loc = 0;
124  while (loc != NameAndValue.size())
125  {
126  if (NameAndValue[loc].first == vname)
127  return loc;
128  ++loc;
129  }
130  return -1;
131  }
std::vector< pair_type > NameAndValue
Definition: VariableSet.h:66

◆ getParameterTypeList()

void getParameterTypeList ( std::vector< int > &  types) const
inline

Definition at line 159 of file VariableSet.h.

References VariableSet::ParameterType.

Referenced by QMCCostFunctionBase::getParameterTypes().

160  {
161  auto ptit(ParameterType.begin()), ptend(ParameterType.end());
162  types.resize(ptend - ptit);
163  auto tit(types.begin());
164  while (ptit != ptend)
165  (*tit++) = (*ptit++).second;
166  }
std::vector< index_pair_type > ParameterType
Definition: VariableSet.h:67

◆ getType()

int getType ( int  i) const
inline

get the i-th parameter's type

Parameters
iindex

Definition at line 204 of file VariableSet.h.

References VariableSet::ParameterType.

Referenced by QMCCostFunctionBase::getType(), and DescentEngine::setupUpdate().

204 { return ParameterType[i].second; }
std::vector< index_pair_type > ParameterType
Definition: VariableSet.h:67

◆ insert()

void insert ( const std::string &  vname,
real_type  v,
bool  enable = true,
int  type = OTHER_P 
)
inline

Definition at line 133 of file VariableSet.h.

References VariableSet::find(), VariableSet::Index, VariableSet::NameAndValue, VariableSet::ParameterType, and VariableSet::Recompute.

Referenced by FakeOptimizableObject::FakeOptimizableObject(), CountingGaussian::initialize(), CountingJastrow< RegionType >::initialize(), BsplineFunctor< REAL >::initialize(), kSpaceJastrow::kSpaceJastrow(), ExampleHeComponent::put(), PadeFunctor< T >::put(), UserFunctor< T >::put(), BsplineFunctor< REAL >::put(), ShortRangeCuspFunctor< T >::put(), Pade2ndOrderFunctor< T >::put(), PadeTwo2ndOrderFunctor< T >::put(), PolynomialFunctor3D::put(), FakeOptimizableObject::readVariationalParameters(), LinearMethodTestSupport::set_samples_and_param(), ShortRangeCuspFunctor< T >::set_variable_from_xml(), optimize::TEST_CASE(), and qmcplusplus::TEST_CASE().

134  {
135  iterator loc = find(vname);
136  int ind_loc = loc - NameAndValue.begin();
137  if (loc == NameAndValue.end()) // && enable==true)
138  {
139  Index.push_back(ind_loc);
140  NameAndValue.push_back(pair_type(vname, v));
141  ParameterType.push_back(index_pair_type(vname, type));
142  Recompute.push_back(index_pair_type(vname, 1));
143  }
144  //disable it if enable == false
145  if (!enable)
146  Index[ind_loc] = -1;
147  }
iterator find(const std::string &vname)
return the iterator of a named parameter
Definition: VariableSet.h:98
std::vector< pair_type >::iterator iterator
Definition: VariableSet.h:55
std::vector< int > Index
store locator of the named variable
Definition: VariableSet.h:65
std::pair< std::string, int > index_pair_type
Definition: VariableSet.h:54
std::pair< std::string, real_type > pair_type
Definition: VariableSet.h:53
std::vector< pair_type > NameAndValue
Definition: VariableSet.h:66
std::vector< index_pair_type > ParameterType
Definition: VariableSet.h:67
std::vector< index_pair_type > Recompute
Definition: VariableSet.h:68

◆ insertFrom()

void insertFrom ( const VariableSet input)

insert a VariableSet to the list

Parameters
inputvariables

Definition at line 37 of file VariableSet.cpp.

References VariableSet::find(), VariableSet::Index, VariableSet::NameAndValue, VariableSet::num_active_vars, VariableSet::ParameterType, and VariableSet::Recompute.

Referenced by CountingGaussian::checkInVariables(), Backflow_ee_kSpace::checkInVariables(), FakeOptimizableObject::checkInVariablesExclusive(), ExampleHeComponent::checkInVariablesExclusive(), MultiSlaterDetTableMethod::checkInVariablesExclusive(), kSpaceJastrow::checkInVariablesExclusive(), RotatedSPOs::checkInVariablesExclusive(), PadeFunctor< T >::checkInVariablesExclusive(), UserFunctor< T >::checkInVariablesExclusive(), Pade2ndOrderFunctor< T >::checkInVariablesExclusive(), ShortRangeCuspFunctor< T >::checkInVariablesExclusive(), BsplineFunctor< REAL >::checkInVariablesExclusive(), PadeTwo2ndOrderFunctor< T >::checkInVariablesExclusive(), ScaledPadeFunctor< T >::checkInVariablesExclusive(), PolynomialFunctor3D::checkInVariablesExclusive(), SlaterDet::checkOutVariables(), JeeIOrbitalSoA< FT >::checkOutVariables(), J1Spin< FT >::checkOutVariables(), J1OrbitalSoA< FT >::checkOutVariables(), and qmcplusplus::TEST_CASE().

38 {
39  for (int i = 0; i < input.size(); ++i)
40  {
41  iterator loc = find(input.name(i));
42  if (loc == NameAndValue.end())
43  {
44  Index.push_back(input.Index[i]);
45  NameAndValue.push_back(input.NameAndValue[i]);
46  ParameterType.push_back(input.ParameterType[i]);
47  Recompute.push_back(input.Recompute[i]);
48  }
49  else
50  (*loc).second = input.NameAndValue[i].second;
51  }
52  num_active_vars = input.num_active_vars;
53 }
iterator find(const std::string &vname)
return the iterator of a named parameter
Definition: VariableSet.h:98
std::vector< pair_type >::iterator iterator
Definition: VariableSet.h:55
std::vector< int > Index
store locator of the named variable
Definition: VariableSet.h:65
std::vector< pair_type > NameAndValue
Definition: VariableSet.h:66
std::vector< index_pair_type > ParameterType
Definition: VariableSet.h:67
testing::ValidSpinDensityInput input
std::vector< index_pair_type > Recompute
Definition: VariableSet.h:68
int num_active_vars
number of active variables
Definition: VariableSet.h:60

◆ insertFromDiff()

void insertFromDiff ( const VariableSet input_1,
const VariableSet input_2 
)

take the difference (input_1-input_2) of values of the optimizable parameter values in two VariableSet objects, and set this object's values to equal them.

Parameters
firstset of input variables
secondset of input variables

Definition at line 95 of file VariableSet.cpp.

References VariableSet::find(), VariableSet::Index, VariableSet::name(), VariableSet::NameAndValue, VariableSet::num_active_vars, VariableSet::ParameterType, VariableSet::Recompute, and VariableSet::size().

96 {
97  real_type diff_val;
98  std::string vname;
99 
100  // Check that objects to be subtracted have the same number of active
101  // variables.
102  if (input_1.num_active_vars != input_2.num_active_vars)
103  throw std::runtime_error("Inconsistent number of parameters in two provided "
104  "variable sets.");
105 
106  for (int i = 0; i < input_1.size(); ++i)
107  {
108  // Check that each of the equivalent variables in both VariableSet objects
109  // have the same name - otherwise we certainly shouldn't be subtracting them.
110  if (input_1.NameAndValue[i].first != input_2.NameAndValue[i].first)
111  throw std::runtime_error("Inconsistent parameters exist in the two provided "
112  "variable sets.");
113 
114  diff_val = input_1.NameAndValue[i].second - input_2.NameAndValue[i].second;
115 
116  iterator loc = find(input_1.name(i));
117  if (loc == NameAndValue.end())
118  {
119  Index.push_back(input_1.Index[i]);
120  ParameterType.push_back(input_1.ParameterType[i]);
121  Recompute.push_back(input_1.Recompute[i]);
122 
123  // We can reuse the above values, which aren't subtracted between the
124  // objects, but the parameter values themselves need to use the
125  // subtracted values.
126  vname = input_1.NameAndValue[i].first;
127  NameAndValue.push_back(pair_type(vname, diff_val));
128  }
129  else
130  (*loc).second = diff_val;
131  }
132  num_active_vars = input_1.num_active_vars;
133 }
iterator find(const std::string &vname)
return the iterator of a named parameter
Definition: VariableSet.h:98
std::vector< pair_type >::iterator iterator
Definition: VariableSet.h:55
std::vector< int > Index
store locator of the named variable
Definition: VariableSet.h:65
std::pair< std::string, real_type > pair_type
Definition: VariableSet.h:53
OHMMS_PRECISION real_type
std::vector< pair_type > NameAndValue
Definition: VariableSet.h:66
std::vector< index_pair_type > ParameterType
Definition: VariableSet.h:67
std::vector< index_pair_type > Recompute
Definition: VariableSet.h:68
int num_active_vars
number of active variables
Definition: VariableSet.h:60

◆ insertFromSum()

void insertFromSum ( const VariableSet input_1,
const VariableSet input_2 
)

sum together the values of the optimizable parameter values in two VariableSet objects, and set this object's values to equal them.

Parameters
firstset of input variables
secondset of input variables

Definition at line 55 of file VariableSet.cpp.

References VariableSet::find(), VariableSet::Index, VariableSet::name(), VariableSet::NameAndValue, VariableSet::num_active_vars, VariableSet::ParameterType, VariableSet::Recompute, and VariableSet::size().

56 {
57  real_type sum_val;
58  std::string vname;
59 
60  // Check that objects to be summed together have the same number of active
61  // variables.
62  if (input_1.num_active_vars != input_2.num_active_vars)
63  throw std::runtime_error("Inconsistent number of parameters in two provided "
64  "variable sets.");
65 
66  for (int i = 0; i < input_1.size(); ++i)
67  {
68  // Check that each of the equivalent variables in both VariableSet objects
69  // have the same name - otherwise we certainly shouldn't be adding them.
70  if (input_1.NameAndValue[i].first != input_2.NameAndValue[i].first)
71  throw std::runtime_error("Inconsistent parameters exist in the two provided "
72  "variable sets.");
73 
74  sum_val = input_1.NameAndValue[i].second + input_2.NameAndValue[i].second;
75 
76  iterator loc = find(input_1.name(i));
77  if (loc == NameAndValue.end())
78  {
79  Index.push_back(input_1.Index[i]);
80  ParameterType.push_back(input_1.ParameterType[i]);
81  Recompute.push_back(input_1.Recompute[i]);
82 
83  // We can reuse the above values, which aren't summed between the
84  // objects, but the parameter values themselves need to use the summed
85  // values.
86  vname = input_1.NameAndValue[i].first;
87  NameAndValue.push_back(pair_type(vname, sum_val));
88  }
89  else
90  (*loc).second = sum_val;
91  }
92  num_active_vars = input_1.num_active_vars;
93 }
iterator find(const std::string &vname)
return the iterator of a named parameter
Definition: VariableSet.h:98
std::vector< pair_type >::iterator iterator
Definition: VariableSet.h:55
std::vector< int > Index
store locator of the named variable
Definition: VariableSet.h:65
std::pair< std::string, real_type > pair_type
Definition: VariableSet.h:53
OHMMS_PRECISION real_type
std::vector< pair_type > NameAndValue
Definition: VariableSet.h:66
std::vector< index_pair_type > ParameterType
Definition: VariableSet.h:67
std::vector< index_pair_type > Recompute
Definition: VariableSet.h:68
int num_active_vars
number of active variables
Definition: VariableSet.h:60

◆ is_optimizable()

bool is_optimizable ( ) const
inline

if any of Index value is not zero, return true

Definition at line 76 of file VariableSet.h.

References VariableSet::num_active_vars.

Referenced by optimize::TEST_CASE().

76 { return num_active_vars > 0; }
int num_active_vars
number of active variables
Definition: VariableSet.h:60

◆ name()

◆ operator[]() [1/3]

real_type& operator[] ( const std::string &  vname)
inline

equivalent to std::map<std::string,T>[string] operator

Definition at line 171 of file VariableSet.h.

References VariableSet::find(), VariableSet::Index, VariableSet::NameAndValue, VariableSet::ParameterType, and VariableSet::Recompute.

172  {
173  iterator loc = find(vname);
174  if (loc == NameAndValue.end())
175  {
176  Index.push_back(-1);
177  NameAndValue.push_back(pair_type(vname, 0));
178  ParameterType.push_back(index_pair_type(vname, 0));
179  Recompute.push_back(index_pair_type(vname, 1));
180  return NameAndValue.back().second;
181  }
182  return (*loc).second;
183  }
iterator find(const std::string &vname)
return the iterator of a named parameter
Definition: VariableSet.h:98
std::vector< pair_type >::iterator iterator
Definition: VariableSet.h:55
std::vector< int > Index
store locator of the named variable
Definition: VariableSet.h:65
std::pair< std::string, int > index_pair_type
Definition: VariableSet.h:54
std::pair< std::string, real_type > pair_type
Definition: VariableSet.h:53
std::vector< pair_type > NameAndValue
Definition: VariableSet.h:66
std::vector< index_pair_type > ParameterType
Definition: VariableSet.h:67
std::vector< index_pair_type > Recompute
Definition: VariableSet.h:68

◆ operator[]() [2/3]

real_type operator[] ( int  i) const
inline

return the i-th value

Parameters
iindex

Definition at line 194 of file VariableSet.h.

References VariableSet::NameAndValue.

194 { return NameAndValue[i].second; }
std::vector< pair_type > NameAndValue
Definition: VariableSet.h:66

◆ operator[]() [3/3]

real_type& operator[] ( int  i)
inline

assign the i-th value

Parameters
iindex

Definition at line 199 of file VariableSet.h.

References VariableSet::NameAndValue.

199 { return NameAndValue[i].second; }
std::vector< pair_type > NameAndValue
Definition: VariableSet.h:66

◆ print()

void print ( std::ostream &  os,
int  leftPadSpaces = 0,
bool  printHeader = false 
) const

Definition at line 195 of file VariableSet.cpp.

References VariableSet::Index, VariableSet::NameAndValue, VariableSet::ParameterType, and VariableSet::Recompute.

Referenced by RotatedSPOs::buildOptVariables(), J1Spin< FT >::checkOutVariables(), BsplineFunctor< REAL >::initialize(), PadeFunctor< T >::put(), BsplineFunctor< REAL >::put(), Pade2ndOrderFunctor< T >::put(), PadeTwo2ndOrderFunctor< T >::put(), PolynomialFunctor3D::put(), QMCCostFunctionBase::Report(), QMCCostFunctionBase::reportParameters(), Backflow_ee_kSpace::reportStatus(), CountingJastrow< RegionType >::reportStatus(), CountingGaussian::reportStatus(), BsplineFunctor< REAL >::reportStatus(), WaveFunctionTester::runDerivCloneTest(), WaveFunctionTester::runDerivNLPPTest(), WaveFunctionTester::runDerivTest(), optimize::TEST_CASE(), BackflowTransformation::testDeriv(), and SlaterDetWithBackflow::testDerivGL().

196 {
197  std::string pad_str = std::string(leftPadSpaces, ' ');
198  int max_name_len = 0;
199  if (NameAndValue.size() > 0)
200  max_name_len =
201  std::max_element(NameAndValue.begin(), NameAndValue.end(), [](const pair_type& e1, const pair_type& e2) {
202  return e1.first.length() < e2.first.length();
203  })->first.length();
204 
205  int max_value_len = 28; // 6 for the precision and 7 for minus sign, leading value, period, and exponent.
206  int max_type_len = 1;
207  int max_recompute_len = 1;
208  int max_use_len = 3;
209  int max_index_len = 1;
210  if (printHeader)
211  {
212  max_name_len = std::max(max_name_len, 4); // size of "Name" header
213  max_type_len = 4;
214  max_recompute_len = 9;
215  max_index_len = 5;
216  os << pad_str << setw(max_name_len) << "Name"
217  << " " << setw(max_value_len) << "Value"
218  << " " << setw(max_type_len) << "Type"
219  << " " << setw(max_recompute_len) << "Recompute"
220  << " " << setw(max_use_len) << "Use"
221  << " " << setw(max_index_len) << "Index" << std::endl;
222  os << pad_str << std::setfill('-') << setw(max_name_len) << ""
223  << " " << setw(max_value_len) << ""
224  << " " << setw(max_type_len) << ""
225  << " " << setw(max_recompute_len) << ""
226  << " " << setw(max_use_len) << ""
227  << " " << setw(max_index_len) << "" << std::endl;
228  os << std::setfill(' ');
229  }
230 
231  for (int i = 0; i < NameAndValue.size(); ++i)
232  {
233  os << pad_str << setw(max_name_len) << NameAndValue[i].first << " " << std::setprecision(6) << std::scientific
234  << setw(max_value_len) << NameAndValue[i].second << " " << setw(max_type_len) << ParameterType[i].second << " "
235  << setw(max_recompute_len) << Recompute[i].second << " ";
236 
237  os << std::defaultfloat;
238 
239  if (Index[i] < 0)
240  os << setw(max_use_len) << "OFF" << std::endl;
241  else
242  os << setw(max_use_len) << "ON"
243  << " " << setw(max_index_len) << Index[i] << std::endl;
244  }
245 }
std::vector< int > Index
store locator of the named variable
Definition: VariableSet.h:65
std::pair< std::string, real_type > pair_type
Definition: VariableSet.h:53
std::vector< pair_type > NameAndValue
Definition: VariableSet.h:66
std::vector< index_pair_type > ParameterType
Definition: VariableSet.h:67
std::vector< index_pair_type > Recompute
Definition: VariableSet.h:68

◆ readFromHDF()

void readFromHDF ( const std::string &  filename,
qmcplusplus::hdf_archive hin 
)

Read variational parameters from an HDF file.

This assumes VariableSet is already set up.

Definition at line 275 of file VariableSet.cpp.

References VariableSet::end(), VariableSet::find(), hdf_archive::open(), hdf_archive::pop(), hdf_archive::push(), and hdf_archive::read().

Referenced by WaveFunctionFactory::buildTWF(), qmcplusplus::TEST_CASE(), and optimize::TEST_CASE().

276 {
277  if (!hin.open(filename, H5F_ACC_RDONLY))
278  {
279  std::ostringstream err_msg;
280  err_msg << "Unable to open VP file: " << filename;
281  throw std::runtime_error(err_msg.str());
282  }
283 
284  try
285  {
286  hin.push("name_value_lists", false);
287  }
288  catch (std::runtime_error&)
289  {
290  std::ostringstream err_msg;
291  err_msg << "The group name_value_lists in not present in file: " << filename;
292  throw std::runtime_error(err_msg.str());
293  }
294 
295  std::vector<qmcplusplus::QMCTraits::RealType> param_values;
296  hin.read(param_values, "parameter_values");
297 
298  std::vector<std::string> param_names;
299  hin.read(param_names, "parameter_names");
300 
301  for (int i = 0; i < param_names.size(); i++)
302  {
303  std::string& vp_name = param_names[i];
304  // Find and set values by name.
305  // Values that are not present do not get added.
306  if (find(vp_name) != end())
307  (*this)[vp_name] = param_values[i];
308  }
309 
310  hin.pop();
311 }
iterator find(const std::string &vname)
return the iterator of a named parameter
Definition: VariableSet.h:98
bool open(const std::filesystem::path &fname, unsigned flags=H5F_ACC_RDWR)
open a file
const_iterator end() const
return the last const_iterator
Definition: VariableSet.h:82
void push(const std::string &gname, bool createit=true)
push a group to the group stack
void read(T &data, const std::string &aname)
read the data from the group aname and check status runtime error is issued on I/O error ...
Definition: hdf_archive.h:306

◆ recompute() [1/2]

◆ recompute() [2/2]

int& recompute ( int  i)
inline

Definition at line 208 of file VariableSet.h.

References VariableSet::Recompute.

208 { return Recompute[i].second; }
std::vector< index_pair_type > Recompute
Definition: VariableSet.h:68

◆ removeInactive()

void removeInactive ( )

remove inactive variables and trim the internal data

Definition at line 135 of file VariableSet.cpp.

References VariableSet::Index, VariableSet::NameAndValue, VariableSet::num_active_vars, VariableSet::ParameterType, and VariableSet::Recompute.

Referenced by VariableSet::activate(), VariableSet::disable(), and qmcplusplus::TEST_CASE().

136 {
137  std::vector<int> valid(Index);
138  std::vector<pair_type> acopy(NameAndValue);
139  std::vector<index_pair_type> bcopy(Recompute), ccopy(ParameterType);
140  num_active_vars = 0;
141  Index.clear();
142  NameAndValue.clear();
143  Recompute.clear();
144  ParameterType.clear();
145  for (int i = 0; i < valid.size(); ++i)
146  {
147  if (valid[i] > -1)
148  {
149  Index.push_back(num_active_vars++);
150  NameAndValue.push_back(acopy[i]);
151  Recompute.push_back(bcopy[i]);
152  ParameterType.push_back(ccopy[i]);
153  }
154  }
155 }
std::vector< int > Index
store locator of the named variable
Definition: VariableSet.h:65
std::vector< pair_type > NameAndValue
Definition: VariableSet.h:66
std::vector< index_pair_type > ParameterType
Definition: VariableSet.h:67
std::vector< index_pair_type > Recompute
Definition: VariableSet.h:68
int num_active_vars
number of active variables
Definition: VariableSet.h:60

◆ resetIndex()

void resetIndex ( )

◆ setComputed()

void setComputed ( )
inline

Definition at line 210 of file VariableSet.h.

References optimize::LOGLINEAR_K, optimize::LOGLINEAR_P, VariableSet::ParameterType, VariableSet::Recompute, and qmcplusplus::Units::second.

Referenced by QMCCostFunction::checkConfigurations(), and QMCCostFunctionBatched::checkConfigurations().

211  {
212  for (int i = 0; i < Recompute.size(); i++)
213  {
214  if (ParameterType[i].second == LOGLINEAR_P)
215  Recompute[i].second = 0;
216  else if (ParameterType[i].second == LOGLINEAR_K)
217  Recompute[i].second = 0;
218  else
219  Recompute[i].second = 1;
220  }
221  }
std::vector< index_pair_type > ParameterType
Definition: VariableSet.h:67
std::vector< index_pair_type > Recompute
Definition: VariableSet.h:68

◆ setIndexDefault()

void setIndexDefault ( )

set default Indices, namely all the variables are active

Definition at line 189 of file VariableSet.cpp.

References VariableSet::Index.

Referenced by BsplineFunctor< REAL >::checkInVariablesExclusive(), and PolynomialFunctor3D::checkInVariablesExclusive().

190 {
191  for (int i = 0; i < Index.size(); ++i)
192  Index[i] = i;
193 }
std::vector< int > Index
store locator of the named variable
Definition: VariableSet.h:65

◆ setParameterType()

void setParameterType ( int  type)
inline

Definition at line 149 of file VariableSet.h.

References VariableSet::ParameterType.

Referenced by BackflowBuilder::makeLongRange_twoBody().

150  {
151  std::vector<index_pair_type>::iterator PTit(ParameterType.begin()), PTend(ParameterType.end());
152  while (PTit != PTend)
153  {
154  (*PTit).second = type;
155  PTit++;
156  }
157  }
std::vector< index_pair_type > ParameterType
Definition: VariableSet.h:67

◆ setRecompute()

void setRecompute ( )
inline

Definition at line 223 of file VariableSet.h.

References VariableSet::Recompute, and qmcplusplus::Units::second.

224  {
225  for (int i = 0; i < Recompute.size(); i++)
226  Recompute[i].second = 1;
227  }
std::vector< index_pair_type > Recompute
Definition: VariableSet.h:68

◆ size()

size_type size ( void  ) const
inline

return the size

Definition at line 88 of file VariableSet.h.

References VariableSet::NameAndValue.

Referenced by RotatedSPOs::buildOptVariables(), RotatedSPOs::checkInVariablesExclusive(), JeeIOrbitalSoA< FT >::checkOutVariables(), J1Spin< FT >::checkOutVariables(), J1OrbitalSoA< FT >::checkOutVariables(), RotatedSPOs::evaluateDerivatives(), kSpaceJastrow::evaluateDerivatives(), J1Spin< FT >::evaluateDerivatives(), SlaterDet::evaluateDerivatives(), J1OrbitalSoA< FT >::evaluateDerivatives(), CountingGaussianRegion::evaluateDerivatives(), CountingJastrow< RegionType >::evaluateDerivatives(), JeeIOrbitalSoA< FT >::evaluateDerivatives(), RotatedSPOs::evaluateDerivativesWF(), J1Spin< FT >::evaluateDerivativesWF(), SlaterDet::evaluateDerivativesWF(), J1OrbitalSoA< FT >::evaluateDerivativesWF(), JeeIOrbitalSoA< FT >::evaluateDerivativesWF(), RotatedSPOs::evaluateDerivRatios(), J1OrbitalSoA< FT >::evaluateDerivRatios(), JeeIOrbitalSoA< FT >::evaluateDerivRatios(), CountingGaussianRegion::evaluateTempDerivatives(), QMCCostFunctionBase::getNumParams(), VariableSet::insertFromDiff(), VariableSet::insertFromSum(), QMCCostFunctionBase::put(), RotatedSPOs::readVariationalParameters(), QMCCostFunctionBase::Report(), QMCCostFunctionBase::reportParametersH5(), ExampleHeComponent::resetParametersExclusive(), CountingJastrow< RegionType >::resetParametersExclusive(), RotatedSPOs::resetParametersExclusive(), PadeFunctor< T >::resetParametersExclusive(), UserFunctor< T >::resetParametersExclusive(), ShortRangeCuspFunctor< T >::resetParametersExclusive(), PadeTwo2ndOrderFunctor< T >::resetParametersExclusive(), QMCCostFunction::resetPsi(), QMCCostFunctionBatched::resetPsi(), J1Spin< FT >::resizeWFOptVectors(), J1OrbitalSoA< FT >::resizeWFOptVectors(), JeeIOrbitalSoA< FT >::resizeWFOptVectors(), TwoBodyJastrow< FT >::resizeWFOptVectors(), WaveFunctionTester::runDerivCloneTest(), WaveFunctionTester::runDerivNLPPTest(), WaveFunctionTester::runDerivTest(), DescentEngine::setupUpdate(), qmcplusplus::TEST_CASE(), BackflowTransformation::testDeriv(), DiracDeterminantWithBackflow::testDerivFjj(), SlaterDetWithBackflow::testDerivGL(), DiracDeterminantWithBackflow::testDerivLi(), and RotatedSPOs::writeVariationalParameters().

88 { return NameAndValue.size(); }
std::vector< pair_type > NameAndValue
Definition: VariableSet.h:66

◆ size_of_active()

int size_of_active ( ) const
inline

return the number of active variables

Definition at line 78 of file VariableSet.h.

References VariableSet::num_active_vars.

Referenced by CountingJastrow< RegionType >::reportStatus(), optimize::TEST_CASE(), qmcplusplus::TEST_CASE(), qmcplusplus::test_LiH_msd(), and CountingGaussianRegion::total_num_derivs().

78 { return num_active_vars; }
int num_active_vars
number of active variables
Definition: VariableSet.h:60

◆ where()

int where ( int  i) const
inline

return the locator of the i-th Index

Definition at line 90 of file VariableSet.h.

References VariableSet::Index.

Referenced by RotatedSPOs::evaluateDerivatives(), kSpaceJastrow::evaluateDerivatives(), J1Spin< FT >::evaluateDerivatives(), SlaterDet::evaluateDerivatives(), J1OrbitalSoA< FT >::evaluateDerivatives(), JeeIOrbitalSoA< FT >::evaluateDerivatives(), RotatedSPOs::evaluateDerivativesWF(), J1Spin< FT >::evaluateDerivativesWF(), SlaterDet::evaluateDerivativesWF(), J1OrbitalSoA< FT >::evaluateDerivativesWF(), JeeIOrbitalSoA< FT >::evaluateDerivativesWF(), RotatedSPOs::evaluateDerivRatios(), J1OrbitalSoA< FT >::evaluateDerivRatios(), JeeIOrbitalSoA< FT >::evaluateDerivRatios(), Backflow_ee_kSpace::indexOffset(), BsplineFunctor< REAL >::isOptimizable(), Backflow_ee_kSpace::resetParameters(), ExampleHeComponent::resetParametersExclusive(), CountingJastrow< RegionType >::resetParametersExclusive(), kSpaceJastrow::resetParametersExclusive(), RotatedSPOs::resetParametersExclusive(), PadeFunctor< T >::resetParametersExclusive(), UserFunctor< T >::resetParametersExclusive(), Pade2ndOrderFunctor< T >::resetParametersExclusive(), ShortRangeCuspFunctor< T >::resetParametersExclusive(), BsplineFunctor< REAL >::resetParametersExclusive(), PadeTwo2ndOrderFunctor< T >::resetParametersExclusive(), PolynomialFunctor3D::resetParametersExclusive(), DescentEngine::setupUpdate(), RotatedSPOs::table_method_eval(), and RotatedSPOs::table_method_evalWF().

90 { return Index[i]; }
std::vector< int > Index
store locator of the named variable
Definition: VariableSet.h:65

◆ writeToHDF()

void writeToHDF ( const std::string &  filename,
qmcplusplus::hdf_archive hout 
) const

Definition at line 247 of file VariableSet.cpp.

References hdf_archive::create(), getDateAndTime(), VariableSet::NameAndValue, hdf_archive::pop(), hdf_archive::push(), and hdf_archive::write().

Referenced by QMCCostFunctionBase::reportParameters(), qmcplusplus::TEST_CASE(), and optimize::TEST_CASE().

248 {
249  hout.create(filename);
250 
251  // File Versioning
252  // 1.0.0 Initial file version
253  // 1.1.0 Files could have object-specific data from OptimizableObject::read/writeVariationalParameters
254  std::vector<int> vp_file_version{1, 1, 0};
255  hout.write(vp_file_version, "version");
256 
257  std::string timestamp(getDateAndTime("%Y-%m-%d %H:%M:%S %Z"));
258  hout.write(timestamp, "timestamp");
259 
260  hout.push("name_value_lists");
261 
262  std::vector<qmcplusplus::QMCTraits::RealType> param_values;
263  std::vector<std::string> param_names;
264  for (auto& pair_it : NameAndValue)
265  {
266  param_names.push_back(pair_it.first);
267  param_values.push_back(pair_it.second);
268  }
269 
270  hout.write(param_names, "parameter_names");
271  hout.write(param_values, "parameter_values");
272  hout.pop();
273 }
void write(T &data, const std::string &aname)
write the data to the group aname and check status runtime error is issued on I/O error ...
Definition: hdf_archive.h:259
string getDateAndTime()
Definition: sysutil.cpp:31
void push(const std::string &gname, bool createit=true)
push a group to the group stack
bool create(const std::filesystem::path &fname, unsigned flags=H5F_ACC_TRUNC)
create a file
std::vector< pair_type > NameAndValue
Definition: VariableSet.h:66

Member Data Documentation

◆ Index

◆ NameAndValue

◆ num_active_vars

◆ ParameterType

◆ Recompute


The documentation for this struct was generated from the following files: