Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

WIP: updates for Julia 1.0 #1

Merged
merged 75 commits into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
dae6b61
Fix deprecations
femtocleaner[bot] Aug 28, 2017
c411386
Run Travis CI against Julia 0.6
omus Sep 5, 2017
88f2acb
Merge pull request #210 from invenia/cv/julia-0.6-ci
madeleineudell Sep 5, 2017
81bb81c
Merge pull request #212 from JuliaOpt/fbot/deps
madeleineudell Sep 7, 2017
017cd44
Fix minor typo in knapsack example
jayvn Nov 15, 2017
10ba398
Bump MPB bound
mlubin Nov 16, 2017
380e2ed
Merge pull request #216 from JuliaOpt/mlubin-patch-1
mlubin Nov 29, 2017
28f5da2
Merge pull request #215 from jayvn/patch-2
mlubin Jan 14, 2018
6854070
updated struct and type parameter syntax to julia 0.6 (#221)
matbesancon Jan 15, 2018
f39dd3c
Replace FactCheck (#222)
jw3126 Jan 27, 2018
0c18219
updated code to julia 1.0
Oct 22, 2018
d608a4a
little changes + ECOS is now the first tested Solver
Oct 23, 2018
b71e158
norm is imported
Oct 23, 2018
b20d8b3
norm is restored
Oct 23, 2018
0c45c8e
starting fixing tests
Oct 23, 2018
a597a6d
undefined arrays fixed
Oct 23, 2018
102905d
testing diag function
Oct 23, 2018
8e1611e
import Base./
Oct 23, 2018
4676fd0
iterate implemented + import functions from LinearAlgebra
Oct 23, 2018
bcb737d
many tests are fixed up to test_sdp.jl
Oct 23, 2018
8968d5d
fix diagm
Oct 23, 2018
86190bf
diagm fixed in tests
Oct 23, 2018
052b653
+(::Array{Float64,2}, ::Float64) fixed
Oct 23, 2018
463f1a1
+(x::Array{Float64,2}, y::Number) implemented
Oct 23, 2018
03ddbc1
diagm is fixed in sdp_constraints.jl
Oct 23, 2018
db4e0d5
fix norm function
Oct 23, 2018
f6acb31
assert is fixed in power_to_socp.jl
Oct 23, 2018
9ec145d
all assert issues fixed in power_to_socp.jl
Oct 23, 2018
a606595
cat function fixed in stack.jl
Oct 23, 2018
fc8847d
test_socp.jl fixed
Oct 23, 2018
9e165b4
test_params.jl fixed
Oct 23, 2018
1e9975d
fixes based on review
Oct 24, 2018
391b044
explicit solver is added to Problem function
Oct 24, 2018
7a73c1a
order of arguments changed in Problem function
Oct 24, 2018
e2ec38b
evaluate(x::AdditionAtom) fixed, starting rewriting tests
Oct 24, 2018
20b7607
evaluate(x::AdditionAtom) fixed
Oct 24, 2018
e705891
satisfy function is fixed
Oct 24, 2018
dd29204
ArgumentError implemented to diagm function
Oct 24, 2018
257ea87
fix! function is fixed
Oct 24, 2018
7602a3b
fix! fixed again
Oct 24, 2018
fe96c3a
diagandlowerpart in conic_form! function is fixed
Oct 24, 2018
0780404
hvcat implemented for types AbstractExpr & AbstractExprOrValue
Oct 24, 2018
1cf17ae
hvcat fixed
Oct 25, 2018
9a8481b
hvcat exported
Oct 25, 2018
987e62f
solver argument removed from Problem function
Oct 25, 2018
09bbca9
type Problem fixed
Oct 25, 2018
71b883a
argument order in function Problem restored
Oct 25, 2018
e37f341
eye functions fixed
Oct 25, 2018
3fc0024
trace => tr fixed
Oct 25, 2018
2e59c05
trace => tr fixed in tests
Oct 25, 2018
759305e
norm => opnorm fixed in operatornorm.jl
Oct 25, 2018
a61fb8d
fixing tests finished
Oct 25, 2018
f49bc5b
replacing Diagonal
Oct 25, 2018
0731560
reduce redundancy of hvcat
Oct 25, 2018
d916c12
stack.jl cleaned
Oct 25, 2018
945cc19
fix test failures due to random seed in test_lp.jl
Oct 25, 2018
c4c2eff
reducing conv threshold of SCSSolver to 1e-12
Oct 25, 2018
9529433
reducing conv threshold of SCSSolver to 1e-12
Oct 25, 2018
a1d20da
skip problematic max/min atom tests for SCS solver
Oct 26, 2018
56613e3
several changes based on second round of review
Oct 26, 2018
b7fbdb5
ctranspose => adjoint & CTransposeAtom => AdjointAtom
Oct 26, 2018
aa3df64
comment out hvcat
Oct 26, 2018
9cf3417
uncomment hvcat
Oct 26, 2018
f161227
trying to fix tests for SCS solver
Oct 26, 2018
698a1c2
tests for SCS solver fixed
Oct 26, 2018
46ed1dd
comment in add_subtract.jl added + deprecated.jl removed
Oct 29, 2018
8f59179
hcat/vcat/vect with Value arguments commented out
Oct 29, 2018
2003b0f
hcat uncommented
Oct 29, 2018
1a407d3
uncomment vcat
Oct 29, 2018
7ac6809
uncomment vect
Oct 29, 2018
53a75a3
test vect
Oct 29, 2018
f154342
test vcat
Oct 29, 2018
e1fec4c
stack.jl cleaned
Oct 29, 2018
a4e2def
dims=1 => dims=Val(1) for vcat and dim=2 => dims=Val(2) for hcat with
Oct 29, 2018
c258ce9
changes in index.jl & fixed mutable struct in power_to_socp.jl
Oct 29, 2018
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
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ os:
- linux
- osx
julia:
- 0.5
- 0.7
molet marked this conversation as resolved.
Show resolved Hide resolved
- 1.0
- nightly
notifications:
email: false
Expand All @@ -14,10 +15,6 @@ addons:
- liblapack-dev
- libgmp-dev
- libglpk-dev
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia -e 'Pkg.clone(pwd())'
- julia -e 'Pkg.test("Convex", coverage=true)'
after_success:
- julia -e 'Pkg.add("Coverage")'
- julia -e 'cd(Pkg.dir("Convex")); using Coverage; Coveralls.submit(process_folder())'
4 changes: 2 additions & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
julia 0.5
MathProgBase 0.5 0.7
julia 0.7
MathProgBase 0.7
DataStructures
Compat 0.24
2 changes: 1 addition & 1 deletion examples/antidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export antidiag, sign, monotonicity, curvature, evaluate, conic_form!

### Diagonal
### Represents the kth diagonal of an mxn matrix as a (min(m, n) - k) x 1 vector
type AntidiagAtom <: AbstractExpr
struct AntidiagAtom <: AbstractExpr
head::Symbol
id_hash::UInt64
children::Tuple{AbstractExpr}
Expand Down
4 changes: 2 additions & 2 deletions examples/binary_knapsack.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"w = [23; 31; 29; 44; 53; 38; 63; 85; 89; 82]\n",
"C = 165 \n",
"p = [92; 57; 49; 68; 60; 43; 67; 84; 87; 72];\n",
"n = length(weights)"
"n = length(w)"
],
"language": "python",
"metadata": {},
Expand Down Expand Up @@ -70,4 +70,4 @@
"metadata": {}
}
]
}
}
7 changes: 2 additions & 5 deletions src/Convex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ __precompile__()

module Convex
import DataStructures
importall Base.Operators
using LinearAlgebra
using SparseArrays
using Compat

global DEFAULT_SOLVER = nothing
Expand Down Expand Up @@ -49,9 +50,6 @@ include("atoms/lp_cone/min.jl")
include("atoms/lp_cone/sumlargest.jl")
include("atoms/lp_cone/dotsort.jl")




### SOC atoms
include("atoms/second_order_cone/norm.jl") # also includes some lp atoms
include("atoms/second_order_cone/norm2.jl")
Expand Down Expand Up @@ -83,7 +81,6 @@ include("atoms/exp_+_sdp_cone/logdet.jl")
### utilities
include("utilities/show.jl")
include("utilities/iteration.jl")
include("utilities/deprecated.jl")
include("utilities/broadcast.jl")

#Temporary workaround for memory leak (https://github.com/JuliaOpt/Convex.jl/issues/83)
Expand Down
7 changes: 4 additions & 3 deletions src/atoms/affine/add_subtract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export sign, curvature, monotonicity, evaluate

### Unary Negation

type NegateAtom <: AbstractExpr
struct NegateAtom <: AbstractExpr
head::Symbol
id_hash::UInt64
children::Tuple{AbstractExpr}
Expand Down Expand Up @@ -53,7 +53,7 @@ end


### Addition
type AdditionAtom <: AbstractExpr
struct AdditionAtom <: AbstractExpr
head::Symbol
id_hash::UInt64
children::Array{AbstractExpr, 1}
Expand Down Expand Up @@ -98,7 +98,8 @@ function curvature(x::AdditionAtom)
end

function evaluate(x::AdditionAtom)
return sum([evaluate(child) for child in x.children])
# broadcast function is used here instead of sum to support addition between scalars and arrays
return broadcast(+, map(evaluate, x.children)...)
molet marked this conversation as resolved.
Show resolved Hide resolved
end

function conic_form!(x::AdditionAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms())
Expand Down
2 changes: 1 addition & 1 deletion src/atoms/affine/conjugate.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Base.conj
export conj
export sign, curvature, monotonicity, evaluate, conic_form!
type ConjugateAtom <: AbstractExpr
struct ConjugateAtom <: AbstractExpr
head::Symbol
id_hash::UInt64
children::Tuple{AbstractExpr}
Expand Down
3 changes: 1 addition & 2 deletions src/atoms/affine/conv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Handles convolution between a constant vector and an expression vector.
#############################################################################

import Base.conv
export conv

function conv(x::Value, y::AbstractExpr)
Expand All @@ -19,4 +18,4 @@ function conv(x::Value, y::AbstractExpr)
return X*y
end

conv(x::AbstractExpr, y::Value) = conv(y, x)
conv(x::AbstractExpr, y::Value) = conv(y, x)
4 changes: 2 additions & 2 deletions src/atoms/affine/diag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
#############################################################################

# k >= min(num_cols, num_rows) || k <= -min(num_rows, num_cols)
import Base.diag
import LinearAlgebra.diag
export diag
#export sign, curvature, monotonicity, evaluate

### Diagonal
### Represents the kth diagonal of an mxn matrix as a (min(m, n) - k) x 1 vector

type DiagAtom <: AbstractExpr
struct DiagAtom <: AbstractExpr
head::Symbol
id_hash::UInt64
children::Tuple{AbstractExpr}
Expand Down
11 changes: 6 additions & 5 deletions src/atoms/affine/diagm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
# Please read expressions.jl first.
#############################################################################

import Base.diagm
export diagm
import LinearAlgebra.diagm, LinearAlgebra.Diagonal
export diagm, Diagonal

type DiagMatrixAtom <: AbstractExpr
struct DiagMatrixAtom <: AbstractExpr
head::Symbol
id_hash::UInt64
children::Tuple{AbstractExpr}
Expand All @@ -22,7 +22,7 @@ type DiagMatrixAtom <: AbstractExpr
elseif num_cols == 1
sz = num_rows
else
error("Only vectors are allowed for diagm. Did you mean to use diag?")
throw(ArgumentError("Only vectors are allowed for diagm/Diagonal. Did you mean to use diag?"))
end

children = (x, )
Expand All @@ -46,10 +46,11 @@ function curvature(x::DiagMatrixAtom)
end

function evaluate(x::DiagMatrixAtom)
return diagm(vec(evaluate(x.children[1])))
return Diagonal(vec(evaluate(x.children[1])))
end

diagm(x::AbstractExpr) = DiagMatrixAtom(x)
Diagonal(x::AbstractExpr) = diagm(x)

function conic_form!(x::DiagMatrixAtom, unique_conic_forms::UniqueConicForms=UniqueConicForms())
if !has_conic_form(unique_conic_forms, x)
Expand Down
2 changes: 1 addition & 1 deletion src/atoms/affine/dot.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Base.dot, Base.vecdot
import LinearAlgebra.dot
export vecdot, dot


Expand Down
16 changes: 8 additions & 8 deletions src/atoms/affine/index.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Base: getindex, to_index
export IndexAtom, getindex

@compat const ArrayOrNothing = Union{AbstractArray, Void}
const ArrayOrNothing = Union{AbstractArray, Nothing}

type IndexAtom <: AbstractExpr
struct IndexAtom <: AbstractExpr
head::Symbol
id_hash::UInt64
children::Tuple{AbstractExpr}
Expand Down Expand Up @@ -54,7 +54,7 @@ function conic_form!(x::IndexAtom, unique_conic_forms::UniqueConicForms=UniqueCo

if x.inds == nothing
sz = length(x.cols) * length(x.rows)
J = Array{Int}(sz)
J = Array{Int}(undef, sz)
k = 1

num_rows = x.children[1].size[1]
Expand All @@ -78,14 +78,14 @@ end

## API Definition begins

getindex{T <: Real}(x::AbstractExpr, rows::AbstractArray{T, 1}, cols::AbstractArray{T, 1}) = IndexAtom(x, rows, cols)
getindex{T <: Real}(x::AbstractExpr, inds::AbstractArray{T, 1}) = IndexAtom(x, inds)
getindex(x::AbstractExpr, rows::AbstractVector{T}, cols::AbstractVector{T}) where {T<:Real} = IndexAtom(x, rows, cols)
getindex(x::AbstractExpr, inds::AbstractVector{<:Real}) = IndexAtom(x, inds)
getindex(x::AbstractExpr, ind::Real) = getindex(x, ind:ind)
getindex(x::AbstractExpr, row::Real, col::Real) = getindex(x, row:row, col:col)
getindex{T <: Real}(x::AbstractExpr, row::Real, cols::AbstractArray{T, 1}) = getindex(x, row:row, cols)
getindex{T <: Real}(x::AbstractExpr, rows::AbstractArray{T, 1}, col::Real) = getindex(x, rows, col:col)
getindex(x::AbstractExpr, row::Real, cols::AbstractVector{<:Real}) = getindex(x, row:row, cols)
getindex(x::AbstractExpr, rows::AbstractVector{<:Real}, col::Real) = getindex(x, rows, col:col)
# XXX todo: speed test; there are lots of possible solutions for this
function getindex(x::AbstractExpr, I::AbstractArray{Bool,2})
function getindex(x::AbstractExpr, I::AbstractMatrix{Bool})
return [xi for (xi,ii) in zip(x,I) if ii]
end
function getindex(x::AbstractExpr, I::AbstractVector{Bool})
Expand Down
4 changes: 2 additions & 2 deletions src/atoms/affine/inner_product.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ export inner_product

function inner_product(x::AbstractExpr,y::AbstractExpr)
if x.size==y.size && x.size[1] == x.size[2]
return(real(trace(x'*y)))
return(real(tr(x'*y)))
else
error("Arguments must be square matrix of same dimension")
end
end

inner_product(x::Value, y::AbstractExpr) = inner_product(Constant(x),y)
inner_product(x::AbstractExpr, y::Value) = inner_product(x,Constant(y))
inner_product(x::AbstractExpr, y::Value) = inner_product(x,Constant(y))
14 changes: 7 additions & 7 deletions src/atoms/affine/multiply_divide.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export sign, monotonicity, curvature, evaluate, conic_form!

### Scalar and matrix multiplication

type MultiplyAtom <: AbstractExpr
struct MultiplyAtom <: AbstractExpr
head::Symbol
id_hash::UInt64
children::Tuple{AbstractExpr, AbstractExpr}
Expand Down Expand Up @@ -83,11 +83,11 @@ function conic_form!(x::MultiplyAtom, unique_conic_forms::UniqueConicForms=Uniqu
# left matrix multiplication
elseif x.children[1].head == :constant
objective = conic_form!(x.children[2], unique_conic_forms)
objective = kron(speye(x.size[2]), x.children[1].value) * objective
objective = kron(sparse(1.0I, x.size[2], x.size[2]), x.children[1].value) * objective
# right matrix multiplication
else
objective = conic_form!(x.children[1], unique_conic_forms)
objective = kron(x.children[2].value', speye(x.size[1])) * objective
objective = kron(x.children[2].value', sparse(1.0I, x.size[1], x.size[1])) * objective
end
cache_conic_form!(unique_conic_forms, x, objective)
end
Expand All @@ -103,12 +103,12 @@ end

*(x::Value, y::AbstractExpr) = MultiplyAtom(Constant(x), y)
*(x::AbstractExpr, y::Value) = MultiplyAtom(x, Constant(y))
/(x::AbstractExpr, y::Value) = MultiplyAtom(x, Constant(1./y))
/(x::AbstractExpr, y::Value) = MultiplyAtom(x, Constant(1 ./ y))

### .*
# All constructors of this check (and so this function requires)
# that the first child be constant to have the expression be DCP
type DotMultiplyAtom <: AbstractExpr
struct DotMultiplyAtom <: AbstractExpr
head::Symbol
id_hash::UInt64
children::Tuple{AbstractExpr, AbstractExpr}
Expand Down Expand Up @@ -171,7 +171,7 @@ function conic_form!(x::DotMultiplyAtom, unique_conic_forms::UniqueConicForms=Un
var = var*ones(1,size(coeff,1))
end

const_multiplier = spdiagm(vec(coeff)) # used to be spdiagm((vec(coeff),), (0,)), not sure why
const_multiplier = spdiagm(0 => vec(coeff))
objective = const_multiplier * conic_form!(var, unique_conic_forms)
cache_conic_form!(unique_conic_forms, x, objective)
end
Expand Down Expand Up @@ -205,5 +205,5 @@ function broadcast(::typeof(*), x::AbstractExpr, y::AbstractExpr)
end
broadcast(::typeof(*), x::Value, y::AbstractExpr) = DotMultiplyAtom(Constant(x), y)
broadcast(::typeof(*), x::AbstractExpr, y::Value) = DotMultiplyAtom(Constant(y), x)
broadcast(::typeof(/), x::AbstractExpr, y::Value) = DotMultiplyAtom(Constant(1./y), x)
broadcast(::typeof(/), x::AbstractExpr, y::Value) = DotMultiplyAtom(Constant(1 ./ y), x)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe instead of overloading Base.broadcast directly, we're now supposed to go through a different set of machinery laid out in https://docs.julialang.org/en/v1/manual/interfaces/#man-interfaces-broadcasting-1. For now this is probably okay, since it does technically work to do it this way, but I can look into reworking this later.

# x ./ y and x / y for x constant, y variable is defined in second_order_cone.qol_elemwise.jl
24 changes: 12 additions & 12 deletions src/atoms/affine/partialtrace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Base.sign
export partialtrace
export sign, curvature, monotonicity, evaluate

type PartialTraceAtom <: AbstractExpr
struct PartialTraceAtom <: AbstractExpr
head::Symbol
id_hash::UInt64
children::Tuple{AbstractExpr}
Expand Down Expand Up @@ -44,8 +44,8 @@ function evaluate(x::PartialTraceAtom)

subsystem = function(sys)
function term(ρ, j::Int)
a = speye(1)
b = speye(1)
a = sparse(1.0I, 1, 1)
b = sparse(1.0I, 1, 1)
i_sys = 1
for dim in dims
if i_sys == sys
Expand All @@ -55,8 +55,8 @@ function evaluate(x::PartialTraceAtom)
a = kron(a, v')
b = kron(b, v)
else
a = kron(a, speye(dim))
b = kron(b, speye(dim))
a = kron(a, sparse(1.0I, dim, dim))
b = kron(b, sparse(1.0I, dim, dim))
end
i_sys += 1
end
Expand All @@ -65,15 +65,15 @@ function evaluate(x::PartialTraceAtom)
return sum([term(ρ, j) for j in 1:dims[sys]])
end
sub_systems = [subsystem(i) for i in 1:length(dims)]
a = eye(1)
a = Matrix(1.0I, 1, 1)
for i in 1:length(dims)
if i == x.sys
continue
else
a = kron(a,sub_systems[i])
end
end
return trace(sub_systems[x.sys])*a
return tr(sub_systems[x.sys])*a
end


Expand All @@ -87,8 +87,8 @@ function conic_form!(x::PartialTraceAtom, unique_conic_forms::UniqueConicForms=U
# in the system we want to trace out
# This function returns every term in the sum
function term(ρ, j::Int)
a = speye(1)
b = speye(1)
a = sparse(1.0I, 1, 1)
b = sparse(1.0I, 1, 1)
i_sys = 1
for dim in dims
if i_sys == sys
Expand All @@ -98,8 +98,8 @@ function conic_form!(x::PartialTraceAtom, unique_conic_forms::UniqueConicForms=U
a = kron(a, v')
b = kron(b, v)
else
a = kron(a, speye(dim))
b = kron(b, speye(dim))
a = kron(a, sparse(1.0I, dim, dim))
b = kron(b, sparse(1.0I, dim, dim))
end
i_sys += 1
end
Expand All @@ -113,4 +113,4 @@ function conic_form!(x::PartialTraceAtom, unique_conic_forms::UniqueConicForms=U
return get_conic_form(unique_conic_forms, x)
end

partialtrace(x::AbstractExpr, sys::Int, dim::Vector) = PartialTraceAtom(x, sys, dim)
partialtrace(x::AbstractExpr, sys::Int, dim::Vector) = PartialTraceAtom(x, sys, dim)
4 changes: 2 additions & 2 deletions src/atoms/affine/real_imag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export sign, monotonicity, curvature, evaluate


### Real
type RealAtom <: AbstractExpr
struct RealAtom <: AbstractExpr
head::Symbol
id_hash::UInt64
children::Tuple{AbstractExpr}
Expand Down Expand Up @@ -65,7 +65,7 @@ real(x::Value) = RealAtom(Constant(x))


### Imaginary
type ImaginaryAtom <: AbstractExpr
struct ImaginaryAtom <: AbstractExpr
head::Symbol
id_hash::UInt64
children::Tuple{AbstractExpr}
Expand Down
Loading