docstr: Interact with the environments lambda times
          
docstr_tok: ["Interact","with","the","environments","lambda","times"]
code: def sample(self):
      """Interact with the environments lambda times"""
      sample_data = defaultdict(list)
  
      env_sample_data = {}
      for env_id in range(self.config["env_num"]):
          env_sample_data[env_id] = defaultdict(list)
      for i in range(self.config["sample_batch_steps"]):
          self.obs_batch = np.stack(self.obs_batch)
          action_batch, value_batch = self.agent.sample(self.obs_batch)
          (
              next_obs_batch,
              reward_batch,
              done_batch,
              info_batch,
          ) = self.vector_env.step(action_batch)
  
          for env_id in range(self.config["env_num"]):
              env_sample_data[env_id]["obs"].append(
                  self.obs_batch[env_id]
              )
              env_sample_data[env_id]["actions"].append(
                  action_batch[env_id].item()
              )
              env_sample_data[env_id]["rewards"].append(
                  reward_batch[env_id]
              )
              env_sample_data[env_id]["dones"].append(
                  done_batch[env_id]
              )
              env_sample_data[env_id]["values"].append(
                  value_batch[env_id].item()
              )
  
              if (
                  done_batch[env_id]
                  or i == self.config["sample_batch_steps"] - 1
              ):
                  next_value = 0
                  if not done_batch[env_id]:
                      next_obs = np.expand_dims(
                          next_obs_batch[env_id], 0
                      )
                      next_value = self.agent.value(next_obs).item()
  
                  values = env_sample_data[env_id]["values"]
                  rewards = env_sample_data[env_id]["rewards"]
                  advantages = calc_gae(
                      rewards,
                      values,
                      next_value,
                      self.config["gamma"],
                      self.config["lambda"],
                  )
                  target_values = advantages + values
  
                  sample_data["obs"].extend(
                      env_sample_data[env_id]["obs"]
                  )
                  sample_data["actions"].extend(
                      env_sample_data[env_id]["actions"]
                  )
                  sample_data["advantages"].extend(advantages)
                  sample_data["target_values"].extend(target_values)
  
                  env_sample_data[env_id] = defaultdict(list)
  
          self.obs_batch = next_obs_batch
  
      for key in sample_data:
          sample_data[key] = np.stack(sample_data[key])
  
      return sample_data
  
file_path: PARL/benchmark/torch/a2c/actor.py
imports: import os
  import gym
  import parl
  import torch
  import numpy
  from collections import defaultdict
  from parl.env.atari_wrappers import wrap_deepmind, MonitorEnv, get_wrapper_by_cls
  from parl.env.vector_env import VectorEnv
  from parl.utils.rl_utils import calc_gae
  from atari_model import ActorCritic
  from parl.algorithms import A2C
  from atari_agent import Agent
label_desc: Use image node_id 2 for calling the Actor obj's underlying member method code with example usage: obj.sample() and returns: sample_data