Skip to content

Commit 8dacd43

Browse files
author
Alexey Stukalov
committed
SemOptimizer: reattach docstrings to ctor
Instead of engine-specific subtype as it might be not available in the user session.
1 parent a560a01 commit 8dacd43

File tree

4 files changed

+66
-38
lines changed

4 files changed

+66
-38
lines changed

ext/SEMNLOptExt/NLopt.jl

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44

55
const NLoptConstraint = Pair{Any, Number}
66

7+
struct SemOptimizerNLopt <: SemOptimizer{:NLopt}
8+
algorithm::Symbol
9+
local_algorithm::Union{Symbol, Nothing}
10+
options::Dict{Symbol, Any}
11+
local_options::Dict{Symbol, Any}
12+
equality_constraints::Vector{NLoptConstraint}
13+
inequality_constraints::Vector{NLoptConstraint}
14+
end
15+
16+
############################################################################################
17+
### Constructor
18+
############################################################################################
19+
720
"""
821
Connects to `NLopt.jl` as the optimization backend.
922
Only usable if `NLopt.jl` is loaded in the current Julia session!
@@ -74,19 +87,6 @@ see [Constrained optimization](@ref) in our online documentation.
7487
7588
Subtype of `SemOptimizer`.
7689
"""
77-
struct SemOptimizerNLopt <: SemOptimizer{:NLopt}
78-
algorithm::Symbol
79-
local_algorithm::Union{Symbol, Nothing}
80-
options::Dict{Symbol, Any}
81-
local_options::Dict{Symbol, Any}
82-
equality_constraints::Vector{NLoptConstraint}
83-
inequality_constraints::Vector{NLoptConstraint}
84-
end
85-
86-
############################################################################################
87-
### Constructor
88-
############################################################################################
89-
9090
function SemOptimizerNLopt(;
9191
algorithm = :LD_LBFGS,
9292
local_algorithm = nothing,
@@ -115,6 +115,15 @@ function SemOptimizerNLopt(;
115115
)
116116
end
117117

118+
"""
119+
SemOptimizer(args...; engine = :NLopt, kwargs...)
120+
121+
Creates SEM optimizer using [*NLopt.jl*](https://github.com/JuliaOpt/NLopt.jl).
122+
123+
# Extended help
124+
125+
See [`SemOptimizerNLopt`](@ref) for a full reference.
126+
"""
118127
SEM.SemOptimizer(::Val{:NLopt}, args...; kwargs...) = SemOptimizerNLopt(args...; kwargs...)
119128

120129
############################################################################################

src/optimizer/Empty.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
############################################################################################
22
### Types
33
############################################################################################
4-
"""
5-
Empty placeholder for models that don't need
6-
an optimizer part.
7-
8-
# Constructor
94

10-
SemOptimizerEmpty()
11-
"""
5+
# dummy SEM optimizer
126
struct SemOptimizerEmpty <: SemOptimizer{:Empty} end
137

148
############################################################################################
159
### Constructor
1610
############################################################################################
1711

12+
"""
13+
SemOptimizer(engine = :Empty)
14+
15+
Constructs a dummy optimizer for models that don't need it.
16+
"""
1817
SemOptimizer(::Val{:Empty}) = SemOptimizerEmpty()
1918

2019
############################################################################################

src/optimizer/abstract.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
engine(::Type{<:SemOptimizer{E}}) where {E} = E
22
engine(optimizer::SemOptimizer) = engine(typeof(optimizer))
33

4+
"""
5+
SemOptimizer(args...; engine::Symbol = :Optim, kwargs...)
6+
7+
Constructs [`SemOptimizer`](@ref) for the specified optimization `engine`.
8+
9+
A wrapper function that passes `args...` and `kwargs...` to the
10+
engine-specific optimizer constructor.
11+
12+
Uses `:Optim` as the default engine.
13+
Throws an error if the specified `engine` is not supported.
14+
Call [`optimizer_engines`](@ref) for the list of supported engines.
15+
16+
For the information about using the engine `:EngineName`, use
17+
```julia
18+
?SemOptimizer(Val(:EngineName))
19+
```
20+
21+
"""
422
SemOptimizer(args...; engine::Symbol = :Optim, kwargs...) =
523
SemOptimizer{engine}(args...; kwargs...)
624

src/optimizer/optim.jl

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,29 @@
33
############################################################################################
44
### Types and Constructor
55
############################################################################################
6-
"""
7-
SemOptimizerOptim{A, B} <: SemOptimizer{:Optim}
8-
9-
Connects to `Optim.jl` as the optimization backend.
106

11-
# Constructor
7+
# SemOptimizer for the Optim.jl
8+
mutable struct SemOptimizerOptim{A, B} <: SemOptimizer{:Optim}
9+
algorithm::A
10+
options::B
11+
end
1212

13-
SemOptimizerOptim(;
13+
"""
14+
SemOptimizer(;
15+
engine = :Optim,
1416
algorithm = LBFGS(),
1517
options = Optim.Options(;f_reltol = 1e-10, x_abstol = 1.5e-8),
1618
kwargs...)
1719
20+
Creates SEM optimizer using [*Optim.jl*](https://julianlsolvers.github.io/Optim.jl/stable/).
21+
1822
# Arguments
19-
- `algorithm`: optimization algorithm from `Optim.jl`
23+
- `algorithm`: optimization algorithm from *Optim.jl*
2024
- `options::Optim.Options`: options for the optimization algorithm
2125
2226
# Usage
23-
All algorithms and options from the Optim.jl library are available, for more information see
24-
the Optim.jl online documentation.
27+
All algorithms and options from the *Optim.jl* package are available, for more information see
28+
the *Optim.jl* online documentation.
2529
2630
# Examples
2731
```julia
@@ -53,22 +57,20 @@ for the variance parameters (the diagonal of the *S* matrix).
5357
## Interfaces
5458
- `algorithm(::SemOptimizerOptim)`
5559
- `options(::SemOptimizerOptim)`
56-
57-
## Implementation
58-
59-
Subtype of `SemOptimizer`.
6060
"""
61-
mutable struct SemOptimizerOptim{A, B} <: SemOptimizer{:Optim}
62-
algorithm::A
63-
options::B
64-
end
65-
6661
SemOptimizerOptim(;
6762
algorithm = LBFGS(),
6863
options = Optim.Options(; f_reltol = 1e-10, x_abstol = 1.5e-8),
6964
kwargs...,
7065
) = SemOptimizerOptim(algorithm, options)
7166

67+
"""
68+
SemOptimizer(args...; engine = :Optim, kwargs...)
69+
70+
Creates SEM optimizer using [*Optim.jl*](https://julianlsolvers.github.io/Optim.jl/stable/).
71+
72+
See [`SemOptimizerOptim`](@ref) for the full reference.
73+
"""
7274
SemOptimizer(::Val{:Optim}, args...; kwargs...) = SemOptimizerOptim(args...; kwargs...)
7375

7476
############################################################################################

0 commit comments

Comments
 (0)