Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow disabling DCP warnings #372

Merged
merged 4 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/src/advanced.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
Advanced Features
=================

DCP warnings
------------

When an expression is created which is not of [DCP
form](https://dcp.stanford.edu/), a warning is emitted. For example,

```repl
x = Variable()
y = Variable()
x*y
```

To disable this, set the module-level parameter `DCP_WARNINGS` via

```julia
Convex.DCP_WARNINGS[] = false
```


Dual Variables
--------------

Expand Down
31 changes: 31 additions & 0 deletions src/Convex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,37 @@ export Positive, Negative, ComplexSign, NoSign
# Problems
export add_constraint!, add_constraints!, maximize, minimize, Problem, satisfy, solve!


# Module level globals

"""
DCP_WARNINGS

Controls whether or not warnings are emitted for when an expression fails to be
of disciplined convex form. To turn warnings off, run

Convex.DCP_WARNINGS[] = false
"""
const DCP_WARNINGS = Threads.Atomic{Bool}(true)

"""
MAXDEPTH

Controls depth of tree printing globally for Convex.jl; defaults to 3. Set via

Convex.MAXDEPTH[] = 5
"""
const MAXDEPTH = Threads.Atomic{Int}(3)

"""
MAXWIDTH

Controls width of tree printing globally for Convex.jl; defaults to 15. Set via

Convex.MAXWIDTH[] = 15
"""
const MAXWIDTH= Threads.Atomic{Int}(15)

### modeling framework
include("dcp.jl")
include("expressions.jl")
Expand Down
4 changes: 3 additions & 1 deletion src/dcp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ struct ConcaveVexity <: Vexity end

struct NotDcp <: Vexity
function NotDcp()
@warn "Expression not DCP compliant. Trying to solve non-DCP compliant problems can lead to unexpected behavior."
if DCP_WARNINGS[]
@warn "Expression not DCP compliant. Trying to solve non-DCP compliant problems can lead to unexpected behavior."
end
return new()
end
end
Expand Down
14 changes: 0 additions & 14 deletions src/utilities/show.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
import Base.show, Base.summary
using .TreePrint

"""
const MAXDEPTH = Ref(3)

Controls depth of tree printing globally for Convex.jl
"""
const MAXDEPTH = Ref(3)

"""
const MAXWIDTH = Ref(15)

Controls width of tree printing globally for Convex.jl
"""
const MAXWIDTH= Ref(15)


"""
show_id(io::IO, x::Union{AbstractExpr, Constraint}; digits = 3)
Expand Down
11 changes: 11 additions & 0 deletions test/test_utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,15 @@ using Convex: AbstractExpr, ConicObj
# x.value = [1 2 3; 4 5 6]
# @fact evaluate(s) --> 21
# end

@testset "DCP warnings" begin
# default is to log
@test_logs (:warn, r"not DCP compliant") Convex.NotDcp()

Convex.DCP_WARNINGS[] = false
@test_logs Convex.NotDcp()
Convex.DCP_WARNINGS[] = true
@test_logs (:warn, r"not DCP compliant") Convex.NotDcp()

end
end