jump-dev / jump-dev/SumOfSquares.jl

Inconsistent behavior of Poly with DynamicPolynomials and TypedPolynomials.

Open
#255 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
131
Forks
26
PR merge metrics
No merged PRs in 30d

Description

I am trying to reproduce the [example on Lyapunov function search](https://jump.dev/SumOfSquares.jl/latest/generated/Systems%20and%20Control/lyapunov_function_search/) from the documentation. The example uses DynamicPolynomials. Since the degree of the polynomials is fixed here, my understanding was that I can freely switch to TypedPolynomials. But then the example fails. Below is the snippet of code relevant to reproduce the failure. First, with DynamicPolynomials:

```julia
julia> using DynamicPolynomials

julia> @polyvar x[1:3]
(PolyVar{true}[x₁, x₂, x₃],)

julia> using SumOfSquares

julia> monosX = x.^2
3-element Vector{Monomial{true}}:
x₁²
x₂²
x₃²

julia> Poly(monosX)
Poly{MonomialBasis{Monomial{true}, Vector{Monomial{true}}}}(MonomialBasis{Monomial{true}, Vector{Monomial{true}}}(Monomial{true}[x₁², x₂², x₃²]))
```
And now (after restarting the REPL) the same code with TypedPolynomials:

```julia
julia> using TypedPolynomials

julia> @polyvar y[1:3]
(y₁, y₂, y₃)

julia> using SumOfSquares

julia> monosY = y.^2
(y₁², y₂², y₃²)

julia> Poly(monosY)
ERROR: MethodError: no method matching Poly(::Tuple{Monomial{(y₁,), 1}, Monomial{(y₂,), 1}, Monomial{(y₃,), 1}})
Closest candidates are:
Poly(::AbstractVector{<:MultivariatePolynomials.AbstractPolynomialLike}) at ~/.julia/packages/PolyJuMP/pghif/src/variable.jl:36
Poly(::PB) where PB<:AbstractPolynomialBasis at ~/.julia/packages/PolyJuMP/pghif/src/variable.jl:34
Stacktrace:
[1] top-level scope
@ REPL[5]:1
```

Is this a feature or a bug? I confess I still do not get the difference between the two polynomial types perfectly.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the documented Lyapunov function search example and reproduce Poly(monosX) versus Poly(monosY) using DynamicPolynomials and TypedPolynomials. Inspect the Poly entry points shown by the MethodError in PolyJuMP's variable.jl, especially the AbstractVector candidate, and consider the issue resolved when the TypedPolynomials form no longer fails in the documented example.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.