Skip to content

Commit 55931d7

Browse files
authored
Fix DCPViolationError for MultiplyAtom (#712)
1 parent ba3a8f2 commit 55931d7

File tree

4 files changed

+7
-12
lines changed

4 files changed

+7
-12
lines changed

src/atoms/MultiplyAtom.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ real_convert(::Type{T}, x::AbstractVector) where {T} = SPARSE_VECTOR{T}(x)
6565

6666
function new_conic_form!(context::Context{T}, x::MultiplyAtom) where {T}
6767
if curvature(x) == NotDcp()
68-
error(
69-
"[MultiplyAtom] multiplication of two non-constant expressions is not DCP compliant",
70-
)
68+
throw(DCPViolationError())
7169
end
7270
if x.children[1].size == (1, 1) || x.children[2].size == (1, 1)
7371
# scalar multiplication

src/dcp.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
# http://web.stanford.edu/~boyd/papers/disc_cvx_prog.html
1616
#############################################################################
1717

18-
struct DCPViolationError <: Exception end
18+
# This is a subtype of MOI.UnsupportedError so that non-DCP
19+
# errors trigger the correct paths in MOI.Test for Convex.Optimizer.
20+
struct DCPViolationError <: MOI.UnsupportedError end
1921

2022
function Base.showerror(io::IO, ::DCPViolationError)
2123
return print(

test/MOI_wrapper.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ function test_runtests()
4444
MOI.VariableBasisStatus,
4545
MOI.ObjectiveBound,
4646
],
47-
);
48-
exclude = ["hs071"], # HS071 is not convex
47+
),
4948
)
5049
return
5150
end

test/test_atoms.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -660,15 +660,11 @@ function test_MultiplyAtom()
660660
Variable(2, 2) * Variable(3, 3)
661661
)
662662
@test_throws(
663-
ErrorException(
664-
"[MultiplyAtom] multiplication of two non-constant expressions is not DCP compliant",
665-
),
663+
DCPViolationError,
666664
_test_atom(_ -> Variable(2)' * Variable(2), ""),
667665
)
668666
@test_throws(
669-
ErrorException(
670-
"[MultiplyAtom] multiplication of two non-constant expressions is not DCP compliant",
671-
),
667+
DCPViolationError,
672668
_test_atom(_ -> Variable() * Variable(), ""),
673669
)
674670
return

0 commit comments

Comments
 (0)