Skip to content

Commit f350938

Browse files
authored
Merge pull request #613 from control-toolbox/605-general-use-ai-to-generate-problem-descriptions-in-optimalcontroljl
added manual-ai-ded.md
2 parents eb5b421 + 4356ec7 commit f350938

3 files changed

Lines changed: 120 additions & 19 deletions

File tree

docs/make.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,12 @@ Draft = false
128128
```
129129
=#
130130
makedocs(;
131-
draft=false,
131+
draft=true, # if draft is true, then the julia code from .md is not executed # debug
132+
# to disable the draft mode in a specific markdown file, use the following:
133+
# ```@meta
134+
# Draft = false
135+
# ```
136+
#draft=false,
132137
#warnonly=[:cross_references, :autodocs_block],
133138
sitename="OptimalControl.jl",
134139
format=Documenter.HTML(;
@@ -150,6 +155,7 @@ makedocs(;
150155
],
151156
"Manual" => [
152157
"Define a problem" => "manual-abstract.md",
158+
"Use AI" => "manual-ai-ded.md",
153159
"Problem characteristics" => "manual-model.md",
154160
"Set an initial guess" => "manual-initial-guess.md",
155161
"Solve a problem" => "manual-solve.md",

docs/src/manual-ai-ded.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# [Use AI](@id manual-ai-ded)
2+
3+
Using now common models from AI, it is an elementary task to have such an agent learn the syntax of OptimalControl.jl DSL, then use the agent to translate standard math into this DSL. Here is a typical prompt, pointing to the [DSL syntax](@ref manual-abstract-syntax):
4+
5+
```
6+
learn the syntax of optimalcontrol.jl dsl described at the link below to translate math into this dsl (julia language):
7+
https://control-toolbox.org/OptimalControl.jl/stable/manual-abstract.html
8+
```
9+
10+
Now, here is an extract of, *e.g.*, [claude.ai](https://claude.ai) answer (Sonnet 4 model) to the request below:
11+
12+
```
13+
translate the problem below into this DSL: minimise the final time tf under the constraint q''(t) = u(t) with -1 <= u(t) <= 1, q(0) = 1, q'(0) = -2, q(tf) = 3, q'(tf) = 1, and q'(t) <= 1
14+
```
15+
16+
```julia
17+
@def begin
18+
tf R, variable
19+
t [0, tf], time
20+
x = (q, v) R², state
21+
u R, control
22+
23+
# Variable constraint
24+
tf 0
25+
26+
# Control constraint
27+
-1 u(t) 1
28+
29+
# Initial conditions
30+
q(0) == 1
31+
v(0) == -2
32+
33+
# Final conditions
34+
q(tf) == 3
35+
v(tf) == 1
36+
37+
# Path constraint
38+
v(t) 1
39+
40+
# Dynamics (q'' = u becomes first-order system)
41+
(t) == [v(t), u(t)]
42+
43+
# Objective: minimize final time
44+
tf min
45+
end
46+
```
47+
48+
The answer is syntactically correct and can be updated, for instance according to the new request below:
49+
50+
```
51+
use a form compatible with examodels
52+
```
53+
54+
```julia
55+
@def begin
56+
tf R, variable
57+
t [0, tf], time
58+
x = (q, v) R², state
59+
u R, control
60+
61+
# Variable constraint
62+
tf 0
63+
64+
# Control constraint
65+
-1 u(t) 1
66+
67+
# Initial conditions
68+
q(0) == 1
69+
v(0) == -2
70+
71+
# Final conditions
72+
q(tf) == 3
73+
v(tf) == 1
74+
75+
# Path constraint
76+
v(t) 1
77+
78+
# Dynamics (coordinate-wise for ExaModels)
79+
(q)(t) == v(t)
80+
(v)(t) == u(t)
81+
82+
# Objective: minimize final time
83+
tf min
84+
end
85+
```

docs/src/manual-solve-gpu.md

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,21 @@ Computation on GPU is currently only tested with CUDA, and the associated backen
3939
sol = solve(ocp, :exa, :madnlp; exa_backend=CUDABackend())
4040
```
4141

42-
```
43-
▫ This is OptimalControl version v1.1.0 running with: direct, exa, madnlp.
4442

45-
▫ The optimal control problem is solved with CTDirect version v0.16.0.
43+
```julia
44+
▫ This is OptimalControl version v1.1.2 running with: direct, exa, madnlp.
45+
46+
▫ The optimal control problem is solved with CTDirect version v0.17.2.
4647

47-
┌─ The NLP is modelled with ExaModels and solved with MadNLP.
48+
┌─ The NLP is modelled with ExaModels and solved with MadNLPMumps.
4849
4950
├─ Number of time steps: 250
50-
└─ Discretisation scheme: trapeze
51+
└─ Discretisation scheme: midpoint
5152

52-
▫ This is MadNLP version v0.8.7, running with cuDSS v0.4.0
53+
▫ This is MadNLP version v0.8.12, running with cuDSS v0.6.0
5354

54-
Number of nonzeros in constraint Jacobian............: 2506
55-
Number of nonzeros in Lagrangian Hessian.............: 2006
55+
Number of nonzeros in constraint Jacobian............: 2256
56+
Number of nonzeros in Lagrangian Hessian.............: 1251
5657

5758
Total number of variables............................: 754
5859
variables with only lower bounds: 0
@@ -64,21 +65,30 @@ Total number of inequality constraints...............: 251
6465
inequality constraints with lower and upper bounds: 251
6566
inequality constraints with only upper bounds: 0
6667

67-
iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls
68-
0 1.0200000e+00 1.10e+00 1.00e+00 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0
69-
...
70-
26 9.8902986e+00 2.22e-16 7.11e-15 -9.0 1.32e-04 - 1.00e+00 1.00e+00h 1
68+
iter objective inf_pr inf_du inf_compl lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls
69+
0 1.0200000e+00 1.10e+00 1.00e+00 1.01e+01 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0
70+
1 1.0199978e+00 1.10e+00 1.45e+00 8.73e-02 -1.0 1.97e+02 - 5.05e-03 4.00e-07h 1
71+
...
72+
27 9.8891249e+00 2.22e-16 7.11e-15 1.60e-09 -9.0 2.36e-04 - 1.00e+00 1.00e+00h 1
7173

72-
Number of Iterations....: 26
74+
Number of Iterations....: 27
7375

7476
(scaled) (unscaled)
75-
Objective...............: 9.8902986337530514e+00 9.8902986337530514e+00
77+
Objective...............: 9.8891248915014458e+00 9.8891248915014458e+00
7678
Dual infeasibility......: 7.1054273576010019e-15 7.1054273576010019e-15
7779
Constraint violation....: 2.2204460492503131e-16 2.2204460492503131e-16
78-
Complementarity.........: 4.8363494304578671e-09 4.8363494304578671e-09
79-
Overall NLP error.......: 4.8363494304578671e-09 4.8363494304578671e-09
80-
81-
...
80+
Complementarity.........: 1.5999963912421547e-09 1.5999963912421547e-09
81+
Overall NLP error.......: 1.5999963912421547e-09 1.5999963912421547e-09
82+
83+
Number of objective function evaluations = 28
84+
Number of objective gradient evaluations = 28
85+
Number of constraint evaluations = 28
86+
Number of constraint Jacobian evaluations = 28
87+
Number of Lagrangian Hessian evaluations = 27
88+
Total wall-clock secs in solver (w/o fun. eval./lin. alg.) = 0.126
89+
Total wall-clock secs in linear solver = 0.103
90+
Total wall-clock secs in NLP function evaluations = 0.022
91+
Total wall-clock secs = 0.251
8292

8393
EXIT: Optimal Solution Found (tol = 1.0e-08).
8494
```

0 commit comments

Comments
 (0)