ALPS Project: scheduler library

Header file montecarlo.h

This header contains Worker, the base class for the user simulation object, and MCRun the derived base class for a Monte Carlo simulation.

Synopsis

namespace alps {
namespace scheduler {

template <class WORKER>
class SimpleMCFactory : public SimpleFactory<WORKER,MCSimulation>
{
public:
  SimpleMCFactory() {}
};

class Worker
{
public:		
  virtual void dostep()=0;
  virtual double work_done() const =0;
  
  virtual void start();
  virtual void halt();

  virtual bool change_parameter(const std::string& name, const alps::StringValue& value);
  
protected:
  typedef boost::lagged_fibonacci607 random_type;
  random_type random;
  double random_real(double a=0., double b=1.,);
  int random_int(int a, int b);
  int random_int(int n);

  alps::Parameters parms;
  
  osiris::ProcessList where;
};

class MCRun : public Worker
{
public:
  MCRun(const osiris::ProcessList& w, const alps::Parameters& p,int node);

  virtual void save(osiris::ODump& dump) const;
  virtual void load(osiris::IDump& dump) const;
  
  virtual void write_xml(const std::string& name, const std::string& dumpname="") const;
  alea::ObservableSet get_measurements() const;

  virtual bool is_thermalized() const=0;
protected:
  alea::ObservableSet measurements;
};

template <class G=lattice::graph_factory<>::graph_type>
class LatticeMCRun : public MCRun, public graph_helper
{
public:  
  LatticeMCRun(const osiris::ProcessList& w,const alps::Parameters& p,int n);
};

template <class G=graph_factory<>::graph_type, class I=short>
class LatticeModelMCRun : public LatticeMCRun<G>, public model_helper<I>
{
public:  
  LatticeModelMCRun(const ProcessList& w,const alps::Parameters& p,int n);
  bool has_sign_problem() const;  
};

}

The SimpleMCFactory class

is a factory fo Monte Carlo simulations, supporting one type of simulation. The WORKKER object passed as template argument is assumed to be derived from MCRun below and will be created by the factory.

The Worker and MCRun class

The Worker class is the base class for all user simulations, containing the features not specific to Monte Carlo simulations. At the moment the only use is for Monte Carlo simulations through the derived class MCRun but further applications will be added in the future. For now we will thus discuss the members of both classes together.

Member functions

MCRun(const osiris::ProcessList& w, const alps::Parameters& p,int node;
is the constructor of a new Monte Carlo run.

The argument w gives the processor nodes on which the MCRun is created, and the argument node the index into this list in case of future multi-CPU simulations. The simulation parameters are given in

. These three arguments are passed to the factory and will just be passed on to the constructor here.

virtual void dostep()=0;
does one simulation step. This needs to be implemented by the user of the library.
virtual double work_done() const =0;
returns the fraction of work that is already done for the simulation. A value of one means that the simulation is finished. This also needs to be implemented by the user of the library.
virtual void start();
is called at the start of the simulation and can be overriden to do some initial work.
virtual void halt();
is called at the end of the simulation and can be overriden to do some final work.
virtual bool change_parameter(const std::string& name, const alps::StringValue& value);
is called when the user changes the parameter given by name to a new value. If the change is allowed or irrelevant the function should do the appropriate changes and return true, while false should be returned if the parameter change is not valid.
virtual void save(osiris::ODump& dump) const;
should be overriden to save the user data into a checkpoint. In contrast to previous library versions the base class function MCRun::save should no longer be called from the derived user class.
virtual void load(osiris::IDump& dump);
should be overrideen to read a Monte Carlo run from a checkpoint, if checkpointing support is desired.
virtual bool is_thermalized() const=0;
needs to be overridden to give a criterion for equilibration of the Monte Carlo simulation and to determine when real measurements should start.
alea::ObservableSet get_measurements() const;
returns the collected measurements.

Type members

typedef boost::lagged_fibonacci607 random_type;
is the type of random number generator used.
double random_real(double a=0., double b=1.);
provides floating point random numbers in the range a to b, inclusive the limiting value a but excluding b.
int random_int(int a, int b);
provides integer random numbers in the range a to b, inclusive the limiting values a and b.
int random_int(int n);
provides integer random numbers in the range 0 to n-1, inclusive the limiting values 0 and n-1.

Data members

random_type random;
is the random number generator
alea::ObservableSet measurements;
the collected measurements into which measurements should be stored.
alps::Parameters parms;
The simulation parameters.
osiris::ProcessList where;
the processes of which the simulation is running. This is empty if the simulation has been loaded for evaluation purposes and no actual simulations will be performed.

The LatticeMCRun class template

is derived from MCRun and graph_helper, thus constructing a lattice and providing access to it.
LatticeMCRun(const osiris::ProcessList& w,const alps::Parameters& p,int n);
The constructor creates the graph from the following input parameters:
ParameterDescription
LATTICE_LIBRARYThe path to an XML file containg lattice descriptions. It will be used to initialize a lattice library. The default is a file called "lattices.xml" in the current working directory.
LATTICEThe name of the lattice or graph in the lattice library that will be constructed.
GRAPHA synonym for LATTICE.

The LatticeModelMCRun class

is derived from LatticeMCRun and model_helper, thus constructing a model and providing access to it.
   
LatticeModelMCRun(const osiris::ProcessList& w,const alps::Parameters& p,int n);
The constructor additionally creates the model from the following input parameters:
ParameterDescription
MODEL_LIBRARYThe path to an XML file containg lattice descriptions. It will be used to initialize a model. The default is a file called "models.xml" in the current working directory.
MODELThe name of a model.
   
bool has_sign_problem() const;
returns true if the model might suffer from a sign problem.

copyright (c) 1994-2010 by Matthias Troyer

Distributed under the Boost Software License, Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt)