SumOfSquares.jl
SumOfSquares.jl copied to clipboard
Inequality with no variable
It was rightly reported to me by email as confusing behavior:
julia> model = SOSModel(CSDP.Optimizer);
julia> using DynamicPolynomials
julia> @polyvar x y
(x, y)
julia> S = @set x^2 + y^2 == 1
Algebraic Set defined by 1 equalitty
x^2 + y^2 - 1.0 = 0
julia> @constraint(model, -1 >= 0, domain = S)
ERROR: At REPL[17]:1: `@constraint(model, -1 >= 0, domain = S)`: Unrecognized constraint building format. Tried to invoke `build_constraint(error, -1, MathOptInterface.GreaterThan{Float64}(0.0); domain = { (x, y) | x^2 + y^2 - 1.0 = 0 })`, but no such method exists. This is due to specifying an unrecognized function, constraint set, and/or extra positional/keyword arguments.
If you're trying to create a JuMP extension, you need to implement `build_constraint` to accomodate these arguments.
Stacktrace:
[1] error(::String, ::String)
@ Base ./error.jl:42
[2] _macro_error(macroname::Symbol, args::Tuple{Symbol, Expr, Expr}, source::LineNumberNode, str::String)
@ JuMP ~/.julia/packages/JuMP/2IF9U/src/macros.jl:1644
[3] (::JuMP.var"#_error#90"{Tuple{Symbol, Expr, Expr}, Symbol, LineNumberNode})(str::String)
@ JuMP ~/.julia/packages/JuMP/2IF9U/src/macros.jl:735
[4] build_constraint(::JuMP.var"#_error#90"{Tuple{Symbol, Expr, Expr}, Symbol, LineNumberNode}, ::Int64, ::MathOptInterface.GreaterThan{Float64}; kwargs::Base.Pairs{Symbol, AlgebraicSet{Float64, Polynomial{true, Float64}, Buchberger, SemialgebraicSets.SolverUsingMultiplicationMatrices{SemialgebraicSets.GröbnerBasisMultiplicationMatricesAlgorithm, ReorderedSchurMultiplicationMatricesSolver{Int64, Random._GLOBAL_RNG}}, Float64}, Tuple{Symbol}, NamedTuple{(:domain,), Tuple{AlgebraicSet{Float64, Polynomial{true, Float64}, Buchberger, SemialgebraicSets.SolverUsingMultiplicationMatrices{SemialgebraicSets.GröbnerBasisMultiplicationMatricesAlgorithm, ReorderedSchurMultiplicationMatricesSolver{Int64, Random._GLOBAL_RNG}}, Float64}}}})
@ JuMP ~/.julia/packages/JuMP/2IF9U/src/macros.jl:535
[5] macro expansion
@ ~/.julia/packages/JuMP/2IF9U/src/macros.jl:814 [inlined]
[6] top-level scope
@ REPL[17]:1
I don't see any way to improve the error message as JuMP does not redirect it to SumOfSquares.
However, we should add a warning in the docs:
https://jump.dev/SumOfSquares.jl/stable/constraints/#Automatically-interpreting-polynomial-nonnegativity-as-a-sum-of-squares-constraint
to recommend the user to use SOSCone() in that case or -1 + 0 * x (actually -1 + 0 * x + 0 * y is preferred due to https://github.com/jump-dev/SumOfSquares.jl/issues/106). Which actually doesn't work but should
julia> @constraint(model, -1 in SOSCone(), domain = S)
ERROR: MethodError: no method matching coefficients(::Int64)
Closest candidates are:
coefficients(::Any, ::Type{<:ScaledMonomialBasis}) at ~/.julia/packages/MultivariateBases/7OoXa/src/scaled.jl:48
coefficients(::Any, ::Type{<:MonomialBasis}) at ~/.julia/packages/MultivariateBases/7OoXa/src/monomial.jl:60
coefficients(::Polynomial) at ~/.julia/packages/DynamicPolynomials/c4rDI/src/poly.jl:118
...
Stacktrace:
[1] non_constant_coefficients(p::Int64)
@ PolyJuMP ~/.julia/packages/PolyJuMP/9Kezv/src/constraint.jl:146
[2] build_constraint(_error::Function, p::Int64, cone::SOSCone; kws::Base.Pairs{Symbol, AlgebraicSet{Float64, Polynomial{true, Float64}, Buchberger, SemialgebraicSets.SolverUsingMultiplicationMatrices{SemialgebraicSets.GröbnerBasisMultiplicationMatricesAlgorithm, ReorderedSchurMultiplicationMatricesSolver{Int64, Random._GLOBAL_RNG}}, Float64}, Tuple{Symbol}, NamedTuple{(:domain,), Tuple{AlgebraicSet{Float64, Polynomial{true, Float64}, Buchberger, SemialgebraicSets.SolverUsingMultiplicationMatrices{SemialgebraicSets.GröbnerBasisMultiplicationMatricesAlgorithm, ReorderedSchurMultiplicationMatricesSolver{Int64, Random._GLOBAL_RNG}}, Float64}}}})
@ SumOfSquares ~/.julia/dev/SumOfSquares/src/constraint.jl:209
[3] macro expansion
@ ~/.julia/packages/JuMP/2IF9U/src/macros.jl:814 [inlined]
[4] top-level scope
@ REPL[18]:1
- [ ] Add warning in doc
- [ ] Fix error with
-1 in SOSCone()