code: def test_loop_invariant_elimination1():
      """
      Invariant pattern: Block input vars are returned as block output vars.
      """
  
      def body(a, b):
          return mb.add(x=a, y=b), b
  
      def cond(a, b):
          a_mean = mb.reduce_mean(x=a, axes=[0, 1])
          b_mean = mb.reduce_mean(x=b, axes=[0, 1])
          return mb.less(x=a_mean, y=b_mean)
  
      @mb.program(
          input_specs=[
              mb.TensorSpec(shape=(1, 2)),
              mb.TensorSpec(shape=(1, 2)),
          ]
      )
      def prog(a, b):
          # b is loop invariant
          return mb.while_loop(_cond=cond, _body=body, loop_vars=(a, b))
  
      while_op = prog.find_ops(op_type="while_loop", exactly_one=True)[
          0
      ]
      assert len(while_op.blocks[0].inputs) == 2
      assert len(while_op.outputs) == 2
      assert len(while_op.loop_vars) == 2
      assert while_op.blocks[0].inputs[0].name == "a.x"
      assert while_op.blocks[0].inputs[1].name == "b.x"
  
      prev_prog = copy.deepcopy(prog)
      PASS_REGISTRY["common::loop_invariant_elimination"](prog)
      assert_same_output_names(prev_prog, prog)
  
      while_op = prog.find_ops(op_type="while_loop", exactly_one=True)[
          0
      ]
      assert len(while_op.blocks[0].inputs) == 1
      assert len(while_op.outputs) == 1
      assert len(while_op.loop_vars) == 1
      assert while_op.blocks[0].inputs[0].name == "a.x"
  
      if validate_model:
          assert_model_is_valid(prog, {"a": (1, 2), "b": (1, 2)})
  
file_path: turicreate/src/external/coremltools_wrap/coremltools/coremltools/converters/mil/mil/passes/test_passes.py
imports: from coremltools.converters.mil.mil import Builder
  from coremltools.converters.mil.testing_utils import assert_op_count_match, assert_model_is_valid, assert_same_output_names, get_op_types_in_program, apply_pass_and_basic_check
  from coremltools.converters.mil.mil import Symbol, types
  from coremltools.converters.mil.mil.passes.pass_registry import PASS_REGISTRY
  import copy
  import pytest
  import numpy
label_desc: Use image node_id 6 for calling a global function with example usage: test_loop_invariant_elimination1() and returns: mb,  b, mb, mb