class_docstr: Batch Knowledge Gradient for multi-fidelity optimization.
  
  A version of `qKnowledgeGradient` 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 `qKnowledgeGradient`.
  Through `valfunc_cls` and `valfunc_argfac`, this can be changed into a custom
  multi-fidelity acquisition function (it is only KG if the terminal value is
  computed using a posterior mean).
class_docstr_tok: ["Batch","Knowledge","Gradient","for","multi-fidelity","optimization",".","A","version","of","`","qKnowledgeGradient","`","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","`","qKnowledgeGradient","`",".","Through","`","valfunc_cls","`","and","`","valfunc_argfac","`",",","this","can","be","changed","into","a","custom","multi-fidelity","acquisition","function","(","it","is","only","KG","if","the","terminal","value","is","computed","using","a","posterior","mean",")","."]
docstr: Multi-Fidelity q-Knowledge Gradient (one-shot optimization).
  
  Args:
      model: A fitted model. Must support fantasizing.
      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.
      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).
      posterior_transform: An optional PosteriorTransform. If given, this
          transforms the posterior before evaluation. If `objective is None`,
          then the analytic posterior mean of the transformed posterior is
          used. If `objective` is given, the `inner_sampler` is used to draw
          samples from the transformed posterior, which are then evaluated under
          the `objective`.
      inner_sampler: The sampler used for inner sampling. Ignored if the
          objective is `None`.
      X_pending: A `m x d`-dim Tensor of `m` design points that have
          points that have been submitted for function evaluation
          but have not yet been evaluated.
      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`.
      cost_aware_utility: A CostAwareUtility computing the cost-transformed
          utility from a candidate set and samples of increases in utility.
      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`.
      expand: A callable mapping a `batch_shape x q x d` input tensor to
          a `batch_shape x (q + q_e)' x d`-dim output tensor, where the
          `q_e` additional points in each q-batch correspond to
          additional ("trace") observations.
      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",".","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",".","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",")",".","posterior_transform",":","An","optional","PosteriorTransform",".","If","given",",","this","transforms","the","posterior","before","evaluation",".","If","`","objective","is","None","`",",","then","the","analytic","posterior","mean","of","the","transformed","posterior","is","used",".","If","`","objective","`","is","given",",","the","`","inner_sampler","`","is","used","to","draw","samples","from","the","transformed","posterior",",","which","are","then","evaluated","under","the","`","objective","`",".","inner_sampler",":","The","sampler","used","for","inner","sampling",".","Ignored","if","the","objective","is","`","None","`",".","X_pending",":","A","`","m","x","d","`","-dim","Tensor","of","`","m","`","design","points","that","have","points","that","have","been","submitted","for","function","evaluation","but","have","not","yet","been","evaluated",".","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","`",".","cost_aware_utility",":","A","CostAwareUtility","computing","the","cost-transformed","utility","from","a","candidate","set","and","samples","of","increases","in","utility",".","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","`",".","expand",":","A","callable","mapping","a","`","batch_shape","x","q","x","d","`","input","tensor","to","a","`","batch_shape","x","(","q","+","q_e",")","'","x","d","`","-dim","output","tensor",",","where","the","`","q_e","`","additional","points","in","each","q-batch","correspond","to","additional","(","``","trace","''",")","observations",".","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,
      num_fantasies: Optional[int] = 64,
      sampler: Optional[MCSampler] = None,
      objective: Optional[MCAcquisitionObjective] = None,
      posterior_transform: Optional[PosteriorTransform] = None,
      inner_sampler: Optional[MCSampler] = None,
      X_pending: Optional[Tensor] = None,
      current_value: Optional[Tensor] = None,
      cost_aware_utility: Optional[CostAwareUtility] = None,
      project: Callable[[Tensor], Tensor] = lambda X: X,
      expand: Callable[[Tensor], Tensor] = lambda X: X,
      valfunc_cls: Optional[Type[AcquisitionFunction]] = None,
      valfunc_argfac: Optional[
          Callable[[Model], Dict[str, Any]]
      ] = None,
  ) -> None:
      r"""Multi-Fidelity q-Knowledge Gradient (one-shot optimization).
  
      Args:
          model: A fitted model. Must support fantasizing.
          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.
          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).
          posterior_transform: An optional PosteriorTransform. If given, this
              transforms the posterior before evaluation. If `objective is None`,
              then the analytic posterior mean of the transformed posterior is
              used. If `objective` is given, the `inner_sampler` is used to draw
              samples from the transformed posterior, which are then evaluated under
              the `objective`.
          inner_sampler: The sampler used for inner sampling. Ignored if the
              objective is `None`.
          X_pending: A `m x d`-dim Tensor of `m` design points that have
              points that have been submitted for function evaluation
              but have not yet been evaluated.
          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`.
          cost_aware_utility: A CostAwareUtility computing the cost-transformed
              utility from a candidate set and samples of increases in utility.
          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`.
          expand: A callable mapping a `batch_shape x q x d` input tensor to
              a `batch_shape x (q + q_e)' x d`-dim output tensor, where the
              `q_e` additional points in each q-batch correspond to
              additional ("trace") observations.
          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`).
      """
      if current_value is None and cost_aware_utility is not None:
          raise UnsupportedError(
              "Cost-aware KG requires current_value to be specified."
          )
      super().__init__(
          model=model,
          num_fantasies=num_fantasies,
          sampler=sampler,
          objective=objective,
          posterior_transform=posterior_transform,
          inner_sampler=inner_sampler,
          X_pending=X_pending,
          current_value=current_value,
      )
      self.cost_aware_utility = cost_aware_utility
      self.project = project
      self.expand = expand
      self._cost_sampler = None
      self.valfunc_cls = valfunc_cls
      self.valfunc_argfac = valfunc_argfac
  
imports: from __future__ import annotations
  from copy import deepcopy
  from typing import Any, Callable, Dict, Optional, Tuple, Type
  import torch
  from botorch import settings
  from botorch.acquisition.acquisition import AcquisitionFunction, MCSamplerMixin, OneShotAcquisitionFunction
  from botorch.acquisition.analytic import PosteriorMean
  from botorch.acquisition.cost_aware import CostAwareUtility
  from botorch.acquisition.monte_carlo import MCAcquisitionFunction, qSimpleRegret
  from botorch.acquisition.objective import MCAcquisitionObjective, PosteriorTransform
  from botorch.exceptions.errors import UnsupportedError
  from botorch.models.model import Model
  from botorch.sampling.base import MCSampler
  from botorch.sampling.normal import SobolQMCNormalSampler
  from botorch.utils.transforms import concatenate_pending_points, match_batch_shape, t_batch_mode_transform
  from torch import Tensor
label_desc: Use image node_id 1 to create a new qMultiFidelityKnowledgeGradient object from inherited base classes: qKnowledgeGradient with example: obj = qMultiFidelityKnowledgeGradient(model, num_fantasies, sampler, objective, posterior_transform, inner_sampler, X_pending, current_value, cost_aware_utility, project, expand, valfunc_cls, valfunc_argfac)