code: def extract_init_args(
      args: Dict[str, Any], class_: Type
  ) -> Dict[str, Any]:
      """Given a dictionary, extract the arguments required for the
      given class's constructor.
      """
      init_args = {}
      signature = inspect.signature(class_.__init__)
      for arg, info in signature.parameters.items():
          if arg in ["self", "args", "kwargs"]:
              continue
          value = args.get(arg)
          if value is None:
              # Only necessary to raise an exception if there is no default
              # value for this argument
              if info.default is inspect.Parameter.empty:
                  raise ValueError(
                      f"Cannot decode to class {class_} because required argument {arg} "
                      "is missing. If that's not the class you were intending to decode, "
                      "make sure you have updated your metric or runner registries."
                  )
              else:
                  # Constructor will use default value
                  continue
          init_args[arg] = value
      return init_args
  
file_path: Ax/ax/utils/common/serialization.py
imports: from __future__ import annotations
  import inspect
  import pydoc
  from types import FunctionType
  from typing import Any, Callable, Dict, List, Optional, Type
label_desc: Use image node_id 6 for calling a global function with example usage: extract_init_args(args, class_) and returns: init_args