Skip to content

Commit 9ad663c

Browse files
fixes tests
1 parent 45ebac7 commit 9ad663c

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

test/optimizationsystem.jl

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ using ModelingToolkit: get_metadata
4242
sys2.b => 9.0
4343
β => 10.0]
4444

45-
prob = OptimizationProblem(combinedsys, u0, p, grad = true, hess = true)
45+
prob = OptimizationProblem(combinedsys, u0, p, grad = true, hess = true, cons_j = true,
46+
cons_h = true)
4647
@test prob.f.sys === combinedsys
4748
sol = solve(prob, Ipopt.Optimizer(); print_level = 0)
4849
@test sol.minimum < -1e5
@@ -58,12 +59,15 @@ end
5859
@named sys = OptimizationSystem(loss, [x, y], [a, b], constraints = cons)
5960

6061
prob = OptimizationProblem(sys, [x => 0.0, y => 0.0], [a => 1.0, b => 1.0],
61-
grad = true, hess = true)
62+
grad = true, hess = true, cons_j = true, cons_h = true)
6263
@test prob.f.sys === sys
6364
sol = solve(prob, IPNewton())
6465
@test sol.minimum < 1.0
6566
sol = solve(prob, Ipopt.Optimizer(); print_level = 0)
6667
@test sol.minimum < 1.0
68+
69+
prob = OptimizationProblem(sys, [x => 0.0, y => 0.0], [a => 1.0, b => 1.0],
70+
grad = false, hess = false, cons_j = false, cons_h = false)
6771
sol = solve(prob, AmplNLWriter.Optimizer(Ipopt_jll.amplexe))
6872
@test sol.minimum < 1.0
6973
end
@@ -77,7 +81,7 @@ end
7781
@named sys = OptimizationSystem(loss, [x, y, z], [a, b], constraints = cons)
7882
sys = structural_simplify(sys)
7983
prob = OptimizationProblem(sys, [x => 0.0, y => 0.0, z => 0.0], [a => 1.0, b => 1.0],
80-
grad = true, hess = true)
84+
grad = true, hess = true, cons_j = true, cons_h = true)
8185
sol = solve(prob, IPNewton())
8286
@test sol.minimum < 1.0
8387
@test sol.u[0.808, -0.064] atol=1e-3
@@ -86,6 +90,9 @@ end
8690
@test sol.minimum < 1.0
8791
@test sol.u[0.808, -0.064] atol=1e-3
8892
@test sol[x]^2 + sol[y]^2 1.0
93+
94+
prob = OptimizationProblem(sys, [x => 0.0, y => 0.0, z => 0.0], [a => 1.0, b => 1.0],
95+
grad = false, hess = false, cons_j = false, cons_h = false)
8996
sol = solve(prob, AmplNLWriter.Optimizer(Ipopt_jll.amplexe))
9097
@test sol.minimum < 1.0
9198
@test sol.u[0.808, -0.064] atol=1e-3
@@ -178,13 +185,14 @@ end
178185
sys2.b => 9.0
179186
β => 10.0]
180187

181-
prob = OptimizationProblem(combinedsys, u0, p, grad = true, hess = true)
188+
prob = OptimizationProblem(combinedsys, u0, p, grad = true, hess = true, cons_j = true,
189+
cons_h = true)
182190
@test prob.f.sys === combinedsys
183191
sol = solve(prob, Ipopt.Optimizer(); print_level = 0)
184192
@test sol.minimum < -1e5
185193

186194
prob = OptimizationProblem(sys2, [x => 0.0, y => 0.0], [a => 1.0, b => 100.0],
187-
grad = true, hess = true)
195+
grad = true, hess = true, cons_j = true, cons_h = true)
188196
@test prob.f.sys === sys2
189197
sol = solve(prob, IPNewton())
190198
@test sol.minimum < 1.0
@@ -213,7 +221,7 @@ end
213221
])
214222

215223
prob = OptimizationProblem(sys, [x[1] => 2.0, x[2] => 0.0], [], grad = true,
216-
hess = true)
224+
hess = true, cons_j = true, cons_h = true)
217225
sol = Optimization.solve(prob, Ipopt.Optimizer(); print_level = 0)
218226
@test sol.u [1, 0]
219227
@test prob.lb == [0.0, 0.0]
@@ -226,8 +234,7 @@ end
226234
@parameters a b
227235
loss = (a - x)^2 + b * (y - x^2)^2
228236
@named sys = OptimizationSystem(loss, [x, y], [a, b, c])
229-
prob = OptimizationProblem(sys, [x => 0.0, y => 0.0], [a => 1.0, b => 100.0],
230-
grad = true, hess = true)
237+
prob = OptimizationProblem(sys, [x => 0.0, y => 0.0], [a => 1.0, b => 100.0])
231238
@test prob.lb == [-Inf, 0.0]
232239
@test prob.ub == [Inf, Inf]
233240
end

0 commit comments

Comments
 (0)