-
Notifications
You must be signed in to change notification settings - Fork 1
Add JuMP interface #20
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
Open
blegat
wants to merge
22
commits into
luotuoqingshan:main
Choose a base branch
from
blegat:bl/lowrankopt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
1307930
Add JuMP interface
blegat 1812f24
Progress
blegat c2c9d1d
Updates
blegat fd0f6bb
Fix
blegat 0f79edb
Working
blegat 8a892a1
Fix
blegat 5d2dfee
Fix rank display
blegat 92a5850
Remove deps
blegat 0dfdee4
Fixes
blegat b824766
Fix when there are also scalars
blegat 35a4390
Refactor construction of SDPAux
blegat 69a6c84
Fix
blegat d40c8cb
Add timings
blegat 00bbea9
Add deps
blegat aafb43b
update bench
blegat 4a7f990
Add status
blegat 7d6b5a9
Updates
blegat f2964d3
Bump LowRankOpt v0.2.1
blegat 1be26bf
Fix
blegat 2ea1d37
Shortcut if objtol is infinite
blegat 0493cc1
Move code to simplify logic
blegat c4c9201
Only set rank to 1 if necessary
blegat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| using Revise | ||
| using SparseArrays | ||
| using SDPLRPlus | ||
|
|
||
| using LowRankOpt | ||
| using Dualization | ||
| include(joinpath(dirname(dirname(pathof(LowRankOpt))), "examples", "maxcut.jl")) | ||
|
|
||
| n = 500 | ||
| import Random | ||
| Random.seed!(0) | ||
| W = sprand(n, n, 0.01) | ||
| W = W + W' | ||
| include(joinpath(@__DIR__, "problems.jl")) | ||
| C, As, b = maxcut(W) | ||
| @time sdplr(C, As, b, 1, maxmajoriter = 20); | ||
|
|
||
| # SDPLRPlus does not support sparse factor | ||
| As = [SymLowRankMatrix(Diagonal(ones(1)), hcat(e_i(Float64, i, n, sparse = false))) for i in 1:n] | ||
| d = SDPLRPlus.SDPData(C, As, b) | ||
| var = SDPLRPlus.SolverVars(d, 1) | ||
| aux = SDPLRPlus.SolverAuxiliary(d) | ||
| @time sdplr(C, As, b, 1, maxmajoriter = 50); | ||
|
|
||
| model = maxcut(W, dual_optimizer(LRO.Optimizer)) | ||
| set_attribute(model, "solver", LRO.BurerMonteiro.Solver) | ||
| set_attribute(model, "sub_solver", SDPLRPlus.Solver) | ||
| set_attribute(model, "ranks", [1]) | ||
| set_attribute(model, "maxmajoriter", 0) | ||
| set_attribute(model, "printlevel", 3) | ||
| @profview optimize!(model) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On this line I got one MKLSparseError, I'm quite confused about this error, do you have any clue? This error keeps showing up in the following benchmarking code too. |
||
| solver = unsafe_backend(model).dual_problem.dual_model.model.optimizer.solver | ||
|
|
||
| using BenchmarkTools | ||
| function A_sym_bench(aux, var, nlp, var_lro) | ||
| println("𝒜 sym") | ||
| @btime SDPLRPlus.𝒜!(var.primal_vio, aux, var.Rt) | ||
| @btime SDPLRPlus.𝒜!(var_lro.primal_vio, nlp, var_lro.Rt) | ||
| end | ||
| function A_not_sym_bench(aux, var, nlp, var_lro) | ||
| println("𝒜 not sym") | ||
| @btime SDPLRPlus.𝒜!(var.A_RD, aux, var.Rt, var.Gt) | ||
| @btime SDPLRPlus.𝒜!(var_lro.A_RD, nlp, var_lro.Rt, var_lro.Gt) | ||
| end | ||
| function At_bench(aux, var, nlp, var_lro) | ||
| println("𝒜t") | ||
| @btime SDPLRPlus.𝒜t!($var.Gt, $var.Rt, $aux, $var) | ||
| @btime SDPLRPlus.𝒜t!($var_lro.Gt, $var_lro.Rt, $nlp, $var_lro) | ||
| end | ||
| function At_bench2(aux, var, nlp, var_lro) | ||
| println("𝒜t rank-1") | ||
| x = rand(n) | ||
| y = similar(x) | ||
| @time SDPLRPlus.𝒜t!(y, aux, x, var) | ||
| @time SDPLRPlus.𝒜t!(y, nlp, x, var_lro) | ||
| end | ||
| nlp = solver.model | ||
| var_lro = solver.solver.var | ||
| A_sym_bench(aux, var, solver.model, solver.solver.var) | ||
| A_not_sym_bench(aux, var, solver.model, solver.solver.var) | ||
| At_bench(aux, var, solver.model, solver.solver.var) | ||
| At_bench2(aux, var, solver.model, solver.solver.var) | ||
| @profview SDPLRPlus.𝒜!(var.primal_vio, aux, var.Rt) | ||
| @profview for i in 1:100 | ||
| SDPLRPlus.𝒜!(var_lro.primal_vio, nlp, var_lro.Rt) | ||
| end | ||
| @time SDPLRPlus.𝒜!(var_lro.primal_vio, nlp, var_lro.Rt) | ||
| @time SDPLRPlus.𝒜t!(var_lro.Gt, var_lro.Rt, nlp, var_lro) | ||
| @profview for _ in 1:1000 | ||
| SDPLRPlus.𝒜t!(var_lro.Gt, var_lro.Rt, nlp, var_lro) | ||
| end | ||
| function bench_lmul(A) | ||
| n = LinearAlgebra.checksquare(A) | ||
| x = rand(1, n) | ||
| y = similar(x) | ||
| @profview for i in 1:100000 | ||
| LinearAlgebra.mul!(y, x, A, 2.0, 1.0) | ||
| end | ||
| #@btime LinearAlgebra.mul!($y, $x, $A, 2.0, 1.0) | ||
| end | ||
| function bench_rmul(A) | ||
| n = LinearAlgebra.checksquare(A) | ||
| x = rand(n, 1) | ||
| y = similar(x) | ||
| @btime LinearAlgebra.mul!($y, $A, $x, 2.0, 1.0) | ||
| end | ||
| bench_lmul(aux.symlowrank_As[1]); | ||
| A = aux.symlowrank_As[1] | ||
| n = LinearAlgebra.checksquare(A) | ||
| x = rand(1, n) | ||
| y = similar(x) | ||
| LinearAlgebra.mul!(y, x, A, 2.0, 1.0) | ||
|
|
||
| bench_rmul(nlp.model.A[1]); | ||
| bench_lmul(nlp.model.A[1]) | ||
| A = nlp.model.A[1] | ||
| n = LinearAlgebra.checksquare(A) | ||
| x = rand(n, 1) | ||
| y = similar(x) | ||
| @time LinearAlgebra.mul!(y, A, x, 2.0, 1.0); | ||
| @btime LinearAlgebra.mul!($y, $A, $x, 2.0, 1.0); | ||
| methods(LinearAlgebra.mul!, typeof.((y, A, x, 2.0, 1.0))) | ||
|
|
||
| A = nlp.model.A[1] | ||
| n = LinearAlgebra.checksquare(A) | ||
| x = rand(n) | ||
| y = similar(x) | ||
| x = rand(n) | ||
| y = similar(x) | ||
| @btime LinearAlgebra.mul!($y, $A, $x, 2.0, 1.0); | ||
|
|
||
| C = LRO._lmul_diag!!(A.scaling, LRO.right_factor(A)' * x) | ||
| lA = LRO.left_factor(A) | ||
| @btime LinearAlgebra.mul!($y, $C, $lA) | ||
| @edit LinearAlgebra.mul!(y, lA, C); | ||
| @edit LinearAlgebra.mul!(y, lA, C, true, true); | ||
| @edit LinearAlgebra._rscale_add!(y, lA, C, true, true); | ||
| @edit LinearAlgebra.mul!($y, $lA, $C, 2.0, 1.0); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,5 +41,6 @@ include("utils.jl") | |
| # main function | ||
| include("sdplr.jl") | ||
|
|
||
| include("lowrankopt.jl") | ||
|
|
||
| end | ||
| end | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running this bench.jl gives me the following error on this line.
I saw in
LowRankOpt.jl,vectordoes not have a default value, is this the cause? Function e_i in LowRankOpt.jl