Julia

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
User avatar
saso
Posts: 1486
Joined: Fri May 16, 2014 1:14 pm
Contact:

Julia

Postby saso » Mon Jan 13, 2020 11:49 am

The Julia Programming Language
https://julialang.org/
Julia was designed from the beginning for high performance. Julia programs compile to efficient native code for multiple platforms via LLVM.
Julia is provided under the MIT license, free for everyone to use. All source code is publicly viewable on GitHub.
Julia Documentation
https://docs.julialang.org/

Learning Julia
https://julialang.org/learning/

Julia for Numerical Computation in MIT Courses
https://github.com/mitmath/julia-mit
High-level dynamic programming languages (as opposed to low-level languages like C or static languages like Java) are essential for interactive exploration of computational science. They allow you to play with matrices, computations on large datasets, plots, and so on without having to worry about managing memory, declaring types, or other minutiae—you can open up a window and start typing commands to immediately get results.

The traditional problem with high-level dynamic languages, however, is that they are slow: as soon as you run into a problem that cannot easily be expressed in terms of built-in library functions operating on large blocks of data ("vectorized" code), you find that your code is suddenly orders of magnitude slower that equivalent code in a low-level language. The typical solution has been to switch to another language (e.g. C or Fortran) to write key computational kernels, calling these from the high-level language (e.g. Matlab or Python) as needed, but this is vastly more difficult than writing code purely in a high-level language and imposes a steep barrier on anyone hoping to transition from casual experimentation to "serious" numerical computation. Julia mostly eliminates this issue, because it is carefully designed to exploit a "just-in-time compiler" called LLVM, making it possible to write high-level code in Julia that achieves near-C speed.
Using Julia's Type System For Hidden Performance Gains
https://www.stochasticlifestyle.com/usi ... snotation/

7 Julia Gotchas and How to Handle Them
https://www.stochasticlifestyle.com/7-j ... as-handle/

Type-Dispatch Design: Post Object-Oriented Programming for Julia
https://www.stochasticlifestyle.com/typ ... ing-julia/

A Comparison Between Differential Equation Solver Suites In MATLAB, R, Julia, Python, C, Mathematica, Maple, and Fortran
http://www.stochasticlifestyle.com/comp ... c-fortran/

I Like Julia Because It Scales and Is Productive: Some Insights From A Julia Developer
https://www.stochasticlifestyle.com/lik ... developer/

Algorithm efficiency comes from problem information
https://www.stochasticlifestyle.com/alg ... formation/

Why Numba and Cython are not substitutes for Julia
https://www.stochasticlifestyle.com/why ... for-julia/

Some State of the Art Packages in Julia v1.0
https://www.stochasticlifestyle.com/som ... ulia-v1-0/

Julia and DifferentialEquations.jl
https://www.youtube.com/watch?v=zJ3R6vOhibA

A Deep Introduction to Julia for Data Science and Scientific Computing
http://ucidatascienceinitiative.github.io/IntroToJulia/

The Essential Tools of Scientific Machine Learning (Scientific ML)
http://www.stochasticlifestyle.com/the- ... ntific-ml/

How To Train Interpretable Neural Networks That Accurately Extrapolate From Small Data
https://www.stochasticlifestyle.com/how ... mall-data/

Universal Differential Equations for Scientific Machine Learning
https://www.youtube.com/watch?v=bBH8HVEr0-A

Parallel Computing and Scientific Machine Learning (MIT Course)
https://github.com/mitmath/18337

Special Subject in Mathematics: Applications of Scientific Machine Learning (MIT Course)
https://github.com/mitmath/18S096SciML

SciML: An Open Source Software Organization for Scientific Machine Learning
https://sciml.ai/2020/03/29/SciML.html

Almost Trivial: Parallelizing a Specialized Matrix Type in Julia
https://mdavezac.github.io/blog/

Julia Programming’s Dramatic Rise in HPC and Elsewhere
https://www.hpcwire.com/2020/01/14/juli ... elsewhere/

Large Scale WinD Farm Optimization Integrating Julia with OpenMDAO
https://www.youtube.com/watch?v=_V7xrvXiESc

Link to a previous forum post on some of the Julia packages (and some other things)
https://forum.freecadweb.org/viewtopic.php?f=8&t=40775
Last edited by saso on Sun Mar 29, 2020 3:22 pm, edited 15 times in total.
User avatar
saso
Posts: 1486
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: Julia

Postby saso » Mon Jan 13, 2020 12:34 pm

A short note to the topic...

So over the last two months, since I have first made a post on DifferentialEquations.jl and DiffEqFlux.jl (https://forum.freecadweb.org/viewtopic.php?f=8&t=40775) I have been slowly reviewing more and more in to Julia and related topics. In the beginning the idea was that they could maybe be helpful for us to just do some quick testing, researching, prototyping and benchmarking the different solvers and code implementations before doing the implementation in FreeCAD with Python and/or C++, but over time the idea of having Julia available directly in FreeCAD started to make more and more sense. It is not about replacing Python or C++ with it, actually it is able to work very well with both of them. And I would say it would probably be best to use it only (mostly) just for the computationally heavy stuff (not GUI or so) and as such it would probably also not be a big problem as a dependency for packaging/building.

Of course it is possible to use it already with FreeCAD if the user sets it up with Python or Jupiter etc but this is useful then only for some more specific needs of the individual user. It is of course just a proposal, to hear others opinion on it, but developing such things like the constraint solvers (https://forum.freecadweb.org/viewtopic.php?f=20&t=40525) or the fcFEM (https://forum.freecadweb.org/viewtopic.php?f=18&t=33974) with Julia would probably make sense. For ODE/PDE solvers for example, there are numerous tricks and optimization techniques to speed them up and packages such as DifferentialEquations.jl, SUNDIALS, CasADi, PETSc,... can easy be compared to geometrical kernels for brep modeling, saying that it is probably questionable if we should really be writing this on our own, Julia has some very strong support for this. And not just that it achieves near-C speeds, for a lot of its packages it also has support for running the code on GPU, could this make fcFEM execute in almost real time, like ansys discovery live (creo simulation live) ?! :roll:
Last edited by saso on Thu Jan 16, 2020 1:16 pm, edited 4 times in total.
User avatar
looo
Posts: 3283
Joined: Mon Nov 11, 2013 5:29 pm

Re: Julia

Postby looo » Mon Jan 13, 2020 1:40 pm

I see Julia as an alternative to the python world. Julia allows faster computation but is still a very new language. Introducing Julia to freecad is a more difficult task than one might expect.

I guess pythons advantages is the clean syntax and the big user base. Accelerating python via jit is possible with numba which is in my eyes a good approach to speed up more time intensive functions.
With binding tools like pybind11 it's also quite simple to speed up things with c/c++.

In my eyes a lot of bubbeling is build around Julia via advertising. At least this is the impression after receiving some mails every month which tells me to switch to Julia.... I guess Julia is not only a community driven approach and therefore advertisement should be consumed carefully.

So from freecad perspective we should better concentrate on the python approach. There is a lot of things which can be optimized. In the long run bubbles will burst and only the working stuff will survive.
triplus
Posts: 9416
Joined: Mon Dec 12, 2011 4:45 pm

Re: Julia

Postby triplus » Wed Jan 15, 2020 7:18 pm

Unless some big revolution happens in a foreseeable future i feel that Python is the place to be.
User avatar
saso
Posts: 1486
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: Julia

Postby saso » Mon Feb 10, 2020 10:02 am

Well, as I have said before, this is not about removing Python from FreeCAD but to add Julia as another "computational engine" to it and for the beginning it was also not meant as to start any development now, but just to share some links, collect some knowledge and do some research on it, so that users who are new to it can learn something and users who have already some knowledge and experience with it can give some opinions...
Last edited by saso on Mon Feb 10, 2020 10:07 am, edited 1 time in total.
User avatar
saso
Posts: 1486
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: Julia

Postby saso » Mon Feb 10, 2020 10:03 am

Continued from https://forum.freecadweb.org/viewtopic. ... 30#p367810
ChrisRackauckas wrote:
Sun Feb 09, 2020 10:31 pm
Hey,
This is Chris Rackauckas, developer of DifferentialEquations.jl and author of StochasticLifestyle.com. Wordpress stats led me over to this community and I found there's some fun discussion. Let me know what your community would need out of differential equation solvers and modeling tools to best support your activities. We'll soon be releasing a bunch of blog posts on PDE-constrained optimization and automated learning of partial differential equations with universal differential equations (showing more of the sparsity techniques to go beyond https://arxiv.org/abs/2001.04385). I'm not much of a CAD guy but if you let me know what you guys need we can work it into our development roadmap and research! Indeed, a lot of our DAE work started because Hilding Elmqvist (inventor of Modelica) transitioned fully to Julia (Modia.jl) and he had a lot of questions to support tooling for his next gen Modelica. If you let us know what FreeCAD needs, we can work it into the Julia Lab's research and our next round of GSoCs :D .
I guess the first thing where some help would be very appreciated would be with the development of our 2D/3D constraints solvers (recent topic on this https://forum.freecadweb.org/viewtopic.php?f=20&t=40525), it represents a very basic and core functionality for our program and as such it is really needed. I guess if we decide to continue develop this in C++ there is not so much interest from you (or the bigger Julia community) to do much of an collaboration in the sense of code development but even at least some advice on the solvers choice and implementations could be very helpful.

Moving a bit further from the basic constraints there is the need for kinematics, also where things related to Modelica start to come in to question (I guess roughly we could define it as the domain of ODE's) and then even further in to FEM/CFD (PDE's). And additional to this "user defined" simulations there is then also the need for optimization/surrogate modeling and design space discovery with the more "classical" methods and as the new possibilities with NDE/UDE's... Maybe this topic https://forum.freecadweb.org/viewtopic.php?f=24&t=41605 of the airfoils workbench and its targets gives a nice example of one such possibility (but in the general computer aided engineering there are endless such examples). My post in that topic https://forum.freecadweb.org/viewtopic. ... 30#p356752 and the videos of a recent OpenMDAO Workshop https://www.youtube.com/user/OpenMDAO/videos can give some more ideas around that. And I am guessing that if we would do this in Julia then there would also be quite some interest on it from your side (and possible the bigger Julia community)?

Realizing at least a small part of this big dream, with a bit of collaboration and help of a few GSoCs, would be huge :)
Last edited by saso on Thu Mar 12, 2020 11:03 am, edited 1 time in total.
adrianinsaval
Posts: 310
Joined: Thu Apr 05, 2018 5:15 pm

Re: Julia

Postby adrianinsaval » Tue Feb 11, 2020 8:40 pm

maybe they can give an alternative to solvespace? It is my understanding that solvespace's license (among other things) is impeding the inclussion of assembly3 in the FreeCAD source code