From 8baa5a7fbcae08f7619a0afa4ada61048dd7c301 Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Wed, 12 Jun 2024 08:32:28 +0200 Subject: [PATCH 1/5] Add SMC tests --- test/Project.toml | 1 + test/coloring.jl | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/test/Project.toml b/test/Project.toml index 2a7be4d..8ac2bbb 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -6,5 +6,6 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" MatrixMarket = "4d4711f2-db25-561a-b6b3-d35e7d4047d3" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" +SparseMatrixColorings = "0a514795-09f3-496d-8182-132a7b665d35" StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/coloring.jl b/test/coloring.jl index b7bc4be..a74bb33 100644 --- a/test/coloring.jl +++ b/test/coloring.jl @@ -6,6 +6,10 @@ using LinearAlgebra using MatrixMarket using Random using SparseArrays +using SparseMatrixColorings: + directly_recoverable_columns, + structurally_orthogonal_columns, + symmetrically_orthogonal_columns using StableRNGs using Test @@ -35,6 +39,19 @@ function test_colors(A::AbstractMatrix, method::String, colors::AbstractVector{< @test issymmetric(A) @test maximum(colors) <= size(A, 1) end + if method in ["STAR", "COLUMN_PARTIAL_DISTANCE_TWO", "ROW_PARTIAL_DISTANCE_TWO"] + @test directly_recoverable_columns(A, colors; verbose=true) + if method == "STAR" + @test directly_recoverable_columns(A, colors; verbose=true) + @test symmetrically_orthogonal_columns(A, colors; verbose=true) + elseif method == "COLUMN_PARTIAL_DISTANCE_TWO" + @test directly_recoverable_columns(A, colors; verbose=true) + @test structurally_orthogonal_columns(A, colors; verbose=true) + elseif method == "ROW_PARTIAL_DISTANCE_TWO" + @test directly_recoverable_columns(transpose(A), colors; verbose=true) + @test structurally_orthogonal_columns(transpose(A), colors; verbose=true) + end + end end function test_colors( @@ -71,7 +88,7 @@ end; @testset verbose = true "Bipartite graph partial coloring" begin @testset "$method" for method in PARTIAL_COLORING_METHODS - @testset "$order" for order in PARTIAL_COLORING_ORDERS[1:1] + @testset "$order" for order in PARTIAL_COLORING_ORDERS @testset "(n, m, p) = $((n, m, p))" for (n, m, p) in asymmetric_params J = sprand(rng, Bool, n, m, p) filename = joinpath(@__DIR__, "J.mtx") From 684fb2933462ec4a14faae2631ffa0447b092cf6 Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Wed, 12 Jun 2024 08:35:29 +0200 Subject: [PATCH 2/5] Typo --- test/coloring.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/coloring.jl b/test/coloring.jl index a74bb33..037108c 100644 --- a/test/coloring.jl +++ b/test/coloring.jl @@ -40,7 +40,6 @@ function test_colors(A::AbstractMatrix, method::String, colors::AbstractVector{< @test maximum(colors) <= size(A, 1) end if method in ["STAR", "COLUMN_PARTIAL_DISTANCE_TWO", "ROW_PARTIAL_DISTANCE_TWO"] - @test directly_recoverable_columns(A, colors; verbose=true) if method == "STAR" @test directly_recoverable_columns(A, colors; verbose=true) @test symmetrically_orthogonal_columns(A, colors; verbose=true) @@ -98,7 +97,7 @@ end; filename, method, order; verbose=false ) @test length(get_colors(coloring_mat)) == length(get_colors(coloring_file)) - # this is not always true since we use different algorithms + # this should be true but it isn't at the moment # @test get_colors(coloring_mat) == get_colors(coloring_file) test_colors(J, method, get_colors(coloring_mat)) test_colors(J, method, get_colors(coloring_file)) From aec1c9fd3924224763fd40263991ad49ae5eb9e8 Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Wed, 12 Jun 2024 08:49:36 +0200 Subject: [PATCH 3/5] Switch loops --- test/coloring.jl | 71 ++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/test/coloring.jl b/test/coloring.jl index 037108c..b9522db 100644 --- a/test/coloring.jl +++ b/test/coloring.jl @@ -13,18 +13,20 @@ using SparseMatrixColorings: using StableRNGs using Test -rng = StableRNG(63) +rng = StableRNG(62) + +samples = 10 asymmetric_params = vcat( - [(10, 20, p) for p in (0.0:0.1:1.0)], # - [(20, 10, p) for p in (0.0:0.1:1.0)], - [(100, 200, p) for p in (0.01:0.01:0.05)], # - [(200, 100, p) for p in (0.01:0.01:0.05)], + [(10, 20, p) for p in (0.0:0.2:1.0)], # + [(20, 10, p) for p in (0.0:0.2:1.0)], + [(100, 200, p) for p in (0.01:0.02:0.05)], # + [(200, 100, p) for p in (0.01:0.02:0.05)], ) symmetric_params = vcat( - [(10, p) for p in (0.0:0.1:1.0)], # - [(100, p) for p in (0.01:0.01:0.05)], + [(10, p) for p in (0.0:0.2:1.0)], # + [(100, p) for p in (0.01:0.02:0.05)], ) function test_colors(A::AbstractMatrix, method::String, colors::AbstractVector{<:Integer}) @@ -70,16 +72,18 @@ end @testset verbose = true "General graph coloring" begin @testset "$method" for method in COLORING_METHODS - @testset "$order" for order in COLORING_ORDERS - @testset "(n, p) = $((n, p))" for (n, p) in symmetric_params + @testset "(n, p) = $((n, p))" for (n, p) in symmetric_params + for _ in 1:samples H = sparse(Symmetric(sprand(rng, Bool, n, n, p))) filename = joinpath(@__DIR__, "H.mtx") MatrixMarket.mmwrite(filename, H) - coloring_mat = ColPackColoring(H, method, order; verbose=false) - coloring_file = ColPackColoring(filename, method, order; verbose=false) - @test get_colors(coloring_mat) == get_colors(coloring_file) - colors = get_colors(coloring_file) - test_colors(H, method, colors) + for order in COLORING_ORDERS + coloring_mat = ColPackColoring(H, method, order; verbose=false) + coloring_file = ColPackColoring(filename, method, order; verbose=false) + @test get_colors(coloring_mat) == get_colors(coloring_file) + test_colors(H, method, get_colors(coloring_file)) + test_colors(H, method, get_colors(coloring_mat)) + end end end end @@ -87,20 +91,23 @@ end; @testset verbose = true "Bipartite graph partial coloring" begin @testset "$method" for method in PARTIAL_COLORING_METHODS - @testset "$order" for order in PARTIAL_COLORING_ORDERS - @testset "(n, m, p) = $((n, m, p))" for (n, m, p) in asymmetric_params + @testset "(n, m, p) = $((n, m, p))" for (n, m, p) in asymmetric_params + for _ in 1:samples J = sprand(rng, Bool, n, m, p) filename = joinpath(@__DIR__, "J.mtx") MatrixMarket.mmwrite(filename, J) - coloring_mat = ColPackPartialColoring(J, method, order; verbose=false) - coloring_file = ColPackPartialColoring( - filename, method, order; verbose=false - ) - @test length(get_colors(coloring_mat)) == length(get_colors(coloring_file)) - # this should be true but it isn't at the moment - # @test get_colors(coloring_mat) == get_colors(coloring_file) - test_colors(J, method, get_colors(coloring_mat)) - test_colors(J, method, get_colors(coloring_file)) + for order in PARTIAL_COLORING_ORDERS + coloring_mat = ColPackPartialColoring(J, method, order; verbose=false) + coloring_file = ColPackPartialColoring( + filename, method, order; verbose=false + ) + @test length(get_colors(coloring_mat)) == + length(get_colors(coloring_file)) + # this should be true but it isn't at the moment + @test_skip get_colors(coloring_mat) == get_colors(coloring_file) + test_colors(J, method, get_colors(coloring_file)) + test_colors(J, method, get_colors(coloring_mat)) + end end end end @@ -108,14 +115,18 @@ end; @testset verbose = true "Bipartite graph bicoloring" begin @testset "$method" for method in BICOLORING_METHODS - @testset "$order" for order in BICOLORING_ORDERS[1:1] - @testset "(n, m, p) = $((n, m, p))" for (n, m, p) in asymmetric_params + @testset "(n, m, p) = $((n, m, p))" for (n, m, p) in asymmetric_params + for _ in 1:samples J = sprand(rng, Bool, n, m, p) filename = joinpath(@__DIR__, "J.mtx") MatrixMarket.mmwrite(filename, J) - coloring_file = ColPackBiColoring(filename, method, order; verbose=false) - colors1, colors2 = get_colors(coloring_file) - test_colors(J, method, colors1, colors2) + for order in BICOLORING_ORDERS + coloring_file = ColPackBiColoring( + filename, method, order; verbose=false + ) + colors1, colors2 = get_colors(coloring_file) + test_colors(J, method, colors1, colors2) + end end end end From ae5e1d6a15e66cd23348c307e47c2f0a2094386e Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Wed, 12 Jun 2024 09:02:09 +0200 Subject: [PATCH 4/5] Remove test on 1.6 --- .github/workflows/Test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index 4f55f96..433d302 100644 --- a/.github/workflows/Test.yml +++ b/.github/workflows/Test.yml @@ -16,7 +16,9 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - julia-version: ['1.6', '1'] + julia-version: + # - '1.6' + - '1' steps: - uses: actions/checkout@v4 From ace9001e22fc9a36eef444d70ab767c8d9fac2ff Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Wed, 12 Jun 2024 16:41:21 +0200 Subject: [PATCH 5/5] 100 samples --- test/coloring.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/coloring.jl b/test/coloring.jl index b9522db..f10f3e6 100644 --- a/test/coloring.jl +++ b/test/coloring.jl @@ -15,7 +15,7 @@ using Test rng = StableRNG(62) -samples = 10 +samples = 100 asymmetric_params = vcat( [(10, 20, p) for p in (0.0:0.2:1.0)], #