You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be handy in some cases to have a second implementation of copy_to that adds variables (and constraints) in the order of increasing index instead of constrained and then free.
That way one can get rid of the index_map. Concretely, I'm working on non-linear on top of MOI with a function f(x) that takes the vector of variables in order of variable index. When copying the model, this would be handy to keep the same order to avoid having to call f(permutation_matrix * x) all the time
I agree, when there is an NLP block then we simply disable constrained variables.
For JuliaManifolds/Manopt.jl#273, we would need to maintain the order of variables but still use constrained variables.
So I think we should, if any part of the model is a black-box function, add constrained variables but without reordering.
We could also do like MIP callbacks and have a variable attribute to get the values so that it goes through the index map but for it to be efficient enough for NLP we might need the CleverDictt o have a special case when the order is the same
We probably want to stop adding keyword arguments to copy_to since we removed them all for MOI v1.
Probably we can query MOI.get(src, SupportsVariableReordering()) which falls back to checking if all attributes and constraint types support it.
This actually hints at a deeper problem: the order of MOI constraints in a copy is not the same between solvers. One places this crops up is writing files like MPS. Most copies end up grouping by constraint type and then construction order, but I do wonder if there should instead be a global order of constraints. i.e., all ConstraintIndex must have a unique .value::Int64 field, not just unique within their constraint type. That's a MOI 2.0 problem though.
@blegat and I discussed this without much of a conclusion. Do we have a reproducible example of the current problem? Is it necessary to use a permutation matrix? Couldn't we just pass a (permuted) view of the vector to the function x?
Here's the bit where we disable constrained variables:
So maybe we do need a way for dest to opt-in to this. I think this is probably the only place where it matters? Because solver wrappers implementing copy_to have control over the order.
one solution would be a three-argument copy_to with default doing whatever the solver wants, and then other copy_to methods which add constraints, like keep variable / constraint order
Keeping constraint order would require a big change to MOI. We're really just not set up to record or communicate that information. (It'd likely mean requiring implementations to use a non-decreasing UUID for .value, and plenty of implementations (ab)use the value field for all sorts of things.
Can you point to a concrete example where this is necessary?
If you want indices to be from 1 to n you can use a MatrixOfConstraints. See Zaphod.jl for an example of how to use it
I'll do that as a temporary solution, but the fact that the order-preserving implementation is right there in copy-to without being accessible is a bit frustrating
Activity
blegat commentedon Jul 5, 2023
I agree, when there is an NLP block then we simply disable constrained variables.
For JuliaManifolds/Manopt.jl#273, we would need to maintain the order of variables but still use constrained variables.
So I think we should, if any part of the model is a black-box function, add constrained variables but without reordering.
We could also do like MIP callbacks and have a variable attribute to get the values so that it goes through the index map but for it to be efficient enough for NLP we might need the
CleverDictt o have a special case when the order is the samematbesancon commentedon Jul 5, 2023
we could add a keyword argument
always_maintain_variable_order=falsetodefault_copy_to, and then:blegat commentedon Jul 5, 2023
We probably want to stop adding keyword arguments to
copy_tosince we removed them all for MOI v1.Probably we can query
MOI.get(src, SupportsVariableReordering())which falls back to checking if all attributes and constraint types support it.matbesancon commentedon Jul 5, 2023
The problem is if you want to set that as the caller of
copy_to, and not at the Optimizer levelblegat commentedon Jul 5, 2023
The approach then is to use a layer like here:
MathOptInterface.jl/src/Utilities/copy.jl
Lines 512 to 643 in dab02e5
odow commentedon Jul 7, 2023
This actually hints at a deeper problem: the order of MOI constraints in a copy is not the same between solvers. One places this crops up is writing files like MPS. Most copies end up grouping by constraint type and then construction order, but I do wonder if there should instead be a global order of constraints. i.e., all
ConstraintIndexmust have a unique.value::Int64field, not just unique within their constraint type. That's a MOI 2.0 problem though.odow commentedon Aug 7, 2023
@blegat and I discussed this without much of a conclusion. Do we have a reproducible example of the current problem? Is it necessary to use a permutation matrix? Couldn't we just pass a (permuted) view of the vector to the function
x?Here's the bit where we disable constrained variables:
MathOptInterface.jl/src/Utilities/copy.jl
Lines 488 to 500 in a049bfe
So maybe we do need a way for
destto opt-in to this. I think this is probably the only place where it matters? Because solver wrappers implementingcopy_tohave control over the order.matbesancon commentedon Aug 7, 2023
one solution would be a three-argument
copy_towith default doing whatever the solver wants, and then othercopy_tomethods which add constraints, like keep variable / constraint orderodow commentedon Aug 8, 2023
Keeping constraint order would require a big change to MOI. We're really just not set up to record or communicate that information. (It'd likely mean requiring implementations to use a non-decreasing UUID for
.value, and plenty of implementations (ab)use the value field for all sorts of things.Can you point to a concrete example where this is necessary?
This line in Boscia is worrying:
https://github.com/ZIB-IOL/Boscia.jl/blob/f47ce9c0c93081de3dc468ef2648401cedfa73f8/src/interface.jl#L101-L103
Nothing in MOI guarantees that variable
.values should be contiguous or1ton.Can't you just work-around this with a permutation vector? Or ask your oracle to accept a
view?blegat commentedon Aug 8, 2023
If you want indices to be from 1 to n you can use a MatrixOfConstraints. See Zaphod.jl for an example of how to use it
odow commentedon Sep 12, 2023
I'd propose we close this. I don't think we need to add more complexity to MOI.
odow commentedon Sep 12, 2023
Maybe we could add all constraints required a shared non-decreasing UUID as one of the MOI 2.0 decisions.
Added to #2180
odow commentedon Sep 13, 2023
Thoughts @matbesancon?
matbesancon commentedon Sep 16, 2023
I'll do that as a temporary solution, but the fact that the order-preserving implementation is right there in copy-to without being accessible is a bit frustrating