Live data from Hacker News

Why physicists still use Fortran (2015)

moreisdifferent.com

251–260 of 300 posts

Re: Why physicists still use Fortran (2015)

#251

Earlier quoted context omitted.

Trusting legacy code with few users is a dangerous proposition. My roommate was given some "state-of-the-art" code and told to run simulations with it. The only graphical output was postscript (for some reason), so every frame was 150 MiB and took minutes to dump - so usually, this was only done at the end to show the result. I managed to hack in a step which just dumped the memory of resulting frame to a file, and t…

Another problem is that most people who wrote this code aren't programmers - they don't write clean code, no tests, etc. They don't really know those are important. Sometimes the code that is used and updated for years looks like a dirty prototype. I don't know what can be done about it except hiring programmers to write code, which wouldn't be either easy or cheap

Well, I guess one moral of the story is that doing image manipulation is easier in Python than Fortran, so it's again using the right tool for the job. And I think the push for Physicists to use Python if possible is good, as the learning curve is less steep. And once you have that tool at your disposal, you might use it more often (instead of Excel).

I can see many projects being improved by providing a Python pre-processor that writes out e.g. a binary config file, the hard-code Fortran/C simulation code reads that, and spits out the simulation results, and then having a Python post-processor that does the pretty stuff at the end.

Academically, it seems that pairing CS undergrads with Physics undergrads to do e.g. a molecular dynamics (MD) course would be cool. The Physics behind MD isn't too hard, and given the right parameters the programming part would be manageable. Then again, CS undergrads aren't necessarily great programmers either...

Clean code and tests are overrated. Version control and a big eco-system is underrated. It's like maths, physicists don't understand maths, they just use it like a carpenter uses a nail without understanding metallurgy, or a programmer uses a CPU without understanding solid-state physics. And that's okay.

Re: Why physicists still use Fortran (2015)

#252
post #26

Earlier quoted context omitted.

Yep. Most of my programming classes were either in pascal or c when I was in undergrad, but in my physics courses, all the way through my graduate education, I used FORTRAN. It's because physics doesn't change that much over the years, FORTRAN code that is time-tested and that works exists and there's no need to re-invent the wheel in another language when more interesting and important problems exist to solve.

David Baker's Rosetta code, which made him a pile of money, is IMO a spectacular example of craptastic C++ written by people who really didn't understand C++ but didn't let that deter them from using every single feature of the language, badly. Some years back we tried to port it to CUDA but there were so many levels of indirection, dereferencing, and virtual functions that it was nearly impossible to make any progre…

Oh, you're that Scott Grand? Allow me to thank you for the work you did on pmemd.cuda, my old research group wouldn't be where they are now without you.

Re: Why physicists still use Fortran (2015)

#253
post #89

So the article basically says: 1) Some stuff is already written in Fortran so they don't want to rewrite that. I dig it. 2) It's fast (except C sometimes) but easier to write than c. Like 100x faster than python. I'm not sure about number two. With the gpu processing revolution wouldn't a python/TensorFlow stack be faster than Fortran? Am I missing something? I remember talking to someone who had worked heavily on at…

A lot of science is done with GPUs ... in FORTRAN and C++. I believe an n body simulation in GPUs is what started the idea of using GPU for general computation.

I would be extremely surprised if you could get similar or better predictions for the same amount of computation from an off the shelf CNN than from a carefully tuned physical model. (I would love to see counterexamples). Even then I would question how well it extrapolates; you generally have a very good idea of where your physics simulation will break down.

I think your friend is right; the physics community can't afford to throw away as much code as the tech community. I wouldn't spend years building a simulation in tensorflow because it will likely be obsolete before I finished (leading to the same problems as FORTRAN but increasing the amount of dependencies).

In any case, if it works well enough it's not going to be rewritten.

Eventually ML will become part of physics simulations, but I don't think there will be easy wins in these well developed areas.

Re: Why physicists still use Fortran (2015)

#255
post #72

Earlier quoted context omitted.

What's the code do? [physics grad level description would be fine] It must surely be generic equipment management, you're not running experiments in physics that are > 30 years old, surely?

Started in the 80s doesn't mean the code is 30 years old, as they keep adding to it and modifying it in Fortran. Plus most of the analysis part is probably just math routines that don't need modification ever after.

Doesn't mean it isn't c.37 years old either ... I think we need specifics to progress this conversation usefully.

Re: Why physicists still use Fortran (2015)

#256
post #50

Speaking from a government contracting point of view: Nobody is going to pay you to rewrite existing code that's already working. Nobody. The customer doesn't give a flying shit about the implementation. He'd be happy with a box of diodes as an implementation, as long as it worked and came in on time and on budget. When you're writing up your proposal for a contract or a grant, the theme should always be that you're…

People don't tend to write tests for their Fortran code so the assumption that its already working and the numbers coming out are correct is a matter of faith. But yes, no one sees it this way.

Writing tests for the the kind of numerical code that FORTRAN is usually used for is hard. Sometimes there is no direct way of testing it because if you knew any of the results already you wouldn't need to run the simulation in the first place. Quite often, the best that you can do is proper sanity checks like conservation of energy and momentum or things like that.

Re: Why physicists still use Fortran (2015)

#257

"Professors usually have this legacy code on hand (often code they wrote themselves decades ago) and pass this code on to their students. This saves their students time, and also takes uncertainty out of the debugging process." This is so true. I'm a PhD student in physics using Fortran for pretty much that reason. At the start of my PhD, in response to my supervisor telling me I should learn Fortran to modify our cu…

Trusting legacy code with few users is a dangerous proposition. My roommate was given some "state-of-the-art" code and told to run simulations with it. The only graphical output was postscript (for some reason), so every frame was 150 MiB and took minutes to dump - so usually, this was only done at the end to show the result. I managed to hack in a step which just dumped the memory of resulting frame to a file, and t…

They where not back checking against real word experiments?

Re: Why physicists still use Fortran (2015)

#258
post #169
post #157

Earlier quoted context omitted.

I have to be honest with you, as someone who writes in both C++ and Python, I really do not see Python being more of a candidate than C++ for displacing Fortran. Can you clarify why you think Python might be able to do it? For scientific computation with high performance requirements, Python is not competitive with Fortan or C++. For work that continues to happen in Fortran due to "academic inertia", my impression (a…

A disclaimer -- I do not work in physics, however a couple of recent physics Ph.D. that I work with expressed similar views. Speed is not nearly as important now as it was 10-15 years ago. A typical scientist's worstation has 20 CPU cores. If I want to use 100 CPUs for a few days, it is trivial and 1000 is easy to get. Thus the fact that Python is slow(er) does not bother me unless I am setting up something major . W…

So more cores means you can simulate to a higher resolution

Re: Why physicists still use Fortran (2015)

#259

Earlier quoted context omitted.

Another problem is that most people who wrote this code aren't programmers - they don't write clean code, no tests, etc. They don't really know those are important. Sometimes the code that is used and updated for years looks like a dirty prototype. I don't know what can be done about it except hiring programmers to write code, which wouldn't be either easy or cheap

Well, I guess one moral of the story is that doing image manipulation is easier in Python than Fortran, so it's again using the right tool for the job. And I think the push for Physicists to use Python if possible is good, as the learning curve is less steep. And once you have that tool at your disposal, you might use it more often (instead of Excel). I can see many projects being improved by providing a Python pre-p…

Why not using both ? You can reuse existing fortran code withing Python, and benefit from the prior experience and speed while enjoying the qualities of Python.

There are several ways to bind Python and fortran together. E.G http://arogozhnikov.github.io/2015/11/29/using-fortran-from-...

Re: Why physicists still use Fortran (2015)

#260

Earlier quoted context omitted.

People don't tend to write tests for their Fortran code so the assumption that its already working and the numbers coming out are correct is a matter of faith. But yes, no one sees it this way.

Writing tests for the the kind of numerical code that FORTRAN is usually used for is hard. Sometimes there is no direct way of testing it because if you knew any of the results already you wouldn't need to run the simulation in the first place. Quite often, the best that you can do is proper sanity checks like conservation of energy and momentum or things like that.

Yes, it's hard. But without an automated test suite checking the numbers coming out then any change to the code could introduce numerical instability.
Post reply on HN