Skip to content

Commit 1571e27

Browse files
committed
[WIP] Update parameters
1 parent 8291998 commit 1571e27

File tree

2 files changed

+48
-17
lines changed

2 files changed

+48
-17
lines changed

src/solver.jl

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export AbstractSolver
1+
export AbstractSolver, solve!, parameters
22

33
"""
44
AbstractSolver
@@ -17,14 +17,51 @@ function solve!(::AbstractSolver, ::AbstractNLPModel) end
1717

1818
"""
1919
named_tuple = parameters(solver)
20+
named_tuple = parameters(SolverType)
21+
named_tuple = parameters(SolverType{T})
2022
21-
Return the parameters of `solver`.
23+
Return the parameters of a `solver`, or of the type `SolverType`.
24+
You can specify the type `T` of the `SolverType`.
25+
The returned structure is a nested NamedTuple.
26+
Each key of `named_tuple` is the name of a parameter, and its value is a NamedTuple containing
27+
- `default`: The default value of the parameter.
28+
- `type`: The type of the parameter, which can any of:
29+
- `:real`: A continuous value within a range
30+
- `:log`: A continuous value that should be explorer logarithmically around it's lower value (usually 0) to avoid the bound itself.
31+
- `:int`: Integer value.
32+
- `:bool`: Boolean value.
33+
- `min`: Minimum value (may not be included for some parameter types).
34+
- `max`: Maximum value.
2235
"""
23-
function parameters(::AbstractSolver) end
36+
function parameters(::Type{AbstractSolver{T}}) where T end
37+
38+
parameters(::Type{S}) where S <: AbstractSolver = parameters(S{Float64})
39+
parameters(solver :: AbstractSolver) = parameters(typeof(solver))
2440

2541
"""
2642
nlp = parameter_problem(solver)
2743
2844
Return the problem associated with the tuning of the parameters of `solver`.
2945
"""
30-
function parameter_problem(::AbstractSolver) end
46+
function parameter_problem(::AbstractSolver) end
47+
48+
# parameter_problem(
49+
# solver::DummySolver,
50+
# problems,
51+
# cost,
52+
# cost_bad
53+
# ) = ADNLPModel(
54+
# x -> begin
55+
# total_cost = 0.0
56+
# for nlp in problems
57+
# try
58+
# output = with_logger(NullLogger()) do
59+
# output, _ = DummySolver(nlp)
60+
# end
61+
# total_cost += cost(output)
62+
# catch
63+
# total_cost +=
64+
# end
65+
# end
66+
# end
67+
# )

test/dummy_solver.jl

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ DummySolver(::Val{:nosolve}, nlp :: AbstractNLPModel) = DummySolver(Float64, Val
3030
DummySolver(nlp :: AbstractNLPModel) = DummySolver(Float64, nlp :: AbstractNLPModel)
3131

3232

33-
function solve!(solver::DummySolver{T}, nlp :: AbstractNLPModel;
33+
function SolverCore.solve!(solver::DummySolver{T}, nlp :: AbstractNLPModel;
3434
x :: AbstractVector{T} = T.(nlp.meta.x0),
3535
atol :: Real = sqrt(eps(T)),
3636
rtol :: Real = sqrt(eps(T)),
@@ -133,15 +133,9 @@ function solve!(solver::DummySolver{T}, nlp :: AbstractNLPModel;
133133
)
134134
end
135135

136-
# parameters(::DummySolver) = NamedTuple(α = 1e-2, δ = 1e-8)
137-
138-
# parameter_problem(solver::DummySolver, problems, cost) = ADNLPModel(
139-
# x -> begin
140-
# for nlp in problems
141-
# try
142-
# output = with_logger(NullLogger()) do
143-
# output, solver = DummySolver()
144-
# end
145-
# end
146-
# end
147-
# )
136+
function SolverCore.parameters(::Type{DummySolver{T}}) where T
137+
(
138+
α = (default=T(1e-2), type=:log, min=zero(T), max=one(T)),
139+
δ = (default=eps(T), type=:log, min=zero(T), max=one(T)),
140+
)
141+
end

0 commit comments

Comments
 (0)