code: def pick_best(in_file, out_file):
      """
      Pick the best entries from a file and store them to another file.
      This function distills the useful log entries from a large log file.
      If out_file already exists, the best entries from both
      in_file and out_file will be saved.
  
      Parameters
      ----------
      in_file: str
          The filename of input
      out_file: str or file
          The filename of output
      """
      context = load_from_file(in_file)
      if os.path.isfile(out_file):
          out_context = load_from_file(out_file)
          context = itertools.chain(context, out_context)
      context, context_clone = itertools.tee(context)
      best_context = ApplyHistoryBest(context)
      best_set = set()
  
      for v in best_context.best_by_model.values():
          best_set.add(measure_str_key(v[0]))
  
      for v in best_context.best_by_targetkey.values():
          best_set.add(measure_str_key(v[0]))
  
      logger.info(
          "Extract %d best records from the %s", len(best_set), in_file
      )
      fout = (
          open(out_file, "w") if isinstance(out_file, str) else out_file
      )
  
      for inp, res in context_clone:
          if measure_str_key(inp) in best_set:
              fout.write(encode(inp, res) + "\n")
              best_set.remove(measure_str_key(inp))
  
imports: import argparse
  import base64
  from io import TextIOBase
  import logging
  import pickle
  import json
  import time
  from typing import Union
  import os
  import itertools
  from collections import OrderedDict
  import numpy
  from ..None import build, lower
  from ..target import Target
  from ..contrib import popen_pool
  from ..None import __version__
  from .None import task
  from .task import ConfigEntity, ApplyHistoryBest
  from .measure import MeasureInput, MeasureResult
label_desc: Use image node_id 7 for calling a global function with example usage: pick_best(in_file, out_file) without return types