code: def test_sort_apply_nodes():
      x = tensor.matrix("x")
      y = tensor.dot(x * 2, x + 1)
  
      def str_cmp(a, b):
          return cmp(str(a), str(b))  # lexicographical sort
  
      nodes = sort_apply_nodes([x], [y], cmps=[str_cmp])
  
      for a, b in zip(nodes[:-1], nodes[1:]):
          assert str(a) <= str(b)
  
file_path: Theano/theano/gof/tests/test_sched.py
imports: from __future__ import absolute_import, print_function, division
  from theano.gof.sched import make_dependence_cmp, sort_apply_nodes, reverse_dict, _toposort, posort
  from theano import tensor
  from theano.gof.graph import io_toposort
  from theano.compat import cmp
label_desc: Use image node_id 2 for calling a global function with example usage: test_sort_apply_nodes() and returns: cmp