Core Classes

template<class Grid, class Hamiltonian, class MutexType, class RNGType = std::mt19937_64, template<class> class RefType = detail::Ref>
class 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.

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

This type is mostly a tuple of other observables.

Public Functions

template<class ...HArgs>
inline 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>
inline 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.

inline 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.

Parameters:

size – the number of statevectors that we want to have.

Returns:

A pointer to the state space memory.

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

This function sets up the layout of the HDF5 Container.

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.

Returns:

An object for the HDF5 File.

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

Create default name for Hamiltonian parameter.

Creates strings of the form param0, param1,…

Parameters:

c – the index of the parameter.

Returns:

param + c

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

Use the user supplied for Hamiltonian parameter.

asks the hamiltonian for the name of the parameter.

Parameters:

c – the index of the parameter.

Returns:

ham.paramname(c).

template<class ...HArgs>
inline 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.

inline void dumplatparamstoH5(H5::Group &h5loc)

Write out the parameters of the lattice.

FIXME: UNIMPLEMENTED

Parameters:

h5loc – The group where to dump the information.

inline 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>
inline 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

inline void init_hot()

The default StateSpace initializer.

This initializes with random directions.

template<typename StateSpace, class Lattice, class H, typename ...Ts>
inline 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>
inline 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>
inline 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

inline 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.

inline void dumpstatespace()

A helper function to dump the entire statespace.

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

inline ~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.

template<size_t N = 0, typename ...Ts, typename S, typename G>
inline enable_if_t(t, s, std::forward<G>(grid))

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 elementaryMCstep()

The elementary Monte Carlo step.

Returns:

acceptance

inline void gameloop()

The basic Monte Carlo loop.

A couple of cycles of updating and measuring.

inline void wrmploop()

Warm up loop.

We warm up the state space with a couple of cycles.

inline void full_output_2D(int dim = 0)

Visual output of 2D statespace to a file.

Parameters:

dim

inline 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.

inline 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.

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.

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

static inline 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.

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.

Returns:

0.

static inline bool dumppresent(const Config &mc)

Test whether MARQOV would need to start from scratch.

Parameters:

mc – A Config object

Returns:

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

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 Types

decltype(std::declval< T >().template measure< StateSpace, Grid >(std::declval< StateSpace >(), std::declval< Grid >())) 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

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

Construct the tuple of Observable Caches.

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

  • t – the tuple of observables.

Returns:

the final tuple of observable caches.