From 6d38326a6b63224875e13334aa5bd04b54e19f3e Mon Sep 17 00:00:00 2001 From: Vaibhav Dixit Date: Thu, 25 Apr 2024 17:13:07 -0400 Subject: [PATCH] Add constrained test: --- test/lbfgsb.jl | 29 +++++------------------------ test/runtests.jl | 3 +++ 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/test/lbfgsb.jl b/test/lbfgsb.jl index 72b3a06e9..1d3336e1d 100644 --- a/test/lbfgsb.jl +++ b/test/lbfgsb.jl @@ -1,6 +1,5 @@ using Optimization -using ForwardDiff, Zygote, ReverseDiff, FiniteDiff, Tracker -using ModelingToolkit, Enzyme, Random +using ForwardDiff, Zygote, ReverseDiff, FiniteDiff using Test x0 = zeros(2) @@ -11,30 +10,12 @@ optf = OptimizationFunction(rosenbrock, AutoEnzyme()) prob = OptimizationProblem(optf, x0) @time res = solve(prob, Optimization.LBFGS(), maxiters = 100) -@test res.uā‰ˆ[1.0, 1.0] atol=1e-3 - -optf = OptimizationFunction(rosenbrock, AutoZygote()) -prob = OptimizationProblem(optf, x0, lb = [0.0, 0.0], ub = [0.3, 0.3]) -res = solve(prob, Optimization.LBFGS(), maxiters = 100) - -@test res.uā‰ˆ[0.3, 0.09] atol=1e-3 - function con2_c(res, x, p) res .= [x[1]^2 + x[2]^2, (x[2] * sin(x[1]) + x[1])-5] end -optf = OptimizationFunction(rosenbrock, AutoForwardDiff(), cons = con2_c) -prob = OptimizationProblem(optf, x0, lcons = [1.0, -Inf], ucons = [1.0, 0.0], lb = [-1.0, -1.0], ub = [1.0, 1.0]) -res = solve(prob, Optimization.LBFGS(), maxiters = 100) - -@test res.objective < l1 -cons_cache = [0.,0.] -con2_c(cons_cache, res.u, res.cache.p) -@test cons_cache[1] ā‰ˆ 1.0 atol=1e-3 -@test cons_cache[2] < 0.0 - optf = OptimizationFunction(rosenbrock, AutoZygote(), cons = con2_c) -prob = OptimizationProblem(optf, x0, lcons = [1.0, -Inf], ucons = [1.0, 0.0], lb = [-1.0, -1.0], ub = [1.0, 1.0]) -res = solve(prob, Optimization.LBFGS(), maxiters = 100) - -@test res.objective < l1 \ No newline at end of file +prob = OptimizationProblem(optf, x0, lcons = [1.0, -Inf], + ucons = [1.0, 0.0], lb = [-1.0, -1.0], + ub = [1.0, 1.0]) +@time res = solve(prob, Optimization.LBFGS(), maxiters = 100) diff --git a/test/runtests.jl b/test/runtests.jl index ca1a60aca..8b85ae3a5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -29,6 +29,9 @@ end VERSION >= v"1.9" && @safetestset "AD Performance Regression Tests" begin include("AD_performance_regression.jl") end + @safetestset "Optimization" begin + include("lbfgsb.jl") + end @safetestset "Mini batching" begin include("minibatch.jl") end