class_docstr: Reporter class.
  
  Examples:
  
      >>> reporter = Reporter()
      >>> with reporter.observe('train') as sub_reporter:
      ...     for batch in iterator:
      ...         stats = dict(loss=0.2)
      ...         sub_reporter.register(stats)
class_docstr_tok: ["Reporter","class",".","Examples",":",">",">",">","reporter","=","Reporter","(",")",">",">",">","with","reporter.observe","(","'train","'",")","as","sub_reporter",":","...","for","batch","in","iterator",":","...","stats","=","dict","(","loss=0.2",")","...","sub_reporter.register","(","stats",")"]
docstr: Return the epoch which resulted the best value.
  
  Example:
      >>> val = reporter.sort_epochs_and_values('eval', 'loss', 'min')
      >>> e_1best, v_1best = val[0]
      >>> e_2best, v_2best = val[1]
docstr_tok: ["Return","the","epoch","which","resulted","the","best","value",".","Example",":",">",">",">","val","=","reporter.sort_epochs_and_values","(","'eval","'",",","'loss","'",",","'min","'",")",">",">",">","e_1best",",","v_1best","=","val","[","0","]",">",">",">","e_2best",",","v_2best","=","val","[","1","]"]
code: def sort_epochs_and_values(
      self, key: str, key2: str, mode: str
  ) -> List[Tuple[int, float]]:
      """Return the epoch which resulted the best value.
  
      Example:
          >>> val = reporter.sort_epochs_and_values('eval', 'loss', 'min')
          >>> e_1best, v_1best = val[0]
          >>> e_2best, v_2best = val[1]
      """
      if mode not in ("min", "max"):
          raise ValueError(f"mode must min or max: {mode}")
      if not self.has(key, key2):
          raise KeyError(
              f"{key}.{key2} is not found: {self.get_all_keys()}"
          )
  
      # iterate from the last epoch
      values = [(e, self.stats[e][key][key2]) for e in self.stats]
  
      if mode == "min":
          values = sorted(values, key=lambda x: x[1])
      else:
          values = sorted(values, key=lambda x: -x[1])
      return values
  
imports: import dataclasses
  import datetime
  import logging
  import time
  import warnings
  from collections import defaultdict
  from contextlib import contextmanager
  from pathlib import Path
  from typing import ContextManager, Dict, List, Optional, Sequence, Tuple, Union
  import humanfriendly
  import numpy
  import torch
  from packaging.version import parse
  from typeguard import check_argument_types, check_return_type
label_desc: Use image node_id 7 for calling the Reporter obj's underlying member method code with example usage: obj.sort_epochs_and_values(key, key2, mode) and returns: values