From 99eaebf4cd7002616c4d946381261ac0941b1d4a Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Wed, 4 Dec 2024 14:13:24 +1300 Subject: [PATCH 1/2] Fix DCPViolationError for MultiplyAtom --- src/atoms/MultiplyAtom.jl | 4 +--- src/dcp.jl | 2 +- test/MOI_wrapper.jl | 3 +-- test/test_atoms.jl | 8 ++------ 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/atoms/MultiplyAtom.jl b/src/atoms/MultiplyAtom.jl index 6e9bf9f27..e6c2e20d1 100644 --- a/src/atoms/MultiplyAtom.jl +++ b/src/atoms/MultiplyAtom.jl @@ -65,9 +65,7 @@ real_convert(::Type{T}, x::AbstractVector) where {T} = SPARSE_VECTOR{T}(x) function new_conic_form!(context::Context{T}, x::MultiplyAtom) where {T} if curvature(x) == NotDcp() - error( - "[MultiplyAtom] multiplication of two non-constant expressions is not DCP compliant", - ) + throw(DCPViolationError()) end if x.children[1].size == (1, 1) || x.children[2].size == (1, 1) # scalar multiplication diff --git a/src/dcp.jl b/src/dcp.jl index 86e9b863c..843191a83 100644 --- a/src/dcp.jl +++ b/src/dcp.jl @@ -15,7 +15,7 @@ # http://web.stanford.edu/~boyd/papers/disc_cvx_prog.html ############################################################################# -struct DCPViolationError <: Exception end +struct DCPViolationError <: MOI.UnsupportedError end function Base.showerror(io::IO, ::DCPViolationError) return print( diff --git a/test/MOI_wrapper.jl b/test/MOI_wrapper.jl index 38299d45f..8a4e4b207 100644 --- a/test/MOI_wrapper.jl +++ b/test/MOI_wrapper.jl @@ -44,8 +44,7 @@ function test_runtests() MOI.VariableBasisStatus, MOI.ObjectiveBound, ], - ); - exclude = ["hs071"], # HS071 is not convex + ), ) return end diff --git a/test/test_atoms.jl b/test/test_atoms.jl index 1243f8a3f..f198c7a02 100644 --- a/test/test_atoms.jl +++ b/test/test_atoms.jl @@ -660,15 +660,11 @@ function test_MultiplyAtom() Variable(2, 2) * Variable(3, 3) ) @test_throws( - ErrorException( - "[MultiplyAtom] multiplication of two non-constant expressions is not DCP compliant", - ), + DCPViolationError, _test_atom(_ -> Variable(2)' * Variable(2), ""), ) @test_throws( - ErrorException( - "[MultiplyAtom] multiplication of two non-constant expressions is not DCP compliant", - ), + DCPViolationError, _test_atom(_ -> Variable() * Variable(), ""), ) return From 02e31431f8129016df8a5d3c9c32972f52367397 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Wed, 4 Dec 2024 14:45:36 +1300 Subject: [PATCH 2/2] Update src/dcp.jl --- src/dcp.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dcp.jl b/src/dcp.jl index 843191a83..653c75fca 100644 --- a/src/dcp.jl +++ b/src/dcp.jl @@ -15,6 +15,8 @@ # http://web.stanford.edu/~boyd/papers/disc_cvx_prog.html ############################################################################# +# This is a subtype of MOI.UnsupportedError so that non-DCP +# errors trigger the correct paths in MOI.Test for Convex.Optimizer. struct DCPViolationError <: MOI.UnsupportedError end function Base.showerror(io::IO, ::DCPViolationError)