code: def write_stats_to_json(cls, file_name, stats):
      
      params = cls._json_dump_options(stats)
      mode = 'w' if PY3 else 'wb'
      try:
        safe_file_dump(file_name, params, mode=mode)
      except Exception as e: # Broad catch - we don't want to fail in stats related failure.
        print('WARNING: Failed to write stats to {} due to Error: {}'.format(file_name, e),
              file=sys.stderr)
docs: Write stats to a local json file.