Core Classes

template<class Grid, class Hamiltonian, class MutexType, class RNGType = std::mt19937_64, template<class> class RefType = detail::Ref>
class MARQOV::Core : public MARQOV::detail::Ref<Grid>

The MARQOV Core class.

This class fuses all the parts that the user has specified and calls them to life if needed. The Hamiltonian and the lattice will be instantiated and depending on these the respective Monte Carlo moves will be generated. I/O for the Observables will be generated. The RNGCache will be initialized.

Template Parameters
  • Grid: the Lattice that we should use.

  • Hamiltonian: The Hamiltonian that we should use.

  • MutexType: The type of the mutex that we use for locking.

  • RNGType: The type of the Random Number Generator that we use.

  • RefType: used internally to distinguish, whether MARQOV::Core should create the lattice or whether it is user provided.

Public Types

typedef Hamiltonian HamiltonianType

Via HamiltonianType the used Hamiltonian is accessible.

typedef Grid Lattice

The Type of the Lattice.

typedef Hamiltonian::StateVector StateVector

The type of the StateVector as retrieved from the Hamiltonian.

typedef Space<StateVector, Lattice> StateSpace

the type of the state space.

Public Functions

template<class ...HArgs>
Core(const Grid &lattice, Config mc, MutexType &mtx, double mybeta, HArgs&&... hargs)

Construct MARQOV with a predefined lattice.

First we have the parameters for the MARQOV::Core class, then follows the arbitrary number of arguments for a particular Hamiltonian.

Template Parameters
  • HArgs: The arguments to the Hamiltonian.

Parameters
  • lattice: A reference to the instantiated lattice object. You are responsible for managing its lifetime.

  • mc: A MARQOV::Config object with all required information.

  • mtx: The std::mutex that synchronizes access to the HDF5 library.

  • mybeta: The temperature that governs the Metropolis dynamics.

  • hargs: A template parameter pack for the Hamiltonian.

template<class ...HArgs, class ...LArgs>
Core(std::tuple<LArgs...> largs, Config mc, MutexType &mtx, double mybeta, HArgs&&... hargs)

Construct MARQOV and let MARQOV create the lattice.

If you require MARQOV::Core to instantiate and embed the lattice for you.

Template Parameters
  • HArgs: the Arguments of the Hamiltonian.

  • LArgs: The Arguments of the Lattice.

Parameters
  • largs: The arguments that we forward to the lattice.

  • mc: The Marqov config object with all configuration.

  • mtx: The Mutex for synchronizing access to the HDF5 library.

  • mybeta: the temperature that governs the Metropolis dynamics.

  • hargs: the arguemts for the Hamiltonian.

auto setupstatespace(int size)

Set up and/or reinitialize state space.

This sets up the state space. If a previous step is present we reread that from the files.

Return

A pointer to the state space memory.

Parameters
  • size: the number of statevectors that we want to have.

template<class ...HArgs>
H5::H5File setupHDF5Container(const Config &mc, HArgs&&... hargs)

This function sets up the layout of the HDF5 Container.

Return

An object for the HDF5 File.

Template Parameters
  • HArgs: The template pack of the Hamiltonian parameters.

Parameters
  • mc: A MARQOV::Config object that we will dump to the respective path.

  • hargs: The arguments of the Hamiltonian.

std::string createparamname(std::false_type, int c)

Create default name for Hamiltonian parameter.

Creates strings of the form param0, param1,…

Return

param + c

Parameters
  • c: the index of the parameter.

std::string createparamname(std::true_type, int c)

Use the user supplied for Hamiltonian parameter.

asks the hamiltonian for the name of the parameter.

Return

ham.paramname(c).

Parameters
  • c: the index of the parameter.

template<class ...HArgs>
void dumphamparamstoH5(H5::Group &h5loc, HArgs&&... hargs)

Write hamiltonian parameters to file.

Template Parameters
  • HArgs: a template parameter pack with the variables for the Hamiltonian.

Parameters
  • h5loc: the HDF5 group where we store these names.

  • hargs: the arguments of the hamiltonian.

void dumplatparamstoH5(H5::Group &h5loc)

Write out the parameters of the lattice.

FIXME: UNIMPLEMENTED

Parameters
  • h5loc: The group where to dump the information.

void dumpenvtoH5(H5::Group &h5loc)

This function tries to dump as much useful information about the environment into the container as possible.

Parameters
  • h5loc: The group where to dump the information.

template<class ...HArgs>
void createstep(H5::H5File &file, int s, const Config &mc, HArgs&&... hargs)

This creates a single step in the HDF5 File.

Template Parameters
  • HArgs: the argument tuple of the Hamiltonian.

Parameters
  • file: the HDF5 file where to create the step

  • s: the number of the step

  • mc: the parameters of MARQOV::Core

  • hargs: the argument tuple of the Hamiltonian

void init_hot()

The default StateSpace initializer.

This initializes with random directions.

template<typename StateSpace, class Lattice, class H, typename ...Ts>
void haminit_helper(std::true_type, StateSpace &statespace, const Lattice &grid, H &ham, Ts&&... ts)

Select the user supplied initializer for the statespace.

Template Parameters
  • StateSpace: The type of the statespace

  • Lattice: The type of the Lattice

  • H: The type of the Hamiltonian

  • Ts: optional arguments

Parameters
  • statespace: The statespace of MARQOV.

  • ham: The Hamiltonian.

  • grid: the currently used lattice.

  • ts: optional arguments.

template<typename StateSpace, class Lattice, class H, typename ...Ts>
void haminit_helper(std::false_type, StateSpace &statespace, const Lattice&, H &ham, Ts&&... ts)

Initializer if no user supplied initializer.

If there’s no user defined function we do a random initialization.

Template Parameters
  • StateSpace: The type of the statespace

  • Lattice: The Lattice

  • H: The Hamiltonian

  • Ts: optional arguments

Parameters
  • statespace: The statespace of MARQOV

  • ham: The Hamiltonian

  • ts: optional arguments

template<typename ...Ts>
void init(Ts&&... ts)

Initialize the state space.

This initializes the state space. If the user has supplied his/her own function we use that, else we use randomized directions.

Template Parameters
  • Ts: optional parameters

Parameters
  • ts: optional parameters

void dumprng()

Dump RNG State to HDF5.

This writes out the state of the RNG to the HDF5 group. We assume that the state is written out as a vector of 64bit integers.

void dumpstatespace()

A helper function to dump the entire statespace.

The internal data layout is the same as for a time series.

~Core()

Destructor.

Uses the HDF5 Mutex to serialize the access to the HDF5 library and hence the output to the library.

Core(const Core &rhs) = delete

The deleted copy constructor of Core.

The Core class cannot be copied.

Core &operator=(const Core &rhs) = delete

The deleted assignment operator of Core.

There cannot be two identical copies of core.

Core(Core &&other) = default

The default move constructor of Core.

FIXME: figure out and note where and why it is actually used.

Core &operator=(Core &&other) = delete

The deleted move assignment operator of Core.

There cannot be two identical copies of Core.

void debugloop(const int nsteps, const int ncluster, const int nsweeps)

The Debug loop.

Parameters
  • nsteps: The number of steps.

  • ncluster: The number of cluster updates.

  • nsweeps: The number of sweeps.

void gameloop_liveview(int nframes = 100, int nsweepsbetweenframe = 5)

Liveview helper function.

use carefully, might generate a lot of terminal output

Parameters
  • nframes:

  • nsweepsbetweenframe:

Public Members

marqovtime::timetracker mrqvt

The TimeTracker for tracking times.

template<size_t N = 0, typename... Ts, typename S, typename G> std::enable_if_t< N< sizeof...(Ts), void > marqov_measure(std::tuple< Ts... > &t, S &s, G &&grid) { FLOGDEBUGVERBOSE<<"Measuring observable "<< N<<" of "<< mcfg.id<<" at b="<< beta<<" tid: "<< std::this_thread::get_id()<<'\n';auto retval=detail::_call(&std::tuple_element< N, std::tuple< Ts... > >::type::template measure< StateSpace, G >, std::get< N >t), std::forward_as_tuple(s, grid));marqov_measure< N+1, Ts... >t, s, std::forward< G >grid));hdf5lock.lock();std::get< N >obscache)<< retval;hdf5lock.unlock();} template< size_t N=0, typename A, typename B, typename S, typename G > inline void marqov_measure(std::pair< A, B > &t, S &s, G &&grid) { auto retval0=t.first.template measure< StateSpace, G >s, grid);auto retval1=t.second.template measure< StateSpace, G >s, grid);hdf5lock.lock();MLOGDEBUGVERBOSE<<"Measuring observable 1 of"<< mcfg.id<<" at b="<< beta<<" tid: "<< std::this_thread::get_id()<<'\n';std::get< 1 >obscache)<< retval1;MLOGDEBUGVERBOSE<<"Measuring observable 2 of"<< mcfg.id<<" at b="<< beta<<" tid: "<< std::this_thread::get_id()<<'\n';std::get< 0 >obscache)<< retval0;hdf5lock.unlock();} double elementaryMCstep();void gameloop() { mlogstate.reset();MLOGDEBUG<<"Beginning Gameloop of "<< mcfg.id<<" at beta = "<< beta<<". ThreadID: "<< std::this_thread::get_id()<<'\n';constexpr int gli=10;double avgclustersize=0;for(int k=0;k< gli;k++) { if(this->mcfg.id==0) MLOGRELEASE<< "."<< std::flush;for(int i=0;i< this->mcfg.gameloopsteps/10;++i) { avgclustersize+=elementaryMCstep();mrqvt.switch_clock("measure");marqov_measure(obs, statespace, this->grid);} } mrqvt.stop();if(this->mcfg.id==0) { MLOGRELEASE<<"Average cluster size: "<< avgclustersize/this-> mcfg gameloopsteps<< std::endl;MLOGRELEASE<< mrqvt.status();} MLOGDEBUG<<"Ending Gameloop of "<< mcfg.id<<"\n";} void wrmploop() { mlogstate.reset();MLOGDEBUG<<"Beginning Warmuploop\n";constexpr int gli=10;if(step< 1) { if(this->mcfg.id==0) std::cout<< "|";for(int k=0;k< gli;k++) { if(this->mcfg.id==0) MLOGRELEASE<< "."<< std::flush;for(int i=0;i< this->mcfg.warmupsteps/10;++i) elementaryMCstep();} if(this->mcfg.id==0) std::cout<< "|";} MLOGDEBUG<<"Ending Warmuploop\n";} void full_output_2D(int dim=0) { const int LL=this-> grid length

Measure observables.

This functions measures observables and recurses into the observable tuple. The measured value gets written to HDF5

Template Parameters
  • N: the current index of the observable.

  • Ts: the types of all observables.

  • S: an index sequence.

  • G: the type of the lattice.

Parameters
  • t: a tuple with all observables

  • s: dummy argument for the index sequence

  • grid: the actual grid

double beta

The inverse temperature.

Hamiltonian ham

An instance of the user-defined Hamiltonian.

Config mcfg

An instance of all our MARQOV related parameters.

int step

The current step of the simulation. Used for HDF5 paths.

std::unique_lock<MutexType> hdf5lock

The global lock to synchronize access to the HDF5 library.

H5::H5File dump

The handle for the HDF5 file. Must be before the obscaches and the statespace.

StateSpace statespace

The statespace. It holds the current configuration space.

H5::Group obsgroup

The HDF5 Group of all our observables.

H5::Group stategroup

The HDF5 Group where to dump the statespace.

decltype(std::declval< Hamiltonian >().observables) typedef ObsTs

This type is mostly a tuple of other observables.

ObsTupleToObsCacheTuple<ObsTs>::RetType obscache

The HDF5 caches for each observable.

ObsTs &obs

the actual observables defined in the hamiltonians.

RNGCache<RNGType> rngcache

The caching RNG.

Public Static Functions

herr_t findstep(hid_t loc_id, const char *name, const H5L_info_t *linfo, void *step)

Helper function for HDF5.

Operator function to find the last step in a file.

Return

0.

Parameters
  • loc_id: an HDF5 id.

  • name: The group name that we are looking at.

  • linfo: Other info from HDF5.

  • step: the last step that is in the file.

bool dumppresent(const Config &mc)

Test whether MARQOV would need to start from scratch.

Return

true if we find an existing HDF5 file, else false.

Parameters

template<int N, typename Tup>
struct ObsCacheTupleIter

Map Tuple of Observables to Tuple of ObservableCaches.

This peels of one level of the recursion.

Template Parameters
  • N: recursion level counter

  • Tup: A Tuple of observables.

template<typename Tup>
struct ObsCacheTupleIter<0, Tup>

Map Tuple of Observables to Tuple of ObservableCaches.

Recursion end.

Template Parameters
  • N: recursion level counter

  • Tup: A Tuple of observables.

Public Types

typedef std::tuple<CacheContainer<typename ObsRetType<typename std::tuple_element<0, Tup>::type>::RetType>> RetType

At recursion end this is an ObsCache with the type of the observable.

template<typename T>
struct ObsRetType

Get the return type of the measure function of an observable.

Template Parameters
  • T: The observable.

Public Members

decltype(std::declval< T >().template measure< StateSpace, Grid >(std::declval< StateSpace >(), std::declval< Grid >())) typedef RetType

This determines the value that we will pass to the vector from the return type of the measure function of the observable…

template<typename Tup>
struct ObsTupleToObsCacheTuple

Map tuple of observables to tuple of ObservableCaches.

This template is the entry point to map a tuple of observables to a tuple of ObservableCaches at Compile Time. This starts the recursion.

Template Parameters
  • Tup: A tuple of observables.

Public Types

typedef ObsCacheTupleIter<std::tuple_size<Tup>::value - 1, Tup>::RetType RetType

this holds the type of the tuple of ObservableCaches.

Public Static Functions

auto getargtuple(H5::Group &h5loc, Tup &t)

Construct the tuple of Observable Caches.

Return

the final tuple of observable caches.

Parameters
  • h5loc: the HDF5 group where we store the observables.

  • t: the tuple of observables.