prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  `plot_intermediate_values` example code does not contain intermediate values.
  The example code snippet embedded in the documentation for [`plot_intermediate_values`](https://github.com/optuna/optuna/blob/master/optuna/visualization/intermediate_values.py) doesn't call `Trial.report` and thus does not contain intermediate values. The example should be updated. See also https://github.com/optuna/optuna/pull/1003#issuecomment-599359742. 
  
  Current documentation with empty plot: https://optuna.readthedocs.io/en/latest/reference/visualization.html#optuna.visualization.plot_intermediate_values
  
  </issue>
  <code>
  [start of optuna/visualization/intermediate_values.py]
  1 from optuna.logging import get_logger
  2 from optuna.trial import TrialState
  3 from optuna import type_checking
  4 from optuna.visualization.utils import _check_plotly_availability
  5 from optuna.visualization.utils import is_available
  6 
  7 if type_checking.TYPE_CHECKING:
  8     from optuna.study import Study  # NOQA
  9 
  10 if is_available():
  11     from optuna.visualization.plotly_imports import go
  12 
  13 logger = get_logger(__name__)
  14 
  15 
  16 def plot_intermediate_values(study):
  17     # type: (Study) -> go.Figure
  18     """Plot intermediate values of all trials in a study.
  19 
  20     Example:
  21 
  22         The following code snippet shows how to plot intermediate values.
  23 
  24         .. testcode::
  25 
  26             import optuna
  27 
  28             def objective(trial):
  29                 x = trial.suggest_uniform('x', -100, 100)
  30                 y = trial.suggest_categorical('y', [-1, 0, 1])
  31                 return x ** 2 + y
  32 
  33             study = optuna.create_study()
  34             study.optimize(objective, n_trials=10)
  35 
  36             optuna.visualization.plot_intermediate_values(study)
  37 
  38         .. raw:: html
  39 
  40             <iframe src="../_static/plot_intermediate_values.html"
  41              width="100%" height="500px" frameborder="0">
  42             </iframe>
  43 
  44     Args:
  45         study:
  46             A :class:`~optuna.study.Study` object whose trials are plotted for their intermediate
  47             values.
  48 
  49     Returns:
  50         A :class:`plotly.graph_objs.Figure` object.
  51     """
  52 
  53     _check_plotly_availability()
  54     return _get_intermediate_plot(study)
  55 
  56 
  57 def _get_intermediate_plot(study):
  58     # type: (Study) -> go.Figure
  59 
  60     layout = go.Layout(
  61         title="Intermediate Values Plot",
  62         xaxis={"title": "Step"},
  63         yaxis={"title": "Intermediate Value"},
  64         showlegend=False,
  65     )
  66 
  67     target_state = [TrialState.PRUNED, TrialState.COMPLETE, TrialState.RUNNING]
  68     trials = [trial for trial in study.trials if trial.state in target_state]
  69 
  70     if len(trials) == 0:
  71         logger.warning("Study instance does not contain trials.")
  72         return go.Figure(data=[], layout=layout)
  73 
  74     traces = []
  75     for trial in trials:
  76         if trial.intermediate_values:
  77             sorted_intermediate_values = sorted(trial.intermediate_values.items())
  78             trace = go.Scatter(
  79                 x=tuple((x for x, _ in sorted_intermediate_values)),
  80                 y=tuple((y for _, y in sorted_intermediate_values)),
  81                 mode="lines+markers",
  82                 marker={"maxdisplayed": 10},
  83                 name="Trial{}".format(trial.number),
  84             )
  85             traces.append(trace)
  86 
  87     if not traces:
  88         logger.warning(
  89             "You need to set up the pruning feature to utilize `plot_intermediate_values()`"
  90         )
  91         return go.Figure(data=[], layout=layout)
  92 
  93     figure = go.Figure(data=traces, layout=layout)
  94 
  95     return figure
  96
  [end of optuna/visualization/intermediate_values.py]
  [start of docs/source/scripts/plot_intermediate_values.py]
  1 import os
  2 
  3 import plotly
  4 
  5 import optuna
  6 
  7 
  8 def objective(trial):
  9     x = trial.suggest_uniform("x", -100, 100)
  10     y = trial.suggest_categorical("y", [-1, 0, 1])
  11     return x ** 2 + y
  12 
  13 
  14 def main():
  15     sampler = optuna.samplers.TPESampler(seed=10)
  16     study = optuna.create_study(sampler=sampler)
  17     study.optimize(objective, n_trials=10)
  18 
  19     fig = optuna.visualization.plot_intermediate_values(study)
  20     fig_html = plotly.offline.plot(fig, output_type="div", include_plotlyjs="cdn", auto_open=False)
  21 
  22     fig_dir = "../plotly_figures"
  23     os.makedirs(fig_dir, exist_ok=True)
  24     with open(os.path.join(fig_dir, "plot_intermediate_values.html"), "w") as f:
  25         f.write(fig_html)
  26 
  27 
  28 if __name__ == "__main__":
  29     main()
  30
  [end of docs/source/scripts/plot_intermediate_values.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/docs/source/scripts/plot_intermediate_values.py b/docs/source/scripts/plot_intermediate_values.py
  --- a/docs/source/scripts/plot_intermediate_values.py
  +++ b/docs/source/scripts/plot_intermediate_values.py
  @@ -5,16 +5,35 @@
   import optuna
   
   
  +def f(x):
  +    return (x - 2) ** 2
  +
  +
  +def df(x):
  +    return 2 * x - 4
  +
  +
   def objective(trial):
  -    x = trial.suggest_uniform("x", -100, 100)
  -    y = trial.suggest_categorical("y", [-1, 0, 1])
  -    return x ** 2 + y
  +    lr = trial.suggest_loguniform("lr", 1e-5, 1e-1)
  +
  +    x = 3
  +    for step in range(128):
  +        y = f(x)
  +
  +        trial.report(y, step=step)
  +        if trial.should_prune():
  +            raise optuna.exceptions.TrialPruned()
  +
  +        gy = df(x)
  +        x -= gy * lr
  +
  +    return y
   
   
   def main():
       sampler = optuna.samplers.TPESampler(seed=10)
       study = optuna.create_study(sampler=sampler)
  -    study.optimize(objective, n_trials=10)
  +    study.optimize(objective, n_trials=16)
   
       fig = optuna.visualization.plot_intermediate_values(study)
       fig_html = plotly.offline.plot(fig, output_type="div", include_plotlyjs="cdn", auto_open=False)
  diff --git a/optuna/visualization/intermediate_values.py b/optuna/visualization/intermediate_values.py
  --- a/optuna/visualization/intermediate_values.py
  +++ b/optuna/visualization/intermediate_values.py
  @@ -25,13 +25,30 @@
   
               import optuna
   
  +            def f(x):
  +                return (x - 2) ** 2
  +
  +            def df(x):
  +                return 2 * x - 4
  +
               def objective(trial):
  -                x = trial.suggest_uniform('x', -100, 100)
  -                y = trial.suggest_categorical('y', [-1, 0, 1])
  -                return x ** 2 + y
  +                lr = trial.suggest_loguniform("lr", 1e-5, 1e-1)
  +
  +                x = 3
  +                for step in range(128):
  +                    y = f(x)
  +
  +                    trial.report(y, step=step)
  +                    if trial.should_prune():
  +                        raise optuna.exceptions.TrialPruned()
  +
  +                    gy = df(x)
  +                    x -= gy * lr
  +
  +                return y
   
               study = optuna.create_study()
  -            study.optimize(objective, n_trials=10)
  +            study.optimize(objective, n_trials=16)
   
               optuna.visualization.plot_intermediate_values(study)
  
verification_info: {"golden_diff": "diff --git a/docs/source/scripts/plot_intermediate_values.py b/docs/source/scripts/plot_intermediate_values.py\n--- a/docs/source/scripts/plot_intermediate_values.py\n+++ b/docs/source/scripts/plot_intermediate_values.py\n@@ -5,16 +5,35 @@\n import optuna\n \n \n+def f(x):\n+    return (x - 2) ** 2\n+\n+\n+def df(x):\n+    return 2 * x - 4\n+\n+\n def objective(trial):\n-    x = trial.suggest_uniform(\"x\", -100, 100)\n-    y = trial.suggest_categorical(\"y\", [-1, 0, 1])\n-    return x ** 2 + y\n+    lr = trial.suggest_loguniform(\"lr\", 1e-5, 1e-1)\n+\n+    x = 3\n+    for step in range(128):\n+        y = f(x)\n+\n+        trial.report(y, step=step)\n+        if trial.should_prune():\n+            raise optuna.exceptions.TrialPruned()\n+\n+        gy = df(x)\n+        x -= gy * lr\n+\n+    return y\n \n \n def main():\n     sampler = optuna.samplers.TPESampler(seed=10)\n     study = optuna.create_study(sampler=sampler)\n-    study.optimize(objective, n_trials=10)\n+    study.optimize(objective, n_trials=16)\n \n     fig = optuna.visualization.plot_intermediate_values(study)\n     fig_html = plotly.offline.plot(fig, output_type=\"div\", include_plotlyjs=\"cdn\", auto_open=False)\ndiff --git a/optuna/visualization/intermediate_values.py b/optuna/visualization/intermediate_values.py\n--- a/optuna/visualization/intermediate_values.py\n+++ b/optuna/visualization/intermediate_values.py\n@@ -25,13 +25,30 @@\n \n             import optuna\n \n+            def f(x):\n+                return (x - 2) ** 2\n+\n+            def df(x):\n+                return 2 * x - 4\n+\n             def objective(trial):\n-                x = trial.suggest_uniform('x', -100, 100)\n-                y = trial.suggest_categorical('y', [-1, 0, 1])\n-                return x ** 2 + y\n+                lr = trial.suggest_loguniform(\"lr\", 1e-5, 1e-1)\n+\n+                x = 3\n+                for step in range(128):\n+                    y = f(x)\n+\n+                    trial.report(y, step=step)\n+                    if trial.should_prune():\n+                        raise optuna.exceptions.TrialPruned()\n+\n+                    gy = df(x)\n+                    x -= gy * lr\n+\n+                return y\n \n             study = optuna.create_study()\n-            study.optimize(objective, n_trials=10)\n+            study.optimize(objective, n_trials=16)\n \n             optuna.visualization.plot_intermediate_values(study)\n", "issue": "`plot_intermediate_values` example code does not contain intermediate values.\nThe example code snippet embedded in the documentation for [`plot_intermediate_values`](https://github.com/optuna/optuna/blob/master/optuna/visualization/intermediate_values.py) doesn't call `Trial.report` and thus does not contain intermediate values. The example should be updated. See also https://github.com/optuna/optuna/pull/1003#issuecomment-599359742. \r\n\r\nCurrent documentation with empty plot: https://optuna.readthedocs.io/en/latest/reference/visualization.html#optuna.visualization.plot_intermediate_values\n", "before_files": [{"content": "from optuna.logging import get_logger\nfrom optuna.trial import TrialState\nfrom optuna import type_checking\nfrom optuna.visualization.utils import _check_plotly_availability\nfrom optuna.visualization.utils import is_available\n\nif type_checking.TYPE_CHECKING:\n    from optuna.study import Study  # NOQA\n\nif is_available():\n    from optuna.visualization.plotly_imports import go\n\nlogger = get_logger(__name__)\n\n\ndef plot_intermediate_values(study):\n    # type: (Study) -> go.Figure\n    \"\"\"Plot intermediate values of all trials in a study.\n\n    Example:\n\n        The following code snippet shows how to plot intermediate values.\n\n        .. testcode::\n\n            import optuna\n\n            def objective(trial):\n                x = trial.suggest_uniform('x', -100, 100)\n                y = trial.suggest_categorical('y', [-1, 0, 1])\n                return x ** 2 + y\n\n            study = optuna.create_study()\n            study.optimize(objective, n_trials=10)\n\n            optuna.visualization.plot_intermediate_values(study)\n\n        .. raw:: html\n\n            <iframe src=\"../_static/plot_intermediate_values.html\"\n             width=\"100%\" height=\"500px\" frameborder=\"0\">\n            </iframe>\n\n    Args:\n        study:\n            A :class:`~optuna.study.Study` object whose trials are plotted for their intermediate\n            values.\n\n    Returns:\n        A :class:`plotly.graph_objs.Figure` object.\n    \"\"\"\n\n    _check_plotly_availability()\n    return _get_intermediate_plot(study)\n\n\ndef _get_intermediate_plot(study):\n    # type: (Study) -> go.Figure\n\n    layout = go.Layout(\n        title=\"Intermediate Values Plot\",\n        xaxis={\"title\": \"Step\"},\n        yaxis={\"title\": \"Intermediate Value\"},\n        showlegend=False,\n    )\n\n    target_state = [TrialState.PRUNED, TrialState.COMPLETE, TrialState.RUNNING]\n    trials = [trial for trial in study.trials if trial.state in target_state]\n\n    if len(trials) == 0:\n        logger.warning(\"Study instance does not contain trials.\")\n        return go.Figure(data=[], layout=layout)\n\n    traces = []\n    for trial in trials:\n        if trial.intermediate_values:\n            sorted_intermediate_values = sorted(trial.intermediate_values.items())\n            trace = go.Scatter(\n                x=tuple((x for x, _ in sorted_intermediate_values)),\n                y=tuple((y for _, y in sorted_intermediate_values)),\n                mode=\"lines+markers\",\n                marker={\"maxdisplayed\": 10},\n                name=\"Trial{}\".format(trial.number),\n            )\n            traces.append(trace)\n\n    if not traces:\n        logger.warning(\n            \"You need to set up the pruning feature to utilize `plot_intermediate_values()`\"\n        )\n        return go.Figure(data=[], layout=layout)\n\n    figure = go.Figure(data=traces, layout=layout)\n\n    return figure\n", "path": "optuna/visualization/intermediate_values.py"}, {"content": "import os\n\nimport plotly\n\nimport optuna\n\n\ndef objective(trial):\n    x = trial.suggest_uniform(\"x\", -100, 100)\n    y = trial.suggest_categorical(\"y\", [-1, 0, 1])\n    return x ** 2 + y\n\n\ndef main():\n    sampler = optuna.samplers.TPESampler(seed=10)\n    study = optuna.create_study(sampler=sampler)\n    study.optimize(objective, n_trials=10)\n\n    fig = optuna.visualization.plot_intermediate_values(study)\n    fig_html = plotly.offline.plot(fig, output_type=\"div\", include_plotlyjs=\"cdn\", auto_open=False)\n\n    fig_dir = \"../plotly_figures\"\n    os.makedirs(fig_dir, exist_ok=True)\n    with open(os.path.join(fig_dir, \"plot_intermediate_values.html\"), \"w\") as f:\n        f.write(fig_html)\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "docs/source/scripts/plot_intermediate_values.py"}]}