code: def test_hyperband_filter_study(
      sampler_init_func: Callable[[], optuna.samplers.BaseSampler]
  ) -> None:
      def objective(trial: optuna.trial.Trial) -> float:
          return trial.suggest_float("value", 0.0, 1.0)
  
      n_trials = 8
      n_brackets = 4
      expected_n_trials_per_bracket = n_trials // n_brackets
      with mock.patch(
          "optuna.pruners.HyperbandPruner._get_bracket_id",
          new=mock.Mock(
              side_effect=lambda study, trial: trial.number % n_brackets
          ),
      ):
          for method_name in [
              "infer_relative_search_space",
              "sample_relative",
              "sample_independent",
          ]:
              sampler = sampler_init_func()
              pruner = optuna.pruners.HyperbandPruner(
                  min_resource=MIN_RESOURCE,
                  max_resource=MAX_RESOURCE,
                  reduction_factor=REDUCTION_FACTOR,
              )
              with mock.patch(
                  "optuna.samplers.{}.{}".format(
                      sampler.__class__.__name__, method_name
                  ),
                  wraps=getattr(sampler, method_name),
              ) as method_mock:
                  study = optuna.study.create_study(
                      sampler=sampler, pruner=pruner
                  )
                  study.optimize(objective, n_trials=n_trials)
                  args = method_mock.call_args[0]
                  study = args[0]
                  trials = study.get_trials()
                  assert len(trials) == expected_n_trials_per_bracket
  
file_path: optuna/tests/pruners_tests/test_hyperband.py
imports: from typing import Callable
  from unittest import mock
  import numpy
  import pytest
  import optuna
label_desc: Use image node_id 5 for calling a global function with example usage: test_hyperband_filter_study(sampler_init_func) and returns: trial