code: def get_sample_stats_stan3(
      fit, variables=None, ignore=None, warmup=False, dtypes=None
  ):
      """Extract sample stats from PyStan3 fit."""
      if dtypes is None:
          dtypes = {}
      dtypes = {
          "divergent__": bool,
          "n_leapfrog__": np.int64,
          "treedepth__": np.int64,
          **dtypes,
      }
  
      rename_dict = {
          "divergent": "diverging",
          "n_leapfrog": "n_steps",
          "treedepth": "tree_depth",
          "stepsize": "step_size",
          "accept_stat": "acceptance_rate",
      }
  
      if isinstance(variables, str):
          variables = [variables]
      if isinstance(ignore, str):
          ignore = [ignore]
  
      if not fit.save_warmup:
          warmup = False
  
      num_warmup = ceil(
          (fit.num_warmup * fit.save_warmup) / fit.num_thin
      )
  
      data = OrderedDict()
      data_warmup = OrderedDict()
      for key in fit.sample_and_sampler_param_names:
          if (variables and key not in variables) or (
              ignore and key in ignore
          ):
              continue
          new_shape = -1, fit.num_chains
          values = fit._draws[
              fit._parameter_indexes(key)
          ]  # pylint: disable=protected-access
          values = values.reshape(new_shape, order="F")
          values = np.moveaxis(values, [-2, -1], [1, 0])
          dtype = dtypes.get(key)
          values = values.astype(dtype)
          name = re.sub("__$", "", key)
          name = rename_dict.get(name, name)
          if warmup:
              data_warmup[name] = values[:, :num_warmup]
          data[name] = values[:, num_warmup:]
  
      return data, data_warmup
  
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 5 for calling a global function with example usage: get_sample_stats_stan3(fit, variables, ignore, warmup, dtypes) and returns: data,  data_warmup