code: def ungroup_affinities(affinities, cores):
      ungrouped_affinities = []
  
      for affinity in affinities:
          if cores == "all_logical":
              ungrouped_affinities.append(
                  list(itertools.chain(*affinity))
              )
          elif cores == "single_logical":
              ungrouped_affinities.append(
                  [group[0] for group in affinity]
              )
          else:
              raise RuntimeError("Unknown cores mode")
      return ungrouped_affinities
  
imports: import collections
  import itertools
  import os
  import pathlib
  import re
  import pynvml
  from typing import Union
  from enum import Enum, auto
label_desc: Use image node_id 5 for calling a global function with example usage: ungroup_affinities(affinities, cores) and returns: ungrouped_affinities