old_contents: from __future__ import unicode_literals
  from __future__ import print_function
  from __future__ import division
  from __future__ import absolute_import
  from builtins import dict
  from future import standard_library
  standard_library.install_aliases()
  from collections import deque
  import random
  import cPickle as pickle
  
  
  class ReplayBuffer(object):
  
      def __init__(self, capacity):
          self.memory = deque(maxlen=capacity)
  
      def append(self, state, action, reward, next_state=None, next_action=None,
                 is_state_terminal=False):
          """Append a transition to this replay buffer
          Args:
            state: s_t
            action: a_t
            reward: r_t
            next_state: s_{t+1} (can be None if terminal)
            next_action: a_{t+1} (can be None for off-policy algorithms)
            is_state_terminal (bool)
          """
          experience = dict(state=state, action=action, reward=reward,
                            next_state=next_state, next_action=next_action,
                            is_state_terminal=is_state_terminal)
          self.memory.append(experience)
  
      def sample(self, n):
          """Sample n unique samples from this replay buffer
          """
          assert len(self.memory) >= n
          return random.sample(self.memory, n)
  
      def __len__(self):
          return len(self.memory)
  
      def save(self, filename):
          with open(filename, 'w') as f:
              pickle.dump(self.memory, f)
  
      def load(self, filename):
          with open(filename) as f:
              self.memory = pickle.load(f)
  
new_contents: from __future__ import unicode_literals
  from __future__ import print_function
  from __future__ import division
  from __future__ import absolute_import
  from builtins import dict
  from future import standard_library
  standard_library.install_aliases()
  from collections import deque
  import random
  
  import six.moves.cPickle as pickle
  
  
  class ReplayBuffer(object):
  
      def __init__(self, capacity):
          self.memory = deque(maxlen=capacity)
  
      def append(self, state, action, reward, next_state=None, next_action=None,
                 is_state_terminal=False):
          """Append a transition to this replay buffer
          Args:
            state: s_t
            action: a_t
            reward: r_t
            next_state: s_{t+1} (can be None if terminal)
            next_action: a_{t+1} (can be None for off-policy algorithms)
            is_state_terminal (bool)
          """
          experience = dict(state=state, action=action, reward=reward,
                            next_state=next_state, next_action=next_action,
                            is_state_terminal=is_state_terminal)
          self.memory.append(experience)
  
      def sample(self, n):
          """Sample n unique samples from this replay buffer
          """
          assert len(self.memory) >= n
          return random.sample(self.memory, n)
  
      def __len__(self):
          return len(self.memory)
  
      def save(self, filename):
          with open(filename, 'wb') as f:
              pickle.dump(self.memory, f)
  
      def load(self, filename):
          with open(filename, 'rb') as f:
              self.memory = pickle.load(f)
  
subject: Support py3