Skip to content

Commit ab07a8b

Browse files
authored
Fix Explicit approach (#45)
* Fix Explicit approach * Fix format
1 parent f520f1d commit ab07a8b

File tree

5 files changed

+35
-19
lines changed

5 files changed

+35
-19
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
2525
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
2626
SemialgebraicSets = "8e049039-38e8-557d-ae3a-bc521ccf6204"
2727
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
28+
SumOfSquares = "4b9e565b-77fc-50a5-a571-1244f986bda1"
2829
TypedTables = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9"
2930

3031
[compat]

src/MacaulayMatrix.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import JuMP
88
import MultivariateMoments as MM
99
import Printf
1010

11+
import SumOfSquares
12+
1113
import CommonSolve: solve, solve!, init, step!
1214

1315
abstract type AbstractIteration end

src/hankel.jl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,19 @@ function MM.moment_matrix(
121121
)
122122
model = JuMP.Model(solver)
123123
JuMP.@variable(model, γ)
124-
JuMP.@objective(model, Min, γ)
125-
JuMP.@variable(model, λ[i in eachindex(polynomials)])
126-
con_ref = JuMP.@constraint(model, γ + dot(polynomials, λ) in SOSCone())
124+
JuMP.@objective(model, Max, γ)
125+
vars = MP.variables(polynomials)
126+
JuMP.@variable(
127+
model,
128+
λ[i in eachindex(polynomials)],
129+
SumOfSquares.PolyJuMP.Poly(
130+
MP.monomials(vars, 0:(maxdegree-MP.maxdegree(polynomials[i]))),
131+
),
132+
)
133+
con_ref = JuMP.@constraint(
134+
model,
135+
LinearAlgebra.dot(polynomials, λ) - γ in SumOfSquares.SOSCone()
136+
)
127137
JuMP.optimize!(model)
128138
if JuMP.termination_status(model) == JuMP.MOI.DUAL_INFEASIBLE
129139
return

test/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[deps]
2-
CSDP = "0a46da34-8e4b-519e-b418-48813639ff34"
2+
Clarabel = "61c947e1-3e6d-4ee4-985a-eec8c727bd6e"
33
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
44
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
55
MacaulayMatrix = "bcb046b7-f005-4e9a-a986-fb3acd014398"

test/macaulay.jl

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import MultivariateBases as MB
66
import MultivariateMoments as MM
77
using MacaulayMatrix
88
using JuMP
9-
import CSDP
9+
import Clarabel
1010

1111
function __test_monomial_ideal_generators(standard, generators)
1212
basis = MB.MonomialBasis(standard)
@@ -48,14 +48,16 @@ function test_monomial_ideal_generators()
4848
end
4949

5050
function _test_moments(polys, solver, d, expected; tol = 1e-4)
51-
ν = MM.moment_matrix(polys, solver, d)
52-
@test MM.value_matrix(ν)[1, 1] 1 rtol = tol
53-
η = MM.atomic_measure(ν, tol)
54-
if isnothing(expected)
55-
@test isnothing(η)
56-
else
57-
sols =.atoms[i].center for i in eachindex.atoms)]
58-
_test_sols(sols, expected)
51+
@testset "$approach" for approach in [Explicit(), Hankel()]
52+
ν = MM.moment_matrix(polys, solver, d, approach)
53+
@test MM.value_matrix(ν)[1, 1] 1 rtol = tol
54+
η = MM.atomic_measure(ν, tol)
55+
if isnothing(expected)
56+
@test isnothing(η)
57+
else
58+
sols =.atoms[i].center for i in eachindex.atoms)]
59+
_test_sols(sols, expected)
60+
end
5961
end
6062
end
6163

@@ -114,7 +116,10 @@ function test_dreesen1()
114116
@testset "psd_hankel" begin
115117
_test_moments(
116118
ps,
117-
optimizer_with_attributes(CSDP.Optimizer, MOI.Silent() => true),
119+
optimizer_with_attributes(
120+
Clarabel.Optimizer,
121+
MOI.Silent() => true,
122+
),
118123
d,
119124
d == 3 ? nothing : expected,
120125
)
@@ -134,11 +139,9 @@ function test_univariate()
134139
sols = solve_system([q], column_maxdegree = d)
135140
_test_sols(sols, [[exp]])
136141
end
137-
solver = optimizer_with_attributes(CSDP.Optimizer, MOI.Silent() => true)
138-
@test psd_hankel([q], solver, 3) === nothing
139-
@testset "d=$d" for d in 4:8
140-
sols = psd_hankel([q], solver, d)
141-
_test_sols(sols, [[exp]])
142+
solver = optimizer_with_attributes(Clarabel.Optimizer, MOI.Silent() => true)
143+
@testset "d=$d" for d in 3:8
144+
_test_moments([q], solver, d, d == 3 ? nothing : [[exp]])
142145
end
143146
end
144147

0 commit comments

Comments
 (0)