gdalle / sparsematrixcolorings.jl Goto Github PK
View Code? Open in Web Editor NEWColoring algorithms for sparse Jacobian and Hessian matrices
Home Page: https://gdalle.github.io/SparseMatrixColorings.jl/
License: MIT License
Coloring algorithms for sparse Jacobian and Hessian matrices
Home Page: https://gdalle.github.io/SparseMatrixColorings.jl/
License: MIT License
The following test is skipped because it fails at the moment:
SparseMatrixColorings.jl/test/performance.jl
Lines 82 to 83 in b6c38d9
I think that we should also export these routines.
The revamp in #38 means we no longer support plain color vectors for decompression. This makes DI incompatible with any coloring algorithm that doesn't come from here, and thus with the ADTypes coloring interface.
In interface.jl
we have:
function coloring(
S::AbstractMatrix,
::ColoringProblem{:symmetric,:column,:direct},
algo::GreedyColoringAlgorithm,
)
ag = adjacency_graph(S)
color, star_set = star_coloring(ag, algo.order)
# TODO: handle star_set
return DefaultColoringResult{:symmetric,:column,:direct}(S, color)
end
function coloring(
S::AbstractMatrix,
::ColoringProblem{:symmetric,:column,:substitution},
algo::GreedyColoringAlgorithm,
)
ag = adjacency_graph(S)
color, tree_set = acyclic_coloring(ag, algo.order)
# TODO: handle tree_set
return DefaultColoringResult{:symmetric,:column,:substitution}(S, color)
end
Should we also add:
function coloring(
S::AbstractMatrix,
::ColoringProblem{:symmetric,:row,:direct},
algo::GreedyColoringAlgorithm,
)
ag = adjacency_graph(S)
color, star_set = star_coloring(ag, algo.order)
# TODO: handle star_set
return DefaultColoringResult{:symmetric,:row,:direct}(S, color)
end
function coloring(
S::AbstractMatrix,
::ColoringProblem{:symmetric,:row,:substitution},
algo::GreedyColoringAlgorithm,
)
ag = adjacency_graph(S)
color, tree_set = acyclic_coloring(ag, algo.order)
# TODO: handle tree_set
return DefaultColoringResult{:symmetric,:row,:substitution}(S, color)
end
Alternative solution:
Should we add a :row_or_column
entry to the partition, and only allow it if structure == :symmetric
?
I don't know where to find the matrices used in Table 7.1 of "New Acyclic and Star Coloring Algorithms"
To compare with ColPack (https://dl.acm.org/doi/10.1145/2513109.2513110) we need the following orders:
#38 is a great PR (congrats to the guy who wrote it) but it leaves aside the question of decompressing when all we have is the StarSet
and not a SparseMatrixCSC
.
Opening this issue to keep track once I merge
In DifferentiationInterface, the structure
and partition
can be deduced from the context, but the decompression
method (either :direct
or :substitution
) should be configurable by the user.
In AutoSparse
backend you can give a ColoringAlgorithm
.
This issue is used to trigger TagBot; feel free to unsubscribe.
If you haven't already, you should update your TagBot.yml
to include issue comment triggers.
Please see this post on Discourse for instructions and more details.
If you'd like for me to do this for you, comment TagBot fix
on this issue.
I'll open a PR within a few hours, please be patient!
There are some matrix types for which we can directly compute the optimal coloring, like (block-)banded matrices.
ArrayInterface.jl does this already but only for column coloring. We could reuse some of that code (if the license is right) and generalize it to other colorings (row, symmetric, bidirectional).
Related:
This would allow processing B
one column or row at a time.
First implementation in #26
Will never be used in practice with GreedyColoringAlgorithm
, but one could imagine optimal colorings with JuMP, which would only output a vector of colors.
#71 contains a LinearSystemColoringResult
, which is part of the answer in the symmetric case.
At the moment, ADTypes specifies that the result of coloring is just a vector of integer colors.
However, in the case of symmetric coloring, we can compute other things (a star set) that speed up decompression.
More generally, a coloring algorithm could return an AbstractColoringResult
, which is then used in a decompression function whose API we need to hash out. Perhaps #35 can help?
At the moment I implement DirectRecover1
from https://www.cs.purdue.edu/homes/apothen/Papers/hessian-coloring-joc.pdf, but DirectRecover2
is more efficient
Once we have solved #44
It is a linear operation so yes. However, it is a linear operation on vectors of values, not matrices.
For column decompression, let
Then there exists a matrix
We can further replace
Example: if
then we have
Is this useful in practice? How does it generalize
In all cases we have linear functions.
:full
, :lower
or :upper
.I compute it anyway when creating the graph
At the moment, our only optimized decompression is for SparseMatrixCSC
in :direct
mode: we store a vector of compressed_indices
such that nonzeros(A) = vec(B)[compressed_indices]
.
We can probably find a similar optimization for :substitution
mode.
What do we want to do for other matrix types, like:
LinearAlgebra
: Bidiagonal
, Tridiagonal
, Symmetric
, etc.It would be rather tiring to find optimal decompression methods for each of these. My proposal (as a first step) would be to always have a SparseMatrixCSC
buffer into which we decompress, and then copy the A_buffer::SparseMatrixCSC
into A::SomeWeirdMatrix
.
Essentially, it's easier to implement fast copy from SparseMatrixCSC
than fast decompression.
Related:
This could help taylor decompression preparation. Right now we make the hypothesis that A = similar(S, Float64)
or something to that effect.
The coloring algorithms in this package only color rows or columns, but it would be nice to have bicoloring for mixed mode (forward+reverse) Jacobian evaluation.
Related:
For the following matrix, how can I know if I should use the "compressed columns" in the AD context associated to colors[i]
or colors[j]
to determine the coefficient H[i,j]
?
10×10 SparseMatrixCSC{Float64, Int64} with 58 stored entries:
2.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 2.0 2.0
1.0 2.0 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0 1.0
1.0 ⋅ 2.0 ⋅ ⋅ ⋅ ⋅ ⋅ 1.0 1.0
1.0 ⋅ ⋅ 2.0 ⋅ ⋅ ⋅ ⋅ 1.0 1.0
1.0 ⋅ ⋅ ⋅ 2.0 ⋅ ⋅ ⋅ 1.0 1.0
1.0 ⋅ ⋅ ⋅ ⋅ 2.0 ⋅ ⋅ 1.0 1.0
1.0 ⋅ ⋅ ⋅ ⋅ ⋅ 2.0 ⋅ 1.0 1.0
1.0 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 2.0 1.0 1.0
2.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 2.0 1.0
2.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 2.0
julia> colors = symmetric_coloring(H, GreedyColoringAlgorithm())
10-element Vector{Int64}:
1
2
2
2
2
2
2
2
3
4
Right now the problem and algorithm constructors are not type-stable. This must be solved before v0.4
julia> using SparseMatrixColorings, Test
julia> @inferred ColoringProblem(structure=:symmetric, partition=:column)
ERROR: return type ColoringProblem{:symmetric, :column} does not match inferred return type ColoringProblem
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:35
julia> @inferred GreedyColoringAlgorithm(decompression=:direct)
ERROR: return type GreedyColoringAlgorithm{:direct, SparseMatrixColorings.NaturalOrder} does not match inferred return type GreedyColoringAlgorithm{_A, SparseMatrixColorings.NaturalOrder} where _A
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:35
I didn't implement it because I'm not even sure it is possible. @amontoison what do you think?
What to do when the patterns don't match? Or the matrix types don't match?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.