LFortran + Jupyterlite + Fplotlib

Since LFortran now works in Jupyterlite and fplotlib is now very usable, I had to take advantage of that. I compiled fplotlib alongside other modules, included it in the WASM host environment, and now have 3 notebook drafts(!) using it. Some of it is a bit hastily put together, but I was keen to just go ahead and do it.

Thanks @certik, @hkvzjal, and all others who worked on any of it.

5 Likes

And Anutosh !

There is a really annoying bug that the kernel takes several minutes to load for me, and I haven’t had time to fix it yet. But once it loads, it works! I see some spurious warning when plotting, but we’ll iron everything out. If you can isolate all these bugs and create issues, we’ll fix it quickly.

The plots look great! Just like matplotlib.

Can you document somewhere how you put it together? We need to streamline it and make it super simple for anyone to ship their codes + dependencies as jupyterlite wasm static pages. And we need to make everything fast, but we will. Did you compile LFotran in Release mode or Debug mode?

2 Likes

I haven’t changed much, so it’s compiled in Debug mode. I’ll play with it some more and try to isolate/report problems I run into. Basically, I just:

  • Created separate folders for the notebooks and the fplotlib source files,
  • Added relative paths to the notebooks to [feature.lite.tasks.lab-build] in pixi.toml in the lfortran root folder (appending --contents ../c3/source/wildfire_euler/fortran/wildfire_euler_f90.ipynb, for example),
  • Added compilation instructions for all fplotlib modules in wasm-build0.sh in correct order. That’s not ideal or quick, of course.

So it’s a bit fiddly. Ideally, it would be as simple as adding a folder for notebooks and external modules. I think it would lower the barrier significantly if people didn’t have to think about what’s actually happening in the process.

1 Like

Can you submit a Draft PR with what you have?

I’ll figure out how to polish it and clean it up. Yes, you definitely need to compile in Release mode, so that it runs faster.

Couldn’t FPM be used in this process to manage the packages? I’m thinking about using the local registry functionality that allows declaring where do packages exist locally with config.toml file and it will take care of building

3 Likes

Yes, we have allow using fpm, that’s obvious, since if you want to include an fpm package with lots of dependencies, we want to piggy back on fpm. We can implement any feature we want in fpm to make this easy.

1 Like

Using fpm in the wasm-build script with the same version of lfortran was my first go-to. I ran into some issues and just wanted to see some results quickly, so I did it rather inelegantly instead.

I can create a PR to show where I changed what.

2 Likes

I submitted a draft PR for documentation (none of this is a real solution; it’s just brute-forcing it).

1 Like

Got it — you simply include the precompiled .mod files as we do with the other demo files. This is actually good and I am happy it works!

Probably the next step is to now get it working with fpm, and fix all bugs.

2 Likes