-
Notifications
You must be signed in to change notification settings - Fork 120
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 objective functions #384
Comments
Thanks for bringing this to my attention. This currently doesn’t work in Convex because Convex rewrites the problem to have a linear objective function subject to “second order cone constraints”. This transformation makes solving such a problem easy for solvers that support such constraints but not quadratic objectives (ECOS, SCS, etc), but makes it unable to work with OSQP that does want this specific form. The long term fix is to only do this transformation as necessary, instead of always doing it as Convex does now. I hope to move to that approach (by delegating these transformations to MathOptInterface which only applies them when necessary) at some point but it might take some time. In the meantime, I’d suggest using JuMP.jl or maybe Parametron.jl, depending on your use case. I’ll mark this as a feature request to be closed whenever the right behavior is implemented. |
You should be able to do (I haven't tested though) using Convex
using LinearAlgebra
using OSQP
using MathOptInterface
x = Variable(5)
P = Diagonal(ones(5))
problem = minimize(quadform(x, P))
solve!(problem, () -> MOI.Bridges.full_bridge_optimizer(OSQP.Optimizer(), Float64)) |
@odow Convex transmit the problem as a SOC constraint and we don't have any bridge to transform this SOC constraint back to a quadratic objective as OSQP requires (and it does not seem to be something feasible via bridges) so I don't think that this will work.
I agree that this would be the ideal long term fix. |
I just noticed that for other solvers like COSMO that allows quadrative objectives, Convex also uses this trick and does not pass along a quadratic objective. What is the current status on this ? Will it be possible soeday to pass along quadratic objectives to solvers ? |
same as before- Convex reformulates all problems with extended formulations (always) and passes a single variable objective.
Just depends if someone implements it or not :). AFAIK no one is actively developing Convex.jl right now, but anyone who wants to can! I used Convex a little bit in my PhD so I tried to help develop it further for a year or two (and mostly just fixed bugs)- happy to try to help and provide code review for any PRs (but I don’t really see myself doing much development myself any time soon- I don’t use Convex anymore, so it’s hard to be motivated for it). |
So there's a path forward here: If the objective is a quadratic atom, then instead of calling Here's the bits that would need changed: Lines 136 to 171 in 946d18d
|
I am trying to use Convex.jl to interface with the OSQP solver. However, for some reason I am unable to use quadform in the objective and still have it link to the OSQP optimizer.
When this code runs I get the following error:
I don't understand why it throws an unsupported constraint error as there are no constraints.
The text was updated successfully, but these errors were encountered: