Skip to content

Commit 481fa02

Browse files
committed
switch DCP warning mechanism
1 parent 15043b2 commit 481fa02

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

docs/src/advanced.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ y = Variable()
1313
x*y
1414
```
1515

16-
To disable this, set the module-level parameter `DCP_WARNINGS` via
16+
To disable this, run
1717

1818
```julia
19-
Convex.DCP_WARNINGS[] = false
19+
Convex.emit_dcp_warnings() = false
2020
```
21+
to redefine the method. See [`Convex.emit_dcp_warnings`](@ref) for more details.
2122

2223

2324
Dual Variables

docs/src/reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ Convex.fix!
2424
Convex.free!
2525
Convex.evaluate
2626
Convex.solve!
27+
Convex.emit_dcp_warnings
2728
```

src/Convex.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,17 @@ export add_constraints!, maximize, minimize, Problem, satisfy, solve!
4242
# Module level globals
4343

4444
"""
45-
DCP_WARNINGS
45+
emit_dcp_warnings
4646
4747
Controls whether or not warnings are emitted for when an expression fails to be
48-
of disciplined convex form. To turn warnings off, run
48+
of disciplined convex form. To turn warnings off, override the method via
4949
50-
Convex.DCP_WARNINGS[] = false
50+
Convex.emit_dcp_warnings() = false
51+
52+
This will cause Julia's method invalidation to recompile any functions emitting
53+
DCP warnings and remove them. This should be run from top-level (not within a function).
5154
"""
52-
const DCP_WARNINGS = Ref(true)
55+
emit_dcp_warnings() = true
5356

5457
"""
5558
MAXDEPTH

src/dcp.jl

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

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

test/test_utilities.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,9 @@ end
440440
# default is to log
441441
@test_logs (:warn, r"not DCP compliant") Convex.NotDcp()
442442

443-
Convex.DCP_WARNINGS[] = false
443+
@eval Convex.emit_dcp_warnings() = false
444444
@test_logs Convex.NotDcp()
445-
Convex.DCP_WARNINGS[] = true
445+
@eval Convex.emit_dcp_warnings() = true
446446
@test_logs (:warn, r"not DCP compliant") Convex.NotDcp()
447447

448448
end

0 commit comments

Comments
 (0)