there are projects like Black and Pyjion that provide online playgrounds. I use the Black playground very often (https://black.vercel.app/) and find it very useful.
I haven’t used Pyjion’s one (https://live.trypyjion.com/) but it seems to follow the same idea as https://godbolt.org/, to see how certain code would be compiled.
I was wondering if others think this could be a useful idea for Numba. Being able to easily switch between Numba IR, LLVM IR, ASM, CFG view, all with a nice format could be interesting.
@stuartarchibald has wanted something like this for a long time! The main challenge is figuring out the details of how to safely host a service that compiles arbitrary, untrusted code from random people on the Internet. Even if we don’t run the resulting function, we should not assume that Numba is secure when compiling untrusted input.
As @sseibert notes, for a long time tools along these lines have been something I’ve wanted and have been building various prototypes for. The interesting thing with Python is that there’s a wealth of tools to help with visualisation that are perhaps less easily accessible from lower level source languages/compilers.
One small prototype of mapping python to (dis)assembly and classifying the instructions can be seen here: Compiler explorer for Numba · Issue #5769 · numba/numba · GitHub another thing that has actually made it to production is the enhanced visualisations available in the dispatcher object’s
inspect_cfg method as demonstrated in numba-examples/Numba_052_refpruner.ipynb at master · numba/numba-examples · GitHub
These prototypes are things I work on on-and-off, a lot of it is just figuring out what it is that is useful and adding APIs to Numba to expose such things. I generally use holoviz panel (GitHub - holoviz/panel: A high-level app and dashboarding solution for Python) to build the tools against these APIs and do so inside notebooks. One option to host something could be just to have the notebook(s) in GitHub - numba/numba-examples: Example Numba implementations of functions which would make them accessible via binder.
thanks for your replies.
@sseibert I figured that running the function is not a good idea, but would it also be a problem to just compile it? Both trypyjion and godbolt seem to be doing it.
@stuartarchibald a prominent link to a binder notebook that has a “paste your code here” section plus a lot of analysis already coded would help a lot. I use Numba every week and even I don’t know everything that’s available and for that which I do know, it takes me a while to set everything up to work on a specific issue.
The APIs that have been added are great, and now the next problem is one of visibility and accessibility.
I’m very comfortable with notebooks (less so with websites), I’ll try to put something together based on the last release notes.
Compiling arbitrary code is definitely a problem, but it is a risk that can be mitigated. (You don’t normally care if a JIT compiler can be exploited in the compilation phase because you are about to run the code, which implies significant trust.) It just requires some thought. I would not want to throw a system on a trusted network at the task, for example. Running things in Binder outsources this problem to someone else, so that’s a good place to start!