docstr: SMAC callback to handle ensemble building
  
  Parameters
  ----------
  backend: Backend
      backend to write and read files
  
  dataset_name: str
      name of dataset
  
  task: int
      Type of ML task
  
  metrics: Sequence[Scorer]
      Metrics to optimize the ensemble for
  
  time_left_for_ensemble: float = np.inf
      How much time is left for the task in seconds.
      Job should finish within this allocated time
  
  max_iterations: int | None = None
      maximal number of iterations to run this script. None indicates no limit
      on iterations.
  
  pynisher_context: "spawn" | "fork" | "forkserver" = "fork"
      The multiprocessing context for pynisher.
  
  ensemble_class : Type[AbstractEnsemble] (default=EnsembleSelection)
      Class implementing the post-hoc ensemble algorithm. Set to
      ``None`` to disable ensemble building or use ``SingleBest``
      to obtain only use the single best model instead of an
      ensemble.
  
  ensemble_kwargs : Dict, optional
      Keyword arguments that are passed to the ensemble class upon
      initialization.
  
  ensemble_nbest: int | float = 50
      If int: consider only the n best prediction
      If float: consider only this fraction of the best models
  
  max_models_on_disc: int | float | None = None
     Defines the maximum number of models that are kept in the disc.
  
     If int, it must be greater or equal than 1, and dictates the max
     number of models to keep.
  
     If float, it will be interpreted as the max megabytes allowed of
     disc space. That is, if the number of ensemble candidates require more
     disc space than this float value, the worst models will be deleted to
     keep within this budget. Models and predictions of the worst-performing
     models will be deleted then.
  
     If None, the feature is disabled. It defines an upper bound on the
     models that can be used in the ensemble.
  
  seed: int = 1
      Seed used for the inidividual runs
  
  precision: 16 | 32 | 64 | 128 = 32
      Precision of floats to read the predictions
  
  memory_limit: int | None = None
      Memory limit in mb. If ``None``, no memory limit is enforced.
  
  read_at_most: int | None = None
      read at most n new prediction files in each iteration. If `None`, will read
      the predictions and calculate losses for all runs that require it.
  
  logger_port: int = DEFAULT_TCP_LOGGING_PORT
      Port that receives logging records
  
  start_time: float | None = None
      DISABLED: Just using time.time() to set it
      The time when this job was started, to account for any latency in job
      allocation.
docstr_tok: ["SMAC","callback","to","handle","ensemble","building","Parameters","--","--","--","--","--","backend",":","Backend","backend","to","write","and","read","files","dataset_name",":","str","name","of","dataset","task",":","int","Type","of","ML","task","metrics",":","Sequence","[","Scorer","]","Metrics","to","optimize","the","ensemble","for","time_left_for_ensemble",":","float","=","np.inf","How","much","time","is","left","for","the","task","in","seconds",".","Job","should","finish","within","this","allocated","time","max_iterations",":","int","|","None","=","None","maximal","number","of","iterations","to","run","this","script",".","None","indicates","no","limit","on","iterations",".","pynisher_context",":","``","spawn","''","|","``","fork","''","|","``","forkserver","''","=","``","fork","''","The","multiprocessing","context","for","pynisher",".","ensemble_class",":","Type","[","AbstractEnsemble","]","(","default=EnsembleSelection",")","Class","implementing","the","post-hoc","ensemble","algorithm",".","Set","to","``","None","``","to","disable","ensemble","building","or","use","``","SingleBest","``","to","obtain","only","use","the","single","best","model","instead","of","an","ensemble",".","ensemble_kwargs",":","Dict",",","optional","Keyword","arguments","that","are","passed","to","the","ensemble","class","upon","initialization",".","ensemble_nbest",":","int","|","float","=","50","If","int",":","consider","only","the","n","best","prediction","If","float",":","consider","only","this","fraction","of","the","best","models","max_models_on_disc",":","int","|","float","|","None","=","None","Defines","the","maximum","number","of","models","that","are","kept","in","the","disc",".","If","int",",","it","must","be","greater","or","equal","than","1",",","and","dictates","the","max","number","of","models","to","keep",".","If","float",",","it","will","be","interpreted","as","the","max","megabytes","allowed","of","disc","space",".","That","is",",","if","the","number","of","ensemble","candidates","require","more","disc","space","than","this","float","value",",","the","worst","models","will","be","deleted","to","keep","within","this","budget",".","Models","and","predictions","of","the","worst-performing","models","will","be","deleted","then",".","If","None",",","the","feature","is","disabled",".","It","defines","an","upper","bound","on","the","models","that","can","be","used","in","the","ensemble",".","seed",":","int","=","1","Seed","used","for","the","inidividual","runs","precision",":","16","|","32","|","64","|","128","=","32","Precision","of","floats","to","read","the","predictions","memory_limit",":","int","|","None","=","None","Memory","limit","in","mb",".","If","``","None","``",",","no","memory","limit","is","enforced",".","read_at_most",":","int","|","None","=","None","read","at","most","n","new","prediction","files","in","each","iteration",".","If","`","None","`",",","will","read","the","predictions","and","calculate","losses","for","all","runs","that","require","it",".","logger_port",":","int","=","DEFAULT_TCP_LOGGING_PORT","Port","that","receives","logging","records","start_time",":","float","|","None","=","None","DISABLED",":","Just","using","time.time","(",")","to","set","it","The","time","when","this","job","was","started",",","to","account","for","any","latency","in","job","allocation","."]
code: def __init__(
      self,
      backend: Backend,
      dataset_name: str,
      task: int,
      metrics: Sequence[Scorer],
      time_left_for_ensembles: float = np.inf,
      max_iterations: int | None = None,
      pynisher_context: str = "fork",
      ensemble_class: Type[AbstractEnsemble] = EnsembleSelection,
      ensemble_kwargs: Dict[str, Any] | None = None,
      ensemble_nbest: int | float = 50,
      max_models_on_disc: int | float | None = None,
      seed: int = 1,
      precision: int = 32,
      memory_limit: int | None = None,
      read_at_most: int | None = None,
      logger_port: int = logging.handlers.DEFAULT_TCP_LOGGING_PORT,
      random_state: int | np.random.RandomState | None = None,
      start_time: float | None = None,
  ):
      """SMAC callback to handle ensemble building
  
      Parameters
      ----------
      backend: Backend
          backend to write and read files
  
      dataset_name: str
          name of dataset
  
      task: int
          Type of ML task
  
      metrics: Sequence[Scorer]
          Metrics to optimize the ensemble for
  
      time_left_for_ensemble: float = np.inf
          How much time is left for the task in seconds.
          Job should finish within this allocated time
  
      max_iterations: int | None = None
          maximal number of iterations to run this script. None indicates no limit
          on iterations.
  
      pynisher_context: "spawn" | "fork" | "forkserver" = "fork"
          The multiprocessing context for pynisher.
  
      ensemble_class : Type[AbstractEnsemble] (default=EnsembleSelection)
          Class implementing the post-hoc ensemble algorithm. Set to
          ``None`` to disable ensemble building or use ``SingleBest``
          to obtain only use the single best model instead of an
          ensemble.
  
      ensemble_kwargs : Dict, optional
          Keyword arguments that are passed to the ensemble class upon
          initialization.
  
      ensemble_nbest: int | float = 50
          If int: consider only the n best prediction
          If float: consider only this fraction of the best models
  
      max_models_on_disc: int | float | None = None
         Defines the maximum number of models that are kept in the disc.
  
         If int, it must be greater or equal than 1, and dictates the max
         number of models to keep.
  
         If float, it will be interpreted as the max megabytes allowed of
         disc space. That is, if the number of ensemble candidates require more
         disc space than this float value, the worst models will be deleted to
         keep within this budget. Models and predictions of the worst-performing
         models will be deleted then.
  
         If None, the feature is disabled. It defines an upper bound on the
         models that can be used in the ensemble.
  
      seed: int = 1
          Seed used for the inidividual runs
  
      precision: 16 | 32 | 64 | 128 = 32
          Precision of floats to read the predictions
  
      memory_limit: int | None = None
          Memory limit in mb. If ``None``, no memory limit is enforced.
  
      read_at_most: int | None = None
          read at most n new prediction files in each iteration. If `None`, will read
          the predictions and calculate losses for all runs that require it.
  
      logger_port: int = DEFAULT_TCP_LOGGING_PORT
          Port that receives logging records
  
      start_time: float | None = None
          DISABLED: Just using time.time() to set it
          The time when this job was started, to account for any latency in job
          allocation.
      """
      self.time_left_for_ensembles = time_left_for_ensembles
      self.backend = backend
      self.dataset_name = dataset_name
      self.task = task
      self.metrics = metrics
      self.ensemble_class = ensemble_class
      self.ensemble_kwargs = ensemble_kwargs
      self.ensemble_nbest = ensemble_nbest
      self.max_models_on_disc = max_models_on_disc
      self.seed = seed
      self.precision = precision
      self.max_iterations = max_iterations
      self.read_at_most = read_at_most
      self.memory_limit = memory_limit
      self.random_state = check_random_state(random_state)
      self.logger_port = logger_port
      self.pynisher_context = pynisher_context
  
      # Store something similar to SMAC's runhistory
      self.history: list[dict[str, Any]] = []
  
      # We only submit new ensembles when there is not an active ensemble job
      self.futures: list[dask.distributed.Future] = []
  
      # The last criteria is the number of iterations
      self.iteration = 0
  
      # Keep track of when we started to know when we need to finish!
      self.start_time = time.time()
  
imports: from __future__ import annotations
  from typing import Any, Dict, Sequence, Type
  import logging.handlers
  import time
  import traceback
  import dask.distributed
  import numpy
  from sklearn.utils.validation import check_random_state
  from smac.callbacks import IncorporateRunResultCallback
  from smac.optimizer.smbo import SMBO
  from smac.runhistory.runhistory import RunInfo, RunValue
  from smac.tae.base import StatusType
  from autosklearn.automl_common.common.utils.backend import Backend
  from autosklearn.ensemble_building.builder import EnsembleBuilder
  from autosklearn.ensembles.abstract_ensemble import AbstractEnsemble
  from autosklearn.ensembles.ensemble_selection import EnsembleSelection
  from autosklearn.metrics import Scorer
  from autosklearn.util.logging_ import get_named_client_logger
label_desc: Use image node_id 1 to create a new EnsembleBuilderManager object from inherited base classes: IncorporateRunResultCallback with example: obj = EnsembleBuilderManager(backend, dataset_name, task, metrics, time_left_for_ensembles, max_iterations, pynisher_context, ensemble_class, ensemble_kwargs, ensemble_nbest, max_models_on_disc, seed, precision, memory_limit, read_at_most, logger_port, random_state, start_time)