prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Backport #1791 to release-2020.06
  
  
  </issue>
  <code>
  [start of src/garage/tf/policies/discrete_qf_derived_policy.py]
  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 of src/garage/tf/policies/discrete_qf_derived_policy.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/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__.
  
verification_info: {"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"}]}