Skip to content

Commit

Permalink
Merge pull request #376 from SciML/errorhandling
Browse files Browse the repository at this point in the history
Be more informative about supported functionality of a backend and correctness of kwargs
  • Loading branch information
Vaibhavdixit02 authored Oct 12, 2022
2 parents de17eda + d2e58e2 commit 8951fa5
Show file tree
Hide file tree
Showing 30 changed files with 150 additions and 86 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ LoggingExtras = "0.4, 0.5"
ProgressLogging = "0.1"
Reexport = "0.2, 1.0"
Requires = "1.0"
SciMLBase = "1.39"
SciMLBase = "1.61"
TerminalLoggers = "0.1"
julia = "1.6"

Expand Down
4 changes: 3 additions & 1 deletion lib/OptimizationBBO/Project.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
name = "OptimizationBBO"
uuid = "3e6eede4-6085-4f62-9a71-46d9bc1eb92b"
authors = ["Vaibhav Dixit <[email protected]> and contributors"]
version = "0.1.1"
version = "0.1.2"

[deps]
BlackBoxOptim = "a134a8b2-14d6-55f6-9291-3336d3ab0209"
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"

[compat]
BlackBoxOptim = "0.6"
Optimization = "3"
Reexport = "1.2"
julia = "1"

[extras]
Expand Down
12 changes: 7 additions & 5 deletions lib/OptimizationBBO/src/OptimizationBBO.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
module OptimizationBBO

using BlackBoxOptim, Optimization, Optimization.SciMLBase
using Reexport
@reexport using Optimization
using BlackBoxOptim, Optimization.SciMLBase

abstract type BBO end

SciMLBase.requiresbounds(::BBO) = true
SciMLBase.allowsbounds(::BBO) = true

for j in string.(BlackBoxOptim.SingleObjectiveMethodNames)
eval(Meta.parse("Base.@kwdef struct BBO_" * j * " <: BBO method=:" * j * " end"))
eval(Meta.parse("export BBO_" * j))
Expand Down Expand Up @@ -35,8 +40,7 @@ function __map_optimizer_args(prob::SciMLBase.OptimizationProblem, opt::BBO;
maxtime::Union{Number, Nothing} = nothing,
abstol::Union{Number, Nothing} = nothing,
reltol::Union{Number, Nothing} = nothing,
verbose::Bool = false,
kwargs...)
verbose::Bool = false)
if !isnothing(reltol)
@warn "common reltol is currently not used by $(opt)"
end
Expand All @@ -49,8 +53,6 @@ function __map_optimizer_args(prob::SciMLBase.OptimizationProblem, opt::BBO;
CallbackInterval = 0.0)
end

mapped_args = (; mapped_args..., kwargs...)

if !isnothing(maxiters)
mapped_args = (; mapped_args..., MaxSteps = maxiters)
end
Expand Down
4 changes: 3 additions & 1 deletion lib/OptimizationCMAEvolutionStrategy/Project.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
name = "OptimizationCMAEvolutionStrategy"
uuid = "bd407f91-200f-4536-9381-e4ba712f53f8"
authors = ["Vaibhav Dixit <[email protected]> and contributors"]
version = "0.1.0"
version = "0.1.1"

[deps]
CMAEvolutionStrategy = "8d3b24bd-414e-49e0-94fb-163cc3a3e411"
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"

[compat]
julia = "1"
CMAEvolutionStrategy = "0.2"
Optimization = "3"
Reexport = "1.2"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
module OptimizationCMAEvolutionStrategy

using CMAEvolutionStrategy, Optimization, Optimization.SciMLBase
using Reexport
@reexport using Optimization
using CMAEvolutionStrategy, Optimization.SciMLBase

export CMAEvolutionStrategyOpt

struct CMAEvolutionStrategyOpt end

SciMLBase.requiresbounds(::CMAEvolutionStrategyOpt) = true
SciMLBase.allowsbounds(::CMAEvolutionStrategyOpt) = true
SciMLBase.allowscallback(::CMAEvolutionStrategyOpt) = false #looks like `logger` kwarg can be used to pass it, so should be implemented

function __map_optimizer_args(prob::OptimizationProblem, opt::CMAEvolutionStrategyOpt;
callback = nothing,
maxiters::Union{Number, Nothing} = nothing,
maxtime::Union{Number, Nothing} = nothing,
abstol::Union{Number, Nothing} = nothing,
reltol::Union{Number, Nothing} = nothing,
kwargs...)
reltol::Union{Number, Nothing} = nothing)
if !isnothing(reltol)
@warn "common reltol is currently not used by $(opt)"
end

mapped_args = (; lower = prob.lb,
upper = prob.ub,
kwargs...)
upper = prob.ub)

if !isnothing(maxiters)
mapped_args = (; mapped_args..., maxiter = maxiters)
Expand Down
2 changes: 1 addition & 1 deletion lib/OptimizationEvolutionary/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "OptimizationEvolutionary"
uuid = "cb963754-43f6-435e-8d4b-99009ff27753"
authors = ["Vaibhav Dixit <[email protected]> and contributors"]
version = "0.1.0"
version = "0.1.1"

[deps]
Evolutionary = "86b6b26d-c046-49b6-aa0b-5f0f74682bd6"
Expand Down
14 changes: 7 additions & 7 deletions lib/OptimizationEvolutionary/src/OptimizationEvolutionary.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
module OptimizationEvolutionary

using Reexport, Optimization, Optimization.SciMLBase
@reexport using Evolutionary
using Reexport
@reexport using Evolutionary, Optimization
using Optimization.SciMLBase

SciMLBase.allowsbounds(opt::Evolutionary.AbstractOptimizer) = true

decompose_trace(trace::Evolutionary.OptimizationTrace) = last(trace)
decompose_trace(trace::Evolutionary.OptimizationTraceRecord) = trace
Expand All @@ -17,12 +20,9 @@ function __map_optimizer_args(prob::OptimizationProblem,
maxiters::Union{Number, Nothing} = nothing,
maxtime::Union{Number, Nothing} = nothing,
abstol::Union{Number, Nothing} = nothing,
reltol::Union{Number, Nothing} = nothing,
kwargs...)
reltol::Union{Number, Nothing} = nothing)
mapped_args = (;)

mapped_args = (; mapped_args..., kwargs...)

if !isnothing(callback)
mapped_args = (; mapped_args..., callback = callback)
end
Expand Down Expand Up @@ -84,7 +84,7 @@ function SciMLBase.__solve(prob::OptimizationProblem, opt::Evolutionary.Abstract
kwargs...)

t0 = time()
if isnothing(prob.ub) | isnothing(prob.ub)
if isnothing(prob.ub) || isnothing(prob.ub)
opt_res = Evolutionary.optimize(_loss, prob.u0, opt, opt_args)
else
cons = Evolutionary.BoxConstraints(prob.lb, prob.ub)
Expand Down
5 changes: 3 additions & 2 deletions lib/OptimizationFlux/src/OptimizationFlux.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module OptimizationFlux

using Optimization, Reexport, Printf, ProgressLogging, Optimization.SciMLBase
@reexport using Flux
using Reexport, Printf, ProgressLogging
@reexport using Flux, Optimization
using Optimization.SciMLBase

function SciMLBase.__solve(prob::OptimizationProblem, opt::Flux.Optimise.AbstractOptimiser,
data = Optimization.DEFAULT_DATA;
Expand Down
4 changes: 3 additions & 1 deletion lib/OptimizationGCMAES/Project.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
name = "OptimizationGCMAES"
uuid = "6f0a0517-dbc2-4a7a-8a20-99ae7f27e911"
authors = ["Vaibhav Dixit <[email protected]> and contributors"]
version = "0.1.0"
version = "0.1.1"

[deps]
GCMAES = "4aa9d100-eb0f-11e8-15f1-25748831eb3b"
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"

[compat]
julia = "1"
Optimization = "3"
GCMAES = "0.1"
Reexport = "1.2"

[extras]
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Expand Down
12 changes: 8 additions & 4 deletions lib/OptimizationGCMAES/src/OptimizationGCMAES.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
module OptimizationGCMAES

using GCMAES, Optimization, Optimization.SciMLBase
using Reexport
@reexport using Optimization
using GCMAES, Optimization.SciMLBase

export GCMAESOpt

struct GCMAESOpt end

SciMLBase.requiresbounds(::GCMAESOpt) = true
SciMLBase.allowsbounds(::GCMAESOpt) = true

function __map_optimizer_args(prob::OptimizationProblem, opt::GCMAESOpt;
callback = nothing,
maxiters::Union{Number, Nothing} = nothing,
maxtime::Union{Number, Nothing} = nothing,
abstol::Union{Number, Nothing} = nothing,
reltol::Union{Number, Nothing} = nothing,
kwargs...)
reltol::Union{Number, Nothing} = nothing)

# add optimiser options from kwargs
mapped_args = (; kwargs...)
mapped_args = (;)

if !(isnothing(maxiters))
mapped_args = (; mapped_args..., maxiter = maxiters)
Expand Down
4 changes: 3 additions & 1 deletion lib/OptimizationMOI/Project.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
name = "OptimizationMOI"
uuid = "fd9f6733-72f4-499f-8506-86b2bdd0dea1"
authors = ["Vaibhav Dixit <[email protected]> and contributors"]
version = "0.1.3"
version = "0.1.4"

[deps]
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"

[compat]
MathOptInterface = "1"
Optimization = "3"
Reexport = "1.2"
julia = "1"

[extras]
Expand Down
14 changes: 13 additions & 1 deletion lib/OptimizationMOI/src/OptimizationMOI.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
module OptimizationMOI

using MathOptInterface, Optimization, Optimization.SciMLBase, SparseArrays
using Reexport
@reexport using Optimization
using MathOptInterface, Optimization.SciMLBase, SparseArrays

const MOI = MathOptInterface

const DenseOrSparse{T} = Union{Matrix{T}, SparseMatrixCSC{T}}

function SciMLBase.allowsbounds(opt::Union{MOI.AbstractOptimizer,
MOI.OptimizerWithAttributes})
true
end
function SciMLBase.allowsconstraints(opt::Union{MOI.AbstractOptimizer,
MOI.OptimizerWithAttributes})
true
end

struct MOIOptimizationProblem{T, F <: OptimizationFunction, uType, P,
JT <: DenseOrSparse{T}, HT <: DenseOrSparse{T},
CHT <: DenseOrSparse{T}} <:
Expand Down
2 changes: 1 addition & 1 deletion lib/OptimizationMetaheuristics/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "OptimizationMetaheuristics"
uuid = "3aafef2f-86ae-4776-b337-85a36adf0b55"
authors = ["Vaibhav Dixit <[email protected]> and contributors"]
version = "0.1.0"
version = "0.1.1"

[deps]
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
Expand Down
15 changes: 7 additions & 8 deletions lib/OptimizationMetaheuristics/src/OptimizationMetaheuristics.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
module OptimizationMetaheuristics

using Reexport, Optimization, Optimization.SciMLBase
@reexport using Metaheuristics
using Reexport
@reexport using Metaheuristics, Optimization
using Optimization.SciMLBase

SciMLBase.requiresbounds(opt::Metaheuristics.AbstractAlgorithm) = true
SciMLBase.allowsbounds(opt::Metaheuristics.AbstractAlgorithm) = true
SciMLBase.allowscallback(opt::Metaheuristics.AbstractAlgorithm) = false

function initial_population!(opt, prob, bounds, f)
opt_init = deepcopy(opt)
Expand Down Expand Up @@ -39,10 +44,6 @@ function __map_optimizer_args!(prob::OptimizationProblem,
end
end

if !isnothing(callback)
@warn "Callback argument is currently not used by $(typeof(opt).super)"
end

if !isnothing(maxiters)
opt.options.iterations = maxiters
end
Expand Down Expand Up @@ -82,8 +83,6 @@ function SciMLBase.__solve(prob::OptimizationProblem, opt::Metaheuristics.Abstra

if !isnothing(prob.lb) & !isnothing(prob.ub)
opt_bounds = [prob.lb prob.ub]'
else
error("$(opt) requires lower and upper bounds to be defined.")
end

if !isnothing(prob.f.cons)
Expand Down
2 changes: 1 addition & 1 deletion lib/OptimizationMultistartOptimization/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "OptimizationMultistartOptimization"
uuid = "e4316d97-8bbb-4fd3-a7d8-3851d2a72823"
authors = ["Vaibhav Dixit <[email protected]> and contributors"]
version = "0.1.0"
version = "0.1.1"

[deps]
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
module OptimizationMultistartOptimization

using Reexport, Optimization, Optimization.SciMLBase
@reexport using MultistartOptimization
using Reexport
@reexport using MultistartOptimization, Optimization
using Optimization.SciMLBase

SciMLBase.requiresbounds(opt::MultistartOptimization.TikTak) = true
SciMLBase.allowsbounds(opt::MultistartOptimization.TikTak) = true

function SciMLBase.__solve(prob::OptimizationProblem,
multiopt::MultistartOptimization.TikTak, opt;
Expand Down
2 changes: 1 addition & 1 deletion lib/OptimizationNLopt/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "OptimizationNLopt"
uuid = "4e6fcdb7-1186-4e1f-a706-475e75c168bb"
authors = ["Vaibhav Dixit <[email protected]> and contributors"]
version = "0.1.0"
version = "0.1.1"

[deps]
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
Expand Down
7 changes: 5 additions & 2 deletions lib/OptimizationNLopt/src/OptimizationNLopt.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
module OptimizationNLopt

using Reexport, Optimization, Optimization.SciMLBase
@reexport using NLopt
using Reexport
@reexport using NLopt, Optimization
using Optimization.SciMLBase

(f::NLopt.Algorithm)() = f

SciMLBase.allowsbounds(opt::Union{NLopt.Algorithm, NLopt.Opt}) = true

function __map_optimizer_args!(prob::OptimizationProblem, opt::NLopt.Opt;
callback = nothing,
maxiters::Union{Number, Nothing} = nothing,
Expand Down
4 changes: 3 additions & 1 deletion lib/OptimizationNOMAD/Project.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
name = "OptimizationNOMAD"
uuid = "2cab0595-8222-4775-b714-9828e6a9e01b"
authors = ["Vaibhav Dixit <[email protected]> and contributors"]
version = "0.1.0"
version = "0.1.1"

[deps]
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
NOMAD = "02130f1c-4665-5b79-af82-ff1385104aa0"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"

[compat]
julia = "1"
NOMAD = "2"
Optimization = "3"
Reexport = "1.2"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
7 changes: 6 additions & 1 deletion lib/OptimizationNOMAD/src/OptimizationNOMAD.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
module OptimizationNOMAD

using NOMAD, Optimization, Optimization.SciMLBase
using Reexport
@reexport using Optimization
using NOMAD, Optimization.SciMLBase

export NOMADOpt
struct NOMADOpt end

SciMLBase.allowsbounds(::NOMADOpt) = true
SciMLBase.allowscallback(::NOMADOpt) = false

function __map_optimizer_args!(prob::OptimizationProblem, opt::NOMAD.NomadProblem;
callback = nothing,
maxiters::Union{Number, Nothing} = nothing,
Expand Down
Loading

0 comments on commit 8951fa5

Please sign in to comment.