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

Pg/one big module #47

Merged
merged 25 commits into from
Oct 31, 2018
Merged
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
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ git:

## uncomment the following lines to override the default test script
#script:
# - julia -e 'Pkg.clone(pwd()); Pkg.build("QOCS"); Pkg.test("QOCS"; coverage=true)'
# - julia -e 'Pkg.clone(pwd()); Pkg.build("COSMO"); Pkg.test("COSMO"; coverage=true)'
after_success:
# push coverage results to Coveralls
- julia -e 'cd(Pkg.dir("QOCS")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- julia -e 'cd(Pkg.dir("COSMO")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
# push coverage results to Codecov
- julia -e 'cd(Pkg.dir("QOCS")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
- julia -e 'cd(Pkg.dir("COSMO")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
![QOCS Logo](https://github.com/migarstka/QOCS_assets/blob/master/QOCS_logo.png)
This repository hosts a Julia implementation of the QOCS solver. It solves convex optimization problems of the following form:
![COSMO Logo](https://github.com/migarstka/COSMO_assets/blob/master/COSMO_logo.png)
This repository hosts a Julia implementation of the COSMO solver. It solves convex optimization problems of the following form:
```
min 1/2 x'Px + q'x
s.t. Ax + s = b, s in C
```
with decision variables `x ϵ R^n`, `s ϵ R^m` and data matrices `P=P'>=0`, `q ϵ R^n`, `A ϵ R^(m×n)`, and `b ϵ R^m`. The convex set C is a composition of convex sets and cones. By default QOCS supports the zero cone, the non-negative orthant, second order cones and positive semidefinite cones. Further convex sets can be added by the user.
with decision variables `x ϵ R^n`, `s ϵ R^m` and data matrices `P=P'>=0`, `q ϵ R^n`, `A ϵ R^(m×n)`, and `b ϵ R^m`. The convex set C is a composition of convex sets and cones. By default COSMO supports the zero cone, the non-negative orthant, second order cones and positive semidefinite cones. Further convex sets can be added by the user.

## Installation / Usage
- The Solver was written for Julia v0.7/1.0
- Clone package to local machine: `Pkg.clone("https://github.com/oxfordcontrol/QOCS.jl")`
- Load the package with `using QOCS`
- Clone package to local machine: `Pkg.clone("https://github.com/oxfordcontrol/COSMO.jl")`
- Load the package with `using COSMO`
- Consider the following example:

### Example
```julia

using QOCS, Test, LinearAlgebra
using COSMO, Test, LinearAlgebra

# Linear program example
# min c'x
Expand All @@ -30,15 +30,15 @@ Aa = -[A;-Matrix(1.0I,4,4);0 -1 0 0;-1 0 -1 0]
ba = vec([b; -ones(4,1);-5;-4])
P = zeros(size(A,2),size(A,2))

constraint1 = QOCS.Constraint(Aa,ba,QOCS.Nonnegatives())
constraint1 = COSMO.Constraint(Aa,ba,COSMO.Nonnegatives)

# define example problem
settings = QOCS.Settings(rho=0.1,sigma=1e-6,alpha=1.6,max_iter=2500,verbose=true,check_termination=1,eps_abs = 1e-6, eps_rel = 1e-6)
settings = COSMO.Settings(rho=0.1,sigma=1e-6,alpha=1.6,max_iter=2500,verbose=true,check_termination=1,eps_abs = 1e-6, eps_rel = 1e-6)

model = QOCS.Model()
model = COSMO.Model()
assemble!(model,P,c,[constraint1])

res = QOCS.optimize!(model,settings);
res = COSMO.optimize!(model,settings);

@testset "Linear Problem" begin
@test isapprox(res.x[1:4],[3;5;1;1], atol=1e-2, norm=(x -> norm(x,Inf)))
Expand All @@ -49,7 +49,7 @@ nothing


## Settings
Settings can be specified using the `QOCS.Settings` struct. The following settings are available:
Settings can be specified using the `COSMO.Settings` struct. The following settings are available:

Argument | Description | Values (default)
--- | --- | ---
Expand All @@ -72,7 +72,7 @@ time_limit | set solver time limit in s | 0
For more low-level settings, see the Settings definition in `/src/Types.jl`.

## Result
After attempting to solve the problem, QOCS will return a result object with the following fields:
After attempting to solve the problem, COSMO will return a result object with the following fields:

Fieldname | Type | Description
--- | --- | ---
Expand All @@ -82,11 +82,11 @@ s | Vector{Float64}| (Primal) set variable
objVal | Float64 | Objective value
iter | Int64 | Number of iterations
status | Symbol | Solution status
info | QOCS.ResultInfo | Struct with more information
times | QOCS.ResultTimes | Struct with several measured times
info | COSMO.ResultInfo | Struct with more information
times | COSMO.ResultTimes | Struct with several measured times

### Status Codes
QOCS will return one of the following statuses:
COSMO will return one of the following statuses:

Status Code | Description
--- | ---
Expand All @@ -99,7 +99,7 @@ Status Code | Description


### Timings
If `settings.verboseTiming` is set to `true` QOCS will report the following times in `result.times`:
If `settings.verboseTiming` is set to `true` COSMO will report the following times in `result.times`:

Time Name | Description
--- | ---
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"QOCS\"); Pkg.build(\"QOCS\")"
Pkg.clone(pwd(), \"COSMO\"); Pkg.build(\"COSMO\")"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"QOCS\")"
- C:\projects\julia\bin\julia -e "Pkg.test(\"COSMO\")"
12 changes: 6 additions & 6 deletions examples/lp.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Test script to test solver for an lp

using Test
using QOCS, LinearAlgebra
using COSMO, LinearAlgebra

# Linear program example
# min c'x
Expand All @@ -16,18 +16,18 @@ Aa = -[A;-Matrix(1.0I,4,4);0 -1 0 0;-1 0 -1 0]
ba = vec([b; -ones(4,1);-5;-4])
P = zeros(size(A,2),size(A,2))

constraint1 = QOCS.Constraint(Aa,ba,QOCS.Nonnegatives())
constraint1 = COSMO.Constraint(Aa,ba,COSMO.Nonnegatives)

# define example problem
settings = QOCS.Settings(rho=0.1,sigma=1e-6,alpha=1.6,max_iter=2500,verbose=true,check_termination=1,eps_abs = 1e-6, eps_rel = 1e-6)
settings = COSMO.Settings(rho=0.1,sigma=1e-6,alpha=1.6,max_iter=2500,verbose=true,check_termination=1,eps_abs = 1e-6, eps_rel = 1e-6)

model = QOCS.Model()
model = COSMO.Model()
assemble!(model,P,c,constraint1)

res = QOCS.optimize!(model,settings);
res = COSMO.optimize!(model,settings);

@testset "Linear Problem" begin
@test isapprox(res.x[1:4],[3;5;1;1], atol=1e-2, norm=(x -> norm(x,Inf)))
@test isapprox(res.objVal,20.0, atol=1e-2)
end
nothing
nothing
13 changes: 6 additions & 7 deletions examples/maxEigenvalue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# This immediately gives us that
# λ1 = min{t | s.t. tI − A ≥ 0}
using Test
using QOCS, SparseArrays,LinearAlgebra, Random
using COSMO, SparseArrays,LinearAlgebra, Random

nn = 10
rng = MersenneTwister(7232)
Expand All @@ -26,15 +26,15 @@ rng = MersenneTwister(7232)
b1 = 1.
b2 = zeros(r^2)

constraint1 = QOCS.Constraint(A1,b1,QOCS.Zeros())
constraint2 = QOCS.Constraint(A2,b2,QOCS.PositiveSemidefiniteCone())
constraint1 = COSMO.Constraint(A1,b1,COSMO.ZeroSet)
constraint2 = COSMO.Constraint(A2,b2,COSMO.PsdCone)
P = spzeros(r^2,r^2)

settings = QOCS.Settings(check_termination=1,scaling = 0)
settings = COSMO.Settings(check_termination=1,scaling = 0)

model = QOCS.Model()
model = COSMO.Model()
assemble!(model,P,c,[constraint1;constraint2])
res = QOCS.optimize!(model,settings);
res = COSMO.optimize!(model,settings);



Expand All @@ -46,4 +46,3 @@ rng = MersenneTwister(7232)
end
end
nothing

18 changes: 9 additions & 9 deletions examples/qp.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Test script to test solver for a qp

using Test
using QOCS, SparseArrays, LinearAlgebra
using COSMO, SparseArrays, LinearAlgebra

# Quadratic program example from OSQP Doc
# min 0.5 * x'Px + q'x
Expand All @@ -15,23 +15,23 @@ u = [1; 0.7; 0.7]
# Define the constraint l <= Ax <= u with the help of a Nonnegatives set
Aa = [-A;A]
ba = [u; -l]
constraint1 = QOCS.Constraint(Aa,ba,QOCS.Nonnegatives())
constraint1 = COSMO.Constraint(Aa,ba,COSMO.Nonnegatives)

# define example problem
settings = QOCS.Settings(verbose=true,eps_abs = 1e-4,eps_rel = 1e-4)
settings = COSMO.Settings(verbose=true,eps_abs = 1e-4,eps_rel = 1e-4)


model = QOCS.Model()
model = COSMO.Model()
assemble!(model,P,q,constraint1)
res = QOCS.optimize!(model,settings);
res = COSMO.optimize!(model,settings);

# solve again by defining the constraints with the help of a box (disable infeasibility checks)
constraint1 = QOCS.Constraint(A,zeros(3),QOCS.Box(l,u))
settings = QOCS.Settings(check_infeasibility = 2500, verbose=true,eps_abs = 1e-4,eps_rel = 1e-4)
constraint1 = COSMO.Constraint(A,zeros(3),COSMO.Box(l,u))
settings = COSMO.Settings(check_infeasibility = 2500, verbose=true,eps_abs = 1e-4,eps_rel = 1e-4)

model = QOCS.Model()
model = COSMO.Model()
assemble!(model,P,q,constraint1)
res_box = QOCS.optimize!(model,settings);
res_box = COSMO.optimize!(model,settings);


@testset "QP Problem" begin
Expand Down
32 changes: 32 additions & 0 deletions src/COSMO.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#__precompile__()
module COSMO

using SparseArrays,LinearAlgebra, SuiteSparse

#export MathOptInterfaceCOSMO
export assemble!,
optimize!,
warmStart!,
reset!

const DefaultFloat = Float64
const DefaultInt = Int64



include("./algebra.jl")
include("./projections.jl")
include("./types.jl") # some types still need tidying
include("./settings.jl") # TODO: unmodified - revisit
include("./constraint.jl") # TODO: unmodified - revisit
include("./parameters.jl") # TODO: unmodified - revisit
include("./residuals.jl") # TODO: unmodified - revisit
include("./scaling.jl") # TODO: set scaling / E scaling is broken
include("./kkt.jl") # TODO: unmodified - revisit. Add lin solver type
include("./infeasibility.jl") # TODO: stylistic fixes needed
include("./printing.jl") # TODO: unmodified - revisit
include("./setup.jl") # TODO: unmodified - revisit (short - consolidate?)
include("./solver.jl") # TODO: unmodified - revisit
include("./interface.jl") # TODO: unmodified - revisit

end #end module
4 changes: 2 additions & 2 deletions src/Helper.jl → src/COSMOTestUtils.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Helper
module COSMOTestUtils
using LinearAlgebra, Random
export generatePosDefMatrix, isNumericallyPosSemDef, isNumericallySymmetric, findNonSymmetricComponent, findDifferentElements, reCreateSparseMatrix,duplicateSparsityPattern, gmean

Expand Down Expand Up @@ -108,4 +108,4 @@ function gmean(a::AbstractArray{T}) where T<:Real
end
return exp(s / n)
end
end #MODULE
end #MODULE
88 changes: 0 additions & 88 deletions src/Infeasibility.jl

This file was deleted.

22 changes: 0 additions & 22 deletions src/KKT.jl

This file was deleted.

Loading