code: def test_study_optimize_with_nonconstant_search_space() -> None:
      def objective_nonconstant_range(trial: Trial) -> float:
          x = trial.suggest_int("x", -1, trial.number)
          return x
  
      study = optuna.create_study(sampler=samplers.BruteForceSampler())
      with pytest.raises(ValueError):
          study.optimize(objective_nonconstant_range, n_trials=10)
  
      def objective_increasing_variable(trial: Trial) -> float:
          return sum(trial.suggest_int(f"x{i}", 0, 0) for i in range(2))
  
      study = optuna.create_study(sampler=samplers.BruteForceSampler())
      study.add_trial(
          optuna.create_trial(
              params={"x0": 0},
              value=0.0,
              distributions={
                  "x0": optuna.distributions.IntDistribution(0, 0)
              },
          )
      )
      with pytest.raises(ValueError):
          study.optimize(objective_increasing_variable, n_trials=10)
  
      def objective_decreasing_variable(trial: Trial) -> float:
          return trial.suggest_int("x0", 0, 0)
  
      study = optuna.create_study(sampler=samplers.BruteForceSampler())
      study.add_trial(
          optuna.create_trial(
              params={"x0": 0, "x1": 0},
              value=0.0,
              distributions={
                  "x0": optuna.distributions.IntDistribution(0, 0),
                  "x1": optuna.distributions.IntDistribution(0, 0),
              },
          )
      )
      with pytest.raises(ValueError):
          study.optimize(objective_decreasing_variable, n_trials=10)
  
file_path: optuna/tests/samplers_tests/test_brute_force.py
imports: import numpy
  import pytest
  import optuna
  from optuna import samplers
  from optuna.samplers._brute_force import _TreeNode
  from optuna.trial import Trial
label_desc: Use image node_id 9 for calling a global function with example usage: test_study_optimize_with_nonconstant_search_space() and returns: x, sum, trial