HNHacker News
TopNewBestAskShowJobs

kbarros

125 karma · joined January 17, 2023

Physicist at Los Alamos National Lab, working in areas of machine learning, high performance computing, quantum chemistry, and physics of magnetic materials.

https://scholar.google.com/citations?hl=en&user=ZmHt6K4AAAAJ

submissionscomments
kbarros··on New horizons for Julia
I'll speak as someone who began as a Julia skeptic, but now finds it invaluable for my day-to-day work. Here are some reasons why you might prefer Rust today:

- Julia's lack of formal interface specification. Julia gets a lot of flexibility from its multi-method dispatch. This feature is often considered a major selling point in allowing code reuse. Many Julia packages in the ecosystem can be combined in a way that "just works". Consider, for example, combining CuArrays.jl with KrylovKit.jl to get GPU acceleration of sparse iterative solvers (https://github.com/Jutho/KrylovKit.jl/issues/15). But it's not always clear who actually "owns" such integrations. Because public interfaces aren't always well documented in Julia, things are prone to breakage, and it can sometimes feel like "action at a distance". This was especially painful with the OffsetArrys.jl package, which suddenly introduced arrays that could begin at any integer index. (That was the major theme of Yuri's blog post, and the simple solution for most people was to avoid OffsetArrays.) Rust's community philosophy and formal trait system err on the side of providing static guarantees for correctness. But these constraints also take away flexibility to fit distinct packages together. For example, Julia has always had excellent support for type specialization, and this has been notoriously challenging to fit into Rust, even in a very limited form: https://users.rust-lang.org/t/the-state-of-specialization/11.... Conversely, there have been many discussions about designing a formal interface system in Julia, but it remains a challenge: https://discourse.julialang.org/t/proposal-adding-optional-s...

- Julia is designed around just-in-time compilation. For example, every time a function is called with new argument types, it will be freshly compiled for that specialization. This is great when you care about getting optimal performance. Also, because Julia allows to reify syntax as value-level objects, you can assemble Julia code that is custom optimized to run-time values. All of this is amazingly powerful for certain kinds of number crunching codes. But carrying around a full LLVM system is clearly a blocker for distributing small, precompiled binaries. Hence the LWN discussion about the preview juliac feature, which will offer a mode for fully static compilation.

- Rust's borrow checker is something to envy. In any other language, I miss the ability to safely passing around references to stack allocated variables, or to know that a referenced value cannot be mutated.

Finally, I would probably recommend Python (not Rust!) for most machine learning or data analysis projects that aren't too "bespoke". There's just so much momentum behind PyTorch and JAX. The Julia community is developing some very interesting packages in this space. Notably, Lux.jl, Enzyme.jl, Reactant.jl, and all of SciML. These are super powerful, but still very researchy. For simple things, Python will probably be less friction.

The best language will depend on your use case. Julia serves its niche very well, even if it doesn't fit every possible use case.

kbarros··on New horizons for Julia
As we've been discussing in another thread, it's possible! One can "opt out" of Julia's dynamic behaviors on a function-by-function basis using the JET.jl tool for static analysis: https://aviatesk.github.io/JET.jl/dev/optanalysis/

Why not make this the default everywhere? Well, there are a lot of scientific use cases where it's convenient to have Python-style dynamic typing and interactivity. A cool thing about Julia is that it allows that, while _also_ allowing to achieve high-performance, all within a single language.

For the record, I do also love the static type system and overall design of Rust. But for my day job (research in numerical methods and computational physics), I find Julia to be the most efficient way to get the job done -- rapid algorithm prototyping, data analysis, plot generation, etc.

kbarros··on New horizons for Julia
Agreed. Julia's combination of REPL + JIT + Revise.jl can feel like magic. The compiler automatically detects changes to your source code and provides hot-code reloading of fully optimized machine code, in the blink of an eye!

Also, it's worth emphasizing that the user experience of Julia has been improving greatly, even in just the last 3 years. Julia 1.9 introduced caching of native code [1], and now at Julia 1.11 the time-to-first-plot in a new Julia process is typically less than a second.

Having said all this, Rust is an absolutely fantastic language too, and might be preferred for large-scale software development efforts where static analysis is prioritized over an interactive development workflow.

[1] https://julialang.org/blog/2023/04/julia-1.9-highlights/#cac...

kbarros··on New horizons for Julia
Dynamic behaviors can be a nice default for all the spots where performance is not critical. So Julia lets you code like Python in places where performance doesn't matter, and then code like C++ or Fortran in places where it does.
kbarros··on New horizons for Julia
> We've had test code that goes from taking 10 minutes to run to over 2 hours because of type instability in a single line of code.

For those who might not be familiar, tooling can sometimes help a lot here. The ProfileView.jl package (or just calling the @profview macro in VSCode) will show an interactive flamegraph. Type instabilities are highlighted in red and memory allocations are highlighted in yellow. This will help to identify the exact line where the type instability or allocation occurs. Also, to prevent regressions, I really like using the JET.jl static analysis package in my unit tests.

kbarros··on New horizons for Julia
Julia is my tool of choice for writing numerical code where performance is critical. I work in computational physics, and have found Julia and its ecosystem to be far nicer than Rust in this space.

It's true that accidental dynamic behaviors are a real concern and can be a performance killer. Fortunately, the language has nice tooling. In VSCode, I often use the visual profiling tool `@profview` to get a flame graph. Anything dynamic gets highlighted in red, and is quick to diagnose. There also exist nice static analysis packages like JET.jl. During development, one can use `report_opt` to statically rule out accidental dynamical behaviors. Such checks can also be incorporated into a project's unit tests. In practice, it's not much of an issue for me anymore. But to be fair, there is a big learning curve for new Julia users. See, e.g., https://docs.julialang.org/en/v1/manual/performance-tips/

kbarros··on Showcasing Makie.jl: From KM3NeT's Neutrino Discovery and Beyond
Makie has grown to become a very powerful tool and an important part of the Julia ecosystem. A few Makie features are especially worth highlighting:

1. Using the "observable" system, it's quite easy to put together simple GUIs with toggles, sliders, etc. This is really nice for interactive data visualization, real time physical simulations, etc.

2. One can (for the most part) smoothly switch between various backend options. GLMakie is the high-performance OpenGL backend. WGLMakie builds on WebGL and can be used in browser context, which is nice in Jupyter notebooks, or in HPC scenarios where the calculation is being performed on a remote cluster. CairoMakie allows for exporting publication-quality vector graphics.

3. A couple years ago there were severe issues with "time to first plot". I'm happy to say that this issue is now (almost completely) fixed! The initial Makie installation will take a couple minutes to precompile and cache object files. But after that, the time-to-first plot in a new Julia session only takes about 1 second.

kbarros··on Ask HN: Has anyone worked at the US National Labs before?
The town of Los Alamos is beautiful, but it's small. It can be a great place if you already a have family that enjoys outdoors activities. Many people prefer to commute from Santa Fe (45 min drive with mountain views, negligible traffic). Certain groups allow a flexible hybrid home/office working mode.

https://www.usnews.com/news/healthiest-communities/articles/...

kbarros··on Ask HN: Has anyone worked at the US National Labs before?
I'm a computational physicist at Los Alamos and would echo these sentiments.

Note that there are two main types of DOE labs: NNSA (Sandia, Los Alamos, Livermore) and Office of Science (Brookhaven, Berkeley, Oak Ridge, Argonne, ...). Although the former is more focused on "nuclear weapons stockpile stewardship", there is still much basic science at all DOE labs, especially where computer science meets physics and other domain sciences.

Perhaps relevant to HN, I would mention the Applied Computer Science group at Los Alamos, which is in hiring mode (https://www.lanl.gov/org/ddste/aldsc/computer-computational-...). Besides supporting computational physicists in code development efforts, this group does a variety of researchy things like designing programming model, doing compiler development, building ML models, especially with an eye towards large scale scientific computing. The pay at a DOE lab is less than FAANG (PhD student interns might be around $80k/yr and starting staff scientists maybe $130k/yr), but the tradeoff for some people would be the research-flavor of the work, and the flexibility. Many of the LANL codes being developed are open source, for example. Other DOE labs have similar computer science divisions. For example, Oak Ridge, Argonne, and Berkeley all have "leadership computing" facilities.