code: def sample_simplex(
      d: int,
      n: int = 1,
      qmc: bool = False,
      seed: Optional[int] = None,
      device: Optional[torch.device] = None,
      dtype: Optional[torch.dtype] = None,
  ) -> Tensor:
      r"""Sample uniformly from a d-simplex.
  
      Args:
          d: The dimension of the simplex.
          n: The number of samples to return.
          qmc: If True, use QMC Sobol sampling (instead of i.i.d. uniform).
          seed: If provided, use as a seed for the RNG.
          device: The torch device.
          dtype: The torch dtype.
  
      Returns:
          An `n x d` tensor of uniform samples from from the d-simplex.
  
      Example:
          >>> sample_simplex(d=3, n=10)
      """
      dtype = torch.float if dtype is None else dtype
      if d == 1:
          return torch.ones(n, 1, device=device, dtype=dtype)
      if qmc:
          sobol_engine = SobolEngine(d - 1, scramble=True, seed=seed)
          rnd = sobol_engine.draw(n, dtype=dtype)
      else:
          with manual_seed(seed=seed):
              rnd = torch.rand(n, d - 1, dtype=dtype)
      srnd, _ = torch.sort(rnd, dim=-1)
      zeros = torch.zeros(n, 1, dtype=dtype)
      ones = torch.ones(n, 1, dtype=dtype)
      srnd = torch.cat([zeros, srnd, ones], dim=-1)
      if device is not None:
          srnd = srnd.to(device)
      return srnd[..., 1:] - srnd[..., :-1]
  
imports: from __future__ import annotations
  from abc import ABC, abstractmethod
  from contextlib import contextmanager
  from typing import Any, Generator, Iterable, List, Optional, Tuple, TYPE_CHECKING
  import numpy
  import scipy
  import torch
  from botorch.exceptions.errors import BotorchError
  from botorch.sampling.qmc import NormalQMCEngine
  from botorch.utils.transforms import unnormalize
  from scipy.spatial import Delaunay, HalfspaceIntersection
  from torch import LongTensor, Tensor
  from torch.quasirandom import SobolEngine
label_desc: Use image node_id 5 for calling a global function with example usage: sample_simplex(d, n, qmc, seed, device, dtype) and returns: unknown, torch