code: def get_attrs(fit):
      """Get attributes from PyStan fit object."""
      attrs = {}
  
      try:
          attrs["args"] = [
              deepcopy(holder.args) for holder in fit.sim["samples"]
          ]
      except Exception as exp:  # pylint: disable=broad-except
          _log.warning("Failed to fetch args from fit: %s", exp)
      if "args" in attrs:
          for arg in attrs["args"]:
              if isinstance(arg["init"], bytes):
                  arg["init"] = arg["init"].decode("utf-8")
          attrs["args"] = json.dumps(attrs["args"])
      try:
          attrs["inits"] = [
              holder.inits for holder in fit.sim["samples"]
          ]
      except Exception as exp:  # pylint: disable=broad-except
          _log.warning("Failed to fetch `args` from fit: %s", exp)
      else:
          attrs["inits"] = json.dumps(attrs["inits"])
  
      attrs["step_size"] = []
      attrs["metric"] = []
      attrs["inv_metric"] = []
      for holder in fit.sim["samples"]:
          try:
              step_size = float(
                  re.search(
                      r"step\s*size\s*=\s*([0-9]+.?[0-9]+)\s*",
                      holder.adaptation_info,
                      flags=re.IGNORECASE,
                  ).group(1)
              )
          except AttributeError:
              step_size = np.nan
          attrs["step_size"].append(step_size)
  
          inv_metric_match = re.search(
              r"mass matrix:\s*(.*)\s*$",
              holder.adaptation_info,
              flags=re.DOTALL,
          )
          if inv_metric_match:
              inv_metric_str = inv_metric_match.group(1)
              if (
                  "Diagonal elements of inverse mass matrix"
                  in holder.adaptation_info
              ):
                  metric = "diag_e"
                  inv_metric = [
                      float(item)
                      for item in inv_metric_str.strip(" #\n").split(
                          ","
                      )
                  ]
              else:
                  metric = "dense_e"
                  inv_metric = [
                      list(map(float, item.split(",")))
                      for item in re.sub(
                          r"#\s", "", inv_metric_str
                      ).splitlines()
                  ]
          else:
              metric = "unit_e"
              inv_metric = None
  
          attrs["metric"].append(metric)
          attrs["inv_metric"].append(inv_metric)
      attrs["inv_metric"] = json.dumps(attrs["inv_metric"])
  
      if not attrs["step_size"]:
          del attrs["step_size"]
  
      attrs["adaptation_info"] = fit.get_adaptation_info()
      attrs["stan_code"] = fit.get_stancode()
  
      return attrs
  
imports: import re
  from collections import OrderedDict
  from copy import deepcopy
  from math import ceil
  import numpy
  import xarray
  from ..None import _log
  from ..rcparams import rcParams
  from .base import dict_to_dataset, generate_dims_coords, infer_stan_dtypes, make_attrs, requires
  from .inference_data import InferenceData
label_desc: Use image node_id 3 for calling a global function with example usage: get_attrs(fit) and returns: attrs