- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 217
feat: create JuMPControlProblem for optimal control #3549
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
base: master
Are you sure you want to change the base?
Conversation
@ChrisRackauckas assuming this passes stuff I think it's ready. |
Requires SciML/SciMLBase.jl#996 |
test/extensions/jump_control.jl
Outdated
@testset "ODE Solution, no cost" begin | ||
# Test solving without anything attached. | ||
@parameters α=1.5 β=1.0 γ=3.0 δ=1.0 | ||
@variables x(..) y(..) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I have to define the variables to optimize over using x(..)
? What if I want to solve an OC problem with components defined in MTKstdlib? Those components have x(t)
variables. It would be nice to have a test for that use case as well since component-based modeling would be the fundamental reason to use MTK over any other tool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that's just if you also want to evaluate them at a point, since this just late binds t
. We could also make an evaluate
operator or something that is the same as evaluate(x(t), 0.2) == x(0.2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add a component test case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there appears to be no tests that the dynamics are satisfied, testing the transcription. This could be tested by simulating the system using the found optimal control included with an interpolation
Sorry yeah I've converted it to a draft for now since stuff is still being added. https://infiniteopt.github.io/InfiniteOpt.jl/stable/develop/extensions/#Derivative-Evaluation-Methods looks like we can extend InfiniteOpt to add our own derivative methods. Should I just do this for all the ODE tableaus we have (like define a This also means we wouldn't have a separate |
Later step, let's do one step at a time.
That's interesting, I wonder why it's actually better.
I think for benchmarking purposes it's good to have both. |
I tried specifying a minimum-time problem, but got an error # Double integrator minimum time
t = M.t_nounits
D = M.D_nounits
@variables x(..) v(..)
@variables u(..) [bounds = (-1.0, 1.0), input = true]
@parameters tf
constr = [v(tf) ~ 0.0, x(tf) ~ 0]
cost = [tf] # Maximize the final distance.
@named block = ODESystem(
[D(x(t)) ~ v(t), D(v(t)) ~ u(t)], t; costs = cost, constraints = constr)
block, input_idxs = structural_simplify(block, ([u(t)], []))
u0map = [x(t) => 1.0, v(t) => 0.0]
tspan = (0.0, tf)
parammap = [u(t) => 0.0, tf=>1.0]
jprob = JuMPDynamicOptProblem(block, u0map, tspan, parammap; steps = 51)
jsol = solve(jprob, Ipopt.Optimizer, :Verner8)
|
Added your free final time problem as a test case, think it should be working now. This rocket launch error with InfiniteOpt seems pretty elusive. I can't find any error with the model specification, but the dynamics that it comes up with are impossible given the controller... What should the output of plotting the DynamicOptSolution? Two side-by-side plots of the inputs and states? I can add an overload for it where the plot recipes go. |
Is there a reason to not just make the solution an ODESolution? Add a residual term to that? |
Just thought this would make it easier for plotting purposes. Symbolic indexing is kind of weird in this case since inputs are usually non-discrete parameters and doing |
Also useful to return the JuMP model so they can inspect the objective value and stuff like that |
@baggepinnen For the rocket launch input solution being wrong, It may just be that OrthogonalCollocation for InfiniteOpt is a bit strange, I tested it with implicit Euler and got this, which still doesn't look like the original solution but gives the right dynamics when I simulate the ODEProblem using it |
will add optimal control tests here when the interface for inputs and stuff is settled.