code: def safe_load_yaml_with_exceptions(
      yaml_file: Union[io.FileIO, IO[Any], str]
  ) -> Any:
      """Attempts to use ruamel.yaml.safe_load on the specified file. If successful, returns
      the output. If not, formats a ruamel.yaml Exception so that the user does not see a traceback
      of our internal APIs.
  
      ---------------------------------------------------------------------------------------------
      DuplicateKeyError Example:
      Input:
          Traceback (most recent call last):
          ...
          ruamel.yaml.constructor.DuplicateKeyError: while constructing a mapping
          in "<unicode string>", line 1, column 1:
              description: constrained_adaptiv ...
              ^ (line: 1)
          found duplicate key "checkpoint_storage" with value "{}" (original value: "{}")
          in "<unicode string>", line 7, column 1:
              checkpoint_storage:
              ^ (line: 7)
          To suppress this check see:
              http://yaml.readthedocs.io/en/latest/api.html#duplicate-keys
          Duplicate keys will become an error in future releases, and are errors
          by default when using the new API.
          Failed to create experiment
      Output:
          Error: invalid experiment config file constrained_adaptive.yaml.
          DuplicateKeyError: found duplicate key "learning_rate" with value "0.022"
          (original value: "0.025")
          in "constrained_adaptive.yaml", line 23, column 3
      ---------------------------------------------------------------------------------------------
      """
  
      try:
          config = _get_yaml().load(yaml_file)
      except (
          yaml.error.MarkedYAMLWarning,
          yaml.error.MarkedYAMLError,
          yaml.error.MarkedYAMLFutureWarning,
      ) as e:
          err_msg = (
              f"Error: invalid experiment config file.\n"
              f"{e.__class__.__name__}: {e.problem}\n{e.problem_mark}"
          )
          print(err_msg)
          sys.exit(1)
      return config
  
imports: import datetime
  import functools
  import io
  import json
  import os
  import pathlib
  import platform
  import random
  import re
  import sys
  import time
  import warnings
  from typing import IO, Any, Callable, Dict, Iterator, Optional, Sequence, Tuple, TypeVar, Union, cast, no_type_check, overload
  import urllib3
  from determined.common import yaml
label_desc: Use image node_id 14 for calling a global function with example usage: safe_load_yaml_with_exceptions(yaml_file) and returns: config