-
-
Notifications
You must be signed in to change notification settings - Fork 401
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
Add documentation on performance and work-around for sparse variable creation #2126
Conversation
docs/src/variables.md
Outdated
@@ -387,6 +387,12 @@ JuMP.Containers.SparseAxisArray{VariableRef,1,Tuple{Int64}} with 2 entries: | |||
[2] = x[2] | |||
``` | |||
|
|||
Note that with many indices and large amount of sparcity, variable construction may take more time than expected, as JuMP is effectively iterating over all indices and evaluating the conditional for each combination. The recommended work-around in such cases is to work directly with a list of tuples. For example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sparcity -> sparsity
docs/src/variables.md
Outdated
|
||
```jldoctest; setup=:(model=Model()) | ||
S = [(1,1,1),(10,10,10)] | ||
@variable(model, x[S]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you make an example with both approach and then show that e.g. one has quadratic complexity and the other one has linear complexity? For instance with a condition i == j and n elements for i and j, it will be quadratic complexity vs linear complexity
docs/src/variables.md
Outdated
@@ -387,6 +387,12 @@ JuMP.Containers.SparseAxisArray{VariableRef,1,Tuple{Int64}} with 2 entries: | |||
[2] = x[2] | |||
``` | |||
|
|||
Note that with many indices and large amount of sparcity, variable construction may take more time than expected, as JuMP is effectively iterating over all indices and evaluating the conditional for each combination. The recommended work-around in such cases is to work directly with a list of tuples. For example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow the 80-character limit used in the rest of the documentation.
docs/src/variables.md
Outdated
@@ -387,6 +387,12 @@ JuMP.Containers.SparseAxisArray{VariableRef,1,Tuple{Int64}} with 2 entries: | |||
[2] = x[2] | |||
``` | |||
|
|||
Note that with many indices and large amount of sparcity, variable construction may take more time than expected, as JuMP is effectively iterating over all indices and evaluating the conditional for each combination. The recommended work-around in such cases is to work directly with a list of tuples. For example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"is effectively iterating" is unnecessarily imprecise, just "iterates"
Codecov Report
@@ Coverage Diff @@
## master #2126 +/- ##
=======================================
Coverage 91.08% 91.08%
=======================================
Files 41 41
Lines 4376 4376
=======================================
Hits 3986 3986
Misses 390 390
Continue to review full report at Codecov.
|
I don't want to merge this until we have a green light on the documentation build. |
@hellemo can you rebase against master ? |
Add note on possible performance implications and suggested work-around following the discussion here:
https://discourse.julialang.org/t/working-efficiently-with-sparse-variables-in-jump/32240