class_docstr: TrainLoop contains the core training loop logic.
class_docstr_tok: ["TrainLoop","contains","the","core","training","loop","logic","."]
docstr: Eval on validation/test data.
  
  :param valid_world:
      list of the pre-created validation worlds.
  :param opt:
      the options that specific the task, eval_task, etc
  :param datatype:
      the datatype to use, such as "valid" or "test"
  :param bool write_log:
      specifies to write metrics to file if the model_file is set
  :param int max_exs:
      limits the number of examples if max_exs > 0
docstr_tok: ["Eval","on","validation\/test","data",".",":","param","valid_world",":","list","of","the","pre-created","validation","worlds",".",":","param","opt",":","the","options","that","specific","the","task",",","eval_task",",","etc",":","param","datatype",":","the","datatype","to","use",",","such","as","``","valid","''","or","``","test","''",":","param","bool","write_log",":","specifies","to","write","metrics","to","file","if","the","model_file","is","set",":","param","int","max_exs",":","limits","the","number","of","examples","if","max_exs",">","0"]
code: def _run_eval(
      self,
      valid_worlds,
      opt,
      datatype,
      max_exs=-1,
      write_log=False,
      extra_log_suffix="",
  ):
      """
      Eval on validation/test data.
  
      :param valid_world:
          list of the pre-created validation worlds.
      :param opt:
          the options that specific the task, eval_task, etc
      :param datatype:
          the datatype to use, such as "valid" or "test"
      :param bool write_log:
          specifies to write metrics to file if the model_file is set
      :param int max_exs:
          limits the number of examples if max_exs > 0
      """
  
      logging.info(f"running eval: {datatype}")
      timer = Timer()
      reports = []
  
      max_exs_per_worker = max_exs / (len(valid_worlds) * num_workers())
      is_multitask = len(valid_worlds) > 1
      for index, v_world in enumerate(valid_worlds):
          if opt.get("evaltask"):
              task = opt["evaltask"].split(",")[index]
          else:
              task = opt["task"].split(",")[index]
          task_report = self._run_single_eval(
              opt,
              v_world,
              max_exs_per_worker,
              datatype,
              is_multitask,
              task,
              index,
          )
          reports.append(task_report)
  
      tasks = [world.getID() for world in valid_worlds]
      named_reports = dict(zip(tasks, reports))
      report = aggregate_named_reports(
          named_reports,
          micro_average=self.opt.get("aggregate_micro", False),
      )
      # get the results from all workers
      report = self._sync_metrics(report)
  
      metrics = f"{datatype}:\n{nice_report(report)}\n"
      logging.info(f"eval completed in {timer.time():.2f}s")
      logging.report(metrics)
  
      # write to file
      if write_log and opt.get("model_file") and is_primary_worker():
          # Write out metrics
          with PathManager.open(
              opt["model_file"] + extra_log_suffix + "." + datatype, "a"
          ) as f:
              f.write(f"{metrics}\n")
  
      return report
  
imports: import copy
  import random
  import torch
  import json
  import os
  import signal
  from typing import Tuple
  import numpy
  import parlai.utils.logging
  from parlai.core.agents import create_agent, create_agent_from_shared
  from parlai.core.exceptions import StopTrainException
  from parlai.core.logs import TensorboardLogger, WandbLogger, ClearMLLogger
  from parlai.core.metrics import Metric
  from parlai.core.metrics import aggregate_named_reports, aggregate_unnamed_reports, dict_report
  from parlai.core.opt import Opt
  from parlai.core.params import ParlaiParser, print_announcements
  from parlai.core.script import ParlaiScript, register_script
  from parlai.core.worlds import create_task, World
  from parlai.scripts.build_dict import build_dict, setup_args
  from parlai.scripts.eval_model import get_task_world_logs
  from parlai.utils.distributed import sync_object, is_primary_worker, all_gather_list, is_distributed, get_rank, num_workers
  from parlai.utils.io import PathManager
  from parlai.utils.misc import Timer, nice_report
  from parlai.utils.world_logging import WorldLogger
label_desc: Use image node_id 6 for calling the TrainLoop obj's underlying member method code with example usage: obj._run_eval(valid_worlds, opt, datatype, max_exs, write_log, extra_log_suffix) and returns: report