Skip to content

Commit 97e6e7b

Browse files
authored
Merge pull request #74 from control-toolbox/doc
add docstrings
2 parents b2292dd + 091a856 commit 97e6e7b

9 files changed

Lines changed: 215 additions & 10 deletions

File tree

docs/make.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ makedocs(;
1616
asset("https://control-toolbox.org/assets/js/documentation.js"),
1717
],
1818
),
19-
pages=["Introduction" => "index.md", "Developers" => "dev.md"],
19+
pages=[
20+
"Introduction" => "index.md",
21+
"Developers" => "dev.md"],
2022
checkdocs=:none,
2123
)
2224

docs/src/dev.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ CurrentModule = CTModels
88
## CTModels
99

1010
```@autodocs
11+
Pages = ["CTModels.jl"]
1112
Modules = [CTModels]
1213
Order = [:module]
13-
Pages = ["CTModels.jl"]
14-
Private = false
1514
```
1615

1716
## Index
@@ -27,6 +26,5 @@ Order = [:constant, :type, :function, :macro]
2726
```@autodocs
2827
Modules = [CTModels]
2928
Order = [:constant, :type, :function, :macro]
30-
Public = false
3129
```
3230

ext/CTModelsJLD.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module CTModelsJLD
33
using CTBase
44
using CTModels
55
using DocStringExtensions
6-
76
using JLD2
87

98
"""
@@ -21,7 +20,7 @@ end
2120
"""
2221
$(TYPEDSIGNATURES)
2322
24-
Read OCP solution in JLD format
23+
Import OCP solution in JLD format
2524
"""
2625
function CTModels.import_ocp_solution(
2726
::CTModels.JLD2Tag, ocp::CTModels.Model; filename_prefix="solution"

ext/CTModelsJSON.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ end
5555
"""
5656
$(TYPEDSIGNATURES)
5757
58-
Read OCP solution in JSON format
58+
Import OCP solution in JSON format
5959
"""
6060
function CTModels.import_ocp_solution(
6161
::CTModels.JSON3Tag, ocp::CTModels.Model; filename_prefix="solution"

src/CTModels.jl

Lines changed: 149 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
Lists all the imported modules and packages:
55
66
$(IMPORTS)
7+
8+
List of all the exported names:
9+
10+
$(EXPORTS)
711
"""
812
module CTModels
913

@@ -16,33 +20,152 @@ using MLStyle
1620
using Parameters # @with_kw: to have default values in struct
1721
using MacroTools: striplines
1822
using PrettyTables # To print a table
19-
import RecipesBase: plot, plot!, RecipesBase
23+
using RecipesBase: plot, plot!, RecipesBase
2024

2125
# aliases
26+
27+
"""
28+
Type alias for a dimension. This is used to define the dimension of the state space,
29+
the costate space, the control space, etc.
30+
31+
```@example
32+
julia> const Dimension = Integer
33+
```
34+
"""
2235
const Dimension = Int
36+
37+
"""
38+
Type alias for a real number.
39+
40+
```@example
41+
julia> const ctNumber = Real
42+
```
43+
"""
2344
const ctNumber = Real
45+
46+
"""
47+
Type alias for a time.
48+
49+
```@example
50+
julia> const Time = ctNumber
51+
```
52+
53+
See also: [`ctNumber`](@ref), [`Times`](@ref), [`TimesDisc`](@ref).
54+
"""
2455
const Time = ctNumber
56+
57+
"""
58+
Type alias for a vector of real numbers.
59+
60+
```@example
61+
julia> const ctVector = AbstractVector{<:ctNumber}
62+
```
63+
64+
See also: [`ctNumber`](@ref).
65+
"""
2566
const ctVector = AbstractVector{<:ctNumber}
67+
68+
"""
69+
Type alias for a vector of times.
70+
71+
```@example
72+
julia> const Times = AbstractVector{<:Time}
73+
```
74+
75+
See also: [`Time`](@ref), [`TimesDisc`](@ref).
76+
"""
77+
const Times = AbstractVector{<:Time}
78+
79+
"""
80+
Type alias for a grid of times. This is used to define a discretization of time interval given to solvers.
81+
82+
```@example
83+
julia> const TimesDisc = Union{Times, StepRangeLen}
84+
```
85+
86+
See also: [`Time`](@ref), [`Times`](@ref).
87+
"""
88+
const TimesDisc = Union{Times,StepRangeLen}
89+
90+
"""
91+
Type alias for a dictionnary of constraints. This is used to store constraints before building the model.
92+
93+
```@example
94+
julia> const TimesDisc = Union{Times, StepRangeLen}
95+
```
96+
97+
See also: [`ConstraintsModel`](@ref), [`PreModel`](@ref) and [`Model`](@ref).
98+
"""
2699
const ConstraintsDictType = Dict{
27100
Symbol,Tuple{Symbol,Union{Function,OrdinalRange{<:Int}},ctVector,ctVector}
28101
}
29-
const Times = AbstractVector{<:Time}
30-
const TimesDisc = Union{Times,StepRangeLen}
31102

32103
#
33104
include("default.jl")
34105

35106
# export / import
107+
"""
108+
$(TYPEDEF)
109+
110+
Abstract type for export/import functions, used to choose between JSON or JLD extensions.
111+
"""
36112
abstract type AbstractTag end
113+
114+
"""
115+
$(TYPEDEF)
116+
117+
JLD tag for export/import functions.
118+
"""
37119
struct JLD2Tag <: AbstractTag end
120+
121+
"""
122+
$(TYPEDEF)
123+
124+
JSON tag for export/import functions.
125+
"""
38126
struct JSON3Tag <: AbstractTag end
39127

40128
# to be extended
129+
"""
130+
$(TYPEDSIGNATURES)
131+
132+
Export a solution in JLD format.
133+
"""
41134
export_ocp_solution(::JLD2Tag, args...; kwargs...) = throw(CTBase.ExtensionError(:JLD2))
135+
136+
"""
137+
$(TYPEDSIGNATURES)
138+
139+
Import a solution from a JLD file.
140+
"""
42141
import_ocp_solution(::JLD2Tag, args...; kwargs...) = throw(CTBase.ExtensionError(:JLD2))
142+
143+
"""
144+
$(TYPEDSIGNATURES)
145+
146+
Export a solution in JSON format.
147+
"""
43148
export_ocp_solution(::JSON3Tag, args...; kwargs...) = throw(CTBase.ExtensionError(:JSON3))
149+
150+
"""
151+
$(TYPEDSIGNATURES)
152+
153+
Import a solution from a JLD file.
154+
"""
44155
import_ocp_solution(::JSON3Tag, args...; kwargs...) = throw(CTBase.ExtensionError(:JSON3))
45156

157+
"""
158+
$(TYPEDSIGNATURES)
159+
160+
Export a solution in JLD or JSON formats.
161+
162+
# Examples
163+
164+
```julia-repl
165+
julia> CTModels.export_ocp_solution(sol; filename_prefix="solution", format=:JSON)
166+
julia> CTModels.export_ocp_solution(sol; filename_prefix="solution", format=:JLD)
167+
```
168+
"""
46169
function export_ocp_solution(args...; format=__format(), kwargs...)
47170
if format == :JLD
48171
return export_ocp_solution(JLD2Tag(), args...; kwargs...)
@@ -57,6 +180,18 @@ function export_ocp_solution(args...; format=__format(), kwargs...)
57180
end
58181
end
59182

183+
"""
184+
$(TYPEDSIGNATURES)
185+
186+
Import a solution from a JLD or JSON file.
187+
188+
# Examples
189+
190+
```julia-repl
191+
julia> sol = CTModels.import_ocp_solution(ocp; filename_prefix="solution", format=:JSON)
192+
julia> sol = CTModels.import_ocp_solution(ocp; filename_prefix="solution", format=:JLD)
193+
```
194+
"""
60195
function import_ocp_solution(args...; format=__format(), kwargs...)
61196
if format == :JLD
62197
return import_ocp_solution(JLD2Tag(), args...; kwargs...)
@@ -76,9 +211,20 @@ include("utils.jl")
76211
include("types.jl")
77212

78213
# to be extended
214+
"""
215+
$(TYPEDSIGNATURES)
216+
217+
Plot a solution.
218+
"""
79219
function RecipesBase.plot(sol::AbstractSolution; kwargs...)
80220
throw(CTBase.ExtensionError(:Plots))
81221
end
222+
223+
"""
224+
$(TYPEDSIGNATURES)
225+
226+
Plot a solution on an existing plot.
227+
"""
82228
function RecipesBase.plot!(p::RecipesBase.AbstractPlot, sol::AbstractSolution; kwargs...)
83229
throw(CTBase.ExtensionError(:Plots))
84230
end

src/dual_model.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
# variable_constraints_lb_dual::VC_LB_Dual
1616
# variable_constraints_ub_dual::VC_UB_Dual
1717

18+
"""
19+
$(TYPEDSIGNATURES)
20+
21+
"""
1822
function path_constraints(
1923
model::DualModel{
2024
PC,
@@ -32,6 +36,10 @@ function path_constraints(
3236
return model.path_constraints
3337
end
3438

39+
"""
40+
$(TYPEDSIGNATURES)
41+
42+
"""
3543
function path_constraints_dual(
3644
model::DualModel{
3745
<:Union{Function,Nothing},
@@ -49,6 +57,10 @@ function path_constraints_dual(
4957
return model.path_constraints_dual
5058
end
5159

60+
"""
61+
$(TYPEDSIGNATURES)
62+
63+
"""
5264
function boundary_constraints(
5365
model::DualModel{
5466
<:Union{Function,Nothing},
@@ -66,6 +78,10 @@ function boundary_constraints(
6678
return model.boundary_constraints
6779
end
6880

81+
"""
82+
$(TYPEDSIGNATURES)
83+
84+
"""
6985
function boundary_constraints_dual(
7086
model::DualModel{
7187
<:Union{Function,Nothing},
@@ -83,6 +99,10 @@ function boundary_constraints_dual(
8399
return model.boundary_constraints_dual
84100
end
85101

102+
"""
103+
$(TYPEDSIGNATURES)
104+
105+
"""
86106
function state_constraints_lb_dual(
87107
model::DualModel{
88108
<:Union{Function,Nothing},
@@ -100,6 +120,10 @@ function state_constraints_lb_dual(
100120
return model.state_constraints_lb_dual
101121
end
102122

123+
"""
124+
$(TYPEDSIGNATURES)
125+
126+
"""
103127
function state_constraints_ub_dual(
104128
model::DualModel{
105129
<:Union{Function,Nothing},
@@ -117,6 +141,10 @@ function state_constraints_ub_dual(
117141
return model.state_constraints_ub_dual
118142
end
119143

144+
"""
145+
$(TYPEDSIGNATURES)
146+
147+
"""
120148
function control_constraints_lb_dual(
121149
model::DualModel{
122150
<:Union{Function,Nothing},
@@ -134,6 +162,10 @@ function control_constraints_lb_dual(
134162
return model.control_constraints_lb_dual
135163
end
136164

165+
"""
166+
$(TYPEDSIGNATURES)
167+
168+
"""
137169
function control_constraints_ub_dual(
138170
model::DualModel{
139171
<:Union{Function,Nothing},
@@ -151,6 +183,10 @@ function control_constraints_ub_dual(
151183
return model.control_constraints_ub_dual
152184
end
153185

186+
"""
187+
$(TYPEDSIGNATURES)
188+
189+
"""
154190
function variable_constraints_lb_dual(
155191
model::DualModel{
156192
<:Union{Function,Nothing},
@@ -168,6 +204,10 @@ function variable_constraints_lb_dual(
168204
return model.variable_constraints_lb_dual
169205
end
170206

207+
"""
208+
$(TYPEDSIGNATURES)
209+
210+
"""
171211
function variable_constraints_ub_dual(
172212
model::DualModel{
173213
<:Union{Function,Nothing},

src/model.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,18 @@ function has_free_initial_time(ocp::Model)::Bool
453453
end
454454

455455
# Final time
456+
"""
457+
$(TYPEDSIGNATURES)
458+
459+
"""
456460
function final_time(ocp::AbstractModel)
457461
throw(CTBase.UnauthorizedCall("You cannot get the final time with this function."))
458462
end
459463

464+
"""
465+
$(TYPEDSIGNATURES)
466+
467+
"""
460468
function final_time(ocp::AbstractModel, variable::AbstractVector)
461469
throw(CTBase.UnauthorizedCall("You cannot get the final time with this function."))
462470
end

0 commit comments

Comments
 (0)