class_docstr: Convenience class for periodically checkpointing.
  
  This can be used to checkpoint any object with trackable state (e.g.
  tensorflow variables or modules); see tf.train.Checkpoint for
  details. Objects inheriting from tf.train.experimental.PythonState can also
  be checkpointed.
  
  Typically people use Checkpointer to make sure that they can correctly recover
  from a machine going down during learning. For more permanent storage of self-
  contained "networks" see the Snapshotter object.
  
  Usage example:
  
  ```python
  model = snt.Linear(10)
  checkpointer = Checkpointer(objects_to_save={'model': model})
  
  for _ in range(100):
    # ...
    checkpointer.save()
  ```
class_docstr_tok: ["Convenience","class","for","periodically","checkpointing",".","This","can","be","used","to","checkpoint","any","object","with","trackable","state","(","e.g",".","tensorflow","variables","or","modules",")",";","see","tf.train.Checkpoint","for","details",".","Objects","inheriting","from","tf.train.experimental.PythonState","can","also","be","checkpointed",".","Typically","people","use","Checkpointer","to","make","sure","that","they","can","correctly","recover","from","a","machine","going","down","during","learning",".","For","more","permanent","storage","of","self-","contained","``","networks","''","see","the","Snapshotter","object",".","Usage","example",":","``","`","python","model","=","snt.Linear","(","10",")","checkpointer","=","Checkpointer","(","objects_to_save=","{","'model","'",":","model","}",")","for","_","in","range","(","100",")",":","#","...","checkpointer.save","(",")","``","`"]
docstr: Builds the saver object.
  
  Args:
    objects_to_save: Mapping specifying what to checkpoint.
    directory: Which directory to put the checkpoint in.
    subdirectory: Sub-directory to use (e.g. if multiple checkpoints are being
      saved).
    time_delta_minutes: How often to save the checkpoint, in minutes.
    enable_checkpointing: whether to checkpoint or not.
    add_uid: If True adds a UID to the checkpoint path, see
      `paths.get_unique_id()` for how this UID is generated.
    max_to_keep: The maximum number of checkpoints to keep.
    checkpoint_ttl_seconds: TTL (time to leave) in seconds for checkpoints.
    keep_checkpoint_every_n_hours: keep_checkpoint_every_n_hours passed to
      tf.train.CheckpointManager.
docstr_tok: ["Builds","the","saver","object",".","Args",":","objects_to_save",":","Mapping","specifying","what","to","checkpoint",".","directory",":","Which","directory","to","put","the","checkpoint","in",".","subdirectory",":","Sub-directory","to","use","(","e.g",".","if","multiple","checkpoints","are","being","saved",")",".","time_delta_minutes",":","How","often","to","save","the","checkpoint",",","in","minutes",".","enable_checkpointing",":","whether","to","checkpoint","or","not",".","add_uid",":","If","True","adds","a","UID","to","the","checkpoint","path",",","see","`","paths.get_unique_id","(",")","`","for","how","this","UID","is","generated",".","max_to_keep",":","The","maximum","number","of","checkpoints","to","keep",".","checkpoint_ttl_seconds",":","TTL","(","time","to","leave",")","in","seconds","for","checkpoints",".","keep_checkpoint_every_n_hours",":","keep_checkpoint_every_n_hours","passed","to","tf.train.CheckpointManager","."]
code: def __init__(
      self,
      objects_to_save: Mapping[
          str, Union[Checkpointable, core.Saveable]
      ],
      *,
      directory: str = "~/acme/",
      subdirectory: str = "default",
      time_delta_minutes: float = 10.0,
      enable_checkpointing: bool = True,
      add_uid: bool = True,
      max_to_keep: int = 1,
      checkpoint_ttl_seconds: Optional[int] = _DEFAULT_CHECKPOINT_TTL,
      keep_checkpoint_every_n_hours: Optional[int] = None,
  ):
      """Builds the saver object.
  
      Args:
        objects_to_save: Mapping specifying what to checkpoint.
        directory: Which directory to put the checkpoint in.
        subdirectory: Sub-directory to use (e.g. if multiple checkpoints are being
          saved).
        time_delta_minutes: How often to save the checkpoint, in minutes.
        enable_checkpointing: whether to checkpoint or not.
        add_uid: If True adds a UID to the checkpoint path, see
          `paths.get_unique_id()` for how this UID is generated.
        max_to_keep: The maximum number of checkpoints to keep.
        checkpoint_ttl_seconds: TTL (time to leave) in seconds for checkpoints.
        keep_checkpoint_every_n_hours: keep_checkpoint_every_n_hours passed to
          tf.train.CheckpointManager.
      """
  
      # Convert `Saveable` objects to TF `Checkpointable` first, if necessary.
      def to_ckptable(
          x: Union[Checkpointable, core.Saveable]
      ) -> Checkpointable:
          if isinstance(x, core.Saveable):
              return SaveableAdapter(x)
          return x
  
      objects_to_save = {
          k: to_ckptable(v) for k, v in objects_to_save.items()
      }
  
      self._time_delta_minutes = time_delta_minutes
      self._last_saved = 0.0
      self._enable_checkpointing = enable_checkpointing
      self._checkpoint_manager = None
  
      if enable_checkpointing:
          # Checkpoint object that handles saving/restoring.
          self._checkpoint = tf.train.Checkpoint(**objects_to_save)
          self._checkpoint_dir = paths.process_path(
              directory,
              "checkpoints",
              subdirectory,
              ttl_seconds=checkpoint_ttl_seconds,
              backups=False,
              add_uid=add_uid,
          )
  
          # Create a manager to maintain different checkpoints.
          self._checkpoint_manager = tf.train.CheckpointManager(
              self._checkpoint,
              directory=self._checkpoint_dir,
              max_to_keep=max_to_keep,
              keep_checkpoint_every_n_hours=keep_checkpoint_every_n_hours,
          )
  
          self.restore()
  
imports: import abc
  import datetime
  import os
  import pickle
  import time
  from typing import Mapping, Optional, Union
  from absl import logging
  from acme import core
  from acme.utils import signals
  from acme.utils import paths
  import sonnet
  import tensorflow
  import tree
  from tensorflow.python.saved_model import revived_types
label_desc: Use image node_id 1 to create a new Checkpointer object  with example: obj = Checkpointer(objects_to_save)