16 ms·
Fortran vs Python: The counter-intuitive rise of Python in scientific computing (2020)
- zaikunzhang 3y agoOriginal post at https://cerfacs.fr/coop/fortran-vs-python https://cerfacs.fr/coop/fortran-vs-python Contents: - “Python, a slower language” - “more and more” - “time-critical scientific computations” - Is Python ever better suited? - User story : same author, two languages - Speed vs agility - Takeaway
- gjvc 3y agoTooling is the thing. To keep older languages popular with people new to the industry (and who never get properly introduced to older tools) it would take someone like JetBrains need to create COBOL and Fortran IDEs. People will always go for shiny and new, like it or not.
- esafak 3y agoI think free is the thing. Python replaced MATLAB and Mathematica, not COBOL or Fortran, which was already out.
- consp 3y agoAt my alma mater it also replaced all existing programming courses for non ee/cs students, replacing Java and Delphi still lingering around from days past. Multi platform support is very important which is one of the reasons to use java. This has the big advantage that in multi disciplinary subjects everybody knows something of the programming language involved. And of course it saves on the insane licensing costs since Mathematica is no longer required in all student software packages (MATLAB still is afaik).
- deleted 3y ago[deleted]
- odyssey7 3y agoConsider that JavaScript is more multi-platform than Java, but is also dynamically typed and interpreted, just like Python.
- cmiles74 3y agoI'm not sure what "more multi-platform" means here. It's been a long time since I've run into an environment that didn't have easy access to Java and it's tools.
- qsort 3y agoI agree with TFA, it's the ecosystem. You're not entirely wrong that free is a component, because impossibly draconian licensing terms means no ecosystem. I still maintain that Python, when evaluated strictly on its merits as a programming language, is the most ass of the "scripting" bunch, but its ecosystem is such that it more than makes up for the difference and I always end up using it for side projects or personal stuff.
- miohtama 3y agoDropbox, Instagram, are largely written in Python. Python is very popular in backend too.
- analog31 3y agoI think that it wasn't so much a matter of one replacing another. My interpretation of the history is that Matlab had steady usage, but within relatively mature domains such as traditional engineering. Meanwhile, Python grew in fields that had no prior loyalty to Matlab, such as physics, data science, ML, the life sciences, children and hobbyists, and software development. The "free" thing is important, because programming tools have all migrated to the open source model. No professional coder is willing to work on paid tools today. If scientists have a basic awareness of their career options, they will borrow tools from the software development world, and not from the engineering world. Those tools are all free. Also, free software changes how you use it. I install a complete Python toolchain (up to and including Jupyter Lab) on every computer that I touch: In the office, the labs, and at home. This allows me to truly use Python as my brain. No software budget is lavish enough to pay for as many "licenses" as I use in a day.
- nephanth 3y agoMatlab also does have relatively bad tooling, though that is partially due to it being non-free (for ex the library installation is so cumbersome because of all the licensing stuff)
- PartiallyTyped 3y agoPython isn't "shiny and new". Python is "almost" ancient. Julia is "new", but also not as easy to use. It isn't about that kind of tooling, but it is about ease of use, and having access to tools that deal with silly things while you do the actual science. Python, first appearance: 20 February 1991; 32 years ago [1] Rust, first appearance: May 15, 2015; 8 years ago [2] Julia, first appearance: 2012; 12 years ago [3] Go, first appearance: November 10, 2009; 14 years ago [4] Java, first appearance: May 23, 1995; 28 years ago [5] Javascript, first appearance: December 4, 1995; 28 years ago[6] [1] https://en.wikipedia.org/wiki/Python_(programming_language) https://en.wikipedia.org/wiki/Python_(programming_language) [2] https://en.wikipedia.org/wiki/Rust_(programming_language) https://en.wikipedia.org/wiki/Rust_(programming_language) [3] https://en.wikipedia.org/wiki/Julia_(programming_language) https://en.wikipedia.org/wiki/Julia_(programming_language) [4] https://en.wikipedia.org/wiki/Go_(programming_language) https://en.wikipedia.org/wiki/Go_(programming_language) [5] https://en.wikipedia.org/wiki/Java_(programming_language) https://en.wikipedia.org/wiki/Java_(programming_language) [6] https://en.wikipedia.org/wiki/Javascript_(programming_language) https://en.wikipedia.org/wiki/Javascript_(programming_langua...
- gjvc 3y agoDear oh dear oh dear oh dear oh dear. Please read what I said again, more carefully, starting from the first word, and try not to be so contrary. I was referring to the fact that the shiny and new tooling will be what attracts users to a given platform / language / ecosystem, regardless of the latter's age. Other participants on this thread apparently seem to have understood this. Happy new year.
- PartiallyTyped 3y agoAnd I was expressing that it isn't that shiny new tooling that attracts users, nor is it the "new" stuff. Nobody uses python because of jetbrains, or whatever. It has nothing to do with IDE support. Jetbrains has support because python is popular, and not the other way around. I was also expressing that Python is an old, almost ancient language, and yet it more used than languages that, by your reasoning, had better "tooling" in the sense that you are using it. Making the point that it has nothing to do with the "age" of the language, the fact that it is perceived as new, or having better tools. Python isn't popular because of its tooling, but despite it. It is popular because it makes it easy to leverage the ecosystem and get things done. It seems that other people understood as much.
- andy99 3y agoI wrote a short thing about working with Fortran for AI recently: https://www.marble.onl/posts/fortran_llms.html https://www.marble.onl/posts/fortran_llms.html I'm a big Fortran now for anything fast. If I was doing EDA or any one-of data science stuff I'd be more likely to use python though (or coreutils and gnuplot depending on the circumstances).
- TrianguloY 3y agoNot sure if it's real or not, but on my university I'm almost sure python is used primarily for being the free alternative to matlab. That, and how easy it is to install and import things.
- HarHarVeryFunny 3y agoThere's also GNU Octave as a free (and largely compatible) alternative to MATLAB. Andrew Ng's original ML course on Coursera used Octave. As a developer who'd never use it (or MATLAB) before, I found Octave very easy to use. Newer ML courses use Python because of it's subsequent adoption by PyTorch.
- PLenz 3y agoThis is less the difference between fortran and python and more the difference between run once for an experiment culture and run as part of a pipeline culture. Languages are mostly funglible, coding culutre is not.
- jraph 3y agoProgramming languages are a bit like social networks. There's some network effect. People go where other people are. Python is currently where things happen.
- QuadmasterXLII 3y agoThe miracle of python is that it has standard syntax for vectorized code across many packages. For i in range(100): mask = lib.abs2(z) < 4 subset = z[mask] subc = c[mask] subcounts = 0 for j in range(100): subcounts = subcounts + lib.abs2 (subset )< 4 subz = subz**2 + subc Z[mask] = subset Counts[mask] += subcounts Was that code using numpy, tensorflow, torch, arrayfire, or some proprietary amd gpu lib? It’s hard to say! Try the same with eigen vs arrayfire in C++ or math.js vs tensorflow.js and you will have to do a hell of a lot more than change the value of lib
- aidos 3y agoI’m confused by seeing talk of vectorisation next to example code full of for loops
- QuadmasterXLII 3y agoI forgot c = lib.arange(-2, 2, .01) c += 1j * c.transpose() at the beginning, and appear to have eaten some downvotes as a result lol
- medo-bear 3y ago> The miracle of python is that it has standard syntax for vectorized code across many packages. If you care about performance you should care about how vectorization is implemented. Python makes vectorization look like magic, but scientists shouldnt do magic. In Steel Bank Common Lisp I can implement SIMD procedures in a straightforward manner. The language is more high level and more low level (yes) than python, and much much faster.
- QuadmasterXLII 3y agoI mean that's exactly how python won. Everyone wrote code and got used to slicing idioms without understanding how they were implemented in SIMD, and then when the implementation got changed from SIMD to GPGPU, the high level code and more importantly idioms didn't have to change.
- deleted 3y ago[deleted]
- zzbn00 3y agoThe slowness of Python meant that nobody thought "it'll be easier just to write this routine" as opposed to looking to re-use existing (most often compiled) code. And if you are doing science, the less time you spend re-inventing code, the more science you will get done.
- zwieback 3y agoI'm so old that Fortran was actually my first language. Over the years I've seen language bindings to the old Fortran numerical libraries we all rely on but Python/numpy is the first wrapper I've actually enjoyed using. It's more than a wrapper in that it brings a compact representation of slices and vectors. However, if I didn't know how things work underneath I'd be a little uneasy. You can always profile after the fact but it helps knowing how to avoid inefficient approaches.
- tyingq 3y agoI imagine part of it is also that a lot of the code isn't the science part. It's all the setup, things like parsing data for input or output. Languages like Python and Perl have very rich standard library stuff for massaging strings, data formats, etc.
- PaulHoule 3y agoIf your data is big you may be amazed at how expensive string parsing can be. You can do a lot of FLOPS in the time it takes to serialize and deserialize a large matrix to ASCII for instance.
- deleted 3y ago[deleted]
- arc619 3y agoPersonally, I think Python's success is down to the productivity of its peudocode-like syntax letting you hack prototypes out fast and easy. In turn, that makes building libraries more attractive, and these things build on each other. FORTRAN is very fast but it's a less forgiving syntax, especially coming from Python. In that regard, I'm surprised Nim hasn't taken off for scientific computing. It has a similar syntax to Python with good Python iterop (eg Nimpy), but is competitive with FORTRAN in both performance and bit twiddling. I would have thought it'd be an easier move to Nim than to FORTRAN (or Rust/C/C++). Does anyone working in SciComp have any input on this - is it just a lack of exposure/PR, or something else?
- larrydag 3y agoAbsolutely. Fortran about 500 lines of code vs <20 lines for Python. The ease of use and flexibility of Python across so many application types makes for a good reason for its popularity. The rise of hardware computing performance makes speed tradeoff trivial.
- Bostonian 3y agoFor code implementing a numerical algorithm, I think the ratio of lines needed in Fortran vs. Python is much less than 25, maybe 2 or 3. And once the code is written in Fortran you just compile with -O3 etc. to get good performance and don't need to thnk about translating to Cython, Numba, or some other language.
- jvanderbot 3y agoPython itself isn't really used for scientific computing. Pythons bindings to high performance libraries, many of which use Fortran under the hood, are used for scientific computing. Combined with the ease of displaying results ala Matlab but much less of the jank, and you have an ideal general purpose sci comp environment
- KeplerBoy 3y agoStill, people leave a lot of performance on the table when using Numpy in sub-optimal ways or when the problem just doesn't translate neatly to Numpy. It's tempting to get lazy and just use a for-loop to iterate over an array sometimes and that will absolutely kill your performance.
- HarHarVeryFunny 3y agoIMO the popularity of Python has as much, if not a lot more, to do with the available libraries and frameworks as the language itself. The language itself seems more inherently suited as a successor to Perl - as a powerful scripting language, rather than one really suited to large, complex, multi-person projects. What seems to have bootstrapped the success of Python for ML and scientific use was early adoption by people in these communities who were not hard core programmers, and found it easy to get started with. Once SciPy and NumPy were available, and NumPy became used for ML, then the momentum of ML helped further accelerate the adoption of Python.
- jampekka 3y agoThe availability of libraries is because of the language. It's a (good) flexible general purpose dynamically typed language which makes writing libraries and good code in general easy. Why it's deemed unsuitable for large, complex, multi-person projects is that enterprise types know only the byzantine OOP mess. And when all you have is OOP, everything is a FactoryFactoryFactory and everything else is "unmanageable".
- HarHarVeryFunny 3y agoThe reason it's not well suited for larger/etc projects has nothing to do with OOP - it's about things like dynamic typing and indent-based structure that make it good for interactive REPL use, scripting and rapid prototyping, but less suited for more complex cases where you'd prefer more compile-time vs run-time checking, and where ease of lifetime maintenance trumps up-front coding time. I disagree that the availability of good libraries for Python is because of the language - especially if we're talking about scientific and ML libraries. In many of these cases the Python libraries are just pass-thrus to the underlying libraries written in C, which was chosen because of it's performance and suitability to the task.
- manuel_w 3y ago> indent-based structure [...] less suited for more complex cases How so?
- cjs_ac 3y agoPython isn't the language of scientific computing, data science, or high-performance computing. Python is a popular user interface for scientific computing, data science or high-performance computing.
- est 3y agoIt's unfair, language is the interface. C replaced assembler, assembler replaced machine code, it's turtles all the way down.
- dehrmann 3y agoMinds are blown when people learn assembly isn't really assembly anymore.
- lolinder 3y agoCan you elaborate on the distinction you're making? Python is the default language in which people express their scientific computations. It may execute C code in the end, but so does any language that ever executes a system call.
- KeplerBoy 3y agomatmuls aren't a syscall though. Little fun fact: Numpy doesn't even come with an efficient, blocked matmul procedure. It has to be linked against a BLAS implement to really provide any decent performance. This also explains why Numpy performance can vary from distribution to distribution. Anaconda ships it with a different BLAS than Pypi.
- dbrueck 3y agoBut for the people using the tools, that's largely a distinction without a difference.
- dadoge 3y agoPython is also a more transferable skill than Fortran. I bet that plays some role too in its popularity in the scientific community, which has many young anxious grad students/postdocs looking to ensure they are employable.
- cmiles74 3y agoMany of the introductory programming courses seem to favor Python. If you already know a little Python, I can see the temptation to stick with it instead of learning Fortran.
- ringofchaos 3y agoPython is also recommended in tech community as recommended programming for coding interviews as you need to write less code.
- 1-6 3y agoI wish Python existed when I was in high school. My school’s compiler wouldn’t remind me that I was missing a semicolon and I would constantly be wasting time looking at syntax rather than grasping bigger concepts.
- pjmlp 3y agoAs someone that was at CERN when Python started to be adopted in the early 2000's, Python got popular as saner Perl alternative for UNIX scripting, build tools (CMT), and as means to provide a REPL to C++ and Fortran libraries instead of dealing with ROOT. That was all, it could have been Tcl instead.
- aulin 3y agoHEP is a somewhat peculiar community. They tend to rely on their own tools, their own libraries. I wouldn't take them as a model to understand historical python adoption in science. I'd bet that their python usage is still mostly as a REPL to ROOT (which by the way has its own REPL), so no numpy, maybe little pandas, no matplotlib.
- npalli 3y agoThe date of this discussion (July/2020) really caught my eye. Fortran is actually making quite a comeback (to the extent an ancient scientific language can :-). I casually looked at the TIOBE index[1], flawed as it may be, it gives you sense of the trends of the larger languages. To my not-a-surprise, turns out precisely in 2020/July Fortran was at it's lowest rank on the index since it was tracked from 2001, and has steadily climbed since then. No doubt it is due to vast number of libraries already existing and python is really glue code not something you write the main code in. As someone joked to me, the first rule of python programming in scientific computing is make sure you don't have any of your program go through python. You cannot avoid Fortran/C++ unless you have very trivial or textbook type code. [1] https://www.tiobe.com/tiobe-index/fortran/ https://www.tiobe.com/tiobe-index/fortran/
- sapiogram 3y agoEven with your disclaimer, Tiobe is useless, even as a vague indicator of anything. It ranks Prolog as having higher market share than Typescript for christ's sake, stop poisoning your brain with that snakeoil shop.
- xondono 3y agoPython wins because it’s the lowest common denominator. We have a bunch of people programming, most of them scientists. Even if Python is poorly suited for us, it’s pretty much the only thing everyone can work with.
- soVeryTired 3y agoEveryone worked with Fortran long before they worked with Python.
- pjs_ 3y agoI worked hard to replace LabView and Matlab with Python in the lab when I was a PhD student - about 15 years ago. By far the biggest motivation to do this was to remove the friction and cost of obtaining licenses for proprietary software.
- LispSporks22 3y agoLike just about any technology in our industry, people use it because it’s popular. Competitive advantage be damned - just use what your competitors use.
- logtempo 3y agoWhen you look at the "monster" that is ROOT-CERN, which is a C/C++ interpreter* with very efficient statistics and plot tools (it can digest tons of data), it is completely logic that Python is a good language for daily lab tasks and analysis. But I'm not sure if it is really used beyond this daily lab task or intern project where performance is not critical. Big simulations I participated were made in C/C++. Nowaday, it seems that at least physics particle community looks enthusiastic regarding Julia development. *: it mimics most of core python features such as no strict typing, data structures that can store different types, on-the-fly coding, graphic interface for representation, no compilation needed.
- deterministic 3y agoPython is mostly used as an API for interacting with high-performance libraries written in other languages. It is the BASIC of today.