QMCPACK
FakeOptimizableObject Class Reference
+ Inheritance diagram for FakeOptimizableObject:
+ Collaboration diagram for FakeOptimizableObject:

Public Member Functions

 FakeOptimizableObject (const std::string &my_name, double var1=0.0, double var2=0.0)
 
void checkInVariablesExclusive (opt_variables_type &active) override
 check in variational parameters to the global list of parameters used by the optimizer. More...
 
void resetParametersExclusive (const opt_variables_type &active) override
 reset the parameters during optimizations. More...
 
void writeVariationalParameters (hdf_archive &hout) override
 Write the variational parameters for this object to the VP HDF file. More...
 
void readVariationalParameters (hdf_archive &hin) override
 Read the variational parameters for this object from the VP HDF file. More...
 
- Public Member Functions inherited from OptimizableObject
 OptimizableObject (const std::string &name)
 
const std::string & getName () const
 
bool isOptimized () const
 
virtual void reportStatus (std::ostream &os)
 print the state, e.g., optimizables More...
 
void setOptimization (bool state)
 

Public Attributes

double extra_data
 
opt_variables_type myVars
 

Detailed Description

Definition at line 22 of file test_OptimizableObject.cpp.

Constructor & Destructor Documentation

◆ FakeOptimizableObject()

FakeOptimizableObject ( const std::string &  my_name,
double  var1 = 0.0,
double  var2 = 0.0 
)
inline

Definition at line 25 of file test_OptimizableObject.cpp.

References VariableSet::insert(), and FakeOptimizableObject::myVars.

25  : OptimizableObject(my_name)
26  {
27  myVars.insert("var1", var1);
28  myVars.insert("var2", var2);
29  }
void insert(const std::string &vname, real_type v, bool enable=true, int type=OTHER_P)
Definition: VariableSet.h:133
OptimizableObject(const std::string &name)

Member Function Documentation

◆ checkInVariablesExclusive()

void checkInVariablesExclusive ( opt_variables_type active)
inlineoverridevirtual

check in variational parameters to the global list of parameters used by the optimizer.

Parameters
activea super set of optimizable variables

The existing checkInVariables implementation in WFC/SPO/.. are inclusive and it calls checkInVariables of its members class A: public SPOSet {} class B: public WFC { A objA; checkInVariables() { objA.checkInVariables(); } };

With OptimizableObject, class A: public OptimizableObject {} class B: public OptimizableObject { A objA; checkInVariablesExclusive() { // should not call objA.checkInVariablesExclusive() if objA has been extracted; } }; A vector of OptimizableObject, will be created by calling extractOptimizableObjects(). All the checkInVariablesExclusive() will be called through this vector and thus checkInVariablesExclusive implementation should only handle non-OptimizableObject members.

Implements OptimizableObject.

Definition at line 30 of file test_OptimizableObject.cpp.

References VariableSet::insertFrom(), and FakeOptimizableObject::myVars.

Referenced by qmcplusplus::TEST_CASE().

30 { active.insertFrom(myVars); }

◆ readVariationalParameters()

void readVariationalParameters ( hdf_archive hin)
inlineoverridevirtual

Read the variational parameters for this object from the VP HDF file.

The hin parameter should come from VariableSet::readFromHDF

By default the parameters are read in VariableSet::readFromHDF, and objects do not need to implement this function (yet).

Reimplemented from OptimizableObject.

Definition at line 49 of file test_OptimizableObject.cpp.

References VariableSet::clear(), FakeOptimizableObject::extra_data, VariableSet::insert(), FakeOptimizableObject::myVars, hdf_archive::pop(), hdf_archive::push(), and hdf_archive::read().

Referenced by qmcplusplus::TEST_CASE().

50  {
51  hin.push("FakeOptimizableObject", false);
52 
53  myVars.clear();
54  double tmp_var1;
55  double tmp_var2;
56  // The HDF read call uses the file's type information to determine the amount data read into the variable.
57  hin.read(tmp_var1, "var1");
58  hin.read(tmp_var2, "var2");
59  hin.read(extra_data, "extra_data");
60  myVars.insert("var1", tmp_var1);
61  myVars.insert("var2", tmp_var2);
62  hin.pop();
63  }
void insert(const std::string &vname, real_type v, bool enable=true, int type=OTHER_P)
Definition: VariableSet.h:133
void clear()
clear the variable set
Definition: VariableSet.cpp:28

◆ resetParametersExclusive()

void resetParametersExclusive ( const opt_variables_type active)
inlineoverridevirtual

reset the parameters during optimizations.

Exclusive, see checkInVariablesExclusive

Implements OptimizableObject.

Definition at line 32 of file test_OptimizableObject.cpp.

32 {}

◆ writeVariationalParameters()

void writeVariationalParameters ( hdf_archive hout)
inlineoverridevirtual

Write the variational parameters for this object to the VP HDF file.

The hout parameter should come from VariableSet::writeToHDF

Objects can use this function to store additional information to the file.

By default the parameters are saved in VariableSet::writeToHDF, and objects do not need to implement this function (yet).

Reimplemented from OptimizableObject.

Definition at line 34 of file test_OptimizableObject.cpp.

References FakeOptimizableObject::extra_data, FakeOptimizableObject::myVars, hdf_archive::pop(), hdf_archive::push(), and hdf_archive::write().

Referenced by qmcplusplus::TEST_CASE().

35  {
36  hout.push("FakeOptimizableObject");
37  // Convert to double before writing to HDF.
38  // If these get written as complex, but read as double, it can cause memory overwrites.
39  // The HDF read call uses the file's type information to determine the amount data read
40  // (2 doubles for complex), but the variable size is just one double.
41  double var1 = std::real(myVars["var1"]);
42  double var2 = std::real(myVars["var2"]);
43  hout.write(var1, "var1");
44  hout.write(var2, "var2");
45  hout.write(extra_data, "extra_data");
46  hout.pop();
47  }
QMCTraits::RealType real

Member Data Documentation

◆ extra_data

◆ myVars


The documentation for this class was generated from the following file: