Skip to content

Commit ccce0c3

Browse files
committed
Test structural_simplify
1 parent deb0b9b commit ccce0c3

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

test/optimizationsystem.jl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,27 @@ end
6969
end
7070

7171
@testset "equality constraint" begin
72-
@variables x y
72+
@variables x y z
7373
@parameters a b
74-
loss = (a - x)^2 + b * (y - x^2)^2
75-
cons = [1.0 ~ x^2 + y^2]
76-
@named sys = OptimizationSystem(loss, [x, y], [a, b], constraints = cons)
77-
prob = OptimizationProblem(sys, [x => 0.0, y => 0.0], [a => 1.0, b => 1.0],
74+
loss = (a - x)^2 + b * z^2
75+
cons = [1.0 ~ x^2 + y^2
76+
z ~ y - x^2]
77+
@named sys = OptimizationSystem(loss, [x, y, z], [a, b], constraints = cons)
78+
sys = structural_simplify(sys)
79+
prob = OptimizationProblem(sys, [x => 0.0, y => 0.0, z => 0.0], [a => 1.0, b => 1.0],
7880
grad = true, hess = true)
7981
sol = solve(prob, IPNewton())
8082
@test sol.minimum < 1.0
81-
@test sol.u[0.808, 0.589] atol=1e-3
82-
@test sol[x]^2 + sol[y]^2 1.0
83+
@test sol.u[0.808, -0.064] atol=1e-3
84+
@test_broken sol[x]^2 + sol[y]^2 1.0
8385
sol = solve(prob, Ipopt.Optimizer(); print_level = 0)
8486
@test sol.minimum < 1.0
85-
@test sol.u[0.808, 0.589] atol=1e-3
86-
@test sol[x]^2 + sol[y]^2 1.0
87+
@test sol.u[0.808, -0.064] atol=1e-3
88+
@test_broken sol[x]^2 + sol[y]^2 1.0
8789
sol = solve(prob, AmplNLWriter.Optimizer(Ipopt_jll.amplexe))
8890
@test sol.minimum < 1.0
89-
@test sol.u[0.808, 0.589] atol=1e-3
90-
@test sol[x]^2 + sol[y]^2 1.0
91+
@test sol.u[0.808, -0.064] atol=1e-3
92+
@test_broken sol[x]^2 + sol[y]^2 1.0
9193
end
9294

9395
@testset "rosenbrock" begin

0 commit comments

Comments
 (0)