Optimization in Julia: Rocket Soft Landing

Igor Shvab
Analytics Vidhya
Published in
3 min readFeb 24, 2022

--

There is new competitor in space of high performance languages tuned for fast computations and general machine learning. Data science practitioners probably noticed slow yet steady rise in applications of Julia programming language.

While created in 2012, now Julia v1.7.2 is still being used predominantly by researchers, for specialized problems that require very fast computations such as real time simulations, robotic control, risk modelling, pharmaceutical modelling, etc. Intrigued by this I decided to reimplement my previous python article on dynamic programming in Julia. Before going into implementation details, few notes on installation and features as compared to python.

  • Julia is general purpose, high level, compiled, and dynamically typed language. Its main selling point is speed. Several benchmark tests shows that Julia is close to C and ahead of Fortran in computation speed, and on average by 2 orders faster than Python or R. Although worth pointing out that very first compilation run in a session can be bit slow.
  • Julia has very light syntax, something in between Matlab and Python. Libraries ecosystem has support for main ML, DL, and optimization methods. Unlike Python, Julia has limited object-oriented capabilities. Array indexing starts from 1.
  • Julia has very good integration with Python and vice versa. It is possible to import and run Python modules and functions using PyCall module. While installing Julia one can either install Python in separate environment inside Julia, or use existing Python installation (conda only).

Hence, companies that use Julia use it for most computationally intense tasks only, while still doing majority of development in Python/R. One can add Julia kernel to jupyter notebook.

In order to get feeling of the language I have rewritten optimization problem of rocket control using JuMP module and Ipopt solver. JuMP is arguably the most known and widely used Julia optimization module that supports number of open-source and commercial solvers for a variety of problem classes, including linear, mixed-integer, conic, and nonlinear programming.

Here, I will try to optimize 2D trajectory of heavy object descending from certain height (say 5km above sea level) and landing softly at desired point, subject to relevant physical forces (gravity pull, rocket engines thrust, wind, etc). For more detail please refer to my previous publication. Full Julia code and python visualization script is available here.

After carefully choosing initial conditions (like entry speed), variable bounds, and different integration scheme, descent trajectory looks much more physically realistic this time.

One can save state and control vectors as numpy arrays using PyCall module and generate landing video in separate python script. Here is example how to call python function inside Julia.

--

--