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

Add OptimizationOptimJL.Optim.BFGS() tests for issues 747, 754 #758

Closed
wants to merge 1 commit into from
Closed
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
36 changes: 30 additions & 6 deletions lib/OptimizationOptimJL/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ end

@testset "OptimizationOptimJL.jl" begin
rosenbrock(x, p) = (p[1] - x[1])^2 + p[2] * (x[2] - x[1]^2)^2
function rosenbrock_grad!(dx, x, p)
dx[1] = -2*(p[1] - x[1]) -4 * p[2] * (x[2] - x[1]^2)*x[1]
dx[2]= 2*p[2]*(x[2]-x[1]^2)
return nothing
end

x0 = zeros(2)
_p = [1.0, 100.0]
l1 = rosenbrock(x0, _p)
Expand Down Expand Up @@ -89,7 +95,7 @@ end
cons = cons)

prob = OptimizationProblem(optprob, x0, _p, lcons = [-5.0], ucons = [10.0])
sol = solve(prob, IPNewton())
@test (sol = solve(prob, IPNewton())) isa Any # test exception not thrown
@test 10 * sol.objective < l1

optprob = OptimizationFunction(rosenbrock, Optimization.AutoForwardDiff();
Expand Down Expand Up @@ -156,18 +162,36 @@ end
sol = solve(prob, BFGS())
@test 10 * sol.objective < l1

# https://github.com/SciML/Optimization.jl/issues/747
optprob = OptimizationFunction(rosenbrock, Optimization.AutoForwardDiff())
prob = OptimizationProblem(optprob, x0, _p; lb = [-1.0, -1.0], ub = [0.8, 0.8])
@test (sol = solve(prob, Optim.BFGS())) isa Any # test exception not thrown
@test 10 * sol.objective < l1

# https://github.com/SciML/Optimization.jl/issues/754
optprob = OptimizationFunction(rosenbrock; grad=rosenbrock_grad!)
prob = OptimizationProblem(optprob, x0, _p)
@test (sol = solve(prob, Optim.BFGS())) isa Any # test exception not thrown
@test 10 * sol.objective < l1

# https://github.com/SciML/Optimization.jl/issues/754
optprob = OptimizationFunction(rosenbrock; grad=rosenbrock_grad!)
prob = OptimizationProblem(optprob, x0, _p; lb = [-1.0, -1.0], ub = [0.8, 0.8])
@test (sol = solve(prob, Optim.BFGS())) isa Any # test exception not thrown
@test 10 * sol.objective < l1

optprob = OptimizationFunction(rosenbrock, Optimization.AutoModelingToolkit())
prob = OptimizationProblem(optprob, x0, _p)
sol = solve(prob, Optim.BFGS())
@test (sol = solve(prob, Optim.BFGS())) isa Any # test exception not thrown
@test 10 * sol.objective < l1

optprob = OptimizationFunction(rosenbrock,
Optimization.AutoModelingToolkit(true, false))
@test (optprob = OptimizationFunction(rosenbrock,
Optimization.AutoModelingToolkit(true, false))) isa Any # test exception not thrown
prob = OptimizationProblem(optprob, x0, _p)
sol = solve(prob, Optim.Newton())
@test (sol = solve(prob, Optim.Newton())) isa Any # test exception not thrown
@test 10 * sol.objective < l1

sol = solve(prob, Optim.KrylovTrustRegion())
@test (sol = solve(prob, Optim.KrylovTrustRegion())) isa Any # test exception not thrown
@test 10 * sol.objective < l1

@testset "cache" begin
Expand Down
Loading