code: def state_reset(link):
      """Reset the state while keeping the previous state of a given link.
  
      This is a context manager that saves saves the current state of the link
      and reset it to the initial state before entering the context, and then
      restores the saved state after escaping the context.
  
      This will just ignore non-Recurrent links.
  
         .. code-block:: python
  
            # Suppose the link is in a non-initial state A
            assert link.get_state() is A
  
            with state_reset(link):
                # The link's state has been reset to the initial state
                assert link.get_state() is InitialState
  
                # After evaluating the link, it may be in a different state
                y1 = link(x1)
                assert link.get_state() is not InitialState
  
            # After escaping from the context, the link is in a state A again
            # because of the context manager
            assert link.get_state() is A
      """
      if isinstance(link, Recurrent):
          link.push_state()
          yield
          link.pop_state()
      else:
          yield
  
imports: from abc import ABCMeta
  from abc import abstractmethod
  import collections
  import contextlib
  import chainer
label_desc: Use image node_id 7 for calling a global function with example usage: state_reset(link) without return types