You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Change disc_method parameter to scheme
- Remove const from parameters and wrap OCP in goddard_problem() function
- Add comments to dynamics functions explaining physics
- Add successful(sol) checks after solve calls
- Update AD backend section to use explicit solve mode with strategy instances
- Add documentation links using @extref syntax
- Simplify plotting code with enumerate and color indexing
- Add :external_cross_references to warnonly in make.jl
Copy file name to clipboardExpand all lines: docs/src/tutorial-continuation.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ using Printf
17
17
using Plots
18
18
```
19
19
20
-
The `init` parameter of the `solve` function allows providing an initial guess. See the [initial guess documentation](https://control-toolbox.org/OptimalControl.jl/stable/manual-initial-guess.html) for more details.
20
+
The `init` parameter of the `solve` function allows providing an initial guess. See the [initial guess documentation](@extrefOptimalControlmanual-initial-guess) for more details.
21
21
22
22
We write a function that returns the OCP for a given final time:
return [ 0, Tmax/m, -b*Tmax ] # [dr/dt, dv/dt, dm/dt] due to thrust
57
65
end
58
66
nothing # hide
59
67
```
60
68
61
69
## Discretisation schemes
62
70
63
-
When calling `solve`, the option `disc_method=...` can be used to specify the discretization scheme. In addition to the default implicit `:midpoint` method, other available options include the implicit `:trapeze` method (also known as Crank–Nicolson), and Gauss–Legendre collocation schemes with 2 and 3 stages: `:gauss_legendre_2` and `:gauss_legendre_3`, of order 4 and 6 respectively. Note that higher-order methods typically result in larger NLP problems for the same number of time steps, and their accuracy also depends on the smoothness of the problem.
71
+
When calling `solve`, the option `scheme=...` can be used to specify the discretization scheme. In addition to the default implicit `:midpoint` method, other available options include the implicit `:trapeze` method (also known as Crank–Nicolson), and Gauss–Legendre collocation schemes with 2 and 3 stages: `:gauss_legendre_2` and `:gauss_legendre_3`, of order 4 and 6 respectively. Note that higher-order methods typically result in larger NLP problems for the same number of time steps, and their accuracy also depends on the smoothness of the problem.
64
72
65
73
Let us first solve the problem with the default `:midpoint` method and display the solution.
66
74
67
75
```@example main-disc
68
-
sol = solve(ocp; disc_method=:midpoint, display=false)
76
+
sol = solve(ocp; scheme=:midpoint, display=false)
77
+
@assert successful(sol) "Solution failed"
69
78
plot(sol; size=(800, 800))
70
79
```
71
80
72
-
Let us now compare different discretization schemes to evaluate their accuracy and performance.
81
+
Let us now compare different discretization schemes to evaluate their accuracy and performance. See the [Strategy options](@id manual-solve-strategy-options) for information on default values for parameters like `tol`.
73
82
74
83
```@example main-disc
75
84
# Solve the problem with different discretization methods
For some large problems, you may notice that the solver takes a long time before the iterations actually begin. This is due to the computation of sparse derivatives — specifically, the Jacobian of the constraints and the Hessian of the Lagrangian — which can be quite costly. One possible alternative is to set the option `adnlp_backend=:manual`, which uses simpler sparsity patterns. The resulting matrices are faster to compute but are also less sparse, so this represents a trade-off between automatic differentiation (AD) preparation time and the efficiency of the optimization itself.
131
+
For some large problems, you may notice that the solver takes a long time before the iterations actually begin. This is due to the computation of sparse derivatives — specifically, the Jacobian of the constraints and the Hessian of the Lagrangian — which can be quite costly. One possible alternative is to set the option `backend=:manual` in the modeler, which uses simpler sparsity patterns. The resulting matrices are faster to compute but are also less sparse, so this represents a trade-off between automatic differentiation (AD) preparation time and the efficiency of the optimization itself.
Let us now compare the performance of the two backends. We will use the `@btimed` macro from the `BenchmarkTools` package to measure the time taken for both the preparation of the NLP problem and the execution of the solver. Besides, we will also collect the number of non-zero elements in the Jacobian and Hessian matrices, which can be useful to understand the sparsity of the problem, thanks to the functions `get_nnzo`, `get_nnzj`, and `get_nnzj` from the `NLPModels` package. The problem is first discretized with the `direct_transcription` method and then solved with the `ipopt` solver, see the [tutorial on direct transcription](@ref tutorial-nlp) for more details.
141
+
This explicit approach with strategy instances is less high-level than the descriptive method used earlier. It provides more control over the solving process and is detailed in the [explicit mode documentation](@extref OptimalControl manual-solve-explicit).
142
+
143
+
Let us now compare the performance of the two backends. We will use the `@btimed` macro from the `BenchmarkTools` package to measure the time taken for both the preparation of the NLP problem and the execution of the solver. Separating these measurements allows us to understand whether the bottleneck is in the discretization/modeling phase (which depends on the AD backend) or in the solver phase (which depends on the sparsity of the matrices). We use a lower-level approach with explicit strategy instances to separately measure the discretization/modeling time and the solver time.
0 commit comments