Skip to content

Add an acyclic coloring#36

Merged
gdalle merged 10 commits intoJuliaDiff:mainfrom
amontoison:acyclic_coloring
Aug 9, 2024
Merged

Add an acyclic coloring#36
gdalle merged 10 commits intoJuliaDiff:mainfrom
amontoison:acyclic_coloring

Conversation

@amontoison
Copy link
Copy Markdown
Collaborator

@amontoison amontoison commented Aug 5, 2024

modified by @gdalle

  • Implement acyclic_coloring with the efficient tree-based algorithm (adds DataStructures.jl to the deps).
  • Implement very naive decompression by substitution for symmetric matrices, can be optimized much more even without the TreeSet. It works by building a matrix T such that T * upper_nonzeros(A) == vec(B) and then inverting the system.
  • Add tests on small instances from the papers as well as large random instances (the equality test is only approximate).

@gdalle
Copy link
Copy Markdown
Member

gdalle commented Aug 5, 2024

Thanks for contributing this! However, before adding it, we may want to think about decompression and how to implement it, see #35 and #37

@amontoison
Copy link
Copy Markdown
Collaborator Author

@gdalle
I will need your help to find the correct size to initialize first_visit_to_tree.
Can we do better than first_visit_to_tree = fill((0, 0), nnz(g))?
I don't know if we can have cases with #trees == #edges.

I have a functional function acyclic_coloring but it doesn't return a correct coloring yet.

using SparseMatrixColorings

A = [
   1  2  0  0  0  0  3  0  0  0
   2  4  5  0  6  0  0  0  0  0
   0  5  7  8  0  9  0  0  0  0
   0  0  8  10 0  0  0  0  0  11
   0  6  0  0  12 13 0  14 0  0
   0  0  9  0  13 15 0  0  16 0
   3  0  0  0  0  0  17 18 0  0
   0  0  0  0  14 0  18 19 20 0
   0  0  0  0  0  16 0  20 21 22
   0  0  0  11 0  0  0  0  22 23
]

g = SparseMatrixColorings.Graph(A)

colors = SparseMatrixColorings.acyclic_coloring(g, SparseMatrixColorings.NaturalOrder())

@test colors == [1, 2, 1, 2, 1, 3, 2, 3, 2, 1]

@amontoison
Copy link
Copy Markdown
Collaborator Author

I checked the code in JuMP, and they use the number of edges:
https://github.com/jump-dev/MathOptInterface.jl/blob/master/src/Nonlinear/ReverseAD/Coloring/Coloring.jl#L184-L187.
They also initialize disjoint_sets with the number of edges instead of dynamically using push! like I do.

@amontoison amontoison marked this pull request as ready for review August 6, 2024 23:22
@codecov
Copy link
Copy Markdown

codecov Bot commented Aug 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.41%. Comparing base (4de73c3) to head (d080331).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #36      +/-   ##
==========================================
+ Coverage   99.23%   99.41%   +0.18%     
==========================================
  Files          11       11              
  Lines         394      516     +122     
==========================================
+ Hits          391      513     +122     
  Misses          3        3              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gdalle
Copy link
Copy Markdown
Member

gdalle commented Aug 8, 2024

I merged #38 even though I wanted to add a few more things so that you can rebase this PR off of it

@gdalle
Copy link
Copy Markdown
Member

gdalle commented Aug 9, 2024

I merged the new ColoringProblem interface from #45 into this PR

@gdalle
Copy link
Copy Markdown
Member

gdalle commented Aug 9, 2024

I merged a few more PRs into this branch, including one that cleans up the examples from the paper figures. Interestingly, Figures 6.1 from "What" and Figure 4 from "Efficient" have the same matrix but different colorings, so it's expected that you wouldn't find both

@amontoison
Copy link
Copy Markdown
Collaborator Author

amontoison commented Aug 9, 2024

I merged a few more PRs into this branch, including one that cleans up the examples from the paper figures. Interestingly, Figures 6.1 from "What" and Figure 4 from "Efficient" have the same matrix but different colorings, so it's expected that you wouldn't find both

I remarked that but the coloring of Figure 6.1 is just an example of an acyclic coloring, it's not related to any code so I don't obtain it with my implementation.
However it's a nice example for testing decompression.

@gdalle gdalle merged commit ac12b9a into JuliaDiff:main Aug 9, 2024
@amontoison amontoison deleted the acyclic_coloring branch August 9, 2024 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants