code: def _prepare_iter_population(
      *,
      draws: int,
      step,
      start: Sequence[PointType],
      parallelize: bool,
      traces: Sequence[BaseTrace],
      tune: int,
      model=None,
      random_seed: RandomSeed = None,
      progressbar=True,
  ) -> Iterator[int]:
      """Prepare a PopulationStepper and traces for population sampling.
  
      Parameters
      ----------
      draws : int
          The number of samples to draw
      step : function
          Step function (should be or contain a population step method)
      start : list
          Start points for each chain
      parallelize : bool
          Setting for multiprocess parallelization
      tune : int
          Number of iterations to tune.
      model : Model (optional if in ``with`` context)
      random_seed : single random seed, optional
      progressbar : bool
          ``progressbar`` argument for the ``PopulationStepper``, (defaults to True)
  
      Returns
      -------
      _iter_population : generator
          Main sampling iterator yieling the iteration number.
      """
      nchains = len(start)
      model = modelcontext(model)
      draws = int(draws)
  
      if draws < 1:
          raise ValueError("Argument `draws` should be above 0.")
  
      if random_seed is not None:
          np.random.seed(random_seed)
  
      # The initialization of traces, samplers and points must happen in the right order:
      # 1. population of points is created
      # 2. steppers are initialized and linked to the points object
      # 3. a PopulationStepper is configured for parallelized stepping
  
      # 1. create a population (points) that tracks each chain
      # it is updated as the chains are advanced
      population = [start[c] for c in range(nchains)]
  
      # 2. Set up the steppers
      steppers: List[Step] = []
      for c in range(nchains):
          # need independent samplers for each chain
          # it is important to copy the actual steppers (but not the delta_logp)
          if isinstance(step, CompoundStep):
              chainstep = CompoundStep([copy(m) for m in step.methods])
          else:
              chainstep = copy(step)
          # link population samplers to the shared population state
          for sm in (
              chainstep.methods
              if isinstance(step, CompoundStep)
              else [chainstep]
          ):
              if isinstance(sm, PopulationArrayStepShared):
                  sm.link_population(population, c)
          steppers.append(chainstep)
  
      # 3. configure the PopulationStepper (expensive call)
      popstep = PopulationStepper(
          steppers, parallelize, progressbar=progressbar
      )
  
      # Because the preparations above are expensive, the actual iterator is
      # in another method. This way the progbar will not be disturbed.
      return _iter_population(
          draws=draws,
          tune=tune,
          popstep=popstep,
          steppers=steppers,
          traces=traces,
          points=population,
      )
  
imports: import logging
  import warnings
  from copy import copy
  from typing import Iterator, List, Sequence, Tuple, Union
  import cloudpickle
  import numpy
  from fastprogress.fastprogress import progress_bar
  from typing_extensions import TypeAlias
  from pymc.backends.base import BaseTrace
  from pymc.initial_point import PointType
  from pymc.model import Model, modelcontext
  from pymc.stats.convergence import log_warning_stats
  from pymc.step_methods import CompoundStep
  from pymc.step_methods.arraystep import BlockedStep, PopulationArrayStepShared, StatsType
  from pymc.step_methods.metropolis import DEMetropolis
  from pymc.util import RandomSeed
label_desc: Use image node_id 3 for calling a global function with example usage: _prepare_iter_population() and returns: _iter_population