We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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

--- 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/visualization/intermediate_values.py`
Content:
```
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
```

Path: `docs/source/scripts/plot_intermediate_values.py`
Content:
```
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 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()

```

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)

{"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"}], "after_files": [{"content": "from optuna.logging import get_logger\nfrom optuna.structs 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 f(x):\n                return (x - 2) ** 2\n\n            def df(x):\n                return 2 * x - 4\n\n            def objective(trial):\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=16)\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 f(x):\n    return (x - 2) ** 2\n\n\ndef df(x):\n    return 2 * x - 4\n\n\ndef objective(trial):\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\ndef main():\n    sampler = optuna.samplers.TPESampler(seed=10)\n    study = optuna.create_study(sampler=sampler)\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)\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"}]}