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

AbstractVector for list of terms in functions #525

Closed
blegat opened this issue Sep 20, 2018 · 4 comments
Closed

AbstractVector for list of terms in functions #525

blegat opened this issue Sep 20, 2018 · 4 comments

Comments

@blegat
Copy link
Member

blegat commented Sep 20, 2018

The functions currently enforces the list of terms to be a Vector, e.g.

mutable struct ScalarAffineFunction{T} <: AbstractScalarFunction
    terms::Vector{ScalarAffineTerm{T}}
    constant::T
end

However, the fact that it is a Vector and not any AbstractVector does not help the solver wrappers in any way. Before we add the term types and we had different field for the coefficients and variables, we could have solver wrappers that pass directly the coefficient vector by pointer to the C-interface but won't do that anymore. It will need to iterate through the vector to do some transformation anyway so I suspect that if we change this to AbstractVector, it won't require any change from the solver wrappers.

The tricky point to discuss is how to update the MOIU model. We have a few choices:

  1. Store only function with Vector terms and collect the terms if a function is passed with AbstractVector
  2. Store a vector of an non-concrete type not specifying which type of vector is it allowing to store function using different types of vectors
  3. Allow either 1) and 2) or even more by simply taking what is in the macro call. For instance if we have ScalarAffineFunction{T, VT <: AbstractVector{T}}, we could define const StandardScalarAffineFunction{T} = ScalarAffineFunction{T, Vector{T}} and use @model ... (StandardScalarAffineFunction, ...) ... to do 1) and do @model ... (ScalarAffineFunction, ...) ... to do 2).

What do you think ?

The advantages of using AbstractVector instead of Vector are numerous:

This was referenced Sep 20, 2018
@mlubin
Copy link
Member

mlubin commented Sep 21, 2018

Using non-concrete vector types may cause a performance hit, not to mention significant code design and readability implications.

For performance, we need to have a comprehensive benchmark suite before making a change like this.

GPU support

I don't understand this use case. Why would you need a ScalarAffineFunction with the vector terms stored on a GPU?

Use views in function iterators

The iterators could also be redesigned to return a hypothetical ScalarAffineFunctionView.

Use StructOfArrays

I didn't understand the linked comment. I, for one, would be pretty unhappy as a solver wrapper author if users are allowed to provide input using arbitrary data structures. It pushes a lot of complexity into the solver interfaces that really shouldn't be needed. I wouldn't want users complaining to me that there's a bug in the solver wrapper because it doesn't handle SomeWeirdArray. The basic problem representation in MOI needs to be as concrete and as simple as possible if we want MOI to have any potential of becoming a standard (see also MathOptFormat). </end rant>

Implement lazy_operate

This argument needs benchmarks to be convincing.

I should also note that I'm not going to consider nonessential breaking changes in MOI until after JuMP 0.19 is close to being ready to release. Every MOI version bump at this stage seems to translate into a ~1 month delay on the JuMP 0.19 release.

@blegat
Copy link
Member Author

blegat commented Sep 21, 2018

I don't understand this use case. Why would you need a ScalarAffineFunction with the vector terms stored on a GPU?

cc @mohamed82008

It pushes a lot of complexity into the solver interfaces that really shouldn't be needed.

The solver interface only uses the AbstractVector interface so the solver interface code shouldn't need any change

I should also note that I'm not going to consider nonessential breaking changes in MOI until after JuMP 0.19 is close to being ready to release.

I totally agree with this, we should add a breaking label for breaking changes

@odow
Copy link
Member

odow commented Apr 30, 2021

We discussed this on April's developer call. This can be implemented in a non-breaking future release by introducing a new function type, and having something like const ScalarAffineFunction{T} = GenericScalarAffineFunction{Vector{T},T}.

Removing from 0.10 milestone and breaking.

@odow odow removed this from the v0.10 milestone Apr 30, 2021
@odow odow removed the breaking label Apr 30, 2021
@odow
Copy link
Member

odow commented Aug 12, 2021

Closing in favor of #863 We should consider things holistically if we're going to redesign the functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants