code: def should_checkpoint(self):
          
          result = self.last_result or {}
  
          if result.get(DONE) and self.checkpoint_at_end:
              return True
  
          if self.checkpoint_freq:
              return result.get(TRAINING_ITERATION,
                                0) % self.checkpoint_freq == 0
          else:
              return False
docs: Whether this trial is due for checkpointing.