ModelingToolkit.jl icon indicating copy to clipboard operation
ModelingToolkit.jl copied to clipboard

OptimizationSystem ignores constraint

Open lamorton opened this issue 3 years ago • 1 comments

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

lamorton avatar Jul 21 '21 17:07 lamorton

Yes, it doesn't lower the constraints right now. That really needs to get fixed.

ChrisRackauckas avatar Jul 22 '21 11:07 ChrisRackauckas

Solved by #1660

lamorton avatar Aug 27 '22 19:08 lamorton