rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
List of all members | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes
Greedy.Checkpoint Class Reference

Detailed Description

Helper class used to store and restore data tree objects at specified checkpoints.

This class can be used for checkpointing. The most prominent use case is the ReducedModel.gen_detailed_data() method. When this method is called, checkpoints are created after each bigger basis extension step at which the generated detailed_data is stored. Each of these Afterwards the checkpoint can be re-read from the harddrive like this:

ids = Checkpoint.get_ids(rmodel)
[detailed_data, cp] = Checkpoint.restore(rmodel, ids(1), 'latest');

Instead of latest one could also have used a file index. See file_rotation_size and store() for more details on this.

Definition at line 18 of file Checkpoint.m.

Public Member Functions

 Checkpoint (Greedy.Checkpoint old, index)
 creates a new checkpoint More...
 
function dd = restore_detailed_data (model, cp_index)
 
function ret = get (field, default)
 access function for user data stored in a Checkpoint instance More...
 
function Checkpoint
child = 
child (index)
 is called when a new Checkpoint instance for the child of a DataTree.INode instance shall be generated. More...
 
function Greedy.Checkpoint cp = store (model,DataTree.INode detailed_data, id, ud)
 stores a DataTree.INode tree on the harddrive and attaches a descriptive text and user data. More...
 

Static Public Member Functions

static function [
dd
, cp ] = 
restore_latest_if_available (model, id)
 
static function [
DataTree.INode dd
, Greedy.Checkpoint cp ] = 
restore (model, id, cp_index)
 restores a check point by a descriptive text and a checkpoint index More...
 
static function cpfn = filename (model, id, cp_index)
 
static function  clear_old_checkpoints (IReducedModel model, num_left)
 clears data files in a checkpoint directory More...
 
static function fp = basepath ()
 returns the basepath for storage of Greedy.Checkpoint instances on the hdd. More...
 
static function fp = filepath (IReducedModel rmodel, id)
 computes a file path from the rmodel hash and an id More...
 
static function idsget_ids (IReducedModel rmodel)
 returns a list of possible ids to restore for a reduced model. More...
 
static function mhash = compute_hash (descr)
 computes an md5 hash string from the model description used to identify it over a file name. More...
 
static function str = stringify (x)
 helper function to make strings out of function_handle, cell and other objects. More...
 
static function ec = static_flags (flag, nec)
 

Public Attributes

 enable_auto_restore = 1
 persistent value for all Checkpoint instances controlling whether checkpoint is enabled or not. More...
 
 enable_storing = true
 
 file_rotation_size = 5
 maximum number of files stored in one directory in parallel. More...
 
 level = 1
 The level indicates which level in a data tree of DataTree.INode instances can be (re)stored by this Checkpoint instance. More...
 
 data_index = {"[]"}
 A cell array of indices as returned by DataTree.INode.get_index() defining the index of the stored DataTree.INode instance with respect to the root element of the tree. More...
 
 userdata = {"[]"}
 a cell array of arbitrary userdata stored with each DataTree.INode node. More...
 
 ids = {"''"}
 a cell array of id strings which describes the DataTree.INode instance or the algorithm which generates it. More...
 
 filenames = {"''"}
 a cell array of filenames where the DataTree.INode children are stored. More...
 

Static Public Attributes

static const  ignorelist
 list of values ignored for hash computation by compute_hash() More...
 

Constructor & Destructor Documentation

Greedy.Checkpoint.Checkpoint ( Greedy.Checkpoint  old,
  index 
)

creates a new checkpoint

Parameters
oldan object whose checkpoint data is copied or included in the newly created checkpoint.
indexif this is empty, argument old is copied, otherwise a new Checkpoint of level old.level+1 is created with data fields.
Required fields of old:
  • level —  level
  • userdata —  userdata
  • ids —  ids
  • data_index —  data index
  • filenames —  filenames

Definition at line 152 of file Checkpoint.m.

Member Function Documentation

function fp = Greedy.Checkpoint.basepath ( )
static

returns the basepath for storage of Greedy.Checkpoint instances on the hdd.

Return values
fpstring of file path to base directory.

Definition at line 470 of file Checkpoint.m.

Here is the caller graph for this function:

function Checkpoint child = Greedy.Checkpoint.child (   index)

is called when a new Checkpoint instance for the child of a DataTree.INode instance shall be generated.

The child must be a DataTree.INode itself.

Parameters
indexa scalar indicating the father child-relationship. child must be the index-th child of father.
Return values
childthe created instance

Definition at line 274 of file Checkpoint.m.

function Greedy.Checkpoint.clear_old_checkpoints ( IReducedModel  model,
  num_left 
)
static

clears data files in a checkpoint directory

The filepath is generated from the argument model.

Parameters
modelan object .
num_leftnumber of files to be left in the directory. (Default = 0)
Required fields of model:
  • descr —  descr

Definition at line 427 of file Checkpoint.m.

Here is the call graph for this function:

function mhash = Greedy.Checkpoint.compute_hash (   descr)
static

computes an md5 hash string from the model description used to identify it over a file name.

Parameters
descra structure describing the model.
Return values
mhasha string of the hash key computed.
Required fields of descr:
  • mu_names —  mu names
  • filecache_ignore_fields_in_model —  filecache ignore fields in model

Definition at line 524 of file Checkpoint.m.

Here is the call graph for this function:

Here is the caller graph for this function:

function fp = Greedy.Checkpoint.filepath ( IReducedModel  rmodel,
  id 
)
static

computes a file path from the rmodel hash and an id

Parameters
rmodelan object
idid strings which describes the DataTree.INode instance or the algorithm which generates it.
Return values
fpstring of file path to the directory where data is stored.
Required fields of rmodel:
  • descr —  descr

Definition at line 481 of file Checkpoint.m.

Here is the call graph for this function:

Here is the caller graph for this function:

function ret = Greedy.Checkpoint.get (   field,
  default 
)

access function for user data stored in a Checkpoint instance

Parameters
fieldname of a field in the userdata structure of this level.
defaultThis value is returned if the field does not exist in the userdata structure.
Return values
retThis returns the value of the userdata field.

Definition at line 252 of file Checkpoint.m.

function ids = Greedy.Checkpoint.get_ids ( IReducedModel  rmodel)
static

returns a list of possible ids to restore for a reduced model.

Parameters
rmodelan object
Return values
idsa cell array of possible ids to restore.

Definition at line 503 of file Checkpoint.m.

Here is the call graph for this function:

function [ DataTree.INode dd , Greedy.Checkpoint cp ] = Greedy.Checkpoint.restore (   model,
  id,
  cp_index 
)
static

restores a check point by a descriptive text and a checkpoint index

Parameters
modelmodel
idthe descriptive id string used when storing the DataTree.INode with store().
cp_indexan file index between 1 and file_rotation_size or the string latest. (Default = lastest)
Return values
ddrestored object . Note, that is the root of a data tree even if the id argument refers to a child of it.
cpan object restored together with the dd object.
Generated fields of cp:
  • level —  level

Definition at line 363 of file Checkpoint.m.

Here is the call graph for this function:

function Greedy.Checkpoint cp = Greedy.Checkpoint.store (   model,
DataTree.INode  detailed_data,
  id,
  ud 
)

stores a DataTree.INode tree on the harddrive and attaches a descriptive text and user data.

The directory where the data is stored is computed via Greedy.Checkpoint.filepath() from the model argument.

Note
The stored DataTree.INode knows its fathers, such that it can be embedded in a full DataTree.INode tree by restore().
Parameters
modelan object or type IReducedModel
detailed_dataan object to be stored on the harddrive
idid strings which describes the DataTree.INode instance or the algorithm which generates it.
udarbitrary user data to stored with this checkpoint.
Return values
cphandle object pointing to the changed Checkpoint instance.

Definition at line 293 of file Checkpoint.m.

Here is the call graph for this function:

Here is the caller graph for this function:

function str = Greedy.Checkpoint.stringify (   x)
static

helper function to make strings out of function_handle, cell and other objects.

This function is utilized by the compute_hash() method.

Parameters
xan arbitrary object from which a string shall be computed.
Return values
strthe string

Definition at line 552 of file Checkpoint.m.

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

Greedy.Checkpoint.data_index = {"[]"}

A cell array of indices as returned by DataTree.INode.get_index() defining the index of the stored DataTree.INode instance with respect to the root element of the tree.

Todo:
: Why do I not store a single vector


Default: {"[]"}

Definition at line 108 of file Checkpoint.m.

Greedy.Checkpoint.enable_auto_restore = 1

persistent value for all Checkpoint instances controlling whether checkpoint is enabled or not.

Note
This property has the MATLAB attribute Dependent set to true.
Matlab documentation of property attributes.
Default: 1

Definition at line 63 of file Checkpoint.m.

Greedy.Checkpoint.file_rotation_size = 5

maximum number of files stored in one directory in parallel.

If this limit is reached, the oldest file is deleted before a new Checkpoint.store() is executed.


Default: 5

Definition at line 82 of file Checkpoint.m.

Greedy.Checkpoint.filenames = {"''"}

a cell array of filenames where the DataTree.INode children are stored.


Default: {"''"}

Definition at line 140 of file Checkpoint.m.

Greedy.Checkpoint.ids = {"''"}

a cell array of id strings which describes the DataTree.INode instance or the algorithm which generates it.


Default: {"''"}

Definition at line 130 of file Checkpoint.m.

Greedy.Checkpoint.ignorelist
static
Initial value:
= {"'Mmax','MM','Mstrich','ei_Mmax','Mmax','M','N','Nmax', \
'verbose','debug', \
'enable_error_estimator' \
"}

list of values ignored for hash computation by compute_hash()

Note
This property has the MATLAB attribute Hidden set to true.
Matlab documentation of property attributes.
Default: {"'Mmax','MM','Mstrich','ei_Mmax','Mmax','M','N','Nmax', \ 'verbose','debug', \ 'enable_error_estimator' \ "}

Definition at line 43 of file Checkpoint.m.

Greedy.Checkpoint.level = 1

The level indicates which level in a data tree of DataTree.INode instances can be (re)stored by this Checkpoint instance.

Level 1 corresponds to the root element of the data tree, level 2 to a child of the root, level 3 to a child of a child of the root element, ...


Default: 1

Definition at line 94 of file Checkpoint.m.

Greedy.Checkpoint.userdata = {"[]"}

a cell array of arbitrary userdata stored with each DataTree.INode node.


Default: {"[]"}

Definition at line 121 of file Checkpoint.m.


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