garage.experiment.snapshotter module

Defines SnapshotConfig and Snapshotter.

exception NotAFileError[source]

Bases: Exception

Raise when the snapshot is not a file.

class SnapshotConfig(snapshot_dir, snapshot_mode, snapshot_gap)

Bases: tuple

snapshot_dir

Alias for field number 0

snapshot_gap

Alias for field number 2

snapshot_mode

Alias for field number 1

class Snapshotter(snapshot_dir='/home/docs/checkouts/readthedocs.org/user_builds/garage/checkouts/v2020.06.3/docs/data/local/experiment', snapshot_mode='last', snapshot_gap=1)[source]

Bases: object

Snapshotter snapshots training data.

When training, it saves data to binary files. When resuming, it loads from saved data.

Parameters:
  • snapshot_dir (str) – Path to save the log and iteration snapshot.
  • snapshot_mode (str) – Mode to save the snapshot. Can be either “all” (all iterations will be saved), “last” (only the last iteration will be saved), “gap” (every snapshot_gap iterations are saved), or “none” (do not save snapshots).
  • snapshot_gap (int) – Gap between snapshot iterations. Wait this number of iterations before taking another snapshot.
load(load_dir, itr='last')[source]

Load one snapshot of parameters from disk.

Parameters:
  • load_dir (str) – Directory of the cloudpickle file to resume experiment from.
  • itr (int or string) – Iteration to load. Can be an integer, ‘last’ or ‘first’.
Returns:

Loaded snapshot.

Return type:

dict

Raises:
  • ValueError – If itr is neither an integer nor one of (“last”, “first”).
  • FileNotFoundError – If the snapshot file is not found in load_dir.
  • NotAFileError – If the snapshot exists but is not a file.
save_itr_params(itr, params)[source]

Save the parameters if at the right iteration.

Parameters:
  • itr (int) – Number of iterations. Used as the index of snapshot.
  • params (obj) – Content of snapshot to be saved.
Raises:

ValueError – If snapshot_mode is not one of “all”, “last” or “gap”.

snapshot_dir

Return the directory of snapshot.

Returns:The directory of snapshot
Return type:str
snapshot_gap

Return the gap number of snapshot.

Returns:The gap number of snapshot.
Return type:int
snapshot_mode

Return the type of snapshot.

Returns:The type of snapshot. Can be “all”, “last” or “gap”
Return type:str