diff --git a/docs/make.jl b/docs/make.jl index 358fdb010..a82064f59 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -13,7 +13,6 @@ makedocs(; "Complex-domain Optimization" => "complex-domain_optimization.md", "Solvers" => "solvers.md", "FAQ" => "faq.md", - "Optimizing in a Loop" => "loop.md", "Advanced" => "advanced.md", "Problem Depot" => "problem_depot.md", "Contributing" => "contributing.md", diff --git a/docs/src/loop.md b/docs/src/loop.md deleted file mode 100644 index 7185ed802..000000000 --- a/docs/src/loop.md +++ /dev/null @@ -1,62 +0,0 @@ -Optimizing in a Loop -==================== - -Memory Management ------------------ - -Convex uses a module-level dictionary to store the conic forms of every -variable and expression created in the same Julia session. These -variables and expressions persist even after they are out of scope. If -you create large numbers of variables inside a loop, this dictionary can -eat a considerable amount of memory. - -To flush the memory, you can call `Convex.clearmemory()`. - -This will remove every variable and expression you've formed before -from the memory cache, so that you're starting as fresh as if you'd -just reimported Convex. - -Caching Expressions -------------------- - -Better yet, take advantage of this cache of variables and expressions! -Create variables and expressions outside the loop, and reuse them inside -the loop as you tweak parameters. Doing this will allow Convex to reuse -the conic forms it has already calculated for previously used -expressions. - -For example, the following **bad** code will create a new instance of a -variable and of the expression `square(x)` for each value of `i`. Don't -do this: - -```julia -for i = 1:10 - x = Variable() - p = minimize(square(x), x >= i) - solve!(p, SCSSolver()) -end -``` - -Contrast this with the following **good** code, which will reuse the -cached conic form for `square(x)` for each `i`, reducing the memory -footprint and speeding up the computation. Do this instead: - -```julia -x = Variable() -obj = square(x) -for i = 1:10 - p = minimize(obj, x >= i) - solve!(p, SCSSolver()) -end -``` - -Warmstarts, Parameters, Fixing and Freeing Variables ----------------------------------------------------- - -If you're solving many problems of the same form, or many similar -problems, you may also want to use warmstarts, or to dynamically fix and -free variables. The former is particularly good for a family of problems -related by a parameter; the latter allows for easy implementation of -alternating minimization for nonconvex problems. See the [Advanced -Features](@ref) section of the documentation for more -information. diff --git a/docs/src/problem_depot.md b/docs/src/problem_depot.md index 2de7151f7..7b0f072cb 100644 --- a/docs/src/problem_depot.md +++ b/docs/src/problem_depot.md @@ -36,13 +36,13 @@ The problems are organized into folders in `src/problem_depot/problems`. Each is end ``` -The `@add_problem` call adds the problem to the registry of problems in [`Convex.ProblemDepot.PROBLEMS`](@ref), which in turn is used by [`run_tests`](@ref) and [`benchmark_suite`](@ref). Next, `affine` is the grouping of the problem; this problem came from one of the affine tests, and in particular is testing the negation atom. Next is the function signature: +The `@add_problem` call adds the problem to the registry of problems in [`Convex.ProblemDepot.PROBLEMS`](@ref), which in turn is used by [`Convex.ProblemDepot.run_tests`](@ref) and [`Convex.ProblemDepot.benchmark_suite`](@ref). Next, `affine` is the grouping of the problem; this problem came from one of the affine tests, and in particular is testing the negation atom. Next is the function signature: ```julia function affine_negate_atom(handle_problem!, ::Val{test}, atol, rtol, ::Type{T}) where {T, test} ``` -this should be the same for every problem, except for the name, which is a description of the problem. It should include what kind of atoms it uses (`affine` in this case), so that certain kinds of atoms can be ruled out by the `exclude` keyword to [`run_tests`](@ref) and [`benchmark_suite`](@ref); for example, many solvers cannot solve mixed-integer problems, so `mip` is included in the name of such problems. +this should be the same for every problem, except for the name, which is a description of the problem. It should include what kind of atoms it uses (`affine` in this case), so that certain kinds of atoms can be ruled out by the `exclude` keyword to [`Convex.ProblemDepot.run_tests`](@ref) and [`Convex.ProblemDepot.benchmark_suite`](@ref); for example, many solvers cannot solve mixed-integer problems, so `mip` is included in the name of such problems. Then begins the body of the problem. It is setup like any other Convex.jl problem, only `handle_problem!` is called instead of `solve!`. This allows particular solvers to be used (via e.g. choosing `handle_problem! = p -> solve!(p, solver)`), or for any other function of the problem (e.g. `handle_problem! = p -> Convex.conic_problem(p)` which is used for benchmarking problem formulation speed.) Tests should be included and gated behind `if test` blocks, so that tests can be skipped for benchmarking, or in the case that the problem is not in fact solved during `handle_problem!`. diff --git a/src/atoms/affine/add_subtract.jl b/src/atoms/affine/add_subtract.jl index 38844b080..facdce95f 100644 --- a/src/atoms/affine/add_subtract.jl +++ b/src/atoms/affine/add_subtract.jl @@ -41,7 +41,7 @@ end -(x::AbstractExpr) = NegateAtom(x) -function conic_form!(x::NegateAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::NegateAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) objective = conic_form!(x.children[1], unique_conic_forms) objective = -objective @@ -102,7 +102,7 @@ function evaluate(x::AdditionAtom) return mapreduce(evaluate, (a, b) -> a .+ b, x.children) end -function conic_form!(x::AdditionAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::AdditionAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) objective = ConicObj() for child in x.children diff --git a/src/atoms/affine/conjugate.jl b/src/atoms/affine/conjugate.jl index 186f9b26c..6b9e9e092 100644 --- a/src/atoms/affine/conjugate.jl +++ b/src/atoms/affine/conjugate.jl @@ -29,7 +29,7 @@ function evaluate(x::ConjugateAtom) return conj(evaluate(x.children[1])) end -function conic_form!(x::ConjugateAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::ConjugateAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) objective = conic_form!(x.children[1], unique_conic_forms) for var in keys(objective) diff --git a/src/atoms/affine/diag.jl b/src/atoms/affine/diag.jl index fc53408a2..5653c53ce 100644 --- a/src/atoms/affine/diag.jl +++ b/src/atoms/affine/diag.jl @@ -70,7 +70,7 @@ diag(x::AbstractExpr, k::Int=0) = DiagAtom(x, k) # 3. We populate coeff with 1s at the correct indices # The canonical form will then be: # coeff * x - d = 0 -function conic_form!(x::DiagAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::DiagAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) (num_rows, num_cols) = x.children[1].size k = x.k diff --git a/src/atoms/affine/diagm.jl b/src/atoms/affine/diagm.jl index 0437d2a78..7c08e0208 100644 --- a/src/atoms/affine/diagm.jl +++ b/src/atoms/affine/diagm.jl @@ -55,7 +55,7 @@ function diagm((d, x)::Pair{<:Integer, <:AbstractExpr}) end Diagonal(x::AbstractExpr) = DiagMatrixAtom(x) -function conic_form!(x::DiagMatrixAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::DiagMatrixAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) sz = x.size[1] diff --git a/src/atoms/affine/index.jl b/src/atoms/affine/index.jl index 1fa96a7f2..9beca6f48 100644 --- a/src/atoms/affine/index.jl +++ b/src/atoms/affine/index.jl @@ -47,7 +47,7 @@ function evaluate(x::IndexAtom) end end -function conic_form!(x::IndexAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::IndexAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) m = length(x) n = length(x.children[1]) diff --git a/src/atoms/affine/multiply_divide.jl b/src/atoms/affine/multiply_divide.jl index 734cb1737..08981e70a 100644 --- a/src/atoms/affine/multiply_divide.jl +++ b/src/atoms/affine/multiply_divide.jl @@ -54,7 +54,7 @@ function evaluate(x::MultiplyAtom) return evaluate(x.children[1]) * evaluate(x.children[2]) end -function conic_form!(x::MultiplyAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::MultiplyAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) # scalar multiplication if x.children[1].size == (1, 1) || x.children[2].size == (1, 1) @@ -145,7 +145,7 @@ function evaluate(x::DotMultiplyAtom) return evaluate(x.children[1]) .* evaluate(x.children[2]) end -function conic_form!(x::DotMultiplyAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::DotMultiplyAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) if vexity(x.children[1]) != ConstVexity() if vexity(x.children[2]) != ConstVexity() diff --git a/src/atoms/affine/partialtranspose.jl b/src/atoms/affine/partialtranspose.jl index 27b9dbd49..90ccfd86a 100644 --- a/src/atoms/affine/partialtranspose.jl +++ b/src/atoms/affine/partialtranspose.jl @@ -82,7 +82,7 @@ end # borrowing this from transpose.jl: # Since everything is vectorized, we simply need to multiply x by a permutation # matrix such that coeff * vectorized(x) - vectorized(x') = 0 -function conic_form!(x::PartialTransposeAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::PartialTransposeAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) objective = conic_form!(x.children[1], unique_conic_forms) @@ -104,5 +104,3 @@ function conic_form!(x::PartialTransposeAtom, unique_conic_forms::UniqueConicFor end partialtranspose(x::AbstractExpr,sys::Int, dim::Vector) = PartialTransposeAtom(x,sys,dim) - - diff --git a/src/atoms/affine/real_imag.jl b/src/atoms/affine/real_imag.jl index 619840442..7aa470371 100644 --- a/src/atoms/affine/real_imag.jl +++ b/src/atoms/affine/real_imag.jl @@ -42,7 +42,7 @@ function evaluate(x::RealAtom) return real.(evaluate(x.children[1])) end -function conic_form!(x::RealAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::RealAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) new_objective = ConicObj() objective = conic_form!(x.children[1], unique_conic_forms) @@ -93,7 +93,7 @@ function evaluate(x::ImaginaryAtom) return imag.(evaluate(x.children[1])) end -function conic_form!(x::ImaginaryAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::ImaginaryAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) new_objective = ConicObj() objective = conic_form!(x.children[1], unique_conic_forms) diff --git a/src/atoms/affine/reshape.jl b/src/atoms/affine/reshape.jl index bfd6ac403..d9038c690 100644 --- a/src/atoms/affine/reshape.jl +++ b/src/atoms/affine/reshape.jl @@ -33,7 +33,7 @@ function evaluate(x::ReshapeAtom) return reshape(evaluate(x.children[1]), x.size[1], x.size[2]) end -function conic_form!(x::ReshapeAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::ReshapeAtom, unique_conic_forms::UniqueConicForms) return conic_form!(x.children[1], unique_conic_forms) end diff --git a/src/atoms/affine/stack.jl b/src/atoms/affine/stack.jl index 7420c433a..3236c030c 100644 --- a/src/atoms/affine/stack.jl +++ b/src/atoms/affine/stack.jl @@ -39,7 +39,7 @@ function evaluate(x::HcatAtom) end -function conic_form!(x::HcatAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::HcatAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) # build a list of child conic objectives and constraints objectives = ConicObj[] @@ -130,4 +130,4 @@ function hvcat(rows::Tuple{Vararg{Int}}, args::AbstractExprOrValue...) a += rows[i] end return vcat(rs...) -end \ No newline at end of file +end diff --git a/src/atoms/affine/sum.jl b/src/atoms/affine/sum.jl index 6aec9e24e..9ba8b0415 100644 --- a/src/atoms/affine/sum.jl +++ b/src/atoms/affine/sum.jl @@ -43,7 +43,7 @@ end # Suppose x was of the form # x = Ay where A was a coefficient. Then sum(x) can also be considered # sum(A, 1) * y -function conic_form!(x::SumAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::SumAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) objective = conic_form!(x.children[1], unique_conic_forms) new_obj = copy(objective) diff --git a/src/atoms/affine/transpose.jl b/src/atoms/affine/transpose.jl index 8bdb02ad9..a43902415 100644 --- a/src/atoms/affine/transpose.jl +++ b/src/atoms/affine/transpose.jl @@ -39,7 +39,7 @@ end # Since everything is vectorized, we simply need to multiply x by a permutation # matrix such that coeff * vectorized(x) - vectorized(x') = 0 -function conic_form!(x::TransposeAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::TransposeAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) objective = conic_form!(x.children[1], unique_conic_forms) @@ -102,7 +102,7 @@ end # Since everything is vectorized, we simply need to multiply x by a permutation # matrix such that coeff * vectorized(x) - vectorized(x') = 0 -function conic_form!(x::AdjointAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::AdjointAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) objective = conic_form!(x.children[1], unique_conic_forms) diff --git a/src/atoms/exp_+_sdp_cone/logdet.jl b/src/atoms/exp_+_sdp_cone/logdet.jl index e3d561cf8..46898458a 100644 --- a/src/atoms/exp_+_sdp_cone/logdet.jl +++ b/src/atoms/exp_+_sdp_cone/logdet.jl @@ -29,7 +29,7 @@ function evaluate(x::LogDetAtom) return log(det(evaluate(x.children[1]))) end -function conic_form!(x::LogDetAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::LogDetAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) A = x.children[1] D = Variable(size(A)) # diagonal matrix diff --git a/src/atoms/exp_cone/entropy.jl b/src/atoms/exp_cone/entropy.jl index 5874d9868..34195c14a 100644 --- a/src/atoms/exp_cone/entropy.jl +++ b/src/atoms/exp_cone/entropy.jl @@ -47,7 +47,7 @@ function evaluate(x::EntropyAtom) return -c .* log.(c) end -function conic_form!(e::EntropyAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(e::EntropyAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, e) # -x log x >= t <=> x exp(t/x) <= 1 <==> (t,x,1) in exp cone t = Variable(e.size) diff --git a/src/atoms/exp_cone/exp.jl b/src/atoms/exp_cone/exp.jl index 721ff1c85..a46681a57 100644 --- a/src/atoms/exp_cone/exp.jl +++ b/src/atoms/exp_cone/exp.jl @@ -45,7 +45,7 @@ end exp(x::AbstractExpr) = ExpAtom(x) -function conic_form!(e::ExpAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(e::ExpAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, e) # exp(x) \leq z <=> (x,ones(),z) \in ExpCone x = e.children[1] diff --git a/src/atoms/exp_cone/log.jl b/src/atoms/exp_cone/log.jl index f5c21e44a..db34e1d00 100644 --- a/src/atoms/exp_cone/log.jl +++ b/src/atoms/exp_cone/log.jl @@ -45,7 +45,7 @@ end log(x::AbstractExpr) = LogAtom(x) -function conic_form!(e::LogAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(e::LogAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, e) # log(z) \geq x <=> (x,ones(),z) \in ExpCone z = e.children[1] diff --git a/src/atoms/exp_cone/logsumexp.jl b/src/atoms/exp_cone/logsumexp.jl index 540e67198..18261b90a 100644 --- a/src/atoms/exp_cone/logsumexp.jl +++ b/src/atoms/exp_cone/logsumexp.jl @@ -46,7 +46,7 @@ end logsumexp(x::AbstractExpr) = LogSumExpAtom(x) -function conic_form!(e::LogSumExpAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(e::LogSumExpAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, e) # log(sum(exp(x))) <= t <=> sum(exp(x)) <= exp(t) <=> sum(exp(x - t)) <= 1 t = Variable(e.size) diff --git a/src/atoms/exp_cone/relative_entropy.jl b/src/atoms/exp_cone/relative_entropy.jl index ae2e3b20c..7d8e98bc4 100644 --- a/src/atoms/exp_cone/relative_entropy.jl +++ b/src/atoms/exp_cone/relative_entropy.jl @@ -50,7 +50,7 @@ function evaluate(e::RelativeEntropyAtom) return out end -function conic_form!(e::RelativeEntropyAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(e::RelativeEntropyAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, e) # transform to conic form: # x log x/y <= z diff --git a/src/atoms/lp_cone/abs.jl b/src/atoms/lp_cone/abs.jl index 9553c9162..77de37d19 100644 --- a/src/atoms/lp_cone/abs.jl +++ b/src/atoms/lp_cone/abs.jl @@ -39,7 +39,7 @@ function evaluate(x::AbsAtom) return abs.(evaluate(x.children[1])) end -function conic_form!(x::AbsAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::AbsAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) c = x.children[1] t = Variable(size(c)) diff --git a/src/atoms/lp_cone/dotsort.jl b/src/atoms/lp_cone/dotsort.jl index 5ab58c8aa..90e4ea3cd 100644 --- a/src/atoms/lp_cone/dotsort.jl +++ b/src/atoms/lp_cone/dotsort.jl @@ -57,7 +57,7 @@ function evaluate(x::DotSortAtom) return sum(sort(vec(evaluate(x.children[1])), rev=true) .* sort(vec(x.w), rev=true)) end -function conic_form!(x::DotSortAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::DotSortAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) y = x.children[1] w = x.w diff --git a/src/atoms/lp_cone/max.jl b/src/atoms/lp_cone/max.jl index 3b62b0b69..229a73e33 100644 --- a/src/atoms/lp_cone/max.jl +++ b/src/atoms/lp_cone/max.jl @@ -63,7 +63,7 @@ function evaluate(x::MaxAtom) end # x <= this and y <= this if max(x, y) = this -function conic_form!(x::MaxAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::MaxAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) this = Variable(x.size[1], x.size[2]) objective = conic_form!(this, unique_conic_forms) diff --git a/src/atoms/lp_cone/maximum.jl b/src/atoms/lp_cone/maximum.jl index aa72f013d..c08e60a66 100644 --- a/src/atoms/lp_cone/maximum.jl +++ b/src/atoms/lp_cone/maximum.jl @@ -45,7 +45,7 @@ end # x <= this if maximum(x) = this # so, this - x will be in the :NonNeg cone -function conic_form!(x::MaximumAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::MaximumAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) this = Variable() objective = conic_form!(this, unique_conic_forms) diff --git a/src/atoms/lp_cone/min.jl b/src/atoms/lp_cone/min.jl index f1ed35ba5..9946514f8 100644 --- a/src/atoms/lp_cone/min.jl +++ b/src/atoms/lp_cone/min.jl @@ -63,7 +63,7 @@ function evaluate(x::MinAtom) end # x >= this and y >= this if min(x, y) = this -function conic_form!(x::MinAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::MinAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) this = Variable(x.size[1], x.size[2]) objective = conic_form!(this, unique_conic_forms) diff --git a/src/atoms/lp_cone/minimum.jl b/src/atoms/lp_cone/minimum.jl index 9fda110aa..14d75134b 100644 --- a/src/atoms/lp_cone/minimum.jl +++ b/src/atoms/lp_cone/minimum.jl @@ -45,7 +45,7 @@ end # x >= this if minimum(x) = this # so, x - this will be in the :NonNeg cone -function conic_form!(x::MinimumAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::MinimumAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) this = Variable() objective = conic_form!(this, unique_conic_forms) diff --git a/src/atoms/lp_cone/sumlargest.jl b/src/atoms/lp_cone/sumlargest.jl index ec137d153..952feeda3 100644 --- a/src/atoms/lp_cone/sumlargest.jl +++ b/src/atoms/lp_cone/sumlargest.jl @@ -47,7 +47,7 @@ function evaluate(x::SumLargestAtom) return sum(sort(vec(evaluate(x.children[1])), rev=true)[1:x.k]) end -function conic_form!(x::SumLargestAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::SumLargestAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) c = x.children[1] t = Variable(size(c)) diff --git a/src/atoms/sdp_cone/matrixfrac.jl b/src/atoms/sdp_cone/matrixfrac.jl index 44b866cb1..be4b4ab47 100644 --- a/src/atoms/sdp_cone/matrixfrac.jl +++ b/src/atoms/sdp_cone/matrixfrac.jl @@ -47,7 +47,7 @@ matrixfrac(x::AbstractExpr, P::AbstractExpr) = MatrixFracAtom(x, P) matrixfrac(x::Value, P::AbstractExpr) = MatrixFracAtom(Constant(x), P) matrixfrac(x::AbstractExpr, P::Value) = MatrixFracAtom(x, Constant(P)) -function conic_form!(m::MatrixFracAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(m::MatrixFracAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, m) x = m.children[1] P = m.children[2] diff --git a/src/atoms/second_order_cone/geomean.jl b/src/atoms/second_order_cone/geomean.jl index 998be6d55..516b1326e 100644 --- a/src/atoms/second_order_cone/geomean.jl +++ b/src/atoms/second_order_cone/geomean.jl @@ -36,7 +36,7 @@ function evaluate(q::GeoMeanAtom) return sqrt.(evaluate(q.children[1]) .* evaluate(q.children[2])) end -function conic_form!(q::GeoMeanAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(q::GeoMeanAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, q) sz = q.children[1].size t = Variable(sz[1], sz[2]) diff --git a/src/atoms/second_order_cone/huber.jl b/src/atoms/second_order_cone/huber.jl index 4f354e1c4..6c05d4b7e 100644 --- a/src/atoms/second_order_cone/huber.jl +++ b/src/atoms/second_order_cone/huber.jl @@ -42,7 +42,7 @@ function evaluate(x::HuberAtom) return c end -function conic_form!(x::HuberAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::HuberAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) c = x.children[1] s = Variable(c.size) diff --git a/src/atoms/second_order_cone/norm2.jl b/src/atoms/second_order_cone/norm2.jl index 866335914..faf015255 100644 --- a/src/atoms/second_order_cone/norm2.jl +++ b/src/atoms/second_order_cone/norm2.jl @@ -40,7 +40,7 @@ end ## Create a new variable euc_norm to represent the norm ## Additionally, create the second order conic constraint (euc_norm, x) in SOC -function conic_form!(x::EucNormAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::EucNormAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) euc_norm = Variable() objective = conic_form!(euc_norm, unique_conic_forms) diff --git a/src/atoms/second_order_cone/qol_elementwise.jl b/src/atoms/second_order_cone/qol_elementwise.jl index 6b0166b8f..439a6bcb3 100644 --- a/src/atoms/second_order_cone/qol_elementwise.jl +++ b/src/atoms/second_order_cone/qol_elementwise.jl @@ -33,7 +33,7 @@ function evaluate(q::QolElemAtom) return (evaluate(q.children[1]).^2) ./ evaluate(q.children[2]) end -function conic_form!(q::QolElemAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(q::QolElemAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, q) sz = q.children[1].size t = Variable(sz[1], sz[2]) diff --git a/src/atoms/second_order_cone/quadoverlin.jl b/src/atoms/second_order_cone/quadoverlin.jl index 522aac70d..eb9796a5f 100644 --- a/src/atoms/second_order_cone/quadoverlin.jl +++ b/src/atoms/second_order_cone/quadoverlin.jl @@ -33,7 +33,7 @@ function evaluate(q::QuadOverLinAtom) return x'*x / evaluate(q.children[2]) end -function conic_form!(q::QuadOverLinAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(q::QuadOverLinAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, q) t = Variable() qol_objective = conic_form!(t, unique_conic_forms) diff --git a/src/atoms/second_order_cone/scaledgeomean.jl b/src/atoms/second_order_cone/scaledgeomean.jl index ce8b3b215..108aa251a 100644 --- a/src/atoms/second_order_cone/scaledgeomean.jl +++ b/src/atoms/second_order_cone/scaledgeomean.jl @@ -35,7 +35,7 @@ function evaluate(q::ScaledGeoMeanAtom) return prod(evaluate(q.children[1]))^(1/nbar) end -function conic_form!(q::ScaledGeoMeanAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(q::ScaledGeoMeanAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, q) t = Variable() qol_objective = conic_form!(t, unique_conic_forms) diff --git a/src/constant.jl b/src/constant.jl index 1d68e2aa6..2a0d3f992 100644 --- a/src/constant.jl +++ b/src/constant.jl @@ -60,7 +60,7 @@ imag_conic_form(x::Constant{<:AbstractVecOrMat{<:Complex}}) = im * vec(imag(x.va # value, which Julia can get via Core.arraylen for arrays and knows is 1 for scalars length(x::Constant) = length(x.value) -function conic_form!(x::Constant, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::Constant, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) #real_Value = real_conic_form(x) #imag_Value = imag_conic_form(x) diff --git a/src/constraints/constraints.jl b/src/constraints/constraints.jl index 304e1fee5..ef3f20400 100644 --- a/src/constraints/constraints.jl +++ b/src/constraints/constraints.jl @@ -33,7 +33,7 @@ function vexity(c::EqConstraint) return vex end -function conic_form!(c::EqConstraint, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(c::EqConstraint, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, c) if !(sign(c.lhs) == ComplexSign() || sign(c.rhs) == ComplexSign()) @@ -93,7 +93,7 @@ function vexity(c::LtConstraint) return vex end -function conic_form!(c::LtConstraint, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(c::LtConstraint, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, c) expr = c.rhs - c.lhs objective = conic_form!(expr, unique_conic_forms) @@ -145,7 +145,7 @@ function vexity(c::GtConstraint) return vex end -function conic_form!(c::GtConstraint, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(c::GtConstraint, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, c) expr = c.lhs - c.rhs objective = conic_form!(expr, unique_conic_forms) diff --git a/src/constraints/exp_constraints.jl b/src/constraints/exp_constraints.jl index f6c24c378..119eea1c3 100644 --- a/src/constraints/exp_constraints.jl +++ b/src/constraints/exp_constraints.jl @@ -37,7 +37,7 @@ function vexity(c::ExpConstraint) return ConvexVexity() end -function conic_form!(c::ExpConstraint, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(c::ExpConstraint, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, c) conic_constrs = ConicConstr[] if c.size == (1, 1) diff --git a/src/constraints/sdp_constraints.jl b/src/constraints/sdp_constraints.jl index 5613bbd8d..62218cb8a 100644 --- a/src/constraints/sdp_constraints.jl +++ b/src/constraints/sdp_constraints.jl @@ -36,7 +36,7 @@ end # so we need the lower triangular part (n*(n+1)/2 entries) of c.child to be in the SDP cone # and we need the corresponding upper elements to match the lower elements, # which we enforce via equality constraints -function conic_form!(c::SDPConstraint, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(c::SDPConstraint, unique_conic_forms::UniqueConicForms) # TODO: # 1) propagate dual values # 2) presolve to eliminate (many) variables --- variables on upper triangular part often don't matter at all diff --git a/src/constraints/soc_constraints.jl b/src/constraints/soc_constraints.jl index 18bd70ea6..ce98b2f00 100644 --- a/src/constraints/soc_constraints.jl +++ b/src/constraints/soc_constraints.jl @@ -16,7 +16,7 @@ struct SOCConstraint <: Constraint end end -function conic_form!(c::SOCConstraint, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(c::SOCConstraint, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, c) objectives = Vector{ConicObj}(undef, length(c.children)) @inbounds for iobj = 1:length(c.children) @@ -43,7 +43,7 @@ struct SOCElemConstraint <: Constraint end end -function conic_form!(c::SOCElemConstraint, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(c::SOCElemConstraint, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, c) num_constrs = length(c.children[1]) num_children = length(c.children) diff --git a/src/problems.jl b/src/problems.jl index 3e5bf81ec..dabddf90e 100644 --- a/src/problems.jl +++ b/src/problems.jl @@ -97,7 +97,7 @@ function vexity(p::Problem) return problem_vex end -function conic_form!(p::Problem, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(p::Problem, unique_conic_forms::UniqueConicForms) objective_var = Variable() objective = conic_form!(objective_var, unique_conic_forms) conic_form!(p.objective - objective_var == 0, unique_conic_forms) diff --git a/src/variable_conic_form.jl b/src/variable_conic_form.jl index e14c7db34..cc8a58401 100644 --- a/src/variable_conic_form.jl +++ b/src/variable_conic_form.jl @@ -1,4 +1,4 @@ -function conic_form!(x::Variable, unique_conic_forms::UniqueConicForms=UniqueConicForms()) +function conic_form!(x::Variable, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) add_to_id_to_variables!(unique_conic_forms, x) if vexity(x) == ConstVexity() @@ -23,4 +23,4 @@ function conic_form!(x::Variable, unique_conic_forms::UniqueConicForms=UniqueCon end end return get_conic_form(unique_conic_forms, x) -end \ No newline at end of file +end