question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fail when using taichi (Exception: Picked an invalid source context)

See original GitHub issue

Your package is so useful that I stop using ipython anymore. Thank you!

I start using taichi recently and I encounter an error, the minimal sample is list below.

import stackprinter
import taichi as ti

stackprinter.set_excepthook(style="darkbg2")


@ti.kernel
def my_kernel() -> float:
    return "22"


my_kernel()

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ckndcommented, Mar 17, 2021

Interesting, in your second example, the troubled frame looks like this:

  • we’re in the inner function in your example above, soframe.f_code.co_name == wrong_syntax_in_taichi
  • frame.f_code.co_firstlineno is 8, which looks correct
  • frame.f_lineno is 13 which is a blank line 🤔

I could extend my workaround and guess a different lineno here too – may still be better than crashing?

1reaction
ckndcommented, Mar 16, 2021

I think I found something. For some reason, the line number that the python interpreter reports on that particular frame is before the beginning of the code scope of that frame (as discovered by the inspect module, which ultimately relies on frame.f_code.co_firstlineno i.e. ultimately the interpreter contradicts itself).

I have a workaround #46, which detects this situation, prints a warning and moves the displayed lineno to the beginning of the frame’s available source block. Of course I’m only half-happy with that, but it fixes the crash and seems like reasonable behavior.

(Interestingly, I could only reproduce this bug with taichi so far, so I assume it’s an edge case where the interpreter confuses itself during the heavy introspection & dynamic rewriting of the stack that taichi seems to be doing.)

If you’re able to test the workaround locally (by doing pip uninstall stackprinter; pip install -e /path/to/a/clone/of/this/repository), I’d be grateful to hear how it goes on your real code!

On my side, I can run your test now and get a traceback with all sorts of stuff in it 🙂 (Note the “problematic” frame in the middle)

     taichi_kernel.define = <bound method PyCapsule.define of <taichi_core.KernelProxy o
                             bject at 0x10d184830>>
     taichi_ast_generator = <function 'Kernel.materialize.<locals>.taichi_ast_generator'
                              kernel.py:357>
    ..................................................

File "/Users/c/.py3/lib/python3.8/site-packages/taichi/lang/kernel.py", line 365, in taichi_ast_generator
    357  def taichi_ast_generator():
 (...)
    361          raise TaichiSyntaxError(
    362              "Kernels cannot call other kernels. I.e., nested kernels are not allowed. Please check if you have direct/indirect invocation of kernels within kernels. Note that some methods provided by the Taichi standard library may invoke kernels, and please move their invocations to Python-scope."
    363          )
    364      self.runtime.inside_kernel = True
--> 365      compiled()
    366      self.runtime.inside_kernel = False
    ..................................................
     TaichiSyntaxError = <class 'taichi.lang.exception.TaichiSyntaxError'>
     self.runtime.inside_kernel = True
     compiled = <function 'my_kernel' test_taichi.py:7>
    ..................................................

File "test_taichi.py", line 7, in my_kernel
    6    # // Stackprinter: This frame reported a line number outside its reported code scope. Line 6 reported, but guessing 7 instead.
--> 7    def my_kernel() -> float:
    8        return "22"
    ..................................................
     float = <class 'float'>
    ..................................................

File "/Users/c/.py3/lib/python3.8/site-packages/taichi/lang/expr.py", line 33, in __init__
    10   def __init__(self, *args, tb=None):
 (...)
    29                   if isinstance(arg, np.ndarray):
    30                       arg = arg.dtype(arg)
    31               except:
    32                   pass
--> 33               self.ptr = impl.make_constant_expr(arg).ptr
    34       else:
    ..................................................
     self = <ti.Expr>
     args = ('22', )
     tb = None
     arg = '22'
     np.ndarray = <class 'numpy.ndarray'>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced guide to creating IntelliJ IDEA plugins
Advanced guide to creating JetBrains Platform plugins: VFS, PSI, Kotlin UI DSL, Dialog, Tool window, List, Swing UI and layout managers, ...
Read more >
Adding Core Data to existing iPhone project - Stack Overflow
When you click on this Model object you will see the interface to add the Entities to your project with any relationships you...
Read more >
PRISMA 2020 explanation and elaboration: updated guidance ...
PRISMA 2020 is intended for use in systematic reviews that include synthesis (such ... Specify the primary source of funding for the review....
Read more >
Nmap Change Log
Hundreds of commercial products now use Nmap for network discovery tasks like port scanning, host discovery, OS detection, service/version detection, and of ...
Read more >
Exercise Standards for Testing and Training - AHA Journals
ECG monitoring is not routinely done with this testing, thus limiting its diagnostic accuracy. Exercise Test Supervision and Interpretation. Exercise testing ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found