prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Improve ThresholdPruner example
  The variable `n_trial_step` in [Threshold Pruner](https://optuna.readthedocs.io/en/stable/reference/generated/optuna.pruners.ThresholdPruner.html) is not used.
  
  Improve ThresholdPruner example
  The variable `n_trial_step` in [Threshold Pruner](https://optuna.readthedocs.io/en/stable/reference/generated/optuna.pruners.ThresholdPruner.html) is not used.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `optuna/pruners/_threshold.py`
  Content:
  ```
  1 import math
  2 from typing import Any
  3 from typing import Optional
  4 
  5 import optuna
  6 from optuna.pruners import BasePruner
  7 from optuna.pruners._percentile import _is_first_in_interval_step
  8 
  9 
  10 def _check_value(value: Any) -> float:
  11     try:
  12         # For convenience, we allow users to report a value that can be cast to `float`.
  13         value = float(value)
  14     except (TypeError, ValueError):
  15         message = "The `value` argument is of type '{}' but supposed to be a float.".format(
  16             type(value).__name__
  17         )
  18         raise TypeError(message) from None
  19 
  20     return value
  21 
  22 
  23 class ThresholdPruner(BasePruner):
  24     """Pruner to detect outlying metrics of the trials.
  25 
  26     Prune if a metric exceeds upper threshold,
  27     falls behind lower threshold or reaches ``nan``.
  28 
  29     Example:
  30         .. testcode::
  31 
  32             from optuna import create_study
  33             from optuna.pruners import ThresholdPruner
  34             from optuna import TrialPruned
  35 
  36 
  37             def objective_for_upper(trial):
  38                 for step, y in enumerate(ys_for_upper):
  39                     trial.report(y, step)
  40 
  41                     if trial.should_prune():
  42                         raise TrialPruned()
  43                 return ys_for_upper[-1]
  44 
  45 
  46             def objective_for_lower(trial):
  47                 for step, y in enumerate(ys_for_lower):
  48                     trial.report(y, step)
  49 
  50                     if trial.should_prune():
  51                         raise TrialPruned()
  52                 return ys_for_lower[-1]
  53 
  54 
  55             ys_for_upper = [0.0, 0.1, 0.2, 0.5, 1.2]
  56             ys_for_lower = [100.0, 90.0, 0.1, 0.0, -1]
  57             n_trial_step = 5
  58 
  59             study = create_study(pruner=ThresholdPruner(upper=1.0))
  60             study.optimize(objective_for_upper, n_trials=10)
  61 
  62             study = create_study(pruner=ThresholdPruner(lower=0.0))
  63             study.optimize(objective_for_lower, n_trials=10)
  64 
  65     Args
  66         lower:
  67             A minimum value which determines whether pruner prunes or not.
  68             If an intermediate value is smaller than lower, it prunes.
  69         upper:
  70             A maximum value which determines whether pruner prunes or not.
  71             If an intermediate value is larger than upper, it prunes.
  72         n_warmup_steps:
  73             Pruning is disabled until the trial exceeds the given number of step.
  74         interval_steps:
  75             Interval in number of steps between the pruning checks, offset by the warmup steps.
  76             If no value has been reported at the time of a pruning check, that particular check
  77             will be postponed until a value is reported. Value must be at least 1.
  78 
  79     """
  80 
  81     def __init__(
  82         self,
  83         lower: Optional[float] = None,
  84         upper: Optional[float] = None,
  85         n_warmup_steps: int = 0,
  86         interval_steps: int = 1,
  87     ) -> None:
  88 
  89         if lower is None and upper is None:
  90             raise TypeError("Either lower or upper must be specified.")
  91         if lower is not None:
  92             lower = _check_value(lower)
  93         if upper is not None:
  94             upper = _check_value(upper)
  95 
  96         lower = lower if lower is not None else -float("inf")
  97         upper = upper if upper is not None else float("inf")
  98 
  99         if lower > upper:
  100             raise ValueError("lower should be smaller than upper.")
  101         if n_warmup_steps < 0:
  102             raise ValueError(
  103                 "Number of warmup steps cannot be negative but got {}.".format(n_warmup_steps)
  104             )
  105         if interval_steps < 1:
  106             raise ValueError(
  107                 "Pruning interval steps must be at least 1 but got {}.".format(interval_steps)
  108             )
  109 
  110         self._lower = lower
  111         self._upper = upper
  112         self._n_warmup_steps = n_warmup_steps
  113         self._interval_steps = interval_steps
  114 
  115     def prune(self, study: "optuna.study.Study", trial: "optuna.trial.FrozenTrial") -> bool:
  116 
  117         step = trial.last_step
  118         if step is None:
  119             return False
  120 
  121         n_warmup_steps = self._n_warmup_steps
  122         if step < n_warmup_steps:
  123             return False
  124 
  125         if not _is_first_in_interval_step(
  126             step, trial.intermediate_values.keys(), n_warmup_steps, self._interval_steps
  127         ):
  128             return False
  129 
  130         latest_value = trial.intermediate_values[step]
  131         if math.isnan(latest_value):
  132             return True
  133 
  134         if latest_value < self._lower:
  135             return True
  136 
  137         if latest_value > self._upper:
  138             return True
  139 
  140         return False
  141
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/optuna/pruners/_threshold.py b/optuna/pruners/_threshold.py
  --- a/optuna/pruners/_threshold.py
  +++ b/optuna/pruners/_threshold.py
  @@ -54,7 +54,6 @@
   
               ys_for_upper = [0.0, 0.1, 0.2, 0.5, 1.2]
               ys_for_lower = [100.0, 90.0, 0.1, 0.0, -1]
  -            n_trial_step = 5
   
               study = create_study(pruner=ThresholdPruner(upper=1.0))
               study.optimize(objective_for_upper, n_trials=10)
  @@ -70,7 +69,7 @@
               A maximum value which determines whether pruner prunes or not.
               If an intermediate value is larger than upper, it prunes.
           n_warmup_steps:
  -            Pruning is disabled until the trial exceeds the given number of step.
  +            Pruning is disabled if the step is less than the given number of warmup steps.
           interval_steps:
               Interval in number of steps between the pruning checks, offset by the warmup steps.
               If no value has been reported at the time of a pruning check, that particular check
  
verification_info: {"golden_diff": "diff --git a/optuna/pruners/_threshold.py b/optuna/pruners/_threshold.py\n--- a/optuna/pruners/_threshold.py\n+++ b/optuna/pruners/_threshold.py\n@@ -54,7 +54,6 @@\n \n             ys_for_upper = [0.0, 0.1, 0.2, 0.5, 1.2]\n             ys_for_lower = [100.0, 90.0, 0.1, 0.0, -1]\n-            n_trial_step = 5\n \n             study = create_study(pruner=ThresholdPruner(upper=1.0))\n             study.optimize(objective_for_upper, n_trials=10)\n@@ -70,7 +69,7 @@\n             A maximum value which determines whether pruner prunes or not.\n             If an intermediate value is larger than upper, it prunes.\n         n_warmup_steps:\n-            Pruning is disabled until the trial exceeds the given number of step.\n+            Pruning is disabled if the step is less than the given number of warmup steps.\n         interval_steps:\n             Interval in number of steps between the pruning checks, offset by the warmup steps.\n             If no value has been reported at the time of a pruning check, that particular check\n", "issue": "Improve ThresholdPruner example\nThe variable `n_trial_step` in [Threshold Pruner](https://optuna.readthedocs.io/en/stable/reference/generated/optuna.pruners.ThresholdPruner.html) is not used.\r\n\nImprove ThresholdPruner example\nThe variable `n_trial_step` in [Threshold Pruner](https://optuna.readthedocs.io/en/stable/reference/generated/optuna.pruners.ThresholdPruner.html) is not used.\r\n\n", "before_files": [{"content": "import math\nfrom typing import Any\nfrom typing import Optional\n\nimport optuna\nfrom optuna.pruners import BasePruner\nfrom optuna.pruners._percentile import _is_first_in_interval_step\n\n\ndef _check_value(value: Any) -> float:\n    try:\n        # For convenience, we allow users to report a value that can be cast to `float`.\n        value = float(value)\n    except (TypeError, ValueError):\n        message = \"The `value` argument is of type '{}' but supposed to be a float.\".format(\n            type(value).__name__\n        )\n        raise TypeError(message) from None\n\n    return value\n\n\nclass ThresholdPruner(BasePruner):\n    \"\"\"Pruner to detect outlying metrics of the trials.\n\n    Prune if a metric exceeds upper threshold,\n    falls behind lower threshold or reaches ``nan``.\n\n    Example:\n        .. testcode::\n\n            from optuna import create_study\n            from optuna.pruners import ThresholdPruner\n            from optuna import TrialPruned\n\n\n            def objective_for_upper(trial):\n                for step, y in enumerate(ys_for_upper):\n                    trial.report(y, step)\n\n                    if trial.should_prune():\n                        raise TrialPruned()\n                return ys_for_upper[-1]\n\n\n            def objective_for_lower(trial):\n                for step, y in enumerate(ys_for_lower):\n                    trial.report(y, step)\n\n                    if trial.should_prune():\n                        raise TrialPruned()\n                return ys_for_lower[-1]\n\n\n            ys_for_upper = [0.0, 0.1, 0.2, 0.5, 1.2]\n            ys_for_lower = [100.0, 90.0, 0.1, 0.0, -1]\n            n_trial_step = 5\n\n            study = create_study(pruner=ThresholdPruner(upper=1.0))\n            study.optimize(objective_for_upper, n_trials=10)\n\n            study = create_study(pruner=ThresholdPruner(lower=0.0))\n            study.optimize(objective_for_lower, n_trials=10)\n\n    Args\n        lower:\n            A minimum value which determines whether pruner prunes or not.\n            If an intermediate value is smaller than lower, it prunes.\n        upper:\n            A maximum value which determines whether pruner prunes or not.\n            If an intermediate value is larger than upper, it prunes.\n        n_warmup_steps:\n            Pruning is disabled until the trial exceeds the given number of step.\n        interval_steps:\n            Interval in number of steps between the pruning checks, offset by the warmup steps.\n            If no value has been reported at the time of a pruning check, that particular check\n            will be postponed until a value is reported. Value must be at least 1.\n\n    \"\"\"\n\n    def __init__(\n        self,\n        lower: Optional[float] = None,\n        upper: Optional[float] = None,\n        n_warmup_steps: int = 0,\n        interval_steps: int = 1,\n    ) -> None:\n\n        if lower is None and upper is None:\n            raise TypeError(\"Either lower or upper must be specified.\")\n        if lower is not None:\n            lower = _check_value(lower)\n        if upper is not None:\n            upper = _check_value(upper)\n\n        lower = lower if lower is not None else -float(\"inf\")\n        upper = upper if upper is not None else float(\"inf\")\n\n        if lower > upper:\n            raise ValueError(\"lower should be smaller than upper.\")\n        if n_warmup_steps < 0:\n            raise ValueError(\n                \"Number of warmup steps cannot be negative but got {}.\".format(n_warmup_steps)\n            )\n        if interval_steps < 1:\n            raise ValueError(\n                \"Pruning interval steps must be at least 1 but got {}.\".format(interval_steps)\n            )\n\n        self._lower = lower\n        self._upper = upper\n        self._n_warmup_steps = n_warmup_steps\n        self._interval_steps = interval_steps\n\n    def prune(self, study: \"optuna.study.Study\", trial: \"optuna.trial.FrozenTrial\") -> bool:\n\n        step = trial.last_step\n        if step is None:\n            return False\n\n        n_warmup_steps = self._n_warmup_steps\n        if step < n_warmup_steps:\n            return False\n\n        if not _is_first_in_interval_step(\n            step, trial.intermediate_values.keys(), n_warmup_steps, self._interval_steps\n        ):\n            return False\n\n        latest_value = trial.intermediate_values[step]\n        if math.isnan(latest_value):\n            return True\n\n        if latest_value < self._lower:\n            return True\n\n        if latest_value > self._upper:\n            return True\n\n        return False\n", "path": "optuna/pruners/_threshold.py"}], "after_files": [{"content": "import math\nfrom typing import Any\nfrom typing import Optional\n\nimport optuna\nfrom optuna.pruners import BasePruner\nfrom optuna.pruners._percentile import _is_first_in_interval_step\n\n\ndef _check_value(value: Any) -> float:\n    try:\n        # For convenience, we allow users to report a value that can be cast to `float`.\n        value = float(value)\n    except (TypeError, ValueError):\n        message = \"The `value` argument is of type '{}' but supposed to be a float.\".format(\n            type(value).__name__\n        )\n        raise TypeError(message) from None\n\n    return value\n\n\nclass ThresholdPruner(BasePruner):\n    \"\"\"Pruner to detect outlying metrics of the trials.\n\n    Prune if a metric exceeds upper threshold,\n    falls behind lower threshold or reaches ``nan``.\n\n    Example:\n        .. testcode::\n\n            from optuna import create_study\n            from optuna.pruners import ThresholdPruner\n            from optuna import TrialPruned\n\n\n            def objective_for_upper(trial):\n                for step, y in enumerate(ys_for_upper):\n                    trial.report(y, step)\n\n                    if trial.should_prune():\n                        raise TrialPruned()\n                return ys_for_upper[-1]\n\n\n            def objective_for_lower(trial):\n                for step, y in enumerate(ys_for_lower):\n                    trial.report(y, step)\n\n                    if trial.should_prune():\n                        raise TrialPruned()\n                return ys_for_lower[-1]\n\n\n            ys_for_upper = [0.0, 0.1, 0.2, 0.5, 1.2]\n            ys_for_lower = [100.0, 90.0, 0.1, 0.0, -1]\n\n            study = create_study(pruner=ThresholdPruner(upper=1.0))\n            study.optimize(objective_for_upper, n_trials=10)\n\n            study = create_study(pruner=ThresholdPruner(lower=0.0))\n            study.optimize(objective_for_lower, n_trials=10)\n\n    Args\n        lower:\n            A minimum value which determines whether pruner prunes or not.\n            If an intermediate value is smaller than lower, it prunes.\n        upper:\n            A maximum value which determines whether pruner prunes or not.\n            If an intermediate value is larger than upper, it prunes.\n        n_warmup_steps:\n            Pruning is disabled if the step is less than the given number of warmup steps.\n        interval_steps:\n            Interval in number of steps between the pruning checks, offset by the warmup steps.\n            If no value has been reported at the time of a pruning check, that particular check\n            will be postponed until a value is reported. Value must be at least 1.\n\n    \"\"\"\n\n    def __init__(\n        self,\n        lower: Optional[float] = None,\n        upper: Optional[float] = None,\n        n_warmup_steps: int = 0,\n        interval_steps: int = 1,\n    ) -> None:\n\n        if lower is None and upper is None:\n            raise TypeError(\"Either lower or upper must be specified.\")\n        if lower is not None:\n            lower = _check_value(lower)\n        if upper is not None:\n            upper = _check_value(upper)\n\n        lower = lower if lower is not None else -float(\"inf\")\n        upper = upper if upper is not None else float(\"inf\")\n\n        if lower > upper:\n            raise ValueError(\"lower should be smaller than upper.\")\n        if n_warmup_steps < 0:\n            raise ValueError(\n                \"Number of warmup steps cannot be negative but got {}.\".format(n_warmup_steps)\n            )\n        if interval_steps < 1:\n            raise ValueError(\n                \"Pruning interval steps must be at least 1 but got {}.\".format(interval_steps)\n            )\n\n        self._lower = lower\n        self._upper = upper\n        self._n_warmup_steps = n_warmup_steps\n        self._interval_steps = interval_steps\n\n    def prune(self, study: \"optuna.study.Study\", trial: \"optuna.trial.FrozenTrial\") -> bool:\n\n        step = trial.last_step\n        if step is None:\n            return False\n\n        n_warmup_steps = self._n_warmup_steps\n        if step < n_warmup_steps:\n            return False\n\n        if not _is_first_in_interval_step(\n            step, trial.intermediate_values.keys(), n_warmup_steps, self._interval_steps\n        ):\n            return False\n\n        latest_value = trial.intermediate_values[step]\n        if math.isnan(latest_value):\n            return True\n\n        if latest_value < self._lower:\n            return True\n\n        if latest_value > self._upper:\n            return True\n\n        return False\n", "path": "optuna/pruners/_threshold.py"}]}