ModelingToolkit Nonlinear Optimal Control

I ran the example nonlinear optimal control problem in the documentation, reproduced below:

using ModelingToolkit

@variables t x(t) v(t) u(t)
@parameters p[1:2]
D = Differential(t)

loss = (4-x)^2 + 2v^2 + u^2
eqs = [
    D(x) ~ v - p[2]*x
    D(v) ~ p[1]*u^3 + v
]

@named sys = ControlSystem(loss,eqs,t,[x,v],[u],p)

dt = 0.1
tspan = (0.0,1.0)
sys = runge_kutta_discretize(sys,dt,tspan)

u0 = rand(length(states(sys))) # guess for the state values
prob = OptimizationProblem(sys,u0,[0.1,0.1],grad=true)

using GalacticOptim, Optim
sol = solve(prob,BFGS())

My question is now how do we interpret the solution?

The solution is a 142 element vector. I am guessing it contains all the information required, including values of state variables at the discretized time points, values of the control variable in the time elements, and possible some values related to the collocation nodes. However I am unable to deconstruct and extract this information. Any information on how to interpret and extract the state and control variable values at various time points will be welcome.
Thanks in advance.

Yeah that’s being changed/removed etc.

Wow that was a quick response!
Meanwhile, any tips on how to proceed, or its best just to wait for the release of a new version?
Thanks.

ControlSystem is being entirely deleted because it’s handled instead by input/output specifications on ODESystem. The pieces of ControlSystem that exist are incomplete anyways. In the meantime, you could write stuff on ODESystem that adds optimal control features, or wait for someone else to do it, but it’s not in a satisfactory state right now.

1 Like

OK thanks for the info.