ModelingToolkit.jl
ModelingToolkit.jl copied to clipboard
OptimizationSystem ignores constraint
Maybe I'm just not using this right. I copied the example code for OptimizationSystem and added an extra variable z
& a constraint for it (z=1
). The constraint gets ignored.
using ModelingToolkit, GalacticOptim, Optim
@variables x y z
@parameters a b
loss = (a - x)^2 + b * (y - x^2)^2 + z^2
lcons = [0~1.0-z]
sys = OptimizationSystem(loss,[x,y,z],[a,b],equality_constraints=lcons)
u0 = [
x=>1.0
y=>2.0
z => 1.0
]
p = [
a => 6.0
b => 7.0
]
prob = OptimizationProblem(sys,u0,p,grad=true,hess=true)
sol = solve(prob,Newton())
yields:
julia> sol = solve(prob,Newton())
u: 3-element Vector{Float64}:
5.999999999999992
35.9999999999999
2.953429564488977e-23
Yes, it doesn't lower the constraints right now. That really needs to get fixed.
Solved by #1660