Thank you for joining. Let's start. So the next talk is by Daria Klimashetska on physics
in Julia, Floresjers.
All right, so today I will talk a bit about implementing physics in Julia using to quite
important packages, Unitful JL and differential equations JL. If you had heard about Julia
yet, it's the next big thing in scientific modeling. I believe those words describe it quite
well. Julia comes for the syntax, stay for the speed, because it has the Python-like syntax
and the speed of C. But I will not talk about it here, because my concept I will be presenting
is applicable to all kinds of programming languages, not only Julia. Let's start with some
words by Richard Feynman, a famous physicist and a noble prize winner, who once said for those
who want some proof that physicists are human, the proof is in the idiocy of all the different
units which they use for measuring energy. That's why packages like Unitful JL are insanely
useful. They allow to attach units to numerical values in the code, which makes the code
much more readable. Let's take for example the constant G. When we see the units, it's clear
that it's gravitational acceleration and not just some random letter G in the code. It also makes
the code much more maintainable. Unitful also provides tools for conversion, so you don't have to
think about what a femtosecond is or how to convert some ancient units from the article.
It also during the compile time, it checks if the values are dimensionally compatible,
so that we don't add meters to seconds, for example. It also lets you check if the variable
you're using is length or time. It's quite useful and prevents the dimensionality errors in your code.
Besides, when you're plotting your data, it also prevents units automatically to the labels,
but I will come back to that in a bit. What's very important, using Unitful JL,
ensures absolutely no runtime overhead. The other package I was talking about is differential equations
to describe what it does. Let's start from a simple pendulum problem, such as the one shown in
the picture. Some of you may remember from school that it is described by the differential
equation shown on the slide. That equation can be translated into the code in a form of a function,
shown here, which calculates the differential of the state vector.
The differential equations JL lets you solve the problem described by this function in just
two lines of code. The first one defines an ordinary differential equation problem
using the function, the initial state vector, and the time span. And the second one, you just need to
type ODE dot solve, and that's all you need to do. The differential equations JL, it's
very advanced package. It solves not only ordinary differential equations, but also partial differential
equations, it runs on CPU, on GPU, has built in mechanics like adaptive time stepping.
So it's one of the main reasons people use Julia. And yeah, when you solve the equation,
you can just print the output, and we can see that the pendulum changes its position periodically
just as we would expect. And also, we can see that the unit will append that the units
automatically to the labels. So when we have these two very useful packages, why don't we try
combining them together? Let's declare all our constants with the units, and try solving it
using differential equations JL. Unfortunately, that will not work. The differential equations
solver will return error that our values are not compatible with the values demanded by the
solver. What does the community say about that? Well, the errors appear quite often.
The suggested solutions are just dropping the units or using only the very basic solvers,
not the most compatible with our problem. So yeah, that kind of is the point.
I believe that the solution can be found in a book by Percy Bridgman, also an Nobel Prize winner.
Where it's written the astute observer, Fourier was the first astute observer,
notices that the equation remain true when the size of the fundamental units is changed.
Therefore, we can say that physics consists of two parts. One part is mathematical model,
and the other part are constants. Mathematical model by definition does not hold any units.
The units are only in the constants. Therefore, if we look at it from the program, it's point of view.
We can say that the constants in the units are just injectable dependency.
So, if we build a code thinking about that, we can declare all our constants with the units,
everyone, every constant from all of the code, in one instance, such as the main staple here.
Then we can define the function describing the problem, but we have to remember to pass the constants
as part of the parameters in the function. Then those three lines of code appear that can be summarized
to just create a named table that holds the constants, but is stripped of the units.
And then if we try to solve it, it will work. So, basically what I just told you is that if we strip
the units it will work, but that's not the point. The point is that this approach will also work with
the units. If we inject our function with our dependency holding the constants and the units,
here is calculated one step of the solver, and later I check if the calculated state vector
is the same dimension as the initial state vector. And as we can see from the on the screenshot
from the terminal, these two are the exact same one, same dimension. So, our function works with the
units too. So, the take home message from the stock is that there is actually no unit full
real and differential equations, real problem. Our stem equation should just be declared that it's
invariant to the units we use, because the units are only an injectable dependency.
And as it was shown by my colleagues, this approach can also be applied to other
grid compiled text, such as Python combined with non-py and pined, where it also solved the over the
issue. Yeah, so let's apply unit our testing and unique diagnostic numerics.
And yeah, this is not a work around. It's just applying the physics principle in your code.
So, it is also part of the example I propose to add to differential equations,
JL documentation. So, if you have any comments or any questions, you can either ask me here,
because we have some time as I see, or you can leave a comment under the full request.
So, yeah, thank you for our attention.
Thank you questions.
Hi, thanks for the talk. I don't know if you're familiar with type theory, but don't you think
in physics we could solve equations or calculate something with, I don't know,
constants or functions defined as, as, with a type, because from what I understand in your talk,
it's, um, how can I say? For what I understand is like a work around, because you don't have
types for variables or something. I don't know if I'm clear.
I mean, there won't be the units while solving the numeric out part of our code, but the units
can just easily be attached again after, to the solution. So, it just lets you keep your code
kind of organized to the numerical part and to the physical part of the code.
But my question is, if you use language with the type system, don't you think it would be
more easy to work with units, so it's saying like your variable g is a ms something of type ms,
I don't know. Do you think it's, uh, I don't think I understand it to be honest.
Oh, yes, this is the question. Well, I, I use, uh, well Julia provides a way to do with the units,
so that you don't have to worry about that. Uh, like, you know, the conversions and stuff,
it's very useful in the code. And I don't think that using other language would, or, well,
actually have that much. And yeah, okay, thank you.
Uh, there are questions. Let's think this speaker again.