Utopia 2
Framework for studying models of complex & adaptive systems.
|
Base class interface for Models using the CRT Pattern. More...
#include <model.hh>
Public Types | |
using | Config = typename ModelTypes::Config |
Data type that holds the configuration. | |
using | DataManager = DataIO::Default::DefaultDataManager< Derived > |
The data manager to use, specialized with the derived model. | |
using | DataGroup = typename ModelTypes::DataGroup |
Data type that is used for storing datasets. | |
using | DataSet = typename ModelTypes::DataSet |
Data type that is used for storing data. | |
using | RNG = typename ModelTypes::RNG |
Data type of the shared RNG. | |
using | Space = typename ModelTypes::Space |
Data type of the space this model resides in. | |
using | Time = typename ModelTypes::Time |
Data type for the model time. | |
using | Monitor = typename ModelTypes::Monitor |
Data type for the monitor. | |
using | MonitorManager = typename ModelTypes::MonitorManager |
Data type for the monitor manager. | |
using | Level = typename ModelTypes::Level |
Data type for the hierarchical level. | |
Public Member Functions | |
template<class ParentModel , class... WriterArgs> | |
Model (const std::string &name, const ParentModel &parent_model, const Config &custom_cfg={}, std::tuple< WriterArgs... > w_args={}, const DataIO::Default::DefaultDecidermap< Derived > &w_deciders=DataIO::Default::default_deciders< Derived >, const DataIO::Default::DefaultTriggermap< Derived > &w_triggers=DataIO::Default::default_triggers< Derived >) | |
Constructs a Model instance. | |
const std::shared_ptr< Space > & | get_space () const |
Return the space this model resides in. | |
Time | get_time () const |
Return the current time of this model. | |
Time | get_time_max () const |
Return the maximum time possible for this model. | |
Config | get_cfg () const |
Return the config node of this model. | |
std::string | get_name () const |
Return the name of this model instance. | |
std::string | get_full_name () const |
Return the full name of this model within the model hierarchy. | |
std::shared_ptr< DataGroup > | get_hdfgrp () const |
Return a pointer to the HDF group this model stores data in. | |
Time | get_write_start () const |
Return the parameter that controls when write_data is called first. | |
Time | get_write_every () const |
Return the parameter that controls how often write_data is called. | |
DataManager | get_datamanager () const |
return the datamanager | |
hsize_t | get_remaining_num_writes () const |
Return the number of remaining write_data calls this model will make. | |
std::shared_ptr< RNG > | get_rng () const |
Return a pointer to the shared RNG. | |
std::shared_ptr< spdlog::logger > | get_logger () const |
Return a pointer to the logger of this model. | |
Monitor | get_monitor () const |
Return the monitor of this model. | |
std::shared_ptr< MonitorManager > | get_monitor_manager () const |
Get the monitor manager of the root model. | |
Level | get_level () const |
Return the hierarchical level within the model hierarchy. | |
virtual void | prolog () |
A function that is called before starting model iteration. | |
virtual void | epilog () |
A function that is called after the last iteration of a model. | |
void | iterate () |
Iterate one (time) step of this model. | |
void | run () |
Run the model from the current time to the maximum time. | |
std::shared_ptr< DataSet > | create_dset (const std::string name, const std::shared_ptr< DataGroup > &hdfgrp, std::vector< hsize_t > add_write_shape, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={}) |
Create a new dataset within the given group. | |
std::shared_ptr< DataSet > | create_dset (const std::string name, const std::vector< hsize_t > add_write_shape, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={}) |
Create a new dataset within the model's base data group. | |
template<class CellManager > | |
std::shared_ptr< DataSet > | create_cm_dset (const std::string name, const CellManager &cm, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={}) |
Create a dataset storing data from a CellManager. | |
template<class AgentManager > | |
std::shared_ptr< DataSet > | create_am_dset (const std::string name, const AgentManager &am, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={}) |
Create a dataset storing data from a AgentManager. | |
Protected Member Functions | |
void | __perform_step () |
Perform the computation of a step. | |
void | __monitor () |
Monitor information in the terminal. | |
void | __write_data () |
Write data; calls the implementation's write_data method. | |
void | __write_initial_state () |
Write the initial state. | |
void | increment_time (const Time dt=1) |
Increment time. | |
void | __prolog () |
The default prolog of a model. | |
void | __epilog () |
The default epilog of a model. | |
Derived & | impl () |
cast to the derived class | |
const Derived & | impl () const |
const cast to the derived interface | |
Protected Attributes | |
const std::string | _name |
Name of the model instance. | |
const std::string | _full_name |
The full name within the model hierarchy. | |
const Level | _level |
The level within the model hierarchy. | |
const Config | _cfg |
Config node belonging to this model instance. | |
const std::shared_ptr< RNG > | _rng |
The RNG shared between models. | |
const std::shared_ptr< spdlog::logger > | _log |
The (model) logger. | |
std::shared_ptr< Space > | _space |
The space this model resides in. | |
Time | _time |
Model-internal current time stamp. | |
const Time | _time_max |
Model-internal maximum time stamp. | |
const std::shared_ptr< DataGroup > | _hdfgrp |
The HDF group this model instance should write its data to. | |
const Time | _write_start |
First time at which write_data is called. | |
const Time | _write_every |
How often to call write_data from iterate. | |
Monitor | _monitor |
The monitor. | |
DataManager | _datamanager |
Manager object for handling data output; see DataManager. | |
Static Protected Attributes | |
static constexpr WriteMode | _write_mode = ModelTypes::write_mode |
Which data-writing mode the base model should use. | |
Private Member Functions | |
template<class Parent > | |
auto | setup_logger (const Parent &parent_model) const |
Constructs this models logger instance from the parent. | |
auto | setup_space () const |
Constructs the Space from configuration or uses the default Space. | |
void | __attach_sig_handlers () const |
Attaches signal handlers: SIGINT, SIGTERM, SIGUSR1. | |
Base class interface for Models using the CRT Pattern.
Derived | Type of the derived model class |
ModelTypes | Traits of this model, can be used for specializing |
using Utopia::Model< Derived, ModelTypes >::Config = typename ModelTypes::Config |
Data type that holds the configuration.
using Utopia::Model< Derived, ModelTypes >::DataGroup = typename ModelTypes::DataGroup |
Data type that is used for storing datasets.
using Utopia::Model< Derived, ModelTypes >::DataManager = DataIO::Default::DefaultDataManager<Derived> |
The data manager to use, specialized with the derived model.
using Utopia::Model< Derived, ModelTypes >::DataSet = typename ModelTypes::DataSet |
Data type that is used for storing data.
using Utopia::Model< Derived, ModelTypes >::Level = typename ModelTypes::Level |
Data type for the hierarchical level.
using Utopia::Model< Derived, ModelTypes >::Monitor = typename ModelTypes::Monitor |
Data type for the monitor.
using Utopia::Model< Derived, ModelTypes >::MonitorManager = typename ModelTypes::MonitorManager |
Data type for the monitor manager.
using Utopia::Model< Derived, ModelTypes >::RNG = typename ModelTypes::RNG |
Data type of the shared RNG.
using Utopia::Model< Derived, ModelTypes >::Space = typename ModelTypes::Space |
Data type of the space this model resides in.
using Utopia::Model< Derived, ModelTypes >::Time = typename ModelTypes::Time |
Data type for the model time.
|
inline |
Constructs a Model instance.
Uses information from a parent model to create a model instance.
ParentModel | The parent model's type |
name | The name of this model instance, ideally used only once on the current hierarchical level |
parent_model | The parent model object from which the corresponding config node, the group, the RNG, and the parent log level are extracted. |
custom_cfg | If given, will use this configuration node instead of trying to extract one from the parent model's configuration. |
w_args | Passed on to DataManager constructor. If not given, the DataManager will still be constructed. Take care to also set the WriteMode accordingly. |
w_deciders | Map which associates names with factory functions for deciders of signature factory()shared_ptr<Decider<Derived>> |
w_triggers | Map which associates names with factory functions for triggers of signature factory()shared_ptr<Trigger<Derived>> |
|
inlineprivate |
Attaches signal handlers: SIGINT, SIGTERM, SIGUSR1.
These signals are caught and handled such that the run method is able to finish in an ordered manner, preventing data corruption. This is done by invoking attach_signal_handler and attaching the default_signal_handler to them.
The SIGUSR1 signal is sent by the frontend if the stop conditions for this simulation are all fulfilled. It will likewise lead to the invocation of the default_signal_handler.
|
inlineprotected |
The default epilog of a model.
Default tasks: None
|
inlineprotected |
Monitor information in the terminal.
|
inlineprotected |
Perform the computation of a step.
|
inlineprotected |
The default prolog of a model.
Default tasks:
|
inlineprotected |
|
inlineprotected |
Write the initial state.
|
inline |
Create a dataset storing data from a AgentManager.
The required capacity - the shape of the dataset - is calculated using both data from the model and the AgentManager. Additionally, dimension and coordinate labels are added.
Agents are also labelled with a (trivial) ID, starting from zero.
write_dim_labels_and_coords
entry to false.name | The name of the dataset |
am | The AgentManager whose agents' states are to be stored in the dataset |
compression_level | The compression level |
chunksize | The chunk size |
|
inline |
Create a dataset storing data from a CellManager.
The required capacity - the shape of the dataset - is calculated using both data from the model and the CellManager. Additionally, dimension and coordinate labels are added.
name | The name of the dataset |
cm | The CellManager whose cells' states are to be stored in the dataset |
compression_level | The compression level |
chunksize | The chunk size |
|
inline |
Create a new dataset within the given group.
The capacity - the shape of the dataset - is calculated automatically from the num_steps and write_every parameter. Additionally, dataset attributes are set that carry information on dimension labels and coordinates.
time
dimension, as that is the only one that is known in this method. Furthermore, this assumes that it writes at write_every
and - importantly - has the first write operation at time zero. Coordinates will be wrong if that is not the case! For such cases, it is advised to suppress writing of these attributes by setting the configuration entry _cfg['write_dim_labels_and_coords'] to false.name | The name of the dataset |
hdfgrp | The parent HDFGroup |
add_write_shape | Additional write shape which, together with the number of time steps, is used to calculate the capacity of the dataset: (capacity = (num_time_steps, add_write_shape)). |
compression_level | The compression level |
chunksize | The chunk size |
|
inline |
Create a new dataset within the model's base data group.
The capacity - the shape of the dataset - is calculated automatically from the num_steps and write_every parameter. Additionally, dataset attributes are set that carry information on dimension labels and coordinates.
time
dimension, as that is the only one that is known in this method. Furthermore, this assumes that it writes at write_every
and - importantly - has the first write operation at time zero. Coordinates will be wrong if that is not the case! For such cases, it is advised to suppress writing of these attributes by setting the configuration entry _cfg['write_dim_labels_and_coords'] to false.name | The name of the dataset |
add_write_shape | Additional write shape which, together with the number of time steps, is used to calculate the capacity of the dataset: (capacity = (num_time_steps, add_write_shape)). |
compression_level | The compression level |
chunksize | The chunk size |
|
inlinevirtual |
A function that is called after the last iteration of a model.
See __epilog() for default tasks
|
inline |
Return the config node of this model.
|
inline |
return the datamanager
|
inline |
Return the full name of this model within the model hierarchy.
|
inline |
Return a pointer to the HDF group this model stores data in.
|
inline |
Return the hierarchical level within the model hierarchy.
|
inline |
Return a pointer to the logger of this model.
|
inline |
Return the monitor of this model.
|
inline |
Get the monitor manager of the root model.
|
inline |
Return the name of this model instance.
|
inline |
Return the number of remaining write_data
calls this model will make.
The 'remaining' refers to the current time being included into the calculation, e.g.: when writing every time, currently at time == 42 and time_max == 43, it will return the value 2, i.e. for the write operations at times 42 and 43
|
inline |
Return a pointer to the shared RNG.
|
inline |
Return the space this model resides in.
|
inline |
Return the current time of this model.
|
inline |
Return the maximum time possible for this model.
|
inline |
Return the parameter that controls how often write_data is called.
|
inline |
Return the parameter that controls when write_data is called first.
|
inlineprotected |
cast to the derived class
|
inlineprotected |
const cast to the derived interface
|
inlineprotected |
|
inline |
Iterate one (time) step of this model.
Increment time, perform step, emit monitor data, and write data. Monitoring is performed differently depending on the model level. The write_data method is called depending on the configured value for the write_mode
(template parameter) and (if in mode basic
): the configuration parameters write_start
and write_every
.
|
inlinevirtual |
A function that is called before starting model iteration.
See __prolog() for default tasks
|
inline |
Run the model from the current time to the maximum time.
This repeatedly calls the iterate method until the maximum time is reached. Additionally, it calls the __write_data
method to allow it to write the initial state. In write mode basic
, this is only done if _write_start == _time
.
|
inlineprivate |
Constructs this models logger instance from the parent.
Also directly sets the log level from the log_level
config entry.
|
inlineprivate |
Constructs the Space from configuration or uses the default Space.
|
protected |
Config node belonging to this model instance.
|
protected |
Manager object for handling data output; see DataManager.
_write_mode
was set to WriteMode::managed.
|
protected |
The full name within the model hierarchy.
|
protected |
The HDF group this model instance should write its data to.
|
protected |
The level within the model hierarchy.
|
protected |
The (model) logger.
|
protected |
The monitor.
|
protected |
Name of the model instance.
|
protected |
The RNG shared between models.
|
protected |
The space this model resides in.
|
protected |
Model-internal current time stamp.
|
protected |
Model-internal maximum time stamp.
|
protected |
How often to call write_data from iterate.
|
staticconstexprprotected |
Which data-writing mode the base model should use.
|
protected |
First time at which write_data is called.