class_docstr: The `RuntimeManager` can be used for a simplified resource management.
  
  It aims to automatically detect valid `Runtimes` based on the ssh configuration.
  It can be used to create a `RuntimeGroup` based on the automatically detected
  instances and possibly based on further filters such as GPU availability.
class_docstr_tok: ["The","`","RuntimeManager","`","can","be","used","for","a","simplified","resource","management",".","It","aims","to","automatically","detect","valid","`","Runtimes","`","based","on","the","ssh","configuration",".","It","can","be","used","to","create","a","`","RuntimeGroup","`","based","on","the","automatically","detected","instances","and","possibly","based","on","further","filters","such","as","GPU","availability","."]
docstr: Create a runtime group with either all detected `Runtimes` or with a subset thereof.
  
  Args:
      include_hosts: Only these hosts will be included in the `RuntimeGroup`. Defaults to None, i.e. not
                     restricted.
      exclude_hosts: If supplied, all detected `Runtimes` beside the here specified ones will be included in the
                     group. Defaults to None, i.e. not restricted.
      gpu_required: True, if gpu availability is required. Defaults to False.
      min_memory: The minimal amount of memory in MB. Defaults to None, i.e. not restricted.
      min_cpu_cores: The minimum number of cpu cores required. Defaults to None, i.e. not restricted.
      installed_executables: Possibility to only include `Runtimes` that have an specific executables installed.
      filter_commands: Shell commands that can be used for generic filtering.
      working_dir: The directory which shall act as working one. Defaults to None. See the `Runtime` docs for
                   further details.
  
  Note:
      The filter criteria are passed through the `check_filter()` method of the `Runtime` class. See its
      documentation for further details and examples.
  
  Returns:
      RuntimeGroup: The created `RuntimeGroup`.
  
  Raises:
      ValueError: Only hosts or excluded_hosts must be provided or Hostname is not contained in the group.
      NoRuntimesError: If no `Runtime` matches the filter criteria or none could be detected.
docstr_tok: ["Create","a","runtime","group","with","either","all","detected","`","Runtimes","`","or","with","a","subset","thereof",".","Args",":","include_hosts",":","Only","these","hosts","will","be","included","in","the","`","RuntimeGroup","`",".","Defaults","to","None",",","i.e",".","not","restricted",".","exclude_hosts",":","If","supplied",",","all","detected","`","Runtimes","`","beside","the","here","specified","ones","will","be","included","in","the","group",".","Defaults","to","None",",","i.e",".","not","restricted",".","gpu_required",":","True",",","if","gpu","availability","is","required",".","Defaults","to","False",".","min_memory",":","The","minimal","amount","of","memory","in","MB",".","Defaults","to","None",",","i.e",".","not","restricted",".","min_cpu_cores",":","The","minimum","number","of","cpu","cores","required",".","Defaults","to","None",",","i.e",".","not","restricted",".","installed_executables",":","Possibility","to","only","include","`","Runtimes","`","that","have","an","specific","executables","installed",".","filter_commands",":","Shell","commands","that","can","be","used","for","generic","filtering",".","working_dir",":","The","directory","which","shall","act","as","working","one",".","Defaults","to","None",".","See","the","`","Runtime","`","docs","for","further","details",".","Note",":","The","filter","criteria","are","passed","through","the","`","check_filter","(",")","`","method","of","the","`","Runtime","`","class",".","See","its","documentation","for","further","details","and","examples",".","Returns",":","RuntimeGroup",":","The","created","`","RuntimeGroup","`",".","Raises",":","ValueError",":","Only","hosts","or","excluded_hosts","must","be","provided","or","Hostname","is","not","contained","in","the","group",".","NoRuntimesError",":","If","no","`","Runtime","`","matches","the","filter","criteria","or","none","could","be","detected","."]
code: def create_group(
      self,
      include_hosts: Union[str, List[str], None] = None,
      exclude_hosts: Union[str, List[str], None] = None,
      gpu_required: bool = False,
      min_memory: Optional[int] = None,
      min_cpu_cores: Optional[int] = None,
      installed_executables: Union[str, List[str], None] = None,
      filter_commands: Union[str, List[str], None] = None,
      working_dir: Optional[str] = None,
  ) -> RuntimeGroup:
      """Create a runtime group with either all detected `Runtimes` or with a subset thereof.
  
      Args:
          include_hosts: Only these hosts will be included in the `RuntimeGroup`. Defaults to None, i.e. not
                         restricted.
          exclude_hosts: If supplied, all detected `Runtimes` beside the here specified ones will be included in the
                         group. Defaults to None, i.e. not restricted.
          gpu_required: True, if gpu availability is required. Defaults to False.
          min_memory: The minimal amount of memory in MB. Defaults to None, i.e. not restricted.
          min_cpu_cores: The minimum number of cpu cores required. Defaults to None, i.e. not restricted.
          installed_executables: Possibility to only include `Runtimes` that have an specific executables installed.
          filter_commands: Shell commands that can be used for generic filtering.
          working_dir: The directory which shall act as working one. Defaults to None. See the `Runtime` docs for
                       further details.
  
      Note:
          The filter criteria are passed through the `check_filter()` method of the `Runtime` class. See its
          documentation for further details and examples.
  
      Returns:
          RuntimeGroup: The created `RuntimeGroup`.
  
      Raises:
          ValueError: Only hosts or excluded_hosts must be provided or Hostname is not contained in the group.
          NoRuntimesError: If no `Runtime` matches the filter criteria or none could be detected.
      """
      self.log.info("RuntimeManager starts looking for valid Runtimes.")
      runtimes_dict = self._group.get_runtimes(
          include_hosts, exclude_hosts
      )  # Raises ValueError
  
      final_runtimes = []
  
      if (
          gpu_required
          or min_memory
          or min_cpu_cores
          or installed_executables
          or filter_commands
      ):
          self.log.info(
              "RuntimeManager starts evaluating the given filter criteria"
          )
  
          # Ensure that all runtime info are read asynchronously before printing.
          # Otherwise each runtime will read its information synchronously.
          if gpu_required or min_memory or min_cpu_cores:
              self._group.fill_runtime_info_buffers_async()
  
          # The evaluation of installed_executables and filter_commands is not yet parallelized.
          # => needs refactoring if heavily used, for now we keep it simple
  
          for runtime in runtimes_dict.values():
              if runtime.check_filter(
                  gpu_required,
                  min_memory,
                  min_cpu_cores,
                  installed_executables,
                  filter_commands,
              ):
                  final_runtimes.append(runtime)
  
      else:
          final_runtimes = list(runtimes_dict.values())
  
      if working_dir:
          for runtime in final_runtimes:
              runtime.working_dir = working_dir
  
      try:
          group = RuntimeGroup(final_runtimes)
          self.log.debug("RuntimeGroup created by RuntimeManager")
      except ValueError as e:
          raise NoRuntimesDetectedError(e)
  
      self.log.info(
          f"RuntimeManager created RuntimeGroup with {str(group.runtime_count)} Runtime(s)."
      )
      return group
  
imports: import atexit
  import logging
  import warnings
  from copy import deepcopy
  from multiprocessing import Pool, Process
  from typing import Dict, Generator, List, Optional, Union
  from storm import Storm
  from lazycluster import _utils
  from lazycluster.exceptions import InvalidRuntimeError, NoPortsLeftError, NoRuntimesDetectedError, PortInUseError
  from lazycluster.runtimes import Runtime, RuntimeTask
label_desc: Use image node_id 4 for calling the RuntimeManager obj's underlying member method code with example usage: obj.create_group(include_hosts, exclude_hosts, gpu_required, min_memory, min_cpu_cores, installed_executables, filter_commands, working_dir) and returns: group