Skip to content

Commit

Permalink
[WIP] Leave only core definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsiqueira committed Apr 8, 2021
1 parent b23cdcc commit 14f84bb
Show file tree
Hide file tree
Showing 17 changed files with 266 additions and 705 deletions.
7 changes: 2 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ uuid = "ff4d7338-4cf1-434d-91df-b86cb86fb843"
version = "0.1.0"

[deps]
ADNLPModels = "54578032-b7ea-4c30-94aa-7cbd1cce6c9a"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
NLPModels = "a4795742-8479-5a88-8948-cc11e1c8c1a6"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[compat]
NLPModels = "0.14"
julia = "^1.3.0"

[extras]
ADNLPModels = "54578032-b7ea-4c30-94aa-7cbd1cce6c9a"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["ADNLPModels", "LinearAlgebra", "Logging", "Test"]
test = ["LinearAlgebra", "Logging", "Test"]
9 changes: 4 additions & 5 deletions src/SolverCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ module SolverCore

# stdlib
using Logging, Printf
using OrderedCollections

# include("stats.jl")
include("logger.jl")
include("output.jl")
include("solver.jl")
include("output.jl")

include("parameters.jl")
include("traits.jl")

include("grid-search-tuning.jl")

include("optsolver.jl")

end
33 changes: 18 additions & 15 deletions src/grid-search-tuning.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
export grid_search_tune

# ISSUE: For grid_search_tune to work, we need to define `reset!`
function reset! end

"""
solver, results = grid_search_tune(SolverType, problems; kwargs...)
Expand Down Expand Up @@ -31,7 +34,6 @@ function grid_search_tune(
success = o -> o.status == :first_order,
costs = [
(o -> o.elapsed_time, 100.0),
(o -> o.counters.neval_obj + o.counters.neval_cons, 1000),
(o -> !success(o), 1),
],
grid_length = 10,
Expand All @@ -40,15 +42,15 @@ function grid_search_tune(
) where Solver <: AbstractSolver

solver_params = parameters(Solver)
params = Dict()
params = OrderedDict()
for (k,v) in pairs(solver_params)
if v[:type] == :real
if v[:type] <: AbstractFloat && (!haskey(v, :scale) || v[:scale] == :linear)
params[k] = LinRange(v[:min], v[:max], grid_length)
elseif v[:type] == :log
elseif v[:type] <: AbstractFloat && v[:scale] == :log
params[k] = exp.(LinRange(log(v[:min]), log(v[:max]), grid_length))
elseif v[:type] == :bool
elseif v[:type] == Bool
params[k] = (false, true)
elseif v[:type] == :int
elseif v[:type] <: Integer
params[k] = v[:min]:v[:max]
end
end
Expand All @@ -57,24 +59,25 @@ function grid_search_tune(
end

# Precompiling
nlp = first(problems)
problem = first(problems)
try
solver = Solver(Val(:nosolve), nlp)
solver = Solver(problem)
output = with_logger(NullLogger()) do
solve!(solver, nlp)
solve!(solver, problem)
end
finally
finalize(nlp)
finalize(problem)
end

cost(θ) = begin
total_cost = [zero(x[2]) for x in costs]
for nlp in problems
reset!(nlp)
for problem in problems
reset!(problem)
try
solver = Solver(Val(:nosolve), nlp)
solver = Solver(problem)
P = (k => θi for (k,θi) in zip(keys(solver_params), θ))
output = with_logger(NullLogger()) do
solve!(solver, nlp; (k => θi for (k,θi) in zip(keys(solver_params), θ))...)
solve!(solver, problem; P...)
end
for (i, c) in enumerate(costs)
if success(output)
Expand All @@ -89,7 +92,7 @@ function grid_search_tune(
end
@show ex
finally
finalize(nlp)
finalize(problem)
end
end
total_cost
Expand Down
88 changes: 0 additions & 88 deletions src/logger.jl

This file was deleted.

71 changes: 0 additions & 71 deletions src/optsolver.jl

This file was deleted.

4 changes: 2 additions & 2 deletions src/output.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export AbstractSolverOutput

"""
AbstractSolverOutput
AbstractSolverOutput{T}
Base type for output of JSO-compliant solvers.
An output must have at least the following:
- `status :: Bool`
- `status :: Symbol`
- `solution`
"""
abstract type AbstractSolverOutput{T} end
Expand Down
45 changes: 45 additions & 0 deletions src/parameters.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
export parameters, are_valid_parameters

"""
named_tuple = parameters(solver)
named_tuple = parameters(SolverType)
named_tuple = parameters(SolverType{T})
Return the parameters of a `solver`, or of the type `SolverType`.
You can specify the type `T` of the `SolverType`.
The returned structure is a nested NamedTuple.
Each key of `named_tuple` is the name of a parameter, and its value is a NamedTuple containing
- `default`: The default value of the parameter.
- `type`: The type of the parameter, such as `Int`, `Float64`, `T`, etc.
and possibly other values depending on the `type`.
Some possibilies are:
- `scale`: How to explore the domain
- `:linear`: A continuous value within a range
- `:log`: A positive continuous value that should be explored logarithmically (like 10⁻², 10⁻¹, 1, 10).
- `min`: Minimum value.
- `max`: Maximum value.
Solvers should define
SolverCore.parameters(::Type{Solver{T}}) where T
"""
function parameters end

parameters(::Type{S}) where S <: AbstractSolver = parameters(S{Float64})
parameters(::S) where S <: AbstractSolver = parameters(S)

"""
are_valid_parameters(solver, args...)
Return whether the parameters given in `args` are valid for `solver`.
The order of the parameters must be the same as in `parameters(solver)`.
Solvers should define
SolverCore.are_valid_parameters(::Type{Solver{T}}, arg1, arg2, ...) where T
"""
function are_valid_parameters end
are_valid_parameters(::Type{S}, args...) where S <: AbstractSolver = are_valid_parameters(S{Float64}, args...)
are_valid_parameters(::S, args...) where S <: AbstractSolver = are_valid_parameters(S, args...)
36 changes: 2 additions & 34 deletions src/solver.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export AbstractSolver, solve!, parameters, are_valid_parameters
export AbstractSolver, solve!

"""
AbstractSolver
Expand All @@ -20,36 +20,4 @@ end
Solve `problem` with `solver`.
"""
function solve!(::AbstractSolver, ::Any) end

"""
named_tuple = parameters(solver)
named_tuple = parameters(SolverType)
named_tuple = parameters(SolverType{T})
Return the parameters of a `solver`, or of the type `SolverType`.
You can specify the type `T` of the `SolverType`.
The returned structure is a nested NamedTuple.
Each key of `named_tuple` is the name of a parameter, and its value is a NamedTuple containing
- `default`: The default value of the parameter.
- `type`: The type of the parameter, which can any of:
- `:real`: A continuous value within a range
- `:log`: A positive continuous value that should be explored logarithmically (like 10⁻², 10⁻¹, 1, 10).
- `:int`: Integer value.
- `:bool`: Boolean value.
- `min`: Minimum value (may not be included for some parameter types).
- `max`: Maximum value.
"""
function parameters(::Type{AbstractSolver{T}}) where T end

parameters(::Type{S}) where S <: AbstractSolver = parameters(S{Float64})
parameters(::S) where S <: AbstractSolver = parameters(S)

"""
are_valid_parameters(solver, args...)
Return whether the parameters given in `args` are valid for `solver`.
The order of the parameters must be the same as in `parameters(solver)`.
"""
function are_valid_parameters(::Type{AbstractSolver}, args...) end
are_valid_parameters(::S) where S <: AbstractSolver = are_valid_parameters(S)
function solve! end
Loading

0 comments on commit 14f84bb

Please sign in to comment.