code: def test_optional_pattern():
      r"""Test the pattern with optional operators. We can define a pattern with some operators
      optional. The merge composite pass will create composite functions for all matched patterns,
      but with different "PartitionedFromPattern" attribute. We expect the backend codegen to
      analyze that attribute and determine the corresponding action.
  
      Pattern:    Matched Case A:    Matched Case B:
  
       conv2d        conv2d             conv2d
         |             |                  |
      bias_add      bias_add           bias_add
         |             |
       (relu)         relu
  
      In the above example, the composite function for matched case A would have
      PartitionedFromPattern="nn.conv2d_nn.bias_add_nn.relu_" while the one for matched case B
      woud be "nn.conv2d_nn.bias_add_".
      """
      pattern_table = [("layer", make_pattern_with_optional())]
  
      def before():
          x = relay.var("x", shape=(1, 3, 7, 7))
          w1 = relay.var("w", shape=(3, 3, 1, 1))
          b1 = relay.var("b", shape=(3,))
          w2 = relay.var("w", shape=(3, 3, 1, 1))
          b2 = relay.var("b", shape=(3,))
          conv = relay.nn.conv2d(x, w1, kernel_size=(1, 1))
          bias = relay.nn.bias_add(conv, b1)
          relu = relay.nn.relu(bias)
          conv = relay.nn.conv2d(relu, w2, kernel_size=(1, 1))
          bias = relay.nn.bias_add(conv, b2)
          return relay.Function([x, w1, w2, b1, b2], bias)
  
      def expected():
          # Matched composite function A
          x = relay.var("x")
          w = relay.var("w")
          b = relay.var("b")
          conv = relay.nn.conv2d(x, w, kernel_size=(1, 1))
          bias = relay.nn.bias_add(conv, b)
          relu = relay.nn.relu(bias)
          func1 = relay.Function([x, w, b], relu)
          func1 = func1.with_attr("Composite", "layer")
          func1 = func1.with_attr(
              "PartitionedFromPattern", "nn.conv2d_nn.bias_add_nn.relu_"
          )
  
          # Matched composite function B
          x = relay.var("x")
          w = relay.var("w")
          b = relay.var("b")
          conv = relay.nn.conv2d(x, w, kernel_size=(1, 1))
          bias = relay.nn.bias_add(conv, b)
          func2 = relay.Function([x, w, b], bias)
          func2 = func2.with_attr("Composite", "layer")
          func2 = func2.with_attr(
              "PartitionedFromPattern", "nn.conv2d_nn.bias_add_"
          )
  
          # Main function
          x = relay.var("x", shape=(1, 3, 7, 7))
          w1 = relay.var("w", shape=(3, 3, 1, 1))
          b1 = relay.var("b", shape=(3,))
          w2 = relay.var("w", shape=(3, 3, 1, 1))
          b2 = relay.var("b", shape=(3,))
          out1 = func1(x, w1, b1)
          out2 = func2(out1, w2, b2)
          return relay.Function([x, w1, w2, b1, b2], out2)
  
      check_result(pattern_table, before(), expected())
  
imports: import pytest
  import tvm
  from tvm import relay, tir
  from tvm.relay.dataflow_pattern import TuplePattern, TupleGetItemPattern, is_op, wildcard
  from tvm.relay.testing import run_opt_pass
label_desc: Use image node_id 12 for calling a global function with example usage: test_optional_pattern() and returns: relay, relay