code: def tensor_lib_entry_frame(exc_traceback):
      """
      Don't trace into internals of numpy/torch/tensorflow/jax; we want to reset frame
      to where in the user's python code it asked the tensor lib to perform an
      invalid operation.
  
      To detect libraries, look for code whose filename has "site-packages/{package}"
      or "dist-packages/{package}".
  
      Return last-user-frame, first-tensor-lib-frame if lib found else last-user-frame, None
  
      Note: Sometimes operators yield exceptions and no tensor lib entry frame. E.g.,
      np.ones(1) @ np.ones(2).
      """
      tb = exc_traceback
      # import traceback
      # for t in traceback.extract_tb(exc_traceback):
      #     print(t)
      packages = ["numpy", "torch", "tensorflow", "jax"]
      dirs = [os.path.join("site-packages", p) for p in packages]
      dirs += [os.path.join("dist-packages", p) for p in packages]
      dirs += [
          "<__array_function__"
      ]  # numpy seems to not have real filename
      prev = tb
      while tb is not None:
          filename = tb.tb_frame.f_code.co_filename
          reached_lib = [p in filename for p in dirs]
          if sum(reached_lib) > 0:
              return prev.tb_frame, tb.tb_frame
          prev = tb
          tb = tb.tb_next
      return prev.tb_frame, None
  
imports: import os
  import sys
  import traceback
  import inspect
  import hashlib
  from pathlib import Path
  import matplotlib.pyplot
  import tsensor
label_desc: Use image node_id 4 for calling a global function with example usage: tensor_lib_entry_frame(exc_traceback) and returns: prev,  None, prev,  tb