We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
garage_benchmark can not run without Google Cloud credential
By default, log files in benchmark will not upload to GCP storage. However, now garage_benchmark cannot run without GCP credential, and will get errors like `google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials.` @gitanshu finds this is because of [this line](https://github.com/rlworkgroup/garage/blob/36f8fbaea5ff304fa3bfea2951d4b9ad3637825f/benchmarks/src/garage_benchmarks/helper.py#L48). This line shoud be moved into `_upload_to_gcp_storage` function.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `benchmarks/src/garage_benchmarks/helper.py`
Content:
```
1 """Helper functions for benchmarks.
2 
3 A decorator and a function are provided for benchmarks. They essentially
4 take care log directory configuration and result plotting.
5 
6 The decorator can be with or without parameters to specify options for
7 plotting and JSON exporting used for automatic benchmarking.
8 
9 If plot is enabled, iterate_experiments() can be called with different
10 experiments function, each of which can have its specified env_ids. In
11 the end, figures will be generated per env_id.
12 
13 Example:
14     @benchmark
15     def ppo_benchmarks():
16         iterate_experiments(ppo_garage_tf)
17         iterate_experiments(ppo_garage_pytorch)
18 
19     @benchmark(plot=False)
20     def my_benchmarks():
21         iterate_experiments(trpo_garage_pytorch, env_ids=env_ids)
22         iterate_experiments(vpg_garage_pytorch, seeds=seeds)
23 
24 Attributes:
25     _plot (dict): A dictionary used for plotting to figures
26         grouped by tasks. If no need to plot, _plot will be None.
27     _log_dir (str): Log directory for running the benchmarking.
28     _auto (bool): Global variable used to control whether to export
29         JSON files for automatic benchmarking.
30 
31 """
32 import csv
33 import functools
34 import json
35 import os
36 import pathlib
37 import random
38 
39 from google.cloud import storage
40 import matplotlib.pyplot as plt
41 import numpy as np
42 import tensorflow as tf
43 
44 _plot = None
45 _log_dir = None
46 _auto = False
47 
48 _bucket = storage.Client().bucket('resl-garage-benchmarks')
49 
50 
51 def benchmark(exec_func=None, *, plot=True, auto=False):
52     """Decorator for benchmark function.
53 
54     Args:
55         exec_func (func): The experiment function.
56         plot (bool): Whether the result of this run needs to be plotted.
57             PNG files will be generated in sub folder /plot.
58         auto (auto): Whether this is automatic benchmarking. JSON files
59             will be generated in sub folder /auto.
60 
61     Returns:
62         func: The wrapper function.
63 
64     """
65     if exec_func is None:
66         return functools.partial(benchmark, plot=plot, auto=auto)
67 
68     @functools.wraps(exec_func)
69     def wrapper_func():
70         """The wrapper function."""
71         # pylint: disable=global-statement
72         global _plot, _log_dir, _auto
73         _plot = {} if plot else None
74         plt.close('all')
75 
76         _log_dir = _get_log_dir(exec_func.__name__)
77 
78         if os.path.exists(_log_dir):
79             count = 1
80             while os.path.exists(_log_dir + '_' + str(count)):
81                 count += 1
82             _log_dir = _log_dir + '_' + str(count)
83 
84         if auto:
85             _auto = auto
86             auto_dir = os.path.join(_log_dir, 'auto')
87             os.makedirs(auto_dir)
88 
89         exec_func()
90 
91         if plot:
92             plot_dir = os.path.join(_log_dir, 'plot')
93             os.makedirs(plot_dir)
94             for env_id in _plot:
95                 plt.figure(env_id)
96                 plt.legend()
97                 plt.xlabel(_plot[env_id]['xlabel'])
98                 plt.ylabel(_plot[env_id]['ylabel'])
99                 plt.title(env_id)
100                 plt.savefig(plot_dir + '/' + env_id)
101 
102         if auto:
103             _upload_to_gcp_storage(_log_dir)
104 
105     return wrapper_func
106 
107 
108 def iterate_experiments(func,
109                         env_ids,
110                         seeds=None,
111                         xcolumn='TotalEnvSteps',
112                         xlabel='Total Environment Steps',
113                         ycolumn='Evaluation/AverageReturn',
114                         ylabel='Average Return'):
115     """Iterate experiments for benchmarking over env_ids and seeds.
116 
117     Args:
118         env_ids (list[str]): List of environment ids.
119         seeds (list[int]): List of seeds.
120         func (func): The experiment function.
121         xcolumn (str): Which column should be the JSON x axis.
122         xlabel (str): Label name for x axis.
123         ycolumn (str): Which column should be the JSON y axis.
124         ylabel (str): Label name for y axis.
125 
126     """
127     func_name = func.__name__.replace('_', '-')
128 
129     if seeds is None:
130         seeds = random.sample(range(100), 4)
131 
132     for env_id in env_ids:
133         task_ys = []
134 
135         if _plot is not None and env_id not in _plot:
136             _plot[env_id] = {'xlabel': xlabel, 'ylabel': ylabel}
137 
138         for seed in seeds:
139             exp_name = func_name + '_' + env_id + '_' + str(seed)
140             sub_log_dir = os.path.join(_log_dir, exp_name)
141 
142             tf.compat.v1.reset_default_graph()
143 
144             func(dict(log_dir=sub_log_dir), env_id=env_id, seed=seed)
145 
146             if _plot is not None or _auto:
147                 xs, ys = _read_csv(sub_log_dir, xcolumn, ycolumn)
148                 task_ys.append(ys)
149 
150         if _plot is not None or _auto:
151             ys_mean = np.array(task_ys).mean(axis=0)
152             ys_std = np.array(task_ys).std(axis=0)
153 
154             if _plot is not None:
155                 plt.figure(env_id)
156 
157                 plt.plot(xs, ys_mean, label=func_name)
158                 plt.fill_between(xs, (ys_mean - ys_std), (ys_mean + ys_std),
159                                  alpha=.1)
160             if _auto:
161                 _export_to_json(env_id + '_' + func_name, xs, xlabel, ys_mean,
162                                 ylabel, ys_std)
163 
164 
165 def _get_log_dir(exec_func_name):
166     """Get the log directory given the experiment name.
167 
168     Args:
169         exec_func_name (str): The function name which runs benchmarks.
170 
171     Returns:
172         str: Log directory.
173 
174     """
175     cwd = pathlib.Path.cwd()
176     return str(cwd.joinpath('data', 'local', 'benchmarks', exec_func_name))
177 
178 
179 def _read_csv(log_dir, xcolumn, ycolumn):
180     """Read csv files and return xs and ys.
181 
182     Args:
183         log_dir (str): Log directory for csv file.
184         xcolumn (str): Which column should be the JSON x axis.
185         ycolumn (str): Which column should be the JSON y axis.
186 
187     Returns:
188         list: List of x axis points.
189         list: List of y axis points.
190 
191     """
192     xs, ys = [], []
193     with open(os.path.join(log_dir, 'progress.csv'), 'r') as csv_file:
194         for row in csv.DictReader(csv_file):
195             xs.append(float(row[xcolumn]))
196             ys.append(float(row[ycolumn]))
197 
198     return xs, ys
199 
200 
201 def _export_to_json(json_name, xs, xlabel, ys, ylabel, ys_std):
202     """Save selected csv column to JSON preparing for automatic benchmarking.
203 
204     Args:
205         json_name (str): The JSON file name.
206         xs (list): List of x axis points
207         xlabel (str): Label name for x axis.
208         ys (np.array): List of y axis points
209         ylabel (str): Label name for y axis.
210         ys_std (np.array): Standard deviation of y asis, used to calculate
211             upper and lower boundary for confidence interval.
212 
213     """
214     json_path = os.path.join(_log_dir, 'auto', json_name + '.json')
215     with open(json_path, 'w') as json_file:
216         json.dump(
217             dict(x=xs,
218                  y=ys.tolist(),
219                  y_min=(ys - ys_std).tolist(),
220                  y_max=(ys + ys_std).tolist(),
221                  xlabel=xlabel,
222                  ylabel=ylabel), json_file)
223 
224 
225 def _upload_to_gcp_storage(exec_dir):
226     """Upload all files to GCP storage under exec_dir folder.
227 
228     Args:
229         exec_dir (str): The execution directory.
230 
231     """
232     exec_name = os.path.basename(exec_dir)
233 
234     for folder_name in os.listdir(exec_dir):
235         folder_path = os.path.join(exec_dir, folder_name)
236         if not os.path.isfile(folder_path):
237             remote_folder = os.path.join(exec_name, folder_name)
238 
239             for file_name in os.listdir(folder_path):
240                 file_path = os.path.join(folder_path, file_name)
241                 if os.path.isfile(file_path):
242                     blob = _bucket.blob(os.path.join(remote_folder, file_name))
243                     blob.upload_from_filename(file_path)
244
```
--- 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/benchmarks/src/garage_benchmarks/helper.py b/benchmarks/src/garage_benchmarks/helper.py
--- a/benchmarks/src/garage_benchmarks/helper.py
+++ b/benchmarks/src/garage_benchmarks/helper.py
@@ -45,8 +45,6 @@
 _log_dir = None
 _auto = False
 
-_bucket = storage.Client().bucket('resl-garage-benchmarks')
-
 
 def benchmark(exec_func=None, *, plot=True, auto=False):
     """Decorator for benchmark function.
@@ -229,6 +227,7 @@
         exec_dir (str): The execution directory.
 
     """
+    _bucket = storage.Client().bucket('resl-garage-benchmarks')
     exec_name = os.path.basename(exec_dir)
 
     for folder_name in os.listdir(exec_dir):

{"golden_diff": "diff --git a/benchmarks/src/garage_benchmarks/helper.py b/benchmarks/src/garage_benchmarks/helper.py\n--- a/benchmarks/src/garage_benchmarks/helper.py\n+++ b/benchmarks/src/garage_benchmarks/helper.py\n@@ -45,8 +45,6 @@\n _log_dir = None\n _auto = False\n \n-_bucket = storage.Client().bucket('resl-garage-benchmarks')\n-\n \n def benchmark(exec_func=None, *, plot=True, auto=False):\n     \"\"\"Decorator for benchmark function.\n@@ -229,6 +227,7 @@\n         exec_dir (str): The execution directory.\n \n     \"\"\"\n+    _bucket = storage.Client().bucket('resl-garage-benchmarks')\n     exec_name = os.path.basename(exec_dir)\n \n     for folder_name in os.listdir(exec_dir):\n", "issue": "garage_benchmark can not run without Google Cloud credential\nBy default, log files in benchmark will not upload to GCP storage. However, now garage_benchmark cannot run without GCP credential, and will get errors like `google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials.` @gitanshu finds this is because of [this line](https://github.com/rlworkgroup/garage/blob/36f8fbaea5ff304fa3bfea2951d4b9ad3637825f/benchmarks/src/garage_benchmarks/helper.py#L48). This line shoud be moved into `_upload_to_gcp_storage` function.\n", "before_files": [{"content": "\"\"\"Helper functions for benchmarks.\n\nA decorator and a function are provided for benchmarks. They essentially\ntake care log directory configuration and result plotting.\n\nThe decorator can be with or without parameters to specify options for\nplotting and JSON exporting used for automatic benchmarking.\n\nIf plot is enabled, iterate_experiments() can be called with different\nexperiments function, each of which can have its specified env_ids. In\nthe end, figures will be generated per env_id.\n\nExample:\n    @benchmark\n    def ppo_benchmarks():\n        iterate_experiments(ppo_garage_tf)\n        iterate_experiments(ppo_garage_pytorch)\n\n    @benchmark(plot=False)\n    def my_benchmarks():\n        iterate_experiments(trpo_garage_pytorch, env_ids=env_ids)\n        iterate_experiments(vpg_garage_pytorch, seeds=seeds)\n\nAttributes:\n    _plot (dict): A dictionary used for plotting to figures\n        grouped by tasks. If no need to plot, _plot will be None.\n    _log_dir (str): Log directory for running the benchmarking.\n    _auto (bool): Global variable used to control whether to export\n        JSON files for automatic benchmarking.\n\n\"\"\"\nimport csv\nimport functools\nimport json\nimport os\nimport pathlib\nimport random\n\nfrom google.cloud import storage\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport tensorflow as tf\n\n_plot = None\n_log_dir = None\n_auto = False\n\n_bucket = storage.Client().bucket('resl-garage-benchmarks')\n\n\ndef benchmark(exec_func=None, *, plot=True, auto=False):\n    \"\"\"Decorator for benchmark function.\n\n    Args:\n        exec_func (func): The experiment function.\n        plot (bool): Whether the result of this run needs to be plotted.\n            PNG files will be generated in sub folder /plot.\n        auto (auto): Whether this is automatic benchmarking. JSON files\n            will be generated in sub folder /auto.\n\n    Returns:\n        func: The wrapper function.\n\n    \"\"\"\n    if exec_func is None:\n        return functools.partial(benchmark, plot=plot, auto=auto)\n\n    @functools.wraps(exec_func)\n    def wrapper_func():\n        \"\"\"The wrapper function.\"\"\"\n        # pylint: disable=global-statement\n        global _plot, _log_dir, _auto\n        _plot = {} if plot else None\n        plt.close('all')\n\n        _log_dir = _get_log_dir(exec_func.__name__)\n\n        if os.path.exists(_log_dir):\n            count = 1\n            while os.path.exists(_log_dir + '_' + str(count)):\n                count += 1\n            _log_dir = _log_dir + '_' + str(count)\n\n        if auto:\n            _auto = auto\n            auto_dir = os.path.join(_log_dir, 'auto')\n            os.makedirs(auto_dir)\n\n        exec_func()\n\n        if plot:\n            plot_dir = os.path.join(_log_dir, 'plot')\n            os.makedirs(plot_dir)\n            for env_id in _plot:\n                plt.figure(env_id)\n                plt.legend()\n                plt.xlabel(_plot[env_id]['xlabel'])\n                plt.ylabel(_plot[env_id]['ylabel'])\n                plt.title(env_id)\n                plt.savefig(plot_dir + '/' + env_id)\n\n        if auto:\n            _upload_to_gcp_storage(_log_dir)\n\n    return wrapper_func\n\n\ndef iterate_experiments(func,\n                        env_ids,\n                        seeds=None,\n                        xcolumn='TotalEnvSteps',\n                        xlabel='Total Environment Steps',\n                        ycolumn='Evaluation/AverageReturn',\n                        ylabel='Average Return'):\n    \"\"\"Iterate experiments for benchmarking over env_ids and seeds.\n\n    Args:\n        env_ids (list[str]): List of environment ids.\n        seeds (list[int]): List of seeds.\n        func (func): The experiment function.\n        xcolumn (str): Which column should be the JSON x axis.\n        xlabel (str): Label name for x axis.\n        ycolumn (str): Which column should be the JSON y axis.\n        ylabel (str): Label name for y axis.\n\n    \"\"\"\n    func_name = func.__name__.replace('_', '-')\n\n    if seeds is None:\n        seeds = random.sample(range(100), 4)\n\n    for env_id in env_ids:\n        task_ys = []\n\n        if _plot is not None and env_id not in _plot:\n            _plot[env_id] = {'xlabel': xlabel, 'ylabel': ylabel}\n\n        for seed in seeds:\n            exp_name = func_name + '_' + env_id + '_' + str(seed)\n            sub_log_dir = os.path.join(_log_dir, exp_name)\n\n            tf.compat.v1.reset_default_graph()\n\n            func(dict(log_dir=sub_log_dir), env_id=env_id, seed=seed)\n\n            if _plot is not None or _auto:\n                xs, ys = _read_csv(sub_log_dir, xcolumn, ycolumn)\n                task_ys.append(ys)\n\n        if _plot is not None or _auto:\n            ys_mean = np.array(task_ys).mean(axis=0)\n            ys_std = np.array(task_ys).std(axis=0)\n\n            if _plot is not None:\n                plt.figure(env_id)\n\n                plt.plot(xs, ys_mean, label=func_name)\n                plt.fill_between(xs, (ys_mean - ys_std), (ys_mean + ys_std),\n                                 alpha=.1)\n            if _auto:\n                _export_to_json(env_id + '_' + func_name, xs, xlabel, ys_mean,\n                                ylabel, ys_std)\n\n\ndef _get_log_dir(exec_func_name):\n    \"\"\"Get the log directory given the experiment name.\n\n    Args:\n        exec_func_name (str): The function name which runs benchmarks.\n\n    Returns:\n        str: Log directory.\n\n    \"\"\"\n    cwd = pathlib.Path.cwd()\n    return str(cwd.joinpath('data', 'local', 'benchmarks', exec_func_name))\n\n\ndef _read_csv(log_dir, xcolumn, ycolumn):\n    \"\"\"Read csv files and return xs and ys.\n\n    Args:\n        log_dir (str): Log directory for csv file.\n        xcolumn (str): Which column should be the JSON x axis.\n        ycolumn (str): Which column should be the JSON y axis.\n\n    Returns:\n        list: List of x axis points.\n        list: List of y axis points.\n\n    \"\"\"\n    xs, ys = [], []\n    with open(os.path.join(log_dir, 'progress.csv'), 'r') as csv_file:\n        for row in csv.DictReader(csv_file):\n            xs.append(float(row[xcolumn]))\n            ys.append(float(row[ycolumn]))\n\n    return xs, ys\n\n\ndef _export_to_json(json_name, xs, xlabel, ys, ylabel, ys_std):\n    \"\"\"Save selected csv column to JSON preparing for automatic benchmarking.\n\n    Args:\n        json_name (str): The JSON file name.\n        xs (list): List of x axis points\n        xlabel (str): Label name for x axis.\n        ys (np.array): List of y axis points\n        ylabel (str): Label name for y axis.\n        ys_std (np.array): Standard deviation of y asis, used to calculate\n            upper and lower boundary for confidence interval.\n\n    \"\"\"\n    json_path = os.path.join(_log_dir, 'auto', json_name + '.json')\n    with open(json_path, 'w') as json_file:\n        json.dump(\n            dict(x=xs,\n                 y=ys.tolist(),\n                 y_min=(ys - ys_std).tolist(),\n                 y_max=(ys + ys_std).tolist(),\n                 xlabel=xlabel,\n                 ylabel=ylabel), json_file)\n\n\ndef _upload_to_gcp_storage(exec_dir):\n    \"\"\"Upload all files to GCP storage under exec_dir folder.\n\n    Args:\n        exec_dir (str): The execution directory.\n\n    \"\"\"\n    exec_name = os.path.basename(exec_dir)\n\n    for folder_name in os.listdir(exec_dir):\n        folder_path = os.path.join(exec_dir, folder_name)\n        if not os.path.isfile(folder_path):\n            remote_folder = os.path.join(exec_name, folder_name)\n\n            for file_name in os.listdir(folder_path):\n                file_path = os.path.join(folder_path, file_name)\n                if os.path.isfile(file_path):\n                    blob = _bucket.blob(os.path.join(remote_folder, file_name))\n                    blob.upload_from_filename(file_path)\n", "path": "benchmarks/src/garage_benchmarks/helper.py"}], "after_files": [{"content": "\"\"\"Helper functions for benchmarks.\n\nA decorator and a function are provided for benchmarks. They essentially\ntake care log directory configuration and result plotting.\n\nThe decorator can be with or without parameters to specify options for\nplotting and JSON exporting used for automatic benchmarking.\n\nIf plot is enabled, iterate_experiments() can be called with different\nexperiments function, each of which can have its specified env_ids. In\nthe end, figures will be generated per env_id.\n\nExample:\n    @benchmark\n    def ppo_benchmarks():\n        iterate_experiments(ppo_garage_tf)\n        iterate_experiments(ppo_garage_pytorch)\n\n    @benchmark(plot=False)\n    def my_benchmarks():\n        iterate_experiments(trpo_garage_pytorch, env_ids=env_ids)\n        iterate_experiments(vpg_garage_pytorch, seeds=seeds)\n\nAttributes:\n    _plot (dict): A dictionary used for plotting to figures\n        grouped by tasks. If no need to plot, _plot will be None.\n    _log_dir (str): Log directory for running the benchmarking.\n    _auto (bool): Global variable used to control whether to export\n        JSON files for automatic benchmarking.\n\n\"\"\"\nimport csv\nimport functools\nimport json\nimport os\nimport pathlib\nimport random\n\nfrom google.cloud import storage\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport tensorflow as tf\n\n_plot = None\n_log_dir = None\n_auto = False\n\n\ndef benchmark(exec_func=None, *, plot=True, auto=False):\n    \"\"\"Decorator for benchmark function.\n\n    Args:\n        exec_func (func): The experiment function.\n        plot (bool): Whether the result of this run needs to be plotted.\n            PNG files will be generated in sub folder /plot.\n        auto (auto): Whether this is automatic benchmarking. JSON files\n            will be generated in sub folder /auto.\n\n    Returns:\n        func: The wrapper function.\n\n    \"\"\"\n    if exec_func is None:\n        return functools.partial(benchmark, plot=plot, auto=auto)\n\n    @functools.wraps(exec_func)\n    def wrapper_func():\n        \"\"\"The wrapper function.\"\"\"\n        # pylint: disable=global-statement\n        global _plot, _log_dir, _auto\n        _plot = {} if plot else None\n        plt.close('all')\n\n        _log_dir = _get_log_dir(exec_func.__name__)\n\n        if os.path.exists(_log_dir):\n            count = 1\n            while os.path.exists(_log_dir + '_' + str(count)):\n                count += 1\n            _log_dir = _log_dir + '_' + str(count)\n\n        if auto:\n            _auto = auto\n            auto_dir = os.path.join(_log_dir, 'auto')\n            os.makedirs(auto_dir)\n\n        exec_func()\n\n        if plot:\n            plot_dir = os.path.join(_log_dir, 'plot')\n            os.makedirs(plot_dir)\n            for env_id in _plot:\n                plt.figure(env_id)\n                plt.legend()\n                plt.xlabel(_plot[env_id]['xlabel'])\n                plt.ylabel(_plot[env_id]['ylabel'])\n                plt.title(env_id)\n                plt.savefig(plot_dir + '/' + env_id)\n\n        if auto:\n            _upload_to_gcp_storage(_log_dir)\n\n    return wrapper_func\n\n\ndef iterate_experiments(func,\n                        env_ids,\n                        seeds=None,\n                        xcolumn='TotalEnvSteps',\n                        xlabel='Total Environment Steps',\n                        ycolumn='Evaluation/AverageReturn',\n                        ylabel='Average Return'):\n    \"\"\"Iterate experiments for benchmarking over env_ids and seeds.\n\n    Args:\n        env_ids (list[str]): List of environment ids.\n        seeds (list[int]): List of seeds.\n        func (func): The experiment function.\n        xcolumn (str): Which column should be the JSON x axis.\n        xlabel (str): Label name for x axis.\n        ycolumn (str): Which column should be the JSON y axis.\n        ylabel (str): Label name for y axis.\n\n    \"\"\"\n    func_name = func.__name__.replace('_', '-')\n\n    if seeds is None:\n        seeds = random.sample(range(100), 4)\n\n    for env_id in env_ids:\n        task_ys = []\n\n        if _plot is not None and env_id not in _plot:\n            _plot[env_id] = {'xlabel': xlabel, 'ylabel': ylabel}\n\n        for seed in seeds:\n            exp_name = func_name + '_' + env_id + '_' + str(seed)\n            sub_log_dir = os.path.join(_log_dir, exp_name)\n\n            tf.compat.v1.reset_default_graph()\n\n            func(dict(log_dir=sub_log_dir), env_id=env_id, seed=seed)\n\n            if _plot is not None or _auto:\n                xs, ys = _read_csv(sub_log_dir, xcolumn, ycolumn)\n                task_ys.append(ys)\n\n        if _plot is not None or _auto:\n            ys_mean = np.array(task_ys).mean(axis=0)\n            ys_std = np.array(task_ys).std(axis=0)\n\n            if _plot is not None:\n                plt.figure(env_id)\n\n                plt.plot(xs, ys_mean, label=func_name)\n                plt.fill_between(xs, (ys_mean - ys_std), (ys_mean + ys_std),\n                                 alpha=.1)\n            if _auto:\n                _export_to_json(env_id + '_' + func_name, xs, xlabel, ys_mean,\n                                ylabel, ys_std)\n\n\ndef _get_log_dir(exec_func_name):\n    \"\"\"Get the log directory given the experiment name.\n\n    Args:\n        exec_func_name (str): The function name which runs benchmarks.\n\n    Returns:\n        str: Log directory.\n\n    \"\"\"\n    cwd = pathlib.Path.cwd()\n    return str(cwd.joinpath('data', 'local', 'benchmarks', exec_func_name))\n\n\ndef _read_csv(log_dir, xcolumn, ycolumn):\n    \"\"\"Read csv files and return xs and ys.\n\n    Args:\n        log_dir (str): Log directory for csv file.\n        xcolumn (str): Which column should be the JSON x axis.\n        ycolumn (str): Which column should be the JSON y axis.\n\n    Returns:\n        list: List of x axis points.\n        list: List of y axis points.\n\n    \"\"\"\n    xs, ys = [], []\n    with open(os.path.join(log_dir, 'progress.csv'), 'r') as csv_file:\n        for row in csv.DictReader(csv_file):\n            xs.append(float(row[xcolumn]))\n            ys.append(float(row[ycolumn]))\n\n    return xs, ys\n\n\ndef _export_to_json(json_name, xs, xlabel, ys, ylabel, ys_std):\n    \"\"\"Save selected csv column to JSON preparing for automatic benchmarking.\n\n    Args:\n        json_name (str): The JSON file name.\n        xs (list): List of x axis points\n        xlabel (str): Label name for x axis.\n        ys (np.array): List of y axis points\n        ylabel (str): Label name for y axis.\n        ys_std (np.array): Standard deviation of y asis, used to calculate\n            upper and lower boundary for confidence interval.\n\n    \"\"\"\n    json_path = os.path.join(_log_dir, 'auto', json_name + '.json')\n    with open(json_path, 'w') as json_file:\n        json.dump(\n            dict(x=xs,\n                 y=ys.tolist(),\n                 y_min=(ys - ys_std).tolist(),\n                 y_max=(ys + ys_std).tolist(),\n                 xlabel=xlabel,\n                 ylabel=ylabel), json_file)\n\n\ndef _upload_to_gcp_storage(exec_dir):\n    \"\"\"Upload all files to GCP storage under exec_dir folder.\n\n    Args:\n        exec_dir (str): The execution directory.\n\n    \"\"\"\n    _bucket = storage.Client().bucket('resl-garage-benchmarks')\n    exec_name = os.path.basename(exec_dir)\n\n    for folder_name in os.listdir(exec_dir):\n        folder_path = os.path.join(exec_dir, folder_name)\n        if not os.path.isfile(folder_path):\n            remote_folder = os.path.join(exec_name, folder_name)\n\n            for file_name in os.listdir(folder_path):\n                file_path = os.path.join(folder_path, file_name)\n                if os.path.isfile(file_path):\n                    blob = _bucket.blob(os.path.join(remote_folder, file_name))\n                    blob.upload_from_filename(file_path)\n", "path": "benchmarks/src/garage_benchmarks/helper.py"}]}