code: def test_get_direct_ancestor():
      data = relay.var("data")
      w0 = relay.var("w0")
      out1 = relay.nn.conv2d(data, w0)
      out2 = relay.add(out1, data * relay.expr.const(5.0))
      out3 = out2 + relay.expr.const(2.5)
      w1 = relay.var("w1")
      out = relay.nn.conv2d(out3, w1)
      net = relay.Function(relay.analysis.free_vars(out), out)
      net = bind_inputs(
          net,
          {
              "data": (1, 16, 224, 224),
              "w0": (16, 16, 1, 1),
              "w1": (16, 16, 1, 1),
          },
      )
      target_ops = [relay.op.get("nn.conv2d")]
      node_list = []
      node_dict = {}
      expr2graph(
          net,
          target_ops,
          node_dict,
          node_list,
          tvm.target.Target("llvm"),
      )
      visited_dict = {}
      input_names = ["data"]
      out = get_direct_ancestor(
          node_list, visited_dict, target_ops, 5, input_names
      )
      assert out == [
          0
      ], "Output mismatch: expecting [0] but got %s." % str(out)
  
      # non-regression test
      out = relay.add(relay.log(data), relay.sqrt(data))
      net = relay.Function(relay.analysis.free_vars(out), out)
      net = bind_inputs(net, {"data": (1, 16, 224, 224)})
      node_list = []
      node_dict = {}
      expr2graph(
          net,
          target_ops,
          node_dict,
          node_list,
          tvm.target.Target("llvm"),
      )
      out = get_direct_ancestor(
          node_list, visited_dict, target_ops, 3, input_names
      )
      assert out == [
          0
      ], "Output mismatch: expecting [0] but got %s." % str(out)
  
file_path: tvm/tests/python/autotvm/test_autotvm_graph_tuner_utils.py
imports: import pytest
  import tvm
  from tvm import te
  from tvm import autotvm, relay
  from tvm.relay.testing import synthetic
  from tvm.autotvm.graph_tuner.utils import has_multiple_inputs, get_direct_ancestor, get_in_nodes, get_out_nodes, expr2graph, bind_inputs
  from tvm.autotvm.graph_tuner._base import OPT_OUT_OP
  from tvm.autotvm.graph_tuner.utils.traverse_graph import _replace_device_with_tracing
  from tvm.relay.expr import Call, TupleGetItem, Tuple, Var
label_desc: Use image node_id 4 for calling a global function with example usage: test_get_direct_ancestor() without return types