code: def testConstantGridSearchBasicVariant(self):
      config = {
          "grid": tune.grid_search([1, 2, 3]),
          "rand": tune.uniform(0, 1000),
          "dependent_rand": tune.sample_from(
              lambda spec: spec.config.rand / 10
          ),
          "dependent_grid": tune.sample_from(
              lambda spec: spec.config.grid / 10
          ),
      }
  
      num_samples = 6
  
      from ray.tune.search.basic_variant import BasicVariantGenerator
  
      # First, do not keep random variables constant
      searcher = BasicVariantGenerator(constant_grid_search=False)
      exp = Experiment(
          run=_mock_objective,
          name="test",
          config=config,
          num_samples=num_samples,
      )
      searcher.add_configurations(exp)
  
      configs = []
      while not searcher.is_finished():
          trial = searcher.next_trial()
          if not trial:
              break
          configs.append(trial.config)
  
      for i in range(num_samples):
          sub_configs = configs[i * 3 : i * 3 + 3]
          # These should not be equal, because we sample randomly for
          # each grid search value
          self.assertNotEqual(
              sub_configs[0]["rand"], sub_configs[1]["rand"]
          )
          self.assertNotEqual(
              sub_configs[0]["rand"], sub_configs[2]["rand"]
          )
  
      # Second, keep random variables constant
      searcher = BasicVariantGenerator(constant_grid_search=True)
      exp = Experiment(
          run=_mock_objective,
          name="test",
          config=config,
          num_samples=num_samples,
      )
      searcher.add_configurations(exp)
  
      configs = []
      while not searcher.is_finished():
          trial = searcher.next_trial()
          if not trial:
              break
          configs.append(trial.config)
  
      for i in range(num_samples):
          sub_configs = configs[i * 3 : i * 3 + 3]
          # These should be equal, because we sample randomly first and
          # then keep the random values constant
          self.assertEqual(
              sub_configs[0]["rand"], sub_configs[1]["rand"]
          )
          self.assertEqual(
              sub_configs[0]["rand"], sub_configs[2]["rand"]
          )
  
      # Also, for different samples the random variables should differ
      self.assertEqual(configs[0]["grid"], configs[3]["grid"])
      self.assertNotEqual(configs[0]["rand"], configs[3]["rand"])
  
imports: from collections import defaultdict
  from unittest.mock import patch
  import numpy
  import unittest
  import ray
  import ray.tune.search.sample
  from ray import train, tune
  from ray.tune import Experiment
  from ray.tune.search.util import logger
  from ray.tune.search.variant_generator import generate_variants
label_desc: Use image node_id 48 for calling the SearchSpaceTest obj's underlying member method code with example usage: obj.testConstantGridSearchBasicVariant() without return types