code: def log_thunk_trace(value, f=sys.stderr):
      """
      Log Theano's diagnostic stack trace for an exception
      raised by raise_with_op.
  
      """
  
      # in future, consider accepting `write` as arg rather than file
      # to support writing to a logger
      def write(msg):
          print("log_thunk_trace: %s" % msg.strip(), file=f)
  
      if hasattr(value, "__thunk_trace__"):
          trace2 = value.__thunk_trace__
          write("There was a problem executing an Op.")
          if trace2 is None:
              write("Could not find where this Op was defined.")
              write(
                  " * You might have instantiated this Op "
                  "directly instead of using a constructor."
              )
              write(
                  " * The Op you constructed might have been"
                  " optimized. Try turning off optimizations."
              )
          elif trace2:
              write("Definition in: ")
              for line in traceback.format_list(trace2):
                  write(line)
              write(
                  "For the full definition stack trace set"
                  " the Theano flags traceback.limit to -1"
              )
  
imports: from __future__ import absolute_import, print_function, division
  from copy import copy, deepcopy
  from sys import getsizeof
  import sys
  import traceback
  import numpy
  import theano
  from theano.compat import izip
  from six import reraise
  from six.moves import StringIO
  from theano.gof import utils
  from theano.gof import graph
  from theano.gof.type import Type
  from .utils import undef
label_desc: Use image node_id 1 for calling a global function with example usage: log_thunk_trace(value, f) without return types