class_docstr: Builds ensembles out of runs that exist in the Backend
  
  This is used by EnsembleBuilderManager and created in a dask-client
  every time a run finishes and there is currently no EnsembleBuilder active.
docstr: Fit an ensemble from the provided runs.
  
  Note
  ----
  Expects all runs to have the "ensemble" predictions present
  
  Parameters
  ----------
  candidates: Sequence[Run]
      List of runs to build an ensemble from
  
  runs: Sequence[Run]
      List of all runs (also pruned ones and dummy runs)
  
  targets: np.ndarray | None = None
      The targets to build the ensemble with
  
  ensemble_class: Type[AbstractEnsemble]
      Implementation of the ensemble algorithm.
  
  ensemble_kwargs: Mapping[str, Any] | None
      Arguments passed to the constructor of the ensemble algorithm.
  
  X_data: SUPPORTED_FEAT_TYPES | None = None
      The base level data.
  
  task: int | None = None
      The kind of task performed
  
  metrics: Sequence[Scorer] | None = None
      Metrics to optimize the ensemble for.
  
  precision: int | None = None
      The precision with which to load run predictions
  
  random_state: int | RandomState | None = None
      The random state to use
  
  Returns
  -------
  AbstractEnsemble
docstr_tok: ["Fit","an","ensemble","from","the","provided","runs",".","Note","--","--","Expects","all","runs","to","have","the","``","ensemble","''","predictions","present","Parameters","--","--","--","--","--","candidates",":","Sequence","[","Run","]","List","of","runs","to","build","an","ensemble","from","runs",":","Sequence","[","Run","]","List","of","all","runs","(","also","pruned","ones","and","dummy","runs",")","targets",":","np.ndarray","|","None","=","None","The","targets","to","build","the","ensemble","with","ensemble_class",":","Type","[","AbstractEnsemble","]","Implementation","of","the","ensemble","algorithm",".","ensemble_kwargs",":","Mapping","[","str",",","Any","]","|","None","Arguments","passed","to","the","constructor","of","the","ensemble","algorithm",".","X_data",":","SUPPORTED_FEAT_TYPES","|","None","=","None","The","base","level","data",".","task",":","int","|","None","=","None","The","kind","of","task","performed","metrics",":","Sequence","[","Scorer","]","|","None","=","None","Metrics","to","optimize","the","ensemble","for",".","precision",":","int","|","None","=","None","The","precision","with","which","to","load","run","predictions","random_state",":","int","|","RandomState","|","None","=","None","The","random","state","to","use","Returns","--","--","--","-","AbstractEnsemble"]
code: def fit_ensemble(
      self,
      candidates: Sequence[Run],
      runs: Sequence[Run],
      *,
      targets: np.ndarray | None = None,
      ensemble_class: Type[AbstractEnsemble] = EnsembleSelection,
      ensemble_kwargs: Mapping[str, Any] | None = None,
      X_data: SUPPORTED_FEAT_TYPES | None = None,
      task: int | None = None,
      metrics: Sequence[Scorer] | None = None,
      precision: int | None = None,
      random_state: int | np.random.RandomState | None = None,
  ) -> AbstractEnsemble:
      """Fit an ensemble from the provided runs.
  
      Note
      ----
      Expects all runs to have the "ensemble" predictions present
  
      Parameters
      ----------
      candidates: Sequence[Run]
          List of runs to build an ensemble from
  
      runs: Sequence[Run]
          List of all runs (also pruned ones and dummy runs)
  
      targets: np.ndarray | None = None
          The targets to build the ensemble with
  
      ensemble_class: Type[AbstractEnsemble]
          Implementation of the ensemble algorithm.
  
      ensemble_kwargs: Mapping[str, Any] | None
          Arguments passed to the constructor of the ensemble algorithm.
  
      X_data: SUPPORTED_FEAT_TYPES | None = None
          The base level data.
  
      task: int | None = None
          The kind of task performed
  
      metrics: Sequence[Scorer] | None = None
          Metrics to optimize the ensemble for.
  
      precision: int | None = None
          The precision with which to load run predictions
  
      random_state: int | RandomState | None = None
          The random state to use
  
      Returns
      -------
      AbstractEnsemble
      """
      # Validate we have targets if None specified
      if targets is None:
          targets = self.targets("ensemble")
          if targets is None:
              path = self.backend._get_targets_ensemble_filename()
              raise ValueError(
                  f"`fit_ensemble` could not find any targets at {path}"
              )
  
      ensemble_class = (
          ensemble_class
          if ensemble_class is not None
          else self.ensemble_class
      )
  
      # Create the ensemble_kwargs, favouring in order:
      # 1) function kwargs, 2) function params 3) init_kwargs 4) init_params
  
      # Collect func params in dict if they're not None
      params = {
          k: v
          for k, v in [
              ("task_type", task),
              ("metrics", metrics),
              ("random_state", random_state),
          ]
          if v is not None
      }
  
      kwargs = {
          "backend": self.backend,
          "task_type": self.task_type,
          "metrics": self.metrics,
          "random_state": self.random_state,
          **(self.ensemble_kwargs or {}),
          **params,
          **(ensemble_kwargs or {}),
      }
  
      ensemble = ensemble_class(**kwargs)  # type: AbstractEnsemble
  
      self.logger.debug(f"Fitting ensemble on {len(candidates)} models")
      start_time = time.time()
  
      precision = precision if precision is not None else self.precision
      predictions_train = [
          run.predictions("ensemble", precision=precision)
          for run in candidates
      ]
  
      ensemble.fit(
          base_models_predictions=predictions_train,
          X_data=X_data,
          true_targets=targets,
          model_identifiers=[run.id for run in candidates],
          runs=runs,
      )
  
      duration = time.time() - start_time
      self.logger.debug(
          f"Fitting the ensemble took {duration} seconds."
      )
      return ensemble
  
imports: from __future__ import annotations
  from typing import Any, Iterable, Mapping, Sequence, Type, cast
  import logging.handlers
  import multiprocessing
  import numbers
  import os
  import pickle
  import time
  import traceback
  from itertools import accumulate
  from pathlib import Path
  import numpy
  import pandas
  import pynisher
  from sklearn.utils.validation import check_random_state
  from autosklearn.automl_common.common.utils.backend import Backend
  from autosklearn.data.validation import SUPPORTED_FEAT_TYPES
  from autosklearn.data.xy_data_manager import XYDataManager
  from autosklearn.ensemble_building.run import Run, RunID
  from autosklearn.ensembles.abstract_ensemble import AbstractEnsemble
  from autosklearn.ensembles.ensemble_selection import EnsembleSelection
  from autosklearn.metrics import Scorer, calculate_loss, calculate_scores
  from autosklearn.util.disk import rmtree
  from autosklearn.util.functional import cut, findwhere, roundrobin, split
  from autosklearn.util.logging_ import get_named_client_logger
  from autosklearn.util.parallel import preload_modules
label_desc: Use image node_id 11 for calling the EnsembleBuilder obj's underlying member method code with example usage: obj.fit_ensemble(candidates, runs) and returns: ensemble