jump-dev / ECOS.jl

A Julia interface to the ECOS conic optimization solver
https://github.com/embotech/ecos
Other
41 stars 17 forks source link

WIP: Conic interface #5

Closed IainNZ closed 10 years ago

IainNZ commented 10 years ago

Don't merge yet, just keep open PR to easily track progress.

@mlubin @joehuchette @madeleineudell @karanveerm

jfsantos commented 10 years ago

Roger that!

IainNZ commented 10 years ago

Progress:

using JuMP
using ECOS
m = Model(solver=ECOSSolver())
@defVar(m, x[1:5])
@setObjective(m, Max, 3x[1] + 4x[2] + 4x[3] + 9x[4] + 5x[5])
@addConstraint(m, pos[i=1:5], x[i] >= 0)
@addConstraint(m, x[1] + x[2] <= 5)
@addConstraint(m, x[2] + x[5] <= 3)
@addConstraint(m, x[3] + x[4] + x[5] <= 9)
solve(m)

works (well, solves the right problem)

jfsantos commented 10 years ago

That's a good sign :) I honestly do not know what would be some interesting "corner cases" to try, but one idea I had is to rewrite some of the original ECOS tests using the conic interface. I can run the MATLAB examples from here and store the outputs in data files. Would this help?

joehuchette commented 10 years ago

Yes, that sounds like it would be great!

IainNZ commented 10 years ago

More tests is always good.

IainNZ commented 10 years ago

I'm hitting a wall extracting stuff from the problem type, i.e.

ecos_prob = unsafe_pointer_to_objref(ecos_prob_ptr)
dump(ecos_prob.x)  # segfault

@mlubin any ideas?

jfsantos commented 10 years ago

I am also getting a segfault when trying to get the solution from the low-level interface. However, doing it like in the CVX implementation works:

using ECOS
include("~/.julia/v0.3/ECOS/test/runtests.jl")
work = pointer_to_array(mywork, 1)[1]
x = pointer_to_array(work.x, 223)

(In this case, I think a cleaner way of doing that would be work = unsafe_load(mywork, 1))

IainNZ commented 10 years ago

Thanks @jfsantos , that works!

jfsantos commented 10 years ago

Great, I'm glad that it helped! By the way, are you using an alternative branch of JuMP to test this? I'm getting started at translating the tests from MATLAB to your conic interface.

IainNZ commented 10 years ago

I'm using master version of JuMP, although release version would work. The interface I'm working on right now (that @joehuchette got started) is just the standard LP interface, not the conic interface. I've just got it working so I'm about to start implementing the conic interface. JuMP doesn't and probably won't use the conic interface, but CVX.jl will.

jfsantos commented 10 years ago

Alright, scratch it then. I mixed things up! None of the MATLAB examples for ECOS are LPs, so I'll wait for the conic interface.

joehuchette commented 10 years ago

Are there any QPs or SOCPs in the test set? We can use JuMP to model those.

jfsantos commented 10 years ago

Yes, there's a portfolio optimization problem written as a SOCP. I'll install Gurobi here and test it with JuMP for the time being. Thanks!

IainNZ commented 10 years ago

OK, so I have LP-as-conic-form done, now the more mind bending part of doing SOC :+1:

@mlubin or @joehuchette , if you are bored, can you add the generic methods to MathProgBase and bump the version?

joehuchette commented 10 years ago

Added, I'll bump it now.

IainNZ commented 10 years ago

Victory! Working up to :SOC cones, not worrying about rotated SOC right now. Main issues to resolve:

IainNZ commented 10 years ago

Now working on https://github.com/cvxgrp/CVX.jl/pull/19

IainNZ commented 10 years ago

OK done as much with CVX as I can figure out. Once this is a bit more robust I think it can be merged. Add some docs and maybe some more tests, then we can probably move to JuliaOpt

mlubin commented 10 years ago

@IainNZ, the conic interface was meant to be flexible on the modeling side, and it's expected that the solver interfaces will likely need to maintain permutation vectors to put the cones into the expected order.

IainNZ commented 10 years ago

Righto then, shouldn't be too painful. Its been pretty good so far

IainNZ commented 10 years ago

OK I think I'm done! Almost ready for merge...

IainNZ commented 10 years ago

OK @jfsantos can you merge this. After you do, I'll add you as a (temporary) admin of JuliaOpt, which will allow you to transfer this package to JuliaOpt in the Settings page. We will then figure how to provide a binary on OSX, then announce it to the world.

joehuchette commented 10 years ago

We'd also love for you to join us in JuliaOpt if you're interested :)

jfsantos commented 10 years ago

Merged! Thank you very much for doing this.

I'm interested in joining JuliaOpt, thanks! After we move this repository to the organization you can downgrade my status from admin to something less "dangerous" :)

IainNZ commented 10 years ago

OK, you are now an "owner" of JuliaOpt. Let me know when you've moved it!

jfsantos commented 10 years ago

I think it is done! Travis still didn't catch up with the change, so let's wait for a few minutes to make sure everything is fine.

IainNZ commented 10 years ago

Fixed it, nice!