code: def sort_apply_nodes(inputs, outputs, cmps):
      """
      Order a graph of apply nodes according to a list of comparators.
  
      The following example sorts first by dependence of nodes (this is a
      topological sort) and then by lexicographical ordering (nodes that start
      with 'E' come before nodes that start with 'I' if there is no dependence.
  
      Examples
      --------
      >>> from theano.gof.graph import sort_apply_nodes, dependence
      >>> from theano.tensor import matrix, dot
      >>> x = matrix('x')
      >>> y = dot(x*2, x+1)
      >>> str_cmp = lambda a, b: cmp(str(a), str(b)) # lexicographical sort
      >>> sort_apply_nodes([x], [y], cmps=[dependence, str_cmp])
      [Elemwise{add,no_inplace}(x, InplaceDimShuffle{x,x}.0),
       InplaceDimShuffle{x,x}(TensorConstant{2}),
       Elemwise{mul,no_inplace}(x, InplaceDimShuffle{x,x}.0),
       InplaceDimShuffle{x,x}(TensorConstant{1}),
       dot(Elemwise{mul,no_inplace}.0, Elemwise{add,no_inplace}.0)]
  
      """
      return posort(list_of_nodes(inputs, outputs), *cmps)
  
file_path: Theano/theano/gof/sched.py
imports: from __future__ import absolute_import, print_function, division
  from collections import defaultdict
  from six import iteritems
  from theano.gof.graph import list_of_nodes
  from theano.compat import cmp
label_desc: Use image node_id 7 for calling a global function with example usage: sort_apply_nodes(inputs, outputs, cmps) and returns: posort