code: def build_einsum_mil(
      vars: List[Var], equation: str, name: str
  ) -> Var:
      """
      Get MIL variables as input and build a variable using MIL builder, that
      contains the output of the einsum equation
  
      :param vars:
          - List[var]
          - list of input variables
      :param equation:
          - str
          - the einsum equation
      :param name:
          - str
          - name tp be assigned to the output var
  
      :return:
          - var
          - output var that contains the einsum result
      """
  
      ## TODO: rdar://73851694 (Update einsum op translation to support generic cases)
      equation = equation.replace(" ", "")
      parsed_vectors = parse_einsum_equation(equation)
  
      if len(vars) != 2:
          return solve_generic_einsum(list(parsed_vectors), vars, name)
  
      equation_rev = _reverse_input_einsum_eq(equation)
      parsed_vectors_rev = parse_einsum_equation(equation_rev)
  
      def _swap(a, b):
          return b, a
  
      a_var, b_var = vars
      is_dynamic = any([any_symbolic(var.shape) for var in vars])
      # list of equations supported for explicit mil translations
      vec_bnqd_bnkd_bnqk = (
          [0, 1, 2, 3],
          [0, 1, 4, 3],
          [0, 1, 2, 4],
      )  # equation == "bnqd,bnkd->bnqk"
      vec_bhcq_bhck_bhqk = (
          [0, 1, 2, 3],
          [0, 1, 2, 4],
          [0, 1, 3, 4],
      )  # equation == "bhcq,bhck->bhqk"
      vec_abc_cd_abd = (
          [0, 1, 2],
          [2, 3],
          [0, 1, 3],
      )  # equation == "abc,cd->abd"
      vec_abc_cde_abde = (
          [0, 1, 2],
          [2, 3, 4],
          [0, 1, 3, 4],
      )  # equation == "abc,cde->abde"
      vec_btnh_bfnh_bnft = (
          [0, 1, 2, 3],
          [0, 4, 2, 3],
          [0, 2, 4, 1],
      )  # equation == "btnh,bfnh->bnft"
      vec_bnft_btnh_bfnh = (
          [0, 1, 2, 3],
          [0, 3, 1, 4],
          [0, 2, 1, 4],
      )  # equation == "bnft,btnh->bfnh"
      vec_abcd_cde_abe = (
          [0, 1, 2, 3],
          [2, 3, 4],
          [0, 1, 4],
      )  # equation == "abcd,cde->abe"
      vec_nchw_nwhu_nchu = (
          [0, 1, 2, 3],
          [0, 3, 2, 4],
          [0, 1, 2, 4],
      )  # equation == "nchw,nwhu->nchu"
      vec_chw_whu_chu = (
          [0, 1, 2],
          [2, 1, 3],
          [0, 1, 3],
      )  # equation == "chw,whu->chu"
  
      # add the op(s) corresponding to the equation
      if vec_bnqd_bnkd_bnqk in [parsed_vectors, parsed_vectors_rev]:
          if parsed_vectors_rev == vec_bnqd_bnkd_bnqk:
              a_var, b_var = _swap(a_var, b_var)
          x = mb.matmul(
              x=a_var,
              y=b_var,
              transpose_x=False,
              transpose_y=True,
              name=name,
          )
      elif vec_bhcq_bhck_bhqk in [parsed_vectors, parsed_vectors_rev]:
          if parsed_vectors_rev == vec_bhcq_bhck_bhqk:
              a_var, b_var = _swap(a_var, b_var)
          x = mb.matmul(
              x=a_var,
              y=b_var,
              transpose_x=True,
              transpose_y=False,
              name=name,
          )
      elif vec_abc_cd_abd in [parsed_vectors, parsed_vectors_rev]:
          if parsed_vectors_rev == vec_abc_cd_abd:
              a_var, b_var = _swap(a_var, b_var)
          x = mb.matmul(
              x=a_var,
              y=b_var,
              transpose_x=False,
              transpose_y=False,
              name=name,
          )
      elif (
          vec_abc_cde_abde in [parsed_vectors, parsed_vectors_rev]
          and not is_dynamic
      ):
          if parsed_vectors_rev == vec_abc_cde_abde:
              a_var, b_var = _swap(a_var, b_var)
          x_1 = mb.reshape(
              x=a_var,
              shape=[a_var.shape[0] * a_var.shape[1], a_var.shape[2]],
          )
          x_2 = mb.reshape(
              x=b_var,
              shape=[b_var.shape[0], b_var.shape[1] * b_var.shape[2]],
          )
          x = mb.matmul(
              x=x_1, y=x_2, transpose_x=False, transpose_y=False
          )
          x = mb.reshape(
              x=x,
              shape=[
                  a_var.shape[0],
                  a_var.shape[1],
                  b_var.shape[1],
                  b_var.shape[2],
              ],
              name=name,
          )
      elif vec_btnh_bfnh_bnft in [parsed_vectors, parsed_vectors_rev]:
          if parsed_vectors_rev == vec_btnh_bfnh_bnft:
              a_var, b_var = _swap(a_var, b_var)
          x_1 = mb.transpose(x=a_var, perm=[0, 2, 1, 3])
          x_2 = mb.transpose(x=b_var, perm=[0, 2, 1, 3])
          x = mb.matmul(
              x=x_2,
              y=x_1,
              transpose_x=False,
              transpose_y=True,
              name=name,
          )
      elif vec_bnft_btnh_bfnh in [parsed_vectors, parsed_vectors_rev]:
          if parsed_vectors_rev == vec_bnft_btnh_bfnh:
              a_var, b_var = _swap(a_var, b_var)
          b_var = mb.transpose(x=b_var, perm=[0, 2, 1, 3])
          x = mb.matmul(
              x=a_var, y=b_var, transpose_x=False, transpose_y=False
          )
          x = mb.transpose(x=x, perm=[0, 2, 1, 3], name=name)
      elif (
          vec_abcd_cde_abe in [parsed_vectors, parsed_vectors_rev]
          and not is_dynamic
      ):
          if parsed_vectors_rev == vec_abcd_cde_abe:
              a_var, b_var = _swap(a_var, b_var)
          x_1 = mb.reshape(
              x=a_var,
              shape=[
                  a_var.shape[0],
                  a_var.shape[1],
                  a_var.shape[2] * a_var.shape[3],
              ],
          )
          x_2 = mb.reshape(
              x=b_var,
              shape=[b_var.shape[0] * b_var.shape[1], b_var.shape[2]],
          )
          x = mb.matmul(
              x=x_1,
              y=x_2,
              transpose_x=False,
              transpose_y=False,
              name=name,
          )
      elif vec_nchw_nwhu_nchu in [parsed_vectors, parsed_vectors_rev]:
          if parsed_vectors == vec_nchw_nwhu_nchu:
              x = mb.einsum(
                  values=(a_var, b_var), equation=equation, name=name
              )
          else:
              x = mb.einsum(
                  values=(b_var, a_var),
                  equation=equation_rev,
                  name=name,
              )
      elif vec_chw_whu_chu in [parsed_vectors, parsed_vectors_rev]:
          if parsed_vectors == vec_chw_whu_chu:
              x = mb.einsum(
                  values=(a_var, b_var), equation=equation, name=name
              )
          else:
              x = mb.einsum(
                  values=(b_var, a_var),
                  equation=equation_rev,
                  name=name,
              )
      else:
          x = solve_generic_einsum(
              list(parsed_vectors), [a_var, b_var], name
          )
  
      return x
  
file_path: coremltools/coremltools/converters/mil/frontend/_utils.py
imports: import itertools
  from typing import List, Optional
  from coremltools.converters.mil.input_types import InputType
  from coremltools.converters.mil.mil import Builder
  from coremltools.converters.mil.mil import Var, types
  from coremltools.converters.mil.mil.ops.defs._utils import parse_einsum_equation
  from coremltools.converters.mil.mil.types.symbolic import any_symbolic, is_symbolic
label_desc: Use image node_id 3 for calling a global function with example usage: build_einsum_mil(vars, equation, name) and returns: x, solve_generic_einsum, b,  a