1
1
using Optimization
2
- using ForwardDiff, Zygote, ReverseDiff, FiniteDiff, Tracker
3
- using ModelingToolkit, Enzyme, Random
2
+ using ForwardDiff, Zygote, ReverseDiff, FiniteDiff
4
3
using Test
5
4
6
5
x0 = zeros (2 )
@@ -11,30 +10,12 @@ optf = OptimizationFunction(rosenbrock, AutoEnzyme())
11
10
prob = OptimizationProblem (optf, x0)
12
11
@time res = solve (prob, Optimization. LBFGS (), maxiters = 100 )
13
12
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
-
22
13
function con2_c (res, x, p)
23
14
res .= [x[1 ]^ 2 + x[2 ]^ 2 , (x[2 ] * sin (x[1 ]) + x[1 ])- 5 ]
24
15
end
25
16
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
-
36
17
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 )
0 commit comments