class_docstr: NeuralEngine takes a list of hooks and executes them in their topological order. The
  topological order of the hooks is determined by their required inputs and outputs.
class_docstr_tok: ["NeuralEngine","takes","a","list","of","hooks","and","executes","them","in","their","topological","order",".","The","topological","order","of","the","hooks","is","determined","by","their","required","inputs","and","outputs","."]
code: def topological_sort(status, hooks):
      # Get DAG
      graph = nx.DiGraph()
      edges = []
      pending_outputs = []
      output_to_hook = {}
      for hook in hooks:
          for pair in itertools.product(
              hook.get_inputs(), hook.get_outputs()
          ):
              edges.append(pair)
          for output in hook.get_outputs():
              assert output not in pending_outputs
              output_to_hook[output] = hook
              pending_outputs.append(output)
      graph.add_edges_from(edges)
      for _current in nx.topological_sort(graph):
          if _current in pending_outputs:
              _hook = output_to_hook[_current]
              yield _hook
              for _hook_out in _hook.get_outputs():
                  pending_outputs.remove(_hook_out)
          else:
              assert _current in status
      assert len(pending_outputs) == 0
  
file_path: pytorchvideo/pytorchvideo/neural_engine/engine.py
imports: import itertools
  from collections import OrderedDict
  from typing import List, Union
  import networkx
  from pytorchvideo.neural_engine import HookBase
label_desc: Use image node_id 4 for calling the NeuralEngine obj's underlying member method code with example usage: obj.topological_sort(status, hooks) without return types