|
1 | 1 | using Optimization, OptimizationOptimJL, OptimizationMOI, Ipopt, Test
|
2 |
| -using ForwardDiff, Zygote, ReverseDiff, FiniteDiff, Tracker |
| 2 | +using ForwardDiff, Zygote, ReverseDiff, FiniteDiff, Tracker, Mooncake |
3 | 3 | using Enzyme, Random
|
4 | 4 |
|
5 | 5 | x0 = zeros(2)
|
|
35 | 35 | @testset "No constraint" begin
|
36 | 36 | for adtype in [AutoEnzyme(), AutoForwardDiff(), AutoZygote(), AutoReverseDiff(),
|
37 | 37 | AutoFiniteDiff(), AutoModelingToolkit(), AutoSparseForwardDiff(),
|
38 |
| - AutoSparseReverseDiff(), AutoSparse(AutoZygote()), AutoModelingToolkit(true, true)] |
| 38 | + AutoSparseReverseDiff(), AutoSparse(AutoZygote()), AutoModelingToolkit(true, true), AutoMooncake()] |
39 | 39 | optf = OptimizationFunction(rosenbrock, adtype)
|
40 | 40 |
|
41 | 41 | prob = OptimizationProblem(optf, x0)
|
|
46 | 46 | @test sol.retcode == ReturnCode.Success
|
47 | 47 | end
|
48 | 48 |
|
49 |
| - sol = solve(prob, Optim.Newton()) |
50 |
| - @test 10 * sol.objective < l1 |
51 |
| - if adtype != AutoFiniteDiff() |
52 |
| - @test sol.retcode == ReturnCode.Success |
| 49 | + # `Newton` requires Hession, which Mooncake doesn't support at the moment. |
| 50 | + if adtype != AutoMooncake() |
| 51 | + sol = solve(prob, Optim.Newton()) |
| 52 | + @test 10 * sol.objective < l1 |
| 53 | + if adtype != AutoFiniteDiff() |
| 54 | + @test sol.retcode == ReturnCode.Success |
| 55 | + end |
53 | 56 | end
|
54 | 57 |
|
55 |
| - sol = solve(prob, Optim.KrylovTrustRegion()) |
56 |
| - @test 10 * sol.objective < l1 |
57 |
| - if adtype != AutoFiniteDiff() |
58 |
| - @test sol.retcode == ReturnCode.Success |
| 58 | + # Requires Hession, which Mooncake doesn't support at the moment. |
| 59 | + if adtype != AutoMooncake() |
| 60 | + sol = solve(prob, Optim.KrylovTrustRegion()) |
| 61 | + @test 10 * sol.objective < l1 |
| 62 | + if adtype != AutoFiniteDiff() |
| 63 | + @test sol.retcode == ReturnCode.Success |
| 64 | + end |
59 | 65 | end
|
60 | 66 |
|
61 | 67 | sol = solve(prob, Optimization.LBFGS(), maxiters = 1000)
|
|
67 | 73 | @testset "One constraint" begin
|
68 | 74 | for adtype in [AutoEnzyme(), AutoForwardDiff(), AutoZygote(), AutoReverseDiff(),
|
69 | 75 | AutoFiniteDiff(), AutoModelingToolkit(), AutoSparseForwardDiff(),
|
70 |
| - AutoSparseReverseDiff(), AutoSparse(AutoZygote()), AutoModelingToolkit(true, true)] |
| 76 | + AutoSparseReverseDiff(), AutoSparse(AutoZygote()), AutoModelingToolkit(true, true), AutoMooncake()] |
71 | 77 | cons = (res, x, p) -> (res[1] = x[1]^2 + x[2]^2 - 1.0; return nothing)
|
72 | 78 | optf = OptimizationFunction(rosenbrock, adtype, cons = cons)
|
73 | 79 |
|
|
77 | 83 | sol = solve(prob, Optimization.LBFGS(), maxiters = 1000)
|
78 | 84 | @test 10 * sol.objective < l1
|
79 | 85 |
|
80 |
| - sol = solve(prob, Ipopt.Optimizer(), max_iter = 1000; print_level = 0) |
81 |
| - @test 10 * sol.objective < l1 |
| 86 | + # Requires Hession, which Mooncake doesn't support at the moment. |
| 87 | + if adtype != AutoMooncake() |
| 88 | + sol = solve(prob, Ipopt.Optimizer(), max_iter = 1000; print_level = 0) |
| 89 | + @test 10 * sol.objective < l1 |
| 90 | + end |
82 | 91 | end
|
83 | 92 | end
|
84 | 93 |
|
85 | 94 | @testset "Two constraints" begin
|
86 | 95 | for adtype in [AutoForwardDiff(), AutoZygote(), AutoReverseDiff(),
|
87 | 96 | AutoFiniteDiff(), AutoModelingToolkit(), AutoSparseForwardDiff(),
|
88 |
| - AutoSparseReverseDiff(), AutoSparse(AutoZygote()), AutoModelingToolkit(true, true)] |
| 97 | + AutoSparseReverseDiff(), AutoSparse(AutoZygote()), AutoModelingToolkit(true, true), AutoMooncake()] |
89 | 98 | function con2_c(res, x, p)
|
90 | 99 | res[1] = x[1]^2 + x[2]^2
|
91 | 100 | res[2] = x[2] * sin(x[1]) - x[1]
|
|
99 | 108 | sol = solve(prob, Optimization.LBFGS(), maxiters = 1000)
|
100 | 109 | @test 10 * sol.objective < l1
|
101 | 110 |
|
102 |
| - sol = solve(prob, Ipopt.Optimizer(), max_iter = 1000; print_level = 0) |
103 |
| - @test 10 * sol.objective < l1 |
| 111 | + # Requires Hession, which Mooncake doesn't support at the moment. |
| 112 | + if adtype != AutoMooncake() |
| 113 | + sol = solve(prob, Ipopt.Optimizer(), max_iter = 1000; print_level = 0) |
| 114 | + @test 10 * sol.objective < l1 |
| 115 | + end |
104 | 116 | end
|
105 | 117 | end
|
0 commit comments