Why scientists are turning to Rust
nature.com
nature.com
> Köster, now at the University of Duisburg-Essen in Germany, was looking for a language that offered the “expressiveness” of Python but the speed of languages such as C and C++.
Rust doesn't have the expressiveness of Python (even when you put expressiveness in quotes), it's not even close. What you're looking for is probably Julia (and Julia is already quite a bit more difficult than Python even if the syntax looks superficially similar).
I think it's really field-dependent. I know academics/profs in the computational biology space that accumulate a looot of software over time from their colleagues/students. Also, it's not the scientists/PIs writing the software :P
Academia needs to recognize and incentivize software (including maintenance) as a research output, and make funding available for more research software engineers.
One lesson I hope people take away from AlphaGo/AlphaFold (and a lot of the work coming out of the Allen Institutes, Broad, etc) is that some really amazing work can be done when big groups of experienced people can work together on a project.
ok sorry.. bad dad joke..
C, C++, Fortran, Python, R, Matlab/Simulink, Mathematica, Julia, and Excel.
I would think VERY few doing numerical computing or statistical or other engineering computations would have the bandwidth to really dive into Rust. I also wouldn't consider it stable enough for many projects (although I'm sure it's fine for some).
Researchers / scientists will sometimes not even write functions. It's that small of a scope.
Scientific computing can mean so many different things that if feels like some of us are talking past each other in this thread.
The person in the article talks about needing to get out every ounce of performance and writing an application that identifies genome variants at scale. You're talking code so small that it doesn't need functions. Those are completely different worlds.
Choosing Rust for something that small is a waste of time. Expecting the people who write so little code that their code doesn't require functions, to be comfortable with Rust is even a bigger stretch.
My current project in Python is massive compared to a normal one atm and it's about 2-3 pages of code in Jupyter. In Rust, if the libraries are there, it would be about the same size. I have 8 functions atm. It's also the end of the project and I'm in talks with data engineers to wrap it in OOP. They'll handle the IO. Or at least, that's how I've always done it and I've done a project in Rust.
Technically they're infrastructure software engineers without the title, but most people don't know what that is, so it can be easier to call them data engineers. The company doesn't give titles like that, they're just "the cloud people" with a vanilla software engineer title.
Unless you're a BI / business analyst, there are probably software engineers that work with AWS / gCloud at your company, who setup the database(s) and do the backend. What you want to do is called an IT request, where you request they help out when you need to productionize. It's bad form for a data scientist or any other kind of researcher to have the keys to the live production servers. While it can be fun to learn that stuff, there is a barrier of entry, specially monitoring software and unit tests.
This is more on the PM (or DPM (data project manager)) side but: https://www.datascience-pm.com/domino-data-science-lifecycle... can give a good map of the process. Many who do research are on their own, not apart of larger teams and are disconnected, so they don't know what options they have. Maybe that roadmap can help, depending on your situation.
When it comes to productionization, I've had too many years of software engineers rewriting my models and adding bugs left and right. The second they want to rewrite it from a notebook into a py file (or equivalent language, usually Java), I get cautious. I find the best process skips these issues and the software engineers will thank you for it: Automate most of the productionization process. Using notebooks as an example, python has libraries that can import notebooks, so you don't have to copy paste code into a py file. Instead an OOP wrapper (which they love) can be written with the interface they like. They can do the IO like streaming data or batching or whatever. They can do the unit tests and monitoring part. What you can do is write the function calls inside of the interface. Usually you want a .predict() method, similar to how ML algos work, but .run() is popular too. Inside of that, put all of the functions from the notebook you want called and in what order. In metaphor it's like writing a header file in C or C++. This py file will then import the notebook and call those functions.
The beauty of this is at least four fold: 1) no new bugs 2) no explaining how the model works, because you're doing that part and 3) If you want to update the model, you can update the notebook and then no work needs to be done in the py file. It's importing the notebook, so it will import the changes. It's fully automated. 4) You can have EDA, plots, documentation, all that stuff that usually takes up 40-60% of the notebook, not be required to remove it, because it will not get called.
The only downside is that every cell in the notebook that the py file will call needs to be wrapped in a function. However, this is a good idea by default, because you'll get global variable type bugs when you run the cells out of order if your cells are not wrapped in a function, so to avoid that you're probably already writing functions in your notebooks.
*Sometimes code has to go fast, and notebooks tend to use dataframes, which is fine for 99% of the work out there. In that case, instead of having the software engineers rewriting my model, because of the problems mentioned above, I will instead 1) Write libraries in C/C++ that accelerate parts of the notebook. And if that can't be done I will 2) write the model directly while prototyping in a language like Rust, C, C++, or Java. I'd rather write it than have someone port it. Most will not do this, because it's beyond the average researcher's skill, but it alleviates so many problems, and I'm not afraid of statically typed languages.
One usually needs Fortran or C++ or Matlab or Python with Numpy for numerical computing that is doing matrix or sparse matrix work (a lot of numerical computing is like this). I don't know of any uses that are so small as to not need functions outside of some extremely small/simplified models for explanatory purposes.
There is also symbolic mathematics that Mathematica really excels at although it's pretty good at a lot of things these days.
If someone just needs fast code to loop through some data, they should be able to use whatever compiled or JIT language they see fit. Heck, it sounds like bash/ask might even fit this use case if the code is so small as to not need functions.
Assuming that "ask" was a typo and you meant "awk", awk does support user-defined functions, as does bash.
https://www.gnu.org/software/gawk/manual/html_node/User_002d...
https://tldp.org/LDP/abs/html/functions.html
The support for that in both is somewhat limited as compared to "full" programming languages, though.
I normally think of scientific programming as something involving lots of large matrices, but that isn't the case for everything.
It typically is. If you have the right libraries, it's only a few lines of code to do a lot of math. C = A + B could be matrix math, not just single variables being added.
I'm a data scientist and I know Rust. Though, to be fair, I'm probably not the type the article is describing.
struct ASimpleDataStructure
a
b
end
Convert a variable to a different type: x = 1
x = Float64(x)
Open a file: open(“a_file.txt”)
Import foreign code: using PyCall
so = pyimport(“scipy.optimize”)
so.newton(x -> cos(x) - x, 1)- I had none of those examples in mind (for example by foreign code I was referring to code written in a different project, not to using a different language). No, I don't need you to give me code snippets on how to do my actual list.
- Obviously Julia can do everything that Python can. And most of it will look ergonomic, short and simple. The difficult part isn't whether the language can do it once you know how, it's how quickly you can get to figuring it out when you don't know it.
- So what makes the small things difficult is really the mix of unhelpful error messages and the limited resources online.
This is my overall point - if you take someone who hasn't written code in either Python or Julia, give them access to online search and ask them to complete almost any task, they'll do it faster and with less effort in Python.
“Unlike the many compilers and ancillary utilities that programmers use to build C code, Rustaceans can use a single tool, called Cargo, to compile Rust code, run tests, auto-generate documentation, upload a package to a repository and more. It also downloads and installs third-party packages automatically.”
Fetching required packages in this way is very convenient, something one notices rather soon when writing Rust applications. There are already many dedicated packages also for highly specialized applications, and with cargo it is easy to use them immediately.
This is in contrast to Python's (has a friendly community, but tends to have bikeshedding), Node's (outright toxic npm-based warfare), or Java's (corporations shit out awful code when they're done with it, ie, everything donated to Eclipse or Apache, or all the dumpster fire code Google has released, and its up to you to judge how awful it really is).
Perl's CPAN? Lots of really nice code that follows a pretty good UNIX "does one thing, and does it well" philosophy, with lots of friendly folks.
As long as Rust doesn't have a Perl 6 moment, we're good.
That said, TensorFlow was written by Google in the typical Google Java way. See that bit above where I shit on Google-supplied Java? This also applies to TensorFlow, even though its written in Python.
There is just something culturally wrong at Google, and I don't know why; Amazon and Microsoft and Netflix and whoever else have donated actually pretty decent code to the FOSS community, and none of it is even a fraction of the trainwreck that Google produces.
Once Raku has dataframes, and it is stable, I'll definitely be checking it out.
Loved the Color scheme and font ... lol. Anyways, will be using Rust for a small side project (short paper for augmented Humans ( https://augmented-humans.org/ deadline in 2 weeks :) let’s see how quickly I can learn it).
Any tutorial recommendations go using Rust for statistics/data plotting? https://lib.rs/crates/plotlib Or the gnuplot Wrapper looks up for the task for me.
That's.. ambitious. Rust is a nice language, but the borrow checker, for all its awesomeness, has a fairly steep learning curve. Unless you're a C++ programmer, in which case this level of thinking won't be totally alien to you at least.
For my first program (task scheduling, regexes, redis, rest), everything was simple and obvious, it was made in about 3 days.
My second program was dealing with several kinds of graphs, optimal sub string addressing, and then I hit the painful points and it took me several weeks of this side project to get my head around the complex concepts of Rust, and several months to really feel at ease.
There's a subset of problems for which Rust is "easy" and it's probably possible, with some guidance and occasional help, to organize one's work around those.
I program C, C++, matlab, Python and Ruby. Just looked a bit into Julia and Haskell.
Language Lover ... also trying not so common languages (my favourite is still OpenDylan).
I've found a lot of people bash NR online as outdated but it has really clear explanation of how certain algorithms are written as well as clean to read code examples. Very helpful to follow along with an explanation of the algorithm and see it all laid out in front of you with code.
So maybe a modern version written in a newer language could be a hit.
Nowadays, a similar effort would have to be community driven, and open-source, and include the deep discussions for domain specializations.
Rust is fine, but it will never catch up or replace Python. Python is just good enough at what it does and will only become better.
I really don’t see Rust being used for anything other than very specific cases.
Perhaps?
> and will only become better.
Very unlikely
https://github.com/Vindaar/ggplotnim https://github.com/unicredit/neo https://github.com/mratsim/Arraymancer
Oddly, it didn't seem like he was particularly locked in by a vast pile of legacy code; he just found it a good match for his mental model of the project.
Fortran is a great language for legacy products, with code written 50 years ago still working fine. But it has also gained new features over the years, keeping it ahead of competitors in terms of its ability to harvest all a machine can deliver.
This is all for technical work like numerical modelling. Scientists are a very practical lot, switching from Fortran to C (usually C++) when that makes sense, then to python, R, etc when that makes sense, and so forth.
The original article was about scientists switching to rust. I don't know anyone who has done that. I do know many who are exploring Julia, though.
Bear in mind that scientists tend to be quite good at technical work. Learning a new language is not a significant problem for them. But scientific programming is about much, much more than programming. The essence of scientific programming is in the underlying mathematics and science, and Fortran just happens to be pretty good at those things.
I haven’t worked with it extensively (I use nix on my workstation) but I’m a big fan of what the Guix folks are doing targeting the scientific community https://hpc.guix.info/blog/2019/05/gnu-guix-1.0-foundation-f...
I have seen physicists write entire non trivial image processing pipelines in Matlab. Where they happily processed gigabytes of images made by some weird microscope costing stupid amounts of €.
It (mostly and somehow) works but it is slow as hell (porting to c++ cut the time to run a process from 1 day to a few seconds).
They never even bothered with a "real" language because the "computer guys" can port that stuff if need be.
If you have a hammer...
In my PhD I was analyzing petabytes of structured data from particle detectors that required relatively complex algorithms just to reconstruct, before any physics analysis is ever started, and the analyses were just as complex. My experiment’s total code base was at least 100kloc of C++ and Fortran if not more, and used a farm with over 20k cores for massive distributed processing, single jobs regularly taking hundreds or thousands of cores and terabytes of memory.
I’m currently working on distributed GPU accelerated hydrodynamic simulations where a single input is in the ~1-10Gb range of structured mesh data and the calculation requires ~200+ Gb of GPU memory.
I really don’t see how excel would be a viable option for basically anything I have worked on in my scientific career, beyond my undergraduate toy analyses.
https://genomebiology.biomedcentral.com/articles/10.1186/s13...
https://www.theverge.com/2020/8/6/21355674/human-genes-renam...
We record (electrical) neural activity from behaving animals. The raw data is about 1 Gb/minute, and we collect hours of it per day, 5-7 days/week. The lab next door has microscopes that produce image sets that are in the Gb to Tb range (big swathes of human brains, imaged at micron resolution). An RNAseq experiment is ~20 Gb range; other genomic things are similar, maybe a bit smaller.
All of this would be intractable in Excel, even over a long weekend :-) On top of that, Excel often doesn't do much of what you would need: there's basically no support for signal processing or image analysis or genomic work.
So did Excel not cut it, or was it a preference to use Python? Back then Excel supported up to 65,535 rows, and would typically crash with over 8,000 rows. I worked in that era in Excel. One model once was split across three spreadsheets. Only one spreadsheet could be open at a time, they would take 20 minutes each to load, and there was about a 50% chance they would crash while loading.
So what do you do if you need over 65,000 instances of labeled data? For a neural network it's nice to have a million instances, yes a million.
R and Python have in them what is called a dataframe. It's a spreadsheet, but in another programming language. We tend to load our data into those, which is just like Excel, but without the hardware limitations. So in many ways, today it's just like it once was, but we get to choose which programming language to use while working in a spreadsheet, and let's be fair, the Excel programming language isn't exactly great.
Examples that immediately come to mind include : numpy, tensorflow, etc ...
Even heavy-duty I/O can be made to crank with python if you do it properly.
Rust shouldn't take away from Python or Java, but it may take away from research that uses Fortran, C, or C++.
It's hard enough to figure out how to do things in any language as a full-time software developer, never mind someone that just needs a program for their research, etc.
I don’t really see Rust being altogether different to someone outside the software industry. It’s yet another complex knowledge domain that can be abused and intractable like any other.
So yes you can easily start hacking something in fortran or c++, and the cognitive load is probably much smaller, but then you have the risk of being eaten by your bugs, or of not working on some problems just because the tool you make is so badly designed you give up doing the necessary changes.
All these pro rust/mozilla journalists are all related to Mozilla in some ways
Few google search and you start to see how all these people are connected
Hmm
What about CSS developpers, they are also turning to Rust?
We'll need the Markdown writters to turn to rust too!