code: def test_simple_substituion():
      """Replace log(x+y) with log(x*y)"""
  
      @mb.program(
          input_specs=[
              mb.TensorSpec(shape=(2, 4)),
              mb.TensorSpec(shape=(2, 4)),
          ]
      )
      def prog(x0, y0):
          x1 = mb.add(x=x0, y=y0)
          z = mb.log(x=x1)
          return z
  
      print("before:\n{}".format(prog))
      block = prog.functions["main"]
      assert len(block.find_ops(op_type="log")) == 1
      assert len(block.find_ops(op_type="add")) == 1
      assert len(block.find_ops(op_type="mul")) == 0
  
      add = block.find_ops(op_type="add")[0]
  
      x0 = add.inputs["x"]
      y0 = add.inputs["y"]
      x1 = add.outputs[0]
  
      with block:
          # It's important to add 'mul' before 'add' (its even better to do it
          # immediately after 'add' but we don't have the API)
          # because we need to replace any op affected by add with 'mul'
          x2 = mb.mul(x=x0, y=y0, before_op=add)
  
      assert len(block.find_ops(op_type="mul")) == 1
      assert len(block.find_ops(op_type="add")) == 1
      assert len(block.find_ops(op_type="log")) == 1
  
      # It's important to set anchor_op = 'mul' because new_var is only visible
      # after 'mul'.
      block.replace_uses_of_var_after_op(
          anchor_op=x2.op, old_var=x1, new_var=x2
      )
      block.remove_ops([add])
  
      print("after:\n{}".format(prog))
      assert len(block.find_ops(op_type="add")) == 0
      assert len(block.find_ops(op_type="mul")) == 1
      assert len(block.find_ops(op_type="log")) == 1
  
file_path: turicreate/src/external/coremltools_wrap/coremltools/coremltools/converters/mil/mil/tests/test_block.py
imports: from __future__ import print_function
  from __future__ import division
  from __future__ import absolute_import
  from coremltools.converters.mil.mil import Builder
  from coremltools.converters.mil.testing_utils import get_op_types_in_program, assert_same_output_shapes, assert_same_output_names
  import copy
label_desc: Use image node_id 6 for calling a global function with example usage: test_simple_substituion() and returns: z