code: def run_train_episode(agent, env, rpm):
      total_reward = 0
      obs = env.reset()
      step = 0
      loss_lst = []
  
      while True:
          step += 1
          context = rpm.recent_obs()
          context.append(obs)
          context = np.stack(context, axis=0)
  
          action = agent.sample(context)
          next_obs, reward, done, _ = env.step(action)
          rpm.append(Experience(obs, action, reward, done))
  
          # train model
          if (rpm.size() > MEMORY_WARMUP_SIZE) and (
              step % UPDATE_FREQ == 0
          ):
              # s,a,r,s',done
              (
                  batch_all_obs,
                  batch_action,
                  batch_reward,
                  batch_done,
              ) = rpm.sample_batch(BATCH_SIZE)
              batch_obs = batch_all_obs[:, :CONTEXT_LEN, :, :]
              batch_next_obs = batch_all_obs[:, 1:, :, :]
  
              train_loss = agent.learn(
                  batch_obs,
                  batch_action,
                  batch_reward,
                  batch_next_obs,
                  batch_done,
              )
              loss_lst.append(train_loss)
  
          total_reward += reward
          obs = next_obs
          if done:
              break
      return total_reward, step, np.mean(loss_lst)
  
file_path: PARL/benchmark/torch/dqn/train.py
imports: import argparse
  import os
  import torch
  import parl
  import gym
  import numpy
  from tqdm import tqdm
  from parl.utils import summary, logger
  from parl.algorithms import DQN, DDQN
  from parl.env.atari_wrappers import wrap_deepmind
  from agent import AtariAgent
  from model import AtariModel
  from replay_memory import ReplayMemory, Experience
label_desc: Use image node_id 1 for calling a global function with example usage: run_train_episode(agent, env, rpm) and returns: total_reward,  step,  np