code: def topological_sort(self):
      # Implemented using depth-first search
      # Also works as a test of acyclicity
      n_nodes = len(self._successors)
  
      sorted_nodes = deque(maxlen=n_nodes)
      visited_nodes = set()
      unvisited_nodes = deque(
          sorted(
              self._predecessors,
              key=lambda k: len(self._predecessors[k]),
          ),
          maxlen=n_nodes,
      )
  
      # It is not mandatory, but to have more intuitive orderings,
      # we start depth-first search from nodes without predecessors (inputs)
  
      def visit(node):
          if node in sorted_nodes:
              return
          if node in visited_nodes:
              raise CyclicDiGraphError("DiGraph is not acyclic.")
  
          visited_nodes.add(node)
          for successor in self._successors[node]:
              visit(successor)
  
          visited_nodes.remove(node)
          sorted_nodes.appendleft(node)
  
      while unvisited_nodes:
          next_node = unvisited_nodes.popleft()
          visit(next_node)
  
      return list(sorted_nodes)
  
file_path: baikal/baikal/_core/digraph.py
imports: from collections import deque, defaultdict, OrderedDict
label_desc: Use image node_id 14 for calling the DiGraph obj's underlying member method code with example usage: obj.topological_sort() and returns: list