From b6cee4630fd9d880a7771c160e7024bf10cfa1b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Mon, 14 Apr 2025 15:12:35 +0200 Subject: [PATCH 1/6] Use isone --- src/Bridges/Variable/kernel.jl | 8 ++++++-- src/Certificate/ideal.jl | 20 ++++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/Bridges/Variable/kernel.jl b/src/Bridges/Variable/kernel.jl index fb83a7ad7..def2a0022 100644 --- a/src/Bridges/Variable/kernel.jl +++ b/src/Bridges/Variable/kernel.jl @@ -19,8 +19,12 @@ function MOI.Bridges.Variable.bridge_constrained_variable( gram, vars, con = SOS.add_gram_matrix(model, M, gram_basis, T) push!(variables, vars) push!(constraints, con) - MA.operate_to!(cache, +, gram) - MA.operate!(SA.UnsafeAddMul(*), acc, cache, weight) + if isone(weight) + MA.operate!(SA.UnsafeAdd(), acc, gram) + else + MA.operate_to!(cache, +, gram) + MA.operate!(SA.UnsafeAddMul(*), acc, cache, weight) + end end MA.operate!(SA.canonical, SA.coeffs(acc)) return KernelBridge{T,M}( diff --git a/src/Certificate/ideal.jl b/src/Certificate/ideal.jl index 4def1276a..c9ed516d1 100644 --- a/src/Certificate/ideal.jl +++ b/src/Certificate/ideal.jl @@ -37,12 +37,20 @@ function _combine_with_gram( ) end for (gram, weight) in zip(gram_bases, weights) - MA.operate_to!( - cache, - +, - GramMatrix{_NonZero}((_, _) -> _NonZero(), gram), - ) - MA.operate!(SA.UnsafeAddMul(*), p, cache, weight) + if isone(weight) + MA.operate!( + SA.UnsafeAdd(), + p, + SA.QuadraticForm(GramMatrix{_NonZero}((_, _) -> _NonZero(), gram)), + ) + else + MA.operate_to!( + cache, + +, + GramMatrix{_NonZero}((_, _) -> _NonZero(), gram), + ) + MA.operate!(SA.UnsafeAddMul(*), p, cache, weight) + end end MA.operate!(SA.canonical, SA.coeffs(p)) return SA.sub_basis(parent(basis), keys(SA.coeffs(p))) From d6e55acdc4116351211964544344ae67d8b44dc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Mon, 20 Apr 2026 16:33:47 +0200 Subject: [PATCH 2/6] Fix format --- src/Certificate/ideal.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Certificate/ideal.jl b/src/Certificate/ideal.jl index c9ed516d1..3e1f7fe0e 100644 --- a/src/Certificate/ideal.jl +++ b/src/Certificate/ideal.jl @@ -41,7 +41,9 @@ function _combine_with_gram( MA.operate!( SA.UnsafeAdd(), p, - SA.QuadraticForm(GramMatrix{_NonZero}((_, _) -> _NonZero(), gram)), + SA.QuadraticForm( + GramMatrix{_NonZero}((_, _) -> _NonZero(), gram), + ), ) else MA.operate_to!( From 631a30797ae02efb7a13f4c13e4933e05e1c149e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Wed, 22 Apr 2026 14:57:42 +0200 Subject: [PATCH 3/6] dev --- .github/workflows/ci.yml | 8 ++++++++ .github/workflows/documentation.yml | 2 ++ .github/workflows/examples.yml | 2 ++ 3 files changed, 12 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9bef7a475..2b6a9c9d1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,14 @@ jobs: version: ${{ matrix.version }} arch: ${{ matrix.arch }} - uses: julia-actions/cache@v2 + - name: dev + shell: julia --project=@. {0} + run: | + using Pkg + Pkg.add([ + PackageSpec(name="MultivariateBases", rev="bl/one"), + PackageSpec(name="MultivariatePolynomials", rev="bl/in_expit"), + ]) - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 # # See https://github.com/oxfordcontrol/Clarabel.jl/pull/230 diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index f0fa77399..bcf622fed 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -22,6 +22,8 @@ jobs: run: | using Pkg Pkg.add([ + PackageSpec(name="MultivariateBases", rev="bl/one"), + PackageSpec(name="MultivariatePolynomials", rev="bl/in_expit"), PackageSpec(path=pwd()), ]) Pkg.instantiate() diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 8e5b6bdf6..9b76eee62 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -17,6 +17,8 @@ jobs: run: | using Pkg Pkg.add([ + PackageSpec(name="MultivariateBases", rev="bl/one"), + PackageSpec(name="MultivariatePolynomials", rev="bl/in_expit"), PackageSpec(path=pwd()), ]) Pkg.instantiate() From 89c25aeb4d189371588dea74e59546dc84974f8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Wed, 22 Apr 2026 17:57:39 +0200 Subject: [PATCH 4/6] Add test --- test/Bridges/Variable/kernel.jl | 51 +++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/test/Bridges/Variable/kernel.jl b/test/Bridges/Variable/kernel.jl index e82aa67b9..fa5e89c48 100644 --- a/test/Bridges/Variable/kernel.jl +++ b/test/Bridges/Variable/kernel.jl @@ -68,6 +68,57 @@ function test_runtests() return end +function test_runtests_weighted() + @polyvar x y + MOI.Bridges.runtests( + SumOfSquares.Bridges.Variable.KernelBridge, + model -> begin + p, _ = MOI.add_constrained_variables( + model, + SumOfSquares.WeightedSOSCone{ + MOI.PositiveSemidefiniteConeTriangle, + }( + MB.SubBasis{MB.Monomial}([ + y^4, + x * y^3, + x^2 * y^2, + x^3 * y, + x^4, + ]), + [MB.SubBasis{MB.Monomial}([y^2, x * y, x^2])], + [MB.algebra_element(2.0 * x^0 * y^0)], + ), + ) + a = float.(1:length(p)) + MOI.add_constraint( + model, + MOI.Utilities.vectorize([a' * p]), + MOI.Zeros(1), + ) + end, + model -> begin + q, _ = MOI.add_constrained_variables( + model, + MOI.PositiveSemidefiniteConeTriangle(3), + ) + a = float.(1:length(q)) + MOI.add_constraint( + model, + MOI.Utilities.vectorize([ + 2.0 * q[1] + + 8.0 * q[2] + + 6.0 * (1.0q[3] + 2.0q[4]) + + 16.0 * q[5] + + 10.0 * q[6], + ]), + MOI.Zeros(1), + ) + end; + cannot_unbridge = true, + ) + return +end + end # module TestVariableKernel.runtests() From 07e9f37595be2c04fc055a5da1072aeb2ef76ee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Wed, 22 Apr 2026 18:01:11 +0200 Subject: [PATCH 5/6] Add test --- test/Bridges/Variable/kernel.jl | 48 +++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/test/Bridges/Variable/kernel.jl b/test/Bridges/Variable/kernel.jl index fa5e89c48..45acc0ab4 100644 --- a/test/Bridges/Variable/kernel.jl +++ b/test/Bridges/Variable/kernel.jl @@ -119,6 +119,54 @@ function test_runtests_weighted() return end +# weight (1 + x), gram basis [1, x] +# (1 + x) * (Q11 + 2*Q12*x + Q22*x^2) +# = Q11 + (2*Q12 + Q11)*x + (Q22 + 2*Q12)*x^2 + Q22*x^3 +function test_runtests_polynomial_weight() + @polyvar x + MOI.Bridges.runtests( + SumOfSquares.Bridges.Variable.KernelBridge, + model -> begin + p, _ = MOI.add_constrained_variables( + model, + SumOfSquares.WeightedSOSCone{ + MOI.PositiveSemidefiniteConeTriangle, + }( + MB.SubBasis{MB.Monomial}([x^0, x, x^2, x^3]), + [MB.SubBasis{MB.Monomial}([x^0, x])], + [MB.algebra_element(1.0 * x^0 + 1.0 * x)], + ), + ) + a = float.(1:length(p)) + MOI.add_constraint( + model, + MOI.Utilities.vectorize([a' * p]), + MOI.Zeros(1), + ) + end, + model -> begin + q, _ = MOI.add_constrained_variables( + model, + SumOfSquares.PositiveSemidefinite2x2ConeTriangle(), + ) + # p[1] = 1.0*q[1], p[2] = 1.0*q[1] + 2.0*q[2], + # p[3] = 2.0*q[2] + 1.0*q[3], p[4] = 1.0*q[3] + MOI.add_constraint( + model, + MOI.Utilities.vectorize([ + 1.0 * q[1] + + 2.0 * (1.0q[1] + 2.0q[2]) + + 3.0 * (2.0q[2] + 1.0q[3]) + + 4.0 * q[3], + ]), + MOI.Zeros(1), + ) + end; + cannot_unbridge = true, + ) + return +end + end # module TestVariableKernel.runtests() From b9353888931e6323d2f0abb41f0a71ae1b2879c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Wed, 22 Apr 2026 18:39:39 +0200 Subject: [PATCH 6/6] Revert "dev" This reverts commit 631a30797ae02efb7a13f4c13e4933e05e1c149e. --- .github/workflows/ci.yml | 8 -------- .github/workflows/documentation.yml | 2 -- .github/workflows/examples.yml | 2 -- 3 files changed, 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2b6a9c9d1..9bef7a475 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,14 +32,6 @@ jobs: version: ${{ matrix.version }} arch: ${{ matrix.arch }} - uses: julia-actions/cache@v2 - - name: dev - shell: julia --project=@. {0} - run: | - using Pkg - Pkg.add([ - PackageSpec(name="MultivariateBases", rev="bl/one"), - PackageSpec(name="MultivariatePolynomials", rev="bl/in_expit"), - ]) - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 # # See https://github.com/oxfordcontrol/Clarabel.jl/pull/230 diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index bcf622fed..f0fa77399 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -22,8 +22,6 @@ jobs: run: | using Pkg Pkg.add([ - PackageSpec(name="MultivariateBases", rev="bl/one"), - PackageSpec(name="MultivariatePolynomials", rev="bl/in_expit"), PackageSpec(path=pwd()), ]) Pkg.instantiate() diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 9b76eee62..8e5b6bdf6 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -17,8 +17,6 @@ jobs: run: | using Pkg Pkg.add([ - PackageSpec(name="MultivariateBases", rev="bl/one"), - PackageSpec(name="MultivariatePolynomials", rev="bl/in_expit"), PackageSpec(path=pwd()), ]) Pkg.instantiate()