Skip to content

Commit cec44c1

Browse files
committed
Revert "Make warning parameter threadsafe"
This reverts commit a10b555.
1 parent a10b555 commit cec44c1

File tree

4 files changed

+13
-37
lines changed

4 files changed

+13
-37
lines changed

docs/src/advanced.md

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

16-
These warnings can be very useful to know if a problem has been formulated
17-
correctly. However, in some circumstances, one may wish to disable these
18-
warnings. To do so, call [`Convex.disable_DCP_warnings()`](@ref). To restore the
19-
warnings, call [`Convex.enable_DCP_warnings()`](@ref).
16+
To disable this, set the module-level parameter `DCP_WARNINGS` via
2017

21-
```@docs
22-
Convex.enable_DCP_warnings()
23-
Convex.disable_DCP_warnings()
18+
```julia
19+
Convex.DCP_WARNINGS[] = false
2420
```
2521

2622

src/Convex.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ export Positive, Negative, ComplexSign, NoSign
3434
# Problems
3535
export add_constraint!, add_constraints!, maximize, minimize, Problem, satisfy, solve!
3636

37-
const DCP_WARNINGS = Bool[]
37+
"""
38+
const DCP_WARNINGS = Ref(true)
3839
39-
function __init__()
40-
resize!(DCP_WARNINGS, Threads.nthreads())
41-
fill!(DCP_WARNINGS, true)
42-
end
40+
Controls whether or not warnings are emitted for when an expression fails to be
41+
of disciplined convex form. To turn warnings off, run
4342
43+
Convex.DCP_WARNINGS[] = false
44+
"""
45+
const DCP_WARNINGS = Ref(true)
4446

4547
### modeling framework
4648
include("dcp.jl")

src/dcp.jl

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,9 @@ struct AffineVexity <: Vexity end
1919
struct ConvexVexity <: Vexity end
2020
struct ConcaveVexity <: Vexity end
2121

22-
23-
"""
24-
enable_DCP_warnings()
25-
26-
Enable warnings from the current thread when an expression fails to be of
27-
disciplined convex form. This setting is enabled by default. See also
28-
[`disable_DCP_warnings`](@ref).
29-
"""
30-
function enable_DCP_warnings()
31-
DCP_WARNINGS[Threads.threadid()] = true
32-
end
33-
34-
"""
35-
disable_DCP_warnings()
36-
37-
Disable warnings from the current thread when an expression fails to be of
38-
disciplined convex form. See also [`enable_DCP_warnings`](@ref).
39-
"""
40-
function disable_DCP_warnings()
41-
DCP_WARNINGS[Threads.threadid()] = false
42-
end
43-
4422
struct NotDcp <: Vexity
4523
function NotDcp()
46-
if DCP_WARNINGS[Threads.threadid()]
24+
if DCP_WARNINGS[]
4725
@warn "Expression not DCP compliant. Trying to solve non-DCP compliant problems can lead to unexpected behavior."
4826
end
4927
return new()

test/test_utilities.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,9 @@ using Convex: AbstractExpr, ConicObj
255255
# default is to log
256256
@test_logs (:warn, r"not DCP compliant") Convex.NotDcp()
257257

258-
Convex.disable_DCP_warnings()
258+
Convex.DCP_WARNINGS[] = false
259259
@test_logs Convex.NotDcp()
260-
Convex.enable_DCP_warnings()
260+
Convex.DCP_WARNINGS[] = true
261261
@test_logs (:warn, r"not DCP compliant") Convex.NotDcp()
262262

263263
end

0 commit comments

Comments
 (0)