-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export _OptimalControlSolution
#74
Comments
Hi @paraynaud , great timing :D Don't hesitate to put your feedback here ! |
Thanks @PierreMartinon for adding those features. |
Doc pending. |
Hi @paraynaud ; just gave a try to your problem: solves fine 👍🏽. Regarding the dynamics, or expressions in # invest.jl
using OptimalControl
T = 1
β = 0.2
γ(t, x) = 3 * exp(-β * t) # yield
x0 = 0.1 # initial capital
@def ocp begin
t ∈ [ 0, T ], time
x ∈ R, state
u ∈ R, control
0 ≤ u(t) ≤ 1
x(0) == x0
ẋ(t) == γ(t, x(t)) * u(t) * x(t) # capital dynamics
∫( (1 - u(t)) * x(t) ) → max
end
sol = solve(ocp)
plot(sol) |
@paraynaud please consider adding some comments / motivation / context for your example and including it in OptimalControl.jl tutos |
@paraynaud I did a more 'raw' version of the export, is this what you had in mind ?
|
@PierreMartinon @gergaud @ocots Regarding optimisation solvers: as for plots (WIP on recipes), it would be nicer (and seems possible) to keep the solver outside our packages
For instance, in the spirit of using OptimalControl
using ADNLPModels
@def ocp begin
...
end
docp = discretise(ocp, model=:adnlp)
dsol = solve(docp)
sol = foo(ocp, dsol) # needs a better name 🥲
plot(sol) NB. This is strongly related to having a proper interface defining what traits a "discrete optimal control problem" should have. |
It is certainly possible, the current way is quite close.
Your foo is actually called
I also keep a solveDirect(ocp, ...) that does everything in one call and returns the OCP solution. |
@PierreMartinon I think we need to keep track (= pass as an arg) the original ocp to build a proper optimal control solution (e.g. to know that the variable, state and control dimensions, their names for further plotting, etc.) hence the signature sol = OCPSolutionFromDOCP(ocp, docp) I am assuming that Regarding
NB. The name is much better but too long 🥲. Should check what the standard for conversion functions in Julia is (typeA2typeB, typeBfromtypeA, typeBoftypeA...) |
A few precisions regarding DOCP:
As for the solve, the question of the interface is still open yes. I guess more use cases are needed to better see what is the most practical. Although I think we definitely need to keep at least some form of a solve() function. Users can still use their own solving method on the NLP from DOCP, and call the solution generation afterwards. For development I will keep a solve somewhere in CTDirect since I need to be able to solve a problem using just CTBase and CTDirect. |
Hi @paraynaud ; any feedback on #74 (comment) above? |
Hi @jbcaillau, I've been quite busy by personal stuffs lately. |
@paraynaud no worry! courage. quite a few things in order (check control-toolbox/CTBase.jl#173), we keep in touch. |
Hello, I recently gave a student lab in which I used the great work done in #73 to extract an
ADLNPModel
:I asked my students to solve the problem using:
sol = solveDOCP(docp)
which uses Ipopt;percival(nlp)
a solver fromJuliaSmoothOptimizers/Percival.jl
;and to print the solution, which is straightforward once
sol
is obtained, i.e.plot(sol)
.However, it is less direct from the solution returned by
percival
.I found the function
_OptimalControlSolution(...)
to build a proper solution from theGenericExecutionStats
thatpercival
returns:which can be printed with
plot(sol)
later.As the
ADNLPModel
is not only embedded indocp
anymore, It would be quite interesting for users wanting to test their own solvers to highlight the feature that_OptimalControlSolution
provides.Currently, it needs a full
GenericExecutionStats
, but I believe the resulting vector should be enough, as the rest of the information could be inferred fromdocp
.That way, a user could implement its own solver without having to fully understand what a
GenericExecutionStats
is.Thanks for your work !
The text was updated successfully, but these errors were encountered: