class_docstr: Batch Hypervolume Knowledge Gradient for multi-fidelity optimization.
  
  See [Daulton2023hvkg]_ for details.
  
  A version of `qHypervolumeKnowledgeGradient` that supports multi-fidelity
  optimization via a `CostAwareUtility` and the `project` and `expand`
  operators. If none of these are set, this acquisition function reduces to
  `qHypervolumeKnowledgeGradient`. Through `valfunc_cls` and `valfunc_argfac`,
  this can be changed into a custom multi-fidelity acquisition function.
class_docstr_tok: ["Batch","Hypervolume","Knowledge","Gradient","for","multi-fidelity","optimization",".","See","[","Daulton2023hvkg","]","_","for","details",".","A","version","of","`","qHypervolumeKnowledgeGradient","`","that","supports","multi-fidelity","optimization","via","a","`","CostAwareUtility","`","and","the","`","project","`","and","`","expand","`","operators",".","If","none","of","these","are","set",",","this","acquisition","function","reduces","to","`","qHypervolumeKnowledgeGradient","`",".","Through","`","valfunc_cls","`","and","`","valfunc_argfac","`",",","this","can","be","changed","into","a","custom","multi-fidelity","acquisition","function","."]
docstr: Multi-Fidelity q-Knowledge Gradient (one-shot optimization).
  
  Args:
      model: A fitted model. Must support fantasizing.
      ref_point: A `m`-dim tensor containing the reference point.
      num_fantasies: The number of fantasy points to use. More fantasy
          points result in a better approximation, at the expense of
          memory and wall time. Unused if `sampler` is specified.
      num_pareto: The number of pareto optimal designs to consider.
      sampler: The sampler used to sample fantasy observations. Optional
          if `num_fantasies` is specified.
      objective: The objective under which the samples are evaluated. If
          `None`, then the analytic posterior mean is used. Otherwise, the
          objective is MC-evaluated (using inner_sampler).
      inner_sampler: The sampler used for inner sampling. Ignored if the
          objective is `None`.
      X_evaluation_mask: A `q x m`-dim tensor of booleans indicating which
          objective(s) each of the `q` points should be evaluated on.
      X_pending: A `n' x d`-dim Tensor of `m` design points that have
          points that have been submitted for function evaluation
          but have not yet been evaluated.
      X_pending_evaluation_mask: A `n' x m`-dim tensor of booleans indicating
          which objective(s) each of the `n'` pending points are being
          evaluated on.
      current_value: The current value, i.e. the expected best objective
          given the observed points `D`. If omitted, forward will not
          return the actual KG value, but the expected best objective
          given the data set `D u X`. If pending points are used,
          this should be the current value under the fantasy model
          conditioned on the pending points so that the incremental KG value
          from the new candidates (not pending points) is used.
      use_posterior_mean: A boolean indicating whether to use the to optimize
          the hypervolume of the posterior mean or whether to optimize the
          expected hypervolume. See [Daulton2023hvkg]_ for details.
      cost_aware_utility: A CostAwareUtility specifying the cost function for
          evaluating the `X` on the objectives indicated by `evaluation_mask`.
      project: A callable mapping a `batch_shape x q x d` tensor of design
          points to a tensor with shape `batch_shape x q_term x d` projected
          to the desired target set (e.g. the target fidelities in case of
          multi-fidelity optimization). For the basic case, `q_term = q`.
      valfunc_cls: An acquisition function class to be used as the terminal
          value function.
      valfunc_argfac: An argument factory, i.e. callable that maps a `Model`
          to a dictionary of kwargs for the terminal value function (e.g.
          `best_f` for `ExpectedImprovement`).
docstr_tok: ["Multi-Fidelity","q-Knowledge","Gradient","(","one-shot","optimization",")",".","Args",":","model",":","A","fitted","model",".","Must","support","fantasizing",".","ref_point",":","A","`","m","`","-dim","tensor","containing","the","reference","point",".","num_fantasies",":","The","number","of","fantasy","points","to","use",".","More","fantasy","points","result","in","a","better","approximation",",","at","the","expense","of","memory","and","wall","time",".","Unused","if","`","sampler","`","is","specified",".","num_pareto",":","The","number","of","pareto","optimal","designs","to","consider",".","sampler",":","The","sampler","used","to","sample","fantasy","observations",".","Optional","if","`","num_fantasies","`","is","specified",".","objective",":","The","objective","under","which","the","samples","are","evaluated",".","If","`","None","`",",","then","the","analytic","posterior","mean","is","used",".","Otherwise",",","the","objective","is","MC-evaluated","(","using","inner_sampler",")",".","inner_sampler",":","The","sampler","used","for","inner","sampling",".","Ignored","if","the","objective","is","`","None","`",".","X_evaluation_mask",":","A","`","q","x","m","`","-dim","tensor","of","booleans","indicating","which","objective","(","s",")","each","of","the","`","q","`","points","should","be","evaluated","on",".","X_pending",":","A","`","n","'","x","d","`","-dim","Tensor","of","`","m","`","design","points","that","have","points","that","have","been","submitted","for","function","evaluation","but","have","not","yet","been","evaluated",".","X_pending_evaluation_mask",":","A","`","n","'","x","m","`","-dim","tensor","of","booleans","indicating","which","objective","(","s",")","each","of","the","`","n","'","`","pending","points","are","being","evaluated","on",".","current_value",":","The","current","value",",","i.e",".","the","expected","best","objective","given","the","observed","points","`","D","`",".","If","omitted",",","forward","will","not","return","the","actual","KG","value",",","but","the","expected","best","objective","given","the","data","set","`","D","u","X","`",".","If","pending","points","are","used",",","this","should","be","the","current","value","under","the","fantasy","model","conditioned","on","the","pending","points","so","that","the","incremental","KG","value","from","the","new","candidates","(","not","pending","points",")","is","used",".","use_posterior_mean",":","A","boolean","indicating","whether","to","use","the","to","optimize","the","hypervolume","of","the","posterior","mean","or","whether","to","optimize","the","expected","hypervolume",".","See","[","Daulton2023hvkg","]","_","for","details",".","cost_aware_utility",":","A","CostAwareUtility","specifying","the","cost","function","for","evaluating","the","`","X","`","on","the","objectives","indicated","by","`","evaluation_mask","`",".","project",":","A","callable","mapping","a","`","batch_shape","x","q","x","d","`","tensor","of","design","points","to","a","tensor","with","shape","`","batch_shape","x","q_term","x","d","`","projected","to","the","desired","target","set","(","e.g",".","the","target","fidelities","in","case","of","multi-fidelity","optimization",")",".","For","the","basic","case",",","`","q_term","=","q","`",".","valfunc_cls",":","An","acquisition","function","class","to","be","used","as","the","terminal","value","function",".","valfunc_argfac",":","An","argument","factory",",","i.e",".","callable","that","maps","a","`","Model","`","to","a","dictionary","of","kwargs","for","the","terminal","value","function","(","e.g",".","`","best_f","`","for","`","ExpectedImprovement","`",")","."]
code: def __init__(
      self,
      model: Model,
      ref_point: Tensor,
      target_fidelities: Dict[int, float],
      num_fantasies: int = 8,
      num_pareto: int = 10,
      sampler: Optional[MCSampler] = None,
      objective: Optional[MCMultiOutputObjective] = None,
      inner_sampler: Optional[MCSampler] = None,
      X_pending: Optional[Tensor] = None,
      X_evaluation_mask: Optional[Tensor] = None,
      X_pending_evaluation_mask: Optional[Tensor] = None,
      current_value: Optional[Tensor] = None,
      cost_aware_utility: Optional[CostAwareUtility] = None,
      project: Callable[[Tensor], Tensor] = lambda X: X,
      valfunc_cls: Optional[Type[AcquisitionFunction]] = None,
      valfunc_argfac: Optional[
          Callable[[Model], Dict[str, Any]]
      ] = None,
      use_posterior_mean: bool = True,
      **kwargs: Any,
  ) -> None:
      r"""Multi-Fidelity q-Knowledge Gradient (one-shot optimization).
  
      Args:
          model: A fitted model. Must support fantasizing.
          ref_point: A `m`-dim tensor containing the reference point.
          num_fantasies: The number of fantasy points to use. More fantasy
              points result in a better approximation, at the expense of
              memory and wall time. Unused if `sampler` is specified.
          num_pareto: The number of pareto optimal designs to consider.
          sampler: The sampler used to sample fantasy observations. Optional
              if `num_fantasies` is specified.
          objective: The objective under which the samples are evaluated. If
              `None`, then the analytic posterior mean is used. Otherwise, the
              objective is MC-evaluated (using inner_sampler).
          inner_sampler: The sampler used for inner sampling. Ignored if the
              objective is `None`.
          X_evaluation_mask: A `q x m`-dim tensor of booleans indicating which
              objective(s) each of the `q` points should be evaluated on.
          X_pending: A `n' x d`-dim Tensor of `m` design points that have
              points that have been submitted for function evaluation
              but have not yet been evaluated.
          X_pending_evaluation_mask: A `n' x m`-dim tensor of booleans indicating
              which objective(s) each of the `n'` pending points are being
              evaluated on.
          current_value: The current value, i.e. the expected best objective
              given the observed points `D`. If omitted, forward will not
              return the actual KG value, but the expected best objective
              given the data set `D u X`. If pending points are used,
              this should be the current value under the fantasy model
              conditioned on the pending points so that the incremental KG value
              from the new candidates (not pending points) is used.
          use_posterior_mean: A boolean indicating whether to use the to optimize
              the hypervolume of the posterior mean or whether to optimize the
              expected hypervolume. See [Daulton2023hvkg]_ for details.
          cost_aware_utility: A CostAwareUtility specifying the cost function for
              evaluating the `X` on the objectives indicated by `evaluation_mask`.
          project: A callable mapping a `batch_shape x q x d` tensor of design
              points to a tensor with shape `batch_shape x q_term x d` projected
              to the desired target set (e.g. the target fidelities in case of
              multi-fidelity optimization). For the basic case, `q_term = q`.
          valfunc_cls: An acquisition function class to be used as the terminal
              value function.
          valfunc_argfac: An argument factory, i.e. callable that maps a `Model`
              to a dictionary of kwargs for the terminal value function (e.g.
              `best_f` for `ExpectedImprovement`).
      """
  
      super().__init__(
          model=model,
          ref_point=ref_point,
          num_fantasies=num_fantasies,
          num_pareto=num_pareto,
          sampler=sampler,
          objective=objective,
          inner_sampler=inner_sampler,
          X_evaluation_mask=X_evaluation_mask,
          X_pending=X_pending,
          X_pending_evaluation_mask=X_pending_evaluation_mask,
          current_value=current_value,
          use_posterior_mean=use_posterior_mean,
          cost_aware_utility=cost_aware_utility,
      )
      self.project = project
      if kwargs.get("expand") is not None:
          raise NotImplementedError(
              "Trace observations are not currently supported."
          )
      self.expand = lambda X: X
      self.valfunc_cls = valfunc_cls
      self.valfunc_argfac = valfunc_argfac
      self.target_fidelities = target_fidelities
  
imports: from copy import deepcopy
  from typing import Any, Callable, Dict, List, Optional, Tuple, Type
  import torch
  from botorch import settings
  from botorch.acquisition.acquisition import AcquisitionFunction, OneShotAcquisitionFunction
  from botorch.acquisition.cost_aware import CostAwareUtility
  from botorch.acquisition.decoupled import DecoupledAcquisitionFunction
  from botorch.acquisition.knowledge_gradient import ProjectedAcquisitionFunction
  from botorch.acquisition.multi_objective.monte_carlo import MultiObjectiveMCAcquisitionFunction, qExpectedHypervolumeImprovement
  from botorch.acquisition.multi_objective.objective import MCMultiOutputObjective
  from botorch.exceptions.errors import UnsupportedError
  from botorch.models.deterministic import PosteriorMeanModel
  from botorch.models.model import Model
  from botorch.sampling.base import MCSampler
  from botorch.sampling.list_sampler import ListSampler
  from botorch.sampling.normal import SobolQMCNormalSampler
  from botorch.sampling.stochastic_samplers import StochasticSampler
  from botorch.utils.multi_objective.box_decompositions.non_dominated import FastNondominatedPartitioning
  from botorch.utils.transforms import match_batch_shape, t_batch_mode_transform
  from torch import Tensor
label_desc: Use image node_id 1 to create a new qMultiFidelityHypervolumeKnowledgeGradient object from inherited base classes: qHypervolumeKnowledgeGradient with example: obj = qMultiFidelityHypervolumeKnowledgeGradient(model, ref_point, target_fidelities, num_fantasies, num_pareto, sampler, objective, inner_sampler, X_pending, X_evaluation_mask, X_pending_evaluation_mask, current_value, cost_aware_utility, project, valfunc_cls, valfunc_argfac, use_posterior_mean)