We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Backport #1791 to release-2020.06


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/garage/tf/policies/discrete_qf_derived_policy.py`
Content:
```
1 """A Discrete QFunction-derived policy.
2 
3 This policy chooses the action that yields to the largest Q-value.
4 """
5 import akro
6 import numpy as np
7 import tensorflow as tf
8 
9 from garage.tf.policies.policy import Policy
10 
11 
12 class DiscreteQfDerivedPolicy(Policy):
13     """DiscreteQfDerived policy.
14 
15     Args:
16         env_spec (garage.envs.env_spec.EnvSpec): Environment specification.
17         qf (garage.q_functions.QFunction): The q-function used.
18         name (str): Name of the policy.
19 
20     """
21 
22     def __init__(self, env_spec, qf, name='DiscreteQfDerivedPolicy'):
23         super().__init__(name, env_spec)
24 
25         assert isinstance(env_spec.action_space, akro.Discrete)
26         self._env_spec = env_spec
27         self._qf = qf
28 
29         self._initialize()
30 
31     def _initialize(self):
32         self._f_qval = tf.compat.v1.get_default_session().make_callable(
33             self._qf.q_vals, feed_list=[self._qf.model.input])
34 
35     @property
36     def vectorized(self):
37         """Vectorized or not.
38 
39         Returns:
40             Bool: True if primitive supports vectorized operations.
41 
42         """
43         return True
44 
45     def get_action(self, observation):
46         """Get action from this policy for the input observation.
47 
48         Args:
49             observation (numpy.ndarray): Observation from environment.
50 
51         Returns:
52             numpy.ndarray: Single optimal action from this policy.
53             dict: Predicted action and agent information. It returns an empty
54                 dict since there is no parameterization.
55 
56         """
57         if isinstance(self.env_spec.observation_space, akro.Image) and \
58                 len(observation.shape) < \
59                 len(self.env_spec.observation_space.shape):
60             observation = self.env_spec.observation_space.unflatten(
61                 observation)
62         q_vals = self._f_qval([observation])
63         opt_action = np.argmax(q_vals)
64 
65         return opt_action, dict()
66 
67     def get_actions(self, observations):
68         """Get actions from this policy for the input observations.
69 
70         Args:
71             observations (numpy.ndarray): Observations from environment.
72 
73         Returns:
74             numpy.ndarray: Optimal actions from this policy.
75             dict: Predicted action and agent information. It returns an empty
76                 dict since there is no parameterization.
77 
78         """
79         if isinstance(self.env_spec.observation_space, akro.Image) and \
80                 len(observations[0].shape) < \
81                 len(self.env_spec.observation_space.shape):
82             observations = self.env_spec.observation_space.unflatten_n(
83                 observations)
84         q_vals = self._f_qval(observations)
85         opt_actions = np.argmax(q_vals, axis=1)
86 
87         return opt_actions, dict()
88 
89     def __getstate__(self):
90         """Object.__getstate__.
91 
92         Returns:
93             dict: the state to be pickled for the instance.
94 
95         """
96         new_dict = self.__dict__.copy()
97         del new_dict['_f_qval']
98         return new_dict
99 
100     def __setstate__(self, state):
101         """Object.__setstate__.
102 
103         Args:
104             state (dict): Unpickled state.
105 
106         """
107         self.__dict__.update(state)
108         self._initialize()
109
```
--- 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/src/garage/tf/policies/discrete_qf_derived_policy.py b/src/garage/tf/policies/discrete_qf_derived_policy.py
--- a/src/garage/tf/policies/discrete_qf_derived_policy.py
+++ b/src/garage/tf/policies/discrete_qf_derived_policy.py
@@ -86,6 +86,74 @@
 
         return opt_actions, dict()
 
+    def get_trainable_vars(self):
+        """Get trainable variables.
+
+        Returns:
+            List[tf.Variable]: A list of trainable variables in the current
+                variable scope.
+
+        """
+        return self._qf.get_trainable_vars()
+
+    def get_global_vars(self):
+        """Get global variables.
+
+        Returns:
+            List[tf.Variable]: A list of global variables in the current
+                variable scope.
+
+        """
+        return self._qf.get_global_vars()
+
+    def get_regularizable_vars(self):
+        """Get all network weight variables in the current scope.
+
+        Returns:
+            List[tf.Variable]: A list of network weight variables in the
+                current variable scope.
+
+        """
+        return self._qf.get_regularizable_vars()
+
+    def get_params(self):
+        """Get the trainable variables.
+
+        Returns:
+            List[tf.Variable]: A list of trainable variables in the current
+                variable scope.
+
+        """
+        return self._qf.get_params()
+
+    def get_param_shapes(self):
+        """Get parameter shapes.
+
+        Returns:
+            List[tuple]: A list of variable shapes.
+
+        """
+        return self._qf.get_param_shapes()
+
+    def get_param_values(self):
+        """Get param values.
+
+        Returns:
+            np.ndarray: Values of the parameters evaluated in
+                the current session
+
+        """
+        return self._qf.get_param_values()
+
+    def set_param_values(self, param_values):
+        """Set param values.
+
+        Args:
+            param_values (np.ndarray): A numpy array of parameter values.
+
+        """
+        self._qf.set_param_values(param_values)
+
     def __getstate__(self):
         """Object.__getstate__.

{"golden_diff": "diff --git a/src/garage/tf/policies/discrete_qf_derived_policy.py b/src/garage/tf/policies/discrete_qf_derived_policy.py\n--- a/src/garage/tf/policies/discrete_qf_derived_policy.py\n+++ b/src/garage/tf/policies/discrete_qf_derived_policy.py\n@@ -86,6 +86,74 @@\n \n         return opt_actions, dict()\n \n+    def get_trainable_vars(self):\n+        \"\"\"Get trainable variables.\n+\n+        Returns:\n+            List[tf.Variable]: A list of trainable variables in the current\n+                variable scope.\n+\n+        \"\"\"\n+        return self._qf.get_trainable_vars()\n+\n+    def get_global_vars(self):\n+        \"\"\"Get global variables.\n+\n+        Returns:\n+            List[tf.Variable]: A list of global variables in the current\n+                variable scope.\n+\n+        \"\"\"\n+        return self._qf.get_global_vars()\n+\n+    def get_regularizable_vars(self):\n+        \"\"\"Get all network weight variables in the current scope.\n+\n+        Returns:\n+            List[tf.Variable]: A list of network weight variables in the\n+                current variable scope.\n+\n+        \"\"\"\n+        return self._qf.get_regularizable_vars()\n+\n+    def get_params(self):\n+        \"\"\"Get the trainable variables.\n+\n+        Returns:\n+            List[tf.Variable]: A list of trainable variables in the current\n+                variable scope.\n+\n+        \"\"\"\n+        return self._qf.get_params()\n+\n+    def get_param_shapes(self):\n+        \"\"\"Get parameter shapes.\n+\n+        Returns:\n+            List[tuple]: A list of variable shapes.\n+\n+        \"\"\"\n+        return self._qf.get_param_shapes()\n+\n+    def get_param_values(self):\n+        \"\"\"Get param values.\n+\n+        Returns:\n+            np.ndarray: Values of the parameters evaluated in\n+                the current session\n+\n+        \"\"\"\n+        return self._qf.get_param_values()\n+\n+    def set_param_values(self, param_values):\n+        \"\"\"Set param values.\n+\n+        Args:\n+            param_values (np.ndarray): A numpy array of parameter values.\n+\n+        \"\"\"\n+        self._qf.set_param_values(param_values)\n+\n     def __getstate__(self):\n         \"\"\"Object.__getstate__.\n", "issue": "Backport #1791 to release-2020.06\n\n", "before_files": [{"content": "\"\"\"A Discrete QFunction-derived policy.\n\nThis policy chooses the action that yields to the largest Q-value.\n\"\"\"\nimport akro\nimport numpy as np\nimport tensorflow as tf\n\nfrom garage.tf.policies.policy import Policy\n\n\nclass DiscreteQfDerivedPolicy(Policy):\n    \"\"\"DiscreteQfDerived policy.\n\n    Args:\n        env_spec (garage.envs.env_spec.EnvSpec): Environment specification.\n        qf (garage.q_functions.QFunction): The q-function used.\n        name (str): Name of the policy.\n\n    \"\"\"\n\n    def __init__(self, env_spec, qf, name='DiscreteQfDerivedPolicy'):\n        super().__init__(name, env_spec)\n\n        assert isinstance(env_spec.action_space, akro.Discrete)\n        self._env_spec = env_spec\n        self._qf = qf\n\n        self._initialize()\n\n    def _initialize(self):\n        self._f_qval = tf.compat.v1.get_default_session().make_callable(\n            self._qf.q_vals, feed_list=[self._qf.model.input])\n\n    @property\n    def vectorized(self):\n        \"\"\"Vectorized or not.\n\n        Returns:\n            Bool: True if primitive supports vectorized operations.\n\n        \"\"\"\n        return True\n\n    def get_action(self, observation):\n        \"\"\"Get action from this policy for the input observation.\n\n        Args:\n            observation (numpy.ndarray): Observation from environment.\n\n        Returns:\n            numpy.ndarray: Single optimal action from this policy.\n            dict: Predicted action and agent information. It returns an empty\n                dict since there is no parameterization.\n\n        \"\"\"\n        if isinstance(self.env_spec.observation_space, akro.Image) and \\\n                len(observation.shape) < \\\n                len(self.env_spec.observation_space.shape):\n            observation = self.env_spec.observation_space.unflatten(\n                observation)\n        q_vals = self._f_qval([observation])\n        opt_action = np.argmax(q_vals)\n\n        return opt_action, dict()\n\n    def get_actions(self, observations):\n        \"\"\"Get actions from this policy for the input observations.\n\n        Args:\n            observations (numpy.ndarray): Observations from environment.\n\n        Returns:\n            numpy.ndarray: Optimal actions from this policy.\n            dict: Predicted action and agent information. It returns an empty\n                dict since there is no parameterization.\n\n        \"\"\"\n        if isinstance(self.env_spec.observation_space, akro.Image) and \\\n                len(observations[0].shape) < \\\n                len(self.env_spec.observation_space.shape):\n            observations = self.env_spec.observation_space.unflatten_n(\n                observations)\n        q_vals = self._f_qval(observations)\n        opt_actions = np.argmax(q_vals, axis=1)\n\n        return opt_actions, dict()\n\n    def __getstate__(self):\n        \"\"\"Object.__getstate__.\n\n        Returns:\n            dict: the state to be pickled for the instance.\n\n        \"\"\"\n        new_dict = self.__dict__.copy()\n        del new_dict['_f_qval']\n        return new_dict\n\n    def __setstate__(self, state):\n        \"\"\"Object.__setstate__.\n\n        Args:\n            state (dict): Unpickled state.\n\n        \"\"\"\n        self.__dict__.update(state)\n        self._initialize()\n", "path": "src/garage/tf/policies/discrete_qf_derived_policy.py"}], "after_files": [{"content": "\"\"\"A Discrete QFunction-derived policy.\n\nThis policy chooses the action that yields to the largest Q-value.\n\"\"\"\nimport akro\nimport numpy as np\nimport tensorflow as tf\n\nfrom garage.tf.policies.policy import Policy\n\n\nclass DiscreteQfDerivedPolicy(Policy):\n    \"\"\"DiscreteQfDerived policy.\n\n    Args:\n        env_spec (garage.envs.env_spec.EnvSpec): Environment specification.\n        qf (garage.q_functions.QFunction): The q-function used.\n        name (str): Name of the policy.\n\n    \"\"\"\n\n    def __init__(self, env_spec, qf, name='DiscreteQfDerivedPolicy'):\n        super().__init__(name, env_spec)\n\n        assert isinstance(env_spec.action_space, akro.Discrete)\n        self._env_spec = env_spec\n        self._qf = qf\n\n        self._initialize()\n\n    def _initialize(self):\n        self._f_qval = tf.compat.v1.get_default_session().make_callable(\n            self._qf.q_vals, feed_list=[self._qf.model.input])\n\n    @property\n    def vectorized(self):\n        \"\"\"Vectorized or not.\n\n        Returns:\n            Bool: True if primitive supports vectorized operations.\n\n        \"\"\"\n        return True\n\n    def get_action(self, observation):\n        \"\"\"Get action from this policy for the input observation.\n\n        Args:\n            observation (numpy.ndarray): Observation from environment.\n\n        Returns:\n            numpy.ndarray: Single optimal action from this policy.\n            dict: Predicted action and agent information. It returns an empty\n                dict since there is no parameterization.\n\n        \"\"\"\n        if isinstance(self.env_spec.observation_space, akro.Image) and \\\n                len(observation.shape) < \\\n                len(self.env_spec.observation_space.shape):\n            observation = self.env_spec.observation_space.unflatten(\n                observation)\n        q_vals = self._f_qval([observation])\n        opt_action = np.argmax(q_vals)\n\n        return opt_action, dict()\n\n    def get_actions(self, observations):\n        \"\"\"Get actions from this policy for the input observations.\n\n        Args:\n            observations (numpy.ndarray): Observations from environment.\n\n        Returns:\n            numpy.ndarray: Optimal actions from this policy.\n            dict: Predicted action and agent information. It returns an empty\n                dict since there is no parameterization.\n\n        \"\"\"\n        if isinstance(self.env_spec.observation_space, akro.Image) and \\\n                len(observations[0].shape) < \\\n                len(self.env_spec.observation_space.shape):\n            observations = self.env_spec.observation_space.unflatten_n(\n                observations)\n        q_vals = self._f_qval(observations)\n        opt_actions = np.argmax(q_vals, axis=1)\n\n        return opt_actions, dict()\n\n    def get_trainable_vars(self):\n        \"\"\"Get trainable variables.\n\n        Returns:\n            List[tf.Variable]: A list of trainable variables in the current\n                variable scope.\n\n        \"\"\"\n        return self._qf.get_trainable_vars()\n\n    def get_global_vars(self):\n        \"\"\"Get global variables.\n\n        Returns:\n            List[tf.Variable]: A list of global variables in the current\n                variable scope.\n\n        \"\"\"\n        return self._qf.get_global_vars()\n\n    def get_regularizable_vars(self):\n        \"\"\"Get all network weight variables in the current scope.\n\n        Returns:\n            List[tf.Variable]: A list of network weight variables in the\n                current variable scope.\n\n        \"\"\"\n        return self._qf.get_regularizable_vars()\n\n    def get_params(self):\n        \"\"\"Get the trainable variables.\n\n        Returns:\n            List[tf.Variable]: A list of trainable variables in the current\n                variable scope.\n\n        \"\"\"\n        return self._qf.get_params()\n\n    def get_param_shapes(self):\n        \"\"\"Get parameter shapes.\n\n        Returns:\n            List[tuple]: A list of variable shapes.\n\n        \"\"\"\n        return self._qf.get_param_shapes()\n\n    def get_param_values(self):\n        \"\"\"Get param values.\n\n        Returns:\n            np.ndarray: Values of the parameters evaluated in\n                the current session\n\n        \"\"\"\n        return self._qf.get_param_values()\n\n    def set_param_values(self, param_values):\n        \"\"\"Set param values.\n\n        Args:\n            param_values (np.ndarray): A numpy array of parameter values.\n\n        \"\"\"\n        self._qf.set_param_values(param_values)\n\n    def __getstate__(self):\n        \"\"\"Object.__getstate__.\n\n        Returns:\n            dict: the state to be pickled for the instance.\n\n        \"\"\"\n        new_dict = self.__dict__.copy()\n        del new_dict['_f_qval']\n        return new_dict\n\n    def __setstate__(self, state):\n        \"\"\"Object.__setstate__.\n\n        Args:\n            state (dict): Unpickled state.\n\n        \"\"\"\n        self.__dict__.update(state)\n        self._initialize()\n", "path": "src/garage/tf/policies/discrete_qf_derived_policy.py"}]}