code: def get_socket_affinities(
      nproc_per_node, exclude_unavailable_cores=True
  ):
      devices = [Device(i) for i in range(nproc_per_node)]
      socket_affinities = [dev.get_cpu_affinity() for dev in devices]
  
      if exclude_unavailable_cores:
          available_cores = os.sched_getaffinity(0)
          socket_affinities = [
              list(set(affinity) & available_cores)
              for affinity in socket_affinities
          ]
  
      check_socket_affinities(socket_affinities)
  
      return socket_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 7 for calling a global function with example usage: get_socket_affinities(nproc_per_node, exclude_unavailable_cores) and returns: socket_affinities