Skip to content

Commit 6a5ffd8

Browse files
authored
Merge pull request #372 from JuliaOpt/DCP_warnings
Allow disabling DCP warnings
2 parents e8b5897 + 8d3692a commit 6a5ffd8

File tree

5 files changed

+64
-15
lines changed

5 files changed

+64
-15
lines changed

docs/src/advanced.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
Advanced Features
22
=================
33

4+
DCP warnings
5+
------------
6+
7+
When an expression is created which is not of [DCP
8+
form](https://dcp.stanford.edu/), a warning is emitted. For example,
9+
10+
```repl
11+
x = Variable()
12+
y = Variable()
13+
x*y
14+
```
15+
16+
To disable this, set the module-level parameter `DCP_WARNINGS` via
17+
18+
```julia
19+
Convex.DCP_WARNINGS[] = false
20+
```
21+
22+
423
Dual Variables
524
--------------
625

src/Convex.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,37 @@ export Positive, Negative, ComplexSign, NoSign
3535
# Problems
3636
export add_constraint!, add_constraints!, maximize, minimize, Problem, satisfy, solve!
3737

38+
39+
# Module level globals
40+
41+
"""
42+
DCP_WARNINGS
43+
44+
Controls whether or not warnings are emitted for when an expression fails to be
45+
of disciplined convex form. To turn warnings off, run
46+
47+
Convex.DCP_WARNINGS[] = false
48+
"""
49+
const DCP_WARNINGS = Threads.Atomic{Bool}(true)
50+
51+
"""
52+
MAXDEPTH
53+
54+
Controls depth of tree printing globally for Convex.jl; defaults to 3. Set via
55+
56+
Convex.MAXDEPTH[] = 5
57+
"""
58+
const MAXDEPTH = Threads.Atomic{Int}(3)
59+
60+
"""
61+
MAXWIDTH
62+
63+
Controls width of tree printing globally for Convex.jl; defaults to 15. Set via
64+
65+
Convex.MAXWIDTH[] = 15
66+
"""
67+
const MAXWIDTH= Threads.Atomic{Int}(15)
68+
3869
### modeling framework
3970
include("dcp.jl")
4071
include("expressions.jl")

src/dcp.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ struct ConcaveVexity <: Vexity end
2121

2222
struct NotDcp <: Vexity
2323
function NotDcp()
24-
@warn "Expression not DCP compliant. Trying to solve non-DCP compliant problems can lead to unexpected behavior."
24+
if DCP_WARNINGS[]
25+
@warn "Expression not DCP compliant. Trying to solve non-DCP compliant problems can lead to unexpected behavior."
26+
end
2527
return new()
2628
end
2729
end

src/utilities/show.jl

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
import Base.show, Base.summary
22
using .TreePrint
33

4-
"""
5-
const MAXDEPTH = Ref(3)
6-
7-
Controls depth of tree printing globally for Convex.jl
8-
"""
9-
const MAXDEPTH = Ref(3)
10-
11-
"""
12-
const MAXWIDTH = Ref(15)
13-
14-
Controls width of tree printing globally for Convex.jl
15-
"""
16-
const MAXWIDTH= Ref(15)
17-
184

195
"""
206
show_id(io::IO, x::Union{AbstractExpr, Constraint}; digits = 3)

test/test_utilities.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,15 @@ using Convex: AbstractExpr, ConicObj
250250
# x.value = [1 2 3; 4 5 6]
251251
# @fact evaluate(s) --> 21
252252
# end
253+
254+
@testset "DCP warnings" begin
255+
# default is to log
256+
@test_logs (:warn, r"not DCP compliant") Convex.NotDcp()
257+
258+
Convex.DCP_WARNINGS[] = false
259+
@test_logs Convex.NotDcp()
260+
Convex.DCP_WARNINGS[] = true
261+
@test_logs (:warn, r"not DCP compliant") Convex.NotDcp()
262+
263+
end
253264
end

0 commit comments

Comments
 (0)