class_docstr: A posterior based on a PyTorch Distribution.
  
  NOTE: For any attribute that is not explicitly defined on the Posterior level, this
  returns the corresponding attribute of the distribution. This allows easy access
  to the distribution attributes, without having to expose them on the Posterior.
class_docstr_tok: ["A","posterior","based","on","a","PyTorch","Distribution",".","NOTE",":","For","any","attribute","that","is","not","explicitly","defined","on","the","Posterior","level",",","this","returns","the","corresponding","attribute","of","the","distribution",".","This","allows","easy","access","to","the","distribution","attributes",",","without","having","to","expose","them","on","the","Posterior","."]
docstr: Sample from the posterior (with gradients).
  
  This is generally used with a sampler that produces the base samples.
  
  Args:
      sample_shape: A `torch.Size` object specifying the sample shape. To
          draw `n` samples, set to `torch.Size([n])`. To draw `b` batches
          of `n` samples each, set to `torch.Size([b, n])`.
  
  Returns:
      Samples from the posterior, a tensor of shape
      `self._extended_shape(sample_shape=sample_shape)`.
docstr_tok: ["Sample","from","the","posterior","(","with","gradients",")",".","This","is","generally","used","with","a","sampler","that","produces","the","base","samples",".","Args",":","sample_shape",":","A","`","torch.Size","`","object","specifying","the","sample","shape",".","To","draw","`","n","`","samples",",","set","to","`","torch.Size","(","[","n","]",")","`",".","To","draw","`","b","`","batches","of","`","n","`","samples","each",",","set","to","`","torch.Size","(","[","b",",","n","]",")","`",".","Returns",":","Samples","from","the","posterior",",","a","tensor","of","shape","`","self._extended_shape","(","sample_shape=sample_shape",")","`","."]
code: def rsample(
      self,
      sample_shape: Optional[torch.Size] = None,
  ) -> Tensor:
      r"""Sample from the posterior (with gradients).
  
      This is generally used with a sampler that produces the base samples.
  
      Args:
          sample_shape: A `torch.Size` object specifying the sample shape. To
              draw `n` samples, set to `torch.Size([n])`. To draw `b` batches
              of `n` samples each, set to `torch.Size([b, n])`.
  
      Returns:
          Samples from the posterior, a tensor of shape
          `self._extended_shape(sample_shape=sample_shape)`.
      """
      if sample_shape is None:
          sample_shape = torch.Size()
      return self.distribution.rsample(sample_shape=sample_shape)
  
file_path: botorch/botorch/posteriors/torch.py
imports: from __future__ import annotations
  from typing import Any, Dict, Optional
  import torch
  from botorch.posteriors.posterior import Posterior
  from torch import Tensor
  from torch.distributions.distribution import Distribution
label_desc: Use image node_id 2 for calling the TorchPosterior obj's underlying member method code with example usage: obj.rsample(sample_shape) and returns: self