class_docstr: A run of a training script.
class_docstr_tok: ["A","run","of","a","training","script","."]
docstr: Get the best checkpoint in this experiment, or None
  if there are no checkpoints or no checkpoint has a primary
  metric.
docstr_tok: ["Get","the","best","checkpoint","in","this","experiment",",","or","None","if","there","are","no","checkpoints","or","no","checkpoint","has","a","primary","metric","."]
code: def best(self) -> Optional[Checkpoint]:
      """
      Get the best checkpoint in this experiment, or None
      if there are no checkpoints or no checkpoint has a primary
      metric.
      """
      if not self.checkpoints:
          return None
      valid_metric = lambda m: m is not None and not math.isnan(m)
      primary_metric_checkpoints = [
          chk
          for chk in self.checkpoints
          if chk.primary_metric
          and valid_metric(chk.metrics[chk.primary_metric["name"]])
      ]
      if not primary_metric_checkpoints:
          return None
      name = primary_metric_checkpoints[0].primary_metric["name"]  # type: ignore
      goal = primary_metric_checkpoints[0].primary_metric["goal"]  # type: ignore
      if not all(
          chk.primary_metric["name"] == name for chk in primary_metric_checkpoints  # type: ignore
      ):
          console.warn(
              "Not all checkpoints in experiment {} have the same primary metric name".format(
                  self.short_id()
              )
          )
      if not all(
          chk.primary_metric["goal"] == goal for chk in primary_metric_checkpoints  # type: ignore
      ):
          console.warn(
              "Not all checkpoints in experiment {} have the same primary metric goal".format(
                  self.short_id()
              )
          )
  
      if goal == "minimize":
          key = lambda chk: -chk.metrics[name]
      else:
          key = lambda chk: chk.metrics[name]
  
      return sorted(primary_metric_checkpoints, key=key)[-1]
  
imports: import datetime
  import getpass
  import html
  import json
  import math
  import os
  import shlex
  import sys
  from typing import TYPE_CHECKING, Any, Callable, Dict, List, MutableSequence, Optional, Tuple
  from .None import console
  from .checkpoint import Checkpoint, CheckpointList, PrimaryMetric
  from .metadata import parse_rfc3339, rfc3339_datetime
  from .packages import get_imported_packages
  from .system import get_python_version
  from .validate import check_path
  from .version import version
label_desc: Use image node_id 11 for calling the Experiment obj's underlying member method code with example usage: obj.best() and returns: sorted, None, None