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

Add support for quadratic constraints #92

Merged
merged 2 commits into from
Dec 5, 2018
Merged

Conversation

tkoolen
Copy link
Owner

@tkoolen tkoolen commented Dec 5, 2018

Unfortunately, I don't think there are currently any MOI optimizers that support modification of quadratic constraints (as I found out after making these changes).

Still useful sans function modification though.

@codecov
Copy link

codecov bot commented Dec 5, 2018

Codecov Report

Merging #92 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #92   +/-   ##
=======================================
  Coverage   98.26%   98.26%           
=======================================
  Files           9        9           
  Lines         635      635           
=======================================
  Hits          624      624           
  Misses         11       11
Impacted Files Coverage Δ
src/moi_interop.jl 98.75% <ø> (ø) ⬆️
src/model.jl 97.64% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 124525d...3178b58. Read the comment docs.

Repository owner deleted a comment from codecov bot Dec 5, 2018
@tkoolen tkoolen changed the title Add support for quadratic constraints (theoretically). Add support for quadratic constraints Dec 5, 2018
@tkoolen
Copy link
Owner Author

tkoolen commented Dec 5, 2018

@rdeits, there are no free solvers with an MOI interface that supports quadratic constraints, is there?

@rdeits
Copy link
Collaborator

rdeits commented Dec 5, 2018

Not that I'm aware of. SCS.jl supports conic constraints, but not quadratic ones, as far as I can tell.

@tkoolen
Copy link
Owner Author

tkoolen commented Dec 5, 2018

OK, thanks.

@tkoolen tkoolen merged commit 46007d3 into master Dec 5, 2018
@tkoolen tkoolen deleted the tk/quadratic-constraints branch December 5, 2018 22:13
@blegat
Copy link

blegat commented Dec 5, 2018

SCS supports quadratic constraints through the QuadtoSOC bridgz but the bridge does not support modification yet

@tkoolen
Copy link
Owner Author

tkoolen commented Dec 5, 2018

OK, great. I'll give that a shot.

@tkoolen
Copy link
Owner Author

tkoolen commented Dec 6, 2018

@blegat, I first tried

optimizer = MOIB.QuadtoSOC{Float64}(SCS.Optimizer(verbose=0))

but that resulted in

ERROR: MathOptInterface.AddVariableNotAllowed: Adding variables cannot be performed. You may want to use a `CachingOptimizer` in `Automatic` mode or you may need to call `resetoptimizer!` before doing this operation if the `CachingOptimizer` is in `Manual` mode.
Stacktrace:
 [1] add_variable(::SCS.Optimizer) at /home/twan/.julia/packages/MathOptInterface/zxv73/src/variables.jl:35
 [2] add_variable(::MathOptInterface.Bridges.SingleBridgeOptimizer{MathOptInterface.Bridges.QuadtoSOCBridge{Float64},MathOptInterface.Bridges.QuadtoSOCInstance{Float64},SCS.Optimizer}) at /home/twan/.julia/packages/MathOptInterface/zxv73/src/Bridges/bridgeoptimizer.jl:320
 [3] default_copy_to(::MathOptInterface.Bridges.SingleBridgeOptimizer{MathOptInterface.Bridges.QuadtoSOCBridge{Float64},MathOptInterface.Bridges.QuadtoSOCInstance{Float64},SCS.Optimizer}, ::Parametron.ParametronMOIModel{Float64}, ::Bool) at /home/twan/.julia/packages/MathOptInterface/zxv73/src/Utilities/copy.jl:175
 [4] #copy_to#1 at /home/twan/.julia/packages/MathOptInterface/zxv73/src/Bridges/bridgeoptimizer.jl:91 [inlined]
 [5] copy_to at /home/twan/.julia/packages/MathOptInterface/zxv73/src/Bridges/bridgeoptimizer.jl:91 [inlined]
 [6] initialize!(::Model{Float64,MathOptInterface.Bridges.SingleBridgeOptimizer{MathOptInterface.Bridges.QuadtoSOCBridge{Float64},MathOptInterface.Bridges.QuadtoSOCInstance{Float64},SCS.Optimizer}}) at /home/twan/.julia/dev/Parametron/src/model.jl:118
 [7] solve!(::Model{Float64,MathOptInterface.Bridges.SingleBridgeOptimizer{MathOptInterface.Bridges.QuadtoSOCBridge{Float64},MathOptInterface.Bridges.QuadtoSOCInstance{Float64},SCS.Optimizer}}) at /home/twan/.julia/dev/Parametron/src/model.jl:153
 [8] top-level scope at ./REPL[47]:2 [inlined]
 [9] top-level scope at ./none:0

I then tried

optimizer = MOIB.QuadtoSOC{Float64}(MOIU.CachingOptimizer(MOIB.QuadtoSOCInstance{Float64}(), SCS.Optimizer(verbose=0)))

but that resulted in

ERROR: MathOptInterface.UnsupportedConstraint{MathOptInterface.VectorAffineFunction{Float64},MathOptInterface.RotatedSecondOrderCone}: `MathOptInterface.VectorAffineFunction{Float64}`-in-`MathOptInterface.RotatedSecondOrderCone` constraints is not supported by the the model.
Stacktrace:
 [1] add_constraint(::MathOptInterface.Bridges.QuadtoSOCInstance{Float64}, ::MathOptInterface.VectorAffineFunction{Float64}, ::MathOptInterface.RotatedSecondOrderCone) at /home/twan/.julia/packages/MathOptInterface/zxv73/src/Utilities/model.jl:330
 [2] add_constraint(::MathOptInterface.Utilities.CachingOptimizer{SCS.Optimizer,MathOptInterface.Bridges.QuadtoSOCInstance{Float64}}, ::MathOptInterface.VectorAffineFunction{Float64}, ::MathOptInterface.RotatedSecondOrderCone) at /home/twan/.julia/packages/MathOptInterface/zxv73/src/Utilities/cachingoptimizer.jl:241
 [3] add_constraint(::MathOptInterface.Bridges.SingleBridgeOptimizer{MathOptInterface.Bridges.QuadtoSOCBridge{Float64},MathOptInterface.Bridges.QuadtoSOCInstance{Float64},MathOptInterface.Utilities.CachingOptimizer{SCS.Optimizer,MathOptInterface.Bridges.QuadtoSOCInstance{Float64}}}, ::MathOptInterface.VectorAffineFunction{Float64}, ::MathOptInterface.RotatedSecondOrderCone) at /home/twan/.julia/packages/MathOptInterface/zxv73/src/Bridges/bridgeoptimizer.jl:300
 [4] MathOptInterface.Bridges.QuadtoSOCBridge{Float64}(::MathOptInterface.Bridges.SingleBridgeOptimizer{MathOptInterface.Bridges.QuadtoSOCBridge{Float64},MathOptInterface.Bridges.QuadtoSOCInstance{Float64},MathOptInterface.Utilities.CachingOptimizer{SCS.Optimizer,MathOptInterface.Bridges.QuadtoSOCInstance{Float64}}}, ::MathOptInterface.ScalarQuadraticFunction{Float64}, ::MathOptInterface.LessThan{Float64}) at /home/twan/.julia/packages/MathOptInterface/zxv73/src/Bridges/quadtosocbridge.jl:106
 [5] add_constraint(::MathOptInterface.Bridges.SingleBridgeOptimizer{MathOptInterface.Bridges.QuadtoSOCBridge{Float64},MathOptInterface.Bridges.QuadtoSOCInstance{Float64},MathOptInterface.Utilities.CachingOptimizer{SCS.Optimizer,MathOptInterface.Bridges.QuadtoSOCInstance{Float64}}}, ::MathOptInterface.ScalarQuadraticFunction{Float64}, ::MathOptInterface.LessThan{Float64}) at /home/twan/.julia/packages/MathOptInterface/zxv73/src/Bridges/bridgeoptimizer.jl:297
 [6] copyconstraints!(::MathOptInterface.Bridges.SingleBridgeOptimizer{MathOptInterface.Bridges.QuadtoSOCBridge{Float64},MathOptInterface.Bridges.QuadtoSOCInstance{Float64},MathOptInterface.Utilities.CachingOptimizer{SCS.Optimizer,MathOptInterface.Bridges.QuadtoSOCInstance{Float64}}}, ::Parametron.ParametronMOIModel{Float64}, ::Bool, ::MathOptInterface.Utilities.IndexMap, ::Type{MathOptInterface.ScalarQuadraticFunction{Float64}}, ::Type{MathOptInterface.LessThan{Float64}}) at /home/twan/.julia/packages/MathOptInterface/zxv73/src/Utilities/copy.jl:145
 [7] default_copy_to(::MathOptInterface.Bridges.SingleBridgeOptimizer{MathOptInterface.Bridges.QuadtoSOCBridge{Float64},MathOptInterface.Bridges.QuadtoSOCInstance{Float64},MathOptInterface.Utilities.CachingOptimizer{SCS.Optimizer,MathOptInterface.Bridges.QuadtoSOCInstance{Float64}}}, ::Parametron.ParametronMOIModel{Float64}, ::Bool) at /home/twan/.julia/packages/MathOptInterface/zxv73/src/Utilities/copy.jl:187
 [8] #copy_to#1 at /home/twan/.julia/packages/MathOptInterface/zxv73/src/Bridges/bridgeoptimizer.jl:91 [inlined]
 [9] copy_to at /home/twan/.julia/packages/MathOptInterface/zxv73/src/Bridges/bridgeoptimizer.jl:91 [inlined]
 [10] initialize!(::Model{Float64,MathOptInterface.Bridges.SingleBridgeOptimizer{MathOptInterface.Bridges.QuadtoSOCBridge{Float64},MathOptInterface.Bridges.QuadtoSOCInstance{Float64},MathOptInterface.Utilities.CachingOptimizer{SCS.Optimizer,MathOptInterface.Bridges.QuadtoSOCInstance{Float64}}}}) at /home/twan/.julia/dev/Parametron/src/model.jl:118
 [11] solve!(::Model{Float64,MathOptInterface.Bridges.SingleBridgeOptimizer{MathOptInterface.Bridges.QuadtoSOCBridge{Float64},MathOptInterface.Bridges.QuadtoSOCInstance{Float64},MathOptInterface.Utilities.CachingOptimizer{SCS.Optimizer,MathOptInterface.Bridges.QuadtoSOCInstance{Float64}}}}) at /home/twan/.julia/dev/Parametron/src/model.jl:153
 [12] top-level scope at ./REPL[61]:2 [inlined]
 [13] top-level scope at ./none:0

Ideally, the first would work, right? I'm not very familiar with this part of MOI, but I noticed this automatic_copy_to function. Should that be used instead of default_copy_to for AbstractBridgeOptimizer?

@tkoolen
Copy link
Owner Author

tkoolen commented Dec 6, 2018

(see this branch: https://github.com/tkoolen/Parametron.jl/tree/tk/scs)

@blegat
Copy link

blegat commented Dec 6, 2018

QuadtoSOCInstance is meant to store Quad constraints before being bridged, they cannot store them when bridged (note this is probably going away jump-dev/MathOptInterface.jl#523).
You can try JuMP.JuMPMOIModel instead.
Note that the CachingOptimizer won't be needed once jump-dev/MathOptInterface.jl#523 is implemented as SCS uses the Allocate-Load interface (this is the reason we might modify the OSQP wrapper to use the Allocate-Load interface instead of using a custom implementation of MOIKcopy_to).

@tkoolen
Copy link
Owner Author

tkoolen commented Dec 6, 2018

OK, thanks. I think I might wait until the dust settles a bit then.

we might modify the OSQP wrapper to use the Allocate-Load interface

I think that's fine. I wouldn't expect it to be slower than what's currently there, but if it is a bit slower, no worries. I need the modification functions to be fast and not allocate, but the performance requirements for copy_to aren't as stringent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants