code: def test(
      agent: Union["PPOLightningAgent", "PPOAgent"],
      device: torch.device,
      logger: SummaryWriter,
      args: argparse.Namespace,
  ):
      env = make_env(
          args.env_id,
          args.seed,
          0,
          args.capture_video,
          logger.log_dir,
          "test",
      )()
      step = 0
      done = False
      cumulative_rew = 0
      next_obs = torch.tensor(
          env.reset(seed=args.seed)[0], device=device
      )
      while not done:
          # Act greedly through the environment
          action = agent.get_greedy_action(next_obs)
  
          # Single environment step
          next_obs, reward, done, truncated, _ = env.step(
              action.cpu().numpy()
          )
          done = done or truncated
          cumulative_rew += reward
          next_obs = torch.tensor(next_obs, device=device)
          step += 1
      logger.add_scalar("Test/cumulative_reward", cumulative_rew, 0)
      env.close()
  
file_path: pytorch-lightning/examples/fabric/reinforcement_learning/rl/utils.py
imports: import argparse
  import math
  import os
  from distutils.util import strtobool
  from typing import TYPE_CHECKING, Optional, Union
  import gymnasium
  import torch
  from torch.utils.tensorboard import SummaryWriter
label_desc: Use image node_id 5 for calling a global function with example usage: test(agent, device, logger, args) without return types