Repository: optuna/optuna

Issue:
HyperbandPruner incorrectly assumes it is the only pruner
If you take the `MultiplePruners` code from https://github.com/optuna/optuna/issues/2042#issuecomment-731515468 and create a study with `pruner=MultiplePruners([first, second, optuna.pruners.HyperbandPruner()])`

then you will end up with the following error at runtime:

```
[...]
  File "C:\Users\Gili\Documents\myproject\python\lib\site-packages\optuna\pruners\_hyperband.py", line 177, in prune
    return self._pruners[bracket_id].prune(bracket_study, trial)
  File "C:\Users\Gili\Documents\myproject\python\lib\site-packages\optuna\pruners\_successive_halving.py", line 192, in prune
    trials = study.get_trials(deepcopy=False)
  File "C:\Users\Gili\Documents\myproject\python\lib\site-packages\optuna\pruners\_hyperband.py", line 304, in get_trials
    assert isinstance(pruner, HyperbandPruner)
AssertionError
```

The problem is that `hyperband._BracketStudy.get_trials()` incorrectly assumes that `study.getPruner()` will return the hyperband but in fact it returns the `MultiplePruners` instance. You can probably fix this by passing a reference of the pruner into `_BracketStudy`'s constructor and then using it in `_BracketStudy.get_trials()`.

## Environment

optuna version is 2.9.1
python version 3.9.0
Microsoft Windows [Version 10.0.19043.1165]
HyperbandPruner incorrectly assumes it is the only pruner
If you take the `MultiplePruners` code from https://github.com/optuna/optuna/issues/2042#issuecomment-731515468 and create a study with `pruner=MultiplePruners([first, second, optuna.pruners.HyperbandPruner()])`

then you will end up with the following error at runtime:

```
[...]
  File "C:\Users\Gili\Documents\myproject\python\lib\site-packages\optuna\pruners\_hyperband.py", line 177, in prune
    return self._pruners[bracket_id].prune(bracket_study, trial)
  File "C:\Users\Gili\Documents\myproject\python\lib\site-packages\optuna\pruners\_successive_halving.py", line 192, in prune
    trials = study.get_trials(deepcopy=False)
  File "C:\Users\Gili\Documents\myproject\python\lib\site-packages\optuna\pruners\_hyperband.py", line 304, in get_trials
    assert isinstance(pruner, HyperbandPruner)
AssertionError
```

The problem is that `hyperband._BracketStudy.get_trials()` incorrectly assumes that `study.getPruner()` will return the hyperband but in fact it returns the `MultiplePruners` instance. You can probably fix this by passing a reference of the pruner into `_BracketStudy`'s constructor and then using it in `_BracketStudy.get_trials()`.

## Environment

optuna version is 2.9.1
python version 3.9.0
Microsoft Windows [Version 10.0.19043.1165]


Discussion:

Resolving patch:
diff --git a/optuna/pruners/_hyperband.py b/optuna/pruners/_hyperband.py
--- a/optuna/pruners/_hyperband.py
+++ b/optuna/pruners/_hyperband.py
@@ -284,12 +284,14 @@ class _BracketStudy(optuna.study.Study):
                 "_study",
             )
 
-            def __init__(self, study: "optuna.study.Study", bracket_id: int) -> None:
+            def __init__(
+                self, study: "optuna.study.Study", pruner: HyperbandPruner, bracket_id: int
+            ) -> None:
                 super().__init__(
                     study_name=study.study_name,
                     storage=study._storage,
                     sampler=study.sampler,
-                    pruner=study.pruner,
+                    pruner=pruner,
                 )
                 self._study = study
                 self._bracket_id = bracket_id
@@ -317,4 +319,4 @@ def __getattribute__(self, attr_name):  # type: ignore
                 else:
                     return object.__getattribute__(self, attr_name)
 
-        return _BracketStudy(study, bracket_id)
+        return _BracketStudy(study, self, bracket_id)


Test patch: