code: def test_save_and_load(self, capacity):
      tempdir = tempfile.mkdtemp()
  
      rbuf = PersistentEpisodicReplayBuffer(self.tempdir.name, capacity)
  
      transs = [
          dict(
              state=n,
              action=n + 10,
              reward=n + 20,
              next_state=n + 1,
              next_action=n + 11,
              is_state_terminal=False,
          )
          for n in range(5)
      ]
  
      # Add two episodes
      rbuf.append(**transs[0])
      rbuf.append(**transs[1])
      rbuf.stop_current_episode()
  
      rbuf.append(**transs[2])
      rbuf.append(**transs[3])
      rbuf.append(**transs[4])
      rbuf.stop_current_episode()
  
      assert len(rbuf) == 5
      assert rbuf.n_episodes == 2
  
      # Save
      filename = os.path.join(tempdir, "rbuf.pkl")
      # Actually does nothing
      rbuf.save(filename)
      del rbuf
  
      # Re-initialize rbuf
      rbuf = PersistentEpisodicReplayBuffer(self.tempdir.name, capacity)
  
      # Sampled transitions are exactly what I added!
      s5 = rbuf.sample(5)
      assert len(s5) == 5
      for t in s5:
          assert len(t) == 1
          n = t[0]["state"]
          assert n in range(5)
          assert t[0] == transs[n]
  
      # And sampled episodes are exactly what I added!
      s2e = rbuf.sample_episodes(2)
      assert len(s2e) == 2
      if s2e[0][0]["state"] == 0:
          assert s2e[0] == [transs[0], transs[1]]
          assert s2e[1] == [transs[2], transs[3], transs[4]]
      else:
          assert s2e[0] == [transs[2], transs[3], transs[4]]
          assert s2e[1] == [transs[0], transs[1]]
  
      # Sizes are correct!
      assert len(rbuf) == 5
      assert rbuf.n_episodes == 2
  
file_path: pfrl/tests/replay_buffers_test/test_persistent_replay_buffer.py
imports: import os
  import tempfile
  import pytest
  from pfrl.replay_buffers import PersistentEpisodicReplayBuffer
label_desc: Use image node_id 4 for calling the TestEpisodicReplayBuffer obj's underlying member method code with example usage: obj.test_save_and_load(capacity) without return types