News for hackers. Stuff that matters.
Re:Why scientists are turning to Rust by st1x7 on Tuesday December 01, 2020 @06:13PM (#25271315)
This seems like a stretch, or it seems very limited to the specific people mentioned in the article. I find it hard to believe that scientists who have specialised very narrowly in their domain will also want to be full-time software engineers too and choose one of the most complex languages on top of that. This just doesn't scale beyond the few people who are really into it.

> 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).

Re:Why scientists are turning to Rust by brundolf on Tuesday December 01, 2020 @06:18PM (#25271359)
Most of Rust's difficulty comes from the borrow-checker. And if you're mostly doing linear work, if you're doing a lot of math, if you have a lot of pretty flat data structures, if you mostly keep things on the stack, then you may not run up against the borrow-checker that often. I would assume (I don't know for sure) that scientific computing tends to do more of this kind of stuff, and not as much heap-juggling/heterogeneous data modeling as, say, a web server.
Re:Why scientists are turning to Rust by johncolanduoni on Tuesday December 01, 2020 @06:35PM (#25271507)
I’ve done simulation work using Rust and in particular the Rayon data-parallelism library and this has been my experience. The kind of organization of data you need to do for good cache behavior (e.g. split data by phases of algorithm, divide work by memory destination and only randomly read when possible) meshes quite well with the borrow checker restrictions.
Re:Why scientists are turning to Rust by ephimetheus on Wednesday December 02, 2020 @02:03AM (#25273912)
Really depends I guess. I can tell you that at least for HEP, especially for the LHC experiments, software is nothing like what you describe. Parts are designed and optimized in such a way but I would imagine it it to be a gigantic effort to try and wrangle with the borrow checker for the rest of the software.
Re:Why scientists are turning to Rust by whymauri on Tuesday December 01, 2020 @06:27PM (#25271433)
>I find it hard to believe that scientists who have specialized very narrowly in their domain will also want to be full-time software engineers too and choose one of the most complex languages on top of that.

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

Re:Why scientists are turning to Rust by walleeee on Tuesday December 01, 2020 @06:32PM (#25271474)
Yes. And a lot of that software collects dust after the paper it produced is published :/

Academia needs to recognize and incentivize software (including maintenance) as a research output, and make funding available for more research software engineers.

Re:Why scientists are turning to Rust by mattkrause on Tuesday December 01, 2020 @06:47PM (#25271611)
Amen! More long-term staff scientist jobs of all stripes!

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.

Re:Why scientists are turning to Rust by walleeee on Tuesday December 01, 2020 @07:03PM (#25271729)
Seriously! My lab does plant root growth modeling, which (like protein folding) is a 3D morphology prediction problem. Tweaking crops for even a small increase in carbon uptake and sequestration in soil (e.g., via deeper or longer roots) may be able to cut a sizeable chunk out of annual CO2 emissions[0], but almost nobody's working on it because it doesn't have direct applications to human healthcare.

[0]: http://www.nature.com/articles/nature17174

Re:Why scientists are turning to Rust by whymauri on Wednesday December 02, 2020 @05:50PM (#25282832)
This is really cool and I wasn't aware of this previously. Thanks for sharing!
Re:Why scientists are turning to Rust by walleeee on Thursday December 03, 2020 @11:25AM (#25290519)
Sure thing! Seems almost nobody is (I wasn't until a year ago)
Re:Why scientists are turning to Rust by sida on Tuesday December 01, 2020 @06:35PM (#25271510)
Do these software collect dust and rust over time?

ok sorry.. bad dad joke..

Re:Why scientists are turning to Rust by pvorb on Tuesday December 01, 2020 @06:44PM (#25271582)
This just made me discover the Dust programming language[1].

[1]: https://bilalhusain.com/dust/

Re:Why scientists are turning to Rust by ibraheemdev on Tuesday December 01, 2020 @09:45PM (#25272720)
There is also DustJS [1]. It is much more popular.

1: https://github.com/linkedin/dustjs

Re:Why scientists are turning to Rust by walleeee on Tuesday December 01, 2020 @06:38PM (#25271527)
wish I'd thought of that...
Re:Why scientists are turning to Rust by 7thaccount on Tuesday December 01, 2020 @06:32PM (#25271480)
I'm also highly sceptical. In my experience scientific software is mostly restricted to:

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).

Re:Why scientists are turning to Rust by proverbialbunny on Tuesday December 01, 2020 @06:34PM (#25271503)
Rust is easier than C++ for this kind of work because of its packages. In some ways Rust is closer to Python for prototyping an idea to see if it works. Rust gets challenging when you have to deal with large systems, which is not a problem for research.

Researchers / scientists will sometimes not even write functions. It's that small of a scope.

Re:Why scientists are turning to Rust by st1x7 on Tuesday December 01, 2020 @06:42PM (#25271558)
> Researchers / scientists will rarely 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.

Re:Why scientists are turning to Rust by proverbialbunny on Tuesday December 01, 2020 @07:14PM (#25271796)
The code I'm talking about needs to run fast (or be type safe) or you wouldn't consider using Rust. But internally in a library or a function that gets ran over and over again and needs to run super fast often isn't a lot of lines of code. So what I mean by a researcher may not even write a function is, they write the meat of the algorithm, it gets handed off to software engineers, and they turn it into a library or OOP it or whatever, and then run it on servers.

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.

Re:Why scientists are turning to Rust by mattkrause on Tuesday December 01, 2020 @07:31PM (#25271932)
I'm a little jealous you work somewhere where there are data engineers to hand off to!
Re:Why scientists are turning to Rust by proverbialbunny on Wednesday December 02, 2020 @11:50AM (#25278261)
I have to push to get them hired sometimes.

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.

Re:Why scientists are turning to Rust by 7thaccount on Wednesday December 02, 2020 @08:28AM (#25276130)
I think I'm in agreement with you.

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.

Re:Why scientists are turning to Rust by vram22 on Wednesday December 02, 2020 @02:46PM (#25280651)
>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.

Re:Why scientists are turning to Rust by 7thaccount on Wednesday December 02, 2020 @11:32PM (#25285403)
Yep, autocorrect I guess. My point being if someone is just doing a little string work than she'll scripting can be very performant and also dead simple.

I normally think of scientific programming as something involving lots of large matrices, but that isn't the case for everything.

Re:Why scientists are turning to Rust by proverbialbunny on Friday December 04, 2020 @05:22PM (#25309042)
>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.

Re:Why scientists are turning to Rust by 7thaccount on Wednesday December 09, 2020 @11:50AM (#25360618)
In my experience yes, but I started thinking about stuff like the human genome project which was mostly done with Perl scripts and BioPerl in the year 2000 iirc. I assume that is mostly just regex work dealing with very large strings. Is it scientific computing? Yes, just not as how I typically view scientific computing.
Re:Why scientists are turning to Rust by zozbot234 on Tuesday December 01, 2020 @08:55PM (#25272409)
C++ still has a few desirable features re: value-parameterized templates and compile-time metaprogramming that currently lack an idiomatic Rust equivalent. In principle, you can replicate anything C++ can do via procedural macros, but it's not necessarily easy. Also proc macros are a nightly-only feature, so there's that.
Re:Why scientists are turning to Rust by steveklabnik on Tuesday December 01, 2020 @09:19PM (#25272560)
Proc macros are not a nightly only feature.
Re:Why scientists are turning to Rust by ThrowawayR2 on Tuesday December 01, 2020 @06:28PM (#25271446)
Scientists didn't have a problem writing Fortran, back in its day. I doubt they'd have a problem with Rust or even C++ if they needed to.
Re:Why scientists are turning to Rust by a-nikolaev on Tuesday December 01, 2020 @06:40PM (#25271547)
And that Fortran on average was pretty bad. Any language that requires certain level of discipline will have hard time to be adopted at a large scale. And this is why Python, R, and "C/C++" are still the best friends for most people in scientific software development.
Re:Why scientists are turning to Rust by proverbialbunny on Tuesday December 01, 2020 @06:29PM (#25271453)
It may help to remember that the previous go-to language for scientists was Fortran. Of course, not all scientists, but a very much alive subset that still use it today.

I'm a data scientist and I know Rust. Though, to be fair, I'm probably not the type the article is describing.

Re:Why scientists are turning to Rust by adamnemecek on Tuesday December 01, 2020 @06:17PM (#25271351)
Scientists will write whatever makes most sense. Julia is comparably easy as python it’s just that it has more advanced features.
Re:Why scientists are turning to Rust by st1x7 on Tuesday December 01, 2020 @06:20PM (#25271375)
It's considerably more difficult than Python, people just get misled by the similar syntax. The advanced features that you're mentioning aren't optional in Julia, especially if you care about performance.
Re:Why scientists are turning to Rust by dnautics on Tuesday December 01, 2020 @06:21PM (#25271388)
But you don't care about performance with Julia. You just write your thing. Then you complain to the community that it's slow, and they optimize it for you! Only half kidding.
Re:Why scientists are turning to Rust by adamnemecek on Tuesday December 01, 2020 @06:35PM (#25271511)
Which part of Julia is difficult?
Re:Why scientists are turning to Rust by st1x7 on Tuesday December 01, 2020 @07:00PM (#25271716)
Compared to Python? Just about everything starting from simple things like how to create a simple data structure, how to convert a variable to a different type, how to understand any error message that you get, how to open a file or modify a visualisation and extending all the way up to overarching concepts like the typing system, importing foreign code and managing dependencies.
Re:Why scientists are turning to Rust by jonniedie on Tuesday December 01, 2020 @08:24PM (#25272244)
A simple data structure:

  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)
Re:Why scientists are turning to Rust by st1x7 on Wednesday December 02, 2020 @03:19AM (#25274293)
This really isn't constructive.

- 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.

Re:Why scientists are turning to Rust by adamnemecek on Tuesday December 01, 2020 @09:01PM (#25272450)
Yeah defining a strict in python would be more lines.
Re:Why scientists are turning to Rust by adamnemecek on Tuesday December 01, 2020 @07:20PM (#25271838)
How is making a structure in Julia harder than in python?
Re:Why scientists are turning to Rust by xiphias2 on Tuesday December 01, 2020 @06:58PM (#25271702)
For me it was understanding the type unification rules. After a long time I read the original dissertation papers, and only that was the time when I finally understood what method is being called why at what point. While method dispatch is the most interesting part of Julia, it's the most complex as well.
Re:Why scientists are turning to Rust by bosswipe on Tuesday December 01, 2020 @06:26PM (#25271426)
I agree, a memory managed language will always beat the borrow checker in expressiveness, ergonomics, simplicity, maintainability. Unless you're writing system-level or low-latency apps I don't see the benefit to Rust. If you need better-than-python performance there are many good memory-managed LLVM or JVM/.Net options available.