Skip to content

Commit 403c777

Browse files
committed
docs is generated ok
1 parent f10a452 commit 403c777

File tree

12 files changed

+1292
-238
lines changed

12 files changed

+1292
-238
lines changed

docs/docutils/DocumenterReference.jl

Lines changed: 1101 additions & 0 deletions
Large diffs are not rendered by default.

docs/make.jl

Lines changed: 93 additions & 120 deletions
Large diffs are not rendered by default.

docs/src/index.md

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,42 @@
22

33
The `CTModels.jl` package is part of the [control-toolbox ecosystem](https://github.com/control-toolbox).
44

5-
The root package is [OptimalControl.jl](https://github.com/control-toolbox/OptimalControl.jl) which aims to provide tools to model and solve optimal control problems with ordinary differential equations by direct and indirect methods, both on CPU and GPU.
5+
!!! note
66

7-
**API Documentation**
7+
The root package is [OptimalControl.jl](https://github.com/control-toolbox/OptimalControl.jl) which aims to provide tools to model and solve optimal control problems with ordinary differential equations by direct and indirect methods, both on CPU and GPU.
88

9-
```@contents
10-
Pages = Main.API_PAGES
11-
Depth = 1
12-
```
9+
!!! warning
10+
11+
In some examples in the documentation, private methods are shown without the module
12+
prefix. This is done for the sake of clarity and readability.
13+
14+
```julia-repl
15+
julia> using CTModels
16+
julia> x = 1
17+
julia> private_fun(x) # throws an error
18+
```
19+
20+
This should instead be written as:
21+
22+
```julia-repl
23+
julia> using CTModels
24+
julia> x = 1
25+
julia> CTModels.private_fun(x)
26+
```
27+
28+
If the method is re-exported by another package,
29+
30+
```julia
31+
module OptimalControl
32+
import CTModels: private_fun
33+
export private_fun
34+
end
35+
```
36+
37+
then there is no need to prefix it with the original module name:
38+
39+
```julia-repl
40+
julia> using OptimalControl
41+
julia> x = 1
42+
julia> private_fun(x)
43+
```

docs/src/interfaces/optimization_modelers.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Modelers implement the
1010
[`AbstractOptimizationModeler`](@ref CTModels.AbstractOptimizationModeler)
1111
interface and are also
1212
[`AbstractOCPTool`](@ref CTModels.AbstractOCPTool)s. This means they follow
13-
both the options interface (see [`ocp_tools.md`](@ref)) and a calling
13+
both the options interface (see [OCP Tools](ocp_tools.md)) and a calling
1414
interface specific to optimization problems.
1515

1616
## Overview of the contract
@@ -54,7 +54,7 @@ not specialized.
5454

5555
Because `AbstractOptimizationModeler <: AbstractOCPTool`, modelers follow the
5656
same options pattern as other tools. See
57-
[`ocp_tools.md`](@ref) for a detailed discussion.
57+
[OCP Tools](ocp_tools.md) for a detailed discussion.
5858

5959
In short, a typical modeler definition looks like:
6060

@@ -148,5 +148,5 @@ To integrate a new modeler into such a registry, you typically:
148148
[`tool_package_name`](@ref CTModels.tool_package_name).
149149
3. Add the modeler type to the appropriate `REGISTERED_*` constant.
150150

151-
See also the `ocp_tools.md` page for the generic `AbstractOCPTool` interface
151+
See also the [OCP Tools](ocp_tools.md) page for the generic `AbstractOCPTool` interface
152152
and examples such as `ADNLPModeler` and `ExaModeler`.

docs/src/interfaces/optimization_problems.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,4 @@ A typical workflow is:
122122
to turn the back-end solution into an OCP-related representation.
123123

124124
For the implementation of modelers and tools, see also
125-
[`ocp_tools.md`](@ref) and the separate page on optimization modelers.
125+
[OCP Tools](ocp_tools.md) and the separate page on optimization modelers.

src/CTModels.jl

Lines changed: 28 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Type alias for a time.
5555
julia> const Time = ctNumber
5656
```
5757
58-
See also: [`ctNumber`](@ref), [`Times`](@ref), [`TimesDisc`](@ref).
58+
See also: [`ctNumber`](@ref), [`Times`](@ref CTModels.Times), [`TimesDisc`](@ref).
5959
"""
6060
const Time = ctNumber
6161

@@ -88,7 +88,7 @@ Type alias for a grid of times. This is used to define a discretization of time
8888
julia> const TimesDisc = Union{Times, StepRangeLen}
8989
```
9090
91-
See also: [`Time`](@ref), [`Times`](@ref).
91+
See also: [`Time`](@ref), [`Times`](@ref CTModels.Times).
9292
"""
9393
const TimesDisc = Union{Times,StepRangeLen}
9494

@@ -99,7 +99,7 @@ Type alias for a dictionary of constraints. This is used to store constraints be
9999
julia> const TimesDisc = Union{Times, StepRangeLen}
100100
```
101101
102-
See also: [`ConstraintsModel`](@ref), [`PreModel`](@ref) and [`Model`](@ref).
102+
See also: [`ConstraintsModel`](@ref), [`PreModel`](@ref) and [`Model`](@ref CTModels.Model).
103103
"""
104104
const ConstraintsDictType = OrderedDict{
105105
Symbol,Tuple{Symbol,Union{Function,OrdinalRange{<:Int}},ctVector,ctVector}
@@ -136,82 +136,42 @@ struct JSON3Tag <: AbstractTag end
136136

137137
# -----------------------------
138138
# to be extended
139-
"""
140-
$(TYPEDSIGNATURES)
141-
142-
Plot an optimal control solution.
143-
144-
This method requires the Plots extension to be loaded.
145-
Throws `CTBase.ExtensionError` if Plots is not available.
146-
"""
147139
function RecipesBase.plot(sol::AbstractSolution, description::Symbol...; kwargs...)
148140
throw(CTBase.ExtensionError(:Plots))
149141
end
150142

151-
"""
152-
$(TYPEDSIGNATURES)
153-
154-
Export an optimal control solution to a JLD2 file.
155-
156-
This method requires the JLD2 extension to be loaded.
157-
Throws `CTBase.ExtensionError` if JLD2 is not available.
158-
"""
159143
function export_ocp_solution(::JLD2Tag, ::AbstractSolution; filename::String)
160144
throw(CTBase.ExtensionError(:JLD2))
161145
end
162146

163-
"""
164-
$(TYPEDSIGNATURES)
165-
166-
Import an optimal control solution from a JLD2 file.
167-
168-
This method requires the JLD2 extension to be loaded.
169-
Throws `CTBase.ExtensionError` if JLD2 is not available.
170-
"""
171147
function import_ocp_solution(::JLD2Tag, ::AbstractModel; filename::String)
172148
throw(CTBase.ExtensionError(:JLD2))
173149
end
174150

175-
"""
176-
$(TYPEDSIGNATURES)
177-
178-
Export an optimal control solution to a JSON file.
179-
180-
This method requires the JSON3 extension to be loaded.
181-
Throws `CTBase.ExtensionError` if JSON3 is not available.
182-
"""
183151
function export_ocp_solution(::JSON3Tag, ::AbstractSolution; filename::String)
184152
throw(CTBase.ExtensionError(:JSON3))
185153
end
186154

187-
"""
188-
$(TYPEDSIGNATURES)
189-
190-
Import an optimal control solution from a JSON file.
191-
192-
This method requires the JSON3 extension to be loaded.
193-
Throws `CTBase.ExtensionError` if JSON3 is not available.
194-
"""
195155
function import_ocp_solution(::JSON3Tag, ::AbstractModel; filename::String)
196156
throw(CTBase.ExtensionError(:JSON3))
197157
end
198158

199159
"""
200-
$(TYPEDSIGNATURES)
160+
export_ocp_solution(sol; format=:JLD, filename="solution")
201161
202-
Export a solution in JLD or JSON formats. Redirect to one of the methods:
162+
Export an optimal control solution to a file.
203163
204-
- [`export_ocp_solution(JLD2Tag(), sol, filename=filename)`](@ref export_ocp_solution(::CTModels.JLD2Tag, ::CTModels.Solution))
205-
- [`export_ocp_solution(JSON3Tag(), sol, filename=filename)`](@ref export_ocp_solution(::CTModels.JSON3Tag, ::CTModels.Solution))
164+
# Arguments
165+
- `sol::AbstractSolution`: The solution to export.
206166
207-
# Examples
167+
# Keyword Arguments
168+
- `format::Symbol=:JLD`: Export format, either `:JLD` or `:JSON`.
169+
- `filename::String="solution"`: Base filename (extension added automatically).
208170
209-
```julia-repl
210-
julia> using JSON3
211-
julia> export_ocp_solution(sol; filename="solution", format=:JSON)
212-
julia> using JLD2
213-
julia> export_ocp_solution(sol; filename="solution", format=:JLD) # JLD is the default
214-
```
171+
# Notes
172+
Requires loading the appropriate package (`JLD2` or `JSON3`) before use.
173+
174+
See also: [`import_ocp_solution`](@ref)
215175
"""
216176
function export_ocp_solution(
217177
sol::AbstractSolution;
@@ -232,21 +192,24 @@ function export_ocp_solution(
232192
end
233193

234194
"""
235-
$(TYPEDSIGNATURES)
195+
import_ocp_solution(ocp; format=:JLD, filename="solution")
236196
237-
Import a solution from a JLD or JSON file. Redirect to one of the methods:
197+
Import an optimal control solution from a file.
238198
239-
- [`import_ocp_solution(JLD2Tag(), ocp, filename=filename)`](@ref import_ocp_solution(::CTModels.JLD2Tag, ::CTModels.Model))
240-
- [`import_ocp_solution(JSON3Tag(), ocp, filename=filename)`](@ref import_ocp_solution(::CTModels.JSON3Tag, ::CTModels.Model))
199+
# Arguments
200+
- `ocp::AbstractModel`: The model associated with the solution.
241201
242-
# Examples
202+
# Keyword Arguments
203+
- `format::Symbol=:JLD`: Import format, either `:JLD` or `:JSON`.
204+
- `filename::String="solution"`: Base filename (extension added automatically).
243205
244-
```julia-repl
245-
julia> using JSON3
246-
julia> sol = import_ocp_solution(ocp; filename="solution", format=:JSON)
247-
julia> using JLD2
248-
julia> sol = import_ocp_solution(ocp; filename="solution", format=:JLD) # JLD is the default
249-
```
206+
# Returns
207+
- `Solution`: The imported solution.
208+
209+
# Notes
210+
Requires loading the appropriate package (`JLD2` or `JSON3`) before use.
211+
212+
See also: [`export_ocp_solution`](@ref)
250213
"""
251214
function import_ocp_solution(
252215
ocp::AbstractModel;
@@ -303,7 +266,4 @@ include(joinpath(@__DIR__, "nlp", "discretized_ocp.jl"))
303266
include(joinpath(@__DIR__, "nlp", "model_api.jl"))
304267
include(joinpath(@__DIR__, "init", "initial_guess.jl"))
305268

306-
#
307-
export plot, plot!
308-
309269
end

src/core/types/nlp.jl

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Concrete subtypes `T <: AbstractOCPTool` are expected to:
2020
- `options_sources::NamedTuple` — provenance for each option
2121
(`:ct_default` or `:user`).
2222
- optionally provide option metadata by specializing
23-
[`_option_specs(::Type{T})`](@ref), returning a `NamedTuple` of
23+
[`_option_specs`](@ref CTModels._option_specs), returning a `NamedTuple` of
2424
[`OptionSpec`](@ref) values.
2525
- typically define a keyword-only constructor
2626
`T(; kwargs...)` implemented using [`_build_ocp_tool_options`](@ref), so
@@ -54,19 +54,6 @@ struct OptionSpec
5454
description::Any # Short English description (String) or `missing` if not documented yet.
5555
end
5656

57-
"""
58-
$(TYPEDSIGNATURES)
59-
60-
Construct an [`OptionSpec`](@ref) with keyword arguments.
61-
62-
# Keyword Arguments
63-
64-
- `type`: Expected Julia type for the option value (default: `missing`).
65-
- `default`: Default value (default: `missing`).
66-
- `description`: Human-readable description (default: `missing`).
67-
"""
68-
OptionSpec(; type=missing, default=missing, description=missing) = OptionSpec(type, default, description)
69-
7057
"""
7158
$(TYPEDEF)
7259

src/core/types/ocp_model.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ $(TYPEDEF)
66
77
Abstract base type for optimal control problem models.
88
9-
Subtypes represent either a fully built immutable model ([`Model`](@ref)) or a
9+
Subtypes represent either a fully built immutable model ([`Model`](@ref CTModels.Model)) or a
1010
mutable model under construction ([`PreModel`](@ref)).
1111
12-
See also: [`Model`](@ref), [`PreModel`](@ref).
12+
See also: [`Model`](@ref CTModels.Model), [`PreModel`](@ref).
1313
"""
1414
abstract type AbstractModel end
1515

@@ -102,49 +102,49 @@ end
102102
"""
103103
$(TYPEDSIGNATURES)
104104
105-
Return `true` since times are always set in a built [`Model`](@ref).
105+
Return `true` since times are always set in a built [`Model`](@ref CTModels.Model).
106106
"""
107107
__is_times_set(ocp::Model)::Bool = true
108108

109109
"""
110110
$(TYPEDSIGNATURES)
111111
112-
Return `true` since state is always set in a built [`Model`](@ref).
112+
Return `true` since state is always set in a built [`Model`](@ref CTModels.Model).
113113
"""
114114
__is_state_set(ocp::Model)::Bool = true
115115

116116
"""
117117
$(TYPEDSIGNATURES)
118118
119-
Return `true` since control is always set in a built [`Model`](@ref).
119+
Return `true` since control is always set in a built [`Model`](@ref CTModels.Model).
120120
"""
121121
__is_control_set(ocp::Model)::Bool = true
122122

123123
"""
124124
$(TYPEDSIGNATURES)
125125
126-
Return `true` since variable is always set in a built [`Model`](@ref).
126+
Return `true` since variable is always set in a built [`Model`](@ref CTModels.Model).
127127
"""
128128
__is_variable_set(ocp::Model)::Bool = true
129129

130130
"""
131131
$(TYPEDSIGNATURES)
132132
133-
Return `true` since dynamics is always set in a built [`Model`](@ref).
133+
Return `true` since dynamics is always set in a built [`Model`](@ref CTModels.Model).
134134
"""
135135
__is_dynamics_set(ocp::Model)::Bool = true
136136

137137
"""
138138
$(TYPEDSIGNATURES)
139139
140-
Return `true` since objective is always set in a built [`Model`](@ref).
140+
Return `true` since objective is always set in a built [`Model`](@ref CTModels.Model).
141141
"""
142142
__is_objective_set(ocp::Model)::Bool = true
143143

144144
"""
145145
$(TYPEDSIGNATURES)
146146
147-
Return `true` since definition is always set in a built [`Model`](@ref).
147+
Return `true` since definition is always set in a built [`Model`](@ref CTModels.Model).
148148
"""
149149
__is_definition_set(ocp::Model)::Bool = true
150150

@@ -154,7 +154,7 @@ $(TYPEDEF)
154154
Mutable optimal control problem model under construction.
155155
156156
A `PreModel` is used to incrementally define an optimal control problem before
157-
building it into an immutable [`Model`](@ref). Fields can be set in any order
157+
building it into an immutable [`Model`](@ref CTModels.Model). Fields can be set in any order
158158
and the model is validated before building.
159159
160160
# Fields

src/nlp/discretized_ocp.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Return the original optimal control problem from a discretised problem.
4040
4141
# Returns
4242
43-
- The underlying [`Model`](@ref) (optimal control problem).
43+
- The underlying [`Model`](@ref CTModels.Model) (optimal control problem).
4444
"""
4545
function ocp_model(prob::DiscretizedOptimalControlProblem)
4646
return prob.optimal_control_problem

src/nlp/options_schema.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ end
6363
# - description : short human-readable description (or `missing`).
6464
# ---------------------------------------------------------------------------
6565

66+
function OptionSpec(; type=missing, default=missing, description=missing)
67+
OptionSpec(type, default, description)
68+
end
69+
6670
# Default: no metadata for a given tool type.
6771
"""
6872
$(TYPEDSIGNATURES)

0 commit comments

Comments
 (0)