We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Remove conda environment from CI/Dockerfiles
Now that we use setup.py for tracking dependencies, there's no need be creating conda environments inside the Dockerfile and CI. We can replace them with a vanilla virtualenv for greatest compatibility.

I suggest we add tests which ensure that the package can still be successfully solved and installed by conda and pipenv. If they don't take too long (<2min) then we can run them in the main CI, otherwise they will be cron_job tests (which are run only nightly).

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `setup.py`
Content:
```
1 from setuptools import find_packages
2 from setuptools import setup
3 
4 # Required dependencies
5 required = [
6     # Please keep alphabetized
7     'akro==0.0.6',
8     'cached_property',
9     'click',
10     'cloudpickle',
11     'cma==1.1.06',
12     # dm_control throws an error during install about not being able to
13     # find a build dependency (absl-py). Later pip executes the `install`
14     # command again and the install succeeds because absl-py has been
15     # installed. This is stupid, but harmless.
16     'dm_control @ https://api.github.com/repos/deepmind/dm_control/tarball/7a36377879c57777e5d5b4da5aae2cd2a29b607a',  # noqa: E501
17     'dowel==0.0.2',
18     'gym[all]==0.12.4',
19     'joblib<0.13,>=0.12',
20     'matplotlib',
21     'mujoco-py<2.1,>=2.0',
22     'numpy==1.14.5',
23     'psutil',
24     # Pyglet 1.4.0 introduces some api change which breaks some
25     # gym environments
26     # See: https://github.com/openai/gym/issues/1588
27     'pyglet<1.4.0,>=1.3.0',
28     'pyprind',
29     'python-dateutil',
30     'torch==1.1.0',
31     'scikit-image',
32     'scipy',
33     'tensorflow<1.13,>=1.12.0',
34     'tensorflow-probability<0.6.0,>=0.5.0',  # for tensorflow 1.12
35     'torchvision==0.3.0'
36 ]
37 
38 # Dependencies for optional features
39 extras = {}
40 extras['all'] = list(set(sum(extras.values(), [])))
41 
42 # Intel dependencies not included in all
43 extras['intel'] = ['intel-tensorflow<1.13,>=1.12.0']
44 
45 # Development dependencies (*not* included in "all")
46 extras['dev'] = [
47     # Please keep alphabetized
48     'baselines @ https://api.github.com/repos/openai/baselines/tarball/f2729693253c0ef4d4086231d36e0a4307ec1cb3',  # noqa: E501
49     'flake8',
50     'flake8-docstrings==1.3.0',
51     'flake8-import-order',
52     'pandas',
53     'pep8-naming==0.7.0',
54     'pre-commit',
55     # pydocstyle 4.0.0 breaks flake8-docstrings 1.3.0
56     # See https://gitlab.com/pycqa/flake8-docstrings/issues/36
57     'pydocstyle<4.0.0',
58     'pylint==1.9.2',
59     'pytest>=3.6',  # Required for pytest-cov on Python 3.6
60     'pytest-cov',
61     'sphinx',
62     'sphinx_rtd_theme',
63     'yapf',
64 ]
65 
66 with open('README.md') as f:
67     readme = f.read()
68 
69 # Get the package version dynamically
70 with open('VERSION') as v:
71     version = v.read().strip()
72 
73 setup(
74     name='garage',
75     version=version,
76     author='Reinforcement Learning Working Group',
77     description='A framework for reproducible reinforcement learning research',
78     url='https://github.com/rlworkgroup/garage',
79     packages=find_packages(where='src'),
80     package_dir={'': 'src'},
81     scripts=['scripts/garage'],
82     install_requires=required,
83     extras_require=extras,
84     license='MIT',
85     long_description=readme,
86     long_description_content_type='text/markdown',
87     classifiers=[
88         'Development Status :: 4 - Beta',
89         'Intended Audience :: Developers',
90         'Intended Audience :: Education',
91         'Intended Audience :: Science/Research',
92         'License :: OSI Approved :: MIT License',
93         'Programming Language :: Python :: 3.5',
94         'Programming Language :: Python :: 3.6',
95         'Programming Language :: Python :: 3.7',
96         'Programming Language :: Python :: 3 :: Only',
97         'Topic :: Scientific/Engineering :: Artificial Intelligence',
98         'Topic :: Scientific/Engineering :: Mathematics',
99         'Topic :: Software Development :: Libraries',
100     ],
101 )
102
```

Path: `src/garage/np/algos/cem.py`
Content:
```
1 from dowel import logger, tabular
2 import numpy as np
3 
4 from garage.np.algos import BatchPolopt
5 
6 
7 class CEM(BatchPolopt):
8     """Cross Entropy Method.
9 
10     CEM works by iteratively optimizing a gaussian distribution of policy.
11 
12     In each epoch, CEM does the following:
13     1. Sample n_samples policies from a gaussian distribution of
14        mean cur_mean and std cur_std.
15     2. Do rollouts for each policy.
16     3. Update cur_mean and cur_std by doing Maximum Likelihood Estimation
17        over the n_best top policies in terms of return.
18 
19     Note:
20         When training CEM with LocalRunner, make sure that n_epoch_cycles for
21         runner equals to n_samples for CEM.
22 
23         This implementation leverage n_epoch_cycles to do rollouts for a single
24         policy in an epoch cycle.
25 
26     Args:
27         env_spec (garage.envs.EnvSpec): Environment specification.
28         policy (garage.np.policies.Policy): Action policy.
29         baseline(garage.np.baselines.Baseline): Baseline for GAE
30             (Generalized Advantage Estimation).
31         n_samples (int): Number of policies sampled in one epoch.
32         discount (float): Environment reward discount.
33         max_path_length (int): Maximum length of a single rollout.
34         best_frac (float): The best fraction.
35         init_std (float): Initial std for policy param distribution.
36         extra_std (float): Decaying std added to param distribution.
37         extra_decay_time (float): Epochs that it takes to decay extra std.
38 
39     """
40 
41     def __init__(self,
42                  env_spec,
43                  policy,
44                  baseline,
45                  n_samples,
46                  discount=0.99,
47                  max_path_length=500,
48                  init_std=1,
49                  best_frac=0.05,
50                  extra_std=1.,
51                  extra_decay_time=100):
52         super().__init__(policy, baseline, discount, max_path_length,
53                          n_samples)
54         self.env_spec = env_spec
55 
56         self.init_std = init_std
57         self.best_frac = best_frac
58         self.extra_std = extra_std
59         self.extra_decay_time = extra_decay_time
60 
61         # epoch-wise
62         self.cur_std = self.init_std
63         self.cur_mean = self.policy.get_param_values()
64         # epoch-cycle-wise
65         self.cur_params = self.cur_mean
66         self.all_returns = []
67         self.all_params = [self.cur_mean.copy()]
68         # fixed
69         self.n_best = int(n_samples * best_frac)
70         assert self.n_best >= 1, (
71             f'n_samples is too low. Make sure that n_samples * best_frac >= 1')
72         self.n_params = len(self.cur_mean)
73 
74     def sample_params(self, epoch):
75         extra_var_mult = max(1.0 - epoch / self.extra_decay_time, 0)
76         sample_std = np.sqrt(
77             np.square(self.cur_std) +
78             np.square(self.extra_std) * extra_var_mult)
79         return np.random.standard_normal(
80             self.n_params) * sample_std + self.cur_mean
81 
82     def train_once(self, itr, paths):
83         paths = self.process_samples(itr, paths)
84 
85         epoch = itr // self.n_samples
86         i_sample = itr - epoch * self.n_samples
87         tabular.record('Epoch', epoch)
88         tabular.record('# Sample', i_sample)
89         # -- Stage: Process path
90         rtn = paths['average_return']
91         self.all_returns.append(paths['average_return'])
92 
93         # -- Stage: Update policy distribution.
94         if (itr + 1) % self.n_samples == 0:
95             avg_rtns = np.array(self.all_returns)
96             best_inds = np.argsort(-avg_rtns)[:self.n_best]
97             best_params = np.array(self.all_params)[best_inds]
98 
99             # MLE of normal distribution
100             self.cur_mean = best_params.mean(axis=0)
101             self.cur_std = best_params.std(axis=0)
102             self.policy.set_param_values(self.cur_mean)
103 
104             # Clear for next epoch
105             rtn = max(self.all_returns)
106             self.all_returns.clear()
107             self.all_params.clear()
108 
109         # -- Stage: Generate a new policy for next path sampling
110         self.cur_params = self.sample_params(itr)
111         self.all_params.append(self.cur_params.copy())
112         self.policy.set_param_values(self.cur_params)
113 
114         logger.log(tabular)
115         return rtn
116 
117     def get_itr_snapshot(self, itr):
118         return dict(itr=itr, policy=self.policy, baseline=self.baseline)
119
```
--- 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/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,15 @@
 from setuptools import find_packages
 from setuptools import setup
 
+try:
+    # pylint: disable=unused-import
+    import numpy  # noqa: F401
+except ImportError:
+    raise RuntimeError(
+        'garage requires numpy in the environment to install. '
+        'Please install numpy==1.14.5 and try again. See '
+        'https://github.com/rlworkgroup/garage/issues/800 for more info.')
+
 # Required dependencies
 required = [
     # Please keep alphabetized
@@ -58,6 +67,7 @@
     'pylint==1.9.2',
     'pytest>=3.6',  # Required for pytest-cov on Python 3.6
     'pytest-cov',
+    'pytest-xdist',
     'sphinx',
     'sphinx_rtd_theme',
     'yapf',
@@ -79,6 +89,7 @@
     packages=find_packages(where='src'),
     package_dir={'': 'src'},
     scripts=['scripts/garage'],
+    python_requires='>=3.5',
     install_requires=required,
     extras_require=extras,
     license='MIT',
diff --git a/src/garage/np/algos/cem.py b/src/garage/np/algos/cem.py
--- a/src/garage/np/algos/cem.py
+++ b/src/garage/np/algos/cem.py
@@ -68,7 +68,7 @@
         # fixed
         self.n_best = int(n_samples * best_frac)
         assert self.n_best >= 1, (
-            f'n_samples is too low. Make sure that n_samples * best_frac >= 1')
+            'n_samples is too low. Make sure that n_samples * best_frac >= 1')
         self.n_params = len(self.cur_mean)
 
     def sample_params(self, epoch):

{"golden_diff": "diff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -1,6 +1,15 @@\n from setuptools import find_packages\n from setuptools import setup\n \n+try:\n+    # pylint: disable=unused-import\n+    import numpy  # noqa: F401\n+except ImportError:\n+    raise RuntimeError(\n+        'garage requires numpy in the environment to install. '\n+        'Please install numpy==1.14.5 and try again. See '\n+        'https://github.com/rlworkgroup/garage/issues/800 for more info.')\n+\n # Required dependencies\n required = [\n     # Please keep alphabetized\n@@ -58,6 +67,7 @@\n     'pylint==1.9.2',\n     'pytest>=3.6',  # Required for pytest-cov on Python 3.6\n     'pytest-cov',\n+    'pytest-xdist',\n     'sphinx',\n     'sphinx_rtd_theme',\n     'yapf',\n@@ -79,6 +89,7 @@\n     packages=find_packages(where='src'),\n     package_dir={'': 'src'},\n     scripts=['scripts/garage'],\n+    python_requires='>=3.5',\n     install_requires=required,\n     extras_require=extras,\n     license='MIT',\ndiff --git a/src/garage/np/algos/cem.py b/src/garage/np/algos/cem.py\n--- a/src/garage/np/algos/cem.py\n+++ b/src/garage/np/algos/cem.py\n@@ -68,7 +68,7 @@\n         # fixed\n         self.n_best = int(n_samples * best_frac)\n         assert self.n_best >= 1, (\n-            f'n_samples is too low. Make sure that n_samples * best_frac >= 1')\n+            'n_samples is too low. Make sure that n_samples * best_frac >= 1')\n         self.n_params = len(self.cur_mean)\n \n     def sample_params(self, epoch):\n", "issue": "Remove conda environment from CI/Dockerfiles\nNow that we use setup.py for tracking dependencies, there's no need be creating conda environments inside the Dockerfile and CI. We can replace them with a vanilla virtualenv for greatest compatibility.\r\n\r\nI suggest we add tests which ensure that the package can still be successfully solved and installed by conda and pipenv. If they don't take too long (<2min) then we can run them in the main CI, otherwise they will be cron_job tests (which are run only nightly).\n", "before_files": [{"content": "from setuptools import find_packages\nfrom setuptools import setup\n\n# Required dependencies\nrequired = [\n    # Please keep alphabetized\n    'akro==0.0.6',\n    'cached_property',\n    'click',\n    'cloudpickle',\n    'cma==1.1.06',\n    # dm_control throws an error during install about not being able to\n    # find a build dependency (absl-py). Later pip executes the `install`\n    # command again and the install succeeds because absl-py has been\n    # installed. This is stupid, but harmless.\n    'dm_control @ https://api.github.com/repos/deepmind/dm_control/tarball/7a36377879c57777e5d5b4da5aae2cd2a29b607a',  # noqa: E501\n    'dowel==0.0.2',\n    'gym[all]==0.12.4',\n    'joblib<0.13,>=0.12',\n    'matplotlib',\n    'mujoco-py<2.1,>=2.0',\n    'numpy==1.14.5',\n    'psutil',\n    # Pyglet 1.4.0 introduces some api change which breaks some\n    # gym environments\n    # See: https://github.com/openai/gym/issues/1588\n    'pyglet<1.4.0,>=1.3.0',\n    'pyprind',\n    'python-dateutil',\n    'torch==1.1.0',\n    'scikit-image',\n    'scipy',\n    'tensorflow<1.13,>=1.12.0',\n    'tensorflow-probability<0.6.0,>=0.5.0',  # for tensorflow 1.12\n    'torchvision==0.3.0'\n]\n\n# Dependencies for optional features\nextras = {}\nextras['all'] = list(set(sum(extras.values(), [])))\n\n# Intel dependencies not included in all\nextras['intel'] = ['intel-tensorflow<1.13,>=1.12.0']\n\n# Development dependencies (*not* included in \"all\")\nextras['dev'] = [\n    # Please keep alphabetized\n    'baselines @ https://api.github.com/repos/openai/baselines/tarball/f2729693253c0ef4d4086231d36e0a4307ec1cb3',  # noqa: E501\n    'flake8',\n    'flake8-docstrings==1.3.0',\n    'flake8-import-order',\n    'pandas',\n    'pep8-naming==0.7.0',\n    'pre-commit',\n    # pydocstyle 4.0.0 breaks flake8-docstrings 1.3.0\n    # See https://gitlab.com/pycqa/flake8-docstrings/issues/36\n    'pydocstyle<4.0.0',\n    'pylint==1.9.2',\n    'pytest>=3.6',  # Required for pytest-cov on Python 3.6\n    'pytest-cov',\n    'sphinx',\n    'sphinx_rtd_theme',\n    'yapf',\n]\n\nwith open('README.md') as f:\n    readme = f.read()\n\n# Get the package version dynamically\nwith open('VERSION') as v:\n    version = v.read().strip()\n\nsetup(\n    name='garage',\n    version=version,\n    author='Reinforcement Learning Working Group',\n    description='A framework for reproducible reinforcement learning research',\n    url='https://github.com/rlworkgroup/garage',\n    packages=find_packages(where='src'),\n    package_dir={'': 'src'},\n    scripts=['scripts/garage'],\n    install_requires=required,\n    extras_require=extras,\n    license='MIT',\n    long_description=readme,\n    long_description_content_type='text/markdown',\n    classifiers=[\n        'Development Status :: 4 - Beta',\n        'Intended Audience :: Developers',\n        'Intended Audience :: Education',\n        'Intended Audience :: Science/Research',\n        'License :: OSI Approved :: MIT License',\n        'Programming Language :: Python :: 3.5',\n        'Programming Language :: Python :: 3.6',\n        'Programming Language :: Python :: 3.7',\n        'Programming Language :: Python :: 3 :: Only',\n        'Topic :: Scientific/Engineering :: Artificial Intelligence',\n        'Topic :: Scientific/Engineering :: Mathematics',\n        'Topic :: Software Development :: Libraries',\n    ],\n)\n", "path": "setup.py"}, {"content": "from dowel import logger, tabular\nimport numpy as np\n\nfrom garage.np.algos import BatchPolopt\n\n\nclass CEM(BatchPolopt):\n    \"\"\"Cross Entropy Method.\n\n    CEM works by iteratively optimizing a gaussian distribution of policy.\n\n    In each epoch, CEM does the following:\n    1. Sample n_samples policies from a gaussian distribution of\n       mean cur_mean and std cur_std.\n    2. Do rollouts for each policy.\n    3. Update cur_mean and cur_std by doing Maximum Likelihood Estimation\n       over the n_best top policies in terms of return.\n\n    Note:\n        When training CEM with LocalRunner, make sure that n_epoch_cycles for\n        runner equals to n_samples for CEM.\n\n        This implementation leverage n_epoch_cycles to do rollouts for a single\n        policy in an epoch cycle.\n\n    Args:\n        env_spec (garage.envs.EnvSpec): Environment specification.\n        policy (garage.np.policies.Policy): Action policy.\n        baseline(garage.np.baselines.Baseline): Baseline for GAE\n            (Generalized Advantage Estimation).\n        n_samples (int): Number of policies sampled in one epoch.\n        discount (float): Environment reward discount.\n        max_path_length (int): Maximum length of a single rollout.\n        best_frac (float): The best fraction.\n        init_std (float): Initial std for policy param distribution.\n        extra_std (float): Decaying std added to param distribution.\n        extra_decay_time (float): Epochs that it takes to decay extra std.\n\n    \"\"\"\n\n    def __init__(self,\n                 env_spec,\n                 policy,\n                 baseline,\n                 n_samples,\n                 discount=0.99,\n                 max_path_length=500,\n                 init_std=1,\n                 best_frac=0.05,\n                 extra_std=1.,\n                 extra_decay_time=100):\n        super().__init__(policy, baseline, discount, max_path_length,\n                         n_samples)\n        self.env_spec = env_spec\n\n        self.init_std = init_std\n        self.best_frac = best_frac\n        self.extra_std = extra_std\n        self.extra_decay_time = extra_decay_time\n\n        # epoch-wise\n        self.cur_std = self.init_std\n        self.cur_mean = self.policy.get_param_values()\n        # epoch-cycle-wise\n        self.cur_params = self.cur_mean\n        self.all_returns = []\n        self.all_params = [self.cur_mean.copy()]\n        # fixed\n        self.n_best = int(n_samples * best_frac)\n        assert self.n_best >= 1, (\n            f'n_samples is too low. Make sure that n_samples * best_frac >= 1')\n        self.n_params = len(self.cur_mean)\n\n    def sample_params(self, epoch):\n        extra_var_mult = max(1.0 - epoch / self.extra_decay_time, 0)\n        sample_std = np.sqrt(\n            np.square(self.cur_std) +\n            np.square(self.extra_std) * extra_var_mult)\n        return np.random.standard_normal(\n            self.n_params) * sample_std + self.cur_mean\n\n    def train_once(self, itr, paths):\n        paths = self.process_samples(itr, paths)\n\n        epoch = itr // self.n_samples\n        i_sample = itr - epoch * self.n_samples\n        tabular.record('Epoch', epoch)\n        tabular.record('# Sample', i_sample)\n        # -- Stage: Process path\n        rtn = paths['average_return']\n        self.all_returns.append(paths['average_return'])\n\n        # -- Stage: Update policy distribution.\n        if (itr + 1) % self.n_samples == 0:\n            avg_rtns = np.array(self.all_returns)\n            best_inds = np.argsort(-avg_rtns)[:self.n_best]\n            best_params = np.array(self.all_params)[best_inds]\n\n            # MLE of normal distribution\n            self.cur_mean = best_params.mean(axis=0)\n            self.cur_std = best_params.std(axis=0)\n            self.policy.set_param_values(self.cur_mean)\n\n            # Clear for next epoch\n            rtn = max(self.all_returns)\n            self.all_returns.clear()\n            self.all_params.clear()\n\n        # -- Stage: Generate a new policy for next path sampling\n        self.cur_params = self.sample_params(itr)\n        self.all_params.append(self.cur_params.copy())\n        self.policy.set_param_values(self.cur_params)\n\n        logger.log(tabular)\n        return rtn\n\n    def get_itr_snapshot(self, itr):\n        return dict(itr=itr, policy=self.policy, baseline=self.baseline)\n", "path": "src/garage/np/algos/cem.py"}], "after_files": [{"content": "from setuptools import find_packages\nfrom setuptools import setup\n\ntry:\n    # pylint: disable=unused-import\n    import numpy  # noqa: F401\nexcept ImportError:\n    raise RuntimeError(\n        'garage requires numpy in the environment to install. '\n        'Please install numpy==1.14.5 and try again. See '\n        'https://github.com/rlworkgroup/garage/issues/800 for more info.')\n\n# Required dependencies\nrequired = [\n    # Please keep alphabetized\n    'akro==0.0.6',\n    'cached_property',\n    'click',\n    'cloudpickle',\n    'cma==1.1.06',\n    # dm_control throws an error during install about not being able to\n    # find a build dependency (absl-py). Later pip executes the `install`\n    # command again and the install succeeds because absl-py has been\n    # installed. This is stupid, but harmless.\n    'dm_control @ https://api.github.com/repos/deepmind/dm_control/tarball/7a36377879c57777e5d5b4da5aae2cd2a29b607a',  # noqa: E501\n    'dowel==0.0.2',\n    'gym[all]==0.12.4',\n    'joblib<0.13,>=0.12',\n    'matplotlib',\n    'mujoco-py<2.1,>=2.0',\n    'numpy==1.14.5',\n    'psutil',\n    # Pyglet 1.4.0 introduces some api change which breaks some\n    # gym environments\n    # See: https://github.com/openai/gym/issues/1588\n    'pyglet<1.4.0,>=1.3.0',\n    'pyprind',\n    'python-dateutil',\n    'torch==1.1.0',\n    'scikit-image',\n    'scipy',\n    'tensorflow<1.13,>=1.12.0',\n    'tensorflow-probability<0.6.0,>=0.5.0',  # for tensorflow 1.12\n    'torchvision==0.3.0'\n]\n\n# Dependencies for optional features\nextras = {}\nextras['all'] = list(set(sum(extras.values(), [])))\n\n# Intel dependencies not included in all\nextras['intel'] = ['intel-tensorflow<1.13,>=1.12.0']\n\n# Development dependencies (*not* included in \"all\")\nextras['dev'] = [\n    # Please keep alphabetized\n    'baselines @ https://api.github.com/repos/openai/baselines/tarball/f2729693253c0ef4d4086231d36e0a4307ec1cb3',  # noqa: E501\n    'flake8',\n    'flake8-docstrings==1.3.0',\n    'flake8-import-order',\n    'pandas',\n    'pep8-naming==0.7.0',\n    'pre-commit',\n    # pydocstyle 4.0.0 breaks flake8-docstrings 1.3.0\n    # See https://gitlab.com/pycqa/flake8-docstrings/issues/36\n    'pydocstyle<4.0.0',\n    'pylint==1.9.2',\n    'pytest>=3.6',  # Required for pytest-cov on Python 3.6\n    'pytest-cov',\n    'pytest-xdist',\n    'sphinx',\n    'sphinx_rtd_theme',\n    'yapf',\n]\n\nwith open('README.md') as f:\n    readme = f.read()\n\n# Get the package version dynamically\nwith open('VERSION') as v:\n    version = v.read().strip()\n\nsetup(\n    name='garage',\n    version=version,\n    author='Reinforcement Learning Working Group',\n    description='A framework for reproducible reinforcement learning research',\n    url='https://github.com/rlworkgroup/garage',\n    packages=find_packages(where='src'),\n    package_dir={'': 'src'},\n    scripts=['scripts/garage'],\n    python_requires='>=3.5',\n    install_requires=required,\n    extras_require=extras,\n    license='MIT',\n    long_description=readme,\n    long_description_content_type='text/markdown',\n    classifiers=[\n        'Development Status :: 4 - Beta',\n        'Intended Audience :: Developers',\n        'Intended Audience :: Education',\n        'Intended Audience :: Science/Research',\n        'License :: OSI Approved :: MIT License',\n        'Programming Language :: Python :: 3.5',\n        'Programming Language :: Python :: 3.6',\n        'Programming Language :: Python :: 3.7',\n        'Programming Language :: Python :: 3 :: Only',\n        'Topic :: Scientific/Engineering :: Artificial Intelligence',\n        'Topic :: Scientific/Engineering :: Mathematics',\n        'Topic :: Software Development :: Libraries',\n    ],\n)\n", "path": "setup.py"}, {"content": "from dowel import logger, tabular\nimport numpy as np\n\nfrom garage.np.algos import BatchPolopt\n\n\nclass CEM(BatchPolopt):\n    \"\"\"Cross Entropy Method.\n\n    CEM works by iteratively optimizing a gaussian distribution of policy.\n\n    In each epoch, CEM does the following:\n    1. Sample n_samples policies from a gaussian distribution of\n       mean cur_mean and std cur_std.\n    2. Do rollouts for each policy.\n    3. Update cur_mean and cur_std by doing Maximum Likelihood Estimation\n       over the n_best top policies in terms of return.\n\n    Note:\n        When training CEM with LocalRunner, make sure that n_epoch_cycles for\n        runner equals to n_samples for CEM.\n\n        This implementation leverage n_epoch_cycles to do rollouts for a single\n        policy in an epoch cycle.\n\n    Args:\n        env_spec (garage.envs.EnvSpec): Environment specification.\n        policy (garage.np.policies.Policy): Action policy.\n        baseline(garage.np.baselines.Baseline): Baseline for GAE\n            (Generalized Advantage Estimation).\n        n_samples (int): Number of policies sampled in one epoch.\n        discount (float): Environment reward discount.\n        max_path_length (int): Maximum length of a single rollout.\n        best_frac (float): The best fraction.\n        init_std (float): Initial std for policy param distribution.\n        extra_std (float): Decaying std added to param distribution.\n        extra_decay_time (float): Epochs that it takes to decay extra std.\n\n    \"\"\"\n\n    def __init__(self,\n                 env_spec,\n                 policy,\n                 baseline,\n                 n_samples,\n                 discount=0.99,\n                 max_path_length=500,\n                 init_std=1,\n                 best_frac=0.05,\n                 extra_std=1.,\n                 extra_decay_time=100):\n        super().__init__(policy, baseline, discount, max_path_length,\n                         n_samples)\n        self.env_spec = env_spec\n\n        self.init_std = init_std\n        self.best_frac = best_frac\n        self.extra_std = extra_std\n        self.extra_decay_time = extra_decay_time\n\n        # epoch-wise\n        self.cur_std = self.init_std\n        self.cur_mean = self.policy.get_param_values()\n        # epoch-cycle-wise\n        self.cur_params = self.cur_mean\n        self.all_returns = []\n        self.all_params = [self.cur_mean.copy()]\n        # fixed\n        self.n_best = int(n_samples * best_frac)\n        assert self.n_best >= 1, (\n            'n_samples is too low. Make sure that n_samples * best_frac >= 1')\n        self.n_params = len(self.cur_mean)\n\n    def sample_params(self, epoch):\n        extra_var_mult = max(1.0 - epoch / self.extra_decay_time, 0)\n        sample_std = np.sqrt(\n            np.square(self.cur_std) +\n            np.square(self.extra_std) * extra_var_mult)\n        return np.random.standard_normal(\n            self.n_params) * sample_std + self.cur_mean\n\n    def train_once(self, itr, paths):\n        paths = self.process_samples(itr, paths)\n\n        epoch = itr // self.n_samples\n        i_sample = itr - epoch * self.n_samples\n        tabular.record('Epoch', epoch)\n        tabular.record('# Sample', i_sample)\n        # -- Stage: Process path\n        rtn = paths['average_return']\n        self.all_returns.append(paths['average_return'])\n\n        # -- Stage: Update policy distribution.\n        if (itr + 1) % self.n_samples == 0:\n            avg_rtns = np.array(self.all_returns)\n            best_inds = np.argsort(-avg_rtns)[:self.n_best]\n            best_params = np.array(self.all_params)[best_inds]\n\n            # MLE of normal distribution\n            self.cur_mean = best_params.mean(axis=0)\n            self.cur_std = best_params.std(axis=0)\n            self.policy.set_param_values(self.cur_mean)\n\n            # Clear for next epoch\n            rtn = max(self.all_returns)\n            self.all_returns.clear()\n            self.all_params.clear()\n\n        # -- Stage: Generate a new policy for next path sampling\n        self.cur_params = self.sample_params(itr)\n        self.all_params.append(self.cur_params.copy())\n        self.policy.set_param_values(self.cur_params)\n\n        logger.log(tabular)\n        return rtn\n\n    def get_itr_snapshot(self, itr):\n        return dict(itr=itr, policy=self.policy, baseline=self.baseline)\n", "path": "src/garage/np/algos/cem.py"}]}