Out of interest I decided to explore sum of squares optimization in the context of Lyapunov functions. Right now I’d like to use it to find the region of attraction for the value function (viewed as a Lyapunov function) of the LQR. As an example I have a single pendulum which I am keeping in its unstable equilibrium using the regulator. As for the approach I am trying to use the “The equality-constrained formulation” in section 9.2.3 of the Underactuated MIT course.
I’ve written the problem using SumOfSquares.jl but even though the simulation shows that the controlled system is stable the region found is practically zero. The script is not too long (83 lines) and hopefully commented thoroughly enough. Any help would be appreciated.
It is quite possible that there is some theoretical mistake based on the fact that I am searching over a region that is a cylinder but to my understanding that shouldn’t be the case.
I suspect (but I am not sure) that the culprit might lie hidden in the way the lifted state variables (c_\theta, s_\theta, \omega) are transformed into the physical state variables (\theta, \omega) around the upper (unstable) equilibrium. Try to run your simulation a bit longer, say, set tspan = (0.0, 10) on line 47 of your code. You will observe that once the pendulum is around the upper position, even tiny oscillations of c_\theta and s_\theta around their equilibrium values lead to a jump in the angle \theta.
By the way, you may have wanted to put -1 instead of 1 on line 54: plt = plot(ts, mapreduce(t -> state_difference(sol(t), [0, 1, 0])', vcat, ts)).
I think that should only effect the plotting, where I have theta=0 at the stable equilibrium. As I linearize the system around the upright equilibrium the controller does behave as it should. I could Indeed somewhat fix it by selecting theta=0 to be at the unstable equilibrium for plotting.
I stripped down the script down a bit. The lyapunov function is now -potential_energy + kinetic_energy. For it, I created the controller ad-hoc. Its first and third term would stabilize the system from any state beside theta=0 so I added the second term to limit the maximum potential ROA. I still run into the same problem.
Mosek terminates early with the status SLOW_PROGRESS for some reason which is probably why the region it too large. I wonder what makes it get stuck and if it could be helped in any way.
From my experience, nonlinear conic optimization has its intrinsic severer numerical issues than linear optimization. Therefore it is not unusual to see Mosek slowing its progress.
Well, I admit did not have prior experience with that equality variant of the ROA optimization problem described in the Tedrake’s notes. But have you tried the more “traditional” inequality one (also described in the notes) for which the constraint would be -\dot V(x) + \lambda(x)(V(x)-\rho) \in \text{SOS}, and \lambda(x)\in\text{SOS}? Of course, you will have to proceed by line-searching for \rho (fixing \rho to some positive value), but that is not a big deal. I am just curious if at least the other approach worked for this system.
Yes, I tried alternating between searching for \lambda(x) and \rho but it again failed with SLOW PROGRESS (not only Mosek but also CSDP), searching for \lambda(x), in the first iteration (I’ve added the script to the gist).
I also tried Hypatia.jl which gave a similar result to Mosek but claimed to be successful. Regarding your result it’s way smaller than I would expect. I also tried searching for a region of attraction when I have the globally stabilizing controller with CSDP and the result was similarly small.
Now that I’ve been thinking about this topic for a bit, I’m not sure I see utility in quantifying the region of attraction using a single value, especially if my Lyapunov function is fixed. It feels like it is restricted by the how the coefficients scale different polynomials. Maybe this also causes some of the numerical issues.
The reason I bring this up is that for the same system I was able to do some cool stuff regarding optimizing a controller for the same Lyapunov function.