LFortran: When is the next release? Can I get a "WebAssembly" app?

Early next year I plan to do a mini “intro to Fortran” course for the grad students in my group. I would love to use LFortran for this. I just have two questions:

(1) The web app on the LFortran website supports arrays. The LFortran that I installed with Conda does not. Do I just need to wait for the next release? If so, when is that likely to happen?

(2) I like the Jupyter notebook that came with LFortran, but I like the web app on the LFortran website better. That one lets me show program and module. Is there a way that I can get a web app like that one?

Thanks.

Arrays are supported. Can you give a short example that doesn’t seem to work? Also, what version did you install?

1 Like

This is interesting… When I set out to write a short sample I discovered that it is a bug in the Jupyter notebook kernel, but not LFortran itself.

Ok. So I start a Jupyter notebook and I type in the following:

real :: x  ! Ok.
x = 5.0    ! Ok.
real :: y  ! Ok. I can declare more variables.
y = 2.5    ! Ok.
real :: a(10) ! ERROR

The error reads

Kernel Restarting:
The kernel for Test_LFortran.ipynb appears to have died. It will restart automatically.”

The error in the terminal reads:

ERROR: received bad message: No such comm registered: b2f636d2-67fc-4cb3-a724-13ecaed50955
Message type: comm_msg

Incidentally, I discovered I didn’t have clang installed and I needed it. I have no idea how the Jupyter notebook was able to run without clang installed. But when I tried to compile a program with lfortran example.f90, I got an error that I didn’t have Clang. I installed Clang, and then the program (with an array) compiled and ran correctly.

I think this has to be done carefully, not to alienate students that potentially already have experience with other programming languages or tools.

When Julia was launched initially in 2012, I remember reading their “manifest”: Why We Created Julia. As good as it sounded, I rewrote one of my Fortran programs in Julia, only to discover it was a factor of 15-20 times slower. (I’m sure that today, a capable Julia programmer would get my program running on GPU in no time.) In any case I wasn’t convinced, and later I read stories that things were prone to breakage, and I think one of the MIT lecturers used the analogy of Julia being the “wild west”. In the end I decided it was not worth my time. The stable version, 1.0.0, arrived in 2018.

What I’m trying to say is you shouldn’t overpromise.

On the other hand I think WebAssembly could become a fantastic platform for a certain class of scientific and engineering applications, including some written in Fortran. There is some overlap between Fortran and the “official” WebAssembly Use Cases. The obstacle as I see it for myself (and I suppose other Fortran programmers too) is how to do the “Web” part, i.e. bind the Fortran program (compiled to WebAssembly) to the page elements, be it a simple terminal, or a GUI of sorts.

4 Likes

Ok. So you’re thinking in terms of a student thinking “Oh, this is just as easy as Python/Jupyter notebooks” only to discover that LFortran isn’t even beta yet?

I was planning to just say that “the Jupyter notebook that we’re using is from a project that’s in development and it doesn’t support all the features of Fortran, but it has just enough features for today’s tutorial”.

But perhaps I should just use GFortran.

1 Like

I guess it depends what type of class of students it is.

I once taught a tutorial on Python and Jupyter, which started with me giving the the students a sheet of exercises they could do in the REPL (starting from simple arithmetic expressions, creatings lists, printing, and just getting used to the Jupyter UI). One of the students approached me in the break, terrified, that I expect them to just start using the REPL without any proper lecture beforehand. (This was a class of food process engineers.)

As long as you test the elements you need before-hand that sounds reasonable to me.

Although the times I’ve been able to trigger internal compiler errors, was always when I didn’t actually know the syntax. So in this sense a fresh class of students might as well be LFortran’s best friend :slight_smile:

The Jupyter kernel has some bugs that we will fix later. First we are focusing on compilation to binaries, locally using LLVM. You can use Conda package for that. Our status is still in alpha, meaning it is expected to break. You can follow our progress at https://lfortran.org/, we are at 4/10 towards beta. Beta meaning it will be expected to work on your code. That being said, depending on which features you use, you might very well find the current alpha version of LFortran very usable already today. It does compile all of dftatom for example and that code uses a lot of Fortran and a lot of arrays and for numerical computing that might be enough.

Regarding what @ivanpribec said about alienating new users and students: I agree. I would recommend using the most mature open source compiler, which is GFortran. And then you can say if you are adventurous, you can try LFortran, and every bug you discover should be celebrated like a Christmas present and reported with joy.

Regarding our plans, here they are, in terms of priority:

  • Get LFortran running locally to compile every project to a binary and work correctly
  • Get the interactive version (Jupyter kernel) working for all of Fortran
  • Get the online WASM version (https://dev.lfortran.org/) working for all Fortran features
  • Create a new WASM based kernel that runs fully in the browser and works with JupyterLite (GitHub - jupyterlite/jupyterlite: Wasm powered Jupyter running in the browser 💡), that will allow you to use Fortran in the browser inside Jupyter (lite) without needing to host a server, just a static page is enough. For teaching students this will be the most robust, fastest and easiest solution. If anybody is interested in developing a prototype of this, let me know.
4 Likes

How about that WebAssembly page? Can I get one of those? I actually like the WebAssembly page better for my needs and can verify that it supports arrays.

Are you talking about https://dev.lfortran.org/ ? Yes, this page doesn’t use the Jupyter kernel feature, it runs LFortran fully in WASM and uses our WASM backend (not LLVM) to compile your code to WASM and run it. I have to warn you that our WASM backend is not as advanced as our LLVM backend, so you will discover more limitations.

Yes, you can either use the link above, or even host/modify your own version, the source code is here:

GitHub - lfortran/lcompilers_frontend: The sources of the web LFortran GUI interface

1 Like

Thanks! I got it working. I had some trouble, actually, so I just want to let you know about it:

% ./build.py
+ curl "https://lfortran.github.io/wasm_builds/release/c82debe8b/lfortran.js" -o public/lfortran.js
...
+ curl "https://lfortran.github.io/wasm_builds/release/c82debe8b/lfortran.wasm" -o public/lfortran.wasm
...
+ curl "https://lfortran.github.io/wasm_builds/release/c82debe8b/lfortran.data" -o public/lfortran.data
...
+ npm run build

> lcompilers_frontend@0.1.0 build
> next build

/tmp/build-0cf654b0.sh: 1: next: not found
Command failed.

I don’t know why that happened, but I tried again as root, and that seemed to help. Next error was that I don’t have npm, so I installed it and tried again. Then I got an error that I don’t understand:

% sudo ./build.py     
+ curl "https://lfortran.github.io/wasm_builds/release/c82debe8b/lfortran.js" -o public/lfortran.js
...
+ curl "https://lfortran.github.io/wasm_builds/release/c82debe8b/lfortran.wasm" -o public/lfortran.wasm
...
+ curl "https://lfortran.github.io/wasm_builds/release/c82debe8b/lfortran.data" -o public/lfortran.data
...
+ npm run build

> lcompilers_frontend@0.1.0 build
> next build

sh: 1: next: not found
Command failed.

I have no idea what that means. I googled for the error and someone on StackOverflow had suggested running sudo npm install, so I did that. I have no idea what I did, but that seemed to move things forward a bit:

> lcompilers_frontend@0.1.0 build
> next build

Browserslist: caniuse-lite is outdated. Please run:
  npx browserslist@latest --update-db
  Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
info  - Checking validity of types  
error - ESLint: Failed to load plugin '@next/next' declared in '.eslintrc.json » eslint-config-next/core-web-vitals » /home/daniel/Volatile/Weave/lcompilers_frontend/node_modules/eslint-config-next/index.js': Unexpected token '.' Referenced from: /home/daniel/Volatile/Weave/lcompilers_frontend/node_modules/eslint-config-next/index.js
Browserslist: caniuse-lite is outdated. Please run:
  npx browserslist@latest --update-db
  Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
info  - Creating an optimized production build  
info  - Compiled successfully
info  - Collecting page data  
info  - Generating static pages (3/3)
info  - Finalizing page optimization  

Page                                       Size     First Load JS
┌ ○ / (1851 ms)                            39.1 kB         197 kB
├   /_app                                  0 B             158 kB
└ ○ /404                                   193 B           158 kB
+ First Load JS shared by all              158 kB
  ├ chunks/framework-4556c45dd113b893.js   45.2 kB
  ├ chunks/main-fc7d2f0e2098927e.js        28.7 kB
  ├ chunks/pages/_app-67a23d0d9717a0da.js  82 kB
  ├ chunks/webpack-6b5bb26bc3b9b58d.js     1.84 kB
  └ css/84c162364c63a3e3.css               67.3 kB

○  (Static)  automatically rendered as static HTML (uses no initial props)

Notice that there is an “error” line up there. I don’t know what ESLint is, but I assume it must be a linter for EcmaScript. I ignored the error and tried to run npm run dev and it ran.

1 Like

@danielc great, I am glad you got it working. It’s deployed automatically by the CI: lcompilers_frontend/.github/workflows/deploy.yml at 7ca67f7906a6a68db6884fa11304c6425c112393 · lfortran/lcompilers_frontend · GitHub, so you can always consult that to get working instructions.

In order to get smoother build experience, follow the README, which uses Conda to setup an environment that should just work. If not, go ahead and report a bug, or send us a PR with a fix.

Wait… that’s not what I did?

I was literally following the steps in the README, right at the top, under the heading “Getting Started”:

conda env create -f environment.yml
conda activate npm
npm install
./build.py
npm run dev
# ... open http://localhost:3000 ...

Those are the steps in the README, no?

1 Like

Yes, if you did the conda activate parts, then it’s correct. I didn’t see those in your post. Also you should not need sudo.

Go ahead and open up an issue with the errors that you are getting. Either our instructions are incorrect or there are some bugs in the build system on some platforms.

Yeah. That wasn’t great either. But the ./build.py step and the npm ... steps would not work without sudo.

Sure. I’ll do that when I get home so I can copy-paste the output.

1 Like