Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit warning when AD backend not specified correctly for automatic box-constraint handling with Optim #741

Merged
merged 3 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/OptimizationOptimJL/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "OptimizationOptimJL"
uuid = "36348300-93cb-4f02-beb5-3c3902f8871e"
authors = ["Vaibhav Dixit <[email protected]> and contributors"]
version = "0.2.3"
version = "0.3.0"

[deps]
Optim = "429524aa-4258-5aef-a3af-852621145aeb"
Expand Down
8 changes: 5 additions & 3 deletions lib/OptimizationOptimJL/src/OptimizationOptimJL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ function SciMLBase.__init(prob::OptimizationProblem,
if opt isa Optim.ParticleSwarm
opt = Optim.ParticleSwarm(; lower = prob.lb, upper = prob.ub,
n_particles = opt.n_particles)
elseif opt isa Optim.SimulatedAnnealing
@warn "$(opt) can currently not be wrapped in Fminbox(). The lower and upper bounds thus will be ignored. Consider using a different optimizer or open an issue with Optim.jl"
else
opt = Optim.Fminbox(opt)
if prob.f isa OptimizationFunction && !(prob.f.adtype isa NoAD)
opt = Optim.Fminbox(opt)
else
throw(ArgumentError("Fminbox($opt) requires gradients, since you didn't use `OptimizationFunction` with a valid AD backend https://docs.sciml.ai/Optimization/stable/API/ad/ the lower and upper bounds thus will be ignored."))
end
end
end
end
Expand Down
Loading