code: def extract_map_statedict(
      m_b: Union[ALEBOGP, ModelListGP], num_outputs: int
  ) -> List[MutableMapping[str, Tensor]]:
      """Extract MAP statedict from the batch-mode ALEBO GP.
  
      The batch GP can be either a single ALEBO GP or a ModelListGP of ALEBO GPs.
  
      Args:
          m_b: Batch-mode GP.
          num_outputs: Number of outputs being modeled.
      """
      warn(
          "`extract_map_statedict` from ax.models.torch.alebo.py is deprecated and "
          "should be removed in Ax 0.5.0.",
          DeprecationWarning,
      )
      is_modellist = num_outputs > 1
      map_sds: List[MutableMapping[str, Tensor]] = [
          OrderedDict() for i in range(num_outputs)
      ]
      sd = m_b.state_dict()
      for k, v in sd.items():
          # Extract model index and parameter name
          if is_modellist:
              g = re.match(r"^models\.([0-9]+)\.(.*)$", k)
              if g is None:
                  raise Exception("Unable to parse ModelList structure")
              model_idx = int(g.group(1))
              param_name = g.group(2)
          else:
              model_idx = 0
              param_name = k
          if len(v.shape) > 1:
              v = torch.select(v, 0, 0)
          map_sds[model_idx][param_name] = v
      return map_sds
  
imports: from __future__ import annotations
  import dataclasses
  import re
  from collections import OrderedDict
  from logging import Logger
  from math import inf
  from numbers import Number
  from typing import Any, Callable, Dict, List, MutableMapping, Optional, Tuple, TypeVar, Union
  from warnings import warn
  import gpytorch
  import numpy
  import torch
  from ax.core.search_space import SearchSpaceDigest
  from ax.core.types import TCandidateMetadata
  from ax.models.random.alebo_initializer import ALEBOInitializer
  from ax.models.torch.botorch import BotorchModel
  from ax.models.torch.botorch_defaults import get_qLogNEI
  from ax.models.torch.utils import _datasets_to_legacy_inputs
  from ax.models.torch_base import TorchGenResults, TorchModel, TorchOptConfig
  from ax.utils.common.docutils import copy_doc
  from ax.utils.common.logger import get_logger
  from ax.utils.common.typeutils import checked_cast
  from botorch.acquisition.acquisition import AcquisitionFunction
  from botorch.acquisition.analytic import ExpectedImprovement
  from botorch.acquisition.objective import PosteriorTransform
  from botorch.models.gp_regression import SingleTaskGP
  from botorch.models.gpytorch import GPyTorchModel
  from botorch.models.model_list_gp_regression import ModelListGP
  from botorch.optim.fit import fit_gpytorch_mll_scipy
  from botorch.optim.initializers import initialize_q_batch_nonneg
  from botorch.optim.optimize import optimize_acqf
  from botorch.optim.utils import _handle_numerical_errors, get_parameters_and_bounds, TorchAttr
  from botorch.posteriors.gpytorch import GPyTorchPosterior
  from botorch.utils.datasets import SupervisedDataset
  from gpytorch.distributions.multivariate_normal import MultivariateNormal
  from gpytorch.kernels.kernel import Kernel
  from gpytorch.kernels.rbf_kernel import postprocess_rbf
  from gpytorch.kernels.scale_kernel import ScaleKernel
  from gpytorch.mlls.exact_marginal_log_likelihood import ExactMarginalLogLikelihood
  from scipy.optimize import approx_fprime
  from torch import Tensor
  from torch.nn.parameter import Parameter
label_desc: Use image node_id 8 for calling a global function with example usage: extract_map_statedict(m_b, num_outputs) and returns: map_sds