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

Speculative: MathOptInterface 2.0 #2180

Open
odow opened this issue May 29, 2023 · 1 comment
Open

Speculative: MathOptInterface 2.0 #2180

odow opened this issue May 29, 2023 · 1 comment
Milestone

Comments

@odow
Copy link
Member

odow commented May 29, 2023

The purpose of this issue is to track things that we could consider changing if we release MathOptInterface v2.0. To be clear for readers, we currently have no plans to release MOI v2. This issue is just to make a note of things so we don't forget them.

Even if we do release MOI v2, we might not implement every item on this list. They're just up for discussion at some point in the process.

[Major] Make all variables belong to a set

We currently have add_variable and add_constrained_variable, and it's complicated to work out how to add a variable when copying to a new solver. Every variable should have a domain, defaulting to x in Reals(1), to distinguish constrained variables from variable-in-set constraints.

This should also help #1993, because a solver might support an attribute for variable-in-set but not constrained-variable (or vice versa).

It would also help #1402 because we'd know the set of each variable when writing a CBF file.

[Major] Remove the 0.5 in QuadraticFunction

The 0.5 factor in ScalarQuadraticFunction and VectorQuadraticFunction is a pain. It makes manually constructing functions error-prone, and writing interfaces is a guess/check of do I need a 2 or a 0.5 factor in front of the diagonals. If Vector{ScalarQuadraticTerm} was literally just a list of terms and not a sparse representation of Q, then we could shift the complexity into the solvers who would know whether they needed the factor.

Examples of bugs because of this: #2182

[Major] reconsider function structure

x-ref #863

[Major] reconsider vector funnctions

As discussed on today's (2023-06-15) nonlinear call, why not just make

struct VectorFunction{F<:AbstractScalarFunction} <: AbstractVectorFunction
    rows::Vector{F}
end

The only special case are VectorAffineFunction and VectorQuadraticFunction, and their structure doesn't add much at present, besides complexity.

[Major] make all indices unique and non-decreasing

x-ref #2236

Currently different constraint types are allowed to use same index values, which means we don't know the order in which constraints were added. Having a unique non-decreasing index would allow us to copy constraints by creation order , or by groups of similar constraints.

[Minor] Remove NLPBlock

We should entirely remove NLPBlock and use ScalarNonlinearFunction instead.

[Minor] Restrict supports for bridges

Bridges are too permissive: #2179 (comment).

For example, VectorizeBridge supports any scalar function:

function MOI.supports_constraint(
::Type{VectorizeBridge{T}},
::Type{<:MOI.AbstractScalarFunction},
::Type{<:MOI.Utilities.ScalarLinearSet{T}},
) where {T}
return true
end

but this can't be true unless each scalar function has an equivalent vector function. Currently, new scalar functions will trigger a method error for this operate(vcat, ...):
H = MOI.Utilities.promote_operation(-, T, G, T)
F = MOI.Utilities.promote_operation(vcat, T, H)

[Minor] Remove this method

# TODO(odow): remove this?
function add_constraint(
model::ModelLike,
v::Vector{VariableIndex},
set::AbstractVectorSet,
)
return add_constraint(model, VectorOfVariables(v), set)
end

[Minor] Rename Utilities.operate! to Utilities.operate!!

x-ref #2207

[Minor] remove various deprecated methods

"""
operate_terms!(op::Function, args...)
Compute `op(args...)`, where at least one element of `args` is a vector of
[`MOI.ScalarAffineTerm`](@ref), [`MOI.ScalarQuadraticTerm`](@ref),
[`MOI.VectorAffineTerm`](@ref), or [`MOI.VectorQuadraticTerm`](@ref).
!!! warning
This method is deprecated and may be removed in MathOptInterface v2.0.
## Methods
1. `-`
a. `operate_term(::typeof(-), ::Vector{<:ScalarTerm})`
"""
function operate_terms!(
::typeof(-),
terms::Vector{<:Union{MOI.ScalarAffineTerm,MOI.ScalarQuadraticTerm}},
)
map!(Base.Fix1(operate_term, -), terms, terms)
return terms
end

"""
operate_coefficient(
op::Function,
f::Union{
MOI.ScalarAffineTerm,
MOI.ScalarQuadraticTerm,
MOI.VectorAffineTerm,
MOI.VectorQuadraticTerm,
},
)
Return a new term, which is the result of calling `op(coefficient)` for on the
coefficient of the term `f`.
!!! warning
This method is deprecated and may be removed in MathOptInterface v2.0. Use
`operate_term(op, f)` instead.
"""
operate_coefficient(op::F, f) where {F} = operate_term(op, f)

"""
eval_term(value_fn::Function, t)
!!! warning
This method is deprecated any may be removed in MathOptInterface v2.0. Use
`eval_variables` instead.
"""
eval_term(value_fn::Function, t) = eval_variables(value_fn, t)
"""
constant_vector(f)
!!! warning
This method is deprecated and may be removed in MathOptInterface v2.0.
"""
function constant_vector(
f::Union{MOI.ScalarAffineFunction,MOI.ScalarQuadraticFunction},
)
return [f.constant]
end
function constant_vector(
f::Union{MOI.VectorAffineFunction,MOI.VectorQuadraticFunction},
)
return f.constants
end

[Minor] Change substitute_variables

#2250

[Minor] Fix default values of attributes

get for attributes like TimeLimitSec could return the solver's default if unset. The nothing business is confusing.

[Minor] Fix test naming

Fix inconsistent naming of tests like _infeasible_ or _INFEASIBLE_

@blegat
Copy link
Member

blegat commented Dec 12, 2023

Another breaking change to make, some tests are called infeasible and some INFEASIBLE, that should be unified.

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

2 participants