Skip to content

Commit 9f457ee

Browse files
authored
Merge pull request #121 from control-toolbox/109-general-build-ocp-solution
replace build sol
2 parents 31a482b + 7ba4bce commit 9f457ee

File tree

11 files changed

+36
-27
lines changed

11 files changed

+36
-27
lines changed

Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ authors = ["Olivier Cots <olivier.cots@toulouse-inp.fr>"]
44
version = "0.2.1"
55

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

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

2224
[compat]
25+
ADNLPModels = "0.8"
2326
CTBase = "0.16"
2427
CTDirect = "0.16"
2528
CTModels = "0.6"
@@ -28,4 +31,5 @@ ExaModels = "0.9"
2831
JuMP = "1"
2932
OptimalControl = "1"
3033
OrderedCollections = "1"
34+
SolverCore = "0.3"
3135
julia = "1.10"

docs/problems.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function generate_documentation(
7676
)
7777
7878
# build an optimal control solution
79-
ocp_sol = build_OCP_solution(docp; primal=nlp_sol.solution, dual=nlp_sol.multipliers, docp_solution=nlp_sol)
79+
ocp_sol = build_ocp_solution(docp, nlp_sol)
8080
nothing # hide
8181
```
8282
@@ -246,7 +246,7 @@ function generate_documentation(
246246
)
247247
248248
# build an optimal control solution
249-
ocp_sol = build_OCP_solution(docp; primal=nlp_sol.solution, dual=nlp_sol.multipliers, docp_solution=nlp_sol)
249+
ocp_sol = build_ocp_solution(docp, nlp_sol)
250250
251251
# plot the OptimalControl solution
252252
plt = plot(

docs/src/assets/Manifest.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ uuid = "5f98b655-cc9a-415a-b60e-744165666948"
10421042
version = "1.1.1"
10431043

10441044
[[deps.OptimalControlProblems]]
1045-
deps = ["CTBase", "CTDirect", "CTModels", "DocStringExtensions", "ExaModels", "OrderedCollections"]
1045+
deps = ["ADNLPModels", "CTBase", "CTDirect", "CTModels", "DocStringExtensions", "ExaModels", "OrderedCollections", "SolverCore"]
10461046
path = "/Users/ocots/Research/logiciels/dev/control-toolbox/OptimalControlProblems"
10471047
uuid = "59046045-fb9c-4c23-964f-ff0a25704f96"
10481048
version = "0.2.1"

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Pkg.add("OptimalControlProblems")
2121
- [0Yassine0](https://github.com/0Yassine0)
2222
- [frapac](https://github.com/frapac)
2323
- [BaptisteCbl](https://github.com/BaptisteCbl)
24-
- [COPS: Large-Scale Optimization Problems](https://www.mcs.anl.gov/~more/cops) and [COPSBenchmark.jl](github.com/MadNLP/COPSBenchmark.jl)
24+
- [COPS: Large-Scale Optimization Problems](https://www.mcs.anl.gov/~more/cops) and [COPSBenchmark.jl](https://github.com/MadNLP/COPSBenchmark.jl)
2525
- [BOCOP - A collection of examples](https://project.inria.fr/bocop/files/2017/05/Examples-BOCOP.pdf)
2626

2727
## Reproducibility

docs/src/tutorial-solve.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,7 @@ sol.iter
4444
To recover the state, control, and costate, we recommend building an optimal control solution and using the associated getters:
4545

4646
```@example main
47-
ocp_sol = build_OCP_solution(
48-
docp;
49-
primal=sol.solution,
50-
dual=sol.multipliers,
51-
docp_solution=sol,
52-
)
47+
ocp_sol = build_ocp_solution(docp, sol)
5348
5449
t = time_grid(ocp_sol) # t0, ..., tN = tf
5550
x = state(ocp_sol) # function of time

src/OptimalControlProblems.jl

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,36 @@ module OptimalControlProblems
33
using CTBase
44
using CTDirect
55
import CTModels: CTModels, time_grid, state, control, costate
6-
import ExaModels: ExaModels, variable
6+
import ExaModels: ExaModels, ExaModel, variable
77
using DocStringExtensions
88
using OrderedCollections: OrderedDict
9+
using SolverCore
10+
import ADNLPModels: ADNLPModels, ADNLPModel
911

1012
# -----------------
1113
# SHOULD NO BE HERE
1214
nlp_model(docp::CTDirect.DOCP) = docp.nlp
1315
ocp_model(docp::CTDirect.DOCP) = docp.ocp
16+
function build_ocp_solution(docp::CTDirect.DOCP, nlp_solution::SolverCore.AbstractExecutionStats)
17+
nlp_model_backend = if nlp_model(docp) isa ADNLPModel
18+
CTDirect.ADNLPBackend()
19+
elseif nlp_model(docp) isa ExaModel
20+
CTDirect.ExaBackend()
21+
else
22+
throw(CTBase.IncorrectArgument("The NLP model is of unknown type."))
23+
end
24+
return CTDirect.build_OCP_solution(
25+
docp;
26+
primal=nlp_solution.solution,
27+
dual=nlp_solution.multipliers,
28+
mult_LB=nlp_solution.multipliers_L,
29+
mult_UB=nlp_solution.multipliers_U,
30+
nlp_model=nlp_model_backend,
31+
docp_solution=nlp_solution
32+
)
33+
end
1434

15-
export nlp_model, ocp_model
35+
export nlp_model, ocp_model, build_ocp_solution
1636

1737
# -----------------
1838

test/figures/init/beam.pdf

0 Bytes
Binary file not shown.

test/figures/solution/beam.pdf

0 Bytes
Binary file not shown.

test/runtests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ end
3434
# ]
3535
# list_of_problems = setdiff(list_of_problems, problems_to_exclude)
3636

37-
# list_of_problems = [
38-
# :beam
39-
# ]
37+
list_of_problems = [
38+
# :beam
39+
]
4040

4141
# The list of all the problems to test
4242
const LIST_OF_PROBLEMS = deepcopy(list_of_problems)

test/test_quick.jl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@ function test_quick()
2929
docp = OptimalControlProblems.eval(f)(OptimalControlBackend(); N=N)
3030
nlp = nlp_model(docp)
3131
nlp_sol = NLPModelsIpopt.ipopt(nlp; kwargs...)
32-
sol = build_OCP_solution(
33-
docp;
34-
primal=nlp_sol.solution,
35-
dual=nlp_sol.multipliers,
36-
docp_solution=nlp_sol,
37-
)
32+
sol = build_ocp_solution(docp, nlp_sol)
3833
o_oc = objective(sol)
3934

4035
############### JuMP ###############

0 commit comments

Comments
 (0)