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:
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 | |
function dd = | restore_detailed_data (model, cp_index) |
function ret = | get (field, default) |
access function for user data stored in a Checkpoint instance | |
function Checkpoint child = | child (index) |
is called when a new Checkpoint instance for the child of a DataTree.INode instance shall be generated. | |
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. | |
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 | |
static function cpfn = | filename (model, id, cp_index) |
static function | clear_old_checkpoints (IReducedModel model, num_left) |
clears data files in a checkpoint directory | |
static function fp = | basepath () |
returns the basepath for storage of Greedy.Checkpoint instances on the hdd. | |
static function fp = | filepath (IReducedModel rmodel, id) |
computes a file path from the rmodel hash and an id | |
static function ids = | get_ids (IReducedModel rmodel) |
returns a list of possible ids to restore for a reduced model. | |
static function mhash = | compute_hash (descr) |
computes an md5 hash string from the model description used to identify it over a file name. | |
static function str = | stringify (x) |
helper function to make strings out of function_handle, cell and other objects. | |
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. | |
enable_storing = true | |
file_rotation_size = 5 | |
maximum number of files stored in one directory in parallel. | |
level = 1 | |
The level indicates which level in a data tree of DataTree.INode instances can be (re)stored by this Checkpoint instance. | |
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. | |
userdata = {"[]"} | |
a cell array of arbitrary userdata stored with each DataTree.INode node. | |
ids = {"''"} | |
a cell array of id strings which describes the DataTree.INode instance or the algorithm which generates it. | |
filenames = {"''"} | |
a cell array of filenames where the DataTree.INode children are stored. | |
Static Public Attributes | |
static const | ignorelist |
list of values ignored for hash computation by compute_hash() | |
Greedy.Checkpoint.Checkpoint | ( | Greedy.Checkpoint | old, |
index | |||
) |
creates a new checkpoint
old | an object whose checkpoint data is copied or included in the newly created checkpoint. |
index | if this is empty, argument old is copied, otherwise a new Checkpoint of level old.level+1 is created with data fields. |
level —
level userdata —
userdata ids —
ids data_index —
data index filenames —
filenames Definition at line 152 of file Checkpoint.m.
|
static |
returns the basepath for storage of Greedy.Checkpoint instances on the hdd.
fp | string of file path to base directory. |
Definition at line 470 of file Checkpoint.m.
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.
index | a scalar indicating the father child-relationship. child must be the index -th child of father. |
child | the created instance |
Definition at line 274 of file Checkpoint.m.
|
static |
clears data files in a checkpoint directory
The filepath is generated from the argument model
.
model | an object . |
num_left | number of files to be left in the directory. (Default = 0) |
descr —
descr Definition at line 427 of file Checkpoint.m.
|
static |
computes an md5 hash string from the model description used to identify it over a file name.
descr | a structure describing the model. |
mhash | a string of the hash key computed. |
mu_names —
mu names filecache_ignore_fields_in_model —
filecache ignore fields in model Definition at line 524 of file Checkpoint.m.
|
static |
computes a file path from the rmodel hash and an id
rmodel | an object |
id | id strings which describes the DataTree.INode instance or the algorithm which generates it. |
fp | string of file path to the directory where data is stored. |
descr —
descr Definition at line 481 of file Checkpoint.m.
function ret = Greedy.Checkpoint.get | ( | field, | |
default | |||
) |
access function for user data stored in a Checkpoint instance
field | name of a field in the userdata structure of this level. |
default | This value is returned if the field does not exist in the userdata structure. |
ret | This returns the value of the userdata field. |
Definition at line 252 of file Checkpoint.m.
|
static |
returns a list of possible ids
to restore for a reduced model.
rmodel | an object |
ids | a cell array of possible ids to restore. |
Definition at line 503 of file Checkpoint.m.
|
static |
restores a check point by a descriptive text and a checkpoint index
model | model |
id | the descriptive id string used when storing the DataTree.INode with store(). |
cp_index | an file index between 1 and file_rotation_size or the string latest . (Default = lastest ) |
dd | restored object . Note, that is the root of a data tree even if the id argument refers to a child of it. |
cp | an object restored together with the dd object. |
level —
level Definition at line 363 of file Checkpoint.m.
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.
model | an object or type IReducedModel |
detailed_data | an object to be stored on the harddrive |
id | id strings which describes the DataTree.INode instance or the algorithm which generates it. |
ud | arbitrary user data to stored with this checkpoint. |
cp | handle object pointing to the changed Checkpoint instance. |
Definition at line 293 of file Checkpoint.m.
|
static |
helper function to make strings out of function_handle, cell and other objects.
This function is utilized by the compute_hash() method.
x | an arbitrary object from which a string shall be computed. |
str | the string |
Definition at line 552 of file Checkpoint.m.
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.
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.
Dependent
set to true. 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.
|
static |
list of values ignored for hash computation by compute_hash()
Hidden
set to true. 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.