News for hackers. Stuff that matters.
Re:GNU Octave by the__alchemist on Saturday January 21, 2023 @12:40PM (#34468249)
Another take: There's value in using a compiled language here. I'm an amateur dabbling in computational chemistry, and my weapon of choice is Rust. (After starting using Python). Why:

  - Fast, in an area where speed is important
  - Can be made faster for repetitive tasks by communicating with a GPU using Vulkan, CUDA etc
  - Can incorporate a GUI, and 3D graphics, which helps for exploring things visually, tweaking parameters, doing time simulations etc.
  - Can share. Ie, I showed my brother yesterday by sharing a 10Mb executable. Matlab has license complications and you need it installed. Sharing Python programs is a disaster. (Docker? Pip? Pyenv? Virtualenv? System Python? System dependencies for the C dependencies?)
Re:GNU Octave by akuro on Saturday January 21, 2023 @12:49PM (#34468337)
Interesting. You might be the first computational chemist I know who actually uses Rust. I know a lot of computational chemists!

Python is the big one, all of the aforementioned chemists are either intermediate or advanced in that. The runner-up seems to be Julia, which I personally have no experience with. The big guys are Fortran and C++. I prefer C for tasks of this nature, but I also shill Scheme so don't listen to my opinions on programming languages.

Best of luck on your computational chemistry endeavours!

Re:GNU Octave by doubleg72 on Saturday January 21, 2023 @01:20PM (#34468698)
Maybe spare the next guy by moving your "don't listen to my opinions on programming languages" statement to beginning of second paragraph... ya know, for efficiency!
Re:GNU Octave by akuro on Saturday January 21, 2023 @01:30PM (#34468816)
Don't listen to my opinions, sure. But pay heed to the large number of computational chemists who do use these languages. There is a reason that professionals employ the tools that they do.
Re:GNU Octave by freehorse on Saturday January 21, 2023 @01:42PM (#34468946)
Historical reasons, most often than not.
Re:GNU Octave by tialaramex on Saturday January 21, 2023 @05:16PM (#34471224)
One reason we have lots of people in numerate disciplines using Python is that we taught them Python. Python is very teachable. Given a class of average 19 year old students from a numerate discipline, my colleagues will teach most of them Python to a reasonable standard in a single module (so e.g 2 hours of teaching per week over 16 weeks).

The same would not be true if we were supposed to teach them C++ for example. It's a huge, sprawling language, full of difficult concepts that are unfriendly to teach, and equally filled with foot guns that if you don't teach them will definitely maim your students, but if you do teach them take up yet more precious time on minutiae.

Safe Rust wouldn't be as hard to teach as C++ but it's no picnic. So even if the Chemists decided that ideally they'd like their undergraduates to learn Rust instead of Python, I think the argument would be that it can't be done on the existing timeline.

Re:GNU Octave by zozbot234 on Saturday January 21, 2023 @05:46PM (#34471500)
> Python is very teachable. Given a class of average 19 year old students from a numerate discipline, my colleagues will teach most of them Python to a reasonable standard in a single module

Compared to Perl, sure, Python is teachable. But I'm willing to speculate that Safe Rust as a semi-pure functional language (basically: when in doubt, .clone() all the things and don't even think about the minor hit to performance) can also be taught as a first-time programming language. Rust may be at a disadvantage to Python wrt. bindings to the existing ecosystem of C/C++/F0RTRAN scientific codes, but that's a temporary state of things.

Re:GNU Octave by aragilar on Saturday January 21, 2023 @08:21PM (#34473026)
To science majors? No. It lacks so many of the things you'd need to get them started (e.g. a REPL/notebook server, interactive plotting, a "here's everything you need" install (a.k.a conda)), and most (but not all) students have no real interest in learning to program. You could get the interested-in-programming ones to learn Rust, but then they're going to hit the large legacy of existing code and wonder why you taught them something that not related to what they're going to use.
Re:GNU Octave by zozbot234 on Saturday January 21, 2023 @09:25PM (#34473517)
There's an interesting experimental project for a Rust REPL and notebook interface at https://github.com/google/evcxr . Other things, e.g. semi-officially endorsed collections of community crates with no strong backward compatibility guarantees, have seen some development already.

> but then they're going to hit the large legacy of existing code and wonder why you taught them something that not related to what they're going to use.

OTOH other languages should be easier to learn by reference to a comparatively elegant language like Rust. Python, Fortran, C++ etc. have almost nothing in common but Rust could arguably be a good introductory baseline that shares features with all of these.

Re:GNU Octave by aragilar on Saturday January 21, 2023 @08:05PM (#34472897)
Now we teach them Python, because the ecosystem and mindshare is there. But why didn't Perl or Ruby (or Tcl) win? It seems like Ruby didn't get the right ecosystem around it, but Perl has PDL (which does seem to predate much of the Python scientific ecosystem), and had SWIG support before Python. Maybe there's a lesson there for the Rust scientific ecosystem?
Re:GNU Octave by worik on Saturday January 21, 2023 @10:00PM (#34473766)
> . But why didn't Perl or Ruby (or Tcl) win?

That is a very good question.

IIRC at the time Perl had a bad reputation because of the weird syntax "$%@" (not weird to shell programmers, so much, but they were weird...)

Python was "object orientated" and from a computer scientist.

Perl is very imperative and informal. Python felt to people like a real language, Perl did not.

I am reaching for reasons as I was very disappointed that Python was the winner. I have never liked Python (personal taste - meaningful white space? Really?) and knew Perl very well.

(Perl Vs. PHP is a different, much more interesting, and tragic story)

Re:GNU Octave by osigurdson on Saturday January 21, 2023 @03:24PM (#34470061)
You take the comment far too literally.
Re:GNU Octave by abirch on Saturday January 21, 2023 @07:23PM (#34472574)
C++ and Fortran are what come to mind for computational chemistry due to the legacy libraries but it's been a long long time since I've used Gaussian.
Re:GNU Octave by rsfern on Saturday January 21, 2023 @10:14PM (#34473865)
i think there are only a couple exceptions to the Fortran/C++ rule. DFTK.jl is the only one I know written in Julia, and there’s GPAW and pySCF in python
Re:GNU Octave by boppo1 on Sunday January 22, 2023 @07:11AM (#34476588)
What's discrediting about scheme?
Re:GNU Octave by akuro on Sunday January 22, 2023 @01:28PM (#34480530)
I don't know, but whenever I plead with people in computational science to read Structure and Interpretation of Classical Mechanics I'm usually met with an eye-roll.
Re:GNU Octave by boppo1 on Monday January 23, 2023 @09:40PM (#34498433)
Interesting, I'd never heard of SICM, only SICP.
Re:GNU Octave by BaculumMeumEst on Saturday January 21, 2023 @01:59PM (#34469126)
Python can be very fast. Library ecosystem and network effects by far outweigh anything you listed. Mindless Rust evangelism is tiresome.
Re:GNU Octave by patrick451 on Saturday January 21, 2023 @04:28PM (#34470742)
One thing is for sure, rust has excellent marketing.
Re:GNU Octave by pdimitar on Saturday January 21, 2023 @05:24PM (#34471299)
Or it's actually good and you're bemoaning it due to bias. It's worth exploring the areas outside of our comfort zone.
Re:GNU Octave by patrick451 on Saturday January 28, 2023 @12:39AM (#34555494)
I've tried it, and it seems interesting. But I distrust anything that appears to have a lot of propaganda behind it, and rust definitely fits that bill. The hype will need to die down and the dust settle before I trust anything important to it.
Re:GNU Octave by pdimitar on Saturday January 28, 2023 @01:03AM (#34555595)
I think you are being unfair here. Literally every community has the 1% of toxic, loud and insufferable people in it. Point me at your hobbies and I'll find these kinds of people there, I can bet my neck on it.

Many people conflate their own irritation from hearing about the thing X often and against their will, with the quality of the thing X.

IMHO critical thinking and maturity demands that we make that distinction.

I have worked several times in Rust companies and their devs are extremely hardcore and very quiet. You couldn't tell these people are responsible for the technical operations and code of worldwide financial services.

So again, be a bit more charitable. Every community has its rotten apples. That says nothing about the quality of the thing that the community stands for.

Re:GNU Octave by BaculumMeumEst on Wednesday February 01, 2023 @09:43AM (#34611104)
i know you were replying to someone else but thanks for your comment, its good to get perspective. i’ll try to be less of a curmudgeon
Re:GNU Octave by pdimitar on Wednesday February 01, 2023 @12:27PM (#34614064)
After being a curmudgeon from 30 to 40 years old, I've figured it's not good for me so I started changing things around and I like my life and career more now.

Don't get me wrong, insufferable people still exist! But I no longer judge an entire community by them.

Re:GNU Octave by noogle on Saturday January 21, 2023 @08:56PM (#34473300)
Python sometimes feel like being stuck in a local-maximum: the network effect is real, but there are so many downsides to the platform itself, and the "two-languages" paradigm renders the computational code obscure and undebuggable.
Re:GNU Octave by wodenokoto on Saturday January 21, 2023 @03:00PM (#34469776)
Maybe it is not part of computational chemistry, but how do you do explorative analysis? More than half my time working with data is spend grouping and summarising data, typically in Pandas and drawing interactive graphs in plotly.
Re:GNU Octave by the__alchemist on Saturday January 21, 2023 @03:23PM (#34470049)
Plots and visualizations in 3D. (Vulkan / WGPU) For example, to compare wave function solutions, I use surface plots of a 2D slice. I have a UI that can change the slice of the non-mapped axis. Plots of psi'', the potential etc too.

Or for simulating molecular motion, draw it out in 3D, with 6DOF FPS-style camera controls etc.

I imagine Pandas would be OOM too slow for this. Compared to Python, Pandas is, in my experience far too slow. Another speed limitation is Matplotlib's 3D plots make my computer crawl when rotating them etc; and they're not very interactive, at least on their own.

When dealing with these systems, a particular computational challenge is that they're 3D, so computation scales with precision^3. (This also adds complications to visualization, as I alluded to above)

Re:GNU Octave by legerdemain on Saturday January 21, 2023 @05:05PM (#34471095)
Did you write your own visualizations using wgpu? I don't think its goals include providing visualization out of the box.
Re:GNU Octave by the__alchemist on Saturday January 21, 2023 @05:44PM (#34471483)
Yep! So, took some work upfront. Basic rendering/navigation engine. `egui` for the GUI.
Re:GNU Octave by einpoklum on Saturday January 21, 2023 @05:32PM (#34471374)
Given your criteria, you might want to consider (modern) C++.

* Fast - in many cases faster than Rust, although the difference is inconsequential relative to Python-to-Rust improvement I guess.

* _Really_ utilize CUDA, OpenCL, Vulcan etc. Specifically, Rust GPU is limited in its supported features, see: https://github.com/Rust-GPU/Rust-CUDA/blob/master/guide/src/... ...

* Host-side use of CUDA is at least as nice, and probably nicer, than what you'll get with Rust. That is, provided you use my own Modern C++ wrappers for the CUDA APIs: https://github.com/eyalroz/cuda-api-wrappers/ :-) ... sorry for the shameless self-plug.

* ... which brings me to another point: Richer offering of libraries for various needs than Rust, for you to possibly utilize.

* Easier to share than Rust. A target system is less likely to have an appropriate version of Rust and the surrounding ecosystem.

There are downsides, of course, but I was just applying your criteria.

Re:GNU Octave by the__alchemist on Saturday January 21, 2023 @05:46PM (#34471502)
I want to get into that for CUDA. I've been using Vulkan via WGPU. But there, everything has to pass between CPU and GPU as byte arrays, when I've heard CUDA lets you maintain the same data structures. On the to-do list.

Would also def benefit from the larger selection of C++ libs, especially for GUI and graphics.

Given the main computation issue is doing the same operation on many values in a 3D array, using the GPU more would be great. And my current setup for that is clumsy.

I disagree on easier to share. Binaries work the same either way. Compiling from source on rust is generally install Rustc, and do `cargo b --release`. Compiling someone else's code in C++ is... complicated.

Re:GNU Octave by einpoklum on Saturday January 21, 2023 @06:16PM (#34471833)
> when I've heard CUDA lets you maintain the same data structure

Yes, that's possible with a combination of:

* Unified address space for pointers (and C++ references are basically pointers)

* Paged virtual memory on GPUs

... however, remember that many/most data structures which make sense on the CPU may not make sense to use on a GPU. And - NVIDIA very often implements and promotes certain features because they sound good in marketing, not because they're actually that useful. Or because they let you make a super-slow program into a meh-speed program, not because you would use them in a really-fast program.

> Compiling from source on rust is generally install Rustc, and do `cargo b --release`.

Well, I guess you may have a point, but let me still make a couple more arguments.

First, installing Rust (and related libraries/tools/whatever) is not trivial for people who don't know rust, and some OS distributions only offer you an older version of rust using their distro-package-managers. It's more likely that a C++ environment is already set up on someone's machine... TBH, though, if the distro is older, that might not be a perfect fit for what you're building.

Second C++ package managers becoming more popular, e.g. Conan: https://conan.io/ ; and that helps for when your OS distro doesn't cover you.

> Compiling someone else's code in C++ is... complicated.

This has actually improved a whole lot over the past... say, decade or so!

* Unzip/untar

* Configure the build with CMake (cross-platform build system generator - almost ubiquitous these days in C++ projects): `cmake -B build_dir/`

* Assuming you have the dependencies set up - it should "just build": `cmake --build build_dir`

* Run the thing from the build directory or install it with `cmake --install build_dir`.

... and if you want to tweak package options more easily than via the command-line, you can use a TUI (ccmake) or GUI (cmake-gui).

The problems start when you're missing dependencies, or if the author didn't make their code platform-independent / multi-platform.

Re:GNU Octave by vlovich123 on Saturday January 21, 2023 @05:52PM (#34471568)
> Fast - in many cases faster than Rust, although the difference is inconsequential relative to Python-to-Rust improvement I guess.

Do you have any examples? AFAIK properly tuned rust and c++ will perform largely the same. Actually, Rust should have a bit of an edge due to the prohibition of aliasing. In practice it can vary if a standard library implementation is suboptimal or the compiler has suboptimal codegen into Bitcode but that’s generally going to be rare these days I think.

> Richer offering of libraries for various needs than Rust, for you to possibly utilize.

Are you talking for computational chemistry specifically or general libraries?. Don’t know about the former. For the latter I’ve found not only are more interesting libraries available, there seem to be generally high quality versions. Additionally, “cargo add xxx” is infinitely faster than integrating some random third party c++ dependency. Not to mention that C++ falls on the floor if one dependency requires transitive dependency X and another (or you) requires X at an incompatible version? Rust handles that elegantly where two different modules can depend on the same package at different versions without conflict without you needing to worry about it beyond the size of the executable.

> Easier to share than Rust. A target system is less likely to have an appropriate version of Rust and the surrounding ecosystem.

Again, haven’t that found to be my experience. Rustup lets you obtain any version of the rust tool chain, no muss no fuss. Additionally, it does a phenomenal job of not worrying about which compiler vendor you’re using (there’s only one) and more importantly there’s no versioning issues with libraries written against an older version of the language - 2021 and 2018. Oh, if you’re on windows, you also don’t have to worry about whether the target person has the right c++ runtime library version installed. With rust they just run the exe.

Re:GNU Octave by Const-me on Saturday January 21, 2023 @09:00PM (#34473335)
> not only are more interesting libraries available, there seem to be generally high quality versions

I wonder what's an equivalent of Eigen? https://eigen.tuxfamily.org/index.php?title=Main_Page

> if you’re on windows, you also don’t have to worry about whether the target person has the right c++ runtime library version installed

It's usually easy to build such binaries for Windows. That's a single combobox in project settings. Here's an example, just running the .exe works: https://github.com/Const-me/Whisper

Re:GNU Octave by vlovich123 on Saturday January 21, 2023 @10:00PM (#34473774)
> I wonder what's an equivalent of Eigen?

2 seconds on Google yields:

https://www.nalgebra.org/

https://rust-lang-nursery.github.io/rust-cookbook/science/ma...

https://docs.rs/GSL/latest/rgsl/

I have no idea the quality but you’ve also got bindings to more mature libraries:

https://docs.rs/lapack/0.14.1/lapack/

And https://www.erikpartridge.com/2019-03/rust-ml-simd-blas-lapa... is an overview from t years ago and does say it’s maybe not as good although not sure how much has changed in that time (eg has nalgebra matured sufficiently?)

It’s possible that Rust is lacking in good linear algebra libraries. I’m not as familiar with that space.

Re:GNU Octave by einpoklum on Sunday January 22, 2023 @04:59PM (#34482674)
> Do you have any examples? AFAIK properly tuned rust and c++ will perform largely the same.

In principle, Rust has some overhead for being "safe", which C++ does not. Also, C++ benefits for longer period of time and more people working on optimizing its libraries and compilers.

> Are you talking for computational chemistry specifically or general libraries?

Ah, indeed, no. I have no idea which chemistry libraries are available for Rust and for C++. I was referring to scientific computing, algebra and other heavy-lifting work.

> Additionally, “cargo add xxx” is infinitely faster than integrating some random third party c++ dependency.

That's not one of OP's criteria. But - seeing how you like package managers, try `conan install /path/to/srcdir` from the build directory. For more details, read:

https://docs.conan.io/en/latest/getting_started.html

> Not to mention that C++ falls on the floor if one dependency requires transitive dependency X and another (or you) requires X at an incompatible version?

C++ is a language, it doesn't have dependency management. As for libraries, that situation is so rare - in my experience - that a chemistry person should not even be bothered to consider it.

> haven’t that found to be my experience.

Well, I learned something new today... I didn't know about rustup. Was it introduced recently?

Re:GNU Octave by vlovich123 on Sunday January 22, 2023 @09:47PM (#34484860)
> In principle, Rust has some overhead for being "safe", which C++ does not. Also, C++ benefits for longer period of time and more people working on optimizing its libraries and compilers.

Do you know of any specific safety features that makes rust slower? About the only one I can think of at runtime is that everything is bounds checked but that’s usually fixable in many ways (and technically c++ has that too except it’s applied randomly based on subtitle API differences like [] isn’t but .at is). As for quality of the standard library it’s hard to say. I haven’t found it to be bad. The HashMap implementation is better out of the box, a Vec/vector doesn’t really have anything special. File system APIs, error handling, modules, and async all feel more mature and polished (not performance per se but just overall completeness of the language). What is on your mind when you say that the c++ standard library is higher quality? Oh, and which of the three major implementations are you referring to?

The compilers story is actually even better because very little optimization happens in the frontend and thus a lot of the optimizations done for c++ apply to rust too. One specific way the language itself is better is that it disallowed aliasing so it’s closer to Fortran for numerical stuff and there’s various optimizations that c++ just can’t do. If I recall correctly that hasn’t been fully hooked up to the compiler due to bugs in LLVM but that will get resolved eventually. Overall, I’m not familiar with the claim that Rust code compiles worse than c++. About the only thing I’ve run into so far is bound checking showing up in hotspot code that I wrote non idiomatically because I’m still new to the language.

> Well, I learned something new today... I didn't know about rustup. Was it introduced recently?

1.0 is 6 years ago so not recent at all (not sure if there were pre 1.0 releases too): https://www.reddit.com/r/rust/comments/5iqsmg/rustup_100_is_...

Re:GNU Octave by flatiron on Saturday January 21, 2023 @08:04PM (#34472885)
If sharing is a problem I’m unsure why you didn’t think docker was the solution. I can’t think of an easier way for both the provider and the consumer than docker.
Re:GNU Octave by Thiez on Sunday January 22, 2023 @05:50AM (#34476123)
They did mention licenses as a complicating factor.