Persistence¶
deap_er.Checkpoint(file_name=None, dir_path=None, autoload=True, make_dir=True, raise_errors=False, hof_ind_cls=None)
¶
Save and load evolution progress with dill.
Only attributes set on the checkpoint instance are written. The library RNG state (buffered uniforms, leftover integers, and Generator) is persisted as well. The target file is chosen at construction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name
|
str | None
|
Checkpoint file name. Defaults to a random UUID
with a |
None
|
dir_path
|
Path | None
|
Directory for the file. Defaults to
|
None
|
autoload
|
bool
|
If True and the file exists, load it during
initialization. A missing file is not an error, even with
|
True
|
make_dir
|
bool
|
If True, create missing parent directories on save. Defaults to True. |
True
|
raise_errors
|
bool
|
If True, propagate I/O and pickle errors.
Otherwise |
False
|
hof_ind_cls
|
type[Any] | None
|
Creator individual type used to rebuild
|
None
|
See the class docstring for argument meanings.
Source code in deap_er/private/checkpoint.py
save_freq
property
writable
¶
Seconds between automatic saves during range().
-1 disables saving. The default is 60 seconds.
Returns:
| Type | Description |
|---|---|
float
|
The current period in seconds. |
last_op
property
¶
Status of the last load or save.
One of none, load_success, load_error,
save_success, or save_error.
__getattr__(name)
¶
__setattr__(name, value)
¶
load()
¶
Load attributes from the checkpoint file onto this instance.
The file is read and validated before anything changes. A failed load leaves the instance and the library RNG untouched.
Returns:
| Type | Description |
|---|---|
bool
|
True on success, False on failure when |
Raises:
| Type | Description |
|---|---|
OSError
|
If the file cannot be read and |
CheckpointError
|
If the file is not a loadable checkpoint and
|
Source code in deap_er/private/checkpoint.py
save()
¶
Write this instance's attributes to the checkpoint file.
Overwrites an existing file through a uniquely named staging
file that is fsynced before the rename, so concurrent writers
and power loss never leave a torn checkpoint. Creates parent
directories when make_dir is True.
Returns:
| Type | Description |
|---|---|
bool
|
True on success, False on failure when |
Raises:
| Type | Description |
|---|---|
OSError
|
If the file cannot be written and |
Exception
|
Whatever serialization raises (for example
|
Source code in deap_er/private/checkpoint.py
range(generations)
¶
Yield generation indices, saving periodically when enabled.
Continues from the last stored counter. When save_freq is
not -1, the checkpoint is written about every
save_freq seconds and once more after the last yield.
save_freq may be changed while iterating.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
generations
|
int
|
Number of generations to yield. |
required |
Returns:
| Type | Description |
|---|---|
Iterator[int]
|
A generator of integer generation indices. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/checkpoint.py
is_loaded()
¶
Return whether the last operation was a successful load.
Returns:
| Type | Description |
|---|---|
bool
|
True if |
is_saved()
¶
Return whether the last operation was a successful save.
Returns:
| Type | Description |
|---|---|
bool
|
True if |