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

More tests from SparseMatrixColorings [SEGFAULT] #25

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 3 additions & 1 deletion .github/workflows/Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
87 changes: 57 additions & 30 deletions test/coloring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,27 @@ using LinearAlgebra
using MatrixMarket
using Random
using SparseArrays
using SparseMatrixColorings:
directly_recoverable_columns,
structurally_orthogonal_columns,
symmetrically_orthogonal_columns
using StableRNGs
using Test

rng = StableRNG(63)
rng = StableRNG(62)

samples = 100

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})
Expand All @@ -35,6 +41,18 @@ 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"]
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(
Expand All @@ -54,52 +72,61 @@ 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
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 is not always true since we use different algorithms
# @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
end;

@testset verbose = true "Bipartite graph bicoloring" begin
@testset "$method" for method in BICOLORING_METHODS
@testset "$order" for order in BICOLORING_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_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
Expand Down
Loading