code: def make_ensemble_builder(
      make_backend: Callable[..., Backend],
      make_sklearn_dataset: Callable[..., XYDataManager],
  ) -> Callable[..., EnsembleBuilder]:
      def _make(
          *,
          automl: AutoML | None = None,
          previous_candidates: list[Run] | None = None,
          backend: Backend | None = None,
          dataset_name: str = "TEST",
          task_type: int = BINARY_CLASSIFICATION,
          metrics: Scorer = copy.deepcopy([accuracy]),
          **kwargs: Any,
      ) -> EnsembleBuilder:
          if automl:
              backend = automl._backend
              dataset_name = automl._dataset_name
              task_type = automl._task
              metrics = automl._metrics
              kwargs = {
                  "ensemble_class": automl._ensemble_class,
                  "ensemble_kwargs": automl._ensemble_kwargs,
                  "ensemble_nbest": automl._ensemble_nbest,
                  "max_models_on_disc": automl._max_models_on_disc,
                  "precision": automl.precision,
                  "read_at_most": automl._read_at_most,
                  "memory_limit": automl._memory_limit,
                  "logger_port": automl._logger_port,
              }
  
          if backend is None:
              backend = make_backend()
  
          # If there's no datamanager, just try populate it with some generic one,
          if not Path(
              backend._get_datamanager_pickle_filename()
          ).exists():
              datamanager = make_sklearn_dataset(
                  name="breast_cancer",
                  task=BINARY_CLASSIFICATION,
                  feat_type="numerical",  # They're all numerical
                  as_datamanager=True,
              )
              backend.save_datamanager(datamanager)
  
              # Annoyingly, some places use datamanger, some places use the file
              # Hence, we take the y_train of the datamanager and use that as the
              # the targets
              if "Y_train" in datamanager.data:
                  backend.save_additional_data(
                      datamanager.data["Y_train"],
                      what="targets_ensemble",
                  )
              if "X_train" in datamanager.data:
                  backend.save_additional_data(
                      datamanager.data["X_train"], what="input_ensemble"
                  )
  
          builder = EnsembleBuilder(
              backend=backend,
              dataset_name=dataset_name,
              task_type=task_type,
              metrics=metrics,
              **kwargs,
          )
  
          if previous_candidates is not None:
              with builder.previous_candidates_path.open("wb") as f:
                  pickle.dump(
                      {run.id: run for run in previous_candidates}, f
                  )
  
          return builder
  
      return _make
  
file_path: auto-sklearn/test/fixtures/ensemble_building.py
imports: from __future__ import annotations
  from typing import Any, Callable
  import copy
  import math
  import pickle
  import sys
  from pathlib import Path
  import numpy
  from autosklearn.automl import AutoML
  from autosklearn.automl_common.common.utils.backend import Backend
  from autosklearn.constants import BINARY_CLASSIFICATION
  from autosklearn.data.xy_data_manager import XYDataManager
  from autosklearn.ensemble_building import EnsembleBuilder, EnsembleBuilderManager, Run
  from autosklearn.metrics import Scorer, accuracy
  from pytest_cases import fixture
  from test.conftest import DEFAULT_SEED
label_desc: Use image node_id 2 for calling a global function with example usage: make_ensemble_builder(make_backend, make_sklearn_dataset) and returns: _make, builder