code: def testLoops(self):
      g = ops.Graph()
      with g.as_default():
  
          def _Cond(_, counter):
              return counter < end
  
          def _Body(buf, counter):
              buf = array_ops.concat([buf, [counter]], 0)
              counter += 1
              return [buf, counter]
  
          start = array_ops.placeholder(shape=[], dtype=dtypes.int32)
          end = array_ops.placeholder(shape=[], dtype=dtypes.int32)
          init_buf = array_ops.zeros(shape=[0], dtype=dtypes.int32)
          loop_vars = [init_buf, start]
          shape_inv = [
              tensor_shape.TensorShape([None]),
              tensor_shape.TensorShape([]),
          ]
          buf, _ = while_loop.while_loop(
              _Cond, _Body, loop_vars, shape_inv
          )
  
          f = -array_ops.ones_like(
              buf, optimize=False
          )  # pylint: disable=invalid-unary-operand-type
          buf_shape = array_ops.shape(buf)
          f_shape = array_ops.shape(f)
          ops.add_to_collection("train_op", buf_shape)
          ops.add_to_collection("train_op", f_shape)
  
      # Optimize the graph.
      mg = meta_graph.create_meta_graph_def(graph=g)
      config = config_pb2.ConfigProto()
      rewriter_config = config.graph_options.rewrite_options
      rewriter_config.min_graph_nodes = -1
      optimized_graph = tf_optimizer.OptimizeGraph(config, mg)
      mg.graph_def.CopyFrom(optimized_graph)
  
      # Check that the nodes referenced in various collections have been preserved
      item = gitem.Item(mg)
      props = item.GetOpProperties()
      buf_prop = props[buf.op.name]
      f_prop = props[f.op.name]
      self.assertEqual(buf_prop, f_prop)
  
file_path: tensorflow-upstream/tensorflow/python/grappler/tf_optimizer_test.py
imports: from tensorflow.core.framework import attr_value_pb2
  from tensorflow.core.protobuf import config_pb2
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import meta_graph
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor_shape
  from tensorflow.python.framework import test_util
  from tensorflow.python.grappler import item
  from tensorflow.python.grappler import tf_optimizer
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import variable_v1
  from tensorflow.python.ops import while_loop
  from tensorflow.python.platform import test
label_desc: Use image node_id 3 for calling the PyWrapOptimizeGraphTest obj's underlying member method code with example usage: obj.testLoops() and returns: unknown, list