ALPS Project: alps library

Header file observable.h

This header contains the abstract base class for Monte Carlo measurements.

Synopsis

namespace alps {

class NoMeasurementsError : public std::runtime_error {
public:
NoMeasurementsError();
};

class Observable
{
public:
typedef uint32_t version_type;

Observable();
Observable(const std::string& n);
Observable(const Observable& o);
virtual ~Observable();

virtual Observable* clone() const = 0;

const std::string& name() const;
void rename (const std::string& newname);

virtual void reset(bool equilibrated=false) = 0;

virtual void output(std::ostream&) const = 0;
virtual void write_xml(std::ostream&, const boost::filesystem::path& fn_hdf5=boost::filesystem::path()) const;
virtual void write_xml(oxstream& oxs, const boost::filesystem::path& fn_hdf5=boost::filesystem::path()) const;

virtual uint32_t version_id() const =0;
virtual void save(ODump& dump) const;
virtual void load(IDump& dump);

virtual bool can_set_thermalization() const;
virtual void set_thermalization(uint32_t todiscard);
virtual uint32_t get_thermalization() const=0;

virtual bool is_signed() const;
virtual void set_sign_name(const std::string& signname);
virtual void set_sign(const Observable& sign);
virtual void clear_sign();
virtual const Observable& sign() const;
virtual const Observable& signed_observable() const;
virtual const std::string& sign_name() const;

virtual uint32_t number_of_runs() const;
virtual Observable* get_run(uint32_t) const;

virtual void compact();

template <class T> void operator<<(const T& x);
};

std::ostream& operator<<(std::ostream& out, const Observable& o);

ODump& operator<<(ODump& od, const Observable& m);
IDump& operator>>(IDump& id, Observable& m);

}

The NoMeasurementsError class

An exception of type NoMeasurementsError gets thrown when results of measurements are accessed for an observable which has not stored any measurement. E.g. the mean value being accessed before the equilibration phase has finished.

The Observable abstract base class

Member functions

typedef uint32_t version_type;
is an integer storing a unique integer identifier of the derived leaf class.
Observable();
the default constructor. Note that the observable needs to be given a name before it can be used in an ObservableSet.
Observable(const std::string& n);
creates an observable with a given name. Every observable has a name.
Observable(const Observable& o);
is the copy constructor. A special copy constructor is needed, because information about which ObservableSet an observable belongs to is invalidated when copying.

creates an observable with a given name. Every observable has a name.
virtual Observable* clone() const = 0;
copies the observable and returns a pointer to the copy.
const std::string& name() const;
returns the name of the observable.
void rename(const std::string& newname);
renames the observable. This is only possible for an Observable not in an  ObservableSet, otherwise a std::runtime_error is thrown.
virtual void reset(bool equilibrated=false) = 0;
resets the observable and restarts the collection of measurements. If the argument is false, the observable collects information during an equilibration phase, while it collects real measurements of the argument is true.

Important note: This function has to be called with a true argument before any real measurements are recorded.

virtual void output(std::ostream&) const = 0;
writes the results of the collected measurements to a std::ostream.
virtual void write_xml(oxstream& oxs, const boost::filesystem::path& fn_hdf5=boost::filesystem::path()) const;
writes the results of the measurement in XML, using the schema presented at http://xml.comp-phys.org to an X. If time series information is present and a second nonempty argument the time series information is written into a file specified by that name.
virtual uint32_t version_id() const =0;
returns a unique integer identifier for the leaf class, used in serialization and deserialization of inhomogeneous collections of observables.
virtual void save(ODump& dump) const;
virtual void load(IDump& dump);
are virtual functions used to implement serialization and deserialization.
virtual bool can_set_thermalization() const;
returns true if the thermalization (equilibration) time can be changed after the measurements have been performed.
virtual void set_thermalization(uint32_t todiscard);
sets the thermalization (equilibration) time to discard the given number of measurements. Throws std::logic_error if the thermalization (equilibration) time cannot be changed for the observable.
virtual uint32_t get_thermalization() const=0;
returns the thermalization (equilibration) time.
virtual bool is_signed() const;
returns true if the observable has a sign or phase problem.
virtual void set_sign_name(const std::string& signname);
sets the name of the observable containing the sign or phase. Throws a std::logic_error for observables without a sign or phase problem.
virtual void set_sign(const Observable& sign);
sets the observable containing the sign or phase. A pointer is stored with the observable. Throws a std::logic_error for observables without a sign or phase problem.
virtual void clear_sign();
removes any previously set sign or phase observable. Throws a std::logic_error for observables without a sign or phase problem.
virtual const Observable& sign() const;
returns a reference to the sign or phase observable. Throws a std::runtime_error if no sign or phase observable has been set. Throws a std::logic_error for observables without a sign or phase problem.
virtual const Observable& signed_observable() const;
returns a reference to the observable which records the signed measurements (i.e. recording the product of sign an observable, before division by the average sign). Throws a std::logic_error for observables without a sign or phase problem.
virtual const std::string& sign_name() const;
returns the name of the sign or phase observables. Throws a std::logic_error for observables without a sign or phase problem.
virtual uint32_t number_of_runs() const;
returns the number of runs (time series) which have contributed to this observable.
virtual Observable* get_run(uint32_t) const;
creates an observable containing data from only one specified run (time series).
virtual void compact();
compacts the observable, reducing the memory allocation, while still enabling access to the most important results. Usually the ability to modify the observable (e.g. change thermalization, get crosscorrelations, ...) gets lost though.
template <class T> void operator<<(const T& x);
is a helper function, dispatiching to the derived class:

I/O operators

std::ostream& operator<<(std::ostream& out, const alps::Observable& o);
calls the output function of an Observable to write it to a std::ostream.
ODump& operator<<(ODump& od, const Observable& m);
IDump& operator>>(IDump& id, Observable& m);
serializes and deserializes an Obseravble object. They call the save and load functions of the obseravble.

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)