Skip to content

Commit

Permalink
Add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Oct 31, 2023
1 parent 8dfc01c commit 443e7b6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
37 changes: 37 additions & 0 deletions ext/ManoptJuMPExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ function MOI.set(model::Optimizer, attr::MOI.RawOptimizerAttribute, value)
return nothing
end

"""
MOI.get(::Optimizer, ::MOI.SolverName)
Return the name of the `Optimizer` with the value of
the `descent_state_type` option.
"""
function MOI.get(model::Optimizer, ::MOI.SolverName)
return "Manopt with $(model.options[DESCENT_STATE_TYPE])"
end
Expand Down Expand Up @@ -255,17 +261,40 @@ function MOI.set(
return nothing
end

"""
MOI.supports(::Optimizer, ::Union{MOI.ObjectiveSense,MOI.ObjectiveFunction})
Return `true` indicating that `Optimizer` supports being set the objective
sense (that is, min, max or feasibility) and the objective function.
"""
function MOI.supports(::Optimizer, ::Union{MOI.ObjectiveSense,MOI.ObjectiveFunction})
return true
end

"""
MOI.set(model::Optimizer, ::MOI.ObjectiveSense, sense::MOI.OptimizationSense)
Modify the objective sense to either `MOI.MAX_SENSE`, `MOI.MIN_SENSE` or
`MOI.FEASIBILITY_SENSE`.
"""
function MOI.set(model::Optimizer, ::MOI.ObjectiveSense, sense::MOI.OptimizationSense)
model.sense = sense
return nothing
end

"""
MOI.set(model::Optimizer, ::MOI.ObjectiveSense, sense::MOI.OptimizationSense)
Return the objective sense, defaults to `MOI.FEASIBILITY_SENSE` if no sense has
already been set.
"""
MOI.get(model::Optimizer, ::MOI.ObjectiveSense) = model.sense

"""
MOI.set(model::Optimizer, ::MOI.ObjectiveFunction{F}, func::F) where {F}
Set the objective function as `func` for `model`.
"""
function MOI.set(model::Optimizer, ::MOI.ObjectiveFunction{F}, func::F) where {F}
nl = convert(MOI.ScalarNonlinearFunction, func)
MOI.Nonlinear.set_objective(model.nlp_model, nl)
Expand All @@ -274,6 +303,14 @@ function MOI.set(model::Optimizer, ::MOI.ObjectiveFunction{F}, func::F) where {F
return nothing
end

"""
const DESCENT_STATE_TYPE = "descent_state_type"
Name of the attribute for the type of the descent state to be used as follows:
```julia
set_attribute(model, "descent_state_type", Manopt.TrustRegionsState)
```
"""
const DESCENT_STATE_TYPE = "descent_state_type"

function MOI.optimize!(model::Optimizer)
Expand Down
6 changes: 3 additions & 3 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function test_sphere()

set_objective_sense(model, MOI.FEASIBILITY_SENSE)
optimize!(model)
@test sum(value.(x).^2) 1
@test sum(value.(x) .^ 2) 1

set_start_value(x[3], nothing)
err = ErrorException("No starting value specified for `3`th variable.")
Expand All @@ -57,7 +57,7 @@ function _test_stiefel(solver)
-1 1
]
# Use `add_bridges = false` in order to test `copy_to`
model = Model(Manopt.JuMP_Optimizer; add_bridges = false)
model = Model(Manopt.JuMP_Optimizer; add_bridges=false)
set_attribute(model, "descent_state_type", solver)
@test get_attribute(model, "descent_state_type") == solver
@variable(model, U[1:2, 1:2] in Stiefel(2, 2), start = 1.0)
Expand All @@ -70,7 +70,7 @@ function _test_stiefel(solver)
end

function test_stiefel()
_test_stiefel(Manopt.GradientDescentState)
return _test_stiefel(Manopt.GradientDescentState)
end

@testset "JuMP tests" begin
Expand Down

0 comments on commit 443e7b6

Please sign in to comment.