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

Container revamp #1102

Merged
merged 4 commits into from
Sep 20, 2017
Merged

Container revamp #1102

merged 4 commits into from
Sep 20, 2017

Conversation

mlubin
Copy link
Member

@mlubin mlubin commented Sep 16, 2017

Replace JuMPDict with Dict. Rewrite JuMPArray to be compatible with AbstractArray. Explicit keyword argument in macro to force container type.

Unfortunately we can't use AxisArrays at the moment because of JuliaArrays/AxisArrays.jl#117. I'm hoping that we can swap AxisArray for JuMPArray before JuMP 1.0/0.19, but for now I'd like to go ahead with this since the basic functionality is there. If we keep JuMPArray, it will need to be polished and performance-tested before the next release.

Broadcast is implemented for JuMPArray, so we can just do resultvalue.(A) when A is an Array or a JuMPArray (but not when it's a Dict).

See commit for list of 11 issues that this PR closes (once merged into master).

Remaining to do for merge:

@codecov
Copy link

codecov bot commented Sep 17, 2017

Codecov Report

Merging #1102 into jump/moi will increase coverage by 0.7%.
The diff coverage is 74.82%.

Impacted file tree graph

@@             Coverage Diff             @@
##           jump/moi    #1102     +/-   ##
===========================================
+ Coverage     21.46%   22.17%   +0.7%     
===========================================
  Files            20       20             
  Lines          3647     3571     -76     
===========================================
+ Hits            783      792      +9     
+ Misses         2864     2779     -85
Impacted Files Coverage Δ
src/operators.jl 9.42% <ø> (+0.45%) ⬆️
src/JuMP.jl 59.18% <ø> (+6.5%) ⬆️
src/print.jl 47.72% <ø> (ø) ⬆️
src/JuMPArray.jl 65.55% <65.16%> (-14.45%) ⬇️
src/macros.jl 74.2% <78.94%> (-1.14%) ⬇️
src/containers.jl 97.14% <97.14%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 76b3430...497083b. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 17, 2017

Codecov Report

Merging #1102 into jump/moi will increase coverage by 1%.
The diff coverage is 78.1%.

Impacted file tree graph

@@            Coverage Diff            @@
##           jump/moi    #1102   +/-   ##
=========================================
+ Coverage     21.46%   22.47%   +1%     
=========================================
  Files            20       20           
  Lines          3647     3578   -69     
=========================================
+ Hits            783      804   +21     
+ Misses         2864     2774   -90
Impacted Files Coverage Δ
src/print.jl 47.72% <ø> (ø) ⬆️
src/operators.jl 9.42% <ø> (+0.45%) ⬆️
src/JuMP.jl 59.18% <ø> (+6.5%) ⬆️
src/JuMPArray.jl 66.66% <66.3%> (-13.34%) ⬇️
src/macros.jl 75.56% <88.09%> (+0.23%) ⬆️
src/containers.jl 97.14% <97.14%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 76b3430...095c030. Read the comment docs.

Replace JuMPDict with Dict. Rewrite JuMPArray to be compatible with
AbstractArray. Explicit keyword argument in macro to force container
type.

Closes #1099
Closes #1047
Closes #417 (collect is now well defined for Array, JuMPArray, and Dict)
Closes #833 (`eachindex` and `indices` are defined for JuMPArray)
Closes #740 (dot broadcast syntax is now the default, no need to explicitly define vectorized functions)
Closes #922 (fixed by checking for duplicates)
Closes #933 (corollary: closes #346)
Closes #643 (colons work for Array and JuMPArray, obviously not Dict)
Closes #730 (end is not supported for JuMPArray)
Closes #646 (we now rely on built-in iteration behavior for Dict)
@mlubin
Copy link
Member Author

mlubin commented Sep 19, 2017

I plan on adding some more tests but otherwise this is ready for review. Note that it closes 11 issues.

@mlubin mlubin changed the title WIP: Container revamp Container revamp Sep 19, 2017
Copy link
Contributor

@joehuchette joehuchette left a comment

Choose a reason for hiding this comment

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

Looks good to me. Do you have a sense of the performance relative to the current implementation?

src/JuMPArray.jl Outdated
struct JuMPArray{T,N,Ax} <: AbstractArray{T,N}
data::Array{T,N}
axes::Ax
lookup::Vector{Dict} # TODO: correctly type return type of the Dict as Int
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this TODO out of scope for this PR?

src/JuMPArray.jl Outdated
# AbstractArray interface

Base.linearindices(A::JuMPArray) = error("JuMPArray does not support this operation.")
Base.size(A::JuMPArray) = error("JuMPArray does not define this operation")
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like this might something users could reasonably expect to work

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't define size for the old JuMPArray, and neither does OffsetArrays. Defining it causes end to return the wrong result.

3. Otherwise, generate an empty `Dict{Any,T}`.

The second element of the return tuple is a `Bool`, `true` if the container type
automatically checks for duplicate terms in the index sets and `false` otherwise.
Copy link
Contributor

Choose a reason for hiding this comment

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

Might it be simpler to add a autocheckforduplicates(::Symbol) function, rather than explicitly returning a boolean?

Copy link
Member Author

Choose a reason for hiding this comment

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

The issue is that it depends on the processing of indexvars and indexsets (hasdependentsets). I agree that this solution isn't too tidy though.

@mlubin
Copy link
Member Author

mlubin commented Sep 20, 2017

Do you have a sense of the performance relative to the current implementation?

There's no reason to benchmark JuMPArray right now because it will just be slow. When rewritten with generated functions it should have similar performance, except no special handling for interval sets (but this could be added transparently without breaking the API).

@joehuchette
Copy link
Contributor

OK. What's the roadmap then with this PR, generated functions, and AxisArrays?

@mlubin
Copy link
Member Author

mlubin commented Sep 20, 2017

What's the roadmap then with this PR, generated functions, and AxisArrays?

I'd like to merge this PR soon and get back to MOI work. When MOI is close to being wrapped up we can revisit and see if AxisArrays has implemented the functionality we need or if we need to tidy up JuMPArray.

@mlubin mlubin merged commit 9466fe9 into jump/moi Sep 20, 2017
@mlubin mlubin deleted the ml/containers2 branch September 20, 2017 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants