Utopia  2
Framework for studying models of complex & adaptive systems.
Public Member Functions | Protected Types | Protected Attributes | Private Member Functions | List of all members
Utopia::PseudoParent< RNG > Class Template Reference

A class to use at the top level of the model hierarchy as a mock parent. More...

#include <model.hh>

Collaboration diagram for Utopia::PseudoParent< RNG >:
Collaboration graph
[legend]

Public Member Functions

 PseudoParent (const std::string cfg_path)
 Constructor that only requires path to a config file. More...
 
 PseudoParent (const std::string cfg_path, const std::string output_path, const int seed=42, const std::string output_file_mode="w", const double emit_interval=5.)
 Constructor that allows granular control over config parameters. More...
 
Level get_level () const
 Return the hierarchical level within the model hierarchy. More...
 
std::string get_full_name () const
 Return the full name of the PseudoParent: an empty string. More...
 
Config get_cfg () const
 Return the config node of the Pseudo model, i.e. the root node. More...
 
std::shared_ptr< HDFFileget_hdffile () const
 Return a pointer to the HDF data file. More...
 
std::shared_ptr< HDFGroupget_hdfgrp () const
 Return a pointer to the HDF group, which is the base group of the file. More...
 
Time get_write_start () const
 Return the parameter that controls when write_data is called first. More...
 
Time get_write_every () const
 Return the parameter that controls how often write_data is called. More...
 
std::shared_ptr< RNG > get_rng () const
 Return a pointer to the RNG. More...
 
std::shared_ptr< spdlog::logger > get_logger () const
 Return a pointer to the logger of this model. More...
 
Time get_time_max () const
 The maximum time value as it can be found in the config. More...
 
std::shared_ptr< MonitorManagerget_monitor_manager () const
 Return the monitor manager of this model. More...
 
const Monitorget_monitor () const
 Return the monitor of this model. More...
 

Protected Types

using Config = Utopia::DataIO::Config
 
using HDFFile = Utopia::DataIO::HDFFile
 
using HDFGroup = Utopia::DataIO::HDFGroup
 
using MonitorManager = Utopia::DataIO::MonitorManager
 
using Monitor = Utopia::DataIO::Monitor
 
using Time = std::size_t
 
using Level = std::size_t
 

Protected Attributes

const Level _level
 The hierarchical level. More...
 
const Config _cfg
 The config node. More...
 
const std::shared_ptr< HDFFile_hdffile
 Pointer to the HDF5 file where data is written to. More...
 
const std::shared_ptr< RNG > _rng
 Pointer to a RNG that can be shared between models. More...
 
const std::shared_ptr< spdlog::logger > _log
 Pointer to the logger of this (pseudo) model. More...
 
const std::shared_ptr< MonitorManager_monitor_mgr
 The monitor manager. More...
 
Monitor _monitor
 The monitor instance of this root model. More...
 

Private Member Functions

void setup_loggers () const
 Set up the global loggers with levels specified in the config file. More...
 
void set_log_level () const
 Set the log level for the pseudo parent from the base_cfg. More...
 

Detailed Description

template<typename RNG = DefaultRNG>
class Utopia::PseudoParent< RNG >

A class to use at the top level of the model hierarchy as a mock parent.

It is especially useful when initializing a top-level model as the the model constructor that expects a Model-class-like object can be used. This class also takes care to load and hold a configuration file, to create a HDFFile for output, and to initialize a shared RNG. A template parameter exists that allows customization of the RNG class.

Template Parameters
RNGThe RNG type to use

Member Typedef Documentation

◆ Config

template<typename RNG = DefaultRNG>
using Utopia::PseudoParent< RNG >::Config = Utopia::DataIO::Config
protected

◆ HDFFile

template<typename RNG = DefaultRNG>
using Utopia::PseudoParent< RNG >::HDFFile = Utopia::DataIO::HDFFile
protected

◆ HDFGroup

template<typename RNG = DefaultRNG>
using Utopia::PseudoParent< RNG >::HDFGroup = Utopia::DataIO::HDFGroup
protected

◆ Level

template<typename RNG = DefaultRNG>
using Utopia::PseudoParent< RNG >::Level = std::size_t
protected

◆ Monitor

template<typename RNG = DefaultRNG>
using Utopia::PseudoParent< RNG >::Monitor = Utopia::DataIO::Monitor
protected

◆ MonitorManager

template<typename RNG = DefaultRNG>
using Utopia::PseudoParent< RNG >::MonitorManager = Utopia::DataIO::MonitorManager
protected

◆ Time

template<typename RNG = DefaultRNG>
using Utopia::PseudoParent< RNG >::Time = std::size_t
protected

Constructor & Destructor Documentation

◆ PseudoParent() [1/2]

template<typename RNG = DefaultRNG>
Utopia::PseudoParent< RNG >::PseudoParent ( const std::string  cfg_path)
inline

Constructor that only requires path to a config file.

From the config file, all necessary information is extracted, i.e.: the path to the output file ('output_path') and the seed of the shared RNG ('seed'). These keys have to be located at the top level of the configuration file.

Parameters
cfg_pathThe path to the YAML-formatted configuration file

◆ PseudoParent() [2/2]

template<typename RNG = DefaultRNG>
Utopia::PseudoParent< RNG >::PseudoParent ( const std::string  cfg_path,
const std::string  output_path,
const int  seed = 42,
const std::string  output_file_mode = "w",
const double  emit_interval = 5. 
)
inline

Constructor that allows granular control over config parameters.

Parameters
cfg_pathThe path to the YAML-formatted configuration file
output_pathWhere the HDF5 file is to be located
seedThe seed the RNG is initialized with (default: 42)
output_file_modeThe access mode of the HDF5 file (default: w)
emit_intervalThe monitor emit interval (in seconds)

Member Function Documentation

◆ get_cfg()

template<typename RNG = DefaultRNG>
Config Utopia::PseudoParent< RNG >::get_cfg ( ) const
inline

Return the config node of the Pseudo model, i.e. the root node.

◆ get_full_name()

template<typename RNG = DefaultRNG>
std::string Utopia::PseudoParent< RNG >::get_full_name ( ) const
inline

Return the full name of the PseudoParent: an empty string.

◆ get_hdffile()

template<typename RNG = DefaultRNG>
std::shared_ptr<HDFFile> Utopia::PseudoParent< RNG >::get_hdffile ( ) const
inline

Return a pointer to the HDF data file.

◆ get_hdfgrp()

template<typename RNG = DefaultRNG>
std::shared_ptr<HDFGroup> Utopia::PseudoParent< RNG >::get_hdfgrp ( ) const
inline

Return a pointer to the HDF group, which is the base group of the file.

◆ get_level()

template<typename RNG = DefaultRNG>
Level Utopia::PseudoParent< RNG >::get_level ( ) const
inline

Return the hierarchical level within the model hierarchy.

◆ get_logger()

template<typename RNG = DefaultRNG>
std::shared_ptr<spdlog::logger> Utopia::PseudoParent< RNG >::get_logger ( ) const
inline

Return a pointer to the logger of this model.

◆ get_monitor()

template<typename RNG = DefaultRNG>
const Monitor& Utopia::PseudoParent< RNG >::get_monitor ( ) const
inline

Return the monitor of this model.

◆ get_monitor_manager()

template<typename RNG = DefaultRNG>
std::shared_ptr<MonitorManager> Utopia::PseudoParent< RNG >::get_monitor_manager ( ) const
inline

Return the monitor manager of this model.

◆ get_rng()

template<typename RNG = DefaultRNG>
std::shared_ptr<RNG> Utopia::PseudoParent< RNG >::get_rng ( ) const
inline

Return a pointer to the RNG.

◆ get_time_max()

template<typename RNG = DefaultRNG>
Time Utopia::PseudoParent< RNG >::get_time_max ( ) const
inline

The maximum time value as it can be found in the config.

Currently, this reads the num_steps key, but this might be changed in the future to allow continuous time steps.

◆ get_write_every()

template<typename RNG = DefaultRNG>
Time Utopia::PseudoParent< RNG >::get_write_every ( ) const
inline

Return the parameter that controls how often write_data is called.

◆ get_write_start()

template<typename RNG = DefaultRNG>
Time Utopia::PseudoParent< RNG >::get_write_start ( ) const
inline

Return the parameter that controls when write_data is called first.

◆ set_log_level()

template<typename RNG = DefaultRNG>
void Utopia::PseudoParent< RNG >::set_log_level ( ) const
inlineprivate

Set the log level for the pseudo parent from the base_cfg.

◆ setup_loggers()

template<typename RNG = DefaultRNG>
void Utopia::PseudoParent< RNG >::setup_loggers ( ) const
inlineprivate

Set up the global loggers with levels specified in the config file.

Extract the following keys from the _cfg member:

- ``log_levels.core``:      the Core module log level; required
- ``log_levels.data_io``:   the DataIO module log level; required
- ``log_levels.data_mngr``: the DataIO::DataManager log level;
                            optional, defaults to ``warn``
- ``log_pattern``:          the global log pattern

Member Data Documentation

◆ _cfg

template<typename RNG = DefaultRNG>
const Config Utopia::PseudoParent< RNG >::_cfg
protected

The config node.

◆ _hdffile

template<typename RNG = DefaultRNG>
const std::shared_ptr<HDFFile> Utopia::PseudoParent< RNG >::_hdffile
protected

Pointer to the HDF5 file where data is written to.

◆ _level

template<typename RNG = DefaultRNG>
const Level Utopia::PseudoParent< RNG >::_level
protected

The hierarchical level.

◆ _log

template<typename RNG = DefaultRNG>
const std::shared_ptr<spdlog::logger> Utopia::PseudoParent< RNG >::_log
protected

Pointer to the logger of this (pseudo) model.

Required for passing on the logging level if unspecified for the respective model

◆ _monitor

template<typename RNG = DefaultRNG>
Monitor Utopia::PseudoParent< RNG >::_monitor
protected

The monitor instance of this root model.

◆ _monitor_mgr

template<typename RNG = DefaultRNG>
const std::shared_ptr<MonitorManager> Utopia::PseudoParent< RNG >::_monitor_mgr
protected

The monitor manager.

◆ _rng

template<typename RNG = DefaultRNG>
const std::shared_ptr<RNG> Utopia::PseudoParent< RNG >::_rng
protected

Pointer to a RNG that can be shared between models.


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