Differentiable Fortran with LFortran and Enzyme

It was on Hacker News frontpage:

@certik

4 Likes

I’m not familiar with Tesseract and Enzyme and I only skimmed this post. Dion @dionhaefner does outstanding work and has posted here before about his JAX ocean model Veros.

3 Likes

Yes, I am super happy that LFortran worked well for them. We are now very close to beta, possibly we could even declare it now, but I like to be conservative and want to get to the point that any code I try just works. Lots of codes now just work (so we stopped publishing a blog post for each one we get working), but many still don’t, so we’ve been quiet the last couple months, busy compiling codes and fixing bugs. As far as I know, all Fortran features are implemented except coarrays (in progress) and length PDT (we have kind PDT).

Probably the best way to tell we are in beta quality is when users generally report that things work for them, such as the blog post above.

7 Likes

If I can say something slightly OT (hoping to just send a feedback to @certik and not start a discussion) I would really like to see LFortran compile NetCDF, that is really the terrible dependency of every ocean/atmosphere model, that kind of blocks me from testing LFortran with my work (though I have never tried, maybe it’s easier than what I expect)

2 Likes

Yes. For my code (around 100000 loc modern Fortran) the remaining problem is the fringe case reported three years ago in post.

@mhulsen can you try again? I can’t reproduce the issue, it works for me in LFortran.

1 Like

Sure, here is the issue for it: Compiling netcdf-fortran · Issue #3883 · lfortran/lfortran · GitHub, I’ll get it fixed, I can see there are some failures. I’ll let you know when it’s done.

3 Likes

I’ll try again, but I can only test the version in Fedora Rawhide, which is the github released version 0.63 from a few months ago.

We’ll make a new release soon. Btw, I noticed the netcdf exposes a similar bug that you hit, and I just fixed it. Are you compiling netcdf also? If so, let me fix netcdf first and then I can ping you to try it.

1 Like

No, I am not compiling netcdf. I’ll test my code when the new release is in Fedora Rawhide.

1 Like

Ok, I have netcdf building locally (Build netcdf by certik · Pull Request #12252 · lfortran/lfortran · GitHub), now I just need to fix all tests to pass (currently 76% pass), then clean everything up and get PRs merged.

5 Likes

If LFortran shipped with a NetCDF build with it, you would make many Earth scientists happy, if not convert them immediately. (Not saying you should do it, or even that it’s a good idea :slightly_smiling_face:).

I think we should aim higher: ship everything with LFortran. So you need a package manager. And by luck we have one (fpm), so I am hoping just integrating both LFortran and netcdf to work well with fpm should take care of this issue?

2 Likes

I have netcdf building and all tests passing now with LFortran for me locally: Get netcdf working by certik · Pull Request #12260 · lfortran/lfortran · GitHub, just need to cleanup the PR and get it in.

6 Likes

Some time ago I was working on a NetCDF wrapper that was kind of following the style of stdlib, perhaps I should resuscitate that project and propose it to the community (in a dedicated topic, pinky promise) so to ship not only the library but also a modern wrapper with it.

1 Like

Version 0.64 is now available in Compiler Explorer.

1 Like