diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..deb76b6 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +version: 2 +updates: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + - package-ecosystem: "julia" # See documentation for possible values +# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file + directory: "/" # Location of package manifests + schedule: + interval: "weekly" diff --git a/.github/workflows/CompatHelper.yml b/.github/workflows/CompatHelper.yml deleted file mode 100644 index cba9134..0000000 --- a/.github/workflows/CompatHelper.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: CompatHelper -on: - schedule: - - cron: 0 0 * * * - workflow_dispatch: -jobs: - CompatHelper: - runs-on: ubuntu-latest - steps: - - name: Pkg.add("CompatHelper") - run: julia -e 'using Pkg; Pkg.add("CompatHelper")' - - name: CompatHelper.main() - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }} - run: julia -e 'using CompatHelper; CompatHelper.main()' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 48d6fe6..10dc72b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: fail-fast: false matrix: version: - - '1.6' + - '1.10' - '1' - 'nightly' os: diff --git a/Project.toml b/Project.toml index 815179a..dc27338 100644 --- a/Project.toml +++ b/Project.toml @@ -7,6 +7,7 @@ version = "0.0.1-DEV" AutoGrad = "6710c13c-97f1-543f-91c5-74e8f7d95b35" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee" +MultivariateBases = "be282fd4-ad43-11e9-1d11-8bd9d7e43378" MultivariatePolynomials = "102ac46a-7ee4-5c85-9060-abc95bfdeaa3" NLopt = "76087f3c-5699-56af-9a33-bf431cd00edd" SemialgebraicSets = "8e049039-38e8-557d-ae3a-bc521ccf6204" @@ -16,9 +17,10 @@ TrigPolys = "bbdedc48-cb31-4a37-9fe3-b015aecc8dd3" [compat] AutoGrad = "1" MathOptInterface = "1" +MultivariateBases = "0.3" MultivariatePolynomials = "0.5" NLopt = "1" SemialgebraicSets = "0.3" -SumOfSquares = "0.7" +SumOfSquares = "0.8" TrigPolys = "0.1" -julia = "1.6" +julia = "1.10" diff --git a/src/BMSOS.jl b/src/BMSOS.jl index 03e8813..2ac384a 100644 --- a/src/BMSOS.jl +++ b/src/BMSOS.jl @@ -17,7 +17,7 @@ function fgradfft(U::AbstractMatrix, p::TrigPolys.TrigPoly; mapfn = Base.map) uB = mapfn(TrigPolys.evaluate, eachrow(Up)) d = sum(u .^ 2 for u in uB) - TrigPolys.evaluate(p) g = reduce(hcat, mapfn(u -> TrigPolys.evaluateT(u .* d), uB))' - return [g[:, 1:xs+1] g[:, 2*xs+2:3*xs+1]] + return [g[:, 1:(xs+1)] g[:, (2*xs+2):(3*xs+1)]] end """ @@ -49,7 +49,7 @@ function value_and_gradient!( uB = mapfn(TrigPolys.evaluate, eachrow(Up)) d = sum(u .^ 2 for u in uB) - TrigPolys.evaluate(p) g = reduce(hcat, mapfn(u -> TrigPolys.evaluateT(u .* d), uB))' - grad[:] = reshape([g[:, 1:xs+1] g[:, 2*xs+2:3*xs+1]], :) + grad[:] = reshape([g[:, 1:(xs+1)] g[:, (2*xs+2):(3*xs+1)]], :) return sum(d .^ 2) end @@ -86,7 +86,7 @@ function get_Up(U::AbstractArray, p::TrigPolys.TrigPoly) # FIXME why not `2 * xs + 2` ? xn = 2 * xs + 1 @assert xn == n "Inconsistent matrix dimension" - Up = [U[:, 1:xs+1] zeros(r, xs) U[:, xs+2:xn] zeros(r, xs)] + Up = [U[:, 1:(xs+1)] zeros(r, xs) U[:, (xs+2):xn] zeros(r, xs)] return r, xs, xn, Up end @@ -171,7 +171,7 @@ function sos_opt( nvars = rank * xn + 1 function f(x) - slices = [x[xn*(i-1)+1:xn*i] for i in 1:rank] + slices = [x[(xn*(i-1)+1):(xn*i)] for i in 1:rank] gam = last(x) uB = sum([evaluate(pad_to(u, p.n)) .^ 2 for u in slices]) return sum((uB - evaluate(p) .+ gam) .^ 2) @@ -203,7 +203,7 @@ function sos_opt( @time (minf, minx, ret) = NLopt.optimize(opt, xinit) @show ret - Uopt = reshape(minx[1:nvars-1], rank, xn) + Uopt = reshape(minx[1:(nvars-1)], rank, xn) xopt = last(minx) return f, fgrad, fvals, xvals, Uopt, xopt, ret, minx end diff --git a/src/MOI_wrapper.jl b/src/MOI_wrapper.jl index 2bbb383..69afc9f 100644 --- a/src/MOI_wrapper.jl +++ b/src/MOI_wrapper.jl @@ -1,4 +1,5 @@ import MultivariatePolynomials as MP +import MultivariateBases as MB import SemialgebraicSets import MathOptInterface as MOI import SumOfSquares @@ -57,7 +58,8 @@ function MOI.add_constraint( error("Nonconstant polynomials are not supported yet!") end # FIXME don't ignore `set.certificate` - optimizer.poly = MP.polynomial(func.constants, set.monomials) + optimizer.poly = + MP.polynomial(func.constants, MB.keys_as_monomials(set.basis)) return MOI.ConstraintIndex{typeof(func),typeof(set)}(0) end diff --git a/test/runtests.jl b/test/runtests.jl index deaedb2..3d7ae55 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -18,7 +18,7 @@ function test_decomp(n = 20) B = reduce(hcat, [TrigPolys.basis(p.n, xi) for xi in samples]) ps = reshape(p.(samples), 1, s) function f(U) - Up = [U[:, 1:xs+1] zeros(r, xs) U[:, xs+2:xn] zeros(r, xs)] + Up = [U[:, 1:(xs+1)] zeros(r, xs) U[:, (xs+2):xn] zeros(r, xs)] return sum((sum((Up * B) .^ 2, dims = 1) - ps) .^ 2) end #f(U) = sum((sum((U*B).^2, dims=1)-ps).^2)