prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  [callbacks] call on_*_end events in reverse order
  
  
  </issue>
  <code>
  [start of hydra/core/callbacks.py]
  1 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
  2 import warnings
  3 from typing import Any
  4 
  5 from omegaconf import DictConfig
  6 
  7 from hydra.core.utils import JobReturn
  8 from hydra.utils import instantiate
  9 
  10 
  11 class Callbacks:
  12     def __init__(self, config: DictConfig) -> None:
  13         self.callbacks = []
  14         for params in config.hydra.callbacks.values():
  15             self.callbacks.append(instantiate(params))
  16 
  17     def _notify(self, function_name: str, **kwargs: Any) -> None:
  18         for c in self.callbacks:
  19             try:
  20                 getattr(c, function_name)(**kwargs)
  21             except Exception as e:
  22                 warnings.warn(
  23                     f"Callback {type(c).__name__}.{function_name} raised {type(e).__name__}: {e}"
  24                 )
  25 
  26     def on_run_start(self, config: DictConfig, **kwargs: Any) -> None:
  27         self._notify(function_name="on_run_start", config=config, **kwargs)
  28 
  29     def on_run_end(self, config: DictConfig, **kwargs: Any) -> None:
  30         self._notify(function_name="on_run_end", config=config, **kwargs)
  31 
  32     def on_multirun_start(self, config: DictConfig, **kwargs: Any) -> None:
  33         self._notify(function_name="on_multirun_start", config=config, **kwargs)
  34 
  35     def on_multirun_end(self, config: DictConfig, **kwargs: Any) -> None:
  36         self._notify(function_name="on_multirun_end", config=config, **kwargs)
  37 
  38     def on_job_start(self, config: DictConfig, **kwargs: Any) -> None:
  39         self._notify(function_name="on_job_start", config=config, **kwargs)
  40 
  41     def on_job_end(
  42         self, config: DictConfig, job_return: JobReturn, **kwargs: Any
  43     ) -> None:
  44         self._notify(
  45             function_name="on_job_end", config=config, job_return=job_return, **kwargs
  46         )
  47
  [end of hydra/core/callbacks.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/hydra/core/callbacks.py b/hydra/core/callbacks.py
  --- a/hydra/core/callbacks.py
  +++ b/hydra/core/callbacks.py
  @@ -14,8 +14,9 @@
           for params in config.hydra.callbacks.values():
               self.callbacks.append(instantiate(params))
   
  -    def _notify(self, function_name: str, **kwargs: Any) -> None:
  -        for c in self.callbacks:
  +    def _notify(self, function_name: str, reverse: bool = False, **kwargs: Any) -> None:
  +        callbacks = reversed(self.callbacks) if reverse else self.callbacks
  +        for c in callbacks:
               try:
                   getattr(c, function_name)(**kwargs)
               except Exception as e:
  @@ -27,13 +28,15 @@
           self._notify(function_name="on_run_start", config=config, **kwargs)
   
       def on_run_end(self, config: DictConfig, **kwargs: Any) -> None:
  -        self._notify(function_name="on_run_end", config=config, **kwargs)
  +        self._notify(function_name="on_run_end", config=config, reverse=True, **kwargs)
   
       def on_multirun_start(self, config: DictConfig, **kwargs: Any) -> None:
           self._notify(function_name="on_multirun_start", config=config, **kwargs)
   
       def on_multirun_end(self, config: DictConfig, **kwargs: Any) -> None:
  -        self._notify(function_name="on_multirun_end", config=config, **kwargs)
  +        self._notify(
  +            function_name="on_multirun_end", reverse=True, config=config, **kwargs
  +        )
   
       def on_job_start(self, config: DictConfig, **kwargs: Any) -> None:
           self._notify(function_name="on_job_start", config=config, **kwargs)
  @@ -42,5 +45,9 @@
           self, config: DictConfig, job_return: JobReturn, **kwargs: Any
       ) -> None:
           self._notify(
  -            function_name="on_job_end", config=config, job_return=job_return, **kwargs
  +            function_name="on_job_end",
  +            config=config,
  +            job_return=job_return,
  +            reverse=True,
  +            **kwargs,
           )
  
verification_info: {"golden_diff": "diff --git a/hydra/core/callbacks.py b/hydra/core/callbacks.py\n--- a/hydra/core/callbacks.py\n+++ b/hydra/core/callbacks.py\n@@ -14,8 +14,9 @@\n         for params in config.hydra.callbacks.values():\n             self.callbacks.append(instantiate(params))\n \n-    def _notify(self, function_name: str, **kwargs: Any) -> None:\n-        for c in self.callbacks:\n+    def _notify(self, function_name: str, reverse: bool = False, **kwargs: Any) -> None:\n+        callbacks = reversed(self.callbacks) if reverse else self.callbacks\n+        for c in callbacks:\n             try:\n                 getattr(c, function_name)(**kwargs)\n             except Exception as e:\n@@ -27,13 +28,15 @@\n         self._notify(function_name=\"on_run_start\", config=config, **kwargs)\n \n     def on_run_end(self, config: DictConfig, **kwargs: Any) -> None:\n-        self._notify(function_name=\"on_run_end\", config=config, **kwargs)\n+        self._notify(function_name=\"on_run_end\", config=config, reverse=True, **kwargs)\n \n     def on_multirun_start(self, config: DictConfig, **kwargs: Any) -> None:\n         self._notify(function_name=\"on_multirun_start\", config=config, **kwargs)\n \n     def on_multirun_end(self, config: DictConfig, **kwargs: Any) -> None:\n-        self._notify(function_name=\"on_multirun_end\", config=config, **kwargs)\n+        self._notify(\n+            function_name=\"on_multirun_end\", reverse=True, config=config, **kwargs\n+        )\n \n     def on_job_start(self, config: DictConfig, **kwargs: Any) -> None:\n         self._notify(function_name=\"on_job_start\", config=config, **kwargs)\n@@ -42,5 +45,9 @@\n         self, config: DictConfig, job_return: JobReturn, **kwargs: Any\n     ) -> None:\n         self._notify(\n-            function_name=\"on_job_end\", config=config, job_return=job_return, **kwargs\n+            function_name=\"on_job_end\",\n+            config=config,\n+            job_return=job_return,\n+            reverse=True,\n+            **kwargs,\n         )\n", "issue": "[callbacks] call on_*_end events in reverse order\n\n", "before_files": [{"content": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\nimport warnings\nfrom typing import Any\n\nfrom omegaconf import DictConfig\n\nfrom hydra.core.utils import JobReturn\nfrom hydra.utils import instantiate\n\n\nclass Callbacks:\n    def __init__(self, config: DictConfig) -> None:\n        self.callbacks = []\n        for params in config.hydra.callbacks.values():\n            self.callbacks.append(instantiate(params))\n\n    def _notify(self, function_name: str, **kwargs: Any) -> None:\n        for c in self.callbacks:\n            try:\n                getattr(c, function_name)(**kwargs)\n            except Exception as e:\n                warnings.warn(\n                    f\"Callback {type(c).__name__}.{function_name} raised {type(e).__name__}: {e}\"\n                )\n\n    def on_run_start(self, config: DictConfig, **kwargs: Any) -> None:\n        self._notify(function_name=\"on_run_start\", config=config, **kwargs)\n\n    def on_run_end(self, config: DictConfig, **kwargs: Any) -> None:\n        self._notify(function_name=\"on_run_end\", config=config, **kwargs)\n\n    def on_multirun_start(self, config: DictConfig, **kwargs: Any) -> None:\n        self._notify(function_name=\"on_multirun_start\", config=config, **kwargs)\n\n    def on_multirun_end(self, config: DictConfig, **kwargs: Any) -> None:\n        self._notify(function_name=\"on_multirun_end\", config=config, **kwargs)\n\n    def on_job_start(self, config: DictConfig, **kwargs: Any) -> None:\n        self._notify(function_name=\"on_job_start\", config=config, **kwargs)\n\n    def on_job_end(\n        self, config: DictConfig, job_return: JobReturn, **kwargs: Any\n    ) -> None:\n        self._notify(\n            function_name=\"on_job_end\", config=config, job_return=job_return, **kwargs\n        )\n", "path": "hydra/core/callbacks.py"}]}