Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Hypatia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const VI = MOI.VariableIndex
const SAF = MOI.ScalarAffineFunction
const VV = MOI.VectorOfVariables
const VAF = MOI.VectorAffineFunction
include("MathOptInterface/MOICones.jl")
include("MathOptInterface/cones.jl")
include("MathOptInterface/transform.jl")
include("MathOptInterface/wrapper.jl")
Expand Down
42 changes: 42 additions & 0 deletions src/MathOptInterface/MOICones.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module MOICones

import Hypatia.Cones: Cone
import MathOptInterface
const MOI = MathOptInterface

# This stopgap interface is used by the predefined cones in src/MathOptInterface/cones.jl
# until they are migrated to the MOIWrapper interface.
abstract type MOICone <: MOI.AbstractVectorSet end

function dimension(cone::MOICone)
return error("dimension($cone) not implemented")

Check warning on line 12 in src/MathOptInterface/MOICones.jl

View check run for this annotation

Codecov / codecov/patch

src/MathOptInterface/MOICones.jl#L11-L12

Added lines #L11 - L12 were not covered by tests
end

MOI.dimension(cone::MOICone) = dimension(cone)

Check warning on line 15 in src/MathOptInterface/MOICones.jl

View check run for this annotation

Codecov / codecov/patch

src/MathOptInterface/MOICones.jl#L15

Added line #L15 was not covered by tests

function cone_from_moi(::Type{<:Real}, cone::MOICone)
return error("cone_from_moi($cone) not implemented")

Check warning on line 18 in src/MathOptInterface/MOICones.jl

View check run for this annotation

Codecov / codecov/patch

src/MathOptInterface/MOICones.jl#L17-L18

Added lines #L17 - L18 were not covered by tests
end

# "Wrapper" for Hypatia cones to be used with MathOptInterface
struct MOIWrapper{T <:Real} <: MOICone
cone::Cone{T}

function MOIWrapper{T}(cone::Cone{T}) where {T <: Real}
return new{T}(cone)

Check warning on line 26 in src/MathOptInterface/MOICones.jl

View check run for this annotation

Codecov / codecov/patch

src/MathOptInterface/MOICones.jl#L25-L26

Added lines #L25 - L26 were not covered by tests
end
end

MOI.dimension(cone::MOIWrapper) = cone.cone.dim

Check warning on line 30 in src/MathOptInterface/MOICones.jl

View check run for this annotation

Codecov / codecov/patch

src/MathOptInterface/MOICones.jl#L30

Added line #L30 was not covered by tests

end

# "Re-export" functions for use in src/MathOptInterface/wrapper.jl
function cone_from_moi(t::Type{<:Real}, cone::MOICones.MOICone)
return MOICones.cone_from_moi(t, cone)

Check warning on line 36 in src/MathOptInterface/MOICones.jl

View check run for this annotation

Codecov / codecov/patch

src/MathOptInterface/MOICones.jl#L35-L36

Added lines #L35 - L36 were not covered by tests
end

# "Re-export" functions for use in src/MathOptInterface/wrapper.jl
function cone_from_moi(t::Type{<:Real}, cone::MOICones.MOIWrapper)
return cone.cone

Check warning on line 41 in src/MathOptInterface/MOICones.jl

View check run for this annotation

Codecov / codecov/patch

src/MathOptInterface/MOICones.jl#L40-L41

Added lines #L40 - L41 were not covered by tests
end
89 changes: 26 additions & 63 deletions src/MathOptInterface/cones.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@

$(TYPEDFIELDS)
"""
struct NonnegativeCone{T <: Real} <: MOI.AbstractVectorSet
struct NonnegativeCone{T <: Real} <: MOICones.MOICone
dim::Int
end
export NonnegativeCone
Expand All @@ -125,7 +125,7 @@

$(TYPEDFIELDS)
"""
struct PosSemidefTriCone{T <: Real, R <: RealOrComplex{T}} <: MOI.AbstractVectorSet
struct PosSemidefTriCone{T <: Real, R <: RealOrComplex{T}} <: MOICones.MOICone
dim::Int
end
export PosSemidefTriCone
Expand All @@ -146,7 +146,7 @@

$(TYPEDFIELDS)
"""
struct DoublyNonnegativeTriCone{T <: Real} <: MOI.AbstractVectorSet
struct DoublyNonnegativeTriCone{T <: Real} <: MOICones.MOICone
dim::Int
use_dual::Bool
end
Expand All @@ -173,7 +173,7 @@
I <: Cones.PSDSparseImpl,
T <: Real,
R <: RealOrComplex{T},
} <: MOI.AbstractVectorSet
} <: MOICones.MOICone
side::Int
row_idxs::Vector{Int}
col_idxs::Vector{Int}
Expand Down Expand Up @@ -220,7 +220,7 @@

$(TYPEDFIELDS)
"""
struct LinMatrixIneqCone{T <: Real} <: MOI.AbstractVectorSet
struct LinMatrixIneqCone{T <: Real} <: MOICones.MOICone
As::Vector
use_dual::Bool
end
Expand All @@ -241,7 +241,7 @@

$(TYPEDFIELDS)
"""
struct EpiNormInfCone{T <: Real, R <: RealOrComplex{T}} <: MOI.AbstractVectorSet
struct EpiNormInfCone{T <: Real, R <: RealOrComplex{T}} <: MOICones.MOICone
dim::Int
use_dual::Bool
end
Expand All @@ -267,7 +267,7 @@

$(TYPEDFIELDS)
"""
struct EpiNormEuclCone{T <: Real} <: MOI.AbstractVectorSet
struct EpiNormEuclCone{T <: Real} <: MOICones.MOICone
dim::Int
end
export EpiNormEuclCone
Expand All @@ -285,7 +285,7 @@

$(TYPEDFIELDS)
"""
struct EpiPerSquareCone{T <: Real} <: MOI.AbstractVectorSet
struct EpiPerSquareCone{T <: Real} <: MOICones.MOICone
dim::Int
end
export EpiPerSquareCone
Expand All @@ -303,7 +303,7 @@

$(TYPEDFIELDS)
"""
struct EpiNormSpectralTriCone{T <: Real, R <: RealOrComplex{T}} <: MOI.AbstractVectorSet
struct EpiNormSpectralTriCone{T <: Real, R <: RealOrComplex{T}} <: MOICones.MOICone
dim::Int
use_dual::Bool
end
Expand All @@ -329,7 +329,7 @@

$(TYPEDFIELDS)
"""
struct EpiNormSpectralCone{T <: Real, R <: RealOrComplex{T}} <: MOI.AbstractVectorSet
struct EpiNormSpectralCone{T <: Real, R <: RealOrComplex{T}} <: MOICones.MOICone
d1::Int
d2::Int
use_dual::Bool
Expand Down Expand Up @@ -363,7 +363,7 @@

$(TYPEDFIELDS)
"""
struct MatrixEpiPerSquareCone{T <: Real, R <: RealOrComplex{T}} <: MOI.AbstractVectorSet
struct MatrixEpiPerSquareCone{T <: Real, R <: RealOrComplex{T}} <: MOICones.MOICone
d1::Int
d2::Int
use_dual::Bool
Expand Down Expand Up @@ -397,7 +397,7 @@

$(TYPEDFIELDS)
"""
struct GeneralizedPowerCone{T <: Real} <: MOI.AbstractVectorSet
struct GeneralizedPowerCone{T <: Real} <: MOICones.MOICone
α::Vector{T}
n::Int
use_dual::Bool
Expand All @@ -421,7 +421,7 @@

$(TYPEDFIELDS)
"""
struct HypoPowerMeanCone{T <: Real} <: MOI.AbstractVectorSet
struct HypoPowerMeanCone{T <: Real} <: MOICones.MOICone
α::Vector{T}
use_dual::Bool
end
Expand All @@ -442,7 +442,7 @@

$(TYPEDFIELDS)
"""
struct HypoGeoMeanCone{T <: Real} <: MOI.AbstractVectorSet
struct HypoGeoMeanCone{T <: Real} <: MOICones.MOICone
dim::Int
use_dual::Bool
end
Expand All @@ -463,7 +463,7 @@

$(TYPEDFIELDS)
"""
struct HypoRootdetTriCone{T <: Real, R <: RealOrComplex{T}} <: MOI.AbstractVectorSet
struct HypoRootdetTriCone{T <: Real, R <: RealOrComplex{T}} <: MOICones.MOICone
dim::Int
use_dual::Bool
end
Expand All @@ -489,7 +489,7 @@

$(TYPEDFIELDS)
"""
struct HypoPerLogCone{T <: Real} <: MOI.AbstractVectorSet
struct HypoPerLogCone{T <: Real} <: MOICones.MOICone
dim::Int
use_dual::Bool
end
Expand All @@ -510,7 +510,7 @@

$(TYPEDFIELDS)
"""
struct HypoPerLogdetTriCone{T <: Real, R <: RealOrComplex{T}} <: MOI.AbstractVectorSet
struct HypoPerLogdetTriCone{T <: Real, R <: RealOrComplex{T}} <: MOICones.MOICone
dim::Int
use_dual::Bool
end
Expand All @@ -536,7 +536,7 @@

$(TYPEDFIELDS)
"""
struct EpiPerSepSpectralCone{T <: Real} <: MOI.AbstractVectorSet
struct EpiPerSepSpectralCone{T <: Real} <: MOICones.MOICone
h::Cones.SepSpectralFun
Q::Type{<:Cones.ConeOfSquares{T}}
d::Int
Expand Down Expand Up @@ -565,7 +565,7 @@

$(TYPEDFIELDS)
"""
struct EpiRelEntropyCone{T <: Real} <: MOI.AbstractVectorSet
struct EpiRelEntropyCone{T <: Real} <: MOICones.MOICone
dim::Int
use_dual::Bool
end
Expand All @@ -586,7 +586,7 @@

$(TYPEDFIELDS)
"""
struct EpiTrRelEntropyTriCone{T <: Real, R <: RealOrComplex{T}} <: MOI.AbstractVectorSet
struct EpiTrRelEntropyTriCone{T <: Real, R <: RealOrComplex{T}} <: MOICones.MOICone
dim::Int
use_dual::Bool
end
Expand All @@ -612,7 +612,7 @@

$(TYPEDFIELDS)
"""
struct WSOSInterpNonnegativeCone{T <: Real, R <: RealOrComplex{T}} <: MOI.AbstractVectorSet
struct WSOSInterpNonnegativeCone{T <: Real, R <: RealOrComplex{T}} <: MOICones.MOICone
U::Int
Ps::Vector{Matrix{R}}
use_dual::Bool
Expand Down Expand Up @@ -642,7 +642,7 @@

$(TYPEDFIELDS)
"""
struct WSOSInterpPosSemidefTriCone{T <: Real} <: MOI.AbstractVectorSet
struct WSOSInterpPosSemidefTriCone{T <: Real} <: MOICones.MOICone
R::Int
U::Int
Ps::Vector{Matrix{T}}
Expand Down Expand Up @@ -676,7 +676,7 @@

$(TYPEDFIELDS)
"""
struct WSOSInterpEpiNormOneCone{T <: Real} <: MOI.AbstractVectorSet
struct WSOSInterpEpiNormOneCone{T <: Real} <: MOICones.MOICone
R::Int
U::Int
Ps::Vector{Matrix{T}}
Expand Down Expand Up @@ -705,7 +705,7 @@

$(TYPEDFIELDS)
"""
struct WSOSInterpEpiNormEuclCone{T <: Real} <: MOI.AbstractVectorSet
struct WSOSInterpEpiNormEuclCone{T <: Real} <: MOICones.MOICone
R::Int
U::Int
Ps::Vector{Matrix{T}}
Expand All @@ -729,45 +729,8 @@

# all cones

const HypatiaCones{T <: Real} = Union{
NonnegativeCone{T},
PosSemidefTriCone{T, T},
PosSemidefTriCone{T, Complex{T}},
DoublyNonnegativeTriCone{T},
PosSemidefTriSparseCone{<:Cones.PSDSparseImpl, T, T},
PosSemidefTriSparseCone{<:Cones.PSDSparseImpl, T, Complex{T}},
LinMatrixIneqCone{T},
EpiNormInfCone{T, T},
EpiNormInfCone{T, Complex{T}},
EpiNormEuclCone{T},
EpiPerSquareCone{T},
EpiNormSpectralTriCone{T, T},
EpiNormSpectralTriCone{T, Complex{T}},
EpiNormSpectralCone{T, T},
EpiNormSpectralCone{T, Complex{T}},
MatrixEpiPerSquareCone{T, T},
MatrixEpiPerSquareCone{T, Complex{T}},
GeneralizedPowerCone{T},
HypoPowerMeanCone{T},
HypoGeoMeanCone{T},
HypoRootdetTriCone{T, T},
HypoRootdetTriCone{T, Complex{T}},
HypoPerLogCone{T},
HypoPerLogdetTriCone{T, T},
HypoPerLogdetTriCone{T, Complex{T}},
EpiPerSepSpectralCone{T},
EpiRelEntropyCone{T},
EpiTrRelEntropyTriCone{T, T},
EpiTrRelEntropyTriCone{T, Complex{T}},
WSOSInterpNonnegativeCone{T, T},
WSOSInterpNonnegativeCone{T, Complex{T}},
WSOSInterpPosSemidefTriCone{T},
WSOSInterpEpiNormOneCone{T},
WSOSInterpEpiNormEuclCone{T},
}

const SupportedCone{T <: Real} = Union{
HypatiaCones{T},
MOICones.MOICone,
MOI.Nonnegatives,
MOI.PositiveSemidefiniteConeTriangle,
MOI.HermitianPositiveSemidefiniteConeTriangle,
Expand All @@ -787,4 +750,4 @@
MOI.RelativeEntropyCone,
}

Base.copy(cone::HypatiaCones) = cone # maybe should deep copy the cone struct, but this is expensive
Base.copy(cone::MOICones.MOICone) = cone # maybe should deep copy the cone struct, but this is expensive

Check warning on line 753 in src/MathOptInterface/cones.jl

View check run for this annotation

Codecov / codecov/patch

src/MathOptInterface/cones.jl#L753

Added line #L753 was not covered by tests
Loading