code: def test_dead_code_elimination():
      @mb.program(
          input_specs=[
              mb.TensorSpec(shape=(2, 4)),
              mb.TensorSpec(shape=(2, 4)),
          ]
      )
      def program0(x, y):
          # following three unused op should be eliminated
          a = mb.const(val=np.zeros(shape=(1,)), mode="immediate_value")
          b = mb.const(val=np.zeros(shape=(1,)), mode="immediate_value")
          _ = mb.add(x=a, y=b)
          return mb.add(x=x, y=y)
  
      assert_op_count_match(program0, expect=4)
      prev_prog = copy.deepcopy(program0)
      PASS_REGISTRY["common::dead_code_elimination"](program0)
      assert_same_output_names(prev_prog, program0)
      assert_op_count_match(program0, expect=1)
  
      if validate_model:
          assert_model_is_valid(program0, {"x": (2, 4), "y": (2, 4)})
  
      @mb.program(input_specs=[mb.TensorSpec(shape=(2, 4))])
      def program1(x):
          weights_val = np.random.rand(2, 4).T.astype(np.float32)
          weights = mb.const(val=weights_val, mode="immediate_value")
          bias_val = np.random.rand(4).astype(np.float32)
          bias = mb.const(val=bias_val, mode="immediate_value")
  
          # unused op and its inputs should be eliminated
          mb.matmul(x=x, y=weights)
  
          return mb.linear(x=x, weight=weights, bias=bias)
  
      assert_op_count_match(program1, expect=6)
      prev_prog = copy.deepcopy(program1)
      PASS_REGISTRY["common::dead_code_elimination"](program1)
      assert_same_output_names(prev_prog, program1)
      assert_op_count_match(program1, expect=3)
  
      if validate_model:
          assert_model_is_valid(program1, {"x": (2, 4)})
  
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 4 for calling a global function with example usage: test_dead_code_elimination() and returns: mb, mb