code: def sample(
      task: ProfetTask, n_samples: int = None
  ) -> Union[Trial, List[Trial]]:
      """Draw random sample(s) from the space of this task.
  
      Samples a trial (dict of hyper-parameters) from the search space of this task.
      This dict can then be passed as an input to the task to get the objective:
  
      ```python
      x: Trial = sample(task)
      assert x in task.space
      y: float = task(**x.param)
  
      xs: List[Trial] = sample(task, n_samples=2)
      ys = [task(**x.param) for x in xs]
      ```
  
      NOTE: The randomness in the sampling is also handled correctly, by passing the local rng State
      of the task.
  
      Parameters
      ----------
      task
          A Profet task.
      n_samples
          The number of samples to be drawn. When None, a single trial is returned. When an integer
          is passed, a list of Trials is returned. Defaults to `None`.
  
      Returns
      -------
      trials
          Single `orion.core.worker.trial.Trial` when `n` is not passed, or list of `Trials`, when
          `n` is an integer. Each element is a separate sample of this space, a trial containing
          values associated with the corresponding dimension.
      """
      if n_samples is None:
          return task.space.sample(
              n_samples=1, seed=task._np_rng_state
          )[0]
      return task.space.sample(
          n_samples=n_samples, seed=task._np_rng_state
      )
  
imports: from dataclasses import asdict, replace
  from logging import getLogger
  from pathlib import Path
  from typing import ClassVar, Type
  import numpy
  import pytest
  from _pytest.tmpdir import TempPathFactory
  from orion.algo.space import Space
  from typing import List, Union, overload
  from pytest_mock import MockerFixture
  from orion.benchmark.task.profet.profet_task import MetaModelConfig, ProfetTask
  from orion.core.worker.trial import Trial
  from .conftest import REAL_PROFET_DATA_DIR, is_nonempty_dir
label_desc: Use image node_id 3 for calling a global function with example usage: sample(task, n_samples) and returns: task, task