From 223a841cac02cef9b9f4b362a205dd4c6ed43ce4 Mon Sep 17 00:00:00 2001 From: Abel Soares Siqueira Date: Thu, 5 Sep 2019 18:33:43 -0300 Subject: [PATCH] Allow callables on bmark functions and add simple bmark tests --- src/bmark/bmark_solvers.jl | 6 +++--- src/bmark/run_solver.jl | 6 +++--- test/runtests.jl | 1 + test/test_bmark.jl | 28 ++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 test/test_bmark.jl diff --git a/src/bmark/bmark_solvers.jl b/src/bmark/bmark_solvers.jl index 2c70038..a430726 100644 --- a/src/bmark/bmark_solvers.jl +++ b/src/bmark/bmark_solvers.jl @@ -1,12 +1,12 @@ export bmark_solvers """ - bmark_solvers(solvers :: Vector{Function}, args...; kwargs...) + bmark_solvers(solvers :: Dict{Symbol,Any}, args...; kwargs...) Run a set of solvers on a set of problems. #### Arguments -* `solvers`: a vector of solvers to which each problem should be passed +* `solvers`: a dictionary of solvers to which each problem should be passed * other positional arguments accepted by `solve_problems()`, except for a solver name #### Keyword arguments @@ -15,7 +15,7 @@ Any keyword argument accepted by `solve_problems()` #### Return value A Dict{Symbol, AbstractExecutionStats} of statistics. """ -function bmark_solvers(solvers :: Dict{Symbol,Function}, args...; +function bmark_solvers(solvers :: Dict{Symbol,<: Any}, args...; kwargs...) stats = Dict{Symbol, DataFrame}() for (name,solver) in solvers diff --git a/src/bmark/run_solver.jl b/src/bmark/run_solver.jl index 890a662..a9cd00e 100644 --- a/src/bmark/run_solver.jl +++ b/src/bmark/run_solver.jl @@ -1,7 +1,7 @@ export solve_problems """ - solve_problems(solver :: Function, problems :: Any; kwargs...) + solve_problems(solver, problems :: Any; kwargs...) Apply a solver to a set of problems. @@ -21,12 +21,12 @@ Apply a solver to a set of problems. #### Return value * a `DataFrame` where each row is a problem, minus the skipped ones if `prune` is true. """ -function solve_problems(solver :: F, problems :: Any; +function solve_problems(solver, problems :: Any; solver_logger :: AbstractLogger=NullLogger(), skipif :: Function=x->false, colstats :: Vector{Symbol} = [:name, :nvar, :ncon, :status, :elapsed_time, :objective, :dual_feas, :primal_feas], info_hdr_override :: Dict{Symbol,String} = Dict{Symbol,String}(), - prune :: Bool=true, kwargs...) where F <: Function + prune :: Bool=true, kwargs...) solverstr = split(string(solver), ".")[end] f_counters = collect(fieldnames(Counters)) diff --git a/test/runtests.jl b/test/runtests.jl index 24f802c..e1852e7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -10,5 +10,6 @@ using LinearAlgebra, Logging, Test include("dummy_solver.jl") include("test_auxiliary.jl") +include("test_bmark.jl") include("test_stats.jl") include("test_logging.jl") diff --git a/test/test_bmark.jl b/test/test_bmark.jl new file mode 100644 index 0000000..82e47a1 --- /dev/null +++ b/test/test_bmark.jl @@ -0,0 +1,28 @@ +using DataFrames + +mutable struct CallableSolver +end + +function (solver :: CallableSolver)(nlp :: AbstractNLPModel; kwargs...) + return GenericExecutionStats(:unknown, nlp) +end + +function test_bmark() + @testset "Testing bmark" begin + problems = [ADNLPModel(x -> sum(x.^k), ones(2k), name="Sum of power $k") for k = 2:4] + callable = CallableSolver() + stats = solve_problems(dummy_solver, problems) + @test stats isa DataFrame + + solve_problems(callable, problems) + + solvers = Dict(:dummy => dummy_solver, :callable => callable) + stats = bmark_solvers(solvers, problems) + @test stats isa Dict{Symbol, DataFrame} + for k in keys(solvers) + @test haskey(stats, k) + end + end +end + +test_bmark()