-
Notifications
You must be signed in to change notification settings - Fork 87
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
Copy vector of variable before giving it to ScalarAffineFunction #67
Conversation
Mmm. This needs a discussion on whether solvers can modify input (JuliaOpt/MathProgBase.jl#43). I'd tend to say that we should ask solvers not to modify the input. |
Solvers should never modify input. Otherwise you might be in the position where Gurobi does, but Clp doesn't. That could lead to a change in behaviour just by changing the solver... |
Since MOI is low-level we can ask more cautiousness to the user to avoid unnecessary copy. |
Another point is that when loading a lot of linear constraints, users might want to re-use the same input vectors to avoid allocating new ones for each constraint. |
So that means that every time JuMP will add a constraint to |
Use case:
With the current implementation f has changed no? if yes then there isn't only a problem on the solver side but also on the user side if the function is pointing on the same vector that the user has provided. I agree with @odow that solvers should not modify input data. but if the user is planning to modify v after giving it to a function he should provide a copy to the function. In the case the user will not modify the vector then he can provide it without copying it. In C++ I would put the argument of the function as a reference on a const vector. EDIT |
I have update the PR into a less controversial change : I do not change |
How about modifying functions to use W̶r̶a̶p̶p̶e̶r̶s̶ ̶o̶f̶ Tuples instead of vectors? If I am not wrong, this way a modification will be possible but only through modifying the whole Tuple. |
The conversion from Vector to tuple is not type stable so it might be inefficient. |
But why would you use Vector if the functions are using Tuple? v = (x,y)
# create a function using that v
v = (v... , z)
# create another function using the new v This way the |
This would require JuMP to store his variables as an |
Tuples are not an appropriate replacement for arbitrary-length vectors. We could easily have an affine function with 1,000,000 coefficients:
|
We can make some optimizations between JuMP and its internal instance if needed. I don't think that should guide the interface design. I would propose that we view the vectors passed though MOI as temporary and belonging to the users, not to solvers. Solvers should not assume that the contents of the vectors will not change in the future. Users may assume that solvers will not modify the vectors. I believe we agree that solvers should not modify the input vectors because that creates a whole class of potential bugs. If we say that users cannot modify the input vectors after providing them to the solver, then we're removing the possibility of reusing the vectors later. I think the following is a pretty reasonable pattern for the user to do:
If we disallow the user to modify vectors afterwords, we have to create new |
The issue is that SOI's solvers, I store everything in MOIU's Why not having a performance hint (see #63) saying that the input vectors will not be modified by the user ? Most solvers would not care but since JuMP will set this hint, SOI's solvers will not do extra copies when called through JuMP. |
Is it really that inefficient? Could you quantify this? |
I will make me sleep bad when I think about it and I will not enjoy using these solvers for sum of squares thinking about the copies that are being done :D |
I mean quantify the actual performance penalty, not the psychological damage :) |
I'd like to see an example where this copying has a performance hit of greater than 5% of the solve time. |
If the constraints are given in a huge vector constraint then at the moment
of the copy there is twice more memory used than required and this might
cause failure.
Le 20 juil. 2017 23:38, "Miles Lubin" <[email protected]> a écrit :
… I'd like to see an example where this copying has a performance hit of
greater than 5% of the solve time.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#67 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA_-jUIL3-Lsa-O2EgEO-EnnlfBhG77hks5sP8i5gaJpZM4OdPCj>
.
|
By the way, JuMP may also use this performance hint with Instance. This
shows that this performance hint may be useful for users of Instance
Le 21 juil. 2017 00:00, "Benoît Legat" <[email protected]> a écrit :
… If the constraints are given in a huge vector constraint then at the
moment of the copy there is twice more memory used than required and this
might cause failure.
Le 20 juil. 2017 23:38, "Miles Lubin" ***@***.***> a écrit :
> I'd like to see an example where this copying has a performance hit of
> greater than 5% of the solve time.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#67 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AA_-jUIL3-Lsa-O2EgEO-EnnlfBhG77hks5sP8i5gaJpZM4OdPCj>
> .
>
|
There will also be a moment when the same amount of memory is used while the wrapper is copying the problem into the C interface, so wouldn't you have a failure at that point also? |
Closing since this will not be merged. The discussion for the performance hint remains open, e.g. JuliaOpt/MathOptInterfaceBridges.jl#2 |
We do
push!(v, z)
later so if we consider thatv
is owned by the function (since it does not copy), we need to copy before giving it