GPU vendor-agnostic fluid dynamics solver in Julia
b-fg.github.io
b-fg.github.io
I wonder if there's a way to share the data buffer across languages. Would be neat if it was feasible to use the real time model data in a game.
This is pretty much what Arrow is made for.
Interesting! Don't think I've seen this one.
Edit: I'm surprised to not find anything when I try to find projects that try to use Apache Arrow in unity 3d. Seems to be a lot of interesting potential in leveraging various simulation libraries in game like applications.
Edit2: Ah, probably because something like waterlilly would have to be rewritten quite a bit too use arrow.
We know macros are awesome, but if you're trying to convert others please provide code, screenshots, or even an interactive web demo.
If you refer to the blog post that made Top HN yesterday, it is very much backed by actual experience (https://nyxt.atlas.engineer/) and quite a load of code (https://github.com/atlas-engineer/nyxt/tree/master/source).
For example:
julia> Meta.show_sexpr(:(f(x, g(y,z))))
(:call, :f, :x, (:call, :g, :y, :z))
Lastly, this old doc page comparing and contrasting Julia with Common Lisp is a fun read: https://docs.julialang.org/en/v1.3-dev/manual/noteworthy-dif...
https://en.wikipedia.org/wiki/History_of_the_Dylan_programmi...
https://en.wikipedia.org/wiki/Apple_Dylan
Nowadays still alive as Open Dylan,
https://www.siscog.pt/en-gb/products
https://www.siscog.pt/en-gb/news/siscog-sponsors-the-2022-eu...
The original purpose of GPUs were visualization, so that seems backwards to me. And, GLMakie is used, which makes it even more counter-intuitive, isn't that specifically built for GPU visualization?
It reads and writes a lot like python (but nicer IMO), I don't think the learning curve is immense to try it for small optimizations. And it's also not unreadable so other people can verify your code
JuliaCall[1] and RCall[2].
Python<->Julia is similarly well exercised with PyCall[1], and recently PythonCall[2].
[1] https://non-contradiction.github.io/JuliaCall/index.html [2] https://github.com/JuliaInterop/RCall.jl [3] https://github.com/JuliaPy/PyCall.jl [4] https://cjdoris.github.io/PythonCall.jl/stable/
likewise if you are solving differential equations, DifferentialEquations.jl is hugely better than any free alternative I know of and arguably better than paid packages. The broader SciML ecosystem that's built up around this has a lot of cool stuff in it too.
other than this it seems like you wouldn't care about the other potential advantages, and might be more put off than average by the disadvantages and occasional rough edges.
> unless it has interesting packages/functionality that my current toolset does not
Multiple dispatch, code-specialization, JIT compiling, automatic loop fusion, broadcasting, many ways of doing compile-time optimizations.... I'm sure there's more.
But I guess you can dismiss these features the same way that you dismiss "the code auto-differentiates" or "it's faster".
I have to shoutout Chris Rackauckas for being a such badass, helpful person too. He'll probably be in this thread any minute because he's the best damn advocate for Julia there is. :-)
But "best damn advocate" is probably the opposite of how I'd describe him in terms of interactions here (and generally with people outside the core Julia circle). He very often comes across as dismissive, overly defensive, and passive aggressive in comments here. All of that is dwarfed by his package contributions tbh, in terms of impact on Julia. But still, probably half of the negative perception about Julia community that people have, come from reading these interactions.
Let the language optimize more so you don't have to write a C++ library or figure out how to use it optimally. Don't waste as much time setting up your environment or worrying about platform compatibility. Don't worry about using multiple languages for different types of computation. And make the on-ramp fairly painless by being a convenient glue language.
It fills the gap of otherwise not having a managed and JITed language for general mathematical computation. If it's more burdensome for you to switch, then don't switch.
Moreover, I think sometimes people get their PhD and think they deserve to use the tools they put in their toolbox, on the problems they focused on, and don't see that all they really did was get a ticket to the game. Most scientists have a phd. Most scientists don't work on the thing their PhD is about ten years later. The sooner you open up to that the sooner you will get out of the postdoc chase and get a job that is a lot more rewarding (both intellectually and financially). All this means that there may be problems you are going to learn about and focus on that you never thought you would at some point, and being open to that and seeing it as an opportunity will carry you further then not.
What I always tell people is the following:
If you are writing code using existing libraries then use whichever language has those languages. The NN stack(s) in Python are great, the statistical ML stack(s) in R are simple and include SOTA techniques.
If you are writing a package yourself, then I assume you know the core of the idea well enough to be able to write your code from the "top down" i.e. you're not experimenting with how to solve the problem at hand, you're implementing something concretely defined.
In this case, and tailored to your use, I would argue that Julia has more advantages than disadvantages, especially compared to R or Python. Here are a few comments:
1. Environments, dependencies, and distribution can all be handled by Pkg.jl, the built in package manager. There is no 3rd party tool involved, there is no disagreement in the community on which is better. This is my biggest pain point with Python.
2. Julia's type system both exists and is more powerful than that of Python (types or classes) and R (even Hadley's new S7(?) system). By powerful I mean generics/parametric types and overloading/dispatch built in. You can code without them, but certain problems are solved elegantly by them. Since working heavily with types in recent years, I find this to be my biggest pain point in R and I wouldn't want to write a package in R, although I like to use it as an end user.
3. New developments in scientific programming, programming ergonomics, hardware generic code (as in this post), and other cool features happen in Julia. New developments in statistics happen in R (and increasingly Julia), new developments funded by big companies happen in Python.
4. The Python and R interpreter start up faster than Julia. The biggest problem here is when you are redefining types, which is the only thing in Julia that can't currently be "hot reloaded" i.e. you need to restart Julia to redefine types.
5. Working with tabular data is (currently) far more ergonomic and effortless in R than Python and Julia.
6. Plotting is not a solved problem in Julia. Plots.jl is pretty easy and pretty powerful, Makie.jl is powerful but very manual. Time to first plot is longer than R or Python.
7. Julia has almost zero technical debt, R and Python have a lot. Backwards compatibility is guaranteed for Julia code written in >v1.0 and Pkg.jl handles package compatibility. If I send you code I wrote 4 years ago along with a Project.toml containing [compat] information then you could run the code with zero effort. (This is the theory, in practice Julia programmers are typically scientists first and coders second, ymmv.)
8. You can choose how low level you want your code to be. Prototyping can be done in Julia, rewriting to be faster can be done in Julia, production code can be done in Julia. Translating Python to C++ production might mean thinking about types for the first time in the dev process. In Julia, going to production just means making sure your code is type stable.
But, there are still reasons I reach for Julia.
Interesting packages where I prefer Julia over Python/R: Turing.jl for Bayesian statistics; Agents.jl for agent-based modelling; DifferentialEquations.jl for ODE solving.
I would much rather data-munge tabular data in Julia (DataFrames.jl) than Python, though R is admittedly quite nice on this front.
Personally I reach for Julia when I want to use one of the previous packages, or something which I want to code up from scratch, where base Julia is much preferable to me than numpy.
This ambivalence might sound absurd on the face of the exponential recent growth of Python (which apparently enticed even some people with serious mojo to get into the act) but take two steps back with me and look at the big (if still hazy) picture:
We are going through a remarkable period where complex algorithmic applications left academia and research labs and diffuse into mainstream society and the economy like never before. This process carries enormous risks and opportunities, which are currently basically... ignored (well, the risk side).
Despite its undeniable strengths and loveability, Python is actually a poster child of the move-fast-and-break-things phase. It is not necessarily best placed for the next phase. The next phase will invariably see a re-examination of all aspects of the stack and qualities that will be prized will be those that eliminate the frictions and risks associated with the large scale deployment of algorithms. The stakes are high, which means there will be plenty of resources seeking to create reliable platforms. The future need not look like the past.
None of the usual suspects ticks all the boxes. In fact we don't even know all the boxes yet. Depends how fast and how seriously models and algorithms get deployed at scale. Python, Julia and R have been propelled forward by circumstances as the main algorithm-centric platforms, and they have each their various warts and blessings but the near and mid-term future will test how well they can deliver on aspects they may have not be designed for.
What risks are you talking about here?
It sounds absurd because trends don't reverse overnight. You can be fairly confident that Python will be the top language in this space for a while and that R will never be the top choice for most applications.
But now is a time where at various high places people will say: "Ok you got my attention. What is this snake language you are talking about and explain why I should bet the house on it".
And the answer is not simple.
https://www.tiobe.com/tiobe-index/perl/
https://www.tiobe.com/tiobe-index/objective-C/
In 2006 (for Perl) and 2014 (for Objective-C) it was clear they had the momentum for their particular space however their limitations were well known and as soon as a better language came along the momentum flipped in an equally dramatic manner. Python is much more widespread so it will remain strong in some areas but you could see the flip in ML/DS given challenges productionizing across broad capabilities (not just doing NN's).
As the joke goes -- python is the second best language for everything, if you know only two languages. With ML expanding beyond narrow big tech domains there will be need for specialized languages like Julia (and others perhaps like Mojo etc..)
Why are you asking to be convinced if you don't want to be convinced?
I love Python, but I can also see eventually doing everything in Julia over the longer term. Mind you, it's entirely possible that AI continues to improve and in 5 years any package will be available in any language, you'll look at code mainly for verification purposes in whatever language you happen to prefer.
If you're writing code that is fundamentally based on mathematical principles and models, even if you aren't personally using mathematics every day, its going to feel a lot better in Julia. That is: Julia looks a lot more like mathematics than Python.
__
Longer version:
Obviously some people are mostly writing websites or GUIs or whatever in Python and won't see the beauty in this.
But if the problems you are working on have, at their base, a mathematical foundation (even if you don't actively practice the math), it's much more beautiful IMO. So, simulation, data analysis/science and machine learning, statistics, etc...
Once you get used to using it for that though you'll realize it's actually quite nice for a lot of other things as well and the "mathematical mindset" it somewhat pushes results in cleaner solutions for other problems too. Just in general the syntax and patterns are nice.
Here are some quick things using randomness in Julia that would be a bit slower and more verbose in Python:
Generate a random number:
> rand()
Pick a random message:
> rand(["First message", "Hello", "Foo"])
Generate a random 3x3 matrix of booleans
> rand(Bool, (3,3))
Define a function and run it elementwise on a random matrix of bools:
> myprint(x)= x > 0 ? "Happy" : "Sad"
> B=and(Bool, (3,3))
> myprint.(B)
Returns:
> 3×3 Matrix{String}:
> "Happy" "Happy" "Sad"
> "Sad" "Happy" "Happy"
> "Sad" "Happy" "Happy"
And many many more nice features...but the Julia design meaning functions like rand() just apply how you expect regardless of the input type are quite nice. rand(list of stirngs) *should* give me a random string and rand(range of numbers) *should* give me a random number in that range! No one would write an academic paper and define a new rand function for each input because well...it's clear what the user wants - rand of something.
Just in case it confuses anyone else: this one is supposed to be `rand` as well, not `and`.
Wales (the animal) oft have barnacles on the leading edges of their flippers, which results in an eddy effect which increases efficiency/thrust.
Da Vinci was the earliest known documentor of eddy-based pumps and predicted the eddies in the ventricular systems of the hearts pumping of blood...
What I would like to model is a toroidal propeller with leading edge bumps ('barnacles') while also having the dimpling pattern of a golf ball to reduce drag... and I want to measure if this idea holds water.
I just dont know how to model this using this tool...
help?
Also, will 'waterlilly' work with a viscosity to Air?
Meaning - toroidal props are a newer entering thing in drones... and I'd like to find out if the above applies equally to fluid/air?
The point of golf ball dimples is to act as vortex generators and improve flow attachment, so having both barnacles and dimples is redundant.
Building a model, on the other hand, could potentially involve a multi-year effort to re-educate yourself to learn how to build models, having to acquire hardware and materials, and setting up a lab for testing. And then building many different actual models.
and i didnt give the following context:
Like JWST "variential dimples and bumps via hydrolic mechanisms, for optimised flow" now we have the hard part added in. (dimple flexing) and there are more levels than that.....
To be clear, I think adding vortex generators to boat propellers is a great idea. But to me the starting place would be a building physical propeller with vortex generators (even if they aren't the perfect vortex generators) and seeing if it has a noticeable impact on boat performance. That would justify the difficulty/time required to build a CFD model which you could use to optimize the design. (I'm saying this given that you don't have experience in CFD and it would be a large outlay of your own time to learn how to use it.)
Building a physical model, on the other hand, merely requires 3D printing the desired shape, doing some sort of casting process to get that out of metal, putting it on a boat, and seeing if you get a noticeable performance impact.
It's one of these situations: https://xkcd.com/1425/
> Building a physical model, on the other hand, merely requires 3D printing the desired shape, doing some sort of casting process to get that out of metal, putting it on a boat, and seeing if you get a noticeable performance impact.
I love how you sneak the word "merely" in there, when for people like me, and presumably the asker, this would be a Herculean task :D
That's an incorrect premise. The asker is clearly not in a position to use an off the shelf CFD package because they don't have the solid basis in fluid mechanics required to interpret the results.
I think maybe you/the asker are thinking of CFD like a tool that simulates fluids. That's not what it is. It's a set of approximations which, sometimes, are applicable to specific circumstances. Even LES, the most general tractable model, requires you to make informed assumptions about the boundary conditions.
> I love how you sneak the word "merely" in there, when for people like me, and presumably the asker, this would be a Herculean task
I'm sure building a physical prop would be challenging if you had no experience, but it is the sort of thing a lot of people can learn from Youtube and do in their garage.
- https://en.wikipedia.org/wiki/Tubercle_effect
- https://arc.aiaa.org/doi/abs/10.2514/1.J050631
- https://physics.paperswithcode.com/paper/effect-of-leading-e...
Enjoy!
I really think there is something here
So we look at the actions of the faster currents as the flipper cuts through, and where does the current flow, such that you can direct micro currents to the other bumps and managing overall flow... such that certain bumps 'feed' others...
and if they are maleable, and you can manage each...
[0] https://news.mit.edu/2016/morphing-airplane-wing-design-1103
[1] https://news.mit.edu/2019/engineers-demonstrate-lighter-flex...
-
The best arch for dividing a sphere is a hexagon.
The idea for dimpling comes from the honeycomb sandwich design patterns we have for use in structurally solid airplane components, coupled with a micro design for stem-cell research from someone from University of San Francisco....
She was building a micro printed 'injector' where she would inject proteins to various stem cell pods.
She would then measure the various cells to see how she could get them to express in a desired outcome....
The hex is from some top secret shit I saw back in the day...
SO... I am thinking that one can util the hex layout and by slurping/pumping vacuum or hyrdo, one can manipulate the dimples on an interface.. on a toroidal propeller in water, pressure is equalized in a certain way to allow live dynamic prop deformations....
In a helo blade it has to be gas activated. but the material overlay has to be able to handle millions of deformations on an individual cell or a neighborhood of cells to reduce piping.
leading edge bumps inflate on way out and release to tailing edge bumps on exit...
For 3 weeks? Because that's how old those release notes are.
Summarizing, they benchmark some machine learning code that uses KernelAbstractions.jl on different platforms and find:
* AMD GPU is slower than CPU
* Intel GPU doesn't finish / seems to leak memory
* Apple GPU doesn't finish / seems to leak memory
Would also be interesting to compare the benchmarks to hand-written CUDA kernels (both in Julia and C++) to quantify the cost of the KernelAbstractions layer.
Oceananigans.jl has really intuitive step-by-step examples and a great discussion page on GitHub.
To be truly vendor-agnostic it needs to support OpenGL or Vulkan.
Also this is the first time I saw examples of Julia code and the syntax looks worse than C++.
For someone who writes both Julia and C++, the above comment comes across as an obscene joke.
Possibly, you object to the programming style in that library, the choice of identifiers or whatever? But that has nothing to do with language syntax.
Julia is flexible enough that you can essentially define domain specific languages within Julia for certain applications. In this case, we are using Julia as an abstract front end and then deferring the concrete interface to vendor specific GPU compilation drivers. Part of what permits this is that Julia is a LLVM front end and many of the vendor drivers include LLVM-based backends. With some transformation of the Julia abstract syntax tree and the LLVM IR we can connect the two.
That said we are mostly dependent on vendors providing the backend compiler technology. When they do, we can bridge Julia to use that interface. We can wrap Vulkan and technologies like oneAPI.
https://github.com/JuliaGPU/Vulkan.jl https://github.com/JuliaGPU/oneAPI.jl
As for syntax, Julia syntax scales from a scripting language to a fully typed language. You can write valid and performant code without specifying any types, but you can also specialize methods for specific types. The type notation uses `::`. The types also have parameters in the curly brackets. The other aspect that makes this specific example complicated is the use of Lisp-like macros which starts with `@`. These allow for code transformation as I described earlier. The last aspect is that the author is making extensive use of Unicode. This is purely optional as you can write Julia with just ASCII. Some authors like to use `ε` instead of `in`.
ex.head == :. && return union!(sym,[ex])
start = ex.head==:(call) ? 2 : 1
Also I don't like |> combination because it is hard to type. Why not use just single pipe character.And macro definition code looks quite different from 'regular' code since it works so much with expressions and symbols.
That's surely an exaggeration, but just for context, most Julia code isn't nearly this macro-heavy. The first half of the final code showcase is all macros and expression manipulation, and those always look a bit weird. Usually, those comprise less than 10% of your code though; and if you're a regular user and not a package author, probably much less than that.