class_docstr: The multivariate Value-at-Risk as introduced in [Prekopa2012MVaR]_.
  
  MVaR is defined as the non-dominated set of points in the extended domain
  of the random variable that have multivariate CDF greater than or equal to
  `alpha`. Note that MVaR is set valued and the size of the set depends on the
  particular realizations of the random variable. [Cousin2013MVaR]_ instead
  propose to use the expectation of the set-valued MVaR as the multivariate
  VaR. We support this alternative with an `expectation` flag.
  
  This supports approximate gradients as discussed in [Daulton2022MARS]_.
docstr: Calculate the MVaR corresponding to the given samples.
  
  Args:
      samples: A `sample_shape x batch_shape x (q * n_w) x m`-dim tensor of
          posterior samples. The q-batches should be ordered so that each
          `n_w` block of samples correspond to the same input.
      X: A `batch_shape x q x d`-dim tensor of inputs. Ignored.
  
  Returns:
      A `sample_shape x batch_shape x q x m'`-dim tensor of MVaR values,
      if `self.expectation=True`.
      Otherwise, this returns a `sample_shape x batch_shape x (q * k') x m'`-dim
      tensor, where `k'` is the maximum `k` across all batches that is returned
      by `get_mvar_set_...`. Each `(q * k') x m'` corresponds to the `k` MVaR
      values for each `q` batch of `n_w` inputs, padded up to `k'` by repeating
      the last element. If `self.pad_to_n_w`, we set `k' = self.n_w`, producing
      a deterministic return shape.
docstr_tok: ["Calculate","the","MVaR","corresponding","to","the","given","samples",".","Args",":","samples",":","A","`","sample_shape","x","batch_shape","x","(","q","*","n_w",")","x","m","`","-dim","tensor","of","posterior","samples",".","The","q-batches","should","be","ordered","so","that","each","`","n_w","`","block","of","samples","correspond","to","the","same","input",".","X",":","A","`","batch_shape","x","q","x","d","`","-dim","tensor","of","inputs",".","Ignored",".","Returns",":","A","`","sample_shape","x","batch_shape","x","q","x","m","'","`","-dim","tensor","of","MVaR","values",",","if","`","self.expectation=True","`",".","Otherwise",",","this","returns","a","`","sample_shape","x","batch_shape","x","(","q","*","k","'",")","x","m","'","`","-dim","tensor",",","where","`","k","'","`","is","the","maximum","`","k","`","across","all","batches","that","is","returned","by","`","get_mvar_set_","...","`",".","Each","`","(","q","*","k","'",")","x","m","'","`","corresponds","to","the","`","k","`","MVaR","values","for","each","`","q","`","batch","of","`","n_w","`","inputs",",","padded","up","to","`","k","'","`","by","repeating","the","last","element",".","If","`","self.pad_to_n_w","`",",","we","set","`","k","'","=","self.n_w","`",",","producing","a","deterministic","return","shape","."]
code: def forward(
      self,
      samples: Tensor,
      X: Optional[Tensor] = None,
  ) -> Tensor:
      r"""Calculate the MVaR corresponding to the given samples.
  
      Args:
          samples: A `sample_shape x batch_shape x (q * n_w) x m`-dim tensor of
              posterior samples. The q-batches should be ordered so that each
              `n_w` block of samples correspond to the same input.
          X: A `batch_shape x q x d`-dim tensor of inputs. Ignored.
  
      Returns:
          A `sample_shape x batch_shape x q x m'`-dim tensor of MVaR values,
          if `self.expectation=True`.
          Otherwise, this returns a `sample_shape x batch_shape x (q * k') x m'`-dim
          tensor, where `k'` is the maximum `k` across all batches that is returned
          by `get_mvar_set_...`. Each `(q * k') x m'` corresponds to the `k` MVaR
          values for each `q` batch of `n_w` inputs, padded up to `k'` by repeating
          the last element. If `self.pad_to_n_w`, we set `k' = self.n_w`, producing
          a deterministic return shape.
      """
      batch_shape, m = samples.shape[:-2], samples.shape[-1]
      prepared_samples = self._prepare_samples(samples)
      # This is -1 x n_w x m.
      prepared_samples = prepared_samples.reshape(
          -1, *prepared_samples.shape[-2:]
      )
      with torch.no_grad():
          if self.use_counting:
              mvar_set = self.get_mvar_set_via_counting(
                  prepared_samples
              )
          else:
              mvar_set = self.get_mvar_set_vectorized(prepared_samples)
      # Set the `pad_size` to either `self.n_w` or the size of the largest MVaR set.
      pad_size = (
          self.n_w
          if self.pad_to_n_w
          else max([_.shape[0] for _ in mvar_set])
      )
      padded_mvar_list = []
      for mvar_ in mvar_set:
          if self.expectation:
              padded_mvar_list.append(mvar_.mean(dim=0))
          else:
              # Repeat the last entry to make `mvar_set` `pad_size x m`.
              repeats_needed = pad_size - mvar_.shape[0]
              padded_mvar_list.append(
                  torch.cat(
                      [mvar_, mvar_[-1].expand(repeats_needed, m)],
                      dim=0,
                  )
              )
      mvars = torch.stack(padded_mvar_list, dim=0)
      if samples.requires_grad:
          mvars = self.make_differentiable(
              prepared_samples=prepared_samples, mvars=mvars
          )
      return mvars.view(*batch_shape, -1, m)
  
imports: import warnings
  from abc import ABC, abstractmethod
  from math import ceil
  from typing import Callable, List, Optional, Union
  import torch
  from botorch.acquisition.multi_objective.objective import IdentityMCMultiOutputObjective, MCMultiOutputObjective
  from botorch.acquisition.risk_measures import CVaR, RiskMeasureMCObjective, VaR
  from botorch.exceptions.errors import UnsupportedError
  from botorch.exceptions.warnings import BotorchWarning
  from botorch.models.model import Model
  from botorch.utils.multi_objective.pareto import is_non_dominated
  from botorch.utils.transforms import normalize
  from torch import Tensor
label_desc: Use image node_id 5 for calling the MVaR obj's underlying member method code with example usage: obj.forward(samples, X) and returns: mvars