Skip to content

Commit 6d38326

Browse files
Add constrained test:
1 parent e70bd46 commit 6d38326

File tree

2 files changed

+8
-24
lines changed

2 files changed

+8
-24
lines changed

test/lbfgsb.jl

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Optimization
2-
using ForwardDiff, Zygote, ReverseDiff, FiniteDiff, Tracker
3-
using ModelingToolkit, Enzyme, Random
2+
using ForwardDiff, Zygote, ReverseDiff, FiniteDiff
43
using Test
54

65
x0 = zeros(2)
@@ -11,30 +10,12 @@ optf = OptimizationFunction(rosenbrock, AutoEnzyme())
1110
prob = OptimizationProblem(optf, x0)
1211
@time res = solve(prob, Optimization.LBFGS(), maxiters = 100)
1312

14-
@test res.u[1.0, 1.0] atol=1e-3
15-
16-
optf = OptimizationFunction(rosenbrock, AutoZygote())
17-
prob = OptimizationProblem(optf, x0, lb = [0.0, 0.0], ub = [0.3, 0.3])
18-
res = solve(prob, Optimization.LBFGS(), maxiters = 100)
19-
20-
@test res.u[0.3, 0.09] atol=1e-3
21-
2213
function con2_c(res, x, p)
2314
res .= [x[1]^2 + x[2]^2, (x[2] * sin(x[1]) + x[1])-5]
2415
end
2516

26-
optf = OptimizationFunction(rosenbrock, AutoForwardDiff(), cons = con2_c)
27-
prob = OptimizationProblem(optf, x0, lcons = [1.0, -Inf], ucons = [1.0, 0.0], lb = [-1.0, -1.0], ub = [1.0, 1.0])
28-
res = solve(prob, Optimization.LBFGS(), maxiters = 100)
29-
30-
@test res.objective < l1
31-
cons_cache = [0.,0.]
32-
con2_c(cons_cache, res.u, res.cache.p)
33-
@test cons_cache[1] 1.0 atol=1e-3
34-
@test cons_cache[2] < 0.0
35-
3617
optf = OptimizationFunction(rosenbrock, AutoZygote(), cons = con2_c)
37-
prob = OptimizationProblem(optf, x0, lcons = [1.0, -Inf], ucons = [1.0, 0.0], lb = [-1.0, -1.0], ub = [1.0, 1.0])
38-
res = solve(prob, Optimization.LBFGS(), maxiters = 100)
39-
40-
@test res.objective < l1
18+
prob = OptimizationProblem(optf, x0, lcons = [1.0, -Inf],
19+
ucons = [1.0, 0.0], lb = [-1.0, -1.0],
20+
ub = [1.0, 1.0])
21+
@time res = solve(prob, Optimization.LBFGS(), maxiters = 100)

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ end
2929
VERSION >= v"1.9" && @safetestset "AD Performance Regression Tests" begin
3030
include("AD_performance_regression.jl")
3131
end
32+
@safetestset "Optimization" begin
33+
include("lbfgsb.jl")
34+
end
3235
@safetestset "Mini batching" begin
3336
include("minibatch.jl")
3437
end

0 commit comments

Comments
 (0)