class_docstr: Tests for TPE GMM Sampler
class_docstr_tok: ["Tests","for","TPE","GMM","Sampler"]
docstr: Test that sampling in a narrow space does not fail to fast
docstr_tok: ["Test","that","sampling","in","a","narrow","space","does","not","fail","to","fast"]
code: def test_sample_narrow_space(self, tpe: TPE):
      """Test that sampling in a narrow space does not fail to fast"""
      mus = numpy.ones(12) * 0.5
      sigmas = [0.5] * 12
  
      times = []
      for bounds in [
          (0.4, 0.6),
          (0.49, 0.51),
          (0.499, 0.501),
          (0.49999, 0.50001),
      ]:
          gmm_sampler = GMMSampler(tpe, mus, sigmas, *bounds)
          times.append(
              timeit.timeit(lambda: gmm_sampler.sample(2), number=100)
          )
  
      # Test that easy sampling takes less time.
      assert sorted(times) == times
  
      gmm_sampler = GMMSampler(
          tpe,
          mus,
          sigmas,
          0.05,
          0.04,
          attempts_factor=1,
          max_attempts=10,
      )
      with pytest.raises(RuntimeError) as exc:
          gmm_sampler.sample(1, attempts=10)
  
      assert exc.match("Failed to sample in interval")
  
imports: from __future__ import annotations
  import copy
  import itertools
  import timeit
  from typing import ClassVar
  import numpy
  import numpy
  import pytest
  from scipy.stats import norm
  from orion.algo.space import Categorical, Fidelity, Integer, Real, Space
  from orion.algo.tpe import TPE, CategoricalSampler, GMMSampler, adaptive_parzen_estimator, compute_max_ei_point, ramp_up_weights
  from orion.core.utils import backward, format_trials
  from orion.core.worker.algo_wrappers.space_transform import SpaceTransform
  from orion.core.worker.primary_algo import create_algo
  from orion.core.worker.transformer import build_required_space
  from orion.core.worker.trial import Trial
  from orion.testing.algo import BaseAlgoTests, TestPhase, first_phase_only
label_desc: Use image node_id 3 for calling the TestGMMSampler obj's underlying member method code with example usage: obj.test_sample_narrow_space(tpe) without return types