Solve on GPU
In this manual, we explain how to use the solve
function from OptimalControl.jl on GPU. We rely on MadNLP and currently only provide support for NVIDIA thanks to CUDA.jl.
CommonSolve.solve
— Methodsolve(
ocp::Model,
description::Symbol...;
display,
kwargs...
) -> Solution{TimeGridModelType, TimesModelType, StateModelType, ControlModelType, VariableModelType, CostateModelType, Float64, DualModelType, CTModels.SolverInfos{Dict{Symbol, Any}}, ModelType} where {TimeGridModelType<:CTModels.TimeGridModel, TimesModelType<:CTModels.TimesModel, StateModelType<:Union{CTModels.StateModelSolution{TS} where TS<:CTModels.var"#114#136", CTModels.StateModelSolution{TS} where TS<:CTModels.var"#115#137"}, ControlModelType<:Union{CTModels.ControlModelSolution{TS} where TS<:CTModels.var"#116#138", CTModels.ControlModelSolution{TS} where TS<:CTModels.var"#117#139"}, VariableModelType<:Union{CTModels.VariableModelSolution{Vector{Float64}}, CTModels.VariableModelSolution{Float64}}, CostateModelType<:Union{CTModels.var"#118#140", CTModels.var"#119#141"}, DualModelType<:(CTModels.DualModel{PC_Dual, Vector{Float64}, SC_LB_Dual, SC_UB_Dual, CC_LB_Dual, CC_UB_Dual, Vector{Float64}, Vector{Float64}} where {PC_Dual<:Union{CTModels.var"#121#143"{CTModels.var"#120#142"}, CTModels.var"#122#144"{CTModels.var"#120#142"}}, SC_LB_Dual<:Union{CTModels.var"#124#146"{CTModels.var"#123#145"}, CTModels.var"#125#147"{CTModels.var"#123#145"}}, SC_UB_Dual<:Union{CTModels.var"#127#149"{CTModels.var"#126#148"}, CTModels.var"#128#150"{CTModels.var"#126#148"}}, CC_LB_Dual<:Union{CTModels.var"#130#152"{CTModels.var"#129#151"}, CTModels.var"#131#153"{CTModels.var"#129#151"}}, CC_UB_Dual<:Union{CTModels.var"#133#155"{CTModels.var"#132#154"}, CTModels.var"#134#156"{CTModels.var"#132#154"}}}), ModelType<:Model}
Solve the optimal control problem ocp
by the method given by the (optional) description. The get the list of available methods:
julia> available_methods()
The higher in the list, the higher is the priority. The keyword arguments are specific to the chosen method and represent the options of the solver.
Arguments
ocp::OptimalControlModel
: the optimal control problem to solve.description::Symbol...
: the description of the method used to solve the problem.kwargs...
: the options of the method.
Examples
The simplest way to solve the optimal control problem is to call the function without any argument.
julia> sol = solve(ocp)
The method description is a list of Symbols. The default is
julia> sol = solve(ocp, :direct, :adnlp, :ipopt)
You can provide a partial description, the function will find the best match.
julia> sol = solve(ocp, :direct)
See the resolution methods section for more details about the available methods.
The keyword arguments are specific to the chosen method and correspond to the options of the different solvers. For example, the keyword max_iter
is an Ipopt option that may be used to set the maximum number of iterations.
julia> sol = solve(ocp, :direct, :ipopt, max_iter=100)
See the direct method section for more details about associated options. These options also detailed in the CTDirect.solve
documentation. This main solve
method redirects to CTDirect.solve
when the :direct
Symbol is given in the description. See also the NLP solvers section for more details about Ipopt or MadNLP options.
To help the solve converge, an initial guess can be provided within the keyword init
. You can provide the initial guess for the state, control, and variable.
julia> sol = solve(ocp, init=(state=[-0.5, 0.2], control=0.5))
See how to set an initial guess for more details.
TBC