class_docstr: General-purpose dependency graph.
  
  Essentially a directed acyclic graph.
  Usually used to find an evaluation order for e.g. variable substitution
  The relation that an edge between A and B represents is:
  "A depends on B, i.e. B should be evaluated before A"
  
  Nodes can be added explicitly or they can be created implicitly
  while adding edges.
  Nodes have keys, which should be some hashable value that identifies
  the elements the graph represents in your use case. E.G. they can just
  be the variable name you want to substitute.
  However, if needed, more generally you can attach any data to a node
  (e.g. a path in your tree), and if so desired, a unique key can be
  created for you. You'll only need to know that key while adding edges
  to/from it.
  Implicit keys and explicit keys can also be mixed.
docstr: Finds one valid evaluation order.
  
  There can be many different valid
  orders.
  NOTE: Generates output one DGNode at a time. May generate DGNodes
  before it finds a circular dependency. If you really need to know
  whether an order can be found, check is_valid() first. However,
  the algorithm for finding cycles is essentially the same as the one
  used for finding an evaluation order, so for very large graphs...
  Ah well, but maybe then you should be using some other solution
  anyway.
  
  Arguments
  ---------
  selected_keys : list, None
      List of keys. If not None, only the selected keys are guaranteed
      in the evaluation order (along with the keys they depend on).
  
  Yields
  ------
  DGNode
      The added DGNodes in a valid evaluation order.
      See the DGNode namedtuple above.
  
  Raises
  ------
  CircularDependencyError
      If a circular dependency is found.
docstr_tok: ["Finds","one","valid","evaluation","order",".","There","can","be","many","different","valid","orders",".","NOTE",":","Generates","output","one","DGNode","at","a","time",".","May","generate","DGNodes","before","it","finds","a","circular","dependency",".","If","you","really","need","to","know","whether","an","order","can","be","found",",","check","is_valid","(",")","first",".","However",",","the","algorithm","for","finding","cycles","is","essentially","the","same","as","the","one","used","for","finding","an","evaluation","order",",","so","for","very","large","graphs","...","Ah","well",",","but","maybe","then","you","should","be","using","some","other","solution","anyway",".","Arguments","--","--","--","--","-","selected_keys",":","list",",","None","List","of","keys",".","If","not","None",",","only","the","selected","keys","are","guaranteed","in","the","evaluation","order","(","along","with","the","keys","they","depend","on",")",".","Yields","--","--","--","DGNode","The","added","DGNodes","in","a","valid","evaluation","order",".","See","the","DGNode","namedtuple","above",".","Raises","--","--","--","CircularDependencyError","If","a","circular","dependency","is","found","."]
code: def get_evaluation_order(self, selected_keys=None):
      """Finds one valid evaluation order.
  
      There can be many different valid
      orders.
      NOTE: Generates output one DGNode at a time. May generate DGNodes
      before it finds a circular dependency. If you really need to know
      whether an order can be found, check is_valid() first. However,
      the algorithm for finding cycles is essentially the same as the one
      used for finding an evaluation order, so for very large graphs...
      Ah well, but maybe then you should be using some other solution
      anyway.
  
      Arguments
      ---------
      selected_keys : list, None
          List of keys. If not None, only the selected keys are guaranteed
          in the evaluation order (along with the keys they depend on).
  
      Yields
      ------
      DGNode
          The added DGNodes in a valid evaluation order.
          See the DGNode namedtuple above.
  
      Raises
      ------
      CircularDependencyError
          If a circular dependency is found.
      """
      seen_ever = set()
  
      def toposort(root_ind, visited):
          """Implementation of topsort."""
          nonlocal seen_ever
          here = visited + [root_ind]
          if root_ind in visited:
              raise CircularDependencyError(
                  "{cycle}".format(
                      cycle=" -> ".join(
                          str(self.digraph[i].key) for i in here
                      )
                  )
              )
          if root_ind in seen_ever:
              return  # Yield nothing
          seen_ever = seen_ever.union(set([root_ind]))
          for to_ind in self.digraph[root_ind].edges:
              for ind in toposort(to_ind, visited=here):
                  yield ind
          yield root_ind
  
      if selected_keys is None:
          start_inds = range(len(self.digraph))
      else:
          start_inds = [self.key2ind[key] for key in selected_keys]
  
      for start_ind in start_inds:
          for ind in toposort(start_ind, []):
              yield self.digraph[ind]
  
file_path: speechbrain/speechbrain/utils/depgraph.py
imports: import collections
  import uuid
label_desc: Use image node_id 7 for calling the DependencyGraph obj's underlying member method code with example usage: obj.get_evaluation_order(selected_keys) without return types