Add set for low-rank constrained SDP
Closes https://github.com/jump-dev/MathOptInterface.jl/issues/2197
Note that once this is done, you can write an SDP in SDPA format directly in JuMP with something like
C = rand(d, d)
A = [rand(d, d) for i in 1:m]
model = Model()
@variable(model, x[1:m+1] in MOI.SetWithDotProducts(
MOI.PositiveSemidefiniteConeTriangle(d),
MOI.TriangleVectorization.([A; [C]]),
))
@constraint(model, x[1:m] == b)
@objective(model, Min, x[end])
or
model = Model()
@variable(model, y[1:m])
@constraint(model, [y; -1] in MOI.LinearCombinationInSet([A; [C]]))
@objective(model, Max, dot(y, b))
And Dualization.dualize should take you from one to the other one!
Solvers implementing this:
- [ ]
Hypatia.LinMatrixIneqCone:A1PSD andA2, ..., A[m]arbitrary - [ ]
Hypatia.WSOSInterpNonnegativeCone:A = u u'(Rank-1 PSD) - [ ]
DSDP:A = a * u * u'(Rank-1) https://github.com/jump-dev/DSDP.jl/pull/37 - [ ]
SDPLR:A = U * Diagonal(d) * U'(Low-Rank) https://github.com/jump-dev/SDPLR.jl/pull/26
Basic
- [x] Add a new
AbstractScalarSetorAbstractVectorSettosrc/sets.jl - [ ] If
isbitstype(S) == false, implementBase.copy(set::S) - [ ] If
isbitstype(S) == false, implementBase.:(==)(x::S, y::S) - [x] If an
AbstractVectorSet, implementdimension(set::S), unless the dimension is given byset.dimension.
Utilities
- [x] If an
AbstractVectorSet, implementUtilities.set_dot, unless the dot product between two vectors in the set is equivalent toLinearAlgebra.dot - [ ] If an
AbstractVectorSet, implementUtilities.set_with_dimensioninsrc/Utilities/matrix_of_constraints.jl - [x] Add the set to the
@modelmacro at the bottom ofsrc/Utilities.model.jl
Documentation
- [ ] Add a docstring, which gives the mathematical definition of the set,
along with an
## Exampleblock containing ajldoctest - [x] Add the docstring to
docs/src/reference/standard_form.md - [x] Add the set to the relevant table in
docs/src/manual/standard_form.md
Tests
- [ ] Define a new
_set(::Type{S})method insrc/Test/test_basic_constraint.jland add the name of the set to the list at the bottom of that files - [ ] If the set has any checks in its constructor, add tests to
test/sets.jl
MathOptFormat
- [ ] Open an issue at
https://github.com/jump-dev/MathOptFormatto add support for the new set {{ replace with link to the issue }} I don't think we should add any set specialization of that set or at least not yet
Optional
- [x] Implement
dual_set(::S)anddual_set_type(::Type{S}) - [x] Add new tests to the
Testsubmodule exercising your new set - [ ] Add new bridges to convert your set into more commonly used sets
This is getting a little out of hand. PositiveSemidefiniteConeSquare, PositiveSemidefiniteConeTriangle, ScaledPositiveSemidefiniteConeTriangle, HermitianPositiveSemidefiniteConeTriangle...
Do we really need yet another PSD cone? Why isn't this just a solver enhancement where they detect and exploit low-rank structures in the general matrix? Because it's a constraint?
You're right, maybe this isn't really a PSD think, we could generalize it for any cone.
model = Model()
@variable(model, (AX[1:m], X[1:n, 1:n]) in ConeWithInnerProducts(A, PSDCone()))
@constraint(model, AX == b)
@objective(model, Min, dot(X, C))
and
model = Model()
@variable(model, y[1:m])
@constraint(model, (y, C) in AffineSpanInCone(A, PSDCone()))
@objective(model, Max, dot(y, b))
Why isn't this just a solver enhancement where they detect and exploit low-rank structures in the general matrix? Because it's a constraint?
That can be very expensive so it wouldn't be so useful in practice. It's also defeating the whole purpose of MOI of being able to transmit custom structure about the problem through JuMP. Even if we have an MOI meta solver that does that, it would need to define a new set to communicate the low-rank structure anyway.
Do you have a numerical example of what the A matrix would be?
Also, (y, C) in isn't going to work because we don't support tuples as arguments.
Also,
(y, C) inisn't going to work because we don't support tuples as arguments.
No, the JuMP syntax won't work, it's just to give an idea.
Other questions:
- Clarify low-rank property of the input data vs low-rank constraints on the output variables
- How can the set be serialized to MOF?
- What solvers support this?
What solvers support this?
I try to keep the list in https://github.com/jump-dev/MathOptInterface.jl/issues/2197
How can the set be serialized to MOF?
I think some special case might not be serializable but that's already the case for other parametrized sets like Scaled and Indicator. Same with MOI.Utililities.Model, we cannot aim to every every set there, other will be handled a bit less efficiently by UniversalFallback anyway, what's important there is to have the LP sets since LP solvers can handle millions of them
@mlubin's concern around the serialization wasn't parameterized sets, but if we allow
struct ConeWithInnerProducts{A<:AbstractMatrix,S<:AbstractVectorSet}
matrix::A
set::S
end
How would we serialize matrix::A to JSON if we don't know the matrix type?
We need to think about doing something like:
struct ConeWithInnerProducts{T,S<:AbstractVectorSet}
matrix::LinearAlgebra.LowerTriangular{Matrix{T}}
set::S
end
If we have your former example, what prevents serializing ConeWithInnerProducts{LinearAlgebra.LowerTriangular{Matrix{T}}} ?
Nothing. We could do that. But the point is that we'd need to pick the matrix type. We couldn't support arbitrary user-defined matrices.
But the point is that we'd need to pick the matrix type. We couldn't support arbitrary user-defined matrices.
Maybe we could only pick the matrix type for the purpose of MOF and MOI.Utilities.Model and leave it parametrized so as to allow additional flexibility for use cases that don't need writing to file and for which the performance of UniversalFallback is just fine. Of course, it will be easier to decide this once I have a few examples working :)
An additional point made by @mlubin that is worth writing down is that, for solvers supporting both low-rank solutions and low-rank constraints like SDPLR (and soon https://github.com/JuliaAlgebra/BMSOS.jl), you can start targeting SDP constraints ⟨A, X⟩ of size 1M of the rank of A and X is O(1). In that case, if A is low-rank but not sparse, communicating it in full and letting the solver do an SVD to recover the low-rank structure is not an option since the full A would have 10^12 entries.
This is probably best explored as a separate MOI extension. That would allow us making breaking releases while we explore the space of possible interfaces. I moved the code to https://github.com/blegat/LowRankOpt.jl. This PR now only contains the changes necessary to make in MOI for LowRankOpt to work.
Yes, I'll add some tests