Help understanding MOI bridges, Even Proof-of-concept doesn't work

You’re close, but you need something like

struct RemovePSDBridge{T} <: MOI.Bridges.Constraint.AbstractBridge 
end

function MOI.Bridges.Constraint.concrete_bridge_type(
    ::Type{<:RemovePSDBridge}, 
    F::Type{<:MOI.AbstractVectorFunction},
    S::Type{<:MOI.PositiveSemidefiniteConeTriangle},
)
    return RemovePSDBridge{Float64}
end

function MOI.supports_constraint(
    ::Type{<:RemovePSDBridge},
	::Type{<:MOI.AbstractVectorFunction},
	::Type{<:MOI.PositiveSemidefiniteConeTriangle},
)
	return true
end

function MOI.Bridges.added_constrained_variable_types(::Type{<:RemovePSDBridge}) 
	return Tuple{DataType}[]
end

function MOI.Bridges.added_constraint_types(::Type{<:RemovePSDBridge})
	return []
end

function MOI.Bridges.Constraint.bridge_constraint(
    ::Type{<:RemovePSDBridge}, 
    ::MOI.ModelLike, 
    f::MOI.AbstractVectorFunction, 
    s::MOI.PositiveSemidefiniteConeTriangle,
)
    return RemovePSDBridge{Float64}()
end

# Wrap the optimizer in a single bridge optimizer
opt = () -> MOI.Bridges.Constraint.SingleBridgeOptimizer{RemovePSDBridge{Float64}}(
    # Clp doesn't support incremental modification, so we need to wrap it in a cache
    MOI.Utilities.CachingOptimizer(
        MOI.Utilities.Model{Float64}(),
        Clp.Optimizer()
    )
)
m = Model(opt)
@variable m x[1:3]
@objective m Min x[1]
@constraint(m,[x[1] x[2];x[2] x[3]] in JuMP.PSDCone())
optimize!(m)

If you’re interested in understanding the bridging system, I suggest you read: MathOptInterface: a data structure for mathematical optimization problems – Optimization Online

Implementing this is definitely nontrivial and not well documented, short of following examples.

@rtwalker did a great job implementing a bridge recently: https://github.com/jump-dev/MathOptInterface.jl/pull/1099. Reading through the comments is probably a good way to learn the thought process.

3 Likes