-
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
Higher order scheme #101
Comments
We did some work on this with Joseph (see the old issue #11 and the branch https://github.com/control-toolbox/CTDirect.jl/tree/old-runge-kutta). We felt it may be better to move to a more abstract interface with the discretization first, since it does involve quite a bit of modifications. You are certainly welcome to try on your side, dont hesitate if you have any questions :-) |
Ok, we'll try this again with @joseph-gergaud. Hopefully the code is better structured now and should make it easier. |
Dear @PierreMartinon, @jbcaillau, and @joseph-gergaud, Thank you for considering this issue and directing me to your previous work on RK schemes. I have tinkered around with the I ended up implementing the same scheme (implicit trapezoidal rule, aka Crank-Nicholson) following your algorithmic guide using JuMP with Ipopt backend. I further implemented a general RK scheme in a similar manner, so I provide here my results. 1. Implicit trapezoidal rule (2 stages, order 2)The control trajectory for the Standalone scripts and plots for both implementations:
I bring this issue to your attention because the difference is significant, as you can see in the attached plots. 2. Higher order scheme: Gauss-Legendre method (2 stages, order 4)I implemented a general RK scheme following your algorithmic guide and the previous RK branch. Here's my standalone script for the JuMP implementation of RK scheme and the control plot with the Gauss-Legendre method of order 4. Takeaway
Finally, I would be happy to help with a general RK scheme implementation when I have more time at hand. For the time being, I will stop at my current code based on your previous work. |
hey @rand-asswad sounds super nice! 👍🏽currently at the JuliaCon, but will have a look at it asap. cheers from eindhoven to @PierreMartinon |
@jbcaillau enjoy JuliaCon and Eindhoven! |
https://control-toolbox.org/docs/optimalcontrol/stable/juliacon2024.html |
I updated the code gists and ran a fresh round of testing with the
Full logs: CTDirect log
JuMP trapezoidal scheme log
JuMP Gauss 2-stages scheme log
|
ping @PierreMartinon |
Hi, a quick question: did you run the optimization twice to remove the compilation time ? (you can set for instance 2 iterations max). One suprise is the 100x larger memory usage. Can you limit the iterations to 50 for instance and see if the memory difference is the same ? Maybe we are doing some unnecessary allocations in CTDirect. I should redo a pass on that, there is a nice option when launching julia, that will output .mem files with memory allocations corresponding to each line of code. Regarding the control oscillations, they can indeed happen especially on singular arcs, and increasing the number of time steps typically does not help. Based on my experience, changing the discretization formula (when possible...) may help, as reducing the number of time steps or setting a smaller tolerance for the NLP solver. In your case it would be interesting to find why Jump seems unaffected (unless it's a random thing). |
hi @PierreMartinon @rand-asswad thanks for the feedback. yes, mem allocation difference sounds huge and needs to be understood.
All in all, thanks @rand-asswad for the input on this! |
First of all, I'm having trouble with using OptimalControl
@def ocp begin
t ∈ [ 0, 1 ], time
x ∈ R², state
u ∈ R, control
x(0) == [ -1, 0 ]
x(1) == [ 0, 0 ]
ẋ(t) == [ x₂(t), u(t) ]
∫( 0.5u(t)^2 ) → min
end
sol = solve(ocp) I get the following error:
I tried it multiple times on a fresh Julia install and the problem persisted with
Since the memory issue is addressed in This problem aside, a quick round of testing following your recommendations gave similar results (this time I only compared for the same discretization scheme).
I'll rerun these tests when I solve the issue with @PierreMartinon regarding the oscillations in the singular arcs, I tried reducing the number of time-steps as well as the tolerance. Unfortunately, I couldn't succeed in removing them with |
@rand-asswad sorry for the late reply (been busy at JuliaCon 🥲). We have split things using extensions, you know need to write the following: using OptimalControl
using NLPModelsIpopt # so as to use Ipopt
using Plots # so as to plot
@def ocp begin
t ∈ [ 0, 1 ], time
x ∈ R², state
u ∈ R, control
x(0) == [ -1, 0 ]
x(1) == [ 0, 0 ]
ẋ(t) == [ x₂(t), u(t) ]
∫( 0.5u(t)^2 ) → min
end
sol = solve(ocp)
plot(sol) In between, there has been an update of ADNLPModels.jl (and sparsity detection in there): can you please re-run your previous tests with the latest version of OptimalControl.jl, now available from the general registry? |
hi @rand-asswad, did you give it a try?
|
@PierreMartinon @gergaud hi, we may have a use case that requires higher order implicit schemes (Gauss...) It is connected to this discussion.
@rand-asswad @DJEMAwalid do not hesitate to add further comments on the application, e.g. a plot of the periodic control.
The text was updated successfully, but these errors were encountered: