code: def sample(self, flat_weights):
      noise_indices, rewards, lengths = [], [], []
      eval_rewards, eval_lengths = [], []
  
      # Perform some rollouts with noise.
      task_tstart = time.time()
      while (
          len(noise_indices) == 0
          or time.time() - task_tstart < self.config["min_task_runtime"]
      ):
          if np.random.uniform() < self.config["eval_prob"]:
              # Do an evaluation run with no perturbation.
              self.agent.set_flat_weights(flat_weights)
              episode_reward, episode_step = self._play_one_episode(
                  add_noise=False
              )
              eval_rewards.append(episode_reward)
              eval_lengths.append(episode_step)
          else:
              # Do a regular run with parameter perturbations.
              noise_index = self.noise.sample_index(
                  self.agent.weights_total_size
              )
  
              perturbation = self.config[
                  "noise_stdev"
              ] * self.noise.get(
                  noise_index, self.agent.weights_total_size
              )
  
              # Mirrored sampling: evaluate pairs of perturbations \epsilon, −\epsilon
              self.agent.set_flat_weights(flat_weights + perturbation)
              (
                  episode_reward_pos,
                  episode_step_pos,
              ) = self._play_one_episode(add_noise=True)
  
              self.agent.set_flat_weights(flat_weights - perturbation)
              (
                  episode_reward_neg,
                  episode_step_neg,
              ) = self._play_one_episode(add_noise=True)
  
              noise_indices.append(noise_index)
              rewards.append([episode_reward_pos, episode_reward_neg])
              lengths.append([episode_step_pos, episode_step_neg])
  
      return {
          "noise_indices": noise_indices,
          "noisy_rewards": rewards,
          "noisy_lengths": lengths,
          "eval_rewards": eval_rewards,
          "eval_lengths": eval_lengths,
      }
  
file_path: PARL/examples/ES/actor.py
imports: import gym
  import parl
  import time
  import numpy
  from es import ES
  from obs_filter import MeanStdFilter
  from mujoco_agent import MujocoAgent
  from mujoco_model import MujocoModel
  from noise import SharedNoiseTable
  from parl.env import CompatWrapper
label_desc: Use image node_id 3 for calling the Actor obj's underlying member method code with example usage: obj.sample(flat_weights) and returns: dict