docstr: Input graph:
  x -> sin ------> sub -> output_1
        |      |
        v      v
  y -> add -> mul -> tan -> realdiv -> output_2
docstr_tok: ["Input","graph",":","x","-",">","sin","--","--","--",">","sub","-",">","output_1","|","|","v","v","y","-",">","add","-",">","mul","-",">","tan","-",">","realdiv","-",">","output_2"]
code: def test_extract_submodel_complex(self):
      """
      Input graph:
      x -> sin ------> sub -> output_1
            |      |
            v      v
      y -> add -> mul -> tan -> realdiv -> output_2
      """
  
      @mb.program(
          input_specs=[
              mb.TensorSpec(shape=(1, 2)),
              mb.TensorSpec(shape=(1, 2)),
          ]
      )
      def prog(x, y):
          sin = mb.sin(x=x, name="sin")
          add = mb.add(x=sin, y=y, name="add")
          sub = mb.sub(x=sin, y=1.5, name="sub")
          mul = mb.mul(x=sin, y=add, name="mul")
          tan = mb.tan(x=mul, name="tan")
          realdiv = mb.real_div(x=tan, y=4.7, name="realdiv")
          return sub, realdiv
  
      model = ct.convert(prog, convert_to="neuralnetwork")
  
      """
          Case 1:
          inputs = None
          outputs = [sin, mul]
          
          Output graph:
          x -> sin ------> output_1
                |      |
                v      v
          y -> add -> mul -> output_2
          """
      submodel = extract_submodel(model, outputs=["sin", "mul"])
      assert get_op_types_in_program(submodel._mil_program) == [
          "sin",
          "add",
          "mul",
      ]
  
      """
          Case 2:
          inputs = None
          outputs = [sin, add]
          
          Output graph:
          x -> sin -> output_1
                |
                v
          y -> add -> output_2
          """
      submodel = extract_submodel(model, outputs=["sin", "add"])
      assert get_op_types_in_program(submodel._mil_program) == [
          "sin",
          "add",
      ]
  
      """
          Case 3:
          inputs = None
          outputs = [mul]
          
          Output graph:
          x -> sin -----
                |      |
                v      v
          y -> add -> mul -> output_1
          """
      submodel = extract_submodel(model, outputs=["mul"])
      assert get_op_types_in_program(submodel._mil_program) == [
          "sin",
          "add",
          "mul",
      ]
  
      """
          Case 4:
          inputs = None
          outputs = [sin, sub]
          
          Output graph:
          x -> sin -> sub -> output_2
                |
                V
             output_1
          y
          """
      submodel = extract_submodel(model, outputs=["sin", "sub"])
      print(submodel._mil_program)
      assert get_op_types_in_program(submodel._mil_program) == [
          "sin",
          "sub",
      ]
  
      """
          Case 5:
          inputs = [x, y]
          outputs = [mul]
          
          Output graph:
          x -> sin -----
                |      |
                v      v
          y -> add -> mul -> output_1
          """
      submodel = extract_submodel(
          model, outputs=["mul"], inputs=["x", "y"]
      )
      assert get_op_types_in_program(submodel._mil_program) == [
          "sin",
          "add",
          "mul",
      ]
  
      """
          Case 6:
          inputs = [mul]
          outputs = [tan]
          
          mul -> tan -> output_1
          """
      submodel = extract_submodel(
          model, outputs=["tan"], inputs=["mul"]
      )
      assert get_op_types_in_program(submodel._mil_program) == ["tan"]
  
      """
          Case 7:
          inputs = [sin, add]
          outputs = [sub, mul]
  
          sin ------> sub -> output_1
                  |
                  v
          add -> mul -> output_2
          """
      submodel = extract_submodel(
          model, outputs=["sub", "mul"], inputs=["sin", "add"]
      )
      assert get_op_types_in_program(submodel._mil_program) == [
          "sub",
          "mul",
      ]
  
      """
          Case 8 (Negative):
          inputs = [sin]
          outputs = [mul]
          
          mul not reachable merely through sin
          """
      with pytest.raises(
          ValueError, match="output mul not reachable from inputs"
      ):
          submodel = extract_submodel(
              model, outputs=["mul"], inputs=["sin"]
          )
  
      """
          Case 9 (Negative):
          inputs = [mul]
          outputs = [sin]
          
          sin not reachable merely through sin
          """
      with pytest.raises(
          ValueError, match="output sin not reachable from inputs"
      ):
          submodel = extract_submodel(
              model, outputs=["sin"], inputs=["mul"]
          )
  
file_path: coremltools/coremltools/converters/mil/mil/tests/test_debug.py
imports: import itertools
  import os
  import tempfile
  import pytest
  import numpy
  import coremltools
  from coremltools.converters.mil import Builder
  from coremltools.converters.mil.debugging_utils import extract_submodel
  from coremltools.converters.mil.mil import get_new_symbol
  from coremltools.converters.mil.mil.types.symbolic import is_symbolic
  from coremltools.converters.mil.testing_utils import get_op_types_in_program
label_desc: Use image node_id 3 for calling the TestExtractSubModel obj's underlying member method code with example usage: obj.test_extract_submodel_complex() and returns: sub,  realdiv