prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Remove trigger option of snapshot and snapshot_object
  They have the same functionality as the trigger argument of Trainer.extend and are redundant. I think they confuse users and they might misunderstand the trigger feature, and so they should be removed in the next major update.
  
  </issue>
  <code>
  [start of chainer/training/extensions/_snapshot.py]
  1 import os
  2 import shutil
  3 import tempfile
  4 
  5 from chainer.serializers import npz
  6 from chainer.training import extension
  7 
  8 
  9 def snapshot_object(target, filename, savefun=npz.save_npz,
  10                     trigger=(1, 'epoch')):
  11     """Returns a trainer extension to take snapshots of a given object.
  12 
  13     This extension serializes the given object and saves it to the output
  14     directory.
  15 
  16     This extension is called once for each epoch by default. The default
  17     priority is -100, which is lower than that of most built-in extensions.
  18 
  19     Args:
  20         target: Object to serialize.
  21         filename (str): Name of the file into which the object is serialized.
  22             It can be a format string, where the trainer object is passed to
  23             the :meth:`str.format` method. For example,
  24             ``'snapshot_{.updater.iteration}'`` is converted to
  25             ``'snapshot_10000'`` at the 10,000th iteration.
  26         savefun: Function to save the object. It takes two arguments: the
  27             output file path and the object to serialize.
  28         trigger: Trigger that decides when to take snapshot. It can be either
  29             an already built trigger object (i.e., a callable object that
  30             accepts a trainer object and returns a bool value), or a tuple in
  31             the form ``<int>, 'epoch'`` or ``<int>, 'iteration'``. In latter
  32             case, the tuple is passed to IntervalTrigger.
  33 
  34     Returns:
  35         An extension function.
  36 
  37     """
  38     @extension.make_extension(trigger=trigger, priority=-100)
  39     def snapshot_object(trainer):
  40         _snapshot_object(trainer, target, filename.format(trainer), savefun)
  41 
  42     return snapshot_object
  43 
  44 
  45 def snapshot(savefun=npz.save_npz,
  46              filename='snapshot_iter_{.updater.iteration}',
  47              trigger=(1, 'epoch')):
  48     """Returns a trainer extension to take snapshots of the trainer.
  49 
  50     This extension serializes the trainer object and saves it to the output
  51     directory. It is used to support resuming the training loop from the saved
  52     state.
  53 
  54     This extension is called once for each epoch by default. The default
  55     priority is -100, which is lower than that of most built-in extensions.
  56 
  57     .. note::
  58        This extension first writes the serialized object to a temporary file
  59        and then rename it to the target file name. Thus, if the program stops
  60        right before the renaming, the temporary file might be left in the
  61        output directory.
  62 
  63     Args:
  64         savefun: Function to save the trainer. It takes two arguments: the
  65             output file path and the trainer object.
  66         filename (str): Name of the file into which the trainer is serialized.
  67             It can be a format string, where the trainer object is passed to
  68             the :meth:`str.format` method.
  69         trigger: Trigger that decides when to take snapshot. It can be either
  70             an already built trigger object (i.e., a callable object that
  71             accepts a trainer object and returns a bool value), or a tuple in
  72             the form ``<int>, 'epoch'`` or ``<int>, 'iteration'``. In latter
  73             case, the tuple is passed to IntervalTrigger.
  74 
  75     """
  76     @extension.make_extension(trigger=trigger, priority=-100)
  77     def snapshot(trainer):
  78         _snapshot_object(trainer, trainer, filename.format(trainer), savefun)
  79 
  80     return snapshot
  81 
  82 
  83 def _snapshot_object(trainer, target, filename, savefun):
  84     fn = filename.format(trainer)
  85     prefix = 'tmp' + fn
  86     fd, tmppath = tempfile.mkstemp(prefix=prefix, dir=trainer.out)
  87     try:
  88         savefun(tmppath, target)
  89     except Exception:
  90         os.close(fd)
  91         os.remove(tmppath)
  92         raise
  93     os.close(fd)
  94     shutil.move(tmppath, os.path.join(trainer.out, fn))
  95
  [end of chainer/training/extensions/_snapshot.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/chainer/training/extensions/_snapshot.py b/chainer/training/extensions/_snapshot.py
  --- a/chainer/training/extensions/_snapshot.py
  +++ b/chainer/training/extensions/_snapshot.py
  @@ -6,15 +6,19 @@
   from chainer.training import extension
   
   
  -def snapshot_object(target, filename, savefun=npz.save_npz,
  -                    trigger=(1, 'epoch')):
  +def snapshot_object(target, filename, savefun=npz.save_npz):
       """Returns a trainer extension to take snapshots of a given object.
   
       This extension serializes the given object and saves it to the output
       directory.
   
  -    This extension is called once for each epoch by default. The default
  -    priority is -100, which is lower than that of most built-in extensions.
  +    This extension is called once per epoch by default. To take a
  +    snapshot at a different interval, a trigger object specifying the
  +    required interval can be passed along with this extension
  +    to the `extend()` method of the trainer.
  +
  +    The default priority is -100, which is lower than that of most
  +    built-in extensions.
   
       Args:
           target: Object to serialize.
  @@ -25,17 +29,12 @@
               ``'snapshot_10000'`` at the 10,000th iteration.
           savefun: Function to save the object. It takes two arguments: the
               output file path and the object to serialize.
  -        trigger: Trigger that decides when to take snapshot. It can be either
  -            an already built trigger object (i.e., a callable object that
  -            accepts a trainer object and returns a bool value), or a tuple in
  -            the form ``<int>, 'epoch'`` or ``<int>, 'iteration'``. In latter
  -            case, the tuple is passed to IntervalTrigger.
   
       Returns:
           An extension function.
   
       """
  -    @extension.make_extension(trigger=trigger, priority=-100)
  +    @extension.make_extension(trigger=(1, 'epoch'), priority=-100)
       def snapshot_object(trainer):
           _snapshot_object(trainer, target, filename.format(trainer), savefun)
   
  @@ -43,16 +42,20 @@
   
   
   def snapshot(savefun=npz.save_npz,
  -             filename='snapshot_iter_{.updater.iteration}',
  -             trigger=(1, 'epoch')):
  +             filename='snapshot_iter_{.updater.iteration}'):
       """Returns a trainer extension to take snapshots of the trainer.
   
       This extension serializes the trainer object and saves it to the output
       directory. It is used to support resuming the training loop from the saved
       state.
   
  -    This extension is called once for each epoch by default. The default
  -    priority is -100, which is lower than that of most built-in extensions.
  +    This extension is called once per epoch by default. To take a
  +    snapshot at a different interval, a trigger object specifying the
  +    required interval can be passed along with this extension
  +    to the `extend()` method of the trainer.
  +
  +    The default priority is -100, which is lower than that of most
  +    built-in extensions.
   
       .. note::
          This extension first writes the serialized object to a temporary file
  @@ -66,14 +69,9 @@
           filename (str): Name of the file into which the trainer is serialized.
               It can be a format string, where the trainer object is passed to
               the :meth:`str.format` method.
  -        trigger: Trigger that decides when to take snapshot. It can be either
  -            an already built trigger object (i.e., a callable object that
  -            accepts a trainer object and returns a bool value), or a tuple in
  -            the form ``<int>, 'epoch'`` or ``<int>, 'iteration'``. In latter
  -            case, the tuple is passed to IntervalTrigger.
   
       """
  -    @extension.make_extension(trigger=trigger, priority=-100)
  +    @extension.make_extension(trigger=(1, 'epoch'), priority=-100)
       def snapshot(trainer):
           _snapshot_object(trainer, trainer, filename.format(trainer), savefun)
  
verification_info: {"golden_diff": "diff --git a/chainer/training/extensions/_snapshot.py b/chainer/training/extensions/_snapshot.py\n--- a/chainer/training/extensions/_snapshot.py\n+++ b/chainer/training/extensions/_snapshot.py\n@@ -6,15 +6,19 @@\n from chainer.training import extension\n \n \n-def snapshot_object(target, filename, savefun=npz.save_npz,\n-                    trigger=(1, 'epoch')):\n+def snapshot_object(target, filename, savefun=npz.save_npz):\n     \"\"\"Returns a trainer extension to take snapshots of a given object.\n \n     This extension serializes the given object and saves it to the output\n     directory.\n \n-    This extension is called once for each epoch by default. The default\n-    priority is -100, which is lower than that of most built-in extensions.\n+    This extension is called once per epoch by default. To take a\n+    snapshot at a different interval, a trigger object specifying the\n+    required interval can be passed along with this extension\n+    to the `extend()` method of the trainer.\n+\n+    The default priority is -100, which is lower than that of most\n+    built-in extensions.\n \n     Args:\n         target: Object to serialize.\n@@ -25,17 +29,12 @@\n             ``'snapshot_10000'`` at the 10,000th iteration.\n         savefun: Function to save the object. It takes two arguments: the\n             output file path and the object to serialize.\n-        trigger: Trigger that decides when to take snapshot. It can be either\n-            an already built trigger object (i.e., a callable object that\n-            accepts a trainer object and returns a bool value), or a tuple in\n-            the form ``<int>, 'epoch'`` or ``<int>, 'iteration'``. In latter\n-            case, the tuple is passed to IntervalTrigger.\n \n     Returns:\n         An extension function.\n \n     \"\"\"\n-    @extension.make_extension(trigger=trigger, priority=-100)\n+    @extension.make_extension(trigger=(1, 'epoch'), priority=-100)\n     def snapshot_object(trainer):\n         _snapshot_object(trainer, target, filename.format(trainer), savefun)\n \n@@ -43,16 +42,20 @@\n \n \n def snapshot(savefun=npz.save_npz,\n-             filename='snapshot_iter_{.updater.iteration}',\n-             trigger=(1, 'epoch')):\n+             filename='snapshot_iter_{.updater.iteration}'):\n     \"\"\"Returns a trainer extension to take snapshots of the trainer.\n \n     This extension serializes the trainer object and saves it to the output\n     directory. It is used to support resuming the training loop from the saved\n     state.\n \n-    This extension is called once for each epoch by default. The default\n-    priority is -100, which is lower than that of most built-in extensions.\n+    This extension is called once per epoch by default. To take a\n+    snapshot at a different interval, a trigger object specifying the\n+    required interval can be passed along with this extension\n+    to the `extend()` method of the trainer.\n+\n+    The default priority is -100, which is lower than that of most\n+    built-in extensions.\n \n     .. note::\n        This extension first writes the serialized object to a temporary file\n@@ -66,14 +69,9 @@\n         filename (str): Name of the file into which the trainer is serialized.\n             It can be a format string, where the trainer object is passed to\n             the :meth:`str.format` method.\n-        trigger: Trigger that decides when to take snapshot. It can be either\n-            an already built trigger object (i.e., a callable object that\n-            accepts a trainer object and returns a bool value), or a tuple in\n-            the form ``<int>, 'epoch'`` or ``<int>, 'iteration'``. In latter\n-            case, the tuple is passed to IntervalTrigger.\n \n     \"\"\"\n-    @extension.make_extension(trigger=trigger, priority=-100)\n+    @extension.make_extension(trigger=(1, 'epoch'), priority=-100)\n     def snapshot(trainer):\n         _snapshot_object(trainer, trainer, filename.format(trainer), savefun)\n", "issue": "Remove trigger option of snapshot and snapshot_object\nThey have the same functionality as the trigger argument of Trainer.extend and are redundant. I think they confuse users and they might misunderstand the trigger feature, and so they should be removed in the next major update.\n", "before_files": [{"content": "import os\nimport shutil\nimport tempfile\n\nfrom chainer.serializers import npz\nfrom chainer.training import extension\n\n\ndef snapshot_object(target, filename, savefun=npz.save_npz,\n                    trigger=(1, 'epoch')):\n    \"\"\"Returns a trainer extension to take snapshots of a given object.\n\n    This extension serializes the given object and saves it to the output\n    directory.\n\n    This extension is called once for each epoch by default. The default\n    priority is -100, which is lower than that of most built-in extensions.\n\n    Args:\n        target: Object to serialize.\n        filename (str): Name of the file into which the object is serialized.\n            It can be a format string, where the trainer object is passed to\n            the :meth:`str.format` method. For example,\n            ``'snapshot_{.updater.iteration}'`` is converted to\n            ``'snapshot_10000'`` at the 10,000th iteration.\n        savefun: Function to save the object. It takes two arguments: the\n            output file path and the object to serialize.\n        trigger: Trigger that decides when to take snapshot. It can be either\n            an already built trigger object (i.e., a callable object that\n            accepts a trainer object and returns a bool value), or a tuple in\n            the form ``<int>, 'epoch'`` or ``<int>, 'iteration'``. In latter\n            case, the tuple is passed to IntervalTrigger.\n\n    Returns:\n        An extension function.\n\n    \"\"\"\n    @extension.make_extension(trigger=trigger, priority=-100)\n    def snapshot_object(trainer):\n        _snapshot_object(trainer, target, filename.format(trainer), savefun)\n\n    return snapshot_object\n\n\ndef snapshot(savefun=npz.save_npz,\n             filename='snapshot_iter_{.updater.iteration}',\n             trigger=(1, 'epoch')):\n    \"\"\"Returns a trainer extension to take snapshots of the trainer.\n\n    This extension serializes the trainer object and saves it to the output\n    directory. It is used to support resuming the training loop from the saved\n    state.\n\n    This extension is called once for each epoch by default. The default\n    priority is -100, which is lower than that of most built-in extensions.\n\n    .. note::\n       This extension first writes the serialized object to a temporary file\n       and then rename it to the target file name. Thus, if the program stops\n       right before the renaming, the temporary file might be left in the\n       output directory.\n\n    Args:\n        savefun: Function to save the trainer. It takes two arguments: the\n            output file path and the trainer object.\n        filename (str): Name of the file into which the trainer is serialized.\n            It can be a format string, where the trainer object is passed to\n            the :meth:`str.format` method.\n        trigger: Trigger that decides when to take snapshot. It can be either\n            an already built trigger object (i.e., a callable object that\n            accepts a trainer object and returns a bool value), or a tuple in\n            the form ``<int>, 'epoch'`` or ``<int>, 'iteration'``. In latter\n            case, the tuple is passed to IntervalTrigger.\n\n    \"\"\"\n    @extension.make_extension(trigger=trigger, priority=-100)\n    def snapshot(trainer):\n        _snapshot_object(trainer, trainer, filename.format(trainer), savefun)\n\n    return snapshot\n\n\ndef _snapshot_object(trainer, target, filename, savefun):\n    fn = filename.format(trainer)\n    prefix = 'tmp' + fn\n    fd, tmppath = tempfile.mkstemp(prefix=prefix, dir=trainer.out)\n    try:\n        savefun(tmppath, target)\n    except Exception:\n        os.close(fd)\n        os.remove(tmppath)\n        raise\n    os.close(fd)\n    shutil.move(tmppath, os.path.join(trainer.out, fn))\n", "path": "chainer/training/extensions/_snapshot.py"}]}