From 1e559964740339d8c380d4992882d27e271d1102 Mon Sep 17 00:00:00 2001 From: Olivier Cots Date: Sat, 15 Jun 2024 23:01:29 +0200 Subject: [PATCH] update doc --- docs/make.jl | 1 + docs/src/api-init.md | 19 +++++++++++++++++++ src/CTBase.jl | 3 --- src/default.jl | 9 +++++++++ src/onepass.jl | 8 +++++++- src/print.jl | 31 +++++++++++++++++++++++-------- src/repl.jl | 6 ++++++ 7 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 docs/src/api-init.md diff --git a/docs/make.jl b/docs/make.jl index f90e8771..b6d847da 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -12,6 +12,7 @@ makedocs( "api-description.md", "api-diffgeom.md", "api-exceptions.md", + "api-init.md", "api-model.md", "api-parser.md", "api-plot.md", diff --git a/docs/src/api-init.md b/docs/src/api-init.md new file mode 100644 index 00000000..6c01cf93 --- /dev/null +++ b/docs/src/api-init.md @@ -0,0 +1,19 @@ +# Initialisation + +## Index + +```@index +Pages = ["api-init.md"] +Modules = [CTBase] +Order = [:module, :constant, :type, :function, :macro] +Private = false +``` + +## Documentation + +```@autodocs +Modules = [CTBase] +Order = [:module, :constant, :type, :function, :macro] +Pages = ["init.jl"] +Private = false +``` diff --git a/src/CTBase.jl b/src/CTBase.jl index aba1c012..5e03391d 100644 --- a/src/CTBase.jl +++ b/src/CTBase.jl @@ -194,8 +194,6 @@ See also: [`ctVector`](@ref), [`DState`](@ref). """ const DCostate = ctVector -__auto() = AutoForwardDiff() # default AD backend - # include("exception.jl") include("description.jl") @@ -214,7 +212,6 @@ include("model.jl") include("differential_geometry.jl") # include("ctparser_utils.jl") -##include("ctparser.jl") include("onepass.jl") include("repl.jl") # diff --git a/src/default.jl b/src/default.jl index d88cc413..3d2f9acb 100644 --- a/src/default.jl +++ b/src/default.jl @@ -1,6 +1,15 @@ """ $(TYPEDSIGNATURES) +Used to set the default value of Automatic Differentiation backend. + +The default value is `AutoForwardDiff()`, that is the `ForwardDiff` package is used by default. +""" +__auto() = AutoForwardDiff() # default AD backend + +""" +$(TYPEDSIGNATURES) + Used to set the default value of the time dependence of the functions. The default value is `Autonomous`, which means that the functions are considered time independent. diff --git a/src/onepass.jl b/src/onepass.jl index f099d8c7..81d4d094 100644 --- a/src/onepass.jl +++ b/src/onepass.jl @@ -430,7 +430,13 @@ p_bolza!(p, ocp, e1, e2, type; log=false) = begin end, p.lnum, p.line) end -# redirection to Model() to avoid confusion with other functions Model from other packages +""" +$(TYPEDSIGNATURES) + +Redirection to [`Model`](@ref) to avoid confusion with other functions Model from other packages +if imported. This function is used by [`@def`](@ref). + +""" function __OCPModel(args...; kwargs...) return CTBase.Model(args...; kwargs...) end diff --git a/src/print.jl b/src/print.jl index 758f9c7d..769ce397 100644 --- a/src/print.jl +++ b/src/print.jl @@ -198,20 +198,35 @@ function Base.show(io::IO, ::MIME"text/plain", ocp::OptimalControlModel{<: TimeD #is_variable_dependent(ocp) && push!(header, "variable") push!(header, "variable") push!(header, "dynamics*", "objective*", "constraints") - data = hcat(__is_time_not_set(ocp) ? "❌" : "✅", - __is_state_not_set(ocp) ? "❌" : "✅", - __is_control_not_set(ocp) ? "❌" : "✅") + data = hcat(__is_time_not_set(ocp) ? "X" : "V", + __is_state_not_set(ocp) ? "X" : "V", + __is_control_not_set(ocp) ? "X" : "V") #is_variable_dependent(ocp) && begin (data = hcat(data, - __is_variable_not_set(ocp) ? "❌" : "✅")) + __is_variable_not_set(ocp) ? "X" : "V")) end data = hcat(data, - __is_dynamics_not_set(ocp) ? "❌" : "✅", - __is_objective_not_set(ocp) ? "❌" : "✅", - isempty(ocp.constraints) ? "❌" : "✅") + __is_dynamics_not_set(ocp) ? "X" : "V", + __is_objective_not_set(ocp) ? "X" : "V", + isempty(ocp.constraints) ? "X" : "V") println("") - pretty_table(data, header=header, header_crayon=crayon"yellow") + h1 = Highlighter( + (data, i, j) -> data[i, j] == "X", + bold = true, + foreground = :red ) + h2 = Highlighter( + (data, i, j) -> data[i, j] == "V", + bold = true, + foreground = :green ) + pretty_table(io, data; + tf=tf_unicode_rounded, + header=header, + header_crayon=crayon"yellow", + crop=:none, + highlighters=(h1, h2), + alignment=:c, + compact_printing=true) nothing end diff --git a/src/repl.jl b/src/repl.jl index ab60e20c..b9f31933 100644 --- a/src/repl.jl +++ b/src/repl.jl @@ -18,6 +18,12 @@ global ct_repl_is_set::Bool = false global ct_repl_data::CTRepl global ct_repl_ct_repl_history::HistoryRepl +""" +$(TYPEDSIGNATURES) + +Update the model adding the expression e. It must be public since in the ct repl, this function +is quoted each time an expression is parsed and is valid. +""" function ct_repl_update_model(e::Expr) ct_repl_data.debug && (println("debug> expression to add: ", e))