code: def test_graph_rewire(seed, clear_buffer):
      nn.clear_parameters()
  
      # A. defining graph definition utility
      def mlp2(x, scope):
          with nn.parameter_scope(scope):
              h = F.tanh(PF.affine(x, 10, name="a1"))
              h = F.tanh(PF.affine(h, 10, name="a1"))
              return h
  
      # A. Create a graph A.
      xa = nn.Variable((2, 10), need_grad=True)
      ya = mlp2(xa, "a")
  
      # B. Create a graph B.
      xb = nn.Variable((2, 10), need_grad=True)
      yb1 = mlp2(xb, "b1")
      yb2 = mlp2(xb, "b2")
  
      # C. Create directly connected graph.
      xc = nn.Variable((2, 10))
      h = mlp2(xc, "a")
      yc1 = mlp2(h, "b1")
      yc2 = mlp2(h, "b2")
  
      # D. Rewire the graphs A and B.
      xb.rewire_on(ya)
  
      # E. Check whether the results are the same.
      rng = np.random.RandomState(seed)
      data = rng.randn(*xa.shape)
      xa.d = data
      xc.d = data
      params = nn.get_parameters()
  
      def zero_grad():
          for p in params.values():
              p.grad.zero()
  
      def backup_params():
          return [p.g.copy() for p in params.values()]
  
      # Checking forward
      nn.forward_all(
          [yb1, yb2, yc1, yc2], clear_no_need_grad=clear_buffer
      )
      assert_allclose(yb1.d, yc1.d)
      assert_allclose(yb2.d, yc2.d)
  
      # Checking backward for yb1 and yc1
      # for now, the first backward cannot be called with clear_buffer=True
      zero_grad()
      yb1.backward(clear_buffer=False)
      gb = backup_params()
      zero_grad()
      yc1.backward(clear_buffer=False)
      gc = backup_params()
      assert_allclose(xa.d, xc.d)
      for b, c in zip(gb, gc):
          assert_allclose(b, c)
  
      # Checking backward for yb2 and yc2
      zero_grad()
      yb2.backward(clear_buffer=clear_buffer)
      gb = backup_params()
      zero_grad()
      yc2.backward(clear_buffer=clear_buffer)
      gc = backup_params()
      assert_allclose(xa.d, xc.d)
      for b, c in zip(gb, gc):
          assert_allclose(b, c)
  
file_path: nnabla/python/test/test_forward_all.py
imports: from six.moves import range
  import pytest
  import numpy
  import nnabla
  import nnabla.functions
  import nnabla.parametric_functions
  from nnabla.testing import assert_allclose
label_desc: Use image node_id 8 for calling a global function with example usage: test_graph_rewire(seed, clear_buffer) and returns: unknown, h