7. Milestone

The milestone provides a way to save the state of some specified objects all the way through the evolution.

class eap.milestone.Milestone([yaml, object[, ...]])

A milestone is a file containing the state of any object that has been hooked. While initializing a milestone, add the objects that you want to be dumped by appending keyworded arguments to the initializer or using the add(). By default the milestone tries to use the YAML format wich is human readable, if PyYAML is not installed, it uses pickling wich is not readable. You can force the use of pickling by setting the argument yaml to False.

In order to use efficiently this module, you must understand properly the assignement principles in Python. This module use the pointers you passed to dump the object, for example the following won’t work as desired

>>> my_object = [1, 2, 3]
>>> ms = Milestone(obj=my_object)
>>> my_object = [3, 5, 6]
>>> ms.dump("example")
>>> ms.load("example.ems")
>>> ms["obj"]
[1, 2, 3]

In order to dump the new value of my_object it is needed to change its internal values directly and not touch the label, as in the following

>>> my_object = [1, 2, 3]
>>> ms = Milestone(obj=my_object)
>>> my_object[:] = [3, 5, 6]
>>> ms.dump("example")
>>> ms.load("example.ems")
>>> ms["obj"]
[3, 5, 6]
dump(prefix)

Dump the current registered objects in a file named prefix.ems, the randomizer state is always added to the file and available under the "randomizer_state" tag.

load(filename)

Load a milestone file retreiving the dumped objects, it is not safe to load a milestone file in a milestone object that contians references as all conflicting names will be updated with the new values.

add(object[, ...])

Add objects to the list of objects to be dumped. The object is added under the name specified by the argument’s name. Keyworded arguments are mandatory in this function.

remove(object[, ...])

Remove objects with the specified name from the list of objects to be dumped.

Previous topic

6. Hall of Fame

Next topic

8. History

This Page