class_docstr: An implementation of the data store using S3 for storing policy checkpoints when using Coach in distributed mode.
  The policy checkpoints are written by the trainer and read by the rollout worker.
class_docstr_tok: ["An","implementation","of","the","data","store","using","S3","for","storing","policy","checkpoints","when","using","Coach","in","distributed","mode",".","The","policy","checkpoints","are","written","by","the","trainer","and","read","by","the","rollout","worker","."]
docstr: save_to_store() uploads the policy checkpoint, gifs and videos to the S3 data store. It reads the checkpoint state files and
  uploads only the latest checkpoint files to S3. It is used by the trainer in Coach when used in the distributed mode.
docstr_tok: ["save_to_store","(",")","uploads","the","policy","checkpoint",",","gifs","and","videos","to","the","S3","data","store",".","It","reads","the","checkpoint","state","files","and","uploads","only","the","latest","checkpoint","files","to","S3",".","It","is","used","by","the","trainer","in","Coach","when","used","in","the","distributed","mode","."]
code: def _save_to_store(self, checkpoint_dir):
      """
      save_to_store() uploads the policy checkpoint, gifs and videos to the S3 data store. It reads the checkpoint state files and
      uploads only the latest checkpoint files to S3. It is used by the trainer in Coach when used in the distributed mode.
      """
      try:
          # remove lock file if it exists
          self.mc.remove_object(
              self.params.bucket_name, SyncFiles.LOCKFILE.value
          )
  
          # Acquire lock
          self.mc.put_object(
              self.params.bucket_name,
              SyncFiles.LOCKFILE.value,
              io.BytesIO(b""),
              0,
          )
  
          state_file = CheckpointStateFile(
              os.path.abspath(checkpoint_dir)
          )
          if state_file.exists():
              ckpt_state = state_file.read()
              checkpoint_file = None
              for root, dirs, files in os.walk(checkpoint_dir):
                  for filename in files:
                      if (
                          filename
                          == CheckpointStateFile.checkpoint_state_filename
                      ):
                          checkpoint_file = (root, filename)
                          continue
                      if filename.startswith(ckpt_state.name):
                          abs_name = os.path.abspath(
                              os.path.join(root, filename)
                          )
                          rel_name = os.path.relpath(
                              abs_name, checkpoint_dir
                          )
                          self.mc.fput_object(
                              self.params.bucket_name,
                              rel_name,
                              abs_name,
                          )
  
              abs_name = os.path.abspath(
                  os.path.join(checkpoint_file[0], checkpoint_file[1])
              )
              rel_name = os.path.relpath(abs_name, checkpoint_dir)
              self.mc.fput_object(
                  self.params.bucket_name, rel_name, abs_name
              )
  
          # upload Finished if present
          if os.path.exists(
              os.path.join(checkpoint_dir, SyncFiles.FINISHED.value)
          ):
              self.mc.put_object(
                  self.params.bucket_name,
                  SyncFiles.FINISHED.value,
                  io.BytesIO(b""),
                  0,
              )
  
          # upload Ready if present
          if os.path.exists(
              os.path.join(
                  checkpoint_dir, SyncFiles.TRAINER_READY.value
              )
          ):
              self.mc.put_object(
                  self.params.bucket_name,
                  SyncFiles.TRAINER_READY.value,
                  io.BytesIO(b""),
                  0,
              )
  
          # release lock
          self.mc.remove_object(
              self.params.bucket_name, SyncFiles.LOCKFILE.value
          )
  
          if self.params.expt_dir and os.path.exists(
              self.params.expt_dir
          ):
              for filename in os.listdir(self.params.expt_dir):
                  if filename.endswith((".csv", ".json")):
                      self.mc.fput_object(
                          self.params.bucket_name,
                          filename,
                          os.path.join(self.params.expt_dir, filename),
                      )
  
          if self.params.expt_dir and os.path.exists(
              os.path.join(self.params.expt_dir, "videos")
          ):
              for filename in os.listdir(
                  os.path.join(self.params.expt_dir, "videos")
              ):
                  self.mc.fput_object(
                      self.params.bucket_name,
                      filename,
                      os.path.join(
                          self.params.expt_dir, "videos", filename
                      ),
                  )
  
          if self.params.expt_dir and os.path.exists(
              os.path.join(self.params.expt_dir, "gifs")
          ):
              for filename in os.listdir(
                  os.path.join(self.params.expt_dir, "gifs")
              ):
                  self.mc.fput_object(
                      self.params.bucket_name,
                      filename,
                      os.path.join(
                          self.params.expt_dir, "gifs", filename
                      ),
                  )
  
      except S3Error as e:
          screen.print("Got exception: %s\n while saving to S3", e)
  
imports: from rl_coach.data_stores.data_store import DataStoreParameters
  from rl_coach.data_stores.checkpoint_data_store import CheckpointDataStore
  from minio import Minio
  from minio.error import S3Error
  from configparser import ConfigParser, Error
  from rl_coach.checkpoint import CheckpointStateFile
  from rl_coach.data_stores.data_store import SyncFiles
  from rl_coach.logger import screen
  import os
  import time
  import io
label_desc: Use image node_id 6 for calling the S3DataStore obj's underlying member method code with example usage: obj._save_to_store(checkpoint_dir) without return types