7 ms·
The Python scientific stack, compiled to WebAssembly
- mr_toad 8y agoPart of an effort to make a Jupytr notebook-like environment without relying on server side code. https://github.com/iodide-project/iodide https://github.com/iodide-project/iodide
- xtrapolate 8y ago> "Part of an effort to make a Jupytr notebook-like environment without relying on server side code." So there won't be any server side code, you'd just be downloading the entire Python stack and dependencies every time you want to use this through your browser. This time it will be WASM though, instead of x86/x64/pyc. That we can, doesn't mean that we should.
- m_mueller 8y agoI guess we need an in-browser package management like npm?
- adrianN 8y agoJust compile Debian to WASM and use apt.
- lx3459683 8y agoJust run a browser in your WASM Debian to hit the same page.
- krapp 8y agoIn-browser package management, combined with caching of common dependencies, yes. Like npm? No.
- m_mueller 8y agoWell I'm not really into JS web development, but NPM and a bunch of Node-like extensions would give you compatibility with lots of existing libraries.
- nostalgeek 8y ago> I guess we need an in-browser package management like npm? It exists and it's called bower.
- mdboom 8y agoThe plan is to build something based on conda.
- tomtimtall 8y agoThat would be dumb, so why assume that would happen? You don’t download every picture on every refresh.
- zitterbewegung 8y agoIt would work on a Chromebook and a iPad also. And yes I could pay for a Jupiter notebook hosted on some instance but I dont want to.
- sciurus 8y agoMaybe, but it might require more RAM and CPU horsepower than they provide in order to be usable.
- Vinnl 8y agoWell, you'd download the entire stack indeed - but not every time. Your browser does caching too.
- applecrazy 8y agoPlus, if it’s packaged as a PWA, it can run offline and seamlessly update the runtime in the background using a Web Worker.
- orbital-decay 8y agoIt doesn't share the cache between the sites though. A local installation has only one runtime.
- Vinnl 8y agoAbsolutely; it's pretty much like installing an application that includes all its dependencies. Which, interestingly, is also the direction installed apps are moving towards somewhat, at least on Linux.
- andybak 8y agoI can think of several scenarios where this could be useful.
- sp332 8y agoThere's an advantage even if you're running it locally. Now you can just load up some static HTML + JS files in your browser instead of spinning up a server and then pointing your browser at localhost.
- Waterluvian 8y agoAs long as it's framed properly it can be acceptable. Ie. You get to a page with details and a "load environment" button with progress bars and all. Of course when it's like 50-100MB you wouldn't use it in some cases. But once cached you're golden for your repeat visitor audience.
- krona 8y agoComing soon [...] Plotting using D3 from Python Wouldn't Bokeh make more sense? I'd be very interested in a serverless Bokeh that didn't force me to ditch Python, for example.
- mdboom 8y agoBokeh could probably be done, but most of Bokeh's client/server complexity becomes unnecessary in this execution model. More recently, pyodide has grown full matplotlib support. See, for example, https://iodide.io/pyodide-demo/matplotlib-sideload.html?sideload=https://matplotlib.org/examples/animation/rain.py https://iodide.io/pyodide-demo/matplotlib-sideload.html?side...
- amelius 8y agoIs there a performance hit compared to "native" Python?
- drchickensalad 8y agoWithout a doubt.
- lkbm 8y agoThere's a chart and some discussion here: http://droettboom.com/blog/2018/04/04/python-in-the-browser/ http://droettboom.com/blog/2018/04/04/python-in-the-browser/ (and some followup at http://droettboom.com/blog/2018/04/11/profiling-webassembly/ http://droettboom.com/blog/2018/04/11/profiling-webassembly/ ) TL;DR: pyodide in Firefox was slower than cpython.
- amelius 8y agoThanks. Note that the author of that post said: > UPDATE 2018-04-11: My hunch was wrong, and I was able to get to the bottom of the root cause and significantly speed up these benchmarks. And there's an updated graph here: http://droettboom.com/blog/2018/04/11/profiling-webassembly/ http://droettboom.com/blog/2018/04/11/profiling-webassembly/
- goatlover 8y agoCertainly for anything using Numpy.
- mdboom 8y agoActually, Numpy-using-code is closer to native speeds than pure Python is. The thing that seems to cause a greater gap between wasm and native speeds is lots of Python-level function calls, not the tight C loops that make up much of Numpy.
- nerdponx 8y agoWhat happens to all of the C code in Numpy, and the calls to external libraries like BLAS?
- Scarblac 8y agoIn particular, does this mean Javascript has access to Numpy? Sounds unbelievable, but would be extremely cool.
- mdboom 8y agoYep. You can "import" python objects over to the Javascript side and start using them from there. It's not as pleasant as working with Numpy in Python, of course, due to lack of operator overloading, of course.
- mjs2600 8y agoC can compile to WASM, but I have no clue about external tools like BLAS. I'd assume that things like Numpy are able to work without tools like BLAS, but you might also be able to compile the essential ones to WASM as well.
- azakai 8y agoPython C extensions like NumPy are compiled into shared libraries, and loaded using dlopen() etc. normally by the main compiled Python runtime. (The only special thing here is that all those components are compiled to WebAssembly so it can run on the Web.)
- alexeiz 8y agoThis is great. Many times I wanted to showcase to colleagues who don't use Python how things would work in Python, but they don't have either Python or Jupyter installed. So I had to run Jupyter server in my own environment and give them access to it. This is quite an inconvenience as well as a security risk. Having a completely server-less Python/Jupyter environment should make this kind of showcasing much easier.
- nsriv 8y agoYou could also use a Jupyter notebook uploaded to colab.research.google.com
- existencebox 8y agoI'll chime in to mention notebooks.azure.com as well. (Typical disclaimer, I'm a dev on the azure notebooks team; we just try to solve exactly the scenario GP was asking so I would be remiss to not throw our hat in the ring)
- kowdermeister 8y agoWhy not show them the basics in https://repl.it/ https://repl.it/ or something similar?
- quiq 8y agoDo they have Docker? Jupyter maintains a few docker images with various parts of the scientific stack.
- nategri 8y agoHow and why would they have docker and not python. Docker's like 10 rungs up the skill ladder.
- supermdguy 8y agoIf they're working with a different stack that includes docker?
- acbart 8y agoI do a lot of work with Skulpt, which included adding (somewhat superficial) support for MatPlotLib. You can make line plots, scatter plots, and histograms. It's a pretty cool system, though I will say developing in it isn't always very fun :)
- lx3459683 8y agoI benchmarked this recently. It comes in at 4-10x slower than cpython for random typical use cases on my machine, which is not too shabby at all. The author also states that numpy is slower than it should be due to lack of support for BLAS at this time. The real impressive feat to me isn't hosting jupyter in the browser. It's access to a reasonably fast implementation of numpy in the browser which smokes native JS code for homogeneous array operations. I would love to see a minimalistic WASM implementation of numpy that can seamlessly interop with normal JS. Such a library would open up all sorts of possibilities that aren't currently feasible due to perf reasons.
- makmanalp 8y agoI can't believe I'm saying this but it would be neat to have a browser native BLAS, or absent that perhaps cross-compiled to WASM from a RUST implementation or something! Makes me think of all the demos like the tensorflow playground (dunno if all that happens in the browser or not).
- TAForObvReasons 8y agoPeople are working on the pure JS version of BLAS: https://github.com/jacobbogers/blasjs https://github.com/jacobbogers/blasjs . Hopefully that work leads to best practices and a standard
- singularity2001 8y agoInteresting, how do you derive at "4-10x slower"? Running the exported notebook here takes time py3 python.py real 0m0.145s chrome: load html: 2sec run html: 13sec! That's not 10 times slower, but a 100 times slower! Still good start.
- lootsauce 8y agoI have used Weblas "GPU Powered BLAS for Browsers" for matrix multiply and it smokes! https://github.com/waylonflinn/weblas https://github.com/waylonflinn/weblas
- deleted 8y ago
- X6S1x6Okd1st 8y agoHuh I am getting ``` TypeError: window[s] is undefined ``` with firefox.
- mdboom 8y agoFile a bug over at https://github.com/iodide-project/pyodide/ https://github.com/iodide-project/pyodide/ I'd love to get to the bottom of that.
- sitkack 8y agoThe goal of http://www.graalvm.org/docs/why-graal/#for-ruby-r-or-python http://www.graalvm.org/docs/why-graal/#for-ruby-r-or-python is to run scipy.