code: def _instantiate_MES(
      model: Model,
      candidate_set: Tensor,
      num_fantasies: int = 16,
      num_mv_samples: int = 10,
      num_y_samples: int = 128,
      use_gumbel: bool = True,
      X_pending: Optional[Tensor] = None,
      maximize: bool = True,
      num_trace_observations: int = 0,
      target_fidelities: Optional[Dict[int, float]] = None,
      fidelity_weights: Optional[Dict[int, float]] = None,
      cost_intercept: float = 1.0,
  ) -> qMaxValueEntropy:
      if target_fidelities:
          if fidelity_weights is None:
              fidelity_weights = {f: 1.0 for f in target_fidelities}
          if not set(target_fidelities) == set(fidelity_weights):
              raise RuntimeError(
                  "Must provide the same indices for target_fidelities "
                  f"({set(target_fidelities)}) and fidelity_weights "
                  f" ({set(fidelity_weights)})."
              )
          cost_model = AffineFidelityCostModel(
              fidelity_weights=fidelity_weights,
              fixed_cost=cost_intercept,
          )
          cost_aware_utility = InverseCostWeightedUtility(
              cost_model=cost_model
          )
  
          def project(X: Tensor) -> Tensor:
              return project_to_target_fidelity(
                  X=X, target_fidelities=target_fidelities
              )
  
          def expand(X: Tensor) -> Tensor:
              return expand_trace_observations(
                  X=X,
                  fidelity_dims=sorted(
                      target_fidelities
                  ),  # pyre-ignore: [6]
                  num_trace_obs=num_trace_observations,
              )
  
          return qMultiFidelityMaxValueEntropy(
              model=model,
              candidate_set=candidate_set,
              num_fantasies=num_fantasies,
              num_mv_samples=num_mv_samples,
              num_y_samples=num_y_samples,
              X_pending=X_pending,
              maximize=maximize,
              cost_aware_utility=cost_aware_utility,
              project=project,
              expand=expand,
          )
  
      return qMaxValueEntropy(
          model=model,
          candidate_set=candidate_set,
          num_fantasies=num_fantasies,
          num_mv_samples=num_mv_samples,
          num_y_samples=num_y_samples,
          X_pending=X_pending,
          maximize=maximize,
      )
  
imports: from typing import Any, Dict, List, Optional, Tuple, Union
  import torch
  from ax.core.search_space import SearchSpaceDigest
  from ax.models.torch.botorch import BotorchModel, get_rounding_func
  from ax.models.torch.botorch_defaults import recommend_best_out_of_sample_point
  from ax.models.torch.utils import _get_X_pending_and_observed, get_out_of_sample_best_point_acqf
  from ax.models.torch_base import TorchGenResults, TorchModel, TorchOptConfig
  from ax.utils.common.docutils import copy_doc
  from ax.utils.common.typeutils import not_none
  from botorch.acquisition.acquisition import AcquisitionFunction
  from botorch.acquisition.cost_aware import InverseCostWeightedUtility
  from botorch.acquisition.max_value_entropy_search import qMaxValueEntropy, qMultiFidelityMaxValueEntropy
  from botorch.acquisition.utils import expand_trace_observations, project_to_target_fidelity
  from botorch.exceptions.errors import UnsupportedError
  from botorch.models.cost import AffineFidelityCostModel
  from botorch.models.model import Model
  from botorch.optim.optimize import optimize_acqf
  from torch import Tensor
  from .utils import subset_model
label_desc: Use image node_id 1 for calling a global function with example usage: _instantiate_MES(model, candidate_set, num_fantasies, num_mv_samples, num_y_samples, use_gumbel, X_pending, maximize, num_trace_observations, target_fidelities, fidelity_weights, cost_intercept) and returns: qMaxValueEntropy, qMultiFidelityMaxValueEntropy, project_to_target_fidelity, expand_trace_observations