code: def test_preset_reward(
      preset_name,
      no_progress_bar=True,
      time_limit=60 * 60,
      verbose=True,
  ):
      preset_validation_params = validation_params(preset_name)
  
      win_size = 10
  
      test_name = "__test_reward_{}".format(preset_name)
      test_path = os.path.join("./experiments", test_name)
      if path.exists(test_path):
          shutil.rmtree(test_path)
  
      # run the experiment in a separate thread
      screen.log_title("Running test {}".format(preset_name))
      log_file_name = "test_log_{preset_name}.txt".format(
          preset_name=preset_name
      )
      cmd = [
          "python3",
          "rl_coach/coach.py",
          "-p",
          "{preset_name}".format(preset_name=preset_name),
          "-e",
          "{test_name}".format(test_name=test_name),
          "-n",
          "{num_workers}".format(
              num_workers=preset_validation_params.num_workers
          ),
          "--seed",
          "0",
          "-c",
      ]
      if preset_validation_params.reward_test_level:
          cmd += [
              "-lvl",
              "{level}".format(
                  level=preset_validation_params.reward_test_level
              ),
          ]
  
      stdout = open(log_file_name, "w")
  
      p = subprocess.Popen(cmd, stdout=stdout, stderr=stdout)
  
      start_time = time.time()
  
      reward_str = "Evaluation Reward"
      if preset_validation_params.num_workers > 1:
          filename_pattern = "worker_0*.csv"
      else:
          filename_pattern = "*.csv"
  
      test_passed = False
  
      # get the csv with the results
      csv_paths = read_csv_paths(
          test_path,
          filename_pattern,
          read_csv_tries=preset_validation_params.read_csv_tries,
      )
  
      if csv_paths:
          csv_path = csv_paths[0]
  
          # verify results
          csv = None
          time.sleep(1)
          averaged_rewards = [0]
  
          last_num_episodes = 0
  
          if not no_progress_bar:
              print_progress(
                  averaged_rewards,
                  last_num_episodes,
                  preset_validation_params,
                  start_time,
                  time_limit,
              )
  
          while csv is None or (
              csv[csv.columns[0]].values[-1]
              < preset_validation_params.max_episodes_to_achieve_reward
              and time.time() - start_time < time_limit
          ):
              try:
                  csv = pd.read_csv(csv_path)
              except:
                  # sometimes the csv is being written at the same time we are
                  # trying to read it. no problem -> try again
                  continue
  
              if reward_str not in csv.keys():
                  continue
  
              rewards = csv[reward_str].values
              rewards = rewards[~np.isnan(rewards)]
  
              if len(rewards) >= 1:
                  averaged_rewards = np.convolve(
                      rewards,
                      np.ones(min(len(rewards), win_size)) / win_size,
                      mode="valid",
                  )
              else:
                  time.sleep(1)
                  continue
  
              if not no_progress_bar:
                  print_progress(
                      averaged_rewards,
                      last_num_episodes,
                      preset_validation_params,
                      start_time,
                      time_limit,
                  )
  
              if csv[csv.columns[0]].shape[0] - last_num_episodes <= 0:
                  continue
  
              last_num_episodes = csv[csv.columns[0]].values[-1]
  
              # check if reward is enough
              if np.any(
                  averaged_rewards
                  >= preset_validation_params.min_reward_threshold
              ):
                  test_passed = True
                  break
              time.sleep(1)
  
      # kill test and print result
      # os.killpg(os.getpgid(p.pid), signal.SIGKILL)
      p.kill()
      screen.log("")
      if test_passed:
          screen.success("Passed successfully")
      else:
          if time.time() - start_time > time_limit:
              screen.error(
                  "Failed due to exceeding time limit", crash=False
              )
              if verbose:
                  screen.error(
                      "command exitcode: {}".format(p.returncode),
                      crash=False,
                  )
                  screen.error(open(log_file_name).read(), crash=False)
          elif csv_paths:
              screen.error(
                  "Failed due to insufficient reward", crash=False
              )
              if verbose:
                  screen.error(
                      "command exitcode: {}".format(p.returncode),
                      crash=False,
                  )
                  screen.error(open(log_file_name).read(), crash=False)
              screen.error(
                  "preset_validation_params.max_episodes_to_achieve_reward: {}".format(
                      preset_validation_params.max_episodes_to_achieve_reward
                  ),
                  crash=False,
              )
              screen.error(
                  "preset_validation_params.min_reward_threshold: {}".format(
                      preset_validation_params.min_reward_threshold
                  ),
                  crash=False,
              )
              screen.error(
                  "averaged_rewards: {}".format(averaged_rewards),
                  crash=False,
              )
              screen.error(
                  "episode number: {}".format(
                      csv["Episode #"].values[-1]
                  ),
                  crash=False,
              )
              screen.error(
                  "training iteration: {}".format(
                      csv["Training Iter"].values[-1]
                  ),
                  crash=False,
              )
          else:
              screen.error("csv file never found", crash=False)
              if verbose:
                  screen.error(
                      "command exitcode: {}".format(p.returncode),
                      crash=False,
                  )
                  screen.error(open(log_file_name).read(), crash=False)
  
      shutil.rmtree(test_path)
      os.remove(log_file_name)
      if not test_passed:
          raise ValueError("golden test failed")
  
imports: import argparse
  import glob
  import os
  import shutil
  import signal
  import subprocess
  import sys
  from importlib import import_module
  from os import path
  import numpy
  import pandas
  import time
  import pytest
  from rl_coach.logger import screen
label_desc: Use image node_id 10 for calling a global function with example usage: test_preset_reward(preset_name, no_progress_bar, time_limit, verbose) without return types