code: def _sample(
      *,
      chain: int,
      progressbar: bool,
      random_seed: RandomSeed,
      start: PointType,
      draws: int,
      step: Step,
      trace: IBaseTrace,
      tune: int,
      model: Optional[Model] = None,
      callback=None,
      **kwargs,
  ) -> None:
      """Main iteration for singleprocess sampling.
  
      Multiple step methods are supported via compound step methods.
  
      Parameters
      ----------
      chain : int
          Number of the chain that the samples will belong to.
      progressbar : bool
          Whether or not to display a progress bar in the command line. The bar shows the percentage
          of completion, the sampling speed in samples per second (SPS), and the estimated remaining
          time until completion ("expected time of arrival"; ETA).
      random_seed : single random seed
      start : dict
          Starting point in parameter space (or partial point)
      draws : int
          The number of samples to draw
      step : function
          Step function
      trace
          A chain backend to record draws and stats.
      tune : int
          Number of iterations to tune.
      model : Model (optional if in ``with`` context)
      """
      skip_first = kwargs.get("skip_first", 0)
  
      sampling_gen = _iter_sample(
          draws=draws,
          step=step,
          start=start,
          trace=trace,
          chain=chain,
          tune=tune,
          model=model,
          random_seed=random_seed,
          callback=callback,
      )
      _pbar_data = {"chain": chain, "divergences": 0}
      _desc = "Sampling chain {chain:d}, {divergences:,d} divergences"
      if progressbar:
          sampling = progress_bar(
              sampling_gen, total=draws, display=progressbar
          )
          sampling.comment = _desc.format(**_pbar_data)
      else:
          sampling = sampling_gen
      try:
          for it, diverging in enumerate(sampling):
              if it >= skip_first and diverging:
                  _pbar_data["divergences"] += 1
                  if progressbar:
                      sampling.comment = _desc.format(**_pbar_data)
      except KeyboardInterrupt:
          pass
  
imports: import logging
  import pickle
  import sys
  import time
  import warnings
  from typing import Any, Dict, Iterator, List, Literal, Mapping, Optional, Sequence, Set, Tuple, Type, Union, overload
  import numpy
  import pytensor.gradient
  from arviz import InferenceData, dict_to_dataset
  from arviz.data.base import make_attrs
  from fastprogress.fastprogress import progress_bar
  from pytensor.graph.basic import Variable
  from typing_extensions import Protocol, TypeAlias
  import pymc
  from pymc.backends import RunType, TraceOrBackend, init_traces
  from pymc.backends.arviz import coords_and_dims_for_inferencedata, find_constants, find_observations
  from pymc.backends.base import IBaseTrace, MultiTrace, _choose_chains
  from pymc.blocking import DictToArrayBijection
  from pymc.exceptions import SamplingError
  from pymc.initial_point import PointType, StartDict, make_initial_point_fns_per_chain
  from pymc.model import Model, modelcontext
  from pymc.sampling.parallel import Draw, _cpu_count
  from pymc.sampling.population import _sample_population
  from pymc.stats.convergence import log_warning_stats, log_warnings, run_convergence_checks
  from pymc.step_methods import NUTS, CompoundStep
  from pymc.step_methods.arraystep import BlockedStep, PopulationArrayStepShared
  from pymc.step_methods.hmc import quadpotential
  from pymc.util import RandomSeed, RandomState, _get_seeds_per_chain, drop_warning_stat, get_untransformed_name, is_transformed_name
  from pymc.vartypes import discrete_types
label_desc: Use image node_id 12 for calling a global function with example usage: _sample() without return types