Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions ext/CTDirectExtADNLP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ Build the NLP model for the DOCP (ADNLPModels version)
* `adnlp_backend`: backend for ADNLPModels ([`:optimized`], `:manual`, `:default`)
"""
function CTDirect.build_nlp!(
docp::CTDirect.DOCP{
<:CTDirect.Discretization,
<:CTModels.Model,
<:CTDirect.ADNLPBackend,
},
docp::CTDirect.DOCP{<:CTDirect.Discretization,<:CTModels.Model,<:CTDirect.ADNLPBackend},
x0;
adnlp_backend=CTDirect.__adnlp_backend(),
show_time=false, #+default
Expand Down
10 changes: 4 additions & 6 deletions ext/CTDirectExtExa.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ Build the NLP model for the DOCP (ExaModels version)
* `exa_backend`: backend for ExaModels ([`nothing`])
"""
function CTDirect.build_nlp!(
docp::CTDirect.DOCP{
<:CTDirect.Discretization,
<:CTModels.Model,
<:CTDirect.ExaBackend,
},
docp::CTDirect.DOCP{<:CTDirect.Discretization,<:CTModels.Model,<:CTDirect.ExaBackend},
x0;
grid_size=CTDirect.__grid_size(),
disc_method=CTDirect.__disc_method(),
Expand Down Expand Up @@ -76,7 +72,9 @@ Retrieve the time grid from the given DOCP solution.

- `::Vector{Float64}`: The time grid.
"""
function CTDirect.get_time_grid_exa(nlp_solution::SolverCore.AbstractExecutionStats, docp::CTDirect.DOCP)
function CTDirect.get_time_grid_exa(
nlp_solution::SolverCore.AbstractExecutionStats, docp::CTDirect.DOCP
)
grid = zeros(docp.time.steps+1)
ocp = docp.ocp

Expand Down
4 changes: 3 additions & 1 deletion ext/CTDirectExtMadNLP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ function CTDirect.solve_docp(
return nlp_solution
end

function CTDirect.SolverInfos(nlp_solution::MadNLP.MadNLPExecutionStats, nlp::NLPModels.AbstractNLPModel)
function CTDirect.SolverInfos(
nlp_solution::MadNLP.MadNLPExecutionStats, nlp::NLPModels.AbstractNLPModel
)
minimize = NLPModels.get_minimize(nlp)
objective = minimize ? nlp_solution.objective : -nlp_solution.objective # sign depends on minimization for MadNLP
iterations = nlp_solution.iter
Expand Down
1 change: 0 additions & 1 deletion src/disc/common.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#= Common parts for the discretization =#

"""
Expand Down
4 changes: 3 additions & 1 deletion src/docp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ julia> DOCP(ocp, nlp_model_backend)
DOCP{...}(...)
```
"""
mutable struct DOCP{D<:CTDirect.Discretization,O<:CTModels.Model,N<:CTDirect.AbstractNLPModelBackend}
mutable struct DOCP{
D<:CTDirect.Discretization,O<:CTModels.Model,N<:CTDirect.AbstractNLPModelBackend
}

# discretization scheme
discretization::D
Expand Down
12 changes: 9 additions & 3 deletions src/solution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ function build_OCP_solution(docp::DOCP, nlp_solution::SolverCore.AbstractExecuti
nlp_model_backend = docp.nlp_model_backend

# retrieve data from NLP solver
objective, iterations, constraints_violation, message, status, successful = SolverInfos(nlp_solution, nlp)
objective, iterations, constraints_violation, message, status, successful = SolverInfos(
nlp_solution, nlp
)

# arrays (explicit conversion for GPU case)
solution = Array(nlp_solution.solution)
Expand Down Expand Up @@ -161,7 +163,9 @@ julia> SolverInfos(nlp_solution)
(1.23, 15, 1.0e-6, "Ipopt/generic", :first_order, true)
```
"""
function SolverInfos(nlp_solution::SolverCore.AbstractExecutionStats, ::NLPModels.AbstractNLPModel)
function SolverInfos(
nlp_solution::SolverCore.AbstractExecutionStats, ::NLPModels.AbstractNLPModel
)
objective = nlp_solution.objective
iterations = nlp_solution.iter
constraints_violation = nlp_solution.primal_feas
Expand Down Expand Up @@ -398,7 +402,9 @@ julia> P, path_dual, bound_dual = parse_DOCP_solution_dual(docp, duals; nlp_mode
([...] , [...], [...])
```
"""
function parse_DOCP_solution_dual(docp, multipliers; nlp_model_backend=ADNLPBackend(), nlp_solution)
function parse_DOCP_solution_dual(
docp, multipliers; nlp_model_backend=ADNLPBackend(), nlp_solution
)

# costate
N = docp.time.steps
Expand Down
14 changes: 2 additions & 12 deletions src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ ERROR: ExtensionError(...)
```
"""
function build_nlp!(
docp::CTDirect.DOCP{
<:CTDirect.Discretization,
<:CTModels.Model,
T,
}, x0; kwargs...
docp::CTDirect.DOCP{<:CTDirect.Discretization,<:CTModels.Model,T}, x0; kwargs...
) where {T<:AbstractNLPModelBackend}
throw(CTBase.ExtensionError(WEAKDEPS[T]...))
end
Expand Down Expand Up @@ -391,13 +387,7 @@ function direct_transcription(
x0 = DOCP_initial_guess(docp, docp_init)

# build nlp
build_nlp!(
docp,
x0;
grid_size=grid_size,
disc_method=disc_method,
kwargs...,
)
build_nlp!(docp, x0; grid_size=grid_size, disc_method=disc_method, kwargs...)

return docp
end
Expand Down
9 changes: 8 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ using CTBase
using CTParser: CTParser, @def
using CTModels:
CTModels, objective, state, control, variable, costate, time_grid, iterations, criterion
using CTDirect: CTDirect, solve, direct_transcription, set_initial_guess, build_OCP_solution, nlp_model, ocp_model
using CTDirect:
CTDirect,
solve,
direct_transcription,
set_initial_guess,
build_OCP_solution,
nlp_model,
ocp_model

# activate NLP modelers
using ADNLPModels
Expand Down
15 changes: 6 additions & 9 deletions test/tmp/test_madnlp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,8 @@ senses = [:min, :max]
solver_types = [:madnlp, :ipopt]
problem_types = [:exa, :adnlp]

results = DataFrame(
sense = String[],
solver = String[],
problem_type = String[],
objective_value = Float64[],
results = DataFrame(;
sense=String[], solver=String[], problem_type=String[], objective_value=Float64[]
)

for sense in senses
Expand All @@ -62,10 +59,10 @@ for sense in senses
push!(
results,
(
sense = String(sense),
solver = String(solver_type),
problem_type = String(problem_type),
objective_value = objective_value,
sense=String(sense),
solver=String(solver_type),
problem_type=String(problem_type),
objective_value=objective_value,
),
)
end
Expand Down