Skip to content
Merged
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
4 changes: 4 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ authors = ["Olivier Cots <olivier.cots@toulouse-inp.fr>"]
version = "0.2.1"

[deps]
ADNLPModels = "54578032-b7ea-4c30-94aa-7cbd1cce6c9a"
CTBase = "54762871-cc72-4466-b8e8-f6c8b58076cd"
CTDirect = "790bbbee-bee9-49ee-8912-a9de031322d5"
CTModels = "34c4fa32-2049-4079-8329-de33c2a22e2d"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
ExaModels = "1037b233-b668-4ce9-9b63-f9f681f55dd2"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
SolverCore = "ff4d7338-4cf1-434d-91df-b86cb86fb843"

[weakdeps]
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
Expand All @@ -20,6 +22,7 @@ JuMPModels = "JuMP"
OptimalControlModels = "OptimalControl"

[compat]
ADNLPModels = "0.8"
CTBase = "0.16"
CTDirect = "0.16"
CTModels = "0.6"
Expand All @@ -28,4 +31,5 @@ ExaModels = "0.9"
JuMP = "1"
OptimalControl = "1"
OrderedCollections = "1"
SolverCore = "0.3"
julia = "1.10"
4 changes: 2 additions & 2 deletions docs/problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function generate_documentation(
)

# build an optimal control solution
ocp_sol = build_OCP_solution(docp; primal=nlp_sol.solution, dual=nlp_sol.multipliers, docp_solution=nlp_sol)
ocp_sol = build_ocp_solution(docp, nlp_sol)
nothing # hide
```

Expand Down Expand Up @@ -246,7 +246,7 @@ function generate_documentation(
)

# build an optimal control solution
ocp_sol = build_OCP_solution(docp; primal=nlp_sol.solution, dual=nlp_sol.multipliers, docp_solution=nlp_sol)
ocp_sol = build_ocp_solution(docp, nlp_sol)

# plot the OptimalControl solution
plt = plot(
Expand Down
2 changes: 1 addition & 1 deletion docs/src/assets/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ uuid = "5f98b655-cc9a-415a-b60e-744165666948"
version = "1.1.1"

[[deps.OptimalControlProblems]]
deps = ["CTBase", "CTDirect", "CTModels", "DocStringExtensions", "ExaModels", "OrderedCollections"]
deps = ["ADNLPModels", "CTBase", "CTDirect", "CTModels", "DocStringExtensions", "ExaModels", "OrderedCollections", "SolverCore"]
path = "/Users/ocots/Research/logiciels/dev/control-toolbox/OptimalControlProblems"
uuid = "59046045-fb9c-4c23-964f-ff0a25704f96"
version = "0.2.1"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Pkg.add("OptimalControlProblems")
- [0Yassine0](https://github.com/0Yassine0)
- [frapac](https://github.com/frapac)
- [BaptisteCbl](https://github.com/BaptisteCbl)
- [COPS: Large-Scale Optimization Problems](https://www.mcs.anl.gov/~more/cops) and [COPSBenchmark.jl](github.com/MadNLP/COPSBenchmark.jl)
- [COPS: Large-Scale Optimization Problems](https://www.mcs.anl.gov/~more/cops) and [COPSBenchmark.jl](https://github.com/MadNLP/COPSBenchmark.jl)
- [BOCOP - A collection of examples](https://project.inria.fr/bocop/files/2017/05/Examples-BOCOP.pdf)

## Reproducibility
Expand Down
7 changes: 1 addition & 6 deletions docs/src/tutorial-solve.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ sol.iter
To recover the state, control, and costate, we recommend building an optimal control solution and using the associated getters:

```@example main
ocp_sol = build_OCP_solution(
docp;
primal=sol.solution,
dual=sol.multipliers,
docp_solution=sol,
)
ocp_sol = build_ocp_solution(docp, sol)

t = time_grid(ocp_sol) # t0, ..., tN = tf
x = state(ocp_sol) # function of time
Expand Down
24 changes: 22 additions & 2 deletions src/OptimalControlProblems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,36 @@ module OptimalControlProblems
using CTBase
using CTDirect
import CTModels: CTModels, time_grid, state, control, costate
import ExaModels: ExaModels, variable
import ExaModels: ExaModels, ExaModel, variable
using DocStringExtensions
using OrderedCollections: OrderedDict
using SolverCore
import ADNLPModels: ADNLPModels, ADNLPModel

# -----------------
# SHOULD NO BE HERE
nlp_model(docp::CTDirect.DOCP) = docp.nlp
ocp_model(docp::CTDirect.DOCP) = docp.ocp
function build_ocp_solution(docp::CTDirect.DOCP, nlp_solution::SolverCore.AbstractExecutionStats)
nlp_model_backend = if nlp_model(docp) isa ADNLPModel
CTDirect.ADNLPBackend()
elseif nlp_model(docp) isa ExaModel
CTDirect.ExaBackend()
else
throw(CTBase.IncorrectArgument("The NLP model is of unknown type."))
end
return CTDirect.build_OCP_solution(
docp;
primal=nlp_solution.solution,
dual=nlp_solution.multipliers,
mult_LB=nlp_solution.multipliers_L,
mult_UB=nlp_solution.multipliers_U,
nlp_model=nlp_model_backend,
docp_solution=nlp_solution
)
end

export nlp_model, ocp_model
export nlp_model, ocp_model, build_ocp_solution

# -----------------

Expand Down
Binary file modified test/figures/init/beam.pdf
Binary file not shown.
Binary file modified test/figures/solution/beam.pdf
Binary file not shown.
6 changes: 3 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ end
# ]
# list_of_problems = setdiff(list_of_problems, problems_to_exclude)

# list_of_problems = [
# :beam
# ]
list_of_problems = [
# :beam
]

# The list of all the problems to test
const LIST_OF_PROBLEMS = deepcopy(list_of_problems)
Expand Down
7 changes: 1 addition & 6 deletions test/test_quick.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ function test_quick()
docp = OptimalControlProblems.eval(f)(OptimalControlBackend(); N=N)
nlp = nlp_model(docp)
nlp_sol = NLPModelsIpopt.ipopt(nlp; kwargs...)
sol = build_OCP_solution(
docp;
primal=nlp_sol.solution,
dual=nlp_sol.multipliers,
docp_solution=nlp_sol,
)
sol = build_ocp_solution(docp, nlp_sol)
o_oc = objective(sol)

############### JuMP ###############
Expand Down
7 changes: 1 addition & 6 deletions test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,7 @@ function comparison(; max_iter, test_name)
nlp_sol = NLPModelsIpopt.ipopt(nlp; Options...)

# build the solution
sol = build_OCP_solution(
docp;
primal=nlp_sol.solution,
dual=nlp_sol.multipliers,
docp_solution=nlp_sol,
)
sol = build_ocp_solution(docp, nlp_sol)

sol_oc = deepcopy(sol) # for plotting

Expand Down
Loading