-
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
Bug with init from sol #68
Comments
@ocots Shouldn't it be as below ? I'll try to add your example in CTDirect in test_continuation.jl
|
@ocots Yup, it works. By the way it would be nice indeed not to have to call OptimalControlInit explicitely, maybe I can make it internal in solve ? Te paramtric ocp
The continuation
Result
|
Yes it should be internal but it is nice to have the possibility to fo it externally. |
Todo: avoid code duplication for the initial guess between OptimalControl and CTDirect @ocots I like your idea of having an upper level function that builds a generic functional initialization from the various possible inputs (vectors, functions, solution), used then by each method to generate its own specific initialization.
It would fuse the code currently in https://github.com/control-toolbox/OptimalControl.jl/blob/a7d6aa74d0cc702348861e8a3fb1e17f3e7bf2b4/src/solve.jl and https://github.com/control-toolbox/CTDirect.jl/blob/ed8c6e07126a08190ec53e1a05d4134f4c8fa466/src/init.jl , and I suggest we extend it to the costate as well (all arguments are supposed to be optional with a default constant initialization of 0.1 for instance). I would rather put OCPInit() in CTBase than OptimalControl since adding OptimalControl also adds CTFlows that is not really related to the direct method. A new source file init.jl ? The actual initialization for the direct method is already in a second function CTDirect.initial_guess and would stay more or less the same. I suspect it would require only minimal changes in the indirect part as well ? |
Just note that the init I use in OptimalControl.jl comes from CTDirect.jl |
Yes I saw, this is why I said 'fuse' :D |
Ok, I'll checkout CTBase on my side and try a first version with a PR (unless you want to do it ?) |
You can do it :-) Don't you think that this piece of code inside if isnothing(init)
init = OptimalControlInit()
elseif init isa CTBase.OptimalControlSolution
init = OptimalControlInit(init)
else
x_init = :state ∈ keys(init) ? init[:state] : nothing
u_init = :control ∈ keys(init) ? init[:control] : nothing
v_init = :variable ∈ keys(init) ? init[:variable] : nothing
init = OptimalControlInit(x_init=x_init, u_init=u_init, v_init=v_init)
end Of course, in this case, the function has to be updated. |
Yes ! Ideally OCPInit will accept as many inputs as possible, and handle them to generate the functions for the variables. Then the module-specific functions for generating the actual initial guess and solving the problem can work in a simpler way. This will avoid duplications like when I started to handle in CTDirect the case of passing directly a solution as initialization, while you had already done it in CTBase. |
First version is fine on the CTDirect side, I just replaced the former CTDirect.OptimalControlInit with a new CTBase.OCPInit.
@ocots about the nice code you mentioned, we could simply check in solve if the init passed is a OCPInit struct, and if not call something like `init=OCPInit(init)*. Then we can pass to solve either an OCPInit struct, or whatever the constructor OCPInit() accepts. I'll try that. |
Ok, seems to work. When calling solve we can use both the explicit call to OCPInit or just pass the data for the initial guess. For instance, a mixed functional x / constant u / default v initial guess
and similarly for a warm start
Same for the other functions that take an initialization (directTrancription, setDOCPInit and solve applied to a DOCP instead of a OCP) Changes are in the 'init_CT...' branches for CTBase and CTDirect. I think the only changes left to do are in OptimalControl. @ocots, do you want to do it ? In the end we'll need to do the merge and release for all 3 packages. |
A first release of CTDirect must be done updating the Y of X.Y.Z version. Then, it will be simple to uodate OptimalControl.jl. I will do the update for OptimalControl.jl. |
Release done for CTBase 0.8.0 and CTDirect 0.5.0 |
OK I do asap the release of OptimalControl.jl |
Release done but I forgot to export new functions from |
We'll do it next time :-) |
There is bug in this example: https://github.com/control-toolbox/HMP/blob/main/main.ipynb
If you try to initialize with a previous solution.
See this part:
The text was updated successfully, but these errors were encountered: