code: def find_ancestor(
      node_set, node_names, adjacency_matrix, node2idx, idx2node
  ):
      """
      Finds ancestors of a given set of nodes in a given graph.
  
      :param node_set: Set of nodes whos ancestors must be obtained.
      :param node_names: Name of all nodes in the graph.
      :param adjacency_matrix: Graph adjacency matrix.
      :param node2idx: A dictionary mapping node names to their row or column index in the adjacency matrix.
      :param idx2node: A dictionary mapping the row or column indices in the adjacency matrix to the corresponding node names.
      :returns: OrderedSet containing ancestors of all nodes in the node_set.
      """
  
      def find_ancestor_help(
          node_name, node_names, adjacency_matrix, node2idx, idx2node
      ):
          ancestors = OrderedSet()
          nodes_to_visit = LifoQueue(maxsize=len(node_names))
          nodes_to_visit.put(node2idx[node_name])
          while not nodes_to_visit.empty():
              child = nodes_to_visit.get()
              ancestors.add(idx2node[child])
              for i in range(len(node_names)):
                  if (
                      idx2node[i] not in ancestors
                      and adjacency_matrix[i, child] == 1
                  ):  # For edge a->b, a is along height and b is along width of adjacency matrix
                      nodes_to_visit.put(i)
          return ancestors
  
      ancestors = OrderedSet()
      for node_name in node_set.get_all():
          ancestors = ancestors.union(
              find_ancestor_help(
                  node_name,
                  node_names,
                  adjacency_matrix,
                  node2idx,
                  idx2node,
              )
          )
      return ancestors
  
imports: import re
  from queue import LifoQueue
  import networkx
  import numpy
  from networkx.algorithms.dag import is_directed_acyclic_graph
  from networkx.algorithms.shortest_paths.generic import shortest_path
  from dowhy.utils.ordered_set import OrderedSet
label_desc: Use image node_id 4 for calling a global function with example usage: find_ancestor(node_set, node_names, adjacency_matrix, node2idx, idx2node) and returns: ancestors, ancestors