Skip to content

Commit

Permalink
more updates to sub libs
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaibhavdixit02 committed Sep 10, 2024
1 parent c4d9714 commit 0b2ef12
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 23 deletions.
1 change: 0 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
- OptimizationBBO
- OptimizationCMAEvolutionStrategy
- OptimizationEvolutionary
- OptimizationFlux
- OptimizationGCMAES
- OptimizationManopt
- OptimizationMetaheuristics
Expand Down
6 changes: 4 additions & 2 deletions lib/OptimizationBBO/src/OptimizationBBO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ function SciMLBase.__solve(cache::Optimization.OptimizationCache{

_loss = function (θ)
if isa(cache.f, MultiObjectiveOptimizationFunction)
return cache.f(θ, cache.p)
x = (cache.f(θ, cache.p),)
return x[1]
else
return first(cache.f(θ, cache.p))
x = cache.f(θ, cache.p)
return first(x)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function SciMLBase.__solve(cache::OptimizationCache{
maxtime = Optimization._check_and_convert_maxtime(cache.solver_args.maxtime)

_loss = function (θ)
x = cache.f(θ, cache.p, cur...)
x = cache.f(θ, cache.p)
return first(x)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/OptimizationMOI/src/nlp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function MOIOptimizationNLPCache(prob::OptimizationProblem,

num_cons = prob.ucons === nothing ? 0 : length(prob.ucons)
f = Optimization.instantiate_function(prob.f, reinit_cache, prob.f.adtype, num_cons;
g = true, h = false, cons_j = true, cons_vjp = true, lag_h = true)
g = true, h = true, cons_j = true, cons_vjp = true, lag_h = true)
T = eltype(prob.u0)
n = length(prob.u0)

Expand Down
22 changes: 11 additions & 11 deletions lib/OptimizationManopt/src/OptimizationManopt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -336,31 +336,31 @@ function build_loss(f::OptimizationFunction, prob, cb)
end
end

function build_gradF(f::OptimizationFunction{true}, cur)
function build_gradF(f::OptimizationFunction{true})
function g(M::AbstractManifold, G, θ)
f.grad(G, θ, cur...)
f.grad(G, θ)
G .= riemannian_gradient(M, θ, G)
end
function g(M::AbstractManifold, θ)
G = zero(θ)
f.grad(G, θ, cur...)
f.grad(G, θ)
return riemannian_gradient(M, θ, G)
end
end

function build_hessF(f::OptimizationFunction{true}, cur)
function build_hessF(f::OptimizationFunction{true})
function h(M::AbstractManifold, H1, θ, X)
H = zeros(eltype(θ), length(θ))
f.hv(H, θ, X, cur...)
f.hv(H, θ, X)
G = zeros(eltype(θ), length(θ))
f.grad(G, θ, cur...)
f.grad(G, θ)
riemannian_Hessian!(M, H1, θ, G, H, X)
end
function h(M::AbstractManifold, θ, X)
H = zeros(eltype(θ), length(θ), length(θ))
f.hess(H, θ, cur...)
f.hess(H, θ)
G = zeros(eltype(θ), length(θ))
f.grad(G, θ, cur...)
f.grad(G, θ)
return riemannian_Hessian(M, θ, G, H, X)
end
end
Expand Down Expand Up @@ -414,7 +414,7 @@ function SciMLBase.__solve(cache::OptimizationCache{
cb_call
end
solver_kwarg = __map_optimizer_args!(cache, cache.opt, callback = _cb,
maxiters = maxiters,
maxiters = cache.solver_args.maxiters,
maxtime = cache.solver_args.maxtime,
abstol = cache.solver_args.abstol,
reltol = cache.solver_args.reltol;
Expand All @@ -424,11 +424,11 @@ function SciMLBase.__solve(cache::OptimizationCache{
_loss = build_loss(cache.f, cache, _cb)

if gradF === nothing
gradF = build_gradF(cache.f, cur)
gradF = build_gradF(cache.f)
end

if hessF === nothing
hessF = build_hessF(cache.f, cur)
hessF = build_hessF(cache.f)
end

if haskey(solver_kwarg, :stopping_criterion)
Expand Down
2 changes: 1 addition & 1 deletion lib/OptimizationOptimJL/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using OptimizationOptimJL,
OptimizationOptimJL.Optim, Optimization, ForwardDiff, Zygote,
Random, ModelingToolkit, OptimizationBase.DifferentiationInterface
Random, ModelingToolkit, Optimization.OptimizationBase.DifferentiationInterface
using Test

struct CallbackTester
Expand Down
6 changes: 0 additions & 6 deletions lib/OptimizationOptimisers/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ using Zygote

prob = OptimizationProblem(optprob, x0, _p)

sol = Optimization.solve(prob,
OptimizationOptimisers.Sophia(; η = 0.5,
λ = 0.0),
maxiters = 1000)
@test 10 * sol.objective < l1

prob = OptimizationProblem(optprob, x0, _p)
sol = solve(prob, Optimisers.Adam(), maxiters = 1000, progress = false)
@test 10 * sol.objective < l1
Expand Down
1 change: 1 addition & 0 deletions lib/OptimizationPRIMA/src/OptimizationPRIMA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ SciMLBase.allowsbounds(opt::Union{BOBYQA, LINCOA, COBYLA}) = true
SciMLBase.requiresconstraints(opt::COBYLA) = true
SciMLBase.requiresgradient(opt::Union{BOBYQA, LINCOA, COBYLA}) = true
SciMLBase.requiresconsjac(opt::Union{LINCOA, COBYLA}) = true
SciMLBase.requiresconshess(opt::COBYLA) = true

function Optimization.OptimizationCache(prob::SciMLBase.OptimizationProblem,
opt::PRIMASolvers;
Expand Down
6 changes: 6 additions & 0 deletions test/ADtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ end
sol = solve(prob, Optim.Newton())
@test 10 * sol.objective < l1
@test sol.retcode == ReturnCode.Success

sol = Optimization.solve(prob,
Optimization.Sophia(; η = 0.5,
λ = 0.0),
maxiters = 1000)
@test 10 * sol.objective < l1
end

@testset "No constraint" begin
Expand Down

0 comments on commit 0b2ef12

Please sign in to comment.