State Persistence
- class Checkpoint(file_name=None, dir_path=None, autoload=True, make_dir=True, raise_errors=False)
This class can be used to save and load evolution progress to and from files. It’s implemented as a lightweight wrapper around the builtin
open()function. Objects are (de-)serialized using the dill library. Only those objects which have been set as attributes of the checkpoint object are persisted to disk. The target save file is assigned on object instantiation. Checkpoint objects automatically persist also the RNG states of therandomandnumpy.randommodules.- Parameters
file_name (Optional[str]) – The name of the checkpoint file. By default, a random UUID +
.dcpfextension is used.dir_path (Optional[Path]) – The path to the checkpoint directory. By default, the current working directory +
/deap-eris used.autoload (Optional[bool]) – If True and the checkpoint file exists, loads the file during initialization, optional. The default value is True.
make_dir (Optional[bool]) – If True, the target directory is recursively created on save, if it does not exist. The default value is True.
raise_errors (Optional[bool]) – If True, errors are propagated, optional. By default, errors are not propagated and False is returned instead.
- load()
Loads objects from the checkpoint file and sets them as attributes of
self.
- save()
Saves the attributes of
selfinto the checkpoint file. If the file already exists, it will be overwritten. If the target directory does not exist, it will be created recursively.
- range(generations)
A special generator method that behaves almost like the builtin
range()function, but it accepts only a single argument of the number of generations to compute. It is intended to be used in aforloop to iterate over the main evolutionary process. The checkpoint is saved to disk everyself.save_freqseconds and also at the end of the loop, if saving is enabled. The saving frequency can be changed while theforloop is running. The values of the range counter are automatically determined from the current (loaded) state of the checkpoint object.
- property save_freq: float
The time in seconds after which to periodically save the checkpoint to a file, when the
range()function is being executed in aforloop. Setting the value to-1disables saving. Acceptsintandfloattypes as values. Float-types allow sub-second timing precision.- Returns
The current saving frequency period, in seconds. The default value is 60 seconds.
- property last_op: str
- Returns the status of the last operation performed on the checkpoint object.Possible string-type return values are:
none
load_success
load_error
save_success
save_error
- is_loaded()
Shorthand for
checkpoint.last_op == 'load_success'.- Returns
True if the checkpoint was successfully loaded from file.
- Return type