code: def _iter_forward_solutions(
      info,
      trans,
      src,
      bem,
      dev_head_ts,
      mindist,
      n_jobs,
      forward,
      picks,
  ):
      """Calculate a forward solution for a subject."""
      logger.info("Setting up forward solutions")
      info = pick_info(info, picks)
      with info._unlock():
          info.update(projs=[], bads=[])  # Ensure no 'projs' or 'bads'
      mri_head_t, trans = _get_trans(trans)
      sensors, rr, info, update_kwargs, bem = _prepare_for_forward(
          src,
          mri_head_t,
          info,
          bem,
          mindist,
          n_jobs,
          allow_bem_none=True,
          verbose=False,
      )
      del (src, mindist)
  
      eegnames = sensors.get("eeg", dict()).get("ch_names", [])
      if not len(eegnames):
          eegfwd = None
      elif forward is not None:
          eegfwd = pick_channels_forward(
              forward, eegnames, verbose=False
          )
      else:
          eegels = sensors.get("eeg", dict()).get("defs", [])
          this_sensors = dict(eeg=dict(ch_names=eegnames, defs=eegels))
          eegfwd = _compute_forwards(
              rr,
              bem=bem,
              sensors=this_sensors,
              n_jobs=n_jobs,
              verbose=False,
          )["eeg"]
          eegfwd = _to_forward_dict(eegfwd, eegnames)
          del eegels
      del eegnames
  
      # short circuit here if there are no MEG channels (don't need to iterate)
      if "meg" not in sensors:
          eegfwd.update(**update_kwargs)
          for _ in dev_head_ts:
              yield eegfwd
          yield eegfwd
          return
  
      coord_frame = FIFF.FIFFV_COORD_HEAD
      if bem is not None and not bem["is_sphere"]:
          idx = np.where(
              np.array([s["id"] for s in bem["surfs"]])
              == FIFF.FIFFV_BEM_SURF_ID_BRAIN
          )[0]
          assert len(idx) == 1
          # make a copy so it isn't mangled in use
          bem_surf = transform_surface_to(
              bem["surfs"][idx[0]], coord_frame, mri_head_t, copy=True
          )
      megcoils = sensors["meg"]["defs"]
      if "eeg" in sensors:
          del sensors["eeg"]
      megnames = sensors["meg"]["ch_names"]
      fwds = dict()
      if eegfwd is not None:
          fwds["eeg"] = eegfwd
      del eegfwd
      for ti, dev_head_t in enumerate(dev_head_ts):
          # Could be *slightly* more efficient not to do this N times,
          # but the cost here is tiny compared to actual fwd calculation
          logger.info(
              "Computing gain matrix for transform #%s/%s"
              % (ti + 1, len(dev_head_ts))
          )
          _transform_orig_meg_coils(megcoils, dev_head_t)
  
          # Make sure our sensors are all outside our BEM
          coil_rr = np.array([coil["r0"] for coil in megcoils])
  
          # Compute forward
          if forward is None:
              if not bem["is_sphere"]:
                  outside = ~_CheckInside(bem_surf)(
                      coil_rr, n_jobs, verbose=False
                  )
              elif bem.radius is not None:
                  d = coil_rr - bem["r0"]
                  outside = np.sqrt(np.sum(d * d, axis=1)) > bem.radius
              else:  # only r0 provided
                  outside = np.ones(len(coil_rr), bool)
              if not outside.all():
                  raise RuntimeError(
                      "%s MEG sensors collided with inner skull "
                      "surface for transform %s"
                      % (np.sum(~outside), ti)
                  )
              megfwd = _compute_forwards(
                  rr,
                  sensors=sensors,
                  bem=bem,
                  n_jobs=n_jobs,
                  verbose=False,
              )["meg"]
              megfwd = _to_forward_dict(megfwd, megnames)
          else:
              megfwd = pick_channels_forward(
                  forward, megnames, verbose=False
              )
          fwds["meg"] = megfwd
          fwd = _merge_fwds(fwds, verbose=False)
          fwd.update(**update_kwargs)
  
          yield fwd
      # need an extra one to fill last buffer
      yield fwd
  
imports: import os
  from collections.abc import Iterable
  from pathlib import Path
  import numpy
  from .._fiff.constants import FIFF
  from .._fiff.meas_info import Info
  from .._fiff.pick import pick_channels, pick_channels_forward, pick_info, pick_types
  from .._ola import _Interp2
  from ..bem import fit_sphere_to_headshape, make_sphere_model, read_bem_solution
  from ..chpi import _get_hpi_initial_fit, get_chpi_info, head_pos_to_trans_rot_t, read_head_pos
  from ..cov import Covariance, make_ad_hoc_cov, read_cov
  from ..event import _get_stim_channel
  from ..forward import _compute_forwards, _magnetic_dipole_field_vec, _merge_fwds, _prep_meg_channels, _prepare_for_forward, _stc_src_sel, _to_forward_dict, _transform_orig_meg_coils, convert_forward_solution, restrict_forward_to_stc
  from ..io import BaseRaw, RawArray
  from ..source_estimate import _BaseSourceEstimate
  from ..source_space._source_space import _ensure_src, _set_source_space_vertices, setup_volume_source_space
  from ..surface import _CheckInside
  from ..transforms import _get_trans, transform_surface_to
  from ..utils import _check_preload, _pl, _validate_type, check_random_state, logger, verbose
  from .source import SourceSimulator
label_desc: Use image node_id 11 for calling a global function with example usage: _iter_forward_solutions(info, trans, src, bem, dev_head_ts, mindist, n_jobs, forward, picks) without return types